You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

824 lines
30 KiB

2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
1 year ago
1 year ago
1 year ago
4 years ago
2 years ago
2 years ago
2 years ago
1 year ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
1 year ago
1 year ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
  2. #
  3. # SPDX-License-Identifier: MIT
  4. """
  5. `adafruit_platformdetect.board`
  6. ================================================================================
  7. Detect boards
  8. * Author(s): Melissa LeBlanc-Williams
  9. Implementation Notes
  10. --------------------
  11. **Software and Dependencies:**
  12. * Linux and Python 3.7 or Higher
  13. """
  14. import os
  15. import re
  16. try:
  17. from typing import Optional
  18. except ImportError:
  19. pass
  20. from adafruit_platformdetect.constants import boards, chips
  21. __version__ = "0.0.0-auto.0"
  22. __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PlatformDetect.git"
  23. class Board:
  24. """Attempt to detect specific boards."""
  25. def __init__(self, detector) -> None:
  26. self.detector = detector
  27. self._board_id = None
  28. # pylint: disable=invalid-name, protected-access, too-many-return-statements
  29. @property
  30. def id(self) -> Optional[str]:
  31. """Return a unique id for the detected board, if any."""
  32. # There are some times we want to trick the platform detection
  33. # say if a raspberry pi doesn't have the right ID, or for testing
  34. # Caching
  35. if self._board_id:
  36. return self._board_id
  37. try:
  38. return os.environ["BLINKA_FORCEBOARD"]
  39. except (AttributeError, KeyError): # no forced board, continue with testing!
  40. pass
  41. chip_id = self.detector.chip.id
  42. board_id = None
  43. if chip_id == chips.H3:
  44. board_id = self._armbian_id() or self._allwinner_variants_id()
  45. elif chip_id == chips.BCM2XXX:
  46. board_id = self._pi_id()
  47. elif chip_id == chips.AM33XX:
  48. board_id = self._beaglebone_id()
  49. elif chip_id == chips.AM65XX:
  50. board_id = self._siemens_simatic_iot2000_id()
  51. elif chip_id == chips.DRA74X:
  52. board_id = self._bbai_id()
  53. elif chip_id == chips.SUN4I:
  54. board_id = self._armbian_id()
  55. elif chip_id == chips.SUN7I:
  56. board_id = self._armbian_id()
  57. elif chip_id == chips.SUN8I:
  58. board_id = self._armbian_id() or self._allwinner_variants_id()
  59. elif chip_id == chips.SAMA5:
  60. board_id = self._sama5_id()
  61. elif chip_id == chips.IMX8MX:
  62. board_id = self._imx8mx_id()
  63. elif chip_id == chips.IMX6ULL:
  64. board_id = self._imx6ull_id()
  65. elif chip_id == chips.S905Y2:
  66. board_id = boards.RADXA_ZERO
  67. elif chip_id == chips.ESP8266:
  68. board_id = boards.FEATHER_HUZZAH
  69. elif chip_id == chips.SAMD21:
  70. board_id = boards.FEATHER_M0_EXPRESS
  71. elif chip_id == chips.STM32F405:
  72. board_id = boards.PYBOARD
  73. elif chip_id == chips.RP2040:
  74. board_id = boards.RASPBERRY_PI_PICO
  75. elif chip_id == chips.S805:
  76. board_id = boards.ODROID_C1
  77. elif chip_id == chips.S905:
  78. board_id = boards.ODROID_C2
  79. elif chip_id == chips.S905X3:
  80. board_id = self._s905x3_id()
  81. elif chip_id == chips.S922X:
  82. board_id = boards.ODROID_N2
  83. elif chip_id == chips.A311D:
  84. board_id = boards.KHADAS_VIM3
  85. elif chip_id == chips.EXYNOS5422:
  86. board_id = boards.ODROID_XU4
  87. elif chip_id == chips.FT232H:
  88. board_id = boards.FTDI_FT232H
  89. elif chip_id == chips.FT2232H:
  90. board_id = boards.FTDI_FT2232H
  91. elif chip_id == chips.APQ8016:
  92. board_id = boards.DRAGONBOARD_410C
  93. elif chip_id in (chips.T210, chips.T186, chips.T194, chips.T234):
  94. board_id = self._tegra_id()
  95. elif chip_id == chips.HFU540:
  96. board_id = self._sifive_id()
  97. elif chip_id == chips.C906:
  98. board_id = self._allwinner_id()
  99. elif chip_id == chips.JH71x0:
  100. board_id = self._beaglebone_id()
  101. elif chip_id == chips.MCP2221:
  102. board_id = boards.MICROCHIP_MCP2221
  103. elif chip_id == chips.BINHO:
  104. board_id = boards.BINHO_NOVA
  105. elif chip_id == chips.LPC4330:
  106. board_id = boards.GREATFET_ONE
  107. elif chip_id == chips.MIPS24KC:
  108. board_id = boards.ONION_OMEGA
  109. elif chip_id == chips.MIPS24KEC:
  110. board_id = boards.ONION_OMEGA2
  111. elif chip_id == chips.ZYNQ7000:
  112. board_id = self._pynq_id()
  113. elif chip_id == chips.A10:
  114. board_id = self._armbian_id()
  115. elif chip_id == chips.A20:
  116. board_id = self._armbian_id()
  117. elif chip_id == chips.A64:
  118. board_id = self._pine64_id()
  119. elif chip_id == chips.H6:
  120. board_id = self._pine64_id() or self._armbian_id()
  121. elif chip_id == chips.H5:
  122. board_id = self._armbian_id() or self._allwinner_variants_id()
  123. elif chip_id == chips.H616:
  124. board_id = self._armbian_id() or self._allwinner_variants_id()
  125. elif chip_id == chips.A33:
  126. board_id = self._clockwork_pi_id()
  127. elif chip_id == chips.RK3308:
  128. board_id = self._rock_pi_id()
  129. elif chip_id == chips.RK3399:
  130. board_id = self._rock_pi_id() or self._armbian_id()
  131. elif chip_id == chips.ATOM_X5_Z8350:
  132. board_id = self._rock_pi_id()
  133. elif chip_id == chips.RK3288:
  134. board_id = self._asus_tinker_board_id()
  135. elif chip_id == chips.RK3328:
  136. board_id = self._rock_pi_id()
  137. elif chip_id == chips.RYZEN_V1605B:
  138. board_id = self._udoo_id()
  139. elif chip_id == chips.PENTIUM_N3710:
  140. board_id = self._udoo_id()
  141. elif chip_id == chips.STM32MP157:
  142. board_id = self._stm32mp1_id()
  143. elif chip_id == chips.STM32MP157DAA1:
  144. board_id = self._stm32mp1_id()
  145. elif chip_id == chips.MT8167:
  146. board_id = boards.CORAL_EDGE_TPU_DEV_MINI
  147. elif chip_id == chips.RP2040_U2IF:
  148. board_id = self._rp2040_u2if_id()
  149. elif chip_id == chips.GENERIC_X86:
  150. board_id = boards.GENERIC_LINUX_PC
  151. elif chip_id == chips.TDA4VM:
  152. board_id = self._tisk_id()
  153. elif chip_id == chips.D1_RISCV:
  154. board_id = self._armbian_id()
  155. elif chip_id == chips.S905X:
  156. board_id = boards.AML_S905X_CC
  157. self._board_id = board_id
  158. return board_id
  159. # pylint: enable=invalid-name
  160. def _pi_id(self) -> Optional[str]:
  161. """Try to detect id of a Raspberry Pi."""
  162. # Check for Pi boards:
  163. pi_rev_code = self._pi_rev_code()
  164. if pi_rev_code:
  165. for model, codes in boards._PI_REV_CODES.items():
  166. if pi_rev_code in codes:
  167. return model
  168. # We may be on a non-Raspbian OS, so try to lazily determine
  169. # the version based on `get_device_model`
  170. else:
  171. pi_model = self.detector.get_device_model()
  172. if pi_model:
  173. pi_model = pi_model.upper().replace(" ", "_")
  174. if "PLUS" in pi_model:
  175. re_model = re.search(r"(RASPBERRY_PI_\d).*([AB]_*)(PLUS)", pi_model)
  176. elif "CM" in pi_model: # untested for Compute Module
  177. re_model = re.search(r"(RASPBERRY_PI_CM)(\d)", pi_model)
  178. else: # untested for non-plus models
  179. re_model = re.search(r"(RASPBERRY_PI_\d).*([AB])", pi_model)
  180. if re_model:
  181. pi_model = "".join(re_model.groups())
  182. available_models = boards._PI_REV_CODES.keys()
  183. for model in available_models:
  184. if model == pi_model:
  185. return model
  186. return None
  187. def _pi_rev_code(self) -> Optional[str]:
  188. """Attempt to find a Raspberry Pi revision code for this board."""
  189. # 2708 is Pi 1
  190. # 2709 is Pi 2
  191. # 2835 is Pi 3 (or greater) on 4.9.x kernel
  192. # Anything else is not a Pi.
  193. if self.detector.chip.id != chips.BCM2XXX:
  194. # Something else, not a Pi.
  195. return None
  196. rev = self.detector.get_cpuinfo_field("Revision")
  197. if rev is not None:
  198. return rev
  199. try:
  200. with open("/proc/device-tree/system/linux,revision", "rb") as revision:
  201. rev_bytes = revision.read()
  202. if rev_bytes[:1] == b"\x00":
  203. rev_bytes = rev_bytes[1:]
  204. return rev_bytes.hex()
  205. except FileNotFoundError:
  206. return None
  207. # pylint: disable=no-self-use
  208. def _beaglebone_id(self) -> Optional[str]:
  209. """Try to detect id of a Beaglebone."""
  210. board_value = self.detector.get_device_compatible()
  211. # Older Builds
  212. if "freedom-u74-arty" in board_value:
  213. return boards.BEAGLEV_STARLIGHT
  214. # Newer Builds
  215. if "beaglev-starlight" in board_value:
  216. return boards.BEAGLEV_STARLIGHT
  217. try:
  218. with open("/sys/bus/nvmem/devices/0-00500/nvmem", "rb") as eeprom:
  219. eeprom_bytes = eeprom.read(16)
  220. except FileNotFoundError:
  221. try:
  222. with open("/sys/bus/nvmem/devices/0-00501/nvmem", "rb") as eeprom:
  223. eeprom_bytes = eeprom.read(16)
  224. except FileNotFoundError:
  225. return None
  226. if eeprom_bytes[:4] != b"\xaaU3\xee":
  227. return None
  228. # special condition for BeagleBone Green rev. 1A
  229. # refer to GitHub issue #57 in this repo for more info
  230. if eeprom_bytes == b"\xaaU3\xeeA335BNLT\x1a\x00\x00\x00":
  231. return boards.BEAGLEBONE_GREEN
  232. id_string = eeprom_bytes[4:].decode("ascii")
  233. for model, bb_ids in boards._BEAGLEBONE_BOARD_IDS.items():
  234. for bb_id in bb_ids:
  235. if id_string == bb_id[1]:
  236. return model
  237. board_value = self.detector.get_armbian_release_field("BOARD")
  238. return None
  239. # pylint: enable=no-self-use
  240. def _bbai_id(self) -> Optional[str]:
  241. """Try to detect id of a Beaglebone AI related board."""
  242. board_value = self.detector.get_device_model()
  243. if "BeagleBone AI" in board_value:
  244. return boards.BEAGLEBONE_AI
  245. return None
  246. def _tisk_id(self) -> Optional[str]:
  247. """Try to detect the id of aarch64 board."""
  248. compatible = self.detector.get_device_compatible()
  249. print(compatible)
  250. if not compatible:
  251. return None
  252. compats = compatible.split("\x00")
  253. for board_id, board_compats in boards._TI_SK_BOARD_IDS:
  254. if any(v in compats for v in board_compats):
  255. return board_id
  256. return None
  257. # pylint: disable=too-many-return-statements
  258. def _armbian_id(self) -> Optional[str]:
  259. """Check whether the current board is an OrangePi board."""
  260. board_value = self.detector.get_armbian_release_field("BOARD")
  261. board = None
  262. if board_value == "orangepipc":
  263. board = boards.ORANGE_PI_PC
  264. elif board_value == "orangepi-r1":
  265. board = boards.ORANGE_PI_R1
  266. elif board_value == "orangepizero":
  267. board = boards.ORANGE_PI_ZERO
  268. elif board_value == "orangepione":
  269. board = boards.ORANGE_PI_ONE
  270. elif board_value == "orangepilite":
  271. board = boards.ORANGE_PI_LITE
  272. elif board_value == "orangepiplus2e":
  273. board = boards.ORANGE_PI_PLUS_2E
  274. elif board_value == "orangepipcplus":
  275. board = boards.ORANGE_PI_PC_PLUS
  276. elif board_value == "pinebook-a64":
  277. board = boards.PINEBOOK
  278. elif board_value == "pineH64":
  279. board = boards.PINEH64
  280. elif board_value == "orangepi2":
  281. board = boards.ORANGE_PI_2
  282. elif board_value == "orangepi3":
  283. board = boards.ORANGE_PI_3
  284. elif board_value == "orangepi3-lts":
  285. board = boards.ORANGE_PI_3_LTS
  286. elif board_value == "orangepi4":
  287. board = boards.ORANGE_PI_4
  288. elif board_value == "orangepi4-lts":
  289. board = boards.ORANGE_PI_4_LTS
  290. elif board_value == "bananapim2zero":
  291. board = boards.BANANA_PI_M2_ZERO
  292. elif board_value == "bananapim2plus":
  293. board = boards.BANANA_PI_M2_PLUS
  294. elif board_value == "bananapim5":
  295. board = boards.BANANA_PI_M5
  296. elif board_value == "orangepizeroplus2-h5":
  297. board = boards.ORANGE_PI_ZERO_PLUS_2H5
  298. elif board_value == "orangepizeroplus":
  299. board = boards.ORANGE_PI_ZERO_PLUS
  300. elif board_value == "orangepizero2":
  301. board = boards.ORANGE_PI_ZERO_2
  302. elif board_value == "nanopiair":
  303. board = boards.NANOPI_NEO_AIR
  304. elif board_value == "nanopiduo2":
  305. board = boards.NANOPI_DUO2
  306. elif board_value == "nanopineo":
  307. board = boards.NANOPI_NEO
  308. elif board_value == "nezha":
  309. board = boards.LICHEE_RV
  310. elif board_value == "pcduino2":
  311. board = boards.PCDUINO2
  312. elif board_value == "pcduino3":
  313. board = boards.PCDUINO3
  314. return board
  315. # pylint: enable=too-many-return-statements
  316. # pylint: enable=too-many-return-statements
  317. def _sama5_id(self) -> Optional[str]:
  318. """Check what type sama5 board."""
  319. board_value = self.detector.get_device_model()
  320. if "Giant Board" in board_value:
  321. return boards.GIANT_BOARD
  322. return None
  323. def _s905x3_id(self) -> Optional[str]:
  324. """Check what type S905X3 board."""
  325. board_value = self.detector.get_device_model()
  326. if "Bananapi BPI-M5" in board_value:
  327. return boards.BANANA_PI_M5
  328. return boards.ODROID_C4
  329. def _stm32mp1_id(self) -> Optional[str]:
  330. """Check what type stm32mp1 board."""
  331. board_value = self.detector.get_device_model()
  332. if "STM32MP157C-DK2" in board_value:
  333. return boards.STM32MP157C_DK2
  334. if "LubanCat" in board_value:
  335. return boards.LUBANCAT_STM32MP157
  336. if "OSD32MP1-BRK" in board_value:
  337. return boards.OSD32MP1_BRK
  338. if "OSD32MP1-RED" in board_value:
  339. return boards.OSD32MP1_RED
  340. if "STM32MP1XX OLinuXino" in board_value:
  341. return boards.STMP157_OLINUXINO_LIME2
  342. return None
  343. def _imx8mx_id(self) -> Optional[str]:
  344. """Check what type iMX8M board."""
  345. board_value = self.detector.get_device_model()
  346. if "FSL i.MX8MM DDR4 EVK" in board_value:
  347. return boards.MAAXBOARD_MINI
  348. if "Freescale i.MX8MQ EVK" in board_value:
  349. return boards.MAAXBOARD
  350. if "Phanbell" in board_value:
  351. return boards.CORAL_EDGE_TPU_DEV
  352. return None
  353. def _imx6ull_id(self) -> Optional[str]:
  354. """Check what type iMX6ULL board."""
  355. board_value = self.detector.get_device_model()
  356. if "LubanCat" in board_value or "Embedfire" in board_value:
  357. return boards.LUBANCAT_IMX6ULL
  358. return None
  359. def _tegra_id(self) -> Optional[str]:
  360. """Try to detect the id of aarch64 board."""
  361. compatible = self.detector.get_device_compatible()
  362. if not compatible:
  363. return None
  364. compats = compatible.split("\x00")
  365. for board_id, board_compats in boards._JETSON_IDS:
  366. if any(v in compats for v in board_compats):
  367. return board_id
  368. return None
  369. def _sifive_id(self) -> Optional[str]:
  370. """Try to detect the id for Sifive RISCV64 board."""
  371. board_value = self.detector.get_device_model()
  372. if "hifive-unleashed-a00" in board_value:
  373. return boards.SIFIVE_UNLEASHED
  374. return None
  375. def _allwinner_id(self) -> Optional[str]:
  376. """Try to detect the id for Allwiner D1 board."""
  377. board_value = self.detector.get_device_model()
  378. if "sun20iw1p1" in board_value:
  379. return boards.ALLWINER_D1
  380. return None
  381. def _pine64_id(self) -> Optional[str]:
  382. """Try to detect the id for Pine64 board or device."""
  383. board_value = self.detector.get_device_model()
  384. board = None
  385. if "pine64" in board_value.lower():
  386. board = boards.PINE64
  387. elif "pine h64" in board_value.lower():
  388. board = boards.PINEH64
  389. elif "pinebook" in board_value.lower():
  390. board = boards.PINEBOOK
  391. elif "pinephone" in board_value.lower():
  392. board = boards.PINEPHONE
  393. elif "sopine" in board_value.lower():
  394. board = boards.SOPINE
  395. return board
  396. # pylint: disable=no-self-use
  397. def _pynq_id(self) -> Optional[str]:
  398. """Try to detect the id for Xilinx PYNQ boards."""
  399. try:
  400. with open(
  401. "/proc/device-tree/chosen/pynq_board", "r", encoding="utf-8"
  402. ) as board_file:
  403. board_model = board_file.read()
  404. match = board_model.upper().replace("-", "_").rstrip("\x00")
  405. for model in boards._PYNQ_IDS:
  406. if model == match:
  407. return model
  408. return None
  409. except FileNotFoundError:
  410. return None
  411. def _rock_pi_id(self) -> Optional[str]:
  412. """Check what type of Rock Pi board."""
  413. board_value = self.detector.get_device_model()
  414. board = None
  415. if board_value and "ROCK Pi S" in board_value:
  416. board = boards.ROCK_PI_S
  417. if board_value and "ROCK PI 4" in board_value.upper():
  418. board = boards.ROCK_PI_4
  419. if board_value and "ROCK PI E" in board_value.upper():
  420. board = boards.ROCK_PI_E
  421. if self.detector.check_board_name_value() == "ROCK Pi X":
  422. board = boards.ROCK_PI_X
  423. return board
  424. def _clockwork_pi_id(self) -> Optional[str]:
  425. """Check what type of Clockwork Pi board."""
  426. board_value = self.detector.get_device_model()
  427. board = None
  428. if board_value and "Clockwork CPI3" in board_value:
  429. board = boards.CLOCKWORK_CPI3
  430. return board
  431. def _udoo_id(self) -> Optional[str]:
  432. """Try to detect the id of udoo board."""
  433. board_asset_tag = self.detector.check_board_asset_tag_value()
  434. for board_id, board_tags in boards._UDOO_BOARD_IDS.items():
  435. if any(v == board_asset_tag for v in board_tags):
  436. return board_id
  437. if self.detector.check_board_name_value() == "UDOO x86":
  438. return boards.UDOO_X86
  439. return None
  440. def _asus_tinker_board_id(self) -> Optional[str]:
  441. """Check what type of Tinker Board."""
  442. board_value = self.detector.get_device_model()
  443. board = None
  444. if board_value and "ASUS Tinker Board" in board_value:
  445. board = boards._ASUS_TINKER_BOARD_IDS
  446. return board
  447. def _pcduino_board_id(self) -> Optional[str]:
  448. """Check on the type of Pcduino"""
  449. board_value = self.detector.get_device_model()
  450. board = None
  451. if "pcduino2" in board_value.lower():
  452. board = boards.PCDUINO2
  453. if "pcduino3" in board_value.lower():
  454. board = boards.PCDUINO3
  455. return board
  456. def _allwinner_variants_id(self) -> Optional[str]:
  457. """Try to detect the id of allwinner based board. (orangepi, nanopi)"""
  458. board_value = self.detector.get_device_model()
  459. board = None
  460. if not board_value:
  461. return board
  462. board_value = board_value.lower()
  463. chip_id = self.detector.chip.id
  464. if "nanopi" in board_value:
  465. if "neo" in board_value and "SUN8I" in chip_id:
  466. board = boards.NANOPI_NEO_AIR
  467. # TODO: Add other specifc board contexts here
  468. elif "orange pi" in board_value:
  469. if "zero" in board_value:
  470. if "H5" in chip_id:
  471. board = boards.ORANGE_PI_ZERO_PLUS_2H5
  472. elif "H616" in chip_id:
  473. board = boards.ORANGE_PI_ZERO_2
  474. # TODO: Add other specifc board contexts here
  475. return board
  476. def _rp2040_u2if_id(self) -> Optional[str]:
  477. import hid
  478. # look for it based on PID/VID
  479. for dev in hid.enumerate():
  480. # Raspberry Pi Pico
  481. vendor = dev["vendor_id"]
  482. product = dev["product_id"]
  483. if vendor == 0xCAFE and product == 0x4005:
  484. return boards.PICO_U2IF
  485. if vendor == 0x239A:
  486. # Feather RP2040
  487. if product == 0x00F1:
  488. return boards.FEATHER_U2IF
  489. # Itsy Bitsy RP2040
  490. if product == 0x00FD:
  491. return boards.ITSYBITSY_U2IF
  492. # QT Py RP2040
  493. if product == 0x00F7:
  494. return boards.QTPY_U2IF
  495. # QT2040 Trinkey
  496. if product == 0x0109:
  497. return boards.QT2040_TRINKEY_U2IF
  498. # MacroPad RP2040
  499. if product == 0x0107:
  500. return boards.MACROPAD_U2IF
  501. # Will only reach here if a device was added in chip.py but here.
  502. raise RuntimeError("RP2040_U2IF device was added to chip but not board.")
  503. def _siemens_simatic_iot2000_id(self) -> Optional[str]:
  504. """Try to detect if this is a IOT2050 Gateway."""
  505. board_value = self.detector.get_device_model()
  506. board = None
  507. if board_value and "SIMATIC IOT2050 Advanced" in board_value:
  508. board = boards.SIEMENS_SIMATIC_IOT2050_ADV
  509. elif board_value and "SIMATIC IOT2050 Basic" in board_value:
  510. board = boards.SIEMENS_SIMATIC_IOT2050_BASIC
  511. return board
  512. @property
  513. def any_siemens_simatic_iot2000(self) -> bool:
  514. """Check whether the current board is a SIEMENS SIMATIC IOT2000 Gateway."""
  515. return self.id in boards._SIEMENS_SIMATIC_IOT2000_IDS
  516. @property
  517. def any_nanopi(self) -> bool:
  518. """Check whether the current board is any defined Nano Pi."""
  519. return self.id in boards._NANOPI_IDS
  520. @property
  521. def any_96boards(self) -> bool:
  522. """Check whether the current board is any 96boards board."""
  523. return self.id in boards._LINARO_96BOARDS_IDS
  524. @property
  525. def any_raspberry_pi(self) -> bool:
  526. """Check whether the current board is any Raspberry Pi."""
  527. return self._pi_rev_code() is not None
  528. @property
  529. def any_raspberry_pi_40_pin(self) -> bool:
  530. """Check whether the current board is any 40-pin Raspberry Pi."""
  531. return self.id in boards._RASPBERRY_PI_40_PIN_IDS
  532. @property
  533. def any_raspberry_pi_cm(self) -> bool:
  534. """Check whether the current board is any Compute Module Raspberry Pi."""
  535. return self.id in boards._RASPBERRY_PI_CM_IDS
  536. @property
  537. def any_beaglebone(self) -> bool:
  538. """Check whether the current board is any Beaglebone-family system."""
  539. return self.id in boards._BEAGLEBONE_IDS
  540. @property
  541. def any_orange_pi(self) -> bool:
  542. """Check whether the current board is any defined Orange Pi."""
  543. return self.id in boards._ORANGE_PI_IDS
  544. @property
  545. def any_lubancat(self) -> bool:
  546. """Check whether the current board is any defined lubancat."""
  547. return self.id in boards._LUBANCAT_IDS
  548. @property
  549. def any_coral_board(self) -> bool:
  550. """Check whether the current board is any defined Coral."""
  551. return self.id in boards._CORAL_IDS
  552. @property
  553. def any_pynq_board(self) -> bool:
  554. """Check whether the current board is any defined PYNQ Board."""
  555. return self.id in boards._PYNQ_IDS
  556. @property
  557. def any_giant_board(self) -> bool:
  558. """Check whether the current board is any defined Giant Board."""
  559. return self.GIANT_BOARD
  560. @property
  561. def any_odroid_40_pin(self) -> bool:
  562. """Check whether the current board is any defined 40-pin Odroid."""
  563. return self.id in boards._ODROID_40_PIN_IDS
  564. @property
  565. def khadas_vim3_40_pin(self) -> bool:
  566. """Check whether the current board is any defined 40-pin Khadas VIM3."""
  567. return self.id in boards._KHADAS_40_PIN_IDS
  568. @property
  569. def any_jetson_board(self) -> bool:
  570. """Check whether the current board is any defined Jetson Board."""
  571. return self.id in [v[0] for v in boards._JETSON_IDS]
  572. @property
  573. def any_sifive_board(self) -> bool:
  574. """Check whether the current board is any defined Jetson Board."""
  575. return self.id in boards._SIFIVE_IDS
  576. @property
  577. def any_onion_omega_board(self) -> bool:
  578. """Check whether the current board is any defined OpenWRT board."""
  579. return self.id in boards._ONION_OMEGA_BOARD_IDS
  580. @property
  581. def any_pine64_board(self) -> bool:
  582. """Check whether the current board is any Pine64 device."""
  583. return self.id in boards._PINE64_DEV_IDS
  584. @property
  585. def any_rock_pi_board(self) -> bool:
  586. """Check whether the current board is any Rock Pi device."""
  587. return self.id in boards._ROCK_PI_IDS
  588. @property
  589. def any_clockwork_pi_board(self) -> bool:
  590. """Check whether the current board is any Clockwork Pi device."""
  591. return self.CLOCKWORK_CPI3
  592. @property
  593. def any_udoo_board(self) -> bool:
  594. """Check to see if the current board is an UDOO board"""
  595. return self.id in boards._UDOO_BOARD_IDS
  596. @property
  597. def any_asus_tinker_board(self) -> bool:
  598. """Check to see if the current board is an ASUS Tinker Board"""
  599. return self.id in boards._ASUS_TINKER_BOARD_IDS
  600. @property
  601. def any_pcduino_board(self) -> bool:
  602. """Check whether the current board is any Pcduino board"""
  603. return self.id in boards._PCDUINO_DEV_IDS
  604. @property
  605. def any_stm32mp1(self) -> bool:
  606. """Check whether the current board is any stm32mp1 board."""
  607. return self.id in boards._STM32MP1_IDS
  608. @property
  609. def any_bananapi(self) -> bool:
  610. """Check whether the current board is any BananaPi-family system."""
  611. return self.id in boards._BANANA_PI_IDS
  612. @property
  613. def any_maaxboard(self) -> bool:
  614. """Check whether the current board is any BananaPi-family system."""
  615. return self.id in boards._MAAXBOARD_IDS
  616. @property
  617. def any_tisk_board(self) -> bool:
  618. """Check whether the current board is any defined TI SK Board."""
  619. return self.id in [v[0] for v in boards._TI_SK_BOARD_IDS]
  620. @property
  621. def any_lichee_riscv_board(self) -> bool:
  622. """Check whether the current board is any defined Lichee RISC-V."""
  623. return self.id in boards._LICHEE_RISCV_IDS
  624. @property
  625. def any_embedded_linux(self) -> bool:
  626. """Check whether the current board is any embedded Linux device."""
  627. return any(
  628. [
  629. self.any_raspberry_pi_40_pin,
  630. self.any_raspberry_pi,
  631. self.any_beaglebone,
  632. self.any_orange_pi,
  633. self.any_nanopi,
  634. self.any_giant_board,
  635. self.any_jetson_board,
  636. self.any_coral_board,
  637. self.any_odroid_40_pin,
  638. self.khadas_vim3_40_pin,
  639. self.any_96boards,
  640. self.any_sifive_board,
  641. self.any_onion_omega_board,
  642. self.any_pine64_board,
  643. self.any_pynq_board,
  644. self.any_rock_pi_board,
  645. self.any_clockwork_pi_board,
  646. self.any_udoo_board,
  647. self.any_asus_tinker_board,
  648. self.any_stm32mp1,
  649. self.any_lubancat,
  650. self.any_bananapi,
  651. self.any_maaxboard,
  652. self.any_tisk_board,
  653. self.any_siemens_simatic_iot2000,
  654. self.any_lichee_riscv_board,
  655. self.any_pcduino_board,
  656. ]
  657. )
  658. @property
  659. def ftdi_ft232h(self) -> bool:
  660. """Check whether the current board is an FTDI FT232H."""
  661. return self.id == boards.FTDI_FT232H
  662. @property
  663. def ftdi_ft2232h(self) -> bool:
  664. """Check whether the current board is an FTDI FT2232H."""
  665. return self.id == boards.FTDI_FT2232H
  666. @property
  667. def microchip_mcp2221(self) -> bool:
  668. """Check whether the current board is a Microchip MCP2221."""
  669. return self.id == boards.MICROCHIP_MCP2221
  670. @property
  671. def pico_u2if(self) -> bool:
  672. """Check whether the current board is a RPi Pico w/ u2if."""
  673. return self.id == boards.PICO_U2IF
  674. @property
  675. def feather_u2if(self) -> bool:
  676. """Check whether the current board is a Feather RP2040 w/ u2if."""
  677. return self.id == boards.FEATHER_U2IF
  678. @property
  679. def itsybitsy_u2if(self) -> bool:
  680. """Check whether the current board is a Itsy Bitsy w/ u2if."""
  681. return self.id == boards.ITSYBITSY_U2IF
  682. @property
  683. def macropad_u2if(self) -> bool:
  684. """Check whether the current board is a MacroPad w/ u2if."""
  685. return self.id == boards.MACROPAD_U2IF
  686. @property
  687. def qtpy_u2if(self) -> bool:
  688. """Check whether the current board is a QT Py w/ u2if."""
  689. return self.id == boards.QTPY_U2IF
  690. @property
  691. def qt2040_trinkey_u2if(self) -> bool:
  692. """Check whether the current board is a QT Py w/ u2if."""
  693. return self.id == boards.QT2040_TRINKEY_U2IF
  694. @property
  695. def binho_nova(self) -> bool:
  696. """Check whether the current board is an BINHO NOVA."""
  697. return self.id == boards.BINHO_NOVA
  698. @property
  699. def greatfet_one(self) -> bool:
  700. """Check whether the current board is a GreatFET One."""
  701. return self.id == boards.GREATFET_ONE
  702. @property
  703. def aml_s905x_cc(self) -> bool:
  704. """Check whether the current board is a aml-s905x-cc One."""
  705. return self.id == boards.AML_S905X_CC
  706. def __getattr__(self, attr: str) -> bool:
  707. """
  708. Detect whether the given attribute is the currently-detected board. See list
  709. of constants at the top of this module for available options.
  710. """
  711. if self.id == attr:
  712. return True
  713. return False