diff options
| author | Jeremiah <barrar@users.noreply.github.com> | 2017-05-13 18:24:43 -0700 |
|---|---|---|
| committer | Jeremiah <barrar@users.noreply.github.com> | 2017-05-13 18:24:43 -0700 |
| commit | 37f6f92765513cd66c92178f48785d492eb06b89 (patch) | |
| tree | eb31474d1c11d04bbe020262b65f9d254082693b /tmk_core/common/keyboard.c | |
| parent | 7b7e285a984a5bf1f7f38f1b5846811dfcb3a185 (diff) | |
| download | qmk_firmware-37f6f92765513cd66c92178f48785d492eb06b89.tar.gz qmk_firmware-37f6f92765513cd66c92178f48785d492eb06b89.zip | |
faster and less bits
Diffstat (limited to 'tmk_core/common/keyboard.c')
| -rw-r--r-- | tmk_core/common/keyboard.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 24cc28892..d8b5dc403 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c | |||
| @@ -63,14 +63,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | #ifdef MATRIX_HAS_GHOST | 65 | #ifdef MATRIX_HAS_GHOST |
| 66 | static matrix_row_t matrix_ghost_check[MATRIX_ROWS]; | 66 | extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; |
| 67 | static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata){ | ||
| 68 | matrix_row_t out = 0; | ||
| 69 | for (int col = 0; col < MATRIX_COLS; col++) { | ||
| 70 | if (pgm_read_byte(&keymaps[0][row][col]) && ((rowdata & (1<<col)))){ | ||
| 71 | out |= 1<<col; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | return out; | ||
| 75 | } | ||
| 76 | |||
| 67 | 77 | ||
| 68 | static inline bool countones(matrix_row_t data) | 78 | static inline bool countones(matrix_row_t data) |
| 69 | { | 79 | { |
| 70 | int count = 0; | 80 | int count = 0; |
| 71 | for (int col = 0; col < MATRIX_COLS; col++) { | 81 | for (int col = 0; col < MATRIX_COLS; col++) { |
| 72 | if (data & (1<<col)) | 82 | if (data & (1<<col)){ |
| 73 | count++; | 83 | count++; |
| 84 | } | ||
| 74 | } | 85 | } |
| 75 | if (count > 1){ | 86 | if (count > 1){ |
| 76 | return true; | 87 | return true; |
| @@ -79,7 +90,7 @@ static inline bool countones(matrix_row_t data) | |||
| 79 | } | 90 | } |
| 80 | static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) | 91 | static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) |
| 81 | { | 92 | { |
| 82 | rowdata &= matrix_ghost_check[row]; | 93 | rowdata = get_real_keys(row, rowdata); |
| 83 | if (((rowdata - 1) & rowdata) == 0){ | 94 | if (((rowdata - 1) & rowdata) == 0){ |
| 84 | return false; | 95 | return false; |
| 85 | } | 96 | } |
| @@ -90,24 +101,13 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) | |||
| 90 | // Ghost occurs when the row shares column line with other row, blanks in the matrix don't matter | 101 | // Ghost occurs when the row shares column line with other row, blanks in the matrix don't matter |
| 91 | // If there are more than two real keys pressed and they match another row's real keys, the row will be ignored. | 102 | // If there are more than two real keys pressed and they match another row's real keys, the row will be ignored. |
| 92 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | 103 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { |
| 93 | if (i != row && countones((matrix_get_row(i) & matrix_ghost_check[i]) & rowdata)){ | 104 | if (i != row && countones(get_real_keys(i, matrix_get_row(i)) & rowdata)){ |
| 94 | return true; | 105 | return true; |
| 95 | } | 106 | } |
| 96 | } | 107 | } |
| 97 | return false; | 108 | return false; |
| 98 | } | 109 | } |
| 99 | 110 | ||
| 100 | extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; | ||
| 101 | // bit map of true keys and empty spots in matrix, each row is reversed | ||
| 102 | static inline void make_ghost_check_array(void){ | ||
| 103 | for (int row = 0; row < MATRIX_ROWS; row++) { | ||
| 104 | for (int col = 0; col < MATRIX_COLS; col++) { | ||
| 105 | if (pgm_read_byte(&keymaps[0][row][col]) != 0) | ||
| 106 | matrix_ghost_check[row] |= 1<<col; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | #endif | 111 | #endif |
| 112 | 112 | ||
| 113 | 113 | ||
| @@ -148,9 +148,6 @@ void keyboard_init(void) { | |||
| 148 | #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) | 148 | #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) |
| 149 | keymap_config.nkro = 1; | 149 | keymap_config.nkro = 1; |
| 150 | #endif | 150 | #endif |
| 151 | #ifdef MATRIX_HAS_GHOST | ||
| 152 | make_ghost_check_array(); | ||
| 153 | #endif | ||
| 154 | } | 151 | } |
| 155 | 152 | ||
| 156 | /* | 153 | /* |
