Skip to content

Commit

Permalink
Simplify GPIO pin setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 3, 2024
1 parent d957c4a commit 8452998
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
32 changes: 3 additions & 29 deletions blinkt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
__version__ = '0.1.2'

OUTL = gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE)
PLATFORMS = {
"Radxa ROCK 5B": {"dat": ("PIN_16", OUTL), "clk": ("PIN_18", OUTL)},
"Raspberry Pi 5": {"dat": ("PIN16", OUTL), "clk": ("PIN18", OUTL)},
"Raspberry Pi 4": {"dat": ("GPIO23", OUTL), "clk": ("GPIO24", OUTL)}
}
NUM_PIXELS = 8
BRIGHTNESS = 7

Expand Down Expand Up @@ -88,33 +83,12 @@ def _sof():
def set_pins(pin_dat, pin_clk):
global clk_lines, dat_lines, dat_line, clk_line

try:
chip = gpiodevice.find_chip_by_pins((pin_dat, pin_clk))
dat_line = chip.line_offset_from_id(pin_dat)
clk_line = chip.line_offset_from_id(pin_clk)
dat_lines = clk_lines = chip.request_lines(consumer="blinkt", config={
dat_line: OUTL,
clk_line: OUTL
})
return
except SystemExit:
pass

chip_dat = gpiodevice.find_chip_by_pins(pin_dat)
dat_line = chip_dat.line_offset_from_id(pin_dat)
dat_lines = chip_dat.request_lines(consumer="blinkt-dat", config={dat_line: OUTL})

chip_clk = gpiodevice.find_chip_by_pins(pin_clk)
clk_line = chip_clk.line_offset_from_id(pin_clk)
clk_lines = chip_clk.request_lines(consumer="blinkt-clk", config={clk_line: OUTL})
dat_lines, dat_line = gpiodevice.get_pin(pin_dat, "blinkt-dat", OUTL)
clk_lines, clk_line = gpiodevice.get_pin(pin_clk, "blinkt-clk", OUTL)


def default_pins():
global clk_lines, dat_lines, dat_line, clk_line

dat, clk = gpiodevice.get_pins_for_platform(PLATFORMS)
dat_lines, dat_line = dat
clk_lines, clk_line = clk
set_pins(23, 24)


def show():
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ classifiers = [
]
dependencies = [
"gpiod",
"gpiodevice>=0.0.2"
"gpiodevice>=0.0.4"
]

[project.urls]
Expand Down

0 comments on commit 8452998

Please sign in to comment.