11"""Attempt detection of current chip / CPU."""
22import sys
3+ import os
34
45AM33XX = "AM33XX"
56BCM2XXX = "BCM2XXX"
1011S805 = "S805"
1112S905 = "S905"
1213GENERIC_X86 = "GENERIC_X86"
14+ FT232H = "FT232H"
1315
1416class Chip :
1517 """Attempt detection of current chip / CPU."""
1618 def __init__ (self , detector ):
1719 self .detector = detector
1820
1921 @property
20- # pylint: disable=invalid-name
21- def id (self ):
22+ def id (self ): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
2223 """Return a unique id for the detected chip, if any."""
24+ # There are some times we want to trick the platform detection
25+ # say if a raspberry pi doesn't have the right ID, or for testing
26+ try :
27+ return os .environ ['BLINKA_FORCECHIP' ]
28+ except KeyError : # no forced chip, continue with testing!
29+ pass
30+
31+ # Special case, if we have an environment var set, we could use FT232H
32+ try :
33+ if os .environ ['BLINKA_FT232H' ]:
34+ # we can't have ftdi1 as a dependency cause its wierd
35+ # to install, sigh.
36+ import ftdi1 as ftdi # pylint: disable=import-error
37+ try :
38+ ctx = None
39+ ctx = ftdi .new () # Create a libftdi context.
40+ # Enumerate FTDI devices.
41+ count , _ = ftdi .usb_find_all (ctx , 0 , 0 )
42+ if count < 0 :
43+ raise RuntimeError ('ftdi_usb_find_all returned error %d : %s' %
44+ count , ftdi .get_error_string (self ._ctx ))
45+ if count == 0 :
46+ raise RuntimeError ('BLINKA_FT232H environment variable' + \
47+ 'set, but no FT232H device found' )
48+ finally :
49+ # Make sure to clean up list and context when done.
50+ if ctx is not None :
51+ ftdi .free (ctx )
52+ return FT232H
53+ except KeyError : # no FT232H environment var
54+ pass
55+
2356 platform = sys .platform
2457 if platform == "linux" :
2558 return self ._linux_id ()
@@ -29,6 +62,7 @@ def id(self):
2962 return SAMD21
3063 if platform == "pyboard" :
3164 return STM32
65+ # nothing found!
3266 return None
3367 # pylint: enable=invalid-name
3468
@@ -42,7 +76,7 @@ def _linux_id(self):
4276 vendor_id = self .detector .get_cpuinfo_field ("vendor_id" )
4377 if vendor_id in ("GenuineIntel" , "AuthenticAMD" ):
4478 linux_id = GENERIC_X86
45- elif hardware in ("BCM2708" , "BCM2708 " , "BCM2835" ):
79+ elif hardware in ("BCM2708" , "BCM2709 " , "BCM2835" ):
4680 linux_id = BCM2XXX
4781 elif "AM33XX" in hardware :
4882 linux_id = AM33XX
0 commit comments