Merge 412376e8a4
into 7f9e9f8c64
This commit is contained in:
commit
df9376ca39
1 changed files with 23 additions and 2 deletions
|
@ -217,6 +217,8 @@ static int kscan_matrix_read(const struct device *dev) {
|
||||||
struct kscan_matrix_data *data = dev->data;
|
struct kscan_matrix_data *data = dev->data;
|
||||||
const struct kscan_matrix_config *config = dev->config;
|
const struct kscan_matrix_config *config = dev->config;
|
||||||
|
|
||||||
|
int num_active = 0;
|
||||||
|
int stored_states[3] = {0};
|
||||||
// Scan the matrix.
|
// Scan the matrix.
|
||||||
for (int i = 0; i < config->outputs.len; i++) {
|
for (int i = 0; i < config->outputs.len; i++) {
|
||||||
const struct kscan_gpio *out_gpio = &config->outputs.gpios[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;
|
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);
|
err = gpio_pin_set_dt(&out_gpio->spec, 0);
|
||||||
|
@ -257,6 +270,14 @@ static int kscan_matrix_read(const struct device *dev) {
|
||||||
#endif
|
#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.
|
// Process the new state.
|
||||||
bool continue_scan = false;
|
bool continue_scan = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue