From ad0c809ff090f463b5cfef4953bccdad8147c8ae Mon Sep 17 00:00:00 2001 From: Kostas Chatzikokolakis Date: Sun, 7 Jan 2024 13:29:30 +0200 Subject: [PATCH] gpiod: enable pullup/pulldown --- mqtt_io/modules/gpio/gpiod.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mqtt_io/modules/gpio/gpiod.py b/mqtt_io/modules/gpio/gpiod.py index bfcc986e..d514e8e0 100644 --- a/mqtt_io/modules/gpio/gpiod.py +++ b/mqtt_io/modules/gpio/gpiod.py @@ -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, @@ -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: