Skip to content

Commit c50b9b5

Browse files
authored
fix wrongly assuming "of_node/compatible" will always exist for all gpiochips
1 parent 929eb5e commit c50b9b5

File tree

1 file changed

+9
-8
lines changed
  • src/adafruit_blinka/microcontroller/generic_linux

1 file changed

+9
-8
lines changed

src/adafruit_blinka/microcontroller/generic_linux/lgpio_pin.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ def _get_gpiochip():
1515
used for userspace GPIO access.
1616
"""
1717
for dev in Path("/sys/bus/gpio/devices").glob("gpiochip*"):
18-
drivers = set((dev / "of_node/compatible").read_text().split("\0"))
19-
# check if driver names are intended for userspace control
20-
if drivers & {
21-
"raspberrypi,rp1-gpio",
22-
"raspberrypi,bcm2835-gpio",
23-
"raspberrypi,bcm2711-gpio",
24-
}:
25-
return lgpio.gpiochip_open(int(dev.name[-1]))
18+
if Path(dev / "of_node/compatible").is_file():
19+
drivers = set((dev / "of_node/compatible").read_text().split("\0"))
20+
# check if driver names are intended for userspace control
21+
if drivers & {
22+
"raspberrypi,rp1-gpio",
23+
"raspberrypi,bcm2835-gpio",
24+
"raspberrypi,bcm2711-gpio",
25+
}:
26+
return lgpio.gpiochip_open(int(dev.name[-1]))
2627
# return chip0 as a fallback
2728
return lgpio.gpiochip_open(0)
2829

0 commit comments

Comments
 (0)