diff options
Diffstat (limited to 'quantum/debounce.c')
-rw-r--r-- | quantum/debounce.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/quantum/debounce.c b/quantum/debounce.c new file mode 100644 index 0000000000..929023ab2d --- /dev/null +++ b/quantum/debounce.c @@ -0,0 +1,52 @@ + +#include "matrix.h" +#include "timer.h" +#include "quantum.h" + +#ifndef DEBOUNCING_DELAY +# define DEBOUNCING_DELAY 5 +#endif + +void debounce_init(uint8_t num_rows) { +} + +#if DEBOUNCING_DELAY > 0 + +static bool debouncing = false; + +void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + static uint16_t debouncing_time; + + if (changed) { + debouncing = true; + debouncing_time = timer_read(); + } + + if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) { + for (uint8_t i = 0; i < num_rows; i++) { + cooked[i] = raw[i]; + } + debouncing = false; + } +} + +bool debounce_active(void) { + return debouncing; +} + +#else + +// no debounce +void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + if (changed) + { + for (uint8_t i = 0; i < num_rows; i++) { + cooked[i] = raw[i]; + } + } +} + +bool debounce_active(void) { + return false; +} +#endif |