From 9e94212401114a95fa97462b787801302cf0c241 Mon Sep 17 00:00:00 2001 From: djhedges Date: Thu, 21 Jul 2022 20:53:52 -0700 Subject: [PATCH] Only read the i2c events if the exist. On the Bananan Pi M5 the ffd1c000.i2c is non-existent. --- .../amlogic/meson_g12_common/pin.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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..31ff8e1 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,7 @@ Linux kernel 5.4.y (mainline) linux/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi """ +import os import re import gpiod from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin @@ -113,15 +114,16 @@ 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 + 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 -- 2.49.0