Skip to content

Commit f471243

Browse files
committed
refactor 96boards detection
- Brings naming in line with existing conventions - Replaces `_is_96Boards()` with an `any_96boards` property - Renames `get_dt_compatible_field()` to `check_dt_compatible_value()` to distinguish between returning a field's string value and a boolean check on whether a value is present. - Adds a 96Boards check to `bin/detect.py`. This might still need some changes, and definitely needs tested on actual 96Boards hardware.
1 parent 9c861c6 commit f471243

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ generally dependent on the former. Platform info is gathered from:
1111

1212
- Python's `sys.platform`
1313

14-
- The `/proc/cpuinfo` file on Linux systems (for processor info, Raspberry Pi
15-
hardware revisions, etc.)
14+
- Various files on Linux systems:
15+
16+
- `/proc/cpuinfo` (for processor info, Raspberry Pi hardware revisions, etc.)
17+
18+
- `/proc/device-tree/compatible` (for 96Boards info)
1619

1720
- Beaglebone EEPROM board IDs
1821

adafruit_platformdetect/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ def get_cpuinfo_field(self, field):
5555

5656
return None
5757

58-
def get_dt_compatible_field(self, field):
58+
def check_dt_compatible_value(self, value):
5959
"""
60-
Search /proc/device-tree/compatible for a field and return True, if found,
60+
Search /proc/device-tree/compatible for a value and return True, if found,
6161
otherwise False.
6262
"""
6363
# Match a value like 'qcom,apq8016-sbc':
64-
if field in open('/proc/device-tree/compatible').read():
65-
return True
64+
if value in open('/proc/device-tree/compatible').read():
65+
return True
6666

6767
return False
6868

adafruit_platformdetect/board.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
ODROID_C2 = "ODROID_C2"
4747

4848
FTDI_FT232H = "FT232H"
49-
# XXX: naming
50-
_96BOARDS = "96BOARDS"
49+
LINARO_96BOARDS = "LINARO_96BOARDS"
5150
# pylint: enable=bad-whitespace
5251

5352
_RASPBERRY_PI_40_PIN_IDS = (
@@ -255,8 +254,10 @@ def id(self):
255254
board_id = ODROID_C2
256255
elif chip_id == ap_chip.FT232H:
257256
board_id = FTDI_FT232H
258-
else:
259-
board_id = self._is_96boards()
257+
# TODO do we want to check chip ID at all for 96Boards?
258+
# elif chip_id == APQ8016:
259+
elif self.any_96boards:
260+
board_id = LINARO_96BOARDS
260261

261262
return board_id
262263
# pylint: enable=invalid-name
@@ -303,18 +304,22 @@ def _beaglebone_id(self):
303304
return None
304305
# pylint: enable=no-self-use
305306

306-
def _is_96Boards(self):
307-
if self.detector.get_dt_compatible_field("qcom,apq8016-sbc") or self.detector.get_dt_compatible_field("hisilicon,hi3660-hikey960") or self.detector.get_dt_compatible_field("hisilicon,hi6220-hikey"):
308-
return _96BOARDS
309-
return None
310-
311307
def _armbian_id(self):
312-
"""Check whether the current board is an OrangePi PC."""
308+
"""Find a board id for an OrangePi PC."""
313309
board_value = self.detector.get_armbian_release_field('BOARD')
314310
if board_value == "orangepipc":
315311
return ORANGE_PI_PC
316312
return None
317313

314+
@property
315+
def any_96boards(self):
316+
"""Check if the current board is any 96Boards-family board."""
317+
return (
318+
self.detector.check_dt_compatible_value("qcom,apq8016-sbc")
319+
or self.detector.check_dt_compatible_value("hisilicon,hi3660-hikey960")
320+
or self.detector.check_dt_compatible_value("hisilicon,hi6220-hikey")
321+
)
322+
318323
@property
319324
def any_raspberry_pi(self):
320325
"""Check whether the current board is any Raspberry Pi."""

adafruit_platformdetect/chip.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s
6969

7070
def _linux_id(self):
7171
"""Attempt to detect the CPU on a computer running the Linux kernel."""
72-
linux_id = None
7372

74-
hardware = self.detector.get_cpuinfo_field("Hardware")
73+
if self.detector.check_dt_compatible_value("qcom,apq8016"):
74+
return APQ8016
7575

76-
if self.detector.get_dt_compatible_field("qcom,apq8016"):
77-
linux_id = APQ8016
78-
return linux_id
76+
linux_id = None
77+
hardware = self.detector.get_cpuinfo_field("Hardware")
7978

8079
if hardware is None:
8180
vendor_id = self.detector.get_cpuinfo_field("vendor_id")
@@ -92,7 +91,7 @@ def _linux_id(self):
9291
elif "ODROID-C2" in hardware:
9392
linux_id = S905
9493

95-
return linux_id
94+
return None
9695

9796
def __getattr__(self, attr):
9897
"""

bin/detect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
print("Board id: ", detector.board.id)
1010

11+
print("Is this a 96Boards board?", detector.board.LINARO_96BOARDS)
1112
print("Is this a Pi 3B+?", detector.board.RASPBERRY_PI_3B_PLUS)
1213
print("Is this a 40-pin Raspberry Pi?", detector.board.any_raspberry_pi_40_pin)
1314
print("Is this a BBB?", detector.board.BEAGLEBONE_BLACK)

0 commit comments

Comments
 (0)