aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorJeremiah <jeremiah.barrar@gmail.com>2017-05-13 13:19:28 -0700
committerJeremiah <jeremiah.barrar@gmail.com>2017-05-13 13:19:28 -0700
commitb9895771edb4cca2bb17f5872a0e6ee068c91500 (patch)
tree2f362902a2f881c90bc8698e0a5b3e93680a6502 /tmk_core
parent849ed5a6a03b14defa94a50b66169abac89b9c08 (diff)
downloadqmk_firmware-b9895771edb4cca2bb17f5872a0e6ee068c91500.tar.gz
qmk_firmware-b9895771edb4cca2bb17f5872a0e6ee068c91500.zip
improvements
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common/keyboard.c39
-rw-r--r--tmk_core/common/keyboard.h1
2 files changed, 16 insertions, 24 deletions
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 93a066e57..116914e1a 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -62,12 +62,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
62#endif 62#endif
63 63
64 64
65
66#ifdef MATRIX_HAS_GHOST 65#ifdef MATRIX_HAS_GHOST
67static uint16_t matrix_ghost_check[MATRIX_ROWS]; 66extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
67// bit map of true keys and empty spots in matrix, each row is reversed
68static uint16_t get_row_ghost_check(uint16_t row){
69 for (int col = 0; col < MATRIX_COLS; col++) {
70 if (keymaps[0][row][col])
71 row &= 1<<col;
72 else
73 row &= 0<<col;
74 }
75 return row;
76}
68static bool has_ghost_in_row(uint8_t row) 77static bool has_ghost_in_row(uint8_t row)
69{ 78{
70 matrix_row_t matrix_row = (matrix_get_row(row) & matrix_ghost_check[row]); 79 matrix_row_t matrix_row = (get_row_ghost_check(matrix_get_row(row)));
71 /* No ghost exists when less than 2 keys are down on the row. 80 /* No ghost exists when less than 2 keys are down on the row.
72 If there are "active" blanks in the matrix, the key can't be pressed by the user, 81 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. 82 there is no doubt as to which keys are really being pressed.
@@ -76,29 +85,16 @@ static bool has_ghost_in_row(uint8_t row)
76 return false; 85 return false;
77 } 86 }
78 // Ghost occurs when the row shares column line with other row, blanks in the matrix don't matter 87 // 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. 88 // If there are two or more real keys pressed and they match another row's real keys, the row will be ignored.
80 for (uint8_t i=0; i < MATRIX_ROWS; i++) { 89 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
81 if (i != row && __builtin_popcount((matrix_get_row(i) & matrix_ghost_check[i]) & matrix_row) > 1){ 90 if (i != row && __builtin_popcount(
91 get_row_ghost_check(matrix_get_row(i)) & matrix_row
92 ) > 1){
82 return true; 93 return true;
83 } 94 }
84 } 95 }
85 return false; 96 return false;
86 return false;
87} 97}
88
89extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
90// bit map of true keys and empty spots in matrix, each row is reversed
91void 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
102#endif 98#endif
103 99
104__attribute__ ((weak)) 100__attribute__ ((weak))
@@ -138,9 +134,6 @@ void keyboard_init(void) {
138#if defined(NKRO_ENABLE) && defined(FORCE_NKRO) 134#if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
139 keymap_config.nkro = 1; 135 keymap_config.nkro = 1;
140#endif 136#endif
141#ifdef MATRIX_HAS_GHOST
142 make_ghost_check_array();
143#endif
144} 137}
145 138
146/* 139/*
diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h
index fe2a8fe81..f17003c2f 100644
--- a/tmk_core/common/keyboard.h
+++ b/tmk_core/common/keyboard.h
@@ -57,7 +57,6 @@ 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
60void make_ghost_check_array(void);
61/* it runs once at early stage of startup before keyboard_init. */ 60/* it runs once at early stage of startup before keyboard_init. */
62void keyboard_setup(void); 61void keyboard_setup(void);
63/* it runs once after initializing host side protocol, debug and MCU peripherals. */ 62/* it runs once after initializing host side protocol, debug and MCU peripherals. */