]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/amlogic/a311d/pin.py
amlogic/a311d: Import get_dts_alias and eliminate duplicate function
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / amlogic / a311d / pin.py
index 5d5ed23f2ac759941c994348736d03d5eb42bd80..3213e38e38170e34061a8b06eada8a99e7af70bf 100644 (file)
@@ -11,21 +11,24 @@ Linux kernel 5.4.y (mainline)
     linux/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi
 """
 
     linux/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi
 """
 
-import re
 import gpiod
 import gpiod
+from adafruit_blinka.microcontroller.alias import get_dts_alias
 from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
 
 from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
 
-chip0 = gpiod.chip("0")
-chip1 = gpiod.chip("1")
+chip0 = gpiod.Chip("0")
+chip1 = gpiod.Chip("1")
 
 
-if chip0.num_lines < 20:
+if chip0.num_lines() < 20:
     aobus = 0
     periphs = 1
     aobus = 0
     periphs = 1
-    periphs_offset = chip1.num_lines - 85
+    periphs_offset = chip1.num_lines() - 85
 else:
     aobus = 1
     periphs = 0
 else:
     aobus = 1
     periphs = 0
-    periphs_offset = chip0.num_lines - 85
+    periphs_offset = chip0.num_lines() - 85
+
+chip0.close()
+chip1.close()
 
 GPIOAO_0 = GPIO496 = Pin((aobus, 0))
 GPIOAO_1 = GPIO497 = Pin((aobus, 1))
 
 GPIOAO_0 = GPIO496 = Pin((aobus, 0))
 GPIOAO_1 = GPIO497 = Pin((aobus, 1))
@@ -149,21 +152,6 @@ UART1_RX = GPIOH_6
 # ordered as uartId, txId, rxId
 uartPorts = ((1, UART1_TX, UART1_RX),)
 
 # ordered as uartId, txId, rxId
 uartPorts = ((1, UART1_TX, UART1_RX),)
 
-
-def get_dts_alias(device: str) -> str:
-    """Get the Device Tree Alias"""
-    uevent_path = "/sys/bus/platform/devices/" + device + "/uevent"
-    with open(uevent_path, "r", encoding="utf-8") as fd:
-        pattern = r"^OF_ALIAS_0=(.*)$"
-        uevent = fd.read().split("\n")
-        for line in uevent:
-            match = re.search(pattern, line)
-            if match:
-                return match.group(1).upper()
-
-        return None
-
-
 # ordered as i2cId, sclId, sdaId
 i2cPorts = []
 
 # ordered as i2cId, sclId, sdaId
 i2cPorts = []