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 000000000..929023ab2 --- /dev/null +++ b/quantum/debounce.c | |||
@@ -0,0 +1,52 @@ | |||
1 | |||
2 | #include "matrix.h" | ||
3 | #include "timer.h" | ||
4 | #include "quantum.h" | ||
5 | |||
6 | #ifndef DEBOUNCING_DELAY | ||
7 | # define DEBOUNCING_DELAY 5 | ||
8 | #endif | ||
9 | |||
10 | void debounce_init(uint8_t num_rows) { | ||
11 | } | ||
12 | |||
13 | #if DEBOUNCING_DELAY > 0 | ||
14 | |||
15 | static bool debouncing = false; | ||
16 | |||
17 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { | ||
18 | static uint16_t debouncing_time; | ||
19 | |||
20 | if (changed) { | ||
21 | debouncing = true; | ||
22 | debouncing_time = timer_read(); | ||
23 | } | ||
24 | |||
25 | if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) { | ||
26 | for (uint8_t i = 0; i < num_rows; i++) { | ||
27 | cooked[i] = raw[i]; | ||
28 | } | ||
29 | debouncing = false; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | bool debounce_active(void) { | ||
34 | return debouncing; | ||
35 | } | ||
36 | |||
37 | #else | ||
38 | |||
39 | // no debounce | ||
40 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { | ||
41 | if (changed) | ||
42 | { | ||
43 | for (uint8_t i = 0; i < num_rows; i++) { | ||
44 | cooked[i] = raw[i]; | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | |||
49 | bool debounce_active(void) { | ||
50 | return false; | ||
51 | } | ||
52 | #endif | ||