1
1
"""Attempt detection of current chip / CPU."""
2
2
import sys
3
+ import os
3
4
4
5
AM33XX = "AM33XX"
5
6
BCM2XXX = "BCM2XXX"
10
11
S805 = "S805"
11
12
S905 = "S905"
12
13
GENERIC_X86 = "GENERIC_X86"
14
+ FT232H = "FT232H"
13
15
14
16
class Chip :
15
17
"""Attempt detection of current chip / CPU."""
16
18
def __init__ (self , detector ):
17
19
self .detector = detector
18
20
19
21
@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
22
23
"""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
+
23
56
platform = sys .platform
24
57
if platform == "linux" :
25
58
return self ._linux_id ()
@@ -29,6 +62,7 @@ def id(self):
29
62
return SAMD21
30
63
if platform == "pyboard" :
31
64
return STM32
65
+ # nothing found!
32
66
return None
33
67
# pylint: enable=invalid-name
34
68
@@ -42,7 +76,7 @@ def _linux_id(self):
42
76
vendor_id = self .detector .get_cpuinfo_field ("vendor_id" )
43
77
if vendor_id in ("GenuineIntel" , "AuthenticAMD" ):
44
78
linux_id = GENERIC_X86
45
- elif hardware in ("BCM2708" , "BCM2708 " , "BCM2835" ):
79
+ elif hardware in ("BCM2708" , "BCM2709 " , "BCM2835" ):
46
80
linux_id = BCM2XXX
47
81
elif "AM33XX" in hardware :
48
82
linux_id = AM33XX
0 commit comments