diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index f80f5232..d528873d 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -487,6 +487,11 @@ def any_embedded_linux(self): self.any_coral_board or self.any_odroid_40_pin or self.any_96boards or \ self.any_sifive_board + @property + def ftdi_ft232h(self): + """Check whether the current board is an FTDI FT232H.""" + return self.id == FTDI_FT232H + def __getattr__(self, attr): """ Detect whether the given attribute is the currently-detected board. See list diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index b3adc544..2ef85695 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -39,25 +39,13 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s # Special case, if we have an environment var set, we could use FT232H try: if os.environ['BLINKA_FT232H']: - # we can't have ftdi1 as a dependency cause its wierd - # to install, sigh. - import ftdi1 as ftdi # pylint: disable=import-error - try: - ctx = None - ctx = ftdi.new() # Create a libftdi context. - # Enumerate FTDI devices. - count, _ = ftdi.usb_find_all(ctx, 0, 0) - if count < 0: - raise RuntimeError('ftdi_usb_find_all returned error %d : %s' % - count, ftdi.get_error_string(self._ctx)) - if count == 0: - raise RuntimeError('BLINKA_FT232H environment variable' + \ - 'set, but no FT232H device found') - finally: - # Make sure to clean up list and context when done. - if ctx is not None: - ftdi.free(ctx) - return FT232H + from pyftdi.usbtools import UsbTools # pylint: disable=import-error + # look for it based on PID/VID + count = len(UsbTools.find_all([(0x0403, 0x6014)])) + if count == 0: + raise RuntimeError('BLINKA_FT232H environment variable' + \ + 'set, but no FT232H device found') + return FT232H except KeyError: # no FT232H environment var pass