Skip to content

Commit

Permalink
gpiod: enable pullup/pulldown
Browse files Browse the repository at this point in the history
  • Loading branch information
chatziko committed Jan 7, 2024
1 parent 390cc52 commit ad0c809
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mqtt_io/modules/gpio/gpiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def setup_module(self) -> None:
PinDirection.OUTPUT: gpiod.line_request.DIRECTION_OUTPUT,
}

self.flags_map = {
PinPUD.OFF: gpiod.line_request.FLAG_BIAS_DISABLE,
PinPUD.UP: gpiod.line_request.FLAG_BIAS_PULL_UP,
PinPUD.DOWN: gpiod.line_request.FLAG_BIAS_PULL_DOWN,
}

self.interrupt_edge_map = {
InterruptEdge.RISING: gpiod.line_request.EVENT_RISING_EDGE,
InterruptEdge.FALLING: gpiod.line_request.EVENT_FALLING_EDGE,
Expand All @@ -63,14 +69,14 @@ def setup_pin(
pullup: pullup settings are not supported
"""
# Pullup settings are called bias in libgpiod and are only
# available since Linux Kernel 5.5. They are as of now not
# yet part of python3-gpiod.
# available since Linux Kernel 5.5.

line: "gpiod.line" = self.chip.get_line(pin)

line_request = self.io.line_request()
line_request.consumer = "mqtt-io"
line_request.request_type = self.direction_map[direction]
line_request.flags = self.flags_map[pullup]

if direction == PinDirection.OUTPUT:
if initial is not None:
Expand Down

0 comments on commit ad0c809

Please sign in to comment.