diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index a391abe..bf85c55 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -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 @@ -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: @@ -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]: @@ -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.""" diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index e073d45..db74a8d 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -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! diff --git a/adafruit_platformdetect/constants/boards.py b/adafruit_platformdetect/constants/boards.py index cc8f945..c1b6403 100644 --- a/adafruit_platformdetect/constants/boards.py +++ b/adafruit_platformdetect/constants/boards.py @@ -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 @@ -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) diff --git a/adafruit_platformdetect/constants/chips.py b/adafruit_platformdetect/constants/chips.py index a2bbb21..c0f9ee4 100644 --- a/adafruit_platformdetect/constants/chips.py +++ b/adafruit_platformdetect/constants/chips.py @@ -78,6 +78,7 @@ CELERON_N5105 = "CELERON_N5105" STM32F405 = "STM32F405" RP2040 = "RP2040" +RP2350 = "RP2350" STM32MP157 = "STM32MP157" STM32MP157DAA1 = "STM32MP157DAA1" MT8167 = "MT8167"