示例#1
0
class source(gr.basic_block):
    """
    docstring for block source
    """
    def __init__(self, serial=None):
        gr.basic_block.__init__(self,
                                name="source",
                                in_sig=None,
                                out_sig=[numpy.byte])
        self.history = []
        try:
            # self.device = GreatFET(serial_number=serial)
            self.device = GreatFET()
        except greatfet.errors.DeviceNotFoundError:
            raise
        self.device.vendor_request_out(vendor_requests.SDIR_START)

    def general_work(self, input_items, output_items):
        if len(self.history) < len(output_items[0]):
            self.history.extend(self.device.device.read(0x81, 0x4000, 1000))
        out_len = min(len(output_items[0]), len(self.history))
        output_items[0][:out_len] = numpy.array(self.history[:out_len],
                                                dtype=numpy.byte)
        self.history = self.history[out_len:]
        return out_len
示例#2
0
def main():
    logfile = 'log.bin'
    parser = argparse.ArgumentParser(
        description="Utility for experimenting with GreatFET's ADC")
    parser.add_argument('-s',
                        dest='serial',
                        metavar='<serialnumber>',
                        type=str,
                        help="Serial number of device, if multiple devices",
                        default=None)
    parser.add_argument('-f',
                        dest='filename',
                        metavar='<filename>',
                        type=str,
                        help="Write data to file",
                        default=logfile)
    parser.add_argument('-v',
                        dest='verbose',
                        action='store_true',
                        help="Write data from file")
    parser.add_argument('-a',
                        dest='adc',
                        action='store_true',
                        help="Use internal ADC")
    args = parser.parse_args()

    log_function = log_verbose if args.verbose else log_silent

    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(
            device.board_name(), device.serial_number()))
    except greatfet.errors.DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(
                args.serial),
                  file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    if args.adc:
        device.vendor_request_out(vendor_requests.ADC_INIT)
    #else:
    #    device.vendor_request_out(vendor_requests.SDIR_RX_START)

    while True:
        data = device.vendor_request_in(vendor_requests.ADC_READ, length=2)
        print('%d' % (data[1] << 8 | data[0]))
        time.sleep(1)

    if not args.adc:
        device.vendor_request_out(vendor_requests.SDIR_RX_STOP)
示例#3
0
def main():
    parser = argparse.ArgumentParser(description="Drive ADF7242 via SPI")
    parser.add_argument('-r', '--read-register', dest='read_reg', metavar='<addr>', default=None,
                        type=auto_int, help="Read register")
    parser.add_argument('-w', '--write-register', dest='write_reg', default=None,
                        nargs=2, metavar=('<addr>', '<value>'),
                        type=auto_int, help="Write register")
    parser.add_argument('-c', '--command', dest='command', default=None,
                        type=auto_int, metavar='<command>', help="SPI command")
    parser.add_argument('-S', '--status', action='store_true', help='Get status byte')
    parser.add_argument('-t', '--temperature', action='store_true', help='Read temperature')
    parser.add_argument('--reset', action='store_true', help='Reset ADF7242')
    parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str,
                        help="Serial number of device, if multiple devices", default=None)
    parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file")
    args = parser.parse_args()

    # Determine whether we're going to log to the stdout, or not at all.
    log_function = log_verbose if args.verbose else log_silent

    # Create our GreatFET connection.
    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number()))
    except DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    device.vendor_request_out(vendor_requests.SPI_INIT)

    if args.reset:
        adf7242_command(device, 0xC7)

    if args.read_reg:
        print('Register value: {:02x}'.format(adf7242_read_reg(device, args.read_reg)))

    if args.write_reg:
        adf7242_write_reg(device, args.write_reg[0], args.write_reg[1])

    if args.command:
        adf7242_command(device, args.command)

    if args.status:
        print('Status: {:02x}'.format(adf7242_status(device)))

    if args.temperature:
        temp = adf7242_temperature(device)
        temp_f = temp * 9 / 5 + 32
        print('Temperature: {:0.1f} °F / {:.01f} °C'.format(temp_f, temp))
