X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/1b0742ea4dd827c3f9217dab1dca35fbec100dce..8e3d2a9bb2216ea6f74c54d440513c646c784b22:/src/adafruit_blinka/microcontroller/amlogic/meson_g12_common/pin.py diff --git a/src/adafruit_blinka/microcontroller/amlogic/meson_g12_common/pin.py b/src/adafruit_blinka/microcontroller/amlogic/meson_g12_common/pin.py index d920b1f..41cf8f2 100644 --- a/src/adafruit_blinka/microcontroller/amlogic/meson_g12_common/pin.py +++ b/src/adafruit_blinka/microcontroller/amlogic/meson_g12_common/pin.py @@ -11,6 +11,8 @@ Linux kernel 5.4.y (mainline) linux/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi """ +from typing import Optional +import os import re import gpiod from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin @@ -110,18 +112,18 @@ UART1_RX = GPIOX_13 uartPorts = ((1, UART1_TX, UART1_RX),) -def get_dts_alias(device: str) -> str: +def get_dts_alias(device: str) -> Optional[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 + if os.path.exists(uevent_path): + 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