Skip to content

Commit 1a8bd20

Browse files
committed
Detect gpiochip via libgpiod for H616
Use python3-libgpiod to scan /dev/gpiochip* and match each chip’s label, replacing the sysfs-only lookup. This ensures reliable detection on H616 and adds support for Orange Pi SBCs where the old method failed.
1 parent a2ce100 commit 1a8bd20

File tree

1 file changed

+11
-6
lines changed
  • src/adafruit_blinka/microcontroller/allwinner/h616

1 file changed

+11
-6
lines changed

src/adafruit_blinka/microcontroller/allwinner/h616/pin.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4-
4+
import gpiod
5+
import glob
56
"""Allwinner H616 Pin Names"""
67
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
78

8-
__chip_num = 1
9-
with open("/sys/class/gpio/gpiochip0/label", "r") as f:
10-
label = f.read().strip()
11-
if label == "300b000.pinctrl":
12-
__chip_num = 0
9+
def find_gpiochip_number(target_label):
10+
for dev in glob.glob("/dev/gpiochip*"):
11+
with gpiod.Chip(dev) as chip:
12+
info = chip.get_info()
13+
if info.label == target_label:
14+
return dev[-1]
15+
16+
__chip_num = int(find_gpiochip_number("300b000.pinctrl") or 0) #fallback to 0
17+
1318
PC0 = Pin((__chip_num, 64))
1419
SPI0_SCLK = PC0
1520
PC1 = Pin((__chip_num, 65))

0 commit comments

Comments
 (0)