]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
microcontroller/alias: Add function for getting pwm chip id.
authorSteve Jeong <steve@how2flow.net>
Thu, 7 Dec 2023 06:44:15 +0000 (06:44 +0000)
committerSteve Jeong <steve@how2flow.net>
Tue, 12 Dec 2023 03:14:34 +0000 (03:14 +0000)
Signed-off-by: Steve Jeong <steve@how2flow.net>
src/adafruit_blinka/microcontroller/alias.py

index ab5067e2d60b8a5acde2bc82b28a3807b4b4277c..c6cc796c78fe1388b4367899e2c476123d15d55d 100644 (file)
@@ -3,7 +3,8 @@
 # SPDX-License-Identifier: MIT
 
 """
-Device Tree Alias Functions
+Functions to find aliases for all hardware,
+including those defined in the device tree.
 """
 
 from typing import Optional
@@ -23,3 +24,14 @@ 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