Skip to content

Commit

Permalink
gpiod: enable pullup/pulldown (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatziko authored Feb 26, 2024
1 parent 05c7111 commit ec4c087
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mqtt_io/modules/gpio/gpiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}


class GPIO(GenericGPIO):
class GPIO(GenericGPIO): # pylint: disable=too-many-instance-attributes
"""
Implementation of GPIO class for libgpiod (linux kernel >= 4.8).
"""
Expand All @@ -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 ec4c087

Please sign in to comment.