Skip to content

Commit

Permalink
Fix debouncing issue for eager algos
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Jun 5, 2019
1 parent 028d02d commit 9768f5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
05-29-2019 - Fixing matrix_scan so it properly returns changed status
05-29-2019 - Add belgian layour for sendstring (qmk#6008)
06-03-2019 - Overhaul of AutoShift feature (qmk#6067)
06-05-2019 - Fix Eager Per Key and Eager Per Row debouncing stuck keys
17 changes: 12 additions & 5 deletions quantum/debounce/eager_pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred.

static debounce_counter_t *debounce_counters;
static bool counters_need_update;
static bool matrix_need_update;

#define DEBOUNCE_ELAPSED 251
#define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1)
Expand All @@ -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);
}

if (changed) {
if (changed || matrix_need_update) {
transfer_matrix_values(raw, cooked, num_rows, current_time);
}
}
Expand All @@ -88,16 +89,22 @@ void update_debounce_counters(uint8_t num_rows, uint8_t current_time) {

// 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) {
matrix_need_update = false;
debounce_counter_t *debounce_pointer = debounce_counters;
for (uint8_t row = 0; row < num_rows; row++) {
matrix_row_t delta = raw[row] ^ cooked[row];
matrix_row_t existing_row = cooked[row];
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
matrix_row_t col_mask = (ROW_SHIFTER << col);
if ((delta & col_mask) && *debounce_pointer == DEBOUNCE_ELAPSED) {
*debounce_pointer = current_time;
counters_need_update = true;
existing_row ^= col_mask; // flip the bit.
if (delta & col_mask) {
if (*debounce_pointer == DEBOUNCE_ELAPSED) {
counters_need_update = true; *debounce_pointer = current_time;
*debounce_pointer = current_time;
counters_need_update = true;
existing_row ^= col_mask; // flip the bit.
} else {
matrix_need_update = true;
}
}
debounce_pointer++;
}
Expand Down
17 changes: 11 additions & 6 deletions quantum/debounce/eager_pr.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred.
#endif

#define debounce_counter_t uint8_t
static bool matrix_need_update;

static debounce_counter_t *debounce_counters;
static bool counters_need_update;
Expand All @@ -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);
}

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);
}
}
Expand All @@ -76,18 +77,22 @@ void update_debounce_counters(uint8_t num_rows, uint8_t current_time) {

// 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) {
matrix_need_update = false;
debounce_counter_t *debounce_pointer = debounce_counters;
for (uint8_t row = 0; row < num_rows; row++) {
matrix_row_t existing_row = cooked[row];
matrix_row_t raw_row = raw[row];

// determine new value basd on debounce pointer + raw value
if (*debounce_pointer == DEBOUNCE_ELAPSED && (existing_row != raw_row)) {
*debounce_pointer = current_time;
cooked[row] = raw_row;
counters_need_update = true;
if (existing_row != raw_row) {
if (*debounce_pointer == DEBOUNCE_ELAPSED) {
*debounce_pointer = current_time;
cooked[row] = raw_row;
counters_need_update = true;
} else {
matrix_need_update = true;
}
}

debounce_pointer++;
}
}
Expand Down

0 comments on commit 9768f5e

Please sign in to comment.