Skip to content

Commit 5fe11b6

Browse files
authored
Merge pull request #408 from makermelissa/pico2
Add detection for Pico W, 2, and 2 W versions
2 parents 85e2e8f + cf6e261 commit 5fe11b6

4 files changed

Lines changed: 41 additions & 4 deletions

File tree

adafruit_platformdetect/board.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
**Software and Dependencies:**
1818
1919
* Linux and Python 3.7 or Higher
20+
* or MicroPython
2021
2122
"""
2223

23-
import glob
24+
try:
25+
import glob
26+
except ImportError:
27+
pass
2428
import os
2529
import re
2630

@@ -101,8 +105,8 @@ def id(self) -> Optional[str]:
101105
board_id = boards.FEATHER_M0_EXPRESS
102106
elif chip_id == chips.STM32F405:
103107
board_id = boards.PYBOARD
104-
elif chip_id == chips.RP2040:
105-
board_id = boards.RASPBERRY_PI_PICO
108+
elif chip_id in (chips.RP2040, chips.RP2350):
109+
board_id = self._raspberry_pi_pico_id()
106110
elif chip_id == chips.S805:
107111
board_id = boards.ODROID_C1
108112
elif chip_id == chips.S905:
@@ -516,6 +520,20 @@ def _armbian_id(self) -> Optional[str]:
516520
board = boards.MILKV_DUO
517521
return board
518522

523+
@staticmethod
524+
def _raspberry_pi_pico_id() -> Optional[str]:
525+
"""Try to detect id of a Raspberry Pi Pico."""
526+
board_id = os.uname().machine
527+
if "Raspberry Pi Pico 2 W" in board_id:
528+
return boards.RASPBERRY_PI_PICO_2_W
529+
if "Raspberry Pi Pico 2" in board_id:
530+
return boards.RASPBERRY_PI_PICO_2
531+
if "Raspberry Pi Pico W" in board_id:
532+
return boards.RASPBERRY_PI_PICO_W
533+
if "Raspberry Pi Pico" in board_id:
534+
return boards.RASPBERRY_PI_PICO
535+
return None
536+
519537
# pylint: enable=too-many-return-statements
520538

521539
def _diet_pi_id(self) -> Optional[str]:
@@ -1228,6 +1246,11 @@ def any_particle_board(self):
12281246
"""Check whether the current board is any Particle device."""
12291247
return self.id in boards._PARTICLE_IDS
12301248

1249+
@property
1250+
def any_raspberry_pi_pico_id(self):
1251+
"""Check whether the current board is any Raspberry Pi Pico."""
1252+
return self.id in boards._RASPBERRY_PI_PICO_IDS
1253+
12311254
@property
12321255
def os_environ_board(self) -> bool:
12331256
"""Check whether the current board is an OS environment variable special case."""

adafruit_platformdetect/chip.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ def id(
194194
if platform == "pyboard":
195195
self._chip_id = chips.STM32F405
196196
return self._chip_id
197-
if platform == "rp2":
197+
if platform == "rp2" and "RP2350" in os.uname().machine:
198+
self._chip_id = chips.RP2350
199+
return self._chip_id
200+
if platform == "rp2" and "RP2040" in os.uname().machine:
198201
self._chip_id = chips.RP2040
199202
return self._chip_id
200203
# nothing found!

adafruit_platformdetect/constants/boards.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
PYBOARD = "PYBOARD"
3434
NODEMCU = "NODEMCU"
3535
RASPBERRY_PI_PICO = "RASPBERRY_PI_PICO"
36+
RASPBERRY_PI_PICO_W = "RASPBERRY_PI_PICO_W"
37+
RASPBERRY_PI_PICO_2 = "RASPBERRY_PI_PICO_2"
38+
RASPBERRY_PI_PICO_2_W = "RASPBERRY_PI_PICO_2_W"
3639
GIANT_BOARD = "GIANT_BOARD"
3740

3841
# ASUS Tinker Boards
@@ -714,6 +717,13 @@
714717
LUCKFOX_PICO_PLUS,
715718
)
716719

720+
_RASPBERRY_PI_PICO_IDS = (
721+
RASPBERRY_PI_PICO,
722+
RASPBERRY_PI_PICO_W,
723+
RASPBERRY_PI_PICO_2,
724+
RASPBERRY_PI_PICO_2_W,
725+
)
726+
717727
# Horizon
718728
_HORIZON_IDS = (RDK_X3, RDK_X5)
719729

adafruit_platformdetect/constants/chips.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
CELERON_N5105 = "CELERON_N5105"
7979
STM32F405 = "STM32F405"
8080
RP2040 = "RP2040"
81+
RP2350 = "RP2350"
8182
STM32MP157 = "STM32MP157"
8283
STM32MP157DAA1 = "STM32MP157DAA1"
8384
MT8167 = "MT8167"

0 commit comments

Comments
 (0)