diff --git a/app/drivers/kscan/kscan_gpio_matrix.c b/app/drivers/kscan/kscan_gpio_matrix.c index b8e72044..276f6d03 100644 --- a/app/drivers/kscan/kscan_gpio_matrix.c +++ b/app/drivers/kscan/kscan_gpio_matrix.c @@ -217,6 +217,8 @@ static int kscan_matrix_read(const struct device *dev) { struct kscan_matrix_data *data = dev->data; const struct kscan_matrix_config *config = dev->config; + int num_active = 0; + int stored_states[3] = {0}; // Scan the matrix. for (int i = 0; i < config->outputs.len; i++) { const struct kscan_gpio *out_gpio = &config->outputs.gpios[i]; @@ -242,8 +244,19 @@ static int kscan_matrix_read(const struct device *dev) { return active; } - debounce_update(&data->matrix_state[index], active, config->debounce_scan_period_ms, - &config->debounce_config); + + if (active) { + if (num_active < sizeof(stored_states) / sizeof(stored_states[0])) { + stored_states[num_active] = index; + } + num_active++; + } else { + debounce_update(&data->matrix_state[index], active, + config->debounce_scan_period_ms, + &config->debounce_config); + } + + } err = gpio_pin_set_dt(&out_gpio->spec, 0); @@ -257,6 +270,14 @@ static int kscan_matrix_read(const struct device *dev) { #endif } + if (0 < num_active && num_active <= 3) { + for (int i = 0; i < num_active; i++) { + int index = stored_states[i]; + debounce_update(&data->matrix_state[index], true, config->debounce_scan_period_ms, + &config->debounce_config); + } + } + // Process the new state. bool continue_scan = false;