Skip to content

Commit 2292125

Browse files
authored
Merge pull request #41 from caternuson/mcp2221
Add MCP2221
2 parents ac83c61 + e000760 commit 2292125

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

adafruit_platformdetect/board.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@
6161
ODROID_C2 = "ODROID_C2"
6262
ODROID_N2 = "ODROID_N2"
6363

64-
FTDI_FT232H = "FT232H"
64+
FTDI_FT232H = "FTDI_FT232H"
6565
DRAGONBOARD_410C = "DRAGONBOARD_410C"
6666

6767
SIFIVE_UNLEASHED = "SIFIVE_UNLEASHED"
6868

69+
MICROCHIP_MCP2221 = "MICROCHIP_MCP2221"
70+
6971
# pylint: enable=bad-whitespace
7072

7173
#OrangePI
@@ -333,6 +335,8 @@ def id(self):
333335
board_id = self._tegra_id()
334336
elif chip_id == ap_chip.HFU540:
335337
board_id = self._sifive_id()
338+
elif chip_id == ap_chip.MCP2221:
339+
board_id = MICROCHIP_MCP2221
336340
return board_id
337341
# pylint: enable=invalid-name
338342

@@ -492,6 +496,11 @@ def ftdi_ft232h(self):
492496
"""Check whether the current board is an FTDI FT232H."""
493497
return self.id == FTDI_FT232H
494498

499+
@property
500+
def microchip_mcp2221(self):
501+
"""Check whether the current board is a Microchip MCP2221."""
502+
return self.id == MICROCHIP_MCP2221
503+
495504
def __getattr__(self, attr):
496505
"""
497506
Detect whether the given attribute is the currently-detected board. See list

adafruit_platformdetect/chip.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
GENERIC_X86 = "GENERIC_X86"
2121
FT232H = "FT232H"
2222
HFU540 = "HFU540"
23+
MCP2221 = "MCP2221"
2324

2425
class Chip:
2526
"""Attempt detection of current chip / CPU."""
@@ -36,18 +37,23 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s
3637
except KeyError: # no forced chip, continue with testing!
3738
pass
3839

39-
# Special case, if we have an environment var set, we could use FT232H
40-
try:
41-
if os.environ['BLINKA_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
49-
except KeyError: # no FT232H environment var
50-
pass
40+
# Special cases controlled by environment var
41+
if os.environ.get('BLINKA_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
49+
if os.environ.get('BLINKA_MCP2221'):
50+
import hid # pylint: disable=import-error
51+
# look for it based on PID/VID
52+
for dev in hid.enumerate():
53+
if dev['vendor_id'] == 0x04D8 and dev['product_id'] == 0x00DD:
54+
return MCP2221
55+
raise RuntimeError('BLINKA_MCP2221 environment variable ' + \
56+
'set, but no MCP2221 device found')
5157

5258
platform = sys.platform
5359
if platform == "linux" or platform == "linux2":

bin/detect.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
print("Is this a SiFive Unleashed? ", detector.board.SIFIVE_UNLEASHED)
2020
print("Is this an embedded Linux system?", detector.board.any_embedded_linux)
2121
print("Is this a generic Linux PC?", detector.board.GENERIC_LINUX_PC)
22+
print("Is this an OS environment variable special case?", detector.board.FTDI_FT232H |
23+
detector.board.MICROCHIP_MCP2221 )
2224

2325
if detector.board.any_raspberry_pi:
2426
print("Raspberry Pi detected.")

0 commit comments

Comments
 (0)