Skip to content

Commit ac83c61

Browse files
authored
Merge pull request #39 from caternuson/pyftdi
Change to pyftdi
2 parents 8cbc616 + a88a915 commit ac83c61

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

adafruit_platformdetect/board.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ def any_embedded_linux(self):
487487
self.any_coral_board or self.any_odroid_40_pin or self.any_96boards or \
488488
self.any_sifive_board
489489

490+
@property
491+
def ftdi_ft232h(self):
492+
"""Check whether the current board is an FTDI FT232H."""
493+
return self.id == FTDI_FT232H
494+
490495
def __getattr__(self, attr):
491496
"""
492497
Detect whether the given attribute is the currently-detected board. See list

adafruit_platformdetect/chip.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,13 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s
3939
# Special case, if we have an environment var set, we could use FT232H
4040
try:
4141
if os.environ['BLINKA_FT232H']:
42-
# we can't have ftdi1 as a dependency cause its wierd
43-
# to install, sigh.
44-
import ftdi1 as ftdi # pylint: disable=import-error
45-
try:
46-
ctx = None
47-
ctx = ftdi.new() # Create a libftdi context.
48-
# Enumerate FTDI devices.
49-
count, _ = ftdi.usb_find_all(ctx, 0, 0)
50-
if count < 0:
51-
raise RuntimeError('ftdi_usb_find_all returned error %d : %s' %
52-
count, ftdi.get_error_string(self._ctx))
53-
if count == 0:
54-
raise RuntimeError('BLINKA_FT232H environment variable' + \
55-
'set, but no FT232H device found')
56-
finally:
57-
# Make sure to clean up list and context when done.
58-
if ctx is not None:
59-
ftdi.free(ctx)
60-
return FT232H
42+
from pyftdi.usbtools import UsbTools # pylint: disable=import-error
43+
# look for it based on PID/VID
44+
count = len(UsbTools.find_all([(0x0403, 0x6014)]))
45+
if count == 0:
46+
raise RuntimeError('BLINKA_FT232H environment variable' + \
47+
'set, but no FT232H device found')
48+
return FT232H
6149
except KeyError: # no FT232H environment var
6250
pass
6351

0 commit comments

Comments
 (0)