From 99877cdff3f891127e806a9bde7105e6250f3737 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sat, 13 May 2017 16:57:23 -0700 Subject: [PATCH] a bit smaller --- tmk_core/common/keyboard.c | 59 ++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 116914e1a..d1794c887 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -63,40 +63,54 @@ along with this program. If not, see . #ifdef MATRIX_HAS_GHOST -extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; -// bit map of true keys and empty spots in matrix, each row is reversed -static uint16_t get_row_ghost_check(uint16_t row){ - for (int col = 0; col < MATRIX_COLS; col++) { - if (keymaps[0][row][col]) - row &= 1< 1){ + return true; + } + return false; +} +static inline bool has_ghost_in_row(uint8_t row, uint16_t rowdata) +{ + rowdata &= matrix_ghost_check[row]; + if (((rowdata - 1) & rowdata) == 0){ + return false; + } /* No ghost exists when less than 2 keys are down on the row. If there are "active" blanks in the matrix, the key can't be pressed by the user, there is no doubt as to which keys are really being pressed. The ghosts will be ignored, they are KC_NO. */ - if (((matrix_row - 1) & matrix_row) == 0){ - return false; - } // Ghost occurs when the row shares column line with other row, blanks in the matrix don't matter - // If there are two or more real keys pressed and they match another row's real keys, the row will be ignored. + // If there are more than two real keys pressed and they match another row's real keys, the row will be ignored. for (uint8_t i=0; i < MATRIX_ROWS; i++) { - if (i != row && __builtin_popcount( - get_row_ghost_check(matrix_get_row(i)) & matrix_row - ) > 1){ + if (i != row && countones((matrix_get_row(i) & matrix_ghost_check[i]) & rowdata)){ return true; } } return false; } + +extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; +// bit map of true keys and empty spots in matrix, each row is reversed +static inline void make_ghost_check_array(void){ + for (int row = 0; row < MATRIX_ROWS; row++) { + for (int col = 0; col < MATRIX_COLS; col++) { + if (pgm_read_byte(&keymaps[0][row][col]) != 0) + matrix_ghost_check[row] |= 1<