X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/2152c18a1e8ec87e45ca2a273819fbde777d4415..f423f596aa463df62cb25e33ff9fbe9702a2f411:/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py index 7eabaa2..ab32a88 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -2,14 +2,31 @@ # # SPDX-License-Identifier: MIT """Allwinner H618 Pin Names""" +import re from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin -# gpiochip select -__chip_num = 0 -with open("/sys/class/gpio/gpiochip0/label", "r") as f: - label = f.read().strip() - if label == "300b000.pinctrl": - __chip_num = 1 +def find_gpiochip_number(target_label): + try: + with open('/sys/kernel/debug/gpio', 'r') as f: + lines = f.readlines() + except FileNotFoundError: + print("The file /sys/kernel/debug/gpio does not exist.") + return None + + gpiochip_number = None + for line in lines: + if target_label in line: + match = re.search(r'gpiochip(\d+)', line) + if match: + gpiochip_number = match.group(1) + break + + return gpiochip_number + +if find_gpiochip_number("300b000.pinctrl"): + __chip_num = 1 +else: + __chip_num = 0 PC0 = Pin((__chip_num, 64)) SPI0_SCLK = PC0 @@ -66,6 +83,7 @@ TWI3_SCL = PG17 PG18 = Pin((__chip_num, 210)) TWI3_SDA = PG18 PG19 = Pin((__chip_num, 211)) +PWM1 = PG19 PH0 = Pin((__chip_num, 224)) PH1 = Pin((__chip_num, 225)) @@ -107,6 +125,7 @@ PI10 = Pin((__chip_num, 266)) UART3_RX = PI10 PI11 = Pin((__chip_num, 267)) PI12 = Pin((__chip_num, 268)) +PWM2 = PI12 PI13 = Pin((__chip_num, 269)) UART4_TX = PI13 PI14 = Pin((__chip_num, 270)) @@ -133,3 +152,9 @@ uartPorts = ( (4, UART4_TX, UART4_RX), (5, UART5_TX, UART5_RX), ) + +# SysFS pwm outputs, pwm channel and pin in first tuple +pwmOuts = [ + ((0, 1), PWM1), + ((0, 2), PWM2), +]