Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpiod: enable pullup/pulldown #341

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading