fix(kscan): different matrices, different waits

This commit is contained in:
down 2022-07-21 03:19:43 +07:00
parent 50d2c8d3fc
commit 7e2a45b582
2 changed files with 23 additions and 9 deletions

View file

@ -31,12 +31,7 @@ config ZMK_KSCAN_GPIO_MATRIX
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_GPIO_MATRIX))
select ZMK_KSCAN_GPIO_DRIVER
config ZMK_KSCAN_GPIO_ROUND_ROBIN_MATRIX
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_GPIO_ROUND_ROBIN_MATRIX))
select ZMK_KSCAN_GPIO_DRIVER
if ZMK_KSCAN_GPIO_MATRIX || ZMK_KSCAN_GPIO_ROUND_ROBIN_MATRIX
if ZMK_KSCAN_GPIO_MATRIX
config ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS
int "Ticks to wait between each output when scanning"
@ -50,6 +45,25 @@ config ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS
endif # ZMK_KSCAN_GPIO_MATRIX
config ZMK_KSCAN_GPIO_ROUND_ROBIN_MATRIX
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_GPIO_ROUND_ROBIN_MATRIX))
select ZMK_KSCAN_GPIO_DRIVER
if ZMK_KSCAN_GPIO_ROUND_ROBIN_MATRIX
config ZMK_KSCAN_ROUND_ROBIN_MATRIX_WAIT_BETWEEN_OUTPUTS
int "Ticks to wait between each output when scanning round robin matrix"
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_ROUND_ROBIN_MATRIX
config ZMK_KSCAN_MOCK_DRIVER
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_MOCK))

View file

@ -64,7 +64,7 @@ static int state_index_io(const struct kscan_round_robin_matrix_config *config,
__ASSERT(output_idx < config->gpio_count, "Invalid output %i", output_idx);
return ((input_idx * config->gpio_count) + output_idx);
}
}
static int kscan_round_robin_matrix_read(const struct device *dev) {
struct kscan_round_robin_matrix_data *data = dev->data;
@ -136,8 +136,8 @@ static int kscan_round_robin_matrix_read(const struct device *dev) {
return err;
}
#if CONFIG_ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS > 0
k_busy_wait(CONFIG_ZMK_KSCAN_MATRIX_WAIT_BETWEEN_OUTPUTS);
#if CONFIG_ZMK_KSCAN_ROUND_ROBIN_MATRIX_WAIT_BETWEEN_OUTPUTS > 0
k_busy_wait(CONFIG_ZMK_KSCAN_ROUND_ROBIN_MATRIX_WAIT_BETWEEN_OUTPUTS);
#endif
}