diff options
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/common/keyboard.c | 36 | ||||
| -rw-r--r-- | tmk_core/common/keyboard.h | 2 |
2 files changed, 31 insertions, 7 deletions
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index eac1f1dd8..93a066e57 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c | |||
| @@ -64,20 +64,41 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | #ifdef MATRIX_HAS_GHOST | 66 | #ifdef MATRIX_HAS_GHOST |
| 67 | static uint16_t matrix_ghost_check[MATRIX_ROWS]; | ||
| 67 | static bool has_ghost_in_row(uint8_t row) | 68 | static bool has_ghost_in_row(uint8_t row) |
| 68 | { | 69 | { |
| 69 | matrix_row_t matrix_row = matrix_get_row(row); | 70 | matrix_row_t matrix_row = (matrix_get_row(row) & matrix_ghost_check[row]); |
| 70 | // No ghost exists when less than 2 keys are down on the row | 71 | /* No ghost exists when less than 2 keys are down on the row. |
| 71 | if (((matrix_row - 1) & matrix_row) == 0) | 72 | If there are "active" blanks in the matrix, the key can't be pressed by the user, |
| 73 | there is no doubt as to which keys are really being pressed. | ||
| 74 | The ghosts will be ignored, they are KC_NO. */ | ||
| 75 | if (((matrix_row - 1) & matrix_row) == 0){ | ||
| 72 | return false; | 76 | return false; |
| 73 | 77 | } | |
| 74 | // Ghost occurs when the row shares column line with other row | 78 | // Ghost occurs when the row shares column line with other row, blanks in the matrix don't matter |
| 79 | // If there are more than two real keys pressed and they match another row's real keys, the row will be ignored. | ||
| 75 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | 80 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { |
| 76 | if (i != row && (matrix_get_row(i) & matrix_row)) | 81 | if (i != row && __builtin_popcount((matrix_get_row(i) & matrix_ghost_check[i]) & matrix_row) > 1){ |
| 77 | return true; | 82 | return true; |
| 83 | } | ||
| 78 | } | 84 | } |
| 79 | return false; | 85 | return false; |
| 86 | return false; | ||
| 80 | } | 87 | } |
| 88 | |||
| 89 | extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; | ||
| 90 | // bit map of true keys and empty spots in matrix, each row is reversed | ||
| 91 | void make_ghost_check_array(){ | ||
| 92 | for (int row = 0; row < MATRIX_ROWS; row++) { | ||
| 93 | for (int col = 0; col < MATRIX_COLS; col++) { | ||
| 94 | if (keymaps[0][row][col] & 0xFF) | ||
| 95 | matrix_ghost_check[row] |= 1<<col; | ||
| 96 | else | ||
| 97 | matrix_ghost_check[row] |= 0<<col; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 81 | #endif | 102 | #endif |
| 82 | 103 | ||
| 83 | __attribute__ ((weak)) | 104 | __attribute__ ((weak)) |
| @@ -117,6 +138,9 @@ void keyboard_init(void) { | |||
| 117 | #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) | 138 | #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) |
| 118 | keymap_config.nkro = 1; | 139 | keymap_config.nkro = 1; |
| 119 | #endif | 140 | #endif |
| 141 | #ifdef MATRIX_HAS_GHOST | ||
| 142 | make_ghost_check_array(); | ||
| 143 | #endif | ||
| 120 | } | 144 | } |
| 121 | 145 | ||
| 122 | /* | 146 | /* |
diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h index 7738251b6..fe2a8fe81 100644 --- a/tmk_core/common/keyboard.h +++ b/tmk_core/common/keyboard.h | |||
| @@ -57,7 +57,7 @@ static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && | |||
| 57 | .time = (timer_read() | 1) \ | 57 | .time = (timer_read() | 1) \ |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | 60 | void make_ghost_check_array(void); | |
| 61 | /* it runs once at early stage of startup before keyboard_init. */ | 61 | /* it runs once at early stage of startup before keyboard_init. */ |
| 62 | void keyboard_setup(void); | 62 | void keyboard_setup(void); |
| 63 | /* it runs once after initializing host side protocol, debug and MCU peripherals. */ | 63 | /* it runs once after initializing host side protocol, debug and MCU peripherals. */ |
