From a799b75e5eff6d40d54700659aa2f0126734c4b0 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Tue, 19 Apr 2022 03:02:00 -0400 Subject: [PATCH] feat(kscan): Kconfig for optional scan delay. Add optional Kconfig setting to delay scanning after each output column is set, and inputs are read, to allow inputs to "settle" after the last column is set back to inactive. --- app/drivers/kscan/Kconfig | 14 ++++++++++++++ app/drivers/kscan/kscan_gpio_matrix.c | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/app/drivers/kscan/Kconfig b/app/drivers/kscan/Kconfig index c9ace0a3..b76a27b4 100644 --- a/app/drivers/kscan/Kconfig +++ b/app/drivers/kscan/Kconfig @@ -30,6 +30,20 @@ config ZMK_KSCAN_GPIO_MATRIX default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_GPIO_MATRIX)) select ZMK_KSCAN_GPIO_DRIVER +if ZMK_KSCAN_GPIO_MATRIX + +config ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS + int "Ticks to wait between each output when scanning" + default 0 + help + When iterating over each output to drive it active, read inputs, then set + inactive again, some boards may take time for the previous output to + "settle" before reading inputs for the next active output column. In that + scenario, set this value to a positive value to configure the number of + usecs to wait after reading each column of keys. + +endif # ZMK_KSCAN_GPIO_MATRIX + config ZMK_KSCAN_MOCK_DRIVER bool default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_MOCK)) diff --git a/app/drivers/kscan/kscan_gpio_matrix.c b/app/drivers/kscan/kscan_gpio_matrix.c index fc355ca2..1ab4d442 100644 --- a/app/drivers/kscan/kscan_gpio_matrix.c +++ b/app/drivers/kscan/kscan_gpio_matrix.c @@ -250,6 +250,10 @@ static int kscan_matrix_read(const struct device *dev) { LOG_ERR("Failed to set output %i inactive: %i", o, err); return err; } + +#if CONFIG_ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS > 0 + k_busy_wait(CONFIG_ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS); +#endif } // Process the new state.