Skip to content

Commit 7fedf5d

Browse files
authored
Merge pull request #3 from adafruit/master
Merge
2 parents 9bada62 + 134ebac commit 7fedf5d

File tree

8 files changed

+107
-27
lines changed

8 files changed

+107
-27
lines changed

adafruit_platformdetect/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def get_cpuinfo_field(self, field):
4848

4949
with open("/proc/cpuinfo", "r") as infile:
5050
cpuinfo = infile.read().split("\n")
51+
infile.close()
5152
for line in cpuinfo:
5253
match = re.search(pattern, line, flags=re.IGNORECASE)
5354
if match:
5455
return match.group(1)
55-
5656
return None
5757

5858
def check_dt_compatible_value(self, value):
@@ -61,12 +61,9 @@ def check_dt_compatible_value(self, value):
6161
otherwise False.
6262
"""
6363
# Match a value like 'qcom,apq8016-sbc':
64-
try:
65-
with open("/proc/device-tree/compatible") as compatible:
66-
if value in compatible.read():
67-
return True
68-
except FileNotFoundError:
69-
pass
64+
dt_compatible = self.get_device_compatible()
65+
if dt_compatible and value in dt_compatible:
66+
return True
7067

7168
return False
7269

@@ -85,6 +82,7 @@ def get_armbian_release_field(self, field):
8582
match = re.search(pattern, line)
8683
if match:
8784
field_value = match.group(1)
85+
release_file.close()
8886
except FileNotFoundError:
8987
pass
9088

@@ -100,6 +98,7 @@ def get_device_model(self):
10098
try:
10199
with open("/proc/device-tree/model", "r") as model_file:
102100
model = model_file.read()
101+
model_file.close()
103102
except FileNotFoundError:
104103
pass
105104

@@ -114,6 +113,7 @@ def get_device_compatible(self):
114113
try:
115114
with open("/proc/device-tree/compatible", "r") as model_file:
116115
model = model_file.read()
116+
model_file.close()
117117
except FileNotFoundError:
118118
pass
119119

@@ -129,21 +129,23 @@ def check_board_asset_tag_value(self):
129129
try:
130130
with open("/sys/devices/virtual/dmi/id/board_asset_tag", "r") as tag_file:
131131
tag = tag_file.read().strip()
132+
tag_file.close()
132133
except FileNotFoundError:
133134
pass
134135

135136
return tag
136137

137138
def check_board_name_value(self):
138139
"""
139-
Search /sys/devices/virtual/dmi/id for the device model and return its value, if found,
140+
Search /sys/devices/virtual/dmi/id for the board name and return its value, if found,
140141
otherwise None. Debian/ubuntu based
141142
"""
142143
board_name = None
143144

144145
try:
145146
with open("/sys/devices/virtual/dmi/id/board_name", "r") as board_name_file:
146147
board_name = board_name_file.read().strip()
148+
board_name.close()
147149
except FileNotFoundError:
148150
pass
149151

adafruit_platformdetect/board.py

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def id(self):
7575
board_id = self._pi_id()
7676
elif chip_id == chips.AM33XX:
7777
board_id = self._beaglebone_id()
78+
elif chip_id == chips.DRA74X:
79+
board_id = self._bbai_id()
7880
elif chip_id == chips.GENERIC_X86:
7981
board_id = boards.GENERIC_LINUX_PC
8082
elif chip_id == chips.SUN8I:
@@ -83,6 +85,8 @@ def id(self):
8385
board_id = self._sama5_id()
8486
elif chip_id == chips.IMX8MX:
8587
board_id = self._imx8mx_id()
88+
elif chip_id == chips.IMX6ULL:
89+
board_id = self._imx6ull_id()
8690
elif chip_id == chips.ESP8266:
8791
board_id = boards.FEATHER_HUZZAH
8892
elif chip_id == chips.SAMD21:
@@ -129,6 +133,8 @@ def id(self):
129133
board_id = self._clockwork_pi_id()
130134
elif chip_id == chips.RK3308:
131135
board_id = self._rock_pi_id()
136+
elif chip_id == chips.ATOM_X5_Z8350:
137+
board_id = self._rock_pi_id()
132138
elif chip_id == chips.RK3288:
133139
board_id = self._asus_tinker_board_id()
134140
elif chip_id == chips.RYZEN_V1605B:
@@ -228,6 +234,13 @@ def _beaglebone_id(self):
228234

229235
# pylint: enable=no-self-use
230236

237+
def _bbai_id(self):
238+
"""Try to detect id of a Beaglebone AI related board."""
239+
board_value = self.detector.get_device_model()
240+
if "BeagleBone AI" in board_value:
241+
return boards.BEAGLEBONE_AI
242+
return None
243+
231244
# pylint: disable=too-many-return-statements
232245
def _armbian_id(self):
233246
"""Check whether the current board is an OrangePi board."""
@@ -236,30 +249,34 @@ def _armbian_id(self):
236249

237250
if board_value == "orangepipc":
238251
board = boards.ORANGE_PI_PC
239-
if board_value == "orangepi-r1":
252+
elif board_value == "orangepi-r1":
240253
board = boards.ORANGE_PI_R1
241-
if board_value == "orangepizero":
254+
elif board_value == "orangepizero":
242255
board = boards.ORANGE_PI_ZERO
243-
if board_value == "orangepione":
256+
elif board_value == "orangepione":
244257
board = boards.ORANGE_PI_ONE
245-
if board_value == "orangepilite":
258+
elif board_value == "orangepilite":
246259
board = boards.ORANGE_PI_LITE
247-
if board_value == "orangepiplus2e":
260+
elif board_value == "orangepiplus2e":
248261
board = boards.ORANGE_PI_PLUS_2E
249-
if board_value == "orangepipcplus":
262+
elif board_value == "orangepipcplus":
250263
board = boards.ORANGE_PI_PC_PLUS
251-
if board_value == "pinebook-a64":
264+
elif board_value == "pinebook-a64":
252265
board = boards.PINEBOOK
253-
if board_value == "pineH64":
266+
elif board_value == "pineH64":
254267
board = boards.PINEH64
255-
if board_value == "orangepi2":
268+
elif board_value == "orangepi2":
256269
board = boards.ORANGE_PI_2
257-
if board_value == "bananapim2zero":
270+
elif board_value == "bananapim2zero":
258271
board = boards.BANANA_PI_M2_ZERO
259-
if board_value == "orangepizeroplus2-h5":
272+
elif board_value == "orangepizeroplus2-h5":
260273
board = boards.ORANGE_PI_ZERO_PLUS_2H5
261-
if board_value == "orangepizeroplus":
274+
elif board_value == "orangepizeroplus":
262275
board = boards.ORANGE_PI_ZERO_PLUS
276+
elif board_value == "nanopiair":
277+
board = boards.NANOPI_NEO_AIR
278+
elif board_value == "nanopiduo2":
279+
board = boards.NANOPI_DUO2
263280

264281
return board
265282

@@ -279,6 +296,8 @@ def _stm32mp1_id(self):
279296
board_value = self.detector.get_device_model()
280297
if "STM32MP157C-DK2" in board_value:
281298
return boards.STM32MP157C_DK2
299+
if "LubanCat" in board_value:
300+
return boards.LUBANCAT_STM32MP157
282301
return None
283302

284303
def _imx8mx_id(self):
@@ -288,6 +307,13 @@ def _imx8mx_id(self):
288307
return boards.CORAL_EDGE_TPU_DEV
289308
return None
290309

310+
def _imx6ull_id(self):
311+
"""Check what type iMX6ULL board."""
312+
board_value = self.detector.get_device_model()
313+
if "LubanCat" in board_value or "Embedfire" in board_value:
314+
return boards.LUBANCAT_IMX6ULL
315+
return None
316+
291317
def _tegra_id(self):
292318
"""Try to detect the id of aarch64 board."""
293319
compatible = self.detector.get_device_compatible()
@@ -344,6 +370,8 @@ def _rock_pi_id(self):
344370
board = None
345371
if board_value and "ROCK Pi S" in board_value:
346372
board = boards.ROCK_PI_S
373+
if self.detector.check_board_name_value() == "ROCK Pi X":
374+
board = boards.ROCK_PI_X
347375
return board
348376

349377
def _clockwork_pi_id(self):
@@ -374,6 +402,11 @@ def _asus_tinker_board_id(self):
374402
board = boards._ASUS_TINKER_BOARD_IDS
375403
return board
376404

405+
@property
406+
def any_nanopi(self):
407+
"""Check whether the current board is any defined Nano Pi."""
408+
return self.id in boards._NANOPI_IDS
409+
377410
@property
378411
def any_96boards(self):
379412
"""Check whether the current board is any 96boards board."""
@@ -404,6 +437,11 @@ def any_orange_pi(self):
404437
"""Check whether the current board is any defined Orange Pi."""
405438
return self.id in boards._ORANGE_PI_IDS
406439

440+
@property
441+
def any_lubancat(self):
442+
"""Check whether the current board is any defined lubancat."""
443+
return self.id in boards._LUBANCAT_IDS
444+
407445
@property
408446
def any_coral_board(self):
409447
"""Check whether the current board is any defined Coral."""
@@ -477,6 +515,7 @@ def any_embedded_linux(self):
477515
self.any_raspberry_pi,
478516
self.any_beaglebone,
479517
self.any_orange_pi,
518+
self.any_nanopi,
480519
self.any_giant_board,
481520
self.any_jetson_board,
482521
self.any_coral_board,
@@ -491,6 +530,7 @@ def any_embedded_linux(self):
491530
self.any_udoo_board,
492531
self.any_asus_tinker_board,
493532
self.any_stm32mp1,
533+
self.any_lubancat,
494534
]
495535
)
496536

adafruit_platformdetect/chip.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def _linux_id(self):
159159
if self.detector.check_dt_compatible_value("mediatek,mt8167"):
160160
return chips.MT8167
161161

162+
if self.detector.check_dt_compatible_value("imx6ull"):
163+
return chips.IMX6ULL
164+
162165
linux_id = None
163166
hardware = self.detector.get_cpuinfo_field("Hardware")
164167

@@ -178,6 +181,8 @@ def _linux_id(self):
178181
## print('model_name =', model_name)
179182
if "N3710" in model_name:
180183
linux_id = chips.PENTIUM_N3710
184+
elif "X5-Z8350" in model_name:
185+
linux_id = chips.ATOM_X5_Z8350
181186
else:
182187
linux_id = chips.GENERIC_X86
183188
## print("linux_id = ", linux_id)
@@ -234,6 +239,8 @@ def _linux_id(self):
234239
if not linux_id:
235240
if "AM33XX" in hardware:
236241
linux_id = chips.AM33XX
242+
elif "DRA74X" in hardware:
243+
linux_id = chips.DRA74X
237244
elif "sun8i" in hardware:
238245
linux_id = chips.SUN8I
239246
elif "ODROIDC" in hardware:

adafruit_platformdetect/constants/boards.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
BEAGLEBONE_ENHANCED = "BEAGLEBONE_ENHANCED"
1313
BEAGLEBONE_USOMIQ = "BEAGLEBONE_USOMIQ"
1414
BEAGLEBONE_AIR = "BEAGLEBONE_AIR"
15+
BEAGLEBONE_AI = "BEAGLEBONE_AI"
1516
BEAGLEBONE_POCKETBONE = "BEAGLEBONE_POCKETBONE"
1617
BEAGLELOGIC_STANDALONE = "BEAGLELOGIC_STANDALONE"
1718
OSD3358_DEV_BOARD = "OSD3358_DEV_BOARD"
@@ -42,6 +43,10 @@
4243
ORANGE_PI_ZERO_PLUS_2H5 = "ORANGE_PI_ZERO_PLUS_2H5"
4344
ORANGE_PI_ZERO_PLUS = "ORANGE_PI_ZERO_PLUS"
4445

46+
# Nano Pi boards
47+
NANOPI_NEO_AIR = "NANOPI_NEO_AIR"
48+
NANOPI_DUO2 = "NANOPI_DUO2"
49+
4550
# Banana Pi boards
4651
BANANA_PI_M2_ZERO = "BANANA_PI_M2_ZERO"
4752

@@ -64,6 +69,10 @@
6469
# STM32 MPU boards
6570
STM32MP157C_DK2 = "STM32MP157C_DK2"
6671

72+
# Embedfire LubanCat board
73+
LUBANCAT_IMX6ULL = "LUBANCAT_IMX6ULL"
74+
LUBANCAT_STM32MP157 = "LUBANCAT_STM32MP157"
75+
6776
# Various Raspberry Pi models
6877
RASPBERRY_PI_B_REV1 = "RASPBERRY_PI_B_REV1"
6978
RASPBERRY_PI_B_REV2 = "RASPBERRY_PI_B_REV2"
@@ -110,6 +119,7 @@
110119
SOPINE = "SOPINE"
111120

112121
ROCK_PI_S = "ROCK_PI_S"
122+
ROCK_PI_X = "ROCK_PI_X"
113123

114124
GREATFET_ONE = "GREATFET_ONE"
115125

@@ -122,7 +132,10 @@
122132
_ASUS_TINKER_BOARD_IDS = (ASUS_TINKER_BOARD,)
123133

124134
# STM32MP1
125-
_STM32MP1_IDS = (STM32MP157C_DK2,)
135+
_STM32MP1_IDS = (
136+
STM32MP157C_DK2,
137+
LUBANCAT_STM32MP157,
138+
)
126139

127140
# OrangePI
128141
_ORANGE_PI_IDS = (
@@ -138,9 +151,21 @@
138151
ORANGE_PI_ZERO_PLUS,
139152
)
140153

154+
# NanoPi
155+
_NANOPI_IDS = (
156+
NANOPI_NEO_AIR,
157+
NANOPI_DUO2,
158+
)
159+
141160
# BananaPI
142161
_BANANA_PI_IDS = (BANANA_PI_M2_ZERO,)
143162

163+
# LubanCat
164+
_LUBANCAT_IDS = (
165+
LUBANCAT_IMX6ULL,
166+
LUBANCAT_STM32MP157,
167+
)
168+
144169
# Coral boards
145170
_CORAL_IDS = (
146171
CORAL_EDGE_TPU_DEV,
@@ -239,6 +264,7 @@
239264
BEAGLEBONE_ENHANCED,
240265
BEAGLEBONE_USOMIQ,
241266
BEAGLEBONE_AIR,
267+
BEAGLEBONE_AI,
242268
BEAGLEBONE_POCKETBONE,
243269
BEAGLELOGIC_STANDALONE,
244270
OSD3358_DEV_BOARD,

adafruit_platformdetect/constants/chips.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Definition of chips."""
22
AM33XX = "AM33XX"
3+
DRA74X = "DRA74X"
4+
IMX6ULL = "IMX6ULL"
35
IMX8MX = "IMX8MX"
46
BCM2XXX = "BCM2XXX"
57
ESP8266 = "ESP8266"
@@ -36,5 +38,6 @@
3638
STM32F405 = "STM32F405"
3739
STM32MP157 = "STM32MP157"
3840
MT8167 = "MT8167"
41+
ATOM_X5_Z8350 = "X5-Z8350"
3942

4043
BCM_RANGE = {"BCM2708", "BCM2709", "BCM2711", "BCM2835", "BCM2837"}

bin/detect.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
print("Is this a Pi 4B?", detector.board.RASPBERRY_PI_4B)
1414
print("Is this a 40-pin Raspberry Pi?", detector.board.any_raspberry_pi_40_pin)
1515
print("Is this a Raspberry Pi Compute Module?", detector.board.any_raspberry_pi_cm)
16-
print("Is this a BeagleBone Black?", detector.board.BEAGLEBONE_BLACK)
17-
print("Is this a BeagleBone Green?", detector.board.BEAGLEBONE_GREEN)
16+
print("Is this a BeagleBone Board?", detector.board.any_beaglebone)
1817
print("Is this a Giant Board?", detector.board.GIANT_BOARD)
1918
print("Is this a Coral Dev Board?", detector.board.CORAL_EDGE_TPU_DEV)
2019
print("Is this a Coral Dev Board Mini?", detector.board.CORAL_EDGE_TPU_DEV_MINI)
2120
print("Is this a SiFive Unleashed? ", detector.board.SIFIVE_UNLEASHED)
2221
print("Is this a PYNQ Board?", detector.board.PYNQ_Z1 | detector.board.PYNQ_Z2)
2322
print("Is this a Rock Pi board?", detector.board.any_rock_pi_board)
23+
print("Is this a NanoPi board?", detector.board.any_nanopi)
2424
print("Is this a Clockwork Pi board?", detector.board.any_clockwork_pi_board)
2525
print("Is this an embedded Linux system?", detector.board.any_embedded_linux)
2626
print("Is this a generic Linux PC?", detector.board.GENERIC_LINUX_PC)
@@ -67,3 +67,6 @@
6767

6868
if detector.board.any_coral_board:
6969
print("Coral device detected.")
70+
71+
if detector.board.any_lubancat:
72+
print("LubanCat detected.")

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
autodoc_mock_imports = ["machine"]
2424

2525
intersphinx_mapping = {
26-
"python": ("https://docs.python.org/3.5", None),
26+
"python": ("https://docs.python.org/3.6", None),
2727
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
2828
}
2929

0 commit comments

Comments
 (0)