Skip to content

Commit 9315725

Browse files
committed
Revert to using a boolean flag for sym_defer_g
1 parent 51b642d commit 9315725

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

quantum/debounce/sym_defer_g.c

+10-18
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,25 @@ When no state changes have occured for DEBOUNCE milliseconds, we push the state.
3030
# define DEBOUNCE UINT8_MAX
3131
#endif
3232

33-
typedef uint8_t debounce_counter_t;
34-
3533
#if DEBOUNCE > 0
36-
37-
# define DEBOUNCE_ELAPSED 0
38-
39-
static debounce_counter_t debounce_counter = DEBOUNCE_ELAPSED;
40-
41-
static fast_timer_t last_time;
34+
static bool debouncing = false;
35+
static fast_timer_t debouncing_time;
4236

4337
void debounce_init(uint8_t num_rows) {}
4438

4539
bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
4640
bool cooked_changed = false;
4741

4842
if (changed) {
49-
debounce_counter = DEBOUNCE;
50-
last_time = timer_read_fast();
51-
} else if (debounce_counter != DEBOUNCE_ELAPSED) {
52-
if (debounce_counter <= timer_elapsed_fast(last_time)) {
53-
debounce_counter = DEBOUNCE_ELAPSED;
54-
size_t matrix_size = num_rows * sizeof(matrix_row_t);
55-
if (memcmp(cooked, raw, matrix_size) != 0) {
56-
memcpy(cooked, raw, matrix_size);
57-
cooked_changed = true;
58-
}
43+
debouncing = true;
44+
debouncing_time = timer_read_fast();
45+
} else if (debouncing && timer_elapsed_fast(debouncing_time) >= DEBOUNCE) {
46+
size_t matrix_size = num_rows * sizeof(matrix_row_t);
47+
if (memcmp(cooked, raw, matrix_size) != 0) {
48+
memcpy(cooked, raw, matrix_size);
49+
cooked_changed = true;
5950
}
51+
debouncing = false;
6052
}
6153

6254
return cooked_changed;

0 commit comments

Comments
 (0)