This commit is contained in:
Sophie Tyalie 2023-09-10 13:41:01 +02:00 committed by GitHub
commit df9376ca39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;