示例#4
0
def main():
    logfile = 'log.bin'
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(
        description="Logic analyzer implementation for GreatFET")
    parser.add_argument('-s',
                        dest='serial',
                        metavar='<serialnumber>',
                        type=str,
                        help="Serial number of device, if multiple devices",
                        default=None)
    parser.add_argument('-f',
                        dest='filename',
                        metavar='<filename>',
                        type=str,
                        help="Write data to file",
                        default=logfile)
    parser.add_argument('-v',
                        dest='verbose',
                        action='store_true',
                        help="Write data from file")
    args = parser.parse_args()

    log_function = log_verbose if args.verbose else log_silent

    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(
            device.board_name(), device.serial_number()))
    except greatfet.errors.DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(
                args.serial),
                  file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    device.vendor_request_out(vendor_requests.LOGIC_ANALYZER_START)

    time.sleep(1)

    f = open(args.filename, 'wb')
    try:
        while True:
            d = device.device.read(0x81, 16384, 1000)
            f.write(d)
    except KeyboardInterrupt:
        pass

    device.vendor_request_out(vendor_requests.LOGIC_ANALYZER_STOP)
示例#5
0
def main():
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(description="Utility for flashing the GreatFET's onboard SPI flash")
    parser.add_argument('-i', '--info', dest='info', action='store_true',
                        help="Read Jedec information from target")
    parser.add_argument('-d', '--dump', dest='dump', metavar='<filename>',
                        type=str, help="Dump flash into file")
    parser.add_argument('-a', '--address', metavar='<n>', default=0,
                        type=int, help="Flash dump starting address")
    parser.add_argument('-l', '--length', metavar='<n>', type=int,default=None,
                        help="number of bytes to read (default: flash size)")
    parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str,
                        help="Serial number of device, if multiple devices", default=None)
    parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file")
    args = parser.parse_args()

    # If we don't have an option, print our usage.
    if not args.info and not args.dump:
        parser.print_help()
        sys.exit()

    # Determine whether we're going to log to the stdout, or not at all.
    log_function = log_verbose if args.verbose else log_silent

    # Create our GreatFET connection.
    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number()))
    except DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    device.vendor_request_out(vendor_requests.SPI_INIT)

    if args.info:
        spi_info(device, log_function=log_verbose)
    if args.dump:
        dump_flash(device, filename=args.dump, address=args.address,
                   length=args.length, log_function=log_verbose)
def main():
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(description="Utility for flashing the GreatFET's onboard SPI flash")
    parser.add_argument('-i', '--info', dest='info', action='store_true',
                        help="Read Jedec information from target")
    parser.add_argument('-d', '--dump', dest='dump', metavar='<filename>',
                        type=str, help="Dump flash into file")
    parser.add_argument('-a', '--address', metavar='<n>', default=0,
                        type=int, help="Flash dump starting address")
    parser.add_argument('-l', '--length', metavar='<n>', type=int,default=None,
                        help="number of bytes to read (default: flash size)")
    parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str,
                        help="Serial number of device, if multiple devices", default=None)
    parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file")
    args = parser.parse_args()

    # If we don't have an option, print our usage.
    if not args.info and not args.dump:
        parser.print_help()
        sys.exit()

    # Determine whether we're going to log to the stdout, or not at all.
    log_function = log_verbose if args.verbose else log_silent

    # Create our GreatFET connection.
    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number()))
    except DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    device.vendor_request_out(vendor_requests.SPI_INIT)

    if args.info:
        spi_info(device, log_function=log_verbose)
    if args.dump:
        dump_flash(device, filename=args.dump, address=args.address,
                   length=args.length, log_function=log_verbose)
示例#7
0
def main():
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(
        description="Utility for flashing the GreatFET's onboard SPI flash")
    parser.add_argument('-s',
                        dest='serial',
                        metavar='<serialnumber>',
                        type=str,
                        help="Serial number of device, if multiple devices",
                        default=None)
    parser.add_argument('-v',
                        dest='verbose',
                        action='store_true',
                        help="Write data from file")
    args = parser.parse_args()

    log_function = log_verbose if args.verbose else log_silent

    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(
            device.board_name(), device.serial_number()))
    except greatfet.errors.DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(
                args.serial),
                  file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    # 0 - 1024
    dac_value = 1024
    device.vendor_request_out(vendor_requests.DAC_SET, value=dac_value)
    print("DAC value set to", dac_value)
def main():
    logfile = 'log.bin'
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(description="Utility for flashing the GreatFET's onboard SPI flash")
    parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str,
                        help="Serial number of device, if multiple devices", default=None)
    parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="Write data to file", default=logfile)
    parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file")
    args = parser.parse_args()

    log_function = log_verbose if args.verbose else log_silent

    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number()))
    except greatfet.errors.DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    device.vendor_request_out(vendor_requests.LOGIC_ANALYZER_START)

    time.sleep(1)

    f = open(args.filename, 'wb')
    try:
        while True:
            d = device.device.read(0x81, 16384, 1000)
            f.write(d)
    except KeyboardInterrupt:
        pass

    device.vendor_request_out(vendor_requests.LOGIC_ANALYZER_STOP)
