diff --git a/adafruit_platformdetect/__init__.py b/adafruit_platformdetect/__init__.py index bdd112da..3cac0113 100644 --- a/adafruit_platformdetect/__init__.py +++ b/adafruit_platformdetect/__init__.py @@ -22,12 +22,12 @@ """ Attempt to detect the current platform. """ -import sys -import platform import re + from adafruit_platformdetect.board import Board from adafruit_platformdetect.chip import Chip + # Various methods here may retain state in future, so tell pylint not to worry # that they don't use self right now: # pylint: disable=no-self-use diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index 7bc8b0df..06e274a4 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -2,330 +2,18 @@ import os import re -import adafruit_platformdetect.chip as ap_chip - # Allow for aligned constant definitions: # pylint: disable=bad-whitespace -BEAGLEBONE = 'BEAGLEBONE' -BEAGLEBONE_BLACK = 'BEAGLEBONE_BLACK' -BEAGLEBONE_BLUE = 'BEAGLEBONE_BLUE' -BEAGLEBONE_BLACK_WIRELESS = 'BEAGLEBONE_BLACK_WIRELESS' -BEAGLEBONE_POCKETBEAGLE = 'BEAGLEBONE_POCKETBEAGLE' -BEAGLEBONE_GREEN = 'BEAGLEBONE_GREEN' -BEAGLEBONE_GREEN_WIRELESS = 'BEAGLEBONE_GREEN_WIRELESS' -BEAGLEBONE_BLACK_INDUSTRIAL = 'BEAGLEBONE_BLACK_INDUSTRIAL' -BEAGLEBONE_ENHANCED = 'BEAGLEBONE_ENHANCED' -BEAGLEBONE_USOMIQ = 'BEAGLEBONE_USOMIQ' -BEAGLEBONE_AIR = 'BEAGLEBONE_AIR' -BEAGLEBONE_POCKETBONE = 'BEAGLEBONE_POCKETBONE' -BEAGLELOGIC_STANDALONE = 'BEAGLELOGIC_STANDALONE' -OSD3358_DEV_BOARD = 'OSD3358_DEV_BOARD' -OSD3358_SM_RED = 'OSD3358_SM_RED' - -FEATHER_HUZZAH = "FEATHER_HUZZAH" -FEATHER_M0_EXPRESS = "FEATHER_M0_EXPRESS" -GENERIC_LINUX_PC = "GENERIC_LINUX_PC" -PYBOARD = "PYBOARD" -NODEMCU = "NODEMCU" -GIANT_BOARD = "GIANT_BOARD" - -# Orange Pi boards -ORANGE_PI_PC = "ORANGE_PI_PC" -ORANGE_PI_R1 = "ORANGE_PI_R1" -ORANGE_PI_ZERO = "ORANGE_PI_ZERO" -ORANGE_PI_ONE = "ORANGE_PI_ONE" -ORANGE_PI_LITE = "ORANGE_PI_LITE" -ORANGE_PI_PC_PLUS = "ORANGE_PI_PC_PLUS" -ORANGE_PI_PLUS_2E = "ORANGE_PI_PLUS_2E" - -# NVIDIA Jetson boards -JETSON_TX1 = 'JETSON_TX1' -JETSON_TX2 = 'JETSON_TX2' -JETSON_XAVIER = 'JETSON_XAVIER' -JETSON_NANO = 'JETSON_NANO' - -# Google Coral dev board -CORAL_EDGE_TPU_DEV = "CORAL_EDGE_TPU_DEV" - -# Various Raspberry Pi models -RASPBERRY_PI_B_REV1 = "RASPBERRY_PI_B_REV1" -RASPBERRY_PI_B_REV2 = "RASPBERRY_PI_B_REV2" -RASPBERRY_PI_B_PLUS = "RASPBERRY_PI_B_PLUS" -RASPBERRY_PI_A = "RASPBERRY_PI_A" -RASPBERRY_PI_A_PLUS = "RASPBERRY_PI_A_PLUS" -RASPBERRY_PI_CM1 = "RASPBERRY_PI_CM1" -RASPBERRY_PI_ZERO = "RASPBERRY_PI_ZERO" -RASPBERRY_PI_ZERO_W = "RASPBERRY_PI_ZERO_W" -RASPBERRY_PI_2B = "RASPBERRY_PI_2B" -RASPBERRY_PI_3B = "RASPBERRY_PI_3B" -RASPBERRY_PI_3B_PLUS = "RASPBERRY_PI_3B_PLUS" -RASPBERRY_PI_CM3 = "RASPBERRY_PI_CM3" -RASPBERRY_PI_3A_PLUS = "RASPBERRY_PI_3A_PLUS" -RASPBERRY_PI_CM3_PLUS = "RASPBERRY_PI_CM3_PLUS" -RASPBERRY_PI_4B = "RASPBERRY_PI_4B" - -ODROID_C1 = "ODROID_C1" -ODROID_C1_PLUS = "ODROID_C1_PLUS" -ODROID_C2 = "ODROID_C2" -ODROID_N2 = "ODROID_N2" - -FTDI_FT232H = "FTDI_FT232H" -DRAGONBOARD_410C = "DRAGONBOARD_410C" - -SIFIVE_UNLEASHED = "SIFIVE_UNLEASHED" - -MICROCHIP_MCP2221 = "MICROCHIP_MCP2221" - -BINHO_NOVA = "BINHO_NOVA" - -ONION_OMEGA = "ONION_OMEGA" -ONION_OMEGA2 = "ONION_OMEGA2" - -PINE64 = "PINE64" -PINEBOOK = "PINEBOOK" -PINEPHONE = "PINEPHONE" - -# pylint: enable=bad-whitespace - -#OrangePI -_ORANGE_PI_IDS = ( - ORANGE_PI_PC, - ORANGE_PI_R1, - ORANGE_PI_ZERO, - ORANGE_PI_ONE, - ORANGE_PI_LITE, - ORANGE_PI_PC_PLUS, - ORANGE_PI_PLUS_2E, -) - -_CORAL_IDS = ( - CORAL_EDGE_TPU_DEV, -) - -_JETSON_IDS = ( - JETSON_TX1, - JETSON_TX2, - JETSON_XAVIER, - JETSON_NANO -) - -_RASPBERRY_PI_40_PIN_IDS = ( - RASPBERRY_PI_B_PLUS, - RASPBERRY_PI_A_PLUS, - RASPBERRY_PI_ZERO, - RASPBERRY_PI_ZERO_W, - RASPBERRY_PI_2B, - RASPBERRY_PI_3B, - RASPBERRY_PI_3B_PLUS, - RASPBERRY_PI_3A_PLUS, - RASPBERRY_PI_4B -) - -_RASPBERRY_PI_CM_IDS = ( - RASPBERRY_PI_CM1, - RASPBERRY_PI_CM3, - RASPBERRY_PI_CM3_PLUS -) - -_ODROID_40_PIN_IDS = ( - ODROID_C1, - ODROID_C1_PLUS, - ODROID_C2, - ODROID_N2 -) - -_BEAGLEBONE_IDS = ( - BEAGLEBONE, - BEAGLEBONE_BLACK, - BEAGLEBONE_BLUE, - BEAGLEBONE_BLACK_WIRELESS, - BEAGLEBONE_POCKETBEAGLE, - BEAGLEBONE_GREEN, - BEAGLEBONE_GREEN_WIRELESS, - BEAGLEBONE_BLACK_INDUSTRIAL, - BEAGLEBONE_ENHANCED, - BEAGLEBONE_USOMIQ, - BEAGLEBONE_AIR, - BEAGLEBONE_POCKETBONE, - BEAGLELOGIC_STANDALONE, - OSD3358_DEV_BOARD, - OSD3358_SM_RED, -) - -_LINARO_96BOARDS_IDS = ( - DRAGONBOARD_410C, -) - - -_SIFIVE_IDS = ( - SIFIVE_UNLEASHED, -) - -# BeagleBone eeprom board ids from: -# https://github.com/beagleboard/image-builder -# Thanks to zmatt on freenode #beagle for pointers. -_BEAGLEBONE_BOARD_IDS = { - # Original bone/white: - BEAGLEBONE: ( - ('A4', 'A335BONE00A4'), - ('A5', 'A335BONE00A5'), - ('A6', 'A335BONE00A6'), - ('A6A', 'A335BONE0A6A'), - ('A6B', 'A335BONE0A6B'), - ('B', 'A335BONE000B'), - ), - BEAGLEBONE_BLACK: ( - ('A5', 'A335BNLT00A5'), - ('A5A', 'A335BNLT0A5A'), - ('A5B', 'A335BNLT0A5B'), - ('A5C', 'A335BNLT0A5C'), - ('A6', 'A335BNLT00A6'), - ('C', 'A335BNLT000C'), - ('C', 'A335BNLT00C0'), - ), - BEAGLEBONE_BLUE: ( - ('A2', 'A335BNLTBLA2'), - ), - BEAGLEBONE_BLACK_WIRELESS: ( - ('A5', 'A335BNLTBWA5'), - ), - BEAGLEBONE_POCKETBEAGLE: ( - ('A2', 'A335PBGL00A2'), - ), - BEAGLEBONE_GREEN: ( - ('1A', 'A335BNLT....'), - ('UNKNOWN', 'A335BNLTBBG1'), - ), - BEAGLEBONE_GREEN_WIRELESS: ( - ('W1A', 'A335BNLTGW1A'), - ), - BEAGLEBONE_BLACK_INDUSTRIAL: ( - ('A0', 'A335BNLTAIA0'), # Arrow - ('A0', 'A335BNLTEIA0'), # Element14 - ), - BEAGLEBONE_ENHANCED: ( - ('A', 'A335BNLTSE0A'), - ), - BEAGLEBONE_USOMIQ: ( - ('6', 'A335BNLTME06'), - ), - BEAGLEBONE_AIR: ( - ('A0', 'A335BNLTNAD0'), - ), - BEAGLEBONE_POCKETBONE: ( - ('0', 'A335BNLTBP00'), - ), - OSD3358_DEV_BOARD: ( - ('0.1', 'A335BNLTGH01'), - ), - OSD3358_SM_RED: ( - ('0', 'A335BNLTOS00'), - ), - BEAGLELOGIC_STANDALONE: ( - ('A', 'A335BLGC000A'), - ) -} - -# Pi revision codes from: -# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md - -# Each tuple here contains both the base codes, and the versions that indicate -# the Pi is overvolted / overclocked - for 4-digit codes, this will be prefixed -# with 1000, and for 6-digit codes it'll be prefixed with 1. These are placed -# on separate lines. - -_PI_REV_CODES = { - RASPBERRY_PI_B_REV1: ( - # Regular codes: - '0002', '0003', - - # Overvolted/clocked versions: - '1000002', '1000003', - ), - RASPBERRY_PI_B_REV2: ( - '0005', '0006', '000d', '000e', '000f', - '1000005', '1000006', '100000d', '100000e', '100000f', - ), - RASPBERRY_PI_B_PLUS: ( - '0010', '0013', '900032', - '1000010', '1000013', '1900032', - ), - RASPBERRY_PI_A: ( - '0007', '0008', '0009', - '1000007', '1000008', '1000009', - ), - RASPBERRY_PI_A_PLUS: ( - '0012', '0015', '900021', - '1000012', '1000015', '1900021', - ), - RASPBERRY_PI_CM1: ( - '0011', '0014', - '10000011', '10000014', - ), - RASPBERRY_PI_ZERO: ( - '900092', '920092', '900093', '920093', - '1900092', '1920092', '1900093', '1920093', # warranty bit 24 - '2900092', '2920092', '2900093', '2920093', # warranty bit 25 - ), - RASPBERRY_PI_ZERO_W: ( - '9000c1', - '19000c1', '29000c1', # warranty bits - ), - RASPBERRY_PI_2B: ( - 'a01040', 'a01041', 'a21041', 'a22042', - '1a01040', '1a01041', '1a21041', '1a22042', # warranty bit 24 - '2a01040', '2a01041', '2a21041', '2a22042', # warranty bit 25 - ), - RASPBERRY_PI_3B: ( - 'a02082', 'a22082', 'a32082', 'a52082', - '1a02082', '1a22082', '1a32082', '1a52082', # warranty bit 24 - '2a02082', '2a22082', '2a32082', '2a52082', # warranty bit 25 - ), - RASPBERRY_PI_3B_PLUS: ( - 'a020d3', - '1a020d3', '2a020d3', # warranty bits - ), - RASPBERRY_PI_CM3: ( - 'a020a0', 'a220a0', - '1a020a0', '2a020a0', # warranty bits - '1a220a0', '2a220a0', - ), - RASPBERRY_PI_3A_PLUS: ( - '9020e0', - '19020e0', '29020e0', # warranty bits - ), - RASPBERRY_PI_CM3_PLUS: ( - 'a02100', - '1a02100', '2a02100', # warranty bits - ), - RASPBERRY_PI_4B: ( - 'a03111', 'b03111', 'c03111', - 'a03112', 'b03112', 'c03112', - '1a03111', '2a03111', '1b03111', '2b03111', # warranty bits - '1c03111', '2c03111', '1a03112', '2a03112', - '1b03112', '2b03112', '1c03112', '2c03112', - ), -} - -# Onion omega boards -_ONION_OMEGA_BOARD_IDS = ( - ONION_OMEGA, - ONION_OMEGA2, -) - -# Pine64 boards and devices -_PINE64_DEV_IDS = ( - PINE64, - PINEBOOK, - PINEPHONE -) +from adafruit_platformdetect.constants import boards, chips + class Board: """Attempt to detect specific boards.""" + def __init__(self, detector): self.detector = detector - # pylint: disable=invalid-name, too-many-branches + # pylint: disable=invalid-name, too-many-branches, protected-access @property def id(self): """Return a unique id for the detected board, if any.""" @@ -333,55 +21,56 @@ def id(self): # say if a raspberry pi doesn't have the right ID, or for testing try: return os.environ['BLINKA_FORCEBOARD'] - except KeyError: # no forced board, continue with testing! + except KeyError: # no forced board, continue with testing! pass chip_id = self.detector.chip.id board_id = None - if chip_id == ap_chip.BCM2XXX: + if chip_id == chips.BCM2XXX: board_id = self._pi_id() - elif chip_id == ap_chip.AM33XX: + elif chip_id == chips.AM33XX: board_id = self._beaglebone_id() - elif chip_id == ap_chip.GENERIC_X86: - board_id = GENERIC_LINUX_PC - elif chip_id == ap_chip.SUN8I: + elif chip_id == chips.GENERIC_X86: + board_id = boards.GENERIC_LINUX_PC + elif chip_id == chips.SUN8I: board_id = self._armbian_id() - elif chip_id == ap_chip.SAMA5: + elif chip_id == chips.SAMA5: board_id = self._sama5_id() - elif chip_id == ap_chip.IMX8MX: + elif chip_id == chips.IMX8MX: board_id = self._imx8mx_id() - elif chip_id == ap_chip.ESP8266: - board_id = FEATHER_HUZZAH - elif chip_id == ap_chip.SAMD21: - board_id = FEATHER_M0_EXPRESS - elif chip_id == ap_chip.STM32: - board_id = PYBOARD - elif chip_id == ap_chip.S805: - board_id = ODROID_C1 - elif chip_id == ap_chip.S905: - board_id = ODROID_C2 - elif chip_id == ap_chip.S922X: - board_id = ODROID_N2 - elif chip_id == ap_chip.FT232H: - board_id = FTDI_FT232H - elif chip_id == ap_chip.APQ8016: - board_id = DRAGONBOARD_410C - elif chip_id in (ap_chip.T210, ap_chip.T186, ap_chip.T194): + elif chip_id == chips.ESP8266: + board_id = boards.FEATHER_HUZZAH + elif chip_id == chips.SAMD21: + board_id = boards.FEATHER_M0_EXPRESS + elif chip_id == chips.STM32: + board_id = boards.PYBOARD + elif chip_id == chips.S805: + board_id = boards.ODROID_C1 + elif chip_id == chips.S905: + board_id = boards.ODROID_C2 + elif chip_id == chips.S922X: + board_id = boards.ODROID_N2 + elif chip_id == chips.FT232H: + board_id = boards.FTDI_FT232H + elif chip_id == chips.APQ8016: + board_id = boards.DRAGONBOARD_410C + elif chip_id in (chips.T210, chips.T186, chips.T194): board_id = self._tegra_id() - elif chip_id == ap_chip.HFU540: + elif chip_id == chips.HFU540: board_id = self._sifive_id() - elif chip_id == ap_chip.MCP2221: - board_id = MICROCHIP_MCP2221 - elif chip_id == ap_chip.BINHO: - board_id = BINHO_NOVA - elif chip_id == ap_chip.MIPS24KC: - board_id = ONION_OMEGA - elif chip_id == ap_chip.MIPS24KEC: - board_id = ONION_OMEGA2 - elif chip_id == ap_chip.A64: + elif chip_id == chips.MCP2221: + board_id = boards.MICROCHIP_MCP2221 + elif chip_id == chips.BINHO: + board_id = boards.BINHO_NOVA + elif chip_id == chips.MIPS24KC: + board_id = boards.ONION_OMEGA + elif chip_id == chips.MIPS24KEC: + board_id = boards.ONION_OMEGA2 + elif chip_id == chips.A64: board_id = self._pine64_id() return board_id + # pylint: enable=invalid-name def _pi_id(self): @@ -389,7 +78,7 @@ def _pi_id(self): # Check for Pi boards: pi_rev_code = self._pi_rev_code() if pi_rev_code: - for model, codes in _PI_REV_CODES.items(): + for model, codes in boards._PI_REV_CODES.items(): if pi_rev_code in codes: return model @@ -402,16 +91,16 @@ def _pi_id(self): if "PLUS" in pi_model: re_model = re.search(r'(RASPBERRY_PI_\d).*([AB]_*)(PLUS)', pi_model) - elif "CM" in pi_model: # untested for Compute Module + elif "CM" in pi_model: # untested for Compute Module re_model = re.search(r'(RASPBERRY_PI_CM)(\d)', pi_model) - else: # untested for non-plus models + else: # untested for non-plus models re_model = re.search(r'(RASPBERRY_PI_\d).*([AB]_*)', pi_model) if re_model: pi_model = "".join(re_model.groups()) - available_models = _PI_REV_CODES.keys() + available_models = boards._PI_REV_CODES.keys() for model in available_models: if model == pi_model: return model @@ -424,7 +113,7 @@ def _pi_rev_code(self): # 2709 is Pi 2 # 2835 is Pi 3 (or greater) on 4.9.x kernel # Anything else is not a Pi. - if self.detector.chip.id != ap_chip.BCM2XXX: + if self.detector.chip.id != chips.BCM2XXX: # Something else, not a Pi. return None return self.detector.get_cpuinfo_field('Revision') @@ -442,50 +131,56 @@ def _beaglebone_id(self): return None id_string = eeprom_bytes[4:].decode("ascii") - for model, bb_ids in _BEAGLEBONE_BOARD_IDS.items(): + for model, bb_ids in boards._BEAGLEBONE_BOARD_IDS.items(): for bb_id in bb_ids: if id_string == bb_id[1]: return model return None + # pylint: enable=no-self-use # pylint: disable=too-many-return-statements def _armbian_id(self): - """Check whether the current board is an OrangePi PC or OrangePI R1.""" + """Check whether the current board is an OrangePi board.""" board_value = self.detector.get_armbian_release_field('BOARD') + board = None + if board_value == "orangepipc": - return ORANGE_PI_PC + board = boards.ORANGE_PI_PC if board_value == "orangepi-r1": - return ORANGE_PI_R1 + board = boards.ORANGE_PI_R1 if board_value == "orangepizero": - return ORANGE_PI_ZERO + board = boards.ORANGE_PI_ZERO if board_value == "orangepione": - return ORANGE_PI_ONE + board = boards.ORANGE_PI_ONE if board_value == "orangepilite": - return ORANGE_PI_LITE + board = boards.ORANGE_PI_LITE if board_value == "orangepiplus2e": - return ORANGE_PI_PLUS_2E + board = boards.ORANGE_PI_PLUS_2E if board_value == "orangepipcplus": - return ORANGE_PI_PC_PLUS + board = boards.ORANGE_PI_PC_PLUS if board_value == "pinebook-a64": - return PINEBOOK + board = boards.PINEBOOK + + return board + + # pylint: enable=too-many-return-statements - return None # pylint: enable=too-many-return-statements def _sama5_id(self): """Check what type sama5 board.""" board_value = self.detector.get_device_model() if "Giant Board" in board_value: - return GIANT_BOARD + return boards.GIANT_BOARD return None def _imx8mx_id(self): """Check what type iMX8M board.""" board_value = self.detector.get_device_model() if "Phanbell" in board_value: - return CORAL_EDGE_TPU_DEV + return boards.CORAL_EDGE_TPU_DEV return None def _tegra_id(self): @@ -493,20 +188,20 @@ def _tegra_id(self): board_value = self.detector.get_device_model() board = None if 'tx1' in board_value.lower(): - board = JETSON_TX1 + board = boards.JETSON_TX1 elif 'quill' in board_value or "storm" in board_value or "lightning" in board_value: - board = JETSON_TX2 + board = boards.JETSON_TX2 elif 'xavier' in board_value.lower() or 'agx' in board_value.lower(): - board = JETSON_XAVIER + board = boards.JETSON_XAVIER elif 'nano' in board_value.lower(): - board = JETSON_NANO + board = boards.JETSON_NANO return board def _sifive_id(self): """Try to detect the id for Sifive RISCV64 board.""" board_value = self.detector.get_device_model() if 'hifive-unleashed-a00' in board_value: - return SIFIVE_UNLEASHED + return boards.SIFIVE_UNLEASHED return None def _pine64_id(self): @@ -514,17 +209,17 @@ def _pine64_id(self): board_value = self.detector.get_device_model() board = None if 'pine64' in board_value.lower(): - board = PINE64 + board = boards.PINE64 elif 'pinebook' in board_value.lower(): - board = PINEBOOK + board = boards.PINEBOOK elif 'pinephone' in board_value.lower(): - board = PINEPHONE + board = boards.PINEPHONE return board @property def any_96boards(self): """Check whether the current board is any 96boards board.""" - return self.id in _LINARO_96BOARDS_IDS + return self.id in boards._LINARO_96BOARDS_IDS @property def any_raspberry_pi(self): @@ -534,22 +229,22 @@ def any_raspberry_pi(self): @property def any_raspberry_pi_40_pin(self): """Check whether the current board is any 40-pin Raspberry Pi.""" - return self.id in _RASPBERRY_PI_40_PIN_IDS + return self.id in boards._RASPBERRY_PI_40_PIN_IDS @property def any_raspberry_pi_cm(self): """Check whether the current board is any Compute Module Raspberry Pi.""" - return self.id in _RASPBERRY_PI_CM_IDS + return self.id in boards._RASPBERRY_PI_CM_IDS @property def any_beaglebone(self): """Check whether the current board is any Beaglebone-family system.""" - return self.id in _BEAGLEBONE_IDS + return self.id in boards._BEAGLEBONE_IDS @property def any_orange_pi(self): """Check whether the current board is any defined Orange Pi.""" - return self.id in _ORANGE_PI_IDS + return self.id in boards._ORANGE_PI_IDS @property def any_coral_board(self): @@ -564,50 +259,54 @@ def any_giant_board(self): @property def any_odroid_40_pin(self): """Check whether the current board is any defined 40-pin Odroid.""" - return self.id in _ODROID_40_PIN_IDS + return self.id in boards._ODROID_40_PIN_IDS @property def any_jetson_board(self): """Check whether the current board is any defined Jetson Board.""" - return self.id in _JETSON_IDS + return self.id in boards._JETSON_IDS @property def any_sifive_board(self): """Check whether the current board is any defined Jetson Board.""" - return self.id in _SIFIVE_IDS + return self.id in boards._SIFIVE_IDS @property def any_onion_omega_board(self): """Check whether the current board is any defined OpenWRT board.""" - return self.id in _ONION_OMEGA_BOARD_IDS + return self.id in boards._ONION_OMEGA_BOARD_IDS @property def any_pine64_board(self): """Check whether the current board is any Pine64 device.""" - return self.id in _PINE64_DEV_IDS + return self.id in boards._PINE64_DEV_IDS @property def any_embedded_linux(self): """Check whether the current board is any embedded Linux device.""" - return self.any_raspberry_pi or self.any_beaglebone or \ - self.any_orange_pi or self.any_giant_board or self.any_jetson_board or \ - self.any_coral_board or self.any_odroid_40_pin or self.any_96boards or \ - self.any_sifive_board or self.any_onion_omega_board or self.any_pine64_board + return any( + [ + self.any_raspberry_pi, self.any_beaglebone, self.any_orange_pi, + self.any_giant_board, self.any_jetson_board, self.any_coral_board, + self.any_odroid_40_pin, self.any_96boards, self.any_sifive_board, + self.any_onion_omega_board, self.any_pine64_board, + ] + ) @property def ftdi_ft232h(self): """Check whether the current board is an FTDI FT232H.""" - return self.id == FTDI_FT232H + return self.id == boards.FTDI_FT232H @property def microchip_mcp2221(self): """Check whether the current board is a Microchip MCP2221.""" - return self.id == MICROCHIP_MCP2221 + return self.id == boards.MICROCHIP_MCP2221 @property def binho_nova(self): """Check whether the current board is an BINHO NOVA.""" - return self.id == BINHO_NOVA + return self.id == boards.BINHO_NOVA def __getattr__(self, attr): """ diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index f46ba013..217d9984 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -2,32 +2,7 @@ import os import sys -AM33XX = "AM33XX" -IMX8MX = "IMX8MX" -BCM2XXX = "BCM2XXX" -ESP8266 = "ESP8266" -SAMD21 = "SAMD21" -STM32 = "STM32" -SUN8I = "SUN8I" -S805 = "S805" -S905 = "S905" -S922X = "S922X" -SAMA5 = "SAMA5" -T210 = "T210" -T186 = "T186" -T194 = "T194" -APQ8016 = "APQ8016" -GENERIC_X86 = "GENERIC_X86" -FT232H = "FT232H" -HFU540 = "HFU540" -MCP2221 = "MCP2221" -BINHO = "BINHO" -MIPS24KC = "MIPS24KC" -MIPS24KEC = "MIPS24KEC" -A64 = "A64" - -BCM_RANGE = {'BCM2708', 'BCM2709', 'BCM2835', 'BCM2837', 'bcm2708', 'bcm2709', - 'bcm2835', 'bcm2837'} +from adafruit_platformdetect.constants import chips class Chip: @@ -54,27 +29,27 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return- if count == 0: raise RuntimeError('BLINKA_FT232H environment variable ' + \ 'set, but no FT232H device found') - return FT232H + return chips.FT232H if os.environ.get('BLINKA_MCP2221'): import hid # pylint: disable=import-error # look for it based on PID/VID for dev in hid.enumerate(): if dev['vendor_id'] == 0x04D8 and dev['product_id'] == 0x00DD: - return MCP2221 + return chips.MCP2221 raise RuntimeError('BLINKA_MCP2221 environment variable ' + \ 'set, but no MCP2221 device found') if os.environ.get('BLINKA_NOVA'): - return BINHO + return chips.BINHO platform = sys.platform if platform in ('linux', 'linux2'): return self._linux_id() if platform == 'esp8266': - return ESP8266 + return chips.ESP8266 if platform == 'samd21': - return SAMD21 + return chips.SAMD21 if platform == 'pyboard': - return STM32 + return chips.STM32 # nothing found! return None @@ -84,10 +59,10 @@ def _linux_id(self): # pylint: disable=too-many-branches,too-many-statements """Attempt to detect the CPU on a computer running the Linux kernel.""" if self.detector.check_dt_compatible_value('qcom,apq8016'): - return APQ8016 + return chips.APQ8016 if self.detector.check_dt_compatible_value('fu500'): - return HFU540 + return chips.HFU540 linux_id = None hardware = self.detector.get_cpuinfo_field('Hardware') @@ -95,30 +70,30 @@ def _linux_id(self): # pylint: disable=too-many-branches,too-many-statements if hardware is None: vendor_id = self.detector.get_cpuinfo_field('vendor_id') if vendor_id in ('GenuineIntel', 'AuthenticAMD'): - linux_id = GENERIC_X86 + linux_id = chips.GENERIC_X86 compatible = self.detector.get_device_compatible() if compatible and 'tegra' in compatible: if 'cv' in compatible or 'nano' in compatible: - linux_id = T210 + linux_id = chips.T210 elif 'quill' in compatible: - linux_id = T186 + linux_id = chips.T186 elif 'xavier' in compatible: - linux_id = T194 + linux_id = chips.T194 if compatible and 'imx8m' in compatible: - linux_id = IMX8MX + linux_id = chips.IMX8MX if compatible and 'odroid-c2' in compatible: - linux_id = S905 + linux_id = chips.S905 if compatible and 'amlogic, g12b' in compatible: - linux_id = S922X + linux_id = chips.S922X cpu_model = self.detector.get_cpuinfo_field("cpu model") if cpu_model is not None: if "MIPS 24Kc" in cpu_model: - linux_id = MIPS24KC + linux_id = chips.MIPS24KC elif "MIPS 24KEc" in cpu_model: - linux_id = MIPS24KEC + linux_id = chips.MIPS24KEC # we still haven't identified the hardware, so # convert it to a list and let the remaining @@ -130,28 +105,28 @@ def _linux_id(self): # pylint: disable=too-many-branches,too-many-statements if not linux_id: if 'AM33XX' in hardware: - linux_id = AM33XX + linux_id = chips.AM33XX elif 'sun8i' in hardware: - linux_id = SUN8I + linux_id = chips.SUN8I elif 'ODROIDC' in hardware: - linux_id = S805 + linux_id = chips.S805 elif 'ODROID-C2' in hardware: - linux_id = S905 + linux_id = chips.S905 elif 'ODROID-N2' in hardware: - linux_id = S922X + linux_id = chips.S922X elif 'SAMA5' in hardware: - linux_id = SAMA5 + linux_id = chips.SAMA5 elif "Pinebook" in hardware: - linux_id = A64 + linux_id = chips.A64 elif "sun50iw1p1" in hardware: - linux_id = A64 + linux_id = chips.A64 else: if isinstance(hardware, str): - if hardware in BCM_RANGE: - linux_id = BCM2XXX + if hardware in chips.BCM_RANGE: + linux_id = chips.BCM2XXX elif isinstance(hardware, list): - if set(hardware) & BCM_RANGE: - linux_id = BCM2XXX + if set(hardware) & chips.BCM_RANGE: + linux_id = chips.BCM2XXX return linux_id diff --git a/adafruit_platformdetect/constants/__init__.py b/adafruit_platformdetect/constants/__init__.py new file mode 100644 index 00000000..65e097b8 --- /dev/null +++ b/adafruit_platformdetect/constants/__init__.py @@ -0,0 +1 @@ +"""Common constants used all over the module.""" \ No newline at end of file diff --git a/adafruit_platformdetect/constants/boards.py b/adafruit_platformdetect/constants/boards.py new file mode 100644 index 00000000..230dd4cd --- /dev/null +++ b/adafruit_platformdetect/constants/boards.py @@ -0,0 +1,315 @@ +"""Definition of boards and/or ids""" +# Allow for aligned constant definitions: +# pylint: disable=bad-whitespace +BEAGLEBONE = 'BEAGLEBONE' +BEAGLEBONE_BLACK = 'BEAGLEBONE_BLACK' +BEAGLEBONE_BLUE = 'BEAGLEBONE_BLUE' +BEAGLEBONE_BLACK_WIRELESS = 'BEAGLEBONE_BLACK_WIRELESS' +BEAGLEBONE_POCKETBEAGLE = 'BEAGLEBONE_POCKETBEAGLE' +BEAGLEBONE_GREEN = 'BEAGLEBONE_GREEN' +BEAGLEBONE_GREEN_WIRELESS = 'BEAGLEBONE_GREEN_WIRELESS' +BEAGLEBONE_BLACK_INDUSTRIAL = 'BEAGLEBONE_BLACK_INDUSTRIAL' +BEAGLEBONE_ENHANCED = 'BEAGLEBONE_ENHANCED' +BEAGLEBONE_USOMIQ = 'BEAGLEBONE_USOMIQ' +BEAGLEBONE_AIR = 'BEAGLEBONE_AIR' +BEAGLEBONE_POCKETBONE = 'BEAGLEBONE_POCKETBONE' +BEAGLELOGIC_STANDALONE = 'BEAGLELOGIC_STANDALONE' +OSD3358_DEV_BOARD = 'OSD3358_DEV_BOARD' +OSD3358_SM_RED = 'OSD3358_SM_RED' + +FEATHER_HUZZAH = "FEATHER_HUZZAH" +FEATHER_M0_EXPRESS = "FEATHER_M0_EXPRESS" +GENERIC_LINUX_PC = "GENERIC_LINUX_PC" +PYBOARD = "PYBOARD" +NODEMCU = "NODEMCU" +GIANT_BOARD = "GIANT_BOARD" + +# Orange Pi boards +ORANGE_PI_PC = "ORANGE_PI_PC" +ORANGE_PI_R1 = "ORANGE_PI_R1" +ORANGE_PI_ZERO = "ORANGE_PI_ZERO" +ORANGE_PI_ONE = "ORANGE_PI_ONE" +ORANGE_PI_LITE = "ORANGE_PI_LITE" +ORANGE_PI_PC_PLUS = "ORANGE_PI_PC_PLUS" +ORANGE_PI_PLUS_2E = "ORANGE_PI_PLUS_2E" + +# NVIDIA Jetson boards +JETSON_TX1 = 'JETSON_TX1' +JETSON_TX2 = 'JETSON_TX2' +JETSON_XAVIER = 'JETSON_XAVIER' +JETSON_NANO = 'JETSON_NANO' + +# Google Coral dev board +CORAL_EDGE_TPU_DEV = "CORAL_EDGE_TPU_DEV" + +# Various Raspberry Pi models +RASPBERRY_PI_B_REV1 = "RASPBERRY_PI_B_REV1" +RASPBERRY_PI_B_REV2 = "RASPBERRY_PI_B_REV2" +RASPBERRY_PI_B_PLUS = "RASPBERRY_PI_B_PLUS" +RASPBERRY_PI_A = "RASPBERRY_PI_A" +RASPBERRY_PI_A_PLUS = "RASPBERRY_PI_A_PLUS" +RASPBERRY_PI_CM1 = "RASPBERRY_PI_CM1" +RASPBERRY_PI_ZERO = "RASPBERRY_PI_ZERO" +RASPBERRY_PI_ZERO_W = "RASPBERRY_PI_ZERO_W" +RASPBERRY_PI_2B = "RASPBERRY_PI_2B" +RASPBERRY_PI_3B = "RASPBERRY_PI_3B" +RASPBERRY_PI_3B_PLUS = "RASPBERRY_PI_3B_PLUS" +RASPBERRY_PI_CM3 = "RASPBERRY_PI_CM3" +RASPBERRY_PI_3A_PLUS = "RASPBERRY_PI_3A_PLUS" +RASPBERRY_PI_CM3_PLUS = "RASPBERRY_PI_CM3_PLUS" +RASPBERRY_PI_4B = "RASPBERRY_PI_4B" + +ODROID_C1 = "ODROID_C1" +ODROID_C1_PLUS = "ODROID_C1_PLUS" +ODROID_C2 = "ODROID_C2" +ODROID_N2 = "ODROID_N2" + +FTDI_FT232H = "FTDI_FT232H" +DRAGONBOARD_410C = "DRAGONBOARD_410C" + +SIFIVE_UNLEASHED = "SIFIVE_UNLEASHED" + +MICROCHIP_MCP2221 = "MICROCHIP_MCP2221" + +BINHO_NOVA = "BINHO_NOVA" + +ONION_OMEGA = "ONION_OMEGA" +ONION_OMEGA2 = "ONION_OMEGA2" + +PINE64 = "PINE64" +PINEBOOK = "PINEBOOK" +PINEPHONE = "PINEPHONE" + +# pylint: enable=bad-whitespace + +# OrangePI +_ORANGE_PI_IDS = ( + ORANGE_PI_PC, + ORANGE_PI_R1, + ORANGE_PI_ZERO, + ORANGE_PI_ONE, + ORANGE_PI_LITE, + ORANGE_PI_PC_PLUS, + ORANGE_PI_PLUS_2E, +) + +_CORAL_IDS = ( + CORAL_EDGE_TPU_DEV, +) + +_JETSON_IDS = ( + JETSON_TX1, + JETSON_TX2, + JETSON_XAVIER, + JETSON_NANO +) + +_RASPBERRY_PI_40_PIN_IDS = ( + RASPBERRY_PI_B_PLUS, + RASPBERRY_PI_A_PLUS, + RASPBERRY_PI_ZERO, + RASPBERRY_PI_ZERO_W, + RASPBERRY_PI_2B, + RASPBERRY_PI_3B, + RASPBERRY_PI_3B_PLUS, + RASPBERRY_PI_3A_PLUS, + RASPBERRY_PI_4B +) + +_RASPBERRY_PI_CM_IDS = ( + RASPBERRY_PI_CM1, + RASPBERRY_PI_CM3, + RASPBERRY_PI_CM3_PLUS +) + +_ODROID_40_PIN_IDS = ( + ODROID_C1, + ODROID_C1_PLUS, + ODROID_C2, + ODROID_N2 +) + +_BEAGLEBONE_IDS = ( + BEAGLEBONE, + BEAGLEBONE_BLACK, + BEAGLEBONE_BLUE, + BEAGLEBONE_BLACK_WIRELESS, + BEAGLEBONE_POCKETBEAGLE, + BEAGLEBONE_GREEN, + BEAGLEBONE_GREEN_WIRELESS, + BEAGLEBONE_BLACK_INDUSTRIAL, + BEAGLEBONE_ENHANCED, + BEAGLEBONE_USOMIQ, + BEAGLEBONE_AIR, + BEAGLEBONE_POCKETBONE, + BEAGLELOGIC_STANDALONE, + OSD3358_DEV_BOARD, + OSD3358_SM_RED, +) + +_LINARO_96BOARDS_IDS = ( + DRAGONBOARD_410C, +) + +_SIFIVE_IDS = ( + SIFIVE_UNLEASHED, +) + +# BeagleBone eeprom board ids from: +# https://github.com/beagleboard/image-builder +# Thanks to zmatt on freenode #beagle for pointers. +_BEAGLEBONE_BOARD_IDS = { + # Original bone/white: + BEAGLEBONE: ( + ('A4', 'A335BONE00A4'), + ('A5', 'A335BONE00A5'), + ('A6', 'A335BONE00A6'), + ('A6A', 'A335BONE0A6A'), + ('A6B', 'A335BONE0A6B'), + ('B', 'A335BONE000B'), + ), + BEAGLEBONE_BLACK: ( + ('A5', 'A335BNLT00A5'), + ('A5A', 'A335BNLT0A5A'), + ('A5B', 'A335BNLT0A5B'), + ('A5C', 'A335BNLT0A5C'), + ('A6', 'A335BNLT00A6'), + ('C', 'A335BNLT000C'), + ('C', 'A335BNLT00C0'), + ), + BEAGLEBONE_BLUE: ( + ('A2', 'A335BNLTBLA2'), + ), + BEAGLEBONE_BLACK_WIRELESS: ( + ('A5', 'A335BNLTBWA5'), + ), + BEAGLEBONE_POCKETBEAGLE: ( + ('A2', 'A335PBGL00A2'), + ), + BEAGLEBONE_GREEN: ( + ('1A', 'A335BNLT....'), + ('UNKNOWN', 'A335BNLTBBG1'), + ), + BEAGLEBONE_GREEN_WIRELESS: ( + ('W1A', 'A335BNLTGW1A'), + ), + BEAGLEBONE_BLACK_INDUSTRIAL: ( + ('A0', 'A335BNLTAIA0'), # Arrow + ('A0', 'A335BNLTEIA0'), # Element14 + ), + BEAGLEBONE_ENHANCED: ( + ('A', 'A335BNLTSE0A'), + ), + BEAGLEBONE_USOMIQ: ( + ('6', 'A335BNLTME06'), + ), + BEAGLEBONE_AIR: ( + ('A0', 'A335BNLTNAD0'), + ), + BEAGLEBONE_POCKETBONE: ( + ('0', 'A335BNLTBP00'), + ), + OSD3358_DEV_BOARD: ( + ('0.1', 'A335BNLTGH01'), + ), + OSD3358_SM_RED: ( + ('0', 'A335BNLTOS00'), + ), + BEAGLELOGIC_STANDALONE: ( + ('A', 'A335BLGC000A'), + ) +} + +# Pi revision codes from: +# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + +# Each tuple here contains both the base codes, and the versions that indicate +# the Pi is overvolted / overclocked - for 4-digit codes, this will be prefixed +# with 1000, and for 6-digit codes it'll be prefixed with 1. These are placed +# on separate lines. + +_PI_REV_CODES = { + RASPBERRY_PI_B_REV1: ( + # Regular codes: + '0002', '0003', + + # Overvolted/clocked versions: + '1000002', '1000003', + ), + RASPBERRY_PI_B_REV2: ( + '0005', '0006', '000d', '000e', '000f', + '1000005', '1000006', '100000d', '100000e', '100000f', + ), + RASPBERRY_PI_B_PLUS: ( + '0010', '0013', '900032', + '1000010', '1000013', '1900032', + ), + RASPBERRY_PI_A: ( + '0007', '0008', '0009', + '1000007', '1000008', '1000009', + ), + RASPBERRY_PI_A_PLUS: ( + '0012', '0015', '900021', + '1000012', '1000015', '1900021', + ), + RASPBERRY_PI_CM1: ( + '0011', '0014', + '10000011', '10000014', + ), + RASPBERRY_PI_ZERO: ( + '900092', '920092', '900093', '920093', + '1900092', '1920092', '1900093', '1920093', # warranty bit 24 + '2900092', '2920092', '2900093', '2920093', # warranty bit 25 + ), + RASPBERRY_PI_ZERO_W: ( + '9000c1', + '19000c1', '29000c1', # warranty bits + ), + RASPBERRY_PI_2B: ( + 'a01040', 'a01041', 'a21041', 'a22042', + '1a01040', '1a01041', '1a21041', '1a22042', # warranty bit 24 + '2a01040', '2a01041', '2a21041', '2a22042', # warranty bit 25 + ), + RASPBERRY_PI_3B: ( + 'a02082', 'a22082', 'a32082', 'a52082', + '1a02082', '1a22082', '1a32082', '1a52082', # warranty bit 24 + '2a02082', '2a22082', '2a32082', '2a52082', # warranty bit 25 + ), + RASPBERRY_PI_3B_PLUS: ( + 'a020d3', + '1a020d3', '2a020d3', # warranty bits + ), + RASPBERRY_PI_CM3: ( + 'a020a0', 'a220a0', + '1a020a0', '2a020a0', # warranty bits + '1a220a0', '2a220a0', + ), + RASPBERRY_PI_3A_PLUS: ( + '9020e0', + '19020e0', '29020e0', # warranty bits + ), + RASPBERRY_PI_CM3_PLUS: ( + 'a02100', + '1a02100', '2a02100', # warranty bits + ), + RASPBERRY_PI_4B: ( + 'a03111', 'b03111', 'c03111', + 'a03112', 'b03112', 'c03112', + '1a03111', '2a03111', '1b03111', '2b03111', # warranty bits + '1c03111', '2c03111', '1a03112', '2a03112', + '1b03112', '2b03112', '1c03112', '2c03112', + ), +} + +# Onion omega boards +_ONION_OMEGA_BOARD_IDS = ( + ONION_OMEGA, + ONION_OMEGA2, +) + +# Pine64 boards and devices +_PINE64_DEV_IDS = ( + PINE64, + PINEBOOK, + PINEPHONE +) diff --git a/adafruit_platformdetect/constants/chips.py b/adafruit_platformdetect/constants/chips.py new file mode 100644 index 00000000..c2f76145 --- /dev/null +++ b/adafruit_platformdetect/constants/chips.py @@ -0,0 +1,27 @@ +"""Definition of chips.""" +AM33XX = "AM33XX" +IMX8MX = "IMX8MX" +BCM2XXX = "BCM2XXX" +ESP8266 = "ESP8266" +SAMD21 = "SAMD21" +STM32 = "STM32" +SUN8I = "SUN8I" +S805 = "S805" +S905 = "S905" +S922X = "S922X" +SAMA5 = "SAMA5" +T210 = "T210" +T186 = "T186" +T194 = "T194" +APQ8016 = "APQ8016" +GENERIC_X86 = "GENERIC_X86" +FT232H = "FT232H" +HFU540 = "HFU540" +MCP2221 = "MCP2221" +BINHO = "BINHO" +MIPS24KC = "MIPS24KC" +MIPS24KEC = "MIPS24KEC" +A64 = "A64" + +BCM_RANGE = {'BCM2708', 'BCM2709', 'BCM2835', 'BCM2837', 'bcm2708', 'bcm2709', + 'bcm2835', 'bcm2837'}