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.

851 lines
31 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
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
2 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.RK3566:
  138. board_id = self._rk3566_id()
  139. elif chip_id == chips.RK3568:
  140. board_id = self._rk3568_id()
  141. elif chip_id == chips.RK3588:
  142. board_id = self._rock_pi_id()
  143. elif chip_id == chips.RYZEN_V1605B:
  144. board_id = self._udoo_id()
  145. elif chip_id == chips.PENTIUM_N3710:
  146. board_id = self._udoo_id()
  147. elif chip_id == chips.STM32MP157:
  148. board_id = self._stm32mp1_id()
  149. elif chip_id == chips.STM32MP157DAA1:
  150. board_id = self._stm32mp1_id()
  151. elif chip_id == chips.MT8167:
  152. board_id = boards.CORAL_EDGE_TPU_DEV_MINI
  153. elif chip_id == chips.RP2040_U2IF:
  154. board_id = self._rp2040_u2if_id()
  155. elif chip_id == chips.GENERIC_X86:
  156. board_id = boards.GENERIC_LINUX_PC
  157. elif chip_id == chips.TDA4VM:
  158. board_id = self._tisk_id()
  159. elif chip_id == chips.D1_RISCV:
  160. board_id = self._armbian_id()
  161. elif chip_id == chips.S905X:
  162. board_id = boards.AML_S905X_CC
  163. self._board_id = board_id
  164. return board_id
  165. # pylint: enable=invalid-name
  166. def _pi_id(self) -> Optional[str]:
  167. """Try to detect id of a Raspberry Pi."""
  168. # Check for Pi boards:
  169. pi_rev_code = self._pi_rev_code()
  170. if pi_rev_code:
  171. for model, codes in boards._PI_REV_CODES.items():
  172. if pi_rev_code in codes:
  173. return model
  174. # We may be on a non-Raspbian OS, so try to lazily determine
  175. # the version based on `get_device_model`
  176. else:
  177. pi_model = self.detector.get_device_model()
  178. if pi_model:
  179. pi_model = pi_model.upper().replace(" ", "_")
  180. if "PLUS" in pi_model:
  181. re_model = re.search(r"(RASPBERRY_PI_\d).*([AB]_*)(PLUS)", pi_model)
  182. elif "CM" in pi_model: # untested for Compute Module
  183. re_model = re.search(r"(RASPBERRY_PI_CM)(\d)", pi_model)
  184. else: # untested for non-plus models
  185. re_model = re.search(r"(RASPBERRY_PI_\d).*([AB])", pi_model)
  186. if re_model:
  187. pi_model = "".join(re_model.groups())
  188. available_models = boards._PI_REV_CODES.keys()
  189. for model in available_models:
  190. if model == pi_model:
  191. return model
  192. return None
  193. def _pi_rev_code(self) -> Optional[str]:
  194. """Attempt to find a Raspberry Pi revision code for this board."""
  195. # 2708 is Pi 1
  196. # 2709 is Pi 2
  197. # 2835 is Pi 3 (or greater) on 4.9.x kernel
  198. # Anything else is not a Pi.
  199. if self.detector.chip.id != chips.BCM2XXX:
  200. # Something else, not a Pi.
  201. return None
  202. rev = self.detector.get_cpuinfo_field("Revision")
  203. if rev is not None:
  204. return rev
  205. try:
  206. with open("/proc/device-tree/system/linux,revision", "rb") as revision:
  207. rev_bytes = revision.read()
  208. if rev_bytes[:1] == b"\x00":
  209. rev_bytes = rev_bytes[1:]
  210. return rev_bytes.hex()
  211. except FileNotFoundError:
  212. return None
  213. # pylint: disable=no-self-use
  214. def _beaglebone_id(self) -> Optional[str]:
  215. """Try to detect id of a Beaglebone."""
  216. board_value = self.detector.get_device_compatible()
  217. # Older Builds
  218. if "freedom-u74-arty" in board_value:
  219. return boards.BEAGLEV_STARLIGHT
  220. # Newer Builds
  221. if "beaglev-starlight" in board_value:
  222. return boards.BEAGLEV_STARLIGHT
  223. try:
  224. with open("/sys/bus/nvmem/devices/0-00500/nvmem", "rb") as eeprom:
  225. eeprom_bytes = eeprom.read(16)
  226. except FileNotFoundError:
  227. try:
  228. with open("/sys/bus/nvmem/devices/0-00501/nvmem", "rb") as eeprom:
  229. eeprom_bytes = eeprom.read(16)
  230. except FileNotFoundError:
  231. return None
  232. if eeprom_bytes[:4] != b"\xaaU3\xee":
  233. return None
  234. # special condition for BeagleBone Green rev. 1A
  235. # refer to GitHub issue #57 in this repo for more info
  236. if eeprom_bytes == b"\xaaU3\xeeA335BNLT\x1a\x00\x00\x00":
  237. return boards.BEAGLEBONE_GREEN
  238. id_string = eeprom_bytes[4:].decode("ascii")
  239. for model, bb_ids in boards._BEAGLEBONE_BOARD_IDS.items():
  240. for bb_id in bb_ids:
  241. if id_string == bb_id[1]:
  242. return model
  243. board_value = self.detector.get_armbian_release_field("BOARD")
  244. return None
  245. # pylint: enable=no-self-use
  246. def _bbai_id(self) -> Optional[str]:
  247. """Try to detect id of a Beaglebone AI related board."""
  248. board_value = self.detector.get_device_model()
  249. if "BeagleBone AI" in board_value:
  250. return boards.BEAGLEBONE_AI
  251. return None
  252. def _tisk_id(self) -> Optional[str]:
  253. """Try to detect the id of aarch64 board."""
  254. compatible = self.detector.get_device_compatible()
  255. print(compatible)
  256. if not compatible:
  257. return None
  258. compats = compatible.split("\x00")
  259. for board_id, board_compats in boards._TI_SK_BOARD_IDS:
  260. if any(v in compats for v in board_compats):
  261. return board_id
  262. return None
  263. # pylint: disable=too-many-return-statements
  264. def _armbian_id(self) -> Optional[str]:
  265. """Check whether the current board is an OrangePi board."""
  266. board_value = self.detector.get_armbian_release_field("BOARD")
  267. board = None
  268. if board_value == "orangepipc":
  269. board = boards.ORANGE_PI_PC
  270. elif board_value == "orangepi-r1":
  271. board = boards.ORANGE_PI_R1
  272. elif board_value == "orangepizero":
  273. board = boards.ORANGE_PI_ZERO
  274. elif board_value == "orangepione":
  275. board = boards.ORANGE_PI_ONE
  276. elif board_value == "orangepilite":
  277. board = boards.ORANGE_PI_LITE
  278. elif board_value == "orangepiplus2e":
  279. board = boards.ORANGE_PI_PLUS_2E
  280. elif board_value == "orangepipcplus":
  281. board = boards.ORANGE_PI_PC_PLUS
  282. elif board_value == "pinebook-a64":
  283. board = boards.PINEBOOK
  284. elif board_value == "pineH64":
  285. board = boards.PINEH64
  286. elif board_value == "orangepi2":
  287. board = boards.ORANGE_PI_2
  288. elif board_value == "orangepi3":
  289. board = boards.ORANGE_PI_3
  290. elif board_value == "orangepi3-lts":
  291. board = boards.ORANGE_PI_3_LTS
  292. elif board_value == "orangepi4":
  293. board = boards.ORANGE_PI_4
  294. elif board_value == "orangepi4-lts":
  295. board = boards.ORANGE_PI_4_LTS
  296. elif board_value == "bananapim2zero":
  297. board = boards.BANANA_PI_M2_ZERO
  298. elif board_value == "bananapim2plus":
  299. board = boards.BANANA_PI_M2_PLUS
  300. elif board_value == "bananapim5":
  301. board = boards.BANANA_PI_M5
  302. elif board_value == "orangepizeroplus2-h5":
  303. board = boards.ORANGE_PI_ZERO_PLUS_2H5
  304. elif board_value == "orangepizeroplus":
  305. board = boards.ORANGE_PI_ZERO_PLUS
  306. elif board_value == "orangepizero2":
  307. board = boards.ORANGE_PI_ZERO_2
  308. elif board_value == "nanopiair":
  309. board = boards.NANOPI_NEO_AIR
  310. elif board_value == "nanopiduo2":
  311. board = boards.NANOPI_DUO2
  312. elif board_value == "nanopineo":
  313. board = boards.NANOPI_NEO
  314. elif board_value == "nezha":
  315. board = boards.LICHEE_RV
  316. elif board_value == "pcduino2":
  317. board = boards.PCDUINO2
  318. elif board_value == "pcduino3":
  319. board = boards.PCDUINO3
  320. return board
  321. # pylint: enable=too-many-return-statements
  322. # pylint: enable=too-many-return-statements
  323. def _sama5_id(self) -> Optional[str]:
  324. """Check what type sama5 board."""
  325. board_value = self.detector.get_device_model()
  326. if "Giant Board" in board_value:
  327. return boards.GIANT_BOARD
  328. return None
  329. def _s905x3_id(self) -> Optional[str]:
  330. """Check what type S905X3 board."""
  331. board_value = self.detector.get_device_model()
  332. if "Bananapi BPI-M5" in board_value:
  333. return boards.BANANA_PI_M5
  334. return boards.ODROID_C4
  335. def _stm32mp1_id(self) -> Optional[str]:
  336. """Check what type stm32mp1 board."""
  337. board_value = self.detector.get_device_model()
  338. if "STM32MP157C-DK2" in board_value:
  339. return boards.STM32MP157C_DK2
  340. if "LubanCat" in board_value:
  341. return boards.LUBANCAT_STM32MP157
  342. if "OSD32MP1-BRK" in board_value:
  343. return boards.OSD32MP1_BRK
  344. if "OSD32MP1-RED" in board_value:
  345. return boards.OSD32MP1_RED
  346. if "STM32MP1XX OLinuXino" in board_value:
  347. return boards.STMP157_OLINUXINO_LIME2
  348. return None
  349. def _imx8mx_id(self) -> Optional[str]:
  350. """Check what type iMX8M board."""
  351. board_value = self.detector.get_device_model()
  352. if "FSL i.MX8MM DDR4 EVK" in board_value:
  353. return boards.MAAXBOARD_MINI
  354. if "Freescale i.MX8MQ EVK" in board_value:
  355. return boards.MAAXBOARD
  356. if "Phanbell" in board_value:
  357. return boards.CORAL_EDGE_TPU_DEV
  358. return None
  359. def _imx6ull_id(self) -> Optional[str]:
  360. """Check what type iMX6ULL board."""
  361. board_value = self.detector.get_device_model()
  362. if "LubanCat" in board_value or "Embedfire" in board_value:
  363. return boards.LUBANCAT_IMX6ULL
  364. return None
  365. def _tegra_id(self) -> Optional[str]:
  366. """Try to detect the id of aarch64 board."""
  367. compatible = self.detector.get_device_compatible()
  368. if not compatible:
  369. return None
  370. compats = compatible.split("\x00")
  371. for board_id, board_compats in boards._JETSON_IDS:
  372. if any(v in compats for v in board_compats):
  373. return board_id
  374. return None
  375. def _sifive_id(self) -> Optional[str]:
  376. """Try to detect the id for Sifive RISCV64 board."""
  377. board_value = self.detector.get_device_model()
  378. if "hifive-unleashed-a00" in board_value:
  379. return boards.SIFIVE_UNLEASHED
  380. return None
  381. def _allwinner_id(self) -> Optional[str]:
  382. """Try to detect the id for Allwiner D1 board."""
  383. board_value = self.detector.get_device_model()
  384. if "sun20iw1p1" in board_value:
  385. return boards.ALLWINER_D1
  386. return None
  387. def _pine64_id(self) -> Optional[str]:
  388. """Try to detect the id for Pine64 board or device."""
  389. board_value = self.detector.get_device_model()
  390. board = None
  391. if "pine64" in board_value.lower():
  392. board = boards.PINE64
  393. elif "pine h64" in board_value.lower():
  394. board = boards.PINEH64
  395. elif "pinebook" in board_value.lower():
  396. board = boards.PINEBOOK
  397. elif "pinephone" in board_value.lower():
  398. board = boards.PINEPHONE
  399. elif "sopine" in board_value.lower():
  400. board = boards.SOPINE
  401. return board
  402. # pylint: disable=no-self-use
  403. def _pynq_id(self) -> Optional[str]:
  404. """Try to detect the id for Xilinx PYNQ boards."""
  405. try:
  406. with open(
  407. "/proc/device-tree/chosen/pynq_board", "r", encoding="utf-8"
  408. ) as board_file:
  409. board_model = board_file.read()
  410. match = board_model.upper().replace("-", "_").rstrip("\x00")
  411. for model in boards._PYNQ_IDS:
  412. if model == match:
  413. return model
  414. return None
  415. except FileNotFoundError:
  416. return None
  417. def _rk3566_id(self) -> Optional[str]:
  418. """Check what type of rk3566 board."""
  419. board_value = self.detector.get_device_model()
  420. board = None
  421. if board_value and "LubanCat-Zero" in board_value:
  422. board = boards.LUBANCAT_ZERO
  423. if board_value and "LubanCat1" in board_value:
  424. board = boards.LUBANCAT1
  425. return board
  426. def _rk3568_id(self) -> Optional[str]:
  427. """Check what type of rk3568 board."""
  428. board_value = self.detector.get_device_model()
  429. board = None
  430. if board_value and "LubanCat2" in board_value:
  431. board = boards.LUBANCAT2
  432. return board
  433. def _rock_pi_id(self) -> Optional[str]:
  434. """Check what type of Rock Pi board."""
  435. board_value = self.detector.get_device_model()
  436. board = None
  437. if board_value and "ROCK Pi S" in board_value:
  438. board = boards.ROCK_PI_S
  439. if board_value and "ROCK PI 4" in board_value.upper():
  440. board = boards.ROCK_PI_4
  441. if board_value and "ROCK PI E" in board_value.upper():
  442. board = boards.ROCK_PI_E
  443. if self.detector.check_board_name_value() == "ROCK Pi X":
  444. board = boards.ROCK_PI_X
  445. if board_value and "ROCK 5" in board_value.upper():
  446. board = boards.ROCK_PI_5
  447. return board
  448. def _clockwork_pi_id(self) -> Optional[str]:
  449. """Check what type of Clockwork Pi board."""
  450. board_value = self.detector.get_device_model()
  451. board = None
  452. if board_value and "Clockwork CPI3" in board_value:
  453. board = boards.CLOCKWORK_CPI3
  454. return board
  455. def _udoo_id(self) -> Optional[str]:
  456. """Try to detect the id of udoo board."""
  457. board_asset_tag = self.detector.check_board_asset_tag_value()
  458. for board_id, board_tags in boards._UDOO_BOARD_IDS.items():
  459. if any(v == board_asset_tag for v in board_tags):
  460. return board_id
  461. if self.detector.check_board_name_value() == "UDOO x86":
  462. return boards.UDOO_X86
  463. return None
  464. def _asus_tinker_board_id(self) -> Optional[str]:
  465. """Check what type of Tinker Board."""
  466. board_value = self.detector.get_device_model()
  467. board = None
  468. if board_value and "ASUS Tinker Board" in board_value:
  469. board = boards._ASUS_TINKER_BOARD_IDS
  470. return board
  471. def _pcduino_board_id(self) -> Optional[str]:
  472. """Check on the type of Pcduino"""
  473. board_value = self.detector.get_device_model()
  474. board = None
  475. if "pcduino2" in board_value.lower():
  476. board = boards.PCDUINO2
  477. if "pcduino3" in board_value.lower():
  478. board = boards.PCDUINO3
  479. return board
  480. def _allwinner_variants_id(self) -> Optional[str]:
  481. """Try to detect the id of allwinner based board. (orangepi, nanopi)"""
  482. board_value = self.detector.get_device_model()
  483. board = None
  484. if not board_value:
  485. return board
  486. board_value = board_value.lower()
  487. chip_id = self.detector.chip.id
  488. if "nanopi" in board_value:
  489. if "neo" in board_value and "SUN8I" in chip_id:
  490. board = boards.NANOPI_NEO_AIR
  491. # TODO: Add other specifc board contexts here
  492. elif "orange pi" in board_value:
  493. if "zero" in board_value:
  494. if "H5" in chip_id:
  495. board = boards.ORANGE_PI_ZERO_PLUS_2H5
  496. elif "H616" in chip_id:
  497. board = boards.ORANGE_PI_ZERO_2
  498. # TODO: Add other specifc board contexts here
  499. return board
  500. def _rp2040_u2if_id(self) -> Optional[str]:
  501. import hid
  502. # look for it based on PID/VID
  503. for dev in hid.enumerate():
  504. # Raspberry Pi Pico
  505. vendor = dev["vendor_id"]
  506. product = dev["product_id"]
  507. if vendor == 0xCAFE and product == 0x4005:
  508. return boards.PICO_U2IF
  509. if vendor == 0x239A:
  510. # Feather RP2040
  511. if product == 0x00F1:
  512. return boards.FEATHER_U2IF
  513. # Itsy Bitsy RP2040
  514. if product == 0x00FD:
  515. return boards.ITSYBITSY_U2IF
  516. # QT Py RP2040
  517. if product == 0x00F7:
  518. return boards.QTPY_U2IF
  519. # QT2040 Trinkey
  520. if product == 0x0109:
  521. return boards.QT2040_TRINKEY_U2IF
  522. # MacroPad RP2040
  523. if product == 0x0107:
  524. return boards.MACROPAD_U2IF
  525. # Will only reach here if a device was added in chip.py but here.
  526. raise RuntimeError("RP2040_U2IF device was added to chip but not board.")
  527. def _siemens_simatic_iot2000_id(self) -> Optional[str]:
  528. """Try to detect if this is a IOT2050 Gateway."""
  529. board_value = self.detector.get_device_model()
  530. board = None
  531. if board_value and "SIMATIC IOT2050 Advanced" in board_value:
  532. board = boards.SIEMENS_SIMATIC_IOT2050_ADV
  533. elif board_value and "SIMATIC IOT2050 Basic" in board_value:
  534. board = boards.SIEMENS_SIMATIC_IOT2050_BASIC
  535. return board
  536. @property
  537. def any_siemens_simatic_iot2000(self) -> bool:
  538. """Check whether the current board is a SIEMENS SIMATIC IOT2000 Gateway."""
  539. return self.id in boards._SIEMENS_SIMATIC_IOT2000_IDS
  540. @property
  541. def any_nanopi(self) -> bool:
  542. """Check whether the current board is any defined Nano Pi."""
  543. return self.id in boards._NANOPI_IDS
  544. @property
  545. def any_96boards(self) -> bool:
  546. """Check whether the current board is any 96boards board."""
  547. return self.id in boards._LINARO_96BOARDS_IDS
  548. @property
  549. def any_raspberry_pi(self) -> bool:
  550. """Check whether the current board is any Raspberry Pi."""
  551. return self._pi_rev_code() is not None
  552. @property
  553. def any_raspberry_pi_40_pin(self) -> bool:
  554. """Check whether the current board is any 40-pin Raspberry Pi."""
  555. return self.id in boards._RASPBERRY_PI_40_PIN_IDS
  556. @property
  557. def any_raspberry_pi_cm(self) -> bool:
  558. """Check whether the current board is any Compute Module Raspberry Pi."""
  559. return self.id in boards._RASPBERRY_PI_CM_IDS
  560. @property
  561. def any_beaglebone(self) -> bool:
  562. """Check whether the current board is any Beaglebone-family system."""
  563. return self.id in boards._BEAGLEBONE_IDS
  564. @property
  565. def any_orange_pi(self) -> bool:
  566. """Check whether the current board is any defined Orange Pi."""
  567. return self.id in boards._ORANGE_PI_IDS
  568. @property
  569. def any_lubancat(self) -> bool:
  570. """Check whether the current board is any defined lubancat."""
  571. return self.id in boards._LUBANCAT_IDS
  572. @property
  573. def any_coral_board(self) -> bool:
  574. """Check whether the current board is any defined Coral."""
  575. return self.id in boards._CORAL_IDS
  576. @property
  577. def any_pynq_board(self) -> bool:
  578. """Check whether the current board is any defined PYNQ Board."""
  579. return self.id in boards._PYNQ_IDS
  580. @property
  581. def any_giant_board(self) -> bool:
  582. """Check whether the current board is any defined Giant Board."""
  583. return self.GIANT_BOARD
  584. @property
  585. def any_odroid_40_pin(self) -> bool:
  586. """Check whether the current board is any defined 40-pin Odroid."""
  587. return self.id in boards._ODROID_40_PIN_IDS
  588. @property
  589. def khadas_vim3_40_pin(self) -> bool:
  590. """Check whether the current board is any defined 40-pin Khadas VIM3."""
  591. return self.id in boards._KHADAS_40_PIN_IDS
  592. @property
  593. def any_jetson_board(self) -> bool:
  594. """Check whether the current board is any defined Jetson Board."""
  595. return self.id in [v[0] for v in boards._JETSON_IDS]
  596. @property
  597. def any_sifive_board(self) -> bool:
  598. """Check whether the current board is any defined Jetson Board."""
  599. return self.id in boards._SIFIVE_IDS
  600. @property
  601. def any_onion_omega_board(self) -> bool:
  602. """Check whether the current board is any defined OpenWRT board."""
  603. return self.id in boards._ONION_OMEGA_BOARD_IDS
  604. @property
  605. def any_pine64_board(self) -> bool:
  606. """Check whether the current board is any Pine64 device."""
  607. return self.id in boards._PINE64_DEV_IDS
  608. @property
  609. def any_rock_pi_board(self) -> bool:
  610. """Check whether the current board is any Rock Pi device."""
  611. return self.id in boards._ROCK_PI_IDS
  612. @property
  613. def any_clockwork_pi_board(self) -> bool:
  614. """Check whether the current board is any Clockwork Pi device."""
  615. return self.CLOCKWORK_CPI3
  616. @property
  617. def any_udoo_board(self) -> bool:
  618. """Check to see if the current board is an UDOO board"""
  619. return self.id in boards._UDOO_BOARD_IDS
  620. @property
  621. def any_asus_tinker_board(self) -> bool:
  622. """Check to see if the current board is an ASUS Tinker Board"""
  623. return self.id in boards._ASUS_TINKER_BOARD_IDS
  624. @property
  625. def any_pcduino_board(self) -> bool:
  626. """Check whether the current board is any Pcduino board"""
  627. return self.id in boards._PCDUINO_DEV_IDS
  628. @property
  629. def any_stm32mp1(self) -> bool:
  630. """Check whether the current board is any stm32mp1 board."""
  631. return self.id in boards._STM32MP1_IDS
  632. @property
  633. def any_bananapi(self) -> bool:
  634. """Check whether the current board is any BananaPi-family system."""
  635. return self.id in boards._BANANA_PI_IDS
  636. @property
  637. def any_maaxboard(self) -> bool:
  638. """Check whether the current board is any BananaPi-family system."""
  639. return self.id in boards._MAAXBOARD_IDS
  640. @property
  641. def any_tisk_board(self) -> bool:
  642. """Check whether the current board is any defined TI SK Board."""
  643. return self.id in [v[0] for v in boards._TI_SK_BOARD_IDS]
  644. @property
  645. def any_lichee_riscv_board(self) -> bool:
  646. """Check whether the current board is any defined Lichee RISC-V."""
  647. return self.id in boards._LICHEE_RISCV_IDS
  648. @property
  649. def any_libre_computer_board(self) -> bool:
  650. """Check whether the current board is any defined Libre Computer board."""
  651. return self.id in boards._LIBRE_COMPUTER_IDS
  652. @property
  653. def any_embedded_linux(self) -> bool:
  654. """Check whether the current board is any embedded Linux device."""
  655. def lazily_generate_conditions():
  656. yield self.any_raspberry_pi_40_pin
  657. yield self.any_raspberry_pi
  658. yield self.any_beaglebone
  659. yield self.any_orange_pi
  660. yield self.any_nanopi
  661. yield self.any_giant_board
  662. yield self.any_jetson_board
  663. yield self.any_coral_board
  664. yield self.any_odroid_40_pin
  665. yield self.khadas_vim3_40_pin
  666. yield self.any_96boards
  667. yield self.any_sifive_board
  668. yield self.any_onion_omega_board
  669. yield self.any_pine64_board
  670. yield self.any_pynq_board
  671. yield self.any_rock_pi_board
  672. yield self.any_clockwork_pi_board
  673. yield self.any_udoo_board
  674. yield self.any_asus_tinker_board
  675. yield self.any_stm32mp1
  676. yield self.any_lubancat
  677. yield self.any_bananapi
  678. yield self.any_maaxboard
  679. yield self.any_tisk_board
  680. yield self.any_siemens_simatic_iot2000
  681. yield self.any_lichee_riscv_board
  682. yield self.any_pcduino_board
  683. yield self.any_libre_computer_board
  684. return any(condition for condition in lazily_generate_conditions())
  685. @property
  686. def ftdi_ft232h(self) -> bool:
  687. """Check whether the current board is an FTDI FT232H."""
  688. return self.id == boards.FTDI_FT232H
  689. @property
  690. def ftdi_ft2232h(self) -> bool:
  691. """Check whether the current board is an FTDI FT2232H."""
  692. return self.id == boards.FTDI_FT2232H
  693. @property
  694. def microchip_mcp2221(self) -> bool:
  695. """Check whether the current board is a Microchip MCP2221."""
  696. return self.id == boards.MICROCHIP_MCP2221
  697. @property
  698. def pico_u2if(self) -> bool:
  699. """Check whether the current board is a RPi Pico w/ u2if."""
  700. return self.id == boards.PICO_U2IF
  701. @property
  702. def feather_u2if(self) -> bool:
  703. """Check whether the current board is a Feather RP2040 w/ u2if."""
  704. return self.id == boards.FEATHER_U2IF
  705. @property
  706. def itsybitsy_u2if(self) -> bool:
  707. """Check whether the current board is a Itsy Bitsy w/ u2if."""
  708. return self.id == boards.ITSYBITSY_U2IF
  709. @property
  710. def macropad_u2if(self) -> bool:
  711. """Check whether the current board is a MacroPad w/ u2if."""
  712. return self.id == boards.MACROPAD_U2IF
  713. @property
  714. def qtpy_u2if(self) -> bool:
  715. """Check whether the current board is a QT Py w/ u2if."""
  716. return self.id == boards.QTPY_U2IF
  717. @property
  718. def qt2040_trinkey_u2if(self) -> bool:
  719. """Check whether the current board is a QT Py w/ u2if."""
  720. return self.id == boards.QT2040_TRINKEY_U2IF
  721. @property
  722. def binho_nova(self) -> bool:
  723. """Check whether the current board is an BINHO NOVA."""
  724. return self.id == boards.BINHO_NOVA
  725. @property
  726. def greatfet_one(self) -> bool:
  727. """Check whether the current board is a GreatFET One."""
  728. return self.id == boards.GREATFET_ONE
  729. def __getattr__(self, attr: str) -> bool:
  730. """
  731. Detect whether the given attribute is the currently-detected board. See list
  732. of constants at the top of this module for available options.
  733. """
  734. if self.id == attr:
  735. return True
  736. return False