From 76ff837fb1e857f9a6dc6f128d08bec289f5825c Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 19 Oct 2019 23:31:54 -0500 Subject: [PATCH 1/8] style edit: remove variation in use of double & single quotes --- adafruit_platformdetect/chip.py | 54 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 2ef85695..e41b911b 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -2,24 +2,24 @@ import sys import os -AM33XX = "AM33XX" -IMX8MX = "IMX8MX" -BCM2XXX = "BCM2XXX" -ESP8266 = "ESP8266" -SAMD21 = "SAMD21" -STM32 = "STM32" -SUN8I = "SUN8I" -S805 = "S805" -S905 = "S905" -S922X = "S922X" -SAMA5 = "SAMA5" -T210 = "T210" -T186 = "T186" -T194 = "T194" -APQ8016 = "APQ8016" -GENERIC_X86 = "GENERIC_X86" -FT232H = "FT232H" -HFU540 = "HFU540" +AM33XX = 'AM33XX' +IMX8MX = 'IMX8MX' +BCM2XXX = 'BCM2XXX' +ESP8266 = 'ESP8266' +SAMD21 = 'SAMD21' +STM32 = 'STM32' +SUN8I = 'SUN8I' +S805 = 'S805' +S905 = 'S905' +S922X = 'S922X' +SAMA5 = 'SAMA5' +T210 = 'T210' +T186 = 'T186' +T194 = 'T194' +APQ8016 = 'APQ8016' +GENERIC_X86 = 'GENERIC_X86' +FT232H = 'FT232H' +HFU540 = 'HFU540' class Chip: """Attempt detection of current chip / CPU.""" @@ -50,13 +50,13 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s pass platform = sys.platform - if platform == "linux" or platform == "linux2": + if platform in ('linux', 'linux2'): return self._linux_id() - if platform == "esp8266": + if platform == 'esp8266': return ESP8266 - if platform == "samd21": + if platform == 'samd21': return SAMD21 - if platform == "pyboard": + if platform == 'pyboard': return STM32 # nothing found! return None @@ -65,18 +65,18 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s def _linux_id(self): # pylint: disable=too-many-branches """Attempt to detect the CPU on a computer running the Linux kernel.""" - if self.detector.check_dt_compatible_value("qcom,apq8016"): + if self.detector.check_dt_compatible_value('qcom,apq8016'): return APQ8016 - if self.detector.check_dt_compatible_value("fu500"): + if self.detector.check_dt_compatible_value('fu500'): return HFU540 linux_id = None - hardware = self.detector.get_cpuinfo_field("Hardware") + hardware = self.detector.get_cpuinfo_field('Hardware') if hardware is None: - vendor_id = self.detector.get_cpuinfo_field("vendor_id") - if vendor_id in ("GenuineIntel", "AuthenticAMD"): + vendor_id = self.detector.get_cpuinfo_field('vendor_id') + if vendor_id in ('GenuineIntel', 'AuthenticAMD'): linux_id = GENERIC_X86 compatible = self.detector.get_device_compatible() From b0f75e8062a0b005f9ff78d0ab1fca184b70cd18 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 19 Oct 2019 23:33:15 -0500 Subject: [PATCH 2/8] widen search for chip id; captures RPi with non-Raspbian OS --- adafruit_platformdetect/chip.py | 40 +++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index e41b911b..14a63a6b 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -21,6 +21,9 @@ FT232H = 'FT232H' HFU540 = 'HFU540' +BCM_RANGE = {'BCM2708', 'BCM2709', 'BCM2835', 'BCM2837', 'bcm2708', 'bcm2709', + 'bcm2835', 'bcm2837'} + class Chip: """Attempt detection of current chip / CPU.""" def __init__(self, detector): @@ -94,20 +97,29 @@ def _linux_id(self): # pylint: disable=too-many-branches if compatible and 'amlogic, g12b' in compatible: linux_id = S922X - elif hardware in ("BCM2708", "BCM2709", "BCM2835"): - linux_id = BCM2XXX - elif "AM33XX" in hardware: - linux_id = AM33XX - elif "sun8i" in hardware: - linux_id = SUN8I - elif "ODROIDC" in hardware: - linux_id = S805 - elif "ODROID-C2" in hardware: - linux_id = S905 - elif "ODROID-N2" in hardware: - linux_id = S922X - elif "SAMA5" in hardware: - linux_id = SAMA5 + # we still haven't identified the hardware, so + # convert it to a list and let the remaining + # conditions attempt. + if not linux_id: + hardware = [ + entry.replace("\x00", "") for entry in compatible.split(",") + ] + + if not linux_id: + if set(hardware) & BCM_RANGE: + linux_id = BCM2XXX + elif 'AM33XX' in hardware: + linux_id = AM33XX + elif 'sun8i' in hardware: + linux_id = SUN8I + elif 'ODROIDC' in hardware: + linux_id = S805 + elif 'ODROID-C2' in hardware: + linux_id = S905 + elif 'ODROID-N2' in hardware: + linux_id = S922X + elif 'SAMA5' in hardware: + linux_id = SAMA5 return linux_id From c3e9a58f9e9418acd123920f41f1d70bca497789 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 20 Oct 2019 11:20:36 -0500 Subject: [PATCH 3/8] attempt to detect the 'board_id' on RPi when running a non-Raspbian OS --- adafruit_platformdetect/board.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index d528873d..9b1de710 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -1,5 +1,6 @@ """Detect boards.""" import os +import re import adafruit_platformdetect.chip as ap_chip # Allow for aligned constant definitions: @@ -344,6 +345,30 @@ def _pi_id(self): for model, codes in _PI_REV_CODES.items(): if pi_rev_code in codes: return model + + # We may be on a non-Raspbian OS, so try to lazily determine + # the version based on `get_device_model` + else: + pi_model = self.detector.get_device_model() + if pi_model: + pi_model = pi_model.upper().replace(' ', '_') + if "PLUS" in pi_model: + re_model = re.search(r'(RASPBERRY_PI_\d).*([AB]_*)(PLUS)', + pi_model) + elif "CM" in pi_model: # untested for Compute Module + re_model = re.search(r'(RASPBERRY_PI_CM)(\d)', + pi_model) + else: # untested for non-plus models + re_model = re.search(r'(RASPBERRY_PI_\d).*([AB]_*)', + pi_model) + + if re_model: + pi_model = "".join(re_model.groups()) + available_models = _PI_REV_CODES.keys() + for model in available_models: + if model == pi_model: + return model + return None def _pi_rev_code(self): From 4edd8858aedf60c19cfa8ad6351dacbe5a6910fb Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 20 Oct 2019 14:29:23 -0500 Subject: [PATCH 4/8] one last style edit --- adafruit_platformdetect/chip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 14a63a6b..73cda2d3 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -102,7 +102,7 @@ def _linux_id(self): # pylint: disable=too-many-branches # conditions attempt. if not linux_id: hardware = [ - entry.replace("\x00", "") for entry in compatible.split(",") + entry.replace('\x00', '') for entry in compatible.split(',') ] if not linux_id: From e310984783218b26f5776c7361f1e1301c0705f2 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 21 Oct 2019 22:55:54 -0500 Subject: [PATCH 5/8] chip.py: accomodate either the str or list version of 'hardware' result --- adafruit_platformdetect/chip.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 73cda2d3..0380ba91 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -106,9 +106,7 @@ def _linux_id(self): # pylint: disable=too-many-branches ] if not linux_id: - if set(hardware) & BCM_RANGE: - linux_id = BCM2XXX - elif 'AM33XX' in hardware: + if 'AM33XX' in hardware: linux_id = AM33XX elif 'sun8i' in hardware: linux_id = SUN8I @@ -120,6 +118,13 @@ def _linux_id(self): # pylint: disable=too-many-branches linux_id = S922X elif 'SAMA5' in hardware: linux_id = SAMA5 + else: + if isinstance(hardware, str): + if hardware in BCM_RANGE: + linux_id = BCM2XXX + elif instance(hardware, list): + if set(hardware) & BCM_RANGE: + linux_id = BCM2XXX return linux_id From 8c64f6fc31eaea9ec65e5b6611092a977549ed2e Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 22 Oct 2019 08:51:58 -0500 Subject: [PATCH 6/8] fix late-night keyword mangle --- adafruit_platformdetect/chip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 0380ba91..843367ba 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -122,7 +122,7 @@ def _linux_id(self): # pylint: disable=too-many-branches if isinstance(hardware, str): if hardware in BCM_RANGE: linux_id = BCM2XXX - elif instance(hardware, list): + elif isinstance(hardware, list): if set(hardware) & BCM_RANGE: linux_id = BCM2XXX From 633a4a92c9ad93c822ff402ef27697f69ab608b6 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 30 Dec 2019 17:32:25 -0600 Subject: [PATCH 7/8] re-add chip.py::BCM_RANGE after merge conflict --- adafruit_platformdetect/chip.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 59c6c900..7c22fb3a 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -23,6 +23,9 @@ MCP2221 = "MCP2221" BINHO = "BINHO" +BCM_RANGE = {'BCM2708', 'BCM2709', 'BCM2835', 'BCM2837', 'bcm2708', 'bcm2709', + 'bcm2835', 'bcm2837'} + class Chip: """Attempt detection of current chip / CPU.""" def __init__(self, detector): From d943f9564678c7d2732ac45ad439f3f0d143f1ca Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 3 Jan 2020 17:52:01 -0600 Subject: [PATCH 8/8] re-add stuff after more merge conflict fixes --- adafruit_platformdetect/board.py | 25 +++++++++++++++++++ adafruit_platformdetect/chip.py | 42 +++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index 4caff304..3c74b74d 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -1,5 +1,6 @@ """Detect boards.""" import os +import re import adafruit_platformdetect.chip as ap_chip # Allow for aligned constant definitions: @@ -367,6 +368,30 @@ def _pi_id(self): for model, codes in _PI_REV_CODES.items(): if pi_rev_code in codes: return model + + # We may be on a non-Raspbian OS, so try to lazily determine + # the version based on `get_device_model` + else: + pi_model = self.detector.get_device_model() + if pi_model: + pi_model = pi_model.upper().replace(' ', '_') + if "PLUS" in pi_model: + re_model = re.search(r'(RASPBERRY_PI_\d).*([AB]_*)(PLUS)', + pi_model) + elif "CM" in pi_model: # untested for Compute Module + re_model = re.search(r'(RASPBERRY_PI_CM)(\d)', + pi_model) + else: # untested for non-plus models + re_model = re.search(r'(RASPBERRY_PI_\d).*([AB]_*)', + pi_model) + + if re_model: + pi_model = "".join(re_model.groups()) + available_models = _PI_REV_CODES.keys() + for model in available_models: + if model == pi_model: + return model + return None def _pi_rev_code(self): diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index a4450eea..ad5ad5b5 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -115,20 +115,34 @@ def _linux_id(self): # pylint: disable=too-many-branches elif "MIPS 24KEc" in cpu_model: linux_id = MIPS24KEC - elif hardware in ("BCM2708", "BCM2709", "BCM2835"): - linux_id = BCM2XXX - elif "AM33XX" in hardware: - linux_id = AM33XX - elif "sun8i" in hardware: - linux_id = SUN8I - elif "ODROIDC" in hardware: - linux_id = S805 - elif "ODROID-C2" in hardware: - linux_id = S905 - elif "ODROID-N2" in hardware: - linux_id = S922X - elif "SAMA5" in hardware: - linux_id = SAMA5 + # we still haven't identified the hardware, so + # convert it to a list and let the remaining + # conditions attempt. + if not linux_id: + hardware = [ + entry.replace('\x00', '') for entry in compatible.split(',') + ] + + if not linux_id: + if 'AM33XX' in hardware: + linux_id = AM33XX + elif 'sun8i' in hardware: + linux_id = SUN8I + elif 'ODROIDC' in hardware: + linux_id = S805 + elif 'ODROID-C2' in hardware: + linux_id = S905 + elif 'ODROID-N2' in hardware: + linux_id = S922X + elif 'SAMA5' in hardware: + linux_id = SAMA5 + else: + if isinstance(hardware, str): + if hardware in BCM_RANGE: + linux_id = BCM2XXX + elif isinstance(hardware, list): + if set(hardware) & BCM_RANGE: + linux_id = BCM2XXX return linux_id