1
0
Fork 0

Fix debouncing issue for eager algorithms (#6081)

* Fix debouncing issue for eager algos

* Fix up typo issue
This commit is contained in:
Drashna Jaelre 2019-07-09 11:09:54 -07:00 committed by GitHub
parent 207e50c534
commit 37be1cb513
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 11 deletions

View file

@ -39,6 +39,7 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred.
static debounce_counter_t *debounce_counters; static debounce_counter_t *debounce_counters;
static bool counters_need_update; static bool counters_need_update;
static bool matrix_need_update;
#define DEBOUNCE_ELAPSED 251 #define DEBOUNCE_ELAPSED 251
#define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1)
@ -63,7 +64,7 @@ void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool
update_debounce_counters(num_rows, current_time); update_debounce_counters(num_rows, current_time);
} }
if (changed) { if (changed || matrix_need_update) {
transfer_matrix_values(raw, cooked, num_rows, current_time); transfer_matrix_values(raw, cooked, num_rows, current_time);
} }
} }
@ -88,16 +89,21 @@ void update_debounce_counters(uint8_t num_rows, uint8_t current_time) {
// upload from raw_matrix to final matrix; // upload from raw_matrix to final matrix;
void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) { void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) {
matrix_need_update = false;
debounce_counter_t *debounce_pointer = debounce_counters; debounce_counter_t *debounce_pointer = debounce_counters;
for (uint8_t row = 0; row < num_rows; row++) { for (uint8_t row = 0; row < num_rows; row++) {
matrix_row_t delta = raw[row] ^ cooked[row]; matrix_row_t delta = raw[row] ^ cooked[row];
matrix_row_t existing_row = cooked[row]; matrix_row_t existing_row = cooked[row];
for (uint8_t col = 0; col < MATRIX_COLS; col++) { for (uint8_t col = 0; col < MATRIX_COLS; col++) {
matrix_row_t col_mask = (ROW_SHIFTER << col); matrix_row_t col_mask = (ROW_SHIFTER << col);
if ((delta & col_mask) && *debounce_pointer == DEBOUNCE_ELAPSED) { if (delta & col_mask) {
if (*debounce_pointer == DEBOUNCE_ELAPSED) {
*debounce_pointer = current_time; *debounce_pointer = current_time;
counters_need_update = true; counters_need_update = true;
existing_row ^= col_mask; // flip the bit. existing_row ^= col_mask; // flip the bit.
} else {
matrix_need_update = true;
}
} }
debounce_pointer++; debounce_pointer++;
} }

View file

@ -28,6 +28,7 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred.
#endif #endif
#define debounce_counter_t uint8_t #define debounce_counter_t uint8_t
static bool matrix_need_update;
static debounce_counter_t *debounce_counters; static debounce_counter_t *debounce_counters;
static bool counters_need_update; static bool counters_need_update;
@ -53,7 +54,7 @@ void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool
update_debounce_counters(num_rows, current_time); update_debounce_counters(num_rows, current_time);
} }
if (changed || (needed_update && !counters_need_update)) { if (changed || (needed_update && !counters_need_update) || matrix_need_update) {
transfer_matrix_values(raw, cooked, num_rows, current_time); transfer_matrix_values(raw, cooked, num_rows, current_time);
} }
} }
@ -76,18 +77,22 @@ void update_debounce_counters(uint8_t num_rows, uint8_t current_time) {
// upload from raw_matrix to final matrix; // upload from raw_matrix to final matrix;
void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) { void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) {
matrix_need_update = false;
debounce_counter_t *debounce_pointer = debounce_counters; debounce_counter_t *debounce_pointer = debounce_counters;
for (uint8_t row = 0; row < num_rows; row++) { for (uint8_t row = 0; row < num_rows; row++) {
matrix_row_t existing_row = cooked[row]; matrix_row_t existing_row = cooked[row];
matrix_row_t raw_row = raw[row]; matrix_row_t raw_row = raw[row];
// determine new value basd on debounce pointer + raw value // determine new value basd on debounce pointer + raw value
if (*debounce_pointer == DEBOUNCE_ELAPSED && (existing_row != raw_row)) { if (existing_row != raw_row) {
if (*debounce_pointer == DEBOUNCE_ELAPSED) {
*debounce_pointer = current_time; *debounce_pointer = current_time;
cooked[row] = raw_row; cooked[row] = raw_row;
counters_need_update = true; counters_need_update = true;
} else {
matrix_need_update = true;
}
} }
debounce_pointer++; debounce_pointer++;
} }
} }