Skip to content

Commit

Permalink
feature(drivers): Option for read wait on matrix.
Browse files Browse the repository at this point in the history
* Add a new Kconfig option, `ZMK_KSCAN_MATRIX_WAIT_BEFORE_INPUTS`
  to delay reading inputs after setting an output active.
  • Loading branch information
petejohanson committed Sep 29, 2022
1 parent 0b39bf4 commit 9782518
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/drivers/kscan/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions app/drivers/kscan/kscan_gpio_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit 9782518

Please sign in to comment.