From 03e663a56ac01041285ba16bb9b3bd7b79dfc7f5 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 24 Nov 2023 05:45:42 +0000 Subject: [PATCH] refactor(kscan): Infer pull flags, use LISTIFY. * To avoid issues with platforms that enforce no pull flags when pins are used as outputs, infer the pull flags in code instead of setting them in the DTS for charlieplex kscan driver. * Use `LISTIFY` macro instead of deprecated `UTIL_LISTIFY`. --- app/module/drivers/kscan/kscan_gpio_charlieplex.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/module/drivers/kscan/kscan_gpio_charlieplex.c b/app/module/drivers/kscan/kscan_gpio_charlieplex.c index 02c029cd..19ba9d29 100644 --- a/app/module/drivers/kscan/kscan_gpio_charlieplex.c +++ b/app/module/drivers/kscan/kscan_gpio_charlieplex.c @@ -110,7 +110,9 @@ static int kscan_charlieplex_set_as_input(const struct gpio_dt_spec *gpio) { return -ENODEV; } - int err = gpio_pin_configure_dt(gpio, GPIO_INPUT); + gpio_flags_t pull_flag = (gpio->dt_flags & GPIO_ACTIVE_HIGH) ? GPIO_PULL_DOWN : GPIO_PULL_UP; + + int err = gpio_pin_configure_dt(gpio, GPIO_INPUT | pull_flag); if (err) { LOG_ERR("Unable to configure pin %u on %s for input", gpio->pin, gpio->port->name); return err; @@ -393,7 +395,7 @@ static const struct kscan_driver_api kscan_charlieplex_api = { \ static struct zmk_debounce_state kscan_charlieplex_state_##n[INST_CHARLIEPLEX_LEN(n)]; \ static const struct gpio_dt_spec kscan_charlieplex_cells_##n[] = { \ - UTIL_LISTIFY(INST_LEN(n), KSCAN_GPIO_CFG_INIT, n)}; \ + LISTIFY(INST_LEN(n), KSCAN_GPIO_CFG_INIT, (, ), n)}; \ static struct kscan_charlieplex_data kscan_charlieplex_data_##n = { \ .charlieplex_state = kscan_charlieplex_state_##n, \ }; \