From 2152c18a1e8ec87e45ca2a273819fbde777d4415 Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Sat, 31 Aug 2024 23:43:17 +0800 Subject: [PATCH 01/10] support allwinner h618 chip and bananapi m4berry and m4zero board --- .../board/bananapi/bpim4berry.py | 71 +++++++++ .../board/bananapi/bpim4zero.py | 71 +++++++++ .../allwinner/h618/__init__.py | 4 + .../microcontroller/allwinner/h618/pin.py | 135 ++++++++++++++++++ src/board.py | 6 + src/digitalio.py | 2 + src/microcontroller/__init__.py | 2 + src/microcontroller/pin.py | 2 + 8 files changed, 293 insertions(+) create mode 100644 src/adafruit_blinka/board/bananapi/bpim4berry.py create mode 100644 src/adafruit_blinka/board/bananapi/bpim4zero.py create mode 100644 src/adafruit_blinka/microcontroller/allwinner/h618/__init__.py create mode 100644 src/adafruit_blinka/microcontroller/allwinner/h618/pin.py diff --git a/src/adafruit_blinka/board/bananapi/bpim4berry.py b/src/adafruit_blinka/board/bananapi/bpim4berry.py new file mode 100644 index 00000000..cfed3a31 --- /dev/null +++ b/src/adafruit_blinka/board/bananapi/bpim4berry.py @@ -0,0 +1,71 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT +"""Pin definitions for the Banana Pi M4 Berry.""" + +from adafruit_blinka.microcontroller.allwinner.h618 import pin + +# I2C +I2C3_SCL = pin.TWI3_SCL +I2C3_SDA = pin.TWI3_SDA +I2C4_SCL = pin.TWI4_SCL +I2C4_SDA = pin.TWI4_SDA + +# Default I2C +SCL = I2C4_SCL +SDA = I2C4_SDA + +# UART +UART1_TX = pin.UART1_TX +UART1_RX = pin.UART1_RX +UART5_TX = pin.UART5_TX +UART5_RX = pin.UART5_RX + +# Default UART +TX = UART1_TX +RX = UART1_RX +TXD = UART1_TX +RXD = UART1_RX + +# SPI +SPI1_MOSI = pin.SPI1_MOSI +SPI1_MISO = pin.SPI1_MISO +SPI1_SCLK = pin.SPI1_SCLK +SPI1_CS0 = pin.SPI1_CS0 + +# Default SPI +MOSI = SPI1_MOSI +MISO = SPI1_MISO +SCLK = SPI1_SCLK +CS = SPI1_CS0 + +# Pinout reference: +# https://wiki.banana-pi.org/Banana_Pi_BPI-M4_Berry#BPI-M4_Berry_40-pin_header +PG16 = pin.PG16 +PG15 = pin.PG15 +PG19 = pin.PG19 +PG6 = pin.PG6 +PG7 = pin.PG7 +PH2 = pin.PH2 +PG11 = pin.PG11 +PH3 = pin.PH3 +PG2 = pin.PG2 +PG8 = pin.PG8 +PG9 = pin.PG9 +PH7 = pin.PH7 +PH8 = pin.PH8 +PG1 = pin.PG1 +PH6 = pin.PH6 +PH5 = pin.PH5 +PH9 = pin.PH9 +PG18 = pin.PG18 +PG17 = pin.PG17 +PG3 = pin.PG3 +PG4 = pin.PG4 +PG0 = pin.PG0 +PG5 = pin.PG5 +PG12 = pin.PG12 +PH4 = pin.PH4 +PG10 = pin.PG10 +PG14 = pin.PG14 +PG13 = pin.PG13 diff --git a/src/adafruit_blinka/board/bananapi/bpim4zero.py b/src/adafruit_blinka/board/bananapi/bpim4zero.py new file mode 100644 index 00000000..bd2e553c --- /dev/null +++ b/src/adafruit_blinka/board/bananapi/bpim4zero.py @@ -0,0 +1,71 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT +"""Pin definitions for the Banana Pi M4 Zero.""" + +from adafruit_blinka.microcontroller.allwinner.h618 import pin + +# I2C +I2C0_SCL = pin.TWI0_SCL +I2C0_SDA = pin.TWI0_SDA +I2C1_SCL = pin.TWI1_SCL +I2C1_SDA = pin.TWI1_SDA + +# Default I2C +SCL = I2C0_SCL +SDA = I2C0_SDA + +# UART +UART4_TX = pin.UART4_TX +UART4_RX = pin.UART4_RX +UART5_TX = pin.UART5_TX +UART5_RX = pin.UART5_RX + +# Default UART +TX = UART4_TX +RX = UART4_RX +TXD = UART4_TX +RXD = UART4_RX + +# SPI +SPI1_MOSI = pin.SPI1_MOSI +SPI1_MISO = pin.SPI1_MISO +SPI1_SCLK = pin.SPI1_SCLK +SPI1_CS0 = pin.SPI1_CS0 + +# Default SPI +MOSI = SPI1_MOSI +MISO = SPI1_MISO +SCLK = SPI1_SCLK +CS = SPI1_CS0 + +# Pinout reference: +# https://wiki.banana-pi.org/Banana_Pi_BPI-M4_Zero#BPI-M4_Zero_40-pin_header +D3 = pin.PI6 +D5 = pin.PI5 +D7 = pin.PI12 +D8 = pin.PI13 +D10 = pin.PI14 +D11 = pin.PH2 +D12 = pin.PI1 +D13 = pin.PH3 +D15 = pin.PI11 +D16 = pin.PI15 +D18 = pin.PI16 +D19 = pin.PH7 +D21 = pin.PH8 +D22 = pin.PC2 +D23 = pin.PH6 +D24 = pin.PH5 +D26 = pin.PH9 +D27 = pin.PI8 +D28 = pin.PI7 +D29 = pin.PI10 +D31 = pin.PI9 +D32 = pin.PH4 +D33 = pin.PH10 +D35 = pin.PI2 +D36 = pin.PC7 +D37 = pin.PI0 +D38 = pin.PI4 +D40 = pin.PI3 diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/__init__.py b/src/adafruit_blinka/microcontroller/allwinner/h618/__init__.py new file mode 100644 index 00000000..bb4a91e0 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/__init__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT +"""Definition for the AllWinner H618 chip""" diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py new file mode 100644 index 00000000..7eabaa27 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -0,0 +1,135 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT +"""Allwinner H618 Pin Names""" +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 + +PC0 = Pin((__chip_num, 64)) +SPI0_SCLK = PC0 +PC1 = Pin((__chip_num, 65)) +PC2 = Pin((__chip_num, 66)) +SPI0_MOSI = PC2 +PC3 = Pin((__chip_num, 67)) +SPI0_CS0 = PC3 +PC4 = Pin((__chip_num, 68)) +SPI0_MISO = PC4 +PC5 = Pin((__chip_num, 69)) +PC6 = Pin((__chip_num, 70)) +PC7 = Pin((__chip_num, 71)) +PC8 = Pin((__chip_num, 72)) +PC9 = Pin((__chip_num, 73)) +PC10 = Pin((__chip_num, 74)) +PC11 = Pin((__chip_num, 75)) +PC12 = Pin((__chip_num, 76)) +PC13 = Pin((__chip_num, 77)) +PC14 = Pin((__chip_num, 78)) +PC15 = Pin((__chip_num, 79)) + +PF0 = Pin((__chip_num, 160)) +PF1 = Pin((__chip_num, 161)) +PF2 = Pin((__chip_num, 162)) +PF3 = Pin((__chip_num, 163)) +PF4 = Pin((__chip_num, 164)) +PF5 = Pin((__chip_num, 165)) +PF6 = Pin((__chip_num, 166)) + +PG0 = Pin((__chip_num, 192)) +PG1 = Pin((__chip_num, 193)) +PG2 = Pin((__chip_num, 194)) +PG3 = Pin((__chip_num, 195)) +PG4 = Pin((__chip_num, 196)) +PG5 = Pin((__chip_num, 197)) +PG6 = Pin((__chip_num, 198)) +UART1_TX = PG6 +PG7 = Pin((__chip_num, 199)) +UART1_RX = PG7 +PG8 = Pin((__chip_num, 200)) +PG9 = Pin((__chip_num, 201)) +PG10 = Pin((__chip_num, 202)) +PG11 = Pin((__chip_num, 203)) +PG12 = Pin((__chip_num, 204)) +PG13 = Pin((__chip_num, 205)) +PG14 = Pin((__chip_num, 206)) +PG15 = Pin((__chip_num, 207)) +TWI4_SCL = PG15 +PG16 = Pin((__chip_num, 208)) +TWI4_SDA = PG16 +PG17 = Pin((__chip_num, 209)) +TWI3_SCL = PG17 +PG18 = Pin((__chip_num, 210)) +TWI3_SDA = PG18 +PG19 = Pin((__chip_num, 211)) + +PH0 = Pin((__chip_num, 224)) +PH1 = Pin((__chip_num, 225)) +PH2 = Pin((__chip_num, 226)) +UART5_TX = PH2 +PH3 = Pin((__chip_num, 227)) +UART5_RX = PH3 +PH4 = Pin((__chip_num, 228)) +PH5 = Pin((__chip_num, 229)) +UART2_TX = PH5 +SPI1_CS0 = PH5 +PH6 = Pin((__chip_num, 230)) +UART2_RX = PH6 +SPI1_SCLK = PH6 +PH7 = Pin((__chip_num, 231)) +SPI1_MOSI = PH7 +PH8 = Pin((__chip_num, 232)) +SPI1_MISO = PH8 +PH9 = Pin((__chip_num, 233)) +SPI1_CS1 = PH9 +PH10 = Pin((__chip_num, 234)) + +PI0 = Pin((__chip_num, 256)) +PI1 = Pin((__chip_num, 257)) +PI2 = Pin((__chip_num, 258)) +PI3 = Pin((__chip_num, 259)) +PI4 = Pin((__chip_num, 260)) +PI5 = Pin((__chip_num, 261)) +TWI0_SCL = PI5 +PI6 = Pin((__chip_num, 262)) +TWI0_SDA = PI6 +PI7 = Pin((__chip_num, 263)) +TWI1_SCL = PI7 +PI8 = Pin((__chip_num, 264)) +TWI1_SDA = PI8 +PI9 = Pin((__chip_num, 265)) +UART3_TX = PI9 +PI10 = Pin((__chip_num, 266)) +UART3_RX = PI10 +PI11 = Pin((__chip_num, 267)) +PI12 = Pin((__chip_num, 268)) +PI13 = Pin((__chip_num, 269)) +UART4_TX = PI13 +PI14 = Pin((__chip_num, 270)) +UART4_RX = PI14 +PI15 = Pin((__chip_num, 271)) +PI16 = Pin((__chip_num, 272)) + +i2cPorts = ( + (0, TWI0_SCL, TWI0_SDA), + (1, TWI1_SCL, TWI1_SDA), + (3, TWI3_SCL, TWI3_SDA), + (4, TWI4_SCL, TWI4_SDA), +) +# ordered as spiId, sckId, mosiId, misoId +spiPorts = ( + (0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO), + (1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO), +) +# ordered as uartId, txId, rxId +uartPorts = ( + (1, UART1_TX, UART1_RX), + (2, UART2_TX, UART2_RX), + (3, UART3_TX, UART3_RX), + (4, UART4_TX, UART4_RX), + (5, UART5_TX, UART5_RX), +) diff --git a/src/board.py b/src/board.py index 8105fd41..14f600a0 100644 --- a/src/board.py +++ b/src/board.py @@ -152,6 +152,12 @@ elif board_id == ap_board.BANANA_PI_M2_PLUS: from adafruit_blinka.board.bananapi.bpim2plus import * +elif board_id == ap_board.BANANA_PI_M4_BERRY: + from adafruit_blinka.board.bananapi.bpim4berry import * + +elif board_id == ap_board.BANANA_PI_M4_ZERO: + from adafruit_blinka.board.bananapi.bpim4zero import * + elif board_id == ap_board.BANANA_PI_M5: from adafruit_blinka.board.bananapi.bpim5 import * diff --git a/src/digitalio.py b/src/digitalio.py index 46f23a64..6f92fc53 100644 --- a/src/digitalio.py +++ b/src/digitalio.py @@ -111,6 +111,8 @@ from adafruit_blinka.microcontroller.allwinner.h5.pin import Pin elif detector.chip.H6: from adafruit_blinka.microcontroller.allwinner.h6.pin import Pin +elif detector.chip.H618: + from adafruit_blinka.microcontroller.allwinner.h618.pin import Pin elif detector.chip.H616: from adafruit_blinka.microcontroller.allwinner.h616.pin import Pin elif detector.chip.D1_RISCV: diff --git a/src/microcontroller/__init__.py b/src/microcontroller/__init__.py index 036fbc9e..ea0b5e28 100644 --- a/src/microcontroller/__init__.py +++ b/src/microcontroller/__init__.py @@ -61,6 +61,8 @@ def delay_us(delay): from adafruit_blinka.microcontroller.allwinner.h5 import * elif chip_id == ap_chip.H6: from adafruit_blinka.microcontroller.allwinner.h6 import * +elif chip_id == ap_chip.H618: + from adafruit_blinka.microcontroller.allwinner.h618 import * elif chip_id == ap_chip.H616: from adafruit_blinka.microcontroller.allwinner.h616 import * elif chip_id == ap_chip.SAMA5: diff --git a/src/microcontroller/pin.py b/src/microcontroller/pin.py index 5872271f..bdc5a8d7 100644 --- a/src/microcontroller/pin.py +++ b/src/microcontroller/pin.py @@ -51,6 +51,8 @@ from adafruit_blinka.microcontroller.allwinner.h5.pin import * elif chip_id == ap_chip.H6: from adafruit_blinka.microcontroller.allwinner.h6.pin import * +elif chip_id == ap_chip.H618: + from adafruit_blinka.microcontroller.allwinner.h618.pin import * elif chip_id == ap_chip.H616: if board_id == ap_boards.REPKA_PI_4_H6: from adafruit_blinka.board.repkapi.repka_pi_4 import * From 1cf5367a437518d62f44c626e4d684a0faa0e853 Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:01:10 +0800 Subject: [PATCH 02/10] bpim4berry: restore pin define --- .../board/bananapi/bpim4berry.py | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/adafruit_blinka/board/bananapi/bpim4berry.py b/src/adafruit_blinka/board/bananapi/bpim4berry.py index cfed3a31..b220718a 100644 --- a/src/adafruit_blinka/board/bananapi/bpim4berry.py +++ b/src/adafruit_blinka/board/bananapi/bpim4berry.py @@ -41,31 +41,31 @@ # Pinout reference: # https://wiki.banana-pi.org/Banana_Pi_BPI-M4_Berry#BPI-M4_Berry_40-pin_header -PG16 = pin.PG16 -PG15 = pin.PG15 -PG19 = pin.PG19 -PG6 = pin.PG6 -PG7 = pin.PG7 -PH2 = pin.PH2 -PG11 = pin.PG11 -PH3 = pin.PH3 -PG2 = pin.PG2 -PG8 = pin.PG8 -PG9 = pin.PG9 -PH7 = pin.PH7 -PH8 = pin.PH8 -PG1 = pin.PG1 -PH6 = pin.PH6 -PH5 = pin.PH5 -PH9 = pin.PH9 -PG18 = pin.PG18 -PG17 = pin.PG17 -PG3 = pin.PG3 -PG4 = pin.PG4 -PG0 = pin.PG0 -PG5 = pin.PG5 -PG12 = pin.PG12 -PH4 = pin.PH4 -PG10 = pin.PG10 -PG14 = pin.PG14 -PG13 = pin.PG13 +D3 = pin.PG16 +D5 = pin.PG15 +D7 = pin.PG19 +D8 = pin.PG6 +D10 = pin.PG7 +D11 = pin.PH2 +D12 = pin.PG11 +D13 = pin.PH3 +D15 = pin.PG2 +D16 = pin.PG8 +D18 = pin.PG9 +D19 = pin.PH7 +D21 = pin.PH8 +D22 = pin.PG1 +D23 = pin.PH6 +D24 = pin.PH5 +D26 = pin.PH9 +D27 = pin.PG18 +D28 = pin.PG17 +D29 = pin.PG3 +D31 = pin.PG4 +D32 = pin.PG0 +D33 = pin.PG5 +D35 = pin.PG12 +D36 = pin.PH4 +D37 = pin.PG10 +D38 = pin.PG14 +D40 = pin.PG13 From 2982747631256df8d29f689e814f0b5962d13c57 Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:36:38 +0800 Subject: [PATCH 03/10] allwinner h618: support mainline gpiochip --- .../microcontroller/allwinner/h618/pin.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py index 7eabaa27..cf7b4798 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -4,12 +4,28 @@ """Allwinner H618 Pin Names""" 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: + parts = line.split() + for part in parts: + if part.startswith('gpiochip'): + gpiochip_number = part[len('gpiochip'):] + break + break + + return gpiochip_number + +__chip_num = 1 +__chip_num = gpiochip_number = find_gpiochip_number("300b000.pinctrl") PC0 = Pin((__chip_num, 64)) SPI0_SCLK = PC0 From 73a4af98827cef92fb5bd4f7a5ed63686bde31f8 Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Tue, 3 Sep 2024 01:26:36 +0800 Subject: [PATCH 04/10] allwinner h618: support mainline gpiochip --- .../microcontroller/allwinner/h618/pin.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py index cf7b4798..34fdb6e1 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: MIT """Allwinner H618 Pin Names""" from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin +import re def find_gpiochip_number(target_label): try: @@ -15,12 +16,10 @@ 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 From 2092c8bddf8d8a89f4325df1c268138f22cac53f Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:04:34 +0800 Subject: [PATCH 05/10] allwinner h618: fix get wrong chip number in venv --- src/adafruit_blinka/microcontroller/allwinner/h618/pin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py index 34fdb6e1..fdbdcc63 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -23,8 +23,10 @@ def find_gpiochip_number(target_label): 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 From 18c14b917ecfc19b64a831aad6aa563c2b9390aa Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:14:03 +0800 Subject: [PATCH 06/10] allwinner h618: support pwm --- src/adafruit_blinka/microcontroller/allwinner/h618/pin.py | 8 ++++++++ src/pwmio.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py index fdbdcc63..426f38d6 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -83,6 +83,7 @@ def find_gpiochip_number(target_label): 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)) @@ -124,6 +125,7 @@ def find_gpiochip_number(target_label): 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)) @@ -150,3 +152,9 @@ def find_gpiochip_number(target_label): (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), +] diff --git a/src/pwmio.py b/src/pwmio.py index 6935ac1a..72ce0d89 100644 --- a/src/pwmio.py +++ b/src/pwmio.py @@ -18,6 +18,8 @@ if detector.board.any_raspberry_pi: from adafruit_blinka.microcontroller.bcm283x.pwmio.PWMOut import PWMOut +elif detector.board.any_bananapi: + from adafruit_blinka.microcontroller.generic_linux.sysfs_pwmout import PWMOut elif detector.board.any_coral_board: from adafruit_blinka.microcontroller.generic_linux.sysfs_pwmout import PWMOut elif detector.board.any_giant_board: From 41b183d45263e45c8f7ee5b6f942edd22c2b2cd3 Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Tue, 3 Sep 2024 19:31:44 +0800 Subject: [PATCH 07/10] support spacemit k1, bananapif3 --- src/adafruit_blinka/board/bananapi/bpif3.py | 56 ++++++ .../rockchip/rk3566/.pin.py.swp | Bin 0 -> 16384 bytes .../microcontroller/spacemit/__init__.py | 4 + .../microcontroller/spacemit/k1/__init__.py | 4 + .../microcontroller/spacemit/k1/pin.py | 180 ++++++++++++++++++ src/board.py | 3 + src/digitalio.py | 2 + src/microcontroller/__init__.py | 2 + src/microcontroller/pin.py | 2 + 9 files changed, 253 insertions(+) create mode 100644 src/adafruit_blinka/board/bananapi/bpif3.py create mode 100644 src/adafruit_blinka/microcontroller/rockchip/rk3566/.pin.py.swp create mode 100644 src/adafruit_blinka/microcontroller/spacemit/__init__.py create mode 100644 src/adafruit_blinka/microcontroller/spacemit/k1/__init__.py create mode 100644 src/adafruit_blinka/microcontroller/spacemit/k1/pin.py diff --git a/src/adafruit_blinka/board/bananapi/bpif3.py b/src/adafruit_blinka/board/bananapi/bpif3.py new file mode 100644 index 00000000..49d71583 --- /dev/null +++ b/src/adafruit_blinka/board/bananapi/bpif3.py @@ -0,0 +1,56 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT +"""Pin definitions for the Banana Pi F3.""" + +from adafruit_blinka.microcontroller.spacemit.k1 import pin + +# I2C +I2C4_SCL = pin.I2C4_SCL +I2C4_SDA = pin.I2C4_SDA + +# Default I2C +SCL = I2C4_SCL +SDA = I2C4_SDA + +# UART +UART0_TX = pin.UART0_TX +UART0_RX = pin.UART0_RX + +# Default UART +TX = UART0_TX +RX = UART0_RX +TXD = UART0_TX +RXD = UART0_RX + +# SPI +SPI3_MOSI = pin.SPI3_MOSI +SPI3_MISO = pin.SPI3_MISO +SPI3_SCLK = pin.SPI3_SCLK +SPI3_CS0 = pin.SPI3_CS0 + +# Default SPI +MOSI = SPI3_MOSI +MISO = SPI3_MISO +SCLK = SPI3_SCLK +CS = SPI3_CS0 + +# Pinout reference: +# https://wiki.banana-pi.org/Banana_Pi_BPI-M4_Berry#BPI-M4_Berry_40-pin_header +D3 = pin.GPIO_52 +D5 = pin.GPIO_51 +D7 = pin.GPIO_70 +D8 = pin.GPIO_47 +D10 = pin.GPIO_48 +D11 = pin.GPIO_71 +D12 = pin.GPIO_74 +D13 = pin.GPIO_72 +D15 = pin.GPIO_73 +D16 = pin.GPIO_91 +D18 = pin.GPIO_92 +D19 = pin.GPIO_77 +D21 = pin.GPIO_78 +D22 = pin.GPIO_49 +D23 = pin.GPIO_75 +D24 = pin.GPIO_76 +D26 = pin.GPIO_50 diff --git a/src/adafruit_blinka/microcontroller/rockchip/rk3566/.pin.py.swp b/src/adafruit_blinka/microcontroller/rockchip/rk3566/.pin.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..7ed8195e96d5a65be059efe2359f0d2e85359708 GIT binary patch literal 16384 zcmeI2ZH!!18OKixg2;;sQ3D#iZqsBJw!3p@cDJS44>Pm8jP0^ZcMFx;+|170-ClNf zW_o9~Wx+&1KTs1x46o`3>q~-f5rZU!7*Ru_K@$Xt@q-^EMpTqU4T-Nr{XO^I^D?EB zQooq=PV(#a{^z;pJkN8U`*O~i#lj7>8E@N|ulT%8srPJqcIn85pQ(R6dai2L+si9! z^2NzNsoj>j>dDR2_-fdU>f@>T`09Ey?nKS;?t1?~r#)V7)|cY7s2@~XQG2C6-isUK zb*(L?+G^B@JB?1eA9q@jvd$*HOFZqy#@uD^~K`PX>{&eRNCs7gh@ zAkl9cdcSwc#e2@wMC5Vj8OSq`XCTi&o`F0Ac?R+f{Nrq;{tkbD7vU**7`_Q#fqUV0Xu)16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88(8<-+x1{pMr0}eIU6%4EZO|K%Rj! zBLlK9F~{Sp$CJCi)@_BuMj27PZZ!Cv7Df~gso6E>tn7G1Ma9P8Ia(M|^>)40S+2Eh zUq%^G%F8~c|FL?v8@8Ln!%@3GoID@*ZSnVyj3$e7yaBUPB8w;dPu{Hb>C3IoV!hQH z9@&>ZXRq*vg57(E_7k7BKB?`(fbB$L8!dThV^Pm*clzFSop!iA`6iWjB+qU07#|*5 z3a9D?K4U#z8tSbf>)xqFC$Dg6bn?=6>d}eysYWM#oMv>*=H!W^)Ae!Ep_8?PG&ug3 zg(>R>uM_4B>z-y9#r~v$%Ic|Wordc1IZ=VIj^`SePBSmzR58s`!znleH^-J-kL0HpjTS%Qb!@!42HZCL2jv6HQhv=DuwLn~>R5I?p0|iybBc9utw_q1ox(v$bi~ z@aKm{wyX4u9iE=Ej3vStQysNmNf^U=c|2*ZG%`By)YvD}iuK;r^Iqx!U37U0je4_j zGmO(U_v{<(Vy!t!Z-nG_mnI*Qpr6}(8)2FQIjys{JWZ z=|W$XuMUxKBsM(bpJ_I0qzbY(2ky69cK0iDX^ zg+X~TkxPlSZkxwhA(O@0%5))Z7qK?oPN$~DV8PM+#IE4lWla`bJ0AI)JZX_#V%hM_ zsvv87f+usPr}bd Date: Wed, 4 Sep 2024 10:10:34 +0800 Subject: [PATCH 08/10] remove tmp file --- .../microcontroller/allwinner/h618/pin.py | 2 +- .../microcontroller/rockchip/rk3566/.pin.py.swp | Bin 16384 -> 0 bytes 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 src/adafruit_blinka/microcontroller/rockchip/rk3566/.pin.py.swp diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py index 426f38d6..ab32a88f 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -2,8 +2,8 @@ # # SPDX-License-Identifier: MIT """Allwinner H618 Pin Names""" -from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin import re +from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin def find_gpiochip_number(target_label): try: diff --git a/src/adafruit_blinka/microcontroller/rockchip/rk3566/.pin.py.swp b/src/adafruit_blinka/microcontroller/rockchip/rk3566/.pin.py.swp deleted file mode 100644 index 7ed8195e96d5a65be059efe2359f0d2e85359708..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI2ZH!!18OKixg2;;sQ3D#iZqsBJw!3p@cDJS44>Pm8jP0^ZcMFx;+|170-ClNf zW_o9~Wx+&1KTs1x46o`3>q~-f5rZU!7*Ru_K@$Xt@q-^EMpTqU4T-Nr{XO^I^D?EB zQooq=PV(#a{^z;pJkN8U`*O~i#lj7>8E@N|ulT%8srPJqcIn85pQ(R6dai2L+si9! z^2NzNsoj>j>dDR2_-fdU>f@>T`09Ey?nKS;?t1?~r#)V7)|cY7s2@~XQG2C6-isUK zb*(L?+G^B@JB?1eA9q@jvd$*HOFZqy#@uD^~K`PX>{&eRNCs7gh@ zAkl9cdcSwc#e2@wMC5Vj8OSq`XCTi&o`F0Ac?R+f{Nrq;{tkbD7vU**7`_Q#fqUV0Xu)16!{u-ZyuyOd3-B}? zgQIW+VmJsZumC$?Gh7INrG|b5KZ1whL6Ew-9bWS@KUXUS)m=M-nS!^&yJoI7I}ub$ zDwXF8u3VlH*$-xB=WD@?pP6&EpXs&v*#W(n>PhR`ybx3-Gg(@ z)}=vfKPVT(8rii*_C+qH);bF`l6ZnF){Z>sSlb+so3s(P?IZ`tzOxA9h7 z|82Mx*L@pp+4bHATXvndv6fxmZK!3}bscFbm^RiWMo_zgZp=m3zMz{(Mc2-tn@C01 z-k_UEMc3}2n@~l!{!~q@qU+3alQO}It}~B5;J?m1`hfpB^XRVsrqa+||9u;8)%D-E z@m5{`eH*W>H2m~!ycO4fQ)%3~T>nj_$t_J+th8g}wUs8ijn`J1=r&$kY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L2jv6HQhv=DuwLn~>R5I?p0|iybBc9utw_q1ox(v$bi~ z@aKm{wyX4u9iE=Ej3vStQysNmNf^U=c|2*ZG%`By)YvD}iuK;r^Iqx!U37U0je4_j zGmO(U_v{<(Vy!t!Z-nG_mnI*Qpr6}(8)2FQIjys{JWZ z=|W$XuMUxKBsM(bpJ_I0qzbY(2ky69cK0iDX^ zg+X~TkxPlSZkxwhA(O@0%5))Z7qK?oPN$~DV8PM+#IE4lWla`bJ0AI)JZX_#V%hM_ zsvv87f+usPr}bd Date: Wed, 4 Sep 2024 10:19:06 +0800 Subject: [PATCH 09/10] fix Missing function or method docstring (missing-function-docstring) --- src/adafruit_blinka/microcontroller/allwinner/h618/pin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py index ab32a88f..8f6c3888 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -6,6 +6,7 @@ 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: lines = f.readlines() From 3746b1b4aef900105cc9cfa19cada6692d5eb94e Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Wed, 4 Sep 2024 11:09:51 +0800 Subject: [PATCH 10/10] fix pre-commit check fail --- .../microcontroller/allwinner/h618/pin.py | 6 ++++-- .../microcontroller/spacemit/k1/pin.py | 14 ++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py index 8f6c3888..1019b598 100644 --- a/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py +++ b/src/adafruit_blinka/microcontroller/allwinner/h618/pin.py @@ -5,10 +5,11 @@ 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.") @@ -17,13 +18,14 @@ def find_gpiochip_number(target_label): gpiochip_number = None for line in lines: if target_label in line: - match = re.search(r'gpiochip(\d+)', 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: diff --git a/src/adafruit_blinka/microcontroller/spacemit/k1/pin.py b/src/adafruit_blinka/microcontroller/spacemit/k1/pin.py index ad70499e..997db4a9 100644 --- a/src/adafruit_blinka/microcontroller/spacemit/k1/pin.py +++ b/src/adafruit_blinka/microcontroller/spacemit/k1/pin.py @@ -5,7 +5,7 @@ from adafruit_blinka.agnostic import detector from adafruit_blinka.microcontroller.alias import get_pwm_chipid from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin - + __chip_num = 0 GPIO_0 = Pin((__chip_num, 0)) @@ -141,9 +141,7 @@ I2C4_SCL = GPIO_51 I2C4_SDA = GPIO_52 -i2cPorts = ( - (4, I2C4_SCL, I2C4_SDA), -) +i2cPorts = ((4, I2C4_SCL, I2C4_SDA),) # SPI SPI3_MISO = GPIO_78 @@ -152,18 +150,14 @@ SPI3_CS0 = GPIO_76 # ordered as spiId, sckId, mosiId, misoId -spiPorts = ( - (3, SPI3_SCLK, SPI3_MOSI, SPI3_MISO), -) +spiPorts = ((3, SPI3_SCLK, SPI3_MOSI, SPI3_MISO),) # UART UART0_TX = GPIO_47 UART0_RX = GPIO_48 # ordered as uartId, txId, rxId -uartPorts = ( - (0, UART0_TX, UART0_RX), -) +uartPorts = ((0, UART0_TX, UART0_RX),) # SysFS pwm outputs, pwm channel and pin in first tuple pwmOuts = []