Skip to content

Commit

Permalink
Revert to using a boolean flag for sym_defer_g
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebrait committed Aug 24, 2023
1 parent 51b642d commit 9315725
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions quantum/debounce/sym_defer_g.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,25 @@ When no state changes have occured for DEBOUNCE milliseconds, we push the state.
# define DEBOUNCE UINT8_MAX
#endif

typedef uint8_t debounce_counter_t;

#if DEBOUNCE > 0

# define DEBOUNCE_ELAPSED 0

static debounce_counter_t debounce_counter = DEBOUNCE_ELAPSED;

static fast_timer_t last_time;
static bool debouncing = false;
static fast_timer_t debouncing_time;

void debounce_init(uint8_t num_rows) {}

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

if (changed) {
debounce_counter = DEBOUNCE;
last_time = timer_read_fast();
} else if (debounce_counter != DEBOUNCE_ELAPSED) {
if (debounce_counter <= timer_elapsed_fast(last_time)) {
debounce_counter = DEBOUNCE_ELAPSED;
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 = true;
debouncing_time = timer_read_fast();
} 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;
}

return cooked_changed;
Expand Down

0 comments on commit 9315725

Please sign in to comment.