Skip to content

Commit ffbbf59

Browse files
authored
Merge branch 'master' into master
2 parents 3f33421 + d2ccda4 commit ffbbf59

File tree

7 files changed

+179
-60
lines changed

7 files changed

+179
-60
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
source actions-ci/install.sh
3636
- name: Pip install pylint, black, & Sphinx
3737
run: |
38-
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
38+
pip install --force-reinstall pylint black Sphinx sphinx-rtd-theme
3939
- name: Library version
4040
run: git describe --dirty --always --tags
4141
- name: Check formatting

adafruit_platformdetect/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def get_device_compatible(self):
121121

122122
def check_board_asset_tag_value(self):
123123
"""
124-
Search /proc/device-tree/model for the device model and return its value, if found,
124+
Search /sys/devices/virtual/dmi/id for the device model and return its value, if found,
125125
otherwise None.
126126
"""
127127
tag = None
@@ -133,3 +133,18 @@ def check_board_asset_tag_value(self):
133133
pass
134134

135135
return tag
136+
137+
def check_board_name_value(self):
138+
"""
139+
Search /sys/devices/virtual/dmi/id for the device model and return its value, if found,
140+
otherwise None. Debian/ubuntu based
141+
"""
142+
board_name = None
143+
144+
try:
145+
with open("/sys/devices/virtual/dmi/id/board_name", "r") as board_name_file:
146+
board_name = board_name_file.read().strip()
147+
except FileNotFoundError:
148+
pass
149+
150+
return board_name

adafruit_platformdetect/board.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,19 @@ class Board:
5050

5151
def __init__(self, detector):
5252
self.detector = detector
53+
self._board_id = None
5354

5455
# pylint: disable=invalid-name, protected-access
5556
@property
5657
def id(self):
5758
"""Return a unique id for the detected board, if any."""
5859
# There are some times we want to trick the platform detection
5960
# say if a raspberry pi doesn't have the right ID, or for testing
61+
62+
# Caching
63+
if self._board_id:
64+
return self._board_id
65+
6066
try:
6167
return os.environ["BLINKA_FORCEBOARD"]
6268
except KeyError: # no forced board, continue with testing!
@@ -81,7 +87,7 @@ def id(self):
8187
board_id = boards.FEATHER_HUZZAH
8288
elif chip_id == chips.SAMD21:
8389
board_id = boards.FEATHER_M0_EXPRESS
84-
elif chip_id == chips.STM32:
90+
elif chip_id == chips.STM32F405:
8591
board_id = boards.PYBOARD
8692
elif chip_id == chips.S805:
8793
board_id = boards.ODROID_C1
@@ -117,6 +123,8 @@ def id(self):
117123
board_id = self._pine64_id()
118124
elif chip_id == chips.H6:
119125
board_id = self._pine64_id()
126+
elif chip_id == chips.H5:
127+
board_id = self._armbian_id()
120128
elif chip_id == chips.A33:
121129
board_id = self._clockwork_pi_id()
122130
elif chip_id == chips.RK3308:
@@ -125,7 +133,12 @@ def id(self):
125133
board_id = self._asus_tinker_board_id()
126134
elif chip_id == chips.RYZEN_V1605B:
127135
board_id = self._udoo_id()
136+
elif chip_id == chips.PENTIUM_N3710:
137+
board_id = self._udoo_id()
138+
elif chip_id == chips.STM32MP157:
139+
board_id = self._stm32mp1_id()
128140

141+
self._board_id = board_id
129142
return board_id
130143

131144
# pylint: enable=invalid-name
@@ -239,6 +252,8 @@ def _armbian_id(self):
239252
board = boards.PINEH64
240253
if board_value == "orangepi2":
241254
board = boards.ORANGE_PI_2
255+
if board_value == "bananapim2zero":
256+
board = boards.BANANA_PI_M2_ZERO
242257

243258
return board
244259

