diff options
| author | Alex Ong <the.onga@gmail.com> | 2019-04-04 08:45:55 +1100 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-04-03 14:45:55 -0700 |
| commit | 17e7762de7e3fdfc61c20aa61022f47370630c6a (patch) | |
| tree | acad10cdb64e24d78154c7c04de3585dece32cc3 /quantum/debounce | |
| parent | e1e08a494bf9ea46e1385559df76d5f49b8e9087 (diff) | |
| download | qmk_firmware-17e7762de7e3fdfc61c20aa61022f47370630c6a.tar.gz qmk_firmware-17e7762de7e3fdfc61c20aa61022f47370630c6a.zip | |
Eager Per Row Debouncing added (added to Ergodox) (#5498)
* Implemented Eager Per Row debouncing algorithm.
Good for when fingers can only press one row at a time (e.g. when keyboard is wired so that "rows" are vertical)
* Added documentation for eager_pr
* Ported ergodox_ez to eager_pr debouncing.
* Removed check for changes in matrix_scan.
* Added further clarification in docs.
* Accidental merge with ergodox_ez
* Small cleanup in eager_pr
* Forgot to debounce_init - this would probably cause seg-faults.
Diffstat (limited to 'quantum/debounce')
| -rw-r--r-- | quantum/debounce/eager_pr.c | 100 | ||||
| -rw-r--r-- | quantum/debounce/readme.md | 2 |
2 files changed, 101 insertions, 1 deletions
diff --git a/quantum/debounce/eager_pr.c b/quantum/debounce/eager_pr.c new file mode 100644 index 000000000..9eb9480a7 --- /dev/null +++ b/quantum/debounce/eager_pr.c | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2019 Alex Ong<the.onga@gmail.com> | ||
| 3 | This program is free software: you can redistribute it and/or modify | ||
| 4 | it under the terms of the GNU General Public License as published by | ||
| 5 | the Free Software Foundation, either version 2 of the License, or | ||
| 6 | (at your option) any later version. | ||
| 7 | This program is distributed in the hope that it will be useful, | ||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 10 | GNU General Public License for more details. | ||
| 11 | You should have received a copy of the GNU General Public License | ||
| 12 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 13 | */ | ||
| 14 | |||
| 15 | /* | ||
| 16 | Basic per-row algorithm. Uses an 8-bit counter per row. | ||
| 17 | After pressing a key, it immediately changes state, and sets a counter. | ||
| 18 | No further inputs are accepted until DEBOUNCE milliseconds have occurred. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include "matrix.h" | ||
| 22 | #include "timer.h" | ||
| 23 | #include "quantum.h" | ||
| 24 | #include <stdlib.h> | ||
| 25 | |||
| 26 | #ifndef DEBOUNCE | ||
| 27 | #define DEBOUNCE 5 | ||
| 28 | #endif | ||
| 29 | |||
| 30 | |||
| 31 | #define debounce_counter_t uint8_t | ||
| 32 | |||
| 33 | static debounce_counter_t *debounce_counters; | ||
| 34 | |||
| 35 | #define DEBOUNCE_ELAPSED 251 | ||
| 36 | #define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1) | ||
| 37 | |||
| 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); | ||
| 40 | |||
| 41 | //we use num_rows rather than MATRIX_ROWS to support split keyboards | ||
| 42 | void debounce_init(uint8_t num_rows) | ||
| 43 | { | ||
| 44 | debounce_counters = (debounce_counter_t*)malloc(num_rows*sizeof(debounce_counter_t)); | ||
| 45 | for (uint8_t r = 0; r < num_rows; r++) | ||
| 46 | { | ||
| 47 | debounce_counters[r] = DEBOUNCE_ELAPSED; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | 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; | ||
| 54 | update_debounce_counters(num_rows, current_time); | ||
| 55 | transfer_matrix_values(raw, cooked, num_rows, current_time); | ||
| 56 | } | ||
| 57 | |||
| 58 | //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) | ||
| 60 | { | ||
| 61 | debounce_counter_t *debounce_pointer = debounce_counters; | ||
| 62 | for (uint8_t row = 0; row < num_rows; row++) | ||
| 63 | { | ||
| 64 | if (*debounce_pointer != DEBOUNCE_ELAPSED) | ||
| 65 | { | ||
| 66 | if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) { | ||
| 67 | *debounce_pointer = DEBOUNCE_ELAPSED; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | debounce_pointer++; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | // 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) | ||
| 76 | { | ||
| 77 | debounce_counter_t *debounce_pointer = debounce_counters; | ||
| 78 | for (uint8_t row = 0; row < num_rows; row++) | ||
| 79 | { | ||
| 80 | matrix_row_t existing_row = cooked[row]; | ||
| 81 | matrix_row_t raw_row = raw[row]; | ||
| 82 | |||
| 83 | //determine new value basd on debounce pointer + raw value | ||
| 84 | if (*debounce_pointer == DEBOUNCE_ELAPSED && | ||
| 85 | (existing_row != raw_row)) | ||
| 86 | { | ||
| 87 | *debounce_pointer = current_time; | ||
| 88 | existing_row = raw_row; | ||
| 89 | } | ||
| 90 | cooked[row] = existing_row; | ||
| 91 | |||
| 92 | debounce_pointer++; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | bool debounce_active(void) | ||
| 97 | { | ||
| 98 | return true; | ||
| 99 | } | ||
| 100 | |||
diff --git a/quantum/debounce/readme.md b/quantum/debounce/readme.md index 5b318d845..f77f78c76 100644 --- a/quantum/debounce/readme.md +++ b/quantum/debounce/readme.md | |||
| @@ -22,7 +22,7 @@ Here are a few that could be implemented: | |||
| 22 | sym_g.c | 22 | sym_g.c |
| 23 | sym_pk.c | 23 | sym_pk.c |
| 24 | sym_pr.c | 24 | sym_pr.c |
| 25 | sym_pr_cycles.c //currently used in ergo-dox | 25 | sym_pr_cycles.c |
| 26 | eager_g.c | 26 | eager_g.c |
| 27 | eager_pk.c | 27 | eager_pk.c |
| 28 | eager_pr.c //could be used in ergo-dox! | 28 | eager_pr.c //could be used in ergo-dox! |
