Skip to content

Commit

Permalink
refactor(kscan): Infer pull flags, use LISTIFY.
Browse files Browse the repository at this point in the history
* 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`.
  • Loading branch information
petejohanson committed Nov 24, 2023
1 parent 7c2ad3d commit a0cc94e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/module/drivers/kscan/kscan_gpio_charlieplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, \
}; \
Expand Down

0 comments on commit a0cc94e

Please sign in to comment.