def test_ft232h(self): with open('pyftdi/tests/resources/ft232h_x2.yaml', 'rb') as yfp: self.loader.load(yfp) eeprom = FtdiEeprom() eeprom.open('ftdi://::FT1ABC1/1', ignore=True) eeprom.erase() eeprom.initialize() # default EEPROM config does not have any CBUS configured as GPIO self.assertEqual(eeprom.cbus_pins, []) self.assertEqual(eeprom.cbus_mask, 0) eeprom.set_property('cbus_func_6', 'gpio') eeprom.set_property('cbus_func_9', 'gpio') # not yet committed self.assertEqual(eeprom.cbus_pins, []) self.assertEqual(eeprom.cbus_mask, 0) eeprom.sync() # committed self.assertEqual(eeprom.cbus_pins, [6, 9]) self.assertEqual(eeprom.cbus_mask, 0xA) eeprom.set_property('cbus_func_5', 'gpio') eeprom.set_property('cbus_func_8', 'gpio') eeprom.sync() self.assertEqual(eeprom.cbus_pins, [5, 6, 8, 9]) self.assertEqual(eeprom.cbus_mask, 0xF) # pin1 and pin3 is not configurable as GPIO self.assertRaises(ValueError, eeprom.set_property, 'cbus_func_1', 'gpio') self.assertRaises(ValueError, eeprom.set_property, 'cbus_func_3', 'gpio') eeprom.close()
def test_ft230x(self): with open('pyftdi/tests/resources/ft230x.yaml', 'rb') as yfp: self.loader.load(yfp) eeprom = FtdiEeprom() eeprom.open('ftdi:///1') # default EEPROM config does not have any CBUS configured as GPIO self.assertEqual(eeprom.cbus_pins, []) self.assertEqual(eeprom.cbus_mask, 0) # enable CBUS1 and CBUS3 as GPIO eeprom.set_property('cbus_func_1', 'gpio') eeprom.set_property('cbus_func_3', 'gpio') eeprom.sync() self.assertEqual(eeprom.cbus_pins, [1, 3]) self.assertEqual(eeprom.cbus_mask, 0xA) # enable CBUS0 and CBUS2 as GPIO eeprom.set_property('cbus_func_0', 'gpio') eeprom.set_property('cbus_func_2', 'gpio') # not yet committed self.assertEqual(eeprom.cbus_pins, [1, 3]) self.assertEqual(eeprom.cbus_mask, 0xA) eeprom.sync() # committed self.assertEqual(eeprom.cbus_pins, [0, 1, 2, 3]) self.assertEqual(eeprom.cbus_mask, 0xF) # invalid CBUS pin self.assertRaises(ValueError, eeprom.set_property, 'cbus_func_4', 'gpio') # invalid pin function self.assertRaises(ValueError, eeprom.set_property, 'cbus_func_0', 'gpio_') # invalid pin self.assertRaises(ValueError, eeprom.set_property, 'cbus_func', 'gpio') # valid alternative mode eeprom.set_property('cbus_func_0', 'txled') eeprom.set_property('cbus_func_1', 'rxled') eeprom.sync() self.assertEqual(eeprom.cbus_pins, [2, 3]) self.assertEqual(eeprom.cbus_mask, 0xC) eeprom.close()