Skip to content

Commit

Permalink
Search for common gpiochip device names.
Browse files Browse the repository at this point in the history
Tested so far on a Pi 4 running Bullseye and a Pi 5 running Bookworm.
  • Loading branch information
Gadgetoid committed Oct 31, 2023
1 parent c8506c9 commit e79775a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions blinkt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Library for the Pimoroni Blinkt! - 8-pixel APA102 LED display."""
import atexit
import glob
import time

import gpiod
Expand All @@ -11,7 +12,10 @@
CLK = 24
NUM_PIXELS = 8
BRIGHTNESS = 7
GPIOCHIP = "/dev/gpiochip4"
RPI_GPIO_LABELS = [
"pinctrl-rp1", # Pi 5 - Bookworm, /dev/gpiochip4 maybe
"pinctrl-bcm2711" # Pi 4 - Bullseye, /dev/gpiochip1 maybe
]

pixels = [[0, 0, 0, BRIGHTNESS]] * NUM_PIXELS

Expand All @@ -28,6 +32,14 @@ def _exit():
gpio_lines.release()


def get_gpiochip():
for path in glob.glob("/dev/gpiochip*"):
if gpiod.is_gpiochip_device(path):
if gpiod.Chip(path).get_info().label in RPI_GPIO_LABELS:
return path
raise RuntimeError("Compatible /dev/gpiochipN device not found!")


def set_brightness(brightness):
"""Set the brightness of all pixels.
Expand Down Expand Up @@ -83,7 +95,7 @@ def show():

if not gpio_lines:
gpio_lines = gpiod.request_lines(
GPIOCHIP,
get_gpiochip(),
consumer="blinkt",
config={
DAT: gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE),
Expand Down

0 comments on commit e79775a

Please sign in to comment.