diff options
Diffstat (limited to 'quantum/debounce/sym_defer_g.c')
-rw-r--r-- | quantum/debounce/sym_defer_g.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/quantum/debounce/sym_defer_g.c b/quantum/debounce/sym_defer_g.c index 25e18890af..d96758fab3 100644 --- a/quantum/debounce/sym_defer_g.c +++ b/quantum/debounce/sym_defer_g.c @@ -24,6 +24,12 @@ When no state changes have occured for DEBOUNCE milliseconds, we push the state. # define DEBOUNCE 5 #endif +// Maximum debounce: 255ms +#if DEBOUNCE > UINT8_MAX +# undef DEBOUNCE +# define DEBOUNCE UINT8_MAX +#endif + #if DEBOUNCE > 0 static bool debouncing = false; static fast_timer_t debouncing_time; @@ -36,11 +42,10 @@ bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool if (changed) { debouncing = true; debouncing_time = timer_read_fast(); - } - - if (debouncing && timer_elapsed_fast(debouncing_time) >= DEBOUNCE) { - if (memcmp(cooked, raw, sizeof(matrix_row_t) * num_rows) != 0) { - memcpy(cooked, raw, sizeof(matrix_row_t) * num_rows); + } else if (debouncing && timer_elapsed_fast(debouncing_time) >= DEBOUNCE) { + size_t matrix_size = num_rows * sizeof(matrix_row_t); + if (memcmp(cooked, raw, matrix_size) != 0) { + memcpy(cooked, raw, matrix_size); cooked_changed = true; } debouncing = false; |