From f39c821d190a4bfb1d03f60159f3d13dc5155312 Mon Sep 17 00:00:00 2001 From: Kurtis Lew Date: Tue, 17 May 2022 15:41:25 -0700 Subject: [PATCH] Simplify kscan_gpio_get_flags Co-authored-by: Pete Johanson --- app/drivers/kscan/kscan_gpio_direct.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/drivers/kscan/kscan_gpio_direct.c b/app/drivers/kscan/kscan_gpio_direct.c index d5fd9047..2da5f6d6 100644 --- a/app/drivers/kscan/kscan_gpio_direct.c +++ b/app/drivers/kscan/kscan_gpio_direct.c @@ -126,19 +126,11 @@ static void kscan_direct_irq_callback_handler(const struct device *port, struct #endif static gpio_flags_t kscan_gpio_get_flags(const struct gpio_dt_spec *gpio, bool active) { - if (((BIT(0) & gpio->dt_flags) == BIT(0))) { // Devicetree configured input ACTIVE_LOW - if (!active) { - return GPIO_ACTIVE_LOW | GPIO_PULL_UP; - } - return GPIO_ACTIVE_LOW; - } else { // Devicetree configured input ACTIVE_HIGH - if (!active) { - return GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN; - } - return GPIO_ACTIVE_HIGH; + gpio_flags_t flags = BIT_MASK(0) & gpio->dt_flags; + if (active) { + flags |= flags ? GPIO_PULL_DOWN : GPIO_PULL_UP; } - LOG_ERR("Could not determine proper flags to set for pin %d", gpio->pin); - return 0; + return flags; } static int kscan_inputs_set_flags(const struct kscan_gpio_list *inputs,