X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/2982747631256df8d29f689e814f0b5962d13c57..3746b1b4aef900105cc9cfa19cada6692d5eb94e:/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 cf7b479..1019b59 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -2,11 +2,14 @@ # # SPDX-License-Identifier: MIT """Allwinner H618 Pin Names""" +import re from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin + def find_gpiochip_number(target_label): + """Get correct gpiochip number, legacy kernel and mainline kernel are different""" try: - with open('/sys/kernel/debug/gpio', 'r') as f: + with open("/sys/kernel/debug/gpio", "r") as f: lines = f.readlines() except FileNotFoundError: print("The file /sys/kernel/debug/gpio does not exist.") @@ -15,17 +18,18 @@ def find_gpiochip_number(target_label): gpiochip_number = None for line in lines: if target_label in line: - parts = line.split() - for part in parts: - if part.startswith('gpiochip'): - gpiochip_number = part[len('gpiochip'):] - break - break + match = re.search(r"gpiochip(\d+)", line) + if match: + gpiochip_number = match.group(1) + break return gpiochip_number -__chip_num = 1 -__chip_num = gpiochip_number = find_gpiochip_number("300b000.pinctrl") + +if find_gpiochip_number("300b000.pinctrl"): + __chip_num = 1 +else: + __chip_num = 0 PC0 = Pin((__chip_num, 64)) SPI0_SCLK = PC0 @@ -82,6 +86,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)) @@ -123,6 +128,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)) @@ -149,3 +155,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), +]