#!/usr/bin/env python import hid_test def import_pins(pin_filename): pins = {} with open(pin_filename + '.csv','r') as f: for line in f.readlines(): [gpio,name] = line.strip().split(',') pins[name] = int(gpio) return pins def read_pin_states(pins): d = hid_test.ice40_flasher() # Set all pins as inputs, pull-down for [name,gpio] in pins.items(): d.gpio_set_direction(gpio,False) d.gpio_set_pulls(gpio,False,True) # One by one, set each pin as an output, read the states of all pins, then set the pin as an input again. changes = {} for [name,gpio] in pins.items(): pre = d.gpio_get_all() d.gpio_set_direction(gpio,True) d.gpio_put(gpio,True) mid = d.gpio_get_all() d.gpio_set_direction(gpio,False) post = d.gpio_get_all() if (pre != 0) or (post != 0): print('Error in pre/post condition, pin:{:} pre:{:08x} post:{:08x}'.format(name,pre,post)) change = [] for [n,g] in pins.items(): if (1<