diff options
Diffstat (limited to 'quantum/debounce/eager_pr.c')
| -rw-r--r-- | quantum/debounce/eager_pr.c | 74 |
1 files changed, 34 insertions, 40 deletions
diff --git a/quantum/debounce/eager_pr.c b/quantum/debounce/eager_pr.c index 9eb9480a7..5b460f663 100644 --- a/quantum/debounce/eager_pr.c +++ b/quantum/debounce/eager_pr.c | |||
| @@ -24,13 +24,13 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred. | |||
| 24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
| 25 | 25 | ||
| 26 | #ifndef DEBOUNCE | 26 | #ifndef DEBOUNCE |
| 27 | #define DEBOUNCE 5 | 27 | # define DEBOUNCE 5 |
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| 30 | |||
| 31 | #define debounce_counter_t uint8_t | 30 | #define debounce_counter_t uint8_t |
| 32 | 31 | ||
| 33 | static debounce_counter_t *debounce_counters; | 32 | static debounce_counter_t *debounce_counters; |
| 33 | static bool counters_need_update; | ||
| 34 | 34 | ||
| 35 | #define DEBOUNCE_ELAPSED 251 | 35 | #define DEBOUNCE_ELAPSED 251 |
| 36 | #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) | 36 | #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) |
| @@ -38,33 +38,35 @@ static debounce_counter_t *debounce_counters; | |||
| 38 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time); | 38 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time); |
| 39 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time); | 39 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time); |
| 40 | 40 | ||
| 41 | //we use num_rows rather than MATRIX_ROWS to support split keyboards | 41 | // we use num_rows rather than MATRIX_ROWS to support split keyboards |
| 42 | void debounce_init(uint8_t num_rows) | 42 | void debounce_init(uint8_t num_rows) { |
| 43 | { | 43 | debounce_counters = (debounce_counter_t *)malloc(num_rows * sizeof(debounce_counter_t)); |
| 44 | debounce_counters = (debounce_counter_t*)malloc(num_rows*sizeof(debounce_counter_t)); | 44 | for (uint8_t r = 0; r < num_rows; r++) { |
| 45 | for (uint8_t r = 0; r < num_rows; r++) | ||
| 46 | { | ||
| 47 | debounce_counters[r] = DEBOUNCE_ELAPSED; | 45 | debounce_counters[r] = DEBOUNCE_ELAPSED; |
| 48 | } | 46 | } |
| 49 | } | 47 | } |
| 50 | 48 | ||
| 51 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) | 49 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { |
| 52 | { | ||
| 53 | uint8_t current_time = timer_read() % MAX_DEBOUNCE; | 50 | uint8_t current_time = timer_read() % MAX_DEBOUNCE; |
| 54 | update_debounce_counters(num_rows, current_time); | 51 | if (counters_need_update) { |
| 55 | transfer_matrix_values(raw, cooked, num_rows, current_time); | 52 | update_debounce_counters(num_rows, current_time); |
| 53 | } | ||
| 54 | |||
| 55 | if (changed) { | ||
| 56 | transfer_matrix_values(raw, cooked, num_rows, current_time); | ||
| 57 | } | ||
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | //If the current time is > debounce counter, set the counter to enable input. | 60 | // If the current time is > debounce counter, set the counter to enable input. |
| 59 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time) | 61 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time) { |
| 60 | { | 62 | counters_need_update = false; |
| 61 | debounce_counter_t *debounce_pointer = debounce_counters; | 63 | debounce_counter_t *debounce_pointer = debounce_counters; |
| 62 | for (uint8_t row = 0; row < num_rows; row++) | 64 | for (uint8_t row = 0; row < num_rows; row++) { |
| 63 | { | 65 | if (*debounce_pointer != DEBOUNCE_ELAPSED) { |
| 64 | if (*debounce_pointer != DEBOUNCE_ELAPSED) | ||
| 65 | { | ||
| 66 | if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) { | 66 | if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) { |
| 67 | *debounce_pointer = DEBOUNCE_ELAPSED; | 67 | *debounce_pointer = DEBOUNCE_ELAPSED; |
| 68 | } else { | ||
| 69 | counters_need_update = true; | ||
| 68 | } | 70 | } |
| 69 | } | 71 | } |
| 70 | debounce_pointer++; | 72 | debounce_pointer++; |
| @@ -72,29 +74,21 @@ void update_debounce_counters(uint8_t num_rows, uint8_t current_time) | |||
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | // upload from raw_matrix to final matrix; | 76 | // upload from raw_matrix to final matrix; |
| 75 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) | 77 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) { |
| 76 | { | ||
| 77 | debounce_counter_t *debounce_pointer = debounce_counters; | 78 | debounce_counter_t *debounce_pointer = debounce_counters; |
| 78 | for (uint8_t row = 0; row < num_rows; row++) | 79 | for (uint8_t row = 0; row < num_rows; row++) { |
| 79 | { | 80 | matrix_row_t existing_row = cooked[row]; |
| 80 | matrix_row_t existing_row = cooked[row]; | 81 | matrix_row_t raw_row = raw[row]; |
| 81 | matrix_row_t raw_row = raw[row]; | 82 | |
| 82 | 83 | // determine new value basd on debounce pointer + raw value | |
| 83 | //determine new value basd on debounce pointer + raw value | 84 | if (*debounce_pointer == DEBOUNCE_ELAPSED && (existing_row != raw_row)) { |
| 84 | if (*debounce_pointer == DEBOUNCE_ELAPSED && | 85 | *debounce_pointer = current_time; |
| 85 | (existing_row != raw_row)) | 86 | cooked[row] = raw_row; |
| 86 | { | 87 | counters_need_update = true; |
| 87 | *debounce_pointer = current_time; | ||
| 88 | existing_row = raw_row; | ||
| 89 | } | 88 | } |
| 90 | cooked[row] = existing_row; | ||
| 91 | |||
| 92 | debounce_pointer++; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | 89 | ||
| 96 | bool debounce_active(void) | 90 | debounce_pointer++; |
| 97 | { | 91 | } |
| 98 | return true; | ||
| 99 | } | 92 | } |
| 100 | 93 | ||
| 94 | bool debounce_active(void) { return true; } | ||
