Skip to content

Commit 93f9ab8

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 93f9ab8

File tree

1 file changed

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

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4-
54
"""Allwinner H616 Pin Names"""
5+
import glob
6+
import gpiod
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+
"""Return the GPIO chip number for the target label, or 0 if not found."""
11+
for dev in glob.glob("/dev/gpiochip*"):
12+
with gpiod.Chip(dev) as chip:
13+
info = chip.get_info()
14+
if info.label == target_label:
15+
return int(dev[-1])
16+
return 0
17+
18+
__chip_num = find_gpiochip_number("300b000.pinctrl")
19+
1320
PC0 = Pin((__chip_num, 64))
1421
SPI0_SCLK = PC0
1522
PC1 = Pin((__chip_num, 65))

0 commit comments

Comments
 (0)