@@ -65,73 +65,74 @@ def id(
65
65
if self ._chip_id :
66
66
return self ._chip_id
67
67
68
- try :
69
- return os .environ ["BLINKA_FORCECHIP" ]
70
- except KeyError : # no forced chip, continue with testing!
71
- pass
72
-
73
- # Special cases controlled by environment var
74
- if os .environ .get ("BLINKA_FT232H" ):
75
- from pyftdi .usbtools import UsbTools
76
-
77
- # look for it based on PID/VID
78
- count = len (UsbTools .find_all ([(0x0403 , 0x6014 )]))
79
- if count == 0 :
68
+ if getattr (os , "environ" , None ) is not None :
69
+ try :
70
+ return os .environ ["BLINKA_FORCECHIP" ]
71
+ except KeyError : # no forced chip, continue with testing!
72
+ pass
73
+
74
+ # Special cases controlled by environment var
75
+ if os .environ .get ("BLINKA_FT232H" ):
76
+ from pyftdi .usbtools import UsbTools
77
+
78
+ # look for it based on PID/VID
79
+ count = len (UsbTools .find_all ([(0x0403 , 0x6014 )]))
80
+ if count == 0 :
81
+ raise RuntimeError (
82
+ "BLINKA_FT232H environment variable "
83
+ + "set, but no FT232H device found"
84
+ )
85
+ self ._chip_id = chips .FT232H
86
+ return self ._chip_id
87
+ if os .environ .get ("BLINKA_FT2232H" ):
88
+ from pyftdi .usbtools import UsbTools
89
+
90
+ # look for it based on PID/VID
91
+ count = len (UsbTools .find_all ([(0x0403 , 0x6010 )]))
92
+ if count == 0 :
93
+ raise RuntimeError (
94
+ "BLINKA_FT2232H environment variable "
95
+ + "set, but no FT2232H device found"
96
+ )
97
+ self ._chip_id = chips .FT2232H
98
+ return self ._chip_id
99
+ if os .environ .get ("BLINKA_MCP2221" ):
100
+ import hid
101
+
102
+ # look for it based on PID/VID
103
+ for dev in hid .enumerate ():
104
+ if dev ["vendor_id" ] == 0x04D8 and dev ["product_id" ] == 0x00DD :
105
+ self ._chip_id = chips .MCP2221
106
+ return self ._chip_id
80
107
raise RuntimeError (
81
- "BLINKA_FT232H environment variable "
82
- + "set, but no FT232H device found"
108
+ "BLINKA_MCP2221 environment variable "
109
+ + "set, but no MCP2221 device found"
83
110
)
84
- self . _chip_id = chips . FT232H
85
- return self . _chip_id
86
- if os . environ . get ( "BLINKA_FT2232H" ):
87
- from pyftdi . usbtools import UsbTools
88
-
89
- # look for it based on PID/VID
90
- count = len ( UsbTools . find_all ([( 0x0403 , 0x6010 )]))
91
- if count == 0 :
111
+ if os . environ . get ( "BLINKA_PICO_U2IF" ):
112
+ import hid
113
+
114
+ # look for it based on PID/VID
115
+ for dev in hid . enumerate ():
116
+ if dev [ "vendor_id" ] == 0xCAFE and dev [ "product_id" ] == 0x4005 :
117
+ self . _chip_id = chips . PICO_U2IF
118
+ return self . _chip_id
92
119
raise RuntimeError (
93
- "BLINKA_FT2232H environment variable "
94
- + "set, but no FT2232H device found"
120
+ "BLINKA_PICO_U2IF environment variable "
121
+ + "set, but no Pico device found"
95
122
)
96
- self ._chip_id = chips .FT2232H
97
- return self ._chip_id
98
- if os .environ .get ("BLINKA_MCP2221" ):
99
- import hid
123
+ if os .environ .get ("BLINKA_GREATFET" ):
124
+ import usb
100
125
101
- # look for it based on PID/VID
102
- for dev in hid .enumerate ():
103
- if dev ["vendor_id" ] == 0x04D8 and dev ["product_id" ] == 0x00DD :
104
- self ._chip_id = chips .MCP2221
126
+ if usb .core .find (idVendor = 0x1D50 , idProduct = 0x60E6 ) is not None :
127
+ self ._chip_id = chips .LPC4330
105
128
return self ._chip_id
106
- raise RuntimeError (
107
- "BLINKA_MCP2221 environment variable "
108
- + "set, but no MCP2221 device found"
109
- )
110
- if os .environ .get ("BLINKA_PICO_U2IF" ):
111
- import hid
112
-
113
- # look for it based on PID/VID
114
- for dev in hid .enumerate ():
115
- if dev ["vendor_id" ] == 0xCAFE and dev ["product_id" ] == 0x4005 :
116
- self ._chip_id = chips .PICO_U2IF
117
- return self ._chip_id
118
- raise RuntimeError (
119
- "BLINKA_PICO_U2IF environment variable "
120
- + "set, but no Pico device found"
121
- )
122
- if os .environ .get ("BLINKA_GREATFET" ):
123
- import usb
124
-
125
- if usb .core .find (idVendor = 0x1D50 , idProduct = 0x60E6 ) is not None :
126
- self ._chip_id = chips .LPC4330
129
+ raise RuntimeError (
130
+ "BLINKA_GREATFET environment variable "
131
+ + "set, but no GreatFET device found"
132
+ )
133
+ if os .environ .get ("BLINKA_NOVA" ):
134
+ self ._chip_id = chips .BINHO
127
135
return self ._chip_id
128
- raise RuntimeError (
129
- "BLINKA_GREATFET environment variable "
130
- + "set, but no GreatFET device found"
131
- )
132
- if os .environ .get ("BLINKA_NOVA" ):
133
- self ._chip_id = chips .BINHO
134
- return self ._chip_id
135
136
136
137
platform = sys .platform
137
138
if platform in ("linux" , "linux2" ):
@@ -146,6 +147,9 @@ def id(
146
147
if platform == "pyboard" :
147
148
self ._chip_id = chips .STM32F405
148
149
return self ._chip_id
150
+ if platform == "rp2" :
151
+ self ._chip_id = chips .RP2040
152
+ return self ._chip_id
149
153
# nothing found!
150
154
return None
151
155
0 commit comments