示例#9
0
def main():
    logfile = 'log.bin'
#    logfile = '/tmp/fifo'
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(description="Utility for experimenting with GreatFET's ADC")
    parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str,
                        help="Serial number of device, if multiple devices", default=None)
    parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="Write data to file", default=logfile)
    parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file")
    parser.add_argument('-a', dest='adc', action='store_true', help="Use internal ADC")
    args = parser.parse_args()

    log_function = log_verbose if args.verbose else log_silent

    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number()))
    except greatfet.errors.DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    if args.adc:
        device.vendor_request_out(vendor_requests.ADC_INIT)
    else:
        device.vendor_request_out(vendor_requests.SDIR_RX_START)

    time.sleep(1)
    print(device.device)

    with open(args.filename, 'wb') as f:
        try:
            while True:
                d = device.device.read(0x81, 0x4000, 1000)
                # print(d)
                f.write(d)
        except KeyboardInterrupt:
            pass

    if not args.adc:
        device.vendor_request_out(vendor_requests.SDIR_RX_STOP)
def main():
    logfile = 'log.bin'
#    logfile = '/tmp/fifo'
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(description="Utility for experimenting with GreatFET's ADC")
    parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str,
                        help="Serial number of device, if multiple devices", default=None)
    parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="Write data to file", default=logfile)
    parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file")
    parser.add_argument('-a', dest='adc', action='store_true', help="Use internal ADC")
    args = parser.parse_args()

    log_function = log_verbose if args.verbose else log_silent

    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number()))
    except greatfet.errors.DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    if args.adc:
        device.vendor_request_out(vendor_requests.ADC_INIT)
    else:
        device.vendor_request_out(vendor_requests.SDIR_RX_START)

    time.sleep(1)
    print(device.device)

    with open(args.filename, 'wb') as f:
        try:
            while True:
                d = device.device.read(0x81, 0x4000, 1000)
                # print(d)
                f.write(d)
        except KeyboardInterrupt:
            pass

    if not args.adc:
        device.vendor_request_out(vendor_requests.SDIR_RX_STOP)
def main():
    logfile = 'log.bin'
#    logfile = '/tmp/fifo'
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(description="Utility for experimenting with GreatFET's ADC")
    parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str,
                        help="Serial number of device, if multiple devices", default=None)
    parser.add_argument('-S', dest='samplerate', metavar='<samplerate>', type=int,
                        help="Sample rate for IR Tx", default=1000000)
    parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="File to read or write", default=logfile)
    parser.add_argument('-r', dest='receive', action='store_true', help="Write data to file")
    parser.add_argument('-R', dest='repeat', action='store_true', help="Repeat file data (tx only)")
    parser.add_argument('-v', dest='verbose', action='store_true', help="Increase verbosity of logging")
    args = parser.parse_args()

    log_function = log_verbose if args.verbose else log_silent

    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number()))
    except greatfet.errors.DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    if args.receive:
        device.vendor_request_out(vendor_requests.SDIR_RX_START)
        time.sleep(1)
        with open(args.filename, 'wb') as f:
            try:
                while True:
                    d = device.device.read(0x81, 0x4000, 1000)
                    # print(d)
                    f.write(d)
            except KeyboardInterrupt:
                pass
        device.vendor_request_out(vendor_requests.SDIR_RX_STOP)

    else:
        index = args.samplerate & 0xFFFF
        value = (args.samplerate >> 16) & 0xFFFF
        device.vendor_request_out(vendor_requests.SDIR_TX_START, value=value, index=index)
        time.sleep(1)
        with open(args.filename, 'rb') as f:
            try:
                while True:
                    data = f.read(0x4000)
                    if len(data) != 0x4000:
                        if args.repeat:
                            print("End of file reached. Looping")
                            f.seek(0,0)
                        else:
                            break
                        if len(data) == 0:
                            data = f.read(0x4000)
                    # print(data[:10])
                    device.device.write(0x02, data)
            except KeyboardInterrupt:
                pass
        device.vendor_request_out(vendor_requests.SDIR_TX_STOP)
示例#12
0
# GND      -> GND
# VBUS     -> VCC
# SCK      -> CKI
# MOSI     -> SDI

from greatfet import GreatFET
from greatfet.protocol import vendor_requests
import bitstring
import time
import math

start_frame = bitstring.Bits('0x00000000')
end_frame = bitstring.Bits('0xffffffff')

