def __init__(self): if ft4222.createDeviceInfoList() < 2: raise Exception("No connected zookeeper found!") self.dev_a = ft4222.openByDescription("FT4222 A") self.dev_b = ft4222.openByDescription("FT4222 B") if DEBUG: for i in range(ft4222.createDeviceInfoList()): print(f"Device {i}: {ft4222.getDeviceInfoDetail(i, False)}") # Setup GPIO self.dev_b.gpio_Init(gpio2=ft4222.Dir.OUTPUT, gpio3=ft4222.Dir.OUTPUT) self.dev_b.setSuspendOut(False) self.dev_b.setWakeUpInterrut(False) # Setup I2C self.dev_a.i2cMaster_Init(kbps=400) self._initialize_ina()
# _____ _____ _____ # |_ | __| __ | # |_| | |__ | -| # |_|_|_|_____|__|__| # MSR Electronics GmbH # import sys import ft4222 nbDev = ft4222.createDeviceInfoList() print("nb of fdti devices: {}".format(nbDev)) ftDetails = [] if nbDev <= 0: print("no devices found...") sys.exit(0) print("devices:") for i in range(nbDev): detail = ft4222.getDeviceInfoDetail(i, False) print(" - {}".format(detail)) ftDetails.append(detail) dev = ft4222.openByDescription('FT4222 A') print(dev) dev.i2cMaster_Init(100)
def main(): """ main function """ parser = argparse.ArgumentParser( description="Test PNG images with cifar-10 based example.", formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "-p", "--path", required=True, help="Relative or absolute path to the directory of test images.") parser.add_argument("-d", "--device", required=True, help="Serial device connected to MAX78000.\n" "Linux: /dev/ttyUSB0\n" "Windows: COM1") args = parser.parse_args() abs_path = os.path.realpath(args.path) if not os.path.exists(abs_path): print("ERROR Directory does not exists: {0}".format(abs_path)) sys.exit() print("\nTesting images from: {0}\n".format(abs_path)) # Open device with default description spim = ft4222.openByDescription('FT4222 A') spim.spiMaster_Init(SPIM.Mode.SINGLE, SPIM.Clock.DIV_8, SPI.Cpol.IDLE_LOW, SPI.Cpha.CLK_LEADING, SPIM.SlaveSelect.SS0) # Serial port must be open before end of SPI transaction to avoid missing characters sport = serial.Serial(args.device, SERIAL_BAUD, timeout=SERIAL_TOUT) for filename in sorted(os.listdir(abs_path)): # Ignore all other files if not filename.endswith('.png'): continue with Image.open(os.path.join(abs_path, filename)) as img: if not img.mode == IMG_MODE: print_result( filename, "Skipped, image mode must be {0}\n".format(IMG_MODE)) continue if not img.size == (IMG_WIDTH, IMG_HEIGHT): print_result( filename, "Skipped, image size must be {0}x{1}\n".format( IMG_WIDTH, IMG_HEIGHT)) continue image_data = img.getdata() # Convert list of tuples to flat list image_data = [ color_value for pixel in image_data for color_value in pixel ] # Send image to MAX78000 SPI slave _ = spim.spiMaster_SingleWrite(bytes(image_data), True) # Wait for the test result # read() blocks until SERIAL_TOUT result = [] while 1: char = sport.read(1) if char == b'': result = "Timeout" break result.append(char.decode('utf-8')) if char == b'\n': result = "".join(result) break print_result(filename, result) sport.close() spim.close()