]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/agnostic/__init__.py
Added pre-commit support
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / agnostic / __init__.py
index 1d93e6c9bdfe7f604784afc29fc30566c5c8c701..14121d3796e7e866cf6243ff1d6a679aa15ba24f 100755 (executable)
@@ -1,3 +1,6 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """Allows useful indirection to test Pin naming logic by switching platform in testing
     or provide bootstrapping logic for board identification where auto-detection is not
     feasible (e.g. multiple ESP8266 boards architecturally identical). Once runtime
@@ -5,46 +8,21 @@
     common modules and operations, depending on platform support
 """
 import sys
+import adafruit_platformdetect
 
 # We intentionally are patching into this namespace as module names so skip the name check.
 # pylint: disable=invalid-name
-platform = sys.platform
 
-board_id = None
+# We'll define board and chip id values in agnostic rather than accessing
+# detector directly elsewhere, just in case additional indirection is necessary
+# at some later point:
 
-if platform is not None:
-    if platform == "esp8266":  # TODO more conservative board-guessing
-        board_id = "feather_huzzah"
-    elif platform == "samd21":
-        board_id = "feather_m0_express"
-    elif platform == "pyboard":
-        platform = "stm32"
-        board_id = "pyboard"
-    elif platform == "linux":
-        import re
-        # we're going to redo the Platform detection, this is a terrible hack
-        # for now.
-        try:
-            # lets see if we're an armbian board
-            for line in open("/etc/armbian-release", 'r'):
-                #print(line)
-                m = re.search('BOARD=(.*)', line)
-                if m:
-                    board_id = m.group(1)
-        except:
-            from Adafruit_GPIO import Platform
-            if Platform.platform_detect() == Platform.RASPBERRY_PI:
-                if Platform.pi_version() == 1:
-                    board_id = "raspi_1"
-                elif Platform.pi_version() == 2:
-                    board_id = "raspi_2"
-                elif Platform.pi_version() == 3:
-                    board_id = "raspi_3"
-            elif Platform.platform_detect() == Platform.BEAGLEBONE_BLACK:
-                board_id = "beaglebone_black"
+detector = adafruit_platformdetect.Detector()
+chip_id = detector.chip.id
+board_id = detector.board.id
 
 implementation = sys.implementation.name
 if implementation == "micropython":
     from utime import sleep
-elif implementation == "circuitpython" or implementation == "cpython":
+elif implementation in ("circuitpython", "cpython"):
     from time import sleep