]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/alias.py
Fixed requirements to use setup.py and rpi-lgpio for the gpio
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / alias.py
index 7347242fbccf283e1add4baca87d0c5e89ab2658..36869196661ba4e5113c0fcdc65e47ce5a54afe8 100644 (file)
@@ -2,10 +2,16 @@
 #
 # SPDX-License-Identifier: MIT
 
+"""
+Functions to find aliases for all hardware,
+including those defined in the device tree.
+"""
+
 from typing import Optional
 import os
 import re
 
+
 def get_dts_alias(device: str) -> Optional[str]:
     """Get the Device Tree Alias"""
     uevent_path = "/sys/bus/platform/devices/" + device + "/uevent"
@@ -18,3 +24,15 @@ def get_dts_alias(device: str) -> Optional[str]:
                 if match:
                     return match.group(1).upper()
     return None
+
+
+def get_pwm_chipid(device: str):
+    """Get the PWM Chip ID"""
+    for chipid in range(32):
+        pwm_sys_path = "/sys/class/pwm/pwmchip{}".format(chipid)
+        if not os.path.exists(pwm_sys_path):
+            continue
+        if device in os.path.realpath(pwm_sys_path):
+            alias = "PWM" + str(chipid)
+            return alias
+    return None