diff options
| -rw-r--r-- | quantum/debounce/debounce_eager_pk.c | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/quantum/debounce/debounce_eager_pk.c b/quantum/debounce/debounce_eager_pk.c index e6e8bfd31..f1457496e 100644 --- a/quantum/debounce/debounce_eager_pk.c +++ b/quantum/debounce/debounce_eager_pk.c | |||
| @@ -39,22 +39,16 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred. | |||
| 39 | 39 | ||
| 40 | #define debounce_counter_t uint8_t | 40 | #define debounce_counter_t uint8_t |
| 41 | 41 | ||
| 42 | static matrix_row_t matrix_debounced[MATRIX_ROWS]; | ||
| 43 | static debounce_counter_t debounce_counters[MATRIX_ROWS*MATRIX_COLS]; | 42 | static debounce_counter_t debounce_counters[MATRIX_ROWS*MATRIX_COLS]; |
| 44 | 43 | ||
| 45 | #define DEBOUNCE_ELAPSED 251 | 44 | #define DEBOUNCE_ELAPSED 251 |
| 46 | #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) | 45 | #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) |
| 47 | 46 | ||
| 48 | void update_debounce_counters(uint8_t current_time); | 47 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time); |
| 49 | void transfer_matrix_values(uint8_t current_time); | 48 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time); |
| 50 | 49 | ||
| 51 | void matrix_debounce_init(void) | 50 | void debounce_init(uint8_t num_rows) |
| 52 | { | 51 | { |
| 53 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) | ||
| 54 | { | ||
| 55 | matrix_debounced[r] = 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | int i = 0; | 52 | int i = 0; |
| 59 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) | 53 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) |
| 60 | { | 54 | { |
| @@ -65,25 +59,24 @@ void matrix_debounce_init(void) | |||
| 65 | } | 59 | } |
| 66 | } | 60 | } |
| 67 | 61 | ||
| 68 | void matrix_debounce(void) | 62 | void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) |
| 69 | { | 63 | { |
| 70 | uint8_t current_time = timer_read() % MAX_DEBOUNCE; | 64 | uint8_t current_time = timer_read() % MAX_DEBOUNCE; |
| 71 | update_debounce_counters(current_time); | 65 | update_debounce_counters(num_rows, current_time); |
| 72 | transfer_matrix_values(current_time); | 66 | transfer_matrix_values(raw, cooked, num_rows, current_time); |
| 73 | } | 67 | } |
| 74 | 68 | ||
| 75 | //If the current time is > debounce counter, set the counter to enable input. | 69 | //If the current time is > debounce counter, set the counter to enable input. |
| 76 | void update_debounce_counters(uint8_t current_time) | 70 | void update_debounce_counters(uint8_t num_rows, uint8_t current_time) |
| 77 | { | 71 | { |
| 78 | debounce_counter_t *debounce_pointer = debounce_counters; | 72 | debounce_counter_t *debounce_pointer = debounce_counters; |
| 79 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) | 73 | for (uint8_t row = 0; row < num_rows; row++) |
| 80 | { | 74 | { |
| 81 | for (uint8_t col = 0; col < MATRIX_COLS; col++) | 75 | for (uint8_t col = 0; col < MATRIX_COLS; col++) |
| 82 | { | 76 | { |
| 83 | if (*debounce_pointer != DEBOUNCE_ELAPSED) | 77 | if (*debounce_pointer != DEBOUNCE_ELAPSED) |
| 84 | { | 78 | { |
| 85 | if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= | 79 | if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) { |
| 86 | DEBOUNCING_DELAY) { | ||
| 87 | *debounce_pointer = DEBOUNCE_ELAPSED; | 80 | *debounce_pointer = DEBOUNCE_ELAPSED; |
| 88 | } | 81 | } |
| 89 | } | 82 | } |
| @@ -93,13 +86,13 @@ void update_debounce_counters(uint8_t current_time) | |||
| 93 | } | 86 | } |
| 94 | 87 | ||
| 95 | // upload from raw_matrix to final matrix; | 88 | // upload from raw_matrix to final matrix; |
| 96 | void transfer_matrix_values(uint8_t current_time) | 89 | void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) |
| 97 | { | 90 | { |
| 98 | debounce_counter_t *debounce_pointer = debounce_counters; | 91 | debounce_counter_t *debounce_pointer = debounce_counters; |
| 99 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) | 92 | for (uint8_t row = 0; row < num_rows; row++) |
| 100 | { | 93 | { |
| 101 | matrix_row_t existing_row = matrix_debounced[row]; | 94 | matrix_row_t existing_row = cooked[row]; |
| 102 | matrix_row_t raw_row = matrix_get_row(row); | 95 | matrix_row_t raw_row = raw[row]; |
| 103 | 96 | ||
| 104 | for (uint8_t col = 0; col < MATRIX_COLS; col++) | 97 | for (uint8_t col = 0; col < MATRIX_COLS; col++) |
| 105 | { | 98 | { |
| @@ -114,10 +107,12 @@ void transfer_matrix_values(uint8_t current_time) | |||
| 114 | } | 107 | } |
| 115 | debounce_pointer++; | 108 | debounce_pointer++; |
| 116 | } | 109 | } |
| 117 | matrix_debounced[row] = existing_row; | 110 | cooked[row] = existing_row; |
| 118 | } | 111 | } |
| 119 | } | 112 | } |
| 120 | 113 | ||
| 114 | bool debounce_active() | ||
| 115 | { | ||
| 116 | return true; | ||
| 117 | } | ||
| 121 | 118 | ||
| 122 | |||
| 123 | //Implementation of no debounce. | ||
