diff options
| author | Jeremiah <jeremiah.barrar@gmail.com> | 2017-05-13 08:51:20 -0700 |
|---|---|---|
| committer | Jeremiah <jeremiah.barrar@gmail.com> | 2017-05-13 08:51:20 -0700 |
| commit | 849ed5a6a03b14defa94a50b66169abac89b9c08 (patch) | |
| tree | cd39b90ae92c499f763e37fb502abee080cc1164 /tmk_core/common/keyboard.c | |
| parent | 4fe58aa6ec53b0f2a08b8a80f3465f8544ea5118 (diff) | |
| download | qmk_firmware-849ed5a6a03b14defa94a50b66169abac89b9c08.tar.gz qmk_firmware-849ed5a6a03b14defa94a50b66169abac89b9c08.zip | |
anti-ghost improvement for older keyboards with empty spots in matrix
Diffstat (limited to 'tmk_core/common/keyboard.c')
| -rw-r--r-- | tmk_core/common/keyboard.c | 36 |
1 files changed, 30 insertions, 6 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 | /* |
