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.

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