gf = GreatFET()
gf.vendor_request_out(vendor_requests.SPI_INIT)


def led_frame(red=0, green=0, blue=0, brightness=0x1f):
    frame = bitstring.Bits(length=3, uint=0x7)
    frame += bitstring.Bits(length=5, uint=(brightness & 0x1f))
    frame += bitstring.Bits(length=8, uint=(blue & 0xff))
    frame += bitstring.Bits(length=8, uint=(green & 0xff))
    frame += bitstring.Bits(length=8, uint=(red & 0xff))
    return frame


def set2pixels(red1=0, blue1=0, green1=0, red2=0, blue2=0, green2=0):
    data = start_frame
    data += led_frame(red1, blue1, green1)
    data += led_frame(red2, blue2, green2)
import sys

import greatfet
from greatfet import GreatFET
from greatfet.protocol import vendor_requests

if __name__ == '__main__':

    device = GreatFET()
    if not device:
        print('No GreatFET devices found!')
        sys.exit()

    # Print the board's information...
    print("Found a {}!".format(device.board_name()))
    print("  Board ID: {}".format(device.board_id()))
    print("  Firmware version: {}".format(device.firmware_version()))
    print("  Part ID: {}".format(device.part_id()))
    print("  Serial number: {}".format(device.serial_number()))

    # ... and toggle it's third LED, for fun.
    device.vendor_request_out(vendor_requests.LED_TOGGLE, 3)

    # Dev note: you can still easily use this to test low-level interfaces.
    # For example, to send the ENABLE_USB1 request, use:
    #
    #   device.vendor_request_out(vendor_requests.ENABLE_USB1)
    #
    # where ENABLE_USB1 is just an integer constant.
示例#14
0
def main():
    logfile = 'log.bin'
    #    logfile = '/tmp/fifo'
    # Set up a simple argument parser.
    parser = argparse.ArgumentParser(
        description="Utility for experimenting with GreatFET's ADC")
    parser.add_argument('-s',
                        dest='serial',
                        metavar='<serialnumber>',
                        type=str,
                        help="Serial number of device, if multiple devices",
                        default=None)
    parser.add_argument('-S',
                        dest='samplerate',
                        metavar='<samplerate>',
                        type=int,
                        help="Sample rate for IR Tx",
                        default=1000000)
    parser.add_argument('-f',
                        dest='filename',
                        metavar='<filename>',
                        type=str,
                        help="File to read or write",
                        default=logfile)
    parser.add_argument('-r',
                        dest='receive',
                        action='store_true',
                        help="Write data to file")
    parser.add_argument('-R',
                        dest='repeat',
                        action='store_true',
                        help="Repeat file data (tx only)")
    parser.add_argument('-v',
                        dest='verbose',
                        action='store_true',
                        help="Increase verbosity of logging")
    args = parser.parse_args()

    log_function = log_verbose if args.verbose else log_silent

    try:
        log_function("Trying to find a GreatFET device...")
        device = GreatFET(serial_number=args.serial)
        log_function("{} found. (Serial number: {})".format(
            device.board_name(), device.serial_number()))
    except greatfet.errors.DeviceNotFoundError:
        if args.serial:
            print("No GreatFET board found matching serial '{}'.".format(
                args.serial),
                  file=sys.stderr)
        else:
            print("No GreatFET board found!", file=sys.stderr)
        sys.exit(errno.ENODEV)

    if args.receive:
        device.vendor_request_out(vendor_requests.SDIR_RX_START)
        time.sleep(1)
        with open(args.filename, 'wb') as f:
            try:
                while True:
                    d = device.device.read(0x81, 0x4000, 1000)
                    # print(d)
                    f.write(d)
            except KeyboardInterrupt:
                pass
        device.vendor_request_out(vendor_requests.SDIR_RX_STOP)

    else:
        index = args.samplerate & 0xFFFF
        value = (args.samplerate >> 16) & 0xFFFF
        device.vendor_request_out(vendor_requests.SDIR_TX_START,
                                  value=value,
                                  index=index)
        time.sleep(1)
        with open(args.filename, 'rb') as f:
            try:
                while True:
                    data = f.read(0x4000)
                    if len(data) != 0x4000:
                        if args.repeat:
                            print("End of file reached. Looping")
                            f.seek(0, 0)
                        else:
                            break
                        if len(data) == 0:
                            data = f.read(0x4000)
                    # print(data[:10])
                    device.device.write(0x02, data)
            except KeyboardInterrupt:
                pass
        device.vendor_request_out(vendor_requests.SDIR_TX_STOP)