From 978251839767ab754b727d1c59e478ac8be30894 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 28 Sep 2022 17:59:25 +0000 Subject: [PATCH] feature(drivers): Option for read wait on matrix. * Add a new Kconfig option, `ZMK_KSCAN_MATRIX_WAIT_BEFORE_INPUTS` to delay reading inputs after setting an output active. --- app/drivers/kscan/Kconfig | 12 +++++++++++- app/drivers/kscan/kscan_gpio_matrix.c | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/drivers/kscan/Kconfig b/app/drivers/kscan/Kconfig index b76a27b4..51546006 100644 --- a/app/drivers/kscan/Kconfig +++ b/app/drivers/kscan/Kconfig @@ -32,6 +32,16 @@ config ZMK_KSCAN_GPIO_MATRIX if ZMK_KSCAN_GPIO_MATRIX +config ZMK_KSCAN_MATRIX_WAIT_BEFORE_INPUTS + int "Ticks to wait before reading inputs after an output set active" + default 0 + help + When iterating over each output to drive it active, read inputs, then set + inactive again, some boards may take time for output to propagate to the + inputs. In that scenario, set this value to a positive value to configure + the number of ticks to wait after setting an output active before reading + the inputs for their active state. + config ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS int "Ticks to wait between each output when scanning" default 0 @@ -40,7 +50,7 @@ config ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS 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. + ticks to wait after reading each column of keys. endif # ZMK_KSCAN_GPIO_MATRIX diff --git a/app/drivers/kscan/kscan_gpio_matrix.c b/app/drivers/kscan/kscan_gpio_matrix.c index 1ab4d442..71fcad29 100644 --- a/app/drivers/kscan/kscan_gpio_matrix.c +++ b/app/drivers/kscan/kscan_gpio_matrix.c @@ -235,6 +235,10 @@ static int kscan_matrix_read(const struct device *dev) { return err; } +#if CONFIG_ZMK_KSCAN_MATRIX_WAIT_BEFORE_INPUTS > 0 + k_busy_wait(CONFIG_ZMK_KSCAN_MATRIX_WAIT_BEFORE_INPUTS); +#endif + for (int i = 0; i < config->inputs.len; i++) { const struct gpio_dt_spec *in_gpio = &config->inputs.gpios[i];