Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions adafruit_platformdetect/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
**Software and Dependencies:**

* Linux and Python 3.7 or Higher
* or MicroPython

"""

import glob
try:
import glob
except ImportError:
pass
import os
import re

Expand Down Expand Up @@ -101,8 +105,8 @@ def id(self) -> Optional[str]:
board_id = boards.FEATHER_M0_EXPRESS
elif chip_id == chips.STM32F405:
board_id = boards.PYBOARD
elif chip_id == chips.RP2040:
board_id = boards.RASPBERRY_PI_PICO
elif chip_id in (chips.RP2040, chips.RP2350):
board_id = self._raspberry_pi_pico_id()
elif chip_id == chips.S805:
board_id = boards.ODROID_C1
elif chip_id == chips.S905:
Expand Down Expand Up @@ -516,6 +520,20 @@ def _armbian_id(self) -> Optional[str]:
board = boards.MILKV_DUO
return board

@staticmethod
def _raspberry_pi_pico_id() -> Optional[str]:
"""Try to detect id of a Raspberry Pi Pico."""
board_id = os.uname().machine
if "Raspberry Pi Pico 2 W" in board_id:
return boards.RASPBERRY_PI_PICO_2_W
if "Raspberry Pi Pico 2" in board_id:
return boards.RASPBERRY_PI_PICO_2
if "Raspberry Pi Pico W" in board_id:
return boards.RASPBERRY_PI_PICO_W
if "Raspberry Pi Pico" in board_id:
return boards.RASPBERRY_PI_PICO
return None

# pylint: enable=too-many-return-statements

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

@property
def any_raspberry_pi_pico_id(self):
"""Check whether the current board is any Raspberry Pi Pico."""
return self.id in boards._RASPBERRY_PI_PICO_IDS

@property
def os_environ_board(self) -> bool:
"""Check whether the current board is an OS environment variable special case."""
Expand Down
5 changes: 4 additions & 1 deletion adafruit_platformdetect/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ def id(
if platform == "pyboard":
self._chip_id = chips.STM32F405
return self._chip_id
if platform == "rp2":
if platform == "rp2" and "RP2350" in os.uname().machine:
self._chip_id = chips.RP2350
return self._chip_id
if platform == "rp2" and "RP2040" in os.uname().machine:
self._chip_id = chips.RP2040
return self._chip_id
# nothing found!
Expand Down
10 changes: 10 additions & 0 deletions adafruit_platformdetect/constants/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
PYBOARD = "PYBOARD"
NODEMCU = "NODEMCU"
RASPBERRY_PI_PICO = "RASPBERRY_PI_PICO"
RASPBERRY_PI_PICO_W = "RASPBERRY_PI_PICO_W"
RASPBERRY_PI_PICO_2 = "RASPBERRY_PI_PICO_2"
RASPBERRY_PI_PICO_2_W = "RASPBERRY_PI_PICO_2_W"
GIANT_BOARD = "GIANT_BOARD"

# ASUS Tinker Boards
Expand Down Expand Up @@ -714,6 +717,13 @@
LUCKFOX_PICO_PLUS,
)

_RASPBERRY_PI_PICO_IDS = (
RASPBERRY_PI_PICO,
RASPBERRY_PI_PICO_W,
RASPBERRY_PI_PICO_2,
RASPBERRY_PI_PICO_2_W,
)

# Horizon
_HORIZON_IDS = (RDK_X3, RDK_X5)

Expand Down
1 change: 1 addition & 0 deletions adafruit_platformdetect/constants/chips.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
CELERON_N5105 = "CELERON_N5105"
STM32F405 = "STM32F405"
RP2040 = "RP2040"
RP2350 = "RP2350"
STM32MP157 = "STM32MP157"
STM32MP157DAA1 = "STM32MP157DAA1"
MT8167 = "MT8167"
Expand Down
Loading