Skip to content

Commit 566dbcd

Browse files
committed
Merge branch 'adafruit:master' into master
2 parents aec4ec9 + d59c788 commit 566dbcd

File tree

3 files changed

+66
-60
lines changed

3 files changed

+66
-60
lines changed

adafruit_platformdetect/chip.py

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -65,73 +65,74 @@ def id(
6565
if self._chip_id:
6666
return self._chip_id
6767

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
80107
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"
83110
)
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
92119
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"
95122
)
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
100125

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
105128
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
127135
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
135136

136137
platform = sys.platform
137138
if platform in ("linux", "linux2"):
@@ -146,6 +147,9 @@ def id(
146147
if platform == "pyboard":
147148
self._chip_id = chips.STM32F405
148149
return self._chip_id
150+
if platform == "rp2":
151+
self._chip_id = chips.RP2040
152+
return self._chip_id
149153
# nothing found!
150154
return None
151155

adafruit_platformdetect/constants/boards.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
GENERIC_LINUX_PC = "GENERIC_LINUX_PC"
2525
PYBOARD = "PYBOARD"
2626
NODEMCU = "NODEMCU"
27+
RASPBERRY_PI_PICO = "RASPBERRY_PI_PICO"
2728
GIANT_BOARD = "GIANT_BOARD"
2829

2930
# ASUS Tinker Boards

adafruit_platformdetect/constants/chips.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
RK3288 = "RK3288"
4242
PENTIUM_N3710 = "PENTIUM_N3710" # SOC Braswell core
4343
STM32F405 = "STM32F405"
44+
RP2040 = "RP2040"
4445
STM32MP157 = "STM32MP157"
4546
MT8167 = "MT8167"
4647
ATOM_X5_Z8350 = "X5-Z8350"

0 commit comments

Comments
 (0)