@@ -253,6 +268,13 @@ def _sama5_id(self):
253268
return boards.GIANT_BOARD
254269
return None
255270

271+
def _stm32mp1_id(self):
272+
"""Check what type stm32mp1 board."""
273+
board_value = self.detector.get_device_model()
274+
if "STM32MP157C-DK2" in board_value:
275+
return boards.STM32MP157C_DK2
276+
return None
277+
256278
def _imx8mx_id(self):
257279
"""Check what type iMX8M board."""
258280
board_value = self.detector.get_device_model()
@@ -266,7 +288,7 @@ def _tegra_id(self):
266288
if not compatible:
267289
return None
268290
compats = compatible.split("\x00")
269-
for board_id, board_compats in boards._JETSON_IDS.items():
291+
for board_id, board_compats in boards._JETSON_IDS:
270292
if any(v in compats for v in board_compats):
271293
return board_id
272294
return None
@@ -330,6 +352,10 @@ def _udoo_id(self):
330352
for board_id, board_tags in boards._UDOO_BOARD_IDS.items():
331353
if any(v == board_asset_tag for v in board_tags):
332354
return board_id
355+
356+
if self.detector.check_board_name_value() == "UDOO x86":
357+
return boards.UDOO_X86
358+
333359
return None
334360

335361
def _asus_tinker_board_id(self):
@@ -393,7 +419,7 @@ def any_odroid_40_pin(self):
393419
@property
394420
def any_jetson_board(self):
395421
"""Check whether the current board is any defined Jetson Board."""
396-
return self.id in boards._JETSON_IDS
422+
return self.id in [v[0] for v in boards._JETSON_IDS]
397423

398424
@property
399425
def any_sifive_board(self):
@@ -425,10 +451,16 @@ def any_udoo_board(self):
425451
"""Check to see if the current board is an UDOO board"""
426452
return self.id in boards._UDOO_BOARD_IDS
427453

454+
@property
428455
def any_asus_tinker_board(self):
429456
"""Check to see if the current board is an ASUS Tinker Board"""
430457
return self.id in boards._ASUS_TINKER_BOARD_IDS
431458

459+
@property
460+
def any_stm32mp1(self):
461+
"""Check whether the current board is any stm32mp1 board."""
462+
return self.id in boards._STM32MP1_IDS
463+
432464
@property
433465
def any_embedded_linux(self):
434466
"""Check whether the current board is any embedded Linux device."""
@@ -450,6 +482,7 @@ def any_embedded_linux(self):
450482
self.any_clockwork_pi_board,
451483
self.any_udoo_board,
452484
self.any_asus_tinker_board,
485+
self.any_stm32mp1,
453486
]
454487
)
455488

adafruit_platformdetect/chip.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Chip:
5151

5252
def __init__(self, detector):
5353
self.detector = detector
54+
self._chip_id = None
5455

5556
@property
5657
def id(
@@ -59,6 +60,11 @@ def id(
5960
"""Return a unique id for the detected chip, if any."""
6061
# There are some times we want to trick the platform detection
6162
# say if a raspberry pi doesn't have the right ID, or for testing
63+
64+
# Caching
65+
if self._chip_id:
66+
return self._chip_id
67+
6268
try:
6369
return os.environ["BLINKA_FORCECHIP"]
6470
except KeyError: # no forced chip, continue with testing!
@@ -75,14 +81,16 @@ def id(
7581
"BLINKA_FT232H environment variable "
7682
+ "set, but no FT232H device found"
7783
)
78-
return chips.FT232H
84+
self._chip_id = chips.FT232H
85+
return self._chip_id
7986
if os.environ.get("BLINKA_MCP2221"):
8087
import hid
8188

8289
# look for it based on PID/VID
8390
for dev in hid.enumerate():
8491
if dev["vendor_id"] == 0x04D8 and dev["product_id"] == 0x00DD:
85-
return chips.MCP2221
92+
self._chip_id = chips.MCP2221
93+
return self._chip_id
8694
raise RuntimeError(
8795
"BLINKA_MCP2221 environment variable "
8896
+ "set, but no MCP2221 device found"
@@ -91,23 +99,29 @@ def id(
9199
import usb
92100

93101
if usb.core.find(idVendor=0x1D50, idProduct=0x60E6) is not None:
94-
return chips.LPC4330
102+
self._chip_id = chips.LPC4330
103+
return self._chip_id
95104
raise RuntimeError(
96105
"BLINKA_GREATFET environment variable "
97106
+ "set, but no GreatFET device found"
98107
)
99108
if os.environ.get("BLINKA_NOVA"):
100-
return chips.BINHO
109+
self._chip_id = chips.BINHO
110+
return self._chip_id
101111

102112
platform = sys.platform
103113
if platform in ("linux", "linux2"):
104-
return self._linux_id()
114+
self._chip_id = self._linux_id()
115+
return self._chip_id
105116
if platform == "esp8266":
106-
return chips.ESP8266
117+
self._chip_id = chips.ESP8266
118+
return self._chip_id
107119
if platform == "samd21":
108-
return chips.SAMD21
120+
self._chip_id = chips.SAMD21
121+
return self._chip_id
109122
if platform == "pyboard":
110-
return chips.STM32
123+
self._chip_id = chips.STM32F405
124+
return self._chip_id
111125
# nothing found!
112126
return None
113127

@@ -133,6 +147,12 @@ def _linux_id(self):
133147
if self.detector.check_dt_compatible_value("rockchip,rk3288"):
134148
return chips.RK3288
135149

150+
if self.detector.check_dt_compatible_value("st,stm32mp157"):
151+
return chips.STM32MP157
152+
153+
if self.detector.check_dt_compatible_value("sun50i-a64"):
154+
return chips.A64
155+
136156
linux_id = None
137157
hardware = self.detector.get_cpuinfo_field("Hardware")
138158
if (
@@ -150,8 +170,15 @@ def _linux_id(self):
150170
linux_id = chips.RYZEN_V1605B
151171
else:
152172
linux_id = chips.GENERIC_X86
173+
## print("linux_id = ", linux_id)
153174
elif vendor_id == "GenuineIntel":
154-
linux_id = chips.GENERIC_X86
175+
model_name = self.detector.get_cpuinfo_field("model name").upper()
176+
## print('model_name =', model_name)
177+
if "N3710" in model_name:
178+
linux_id = chips.PENTIUM_N3710
179+
else:
180+
linux_id = chips.GENERIC_X86
181+
## print("linux_id = ", linux_id)
155182

156183
compatible = self.detector.get_device_compatible()
157184
if compatible and "tegra" in compatible:
@@ -181,6 +208,8 @@ def _linux_id(self):
181208
linux_id = chips.A64
182209
if compatible and "sun50i-h6" in compatible:
183210
linux_id = chips.H6
211+
if compatible and "sun50i-h5" in compatible:
212+
linux_id = chips.H5
184213
if compatible and "odroid-xu4" in compatible:
185214
linux_id = chips.EXYNOS5422
186215

@@ -219,9 +248,6 @@ def _linux_id(self):
219248
linux_id = chips.SAMA5
220249
elif "Pinebook" in hardware:
221250
linux_id = chips.A64
222-
# elif "sun50iw1p1" in hardware: #sun50iw1p1 is a common identfier in Allwinner SOC's. I do not believe it should be
223-
# linux_id = chips.A64 #used as an identifier. I feel it makes more sense to rely on the device compatible field. Otherwise it will be
224-
# Impossible to differentiate between Allwinner A64's and Allwinner H6's.
225251
elif "ASUS_TINKER_BOARD" in hardware:
226252
linux_id = chips.RK3288
227253
elif "Xilinx Zynq" in hardware:

0 commit comments

Comments
 (0)