aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-03-05 21:46:35 +0900
committertmk <nobody@nowhere>2013-03-05 21:46:35 +0900
commit5d6b848a157a2e94859949961297d40da6a77527 (patch)
tree685ba0477174789f5d64902a5cd96114346aa9d7
parent38bbe976e00a9a7bf6f8157016717e80503bf6a9 (diff)
parent81d2753ab07890532ea8c4bd6a68de3e5e08ca33 (diff)
downloadqmk_firmware-5d6b848a157a2e94859949961297d40da6a77527.tar.gz
qmk_firmware-5d6b848a157a2e94859949961297d40da6a77527.zip
Merge branch 'ghost_fix'
-rw-r--r--common/keyboard.c25
-rw-r--r--common/matrix.h4
-rw-r--r--keyboard/hbkb/Makefile.lufa1
-rw-r--r--keyboard/hbkb/matrix.c27
4 files changed, 26 insertions, 31 deletions
diff --git a/common/keyboard.c b/common/keyboard.c
index 432ea8934..91f321d9c 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -34,6 +34,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
34#endif 34#endif
35 35
36 36
37#ifdef MATRIX_HAS_GHOST
38static bool has_ghost_in_row(uint8_t row)
39{
40 matrix_row_t matrix_row = matrix_get_row(row);
41 // No ghost exists when less than 2 keys are down on the row
42 if (((matrix_row - 1) & matrix_row) == 0)
43 return false;
44
45 // Ghost occurs when the row shares column line with other row
46 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
47 if (i != row && (matrix_get_row(i) & matrix_row))
48 return true;
49 }
50 return false;
51}
52#endif
53
54
37void keyboard_init(void) 55void keyboard_init(void)
38{ 56{
39 // TODO: configuration of sendchar impl 57 // TODO: configuration of sendchar impl
@@ -81,7 +99,12 @@ void keyboard_task(void)
81 matrix_change = matrix_row ^ matrix_prev[r]; 99 matrix_change = matrix_row ^ matrix_prev[r];
82 if (matrix_change) { 100 if (matrix_change) {
83 if (debug_matrix) matrix_print(); 101 if (debug_matrix) matrix_print();
84 102#ifdef MATRIX_HAS_GHOST
103 if (has_ghost_in_row(r)) {
104 matrix_prev[r] = matrix_row;
105 continue;
106 }
107#endif
85 for (uint8_t c = 0; c < MATRIX_COLS; c++) { 108 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
86 if (matrix_change & ((matrix_row_t)1<<c)) { 109 if (matrix_change & ((matrix_row_t)1<<c)) {
87 action_exec((keyevent_t){ 110 action_exec((keyevent_t){
diff --git a/common/matrix.h b/common/matrix.h
index b3332d5ff..d62acb668 100644
--- a/common/matrix.h
+++ b/common/matrix.h
@@ -45,14 +45,10 @@ void matrix_init(void);
45uint8_t matrix_scan(void); 45uint8_t matrix_scan(void);
46/* whether modified from previous scan. used after matrix_scan. */ 46/* whether modified from previous scan. used after matrix_scan. */
47bool matrix_is_modified(void); 47bool matrix_is_modified(void);
48/* whether ghosting occur on matrix. */
49bool matrix_has_ghost(void);
50/* whether a swtich is on */ 48/* whether a swtich is on */
51bool matrix_is_on(uint8_t row, uint8_t col); 49bool matrix_is_on(uint8_t row, uint8_t col);
52/* matrix state on row */ 50/* matrix state on row */
53matrix_row_t matrix_get_row(uint8_t row); 51matrix_row_t matrix_get_row(uint8_t row);
54/* count keys pressed */
55uint8_t matrix_key_count(void);
56/* print matrix for debug */ 52/* print matrix for debug */
57void matrix_print(void); 53void matrix_print(void);
58 54
diff --git a/keyboard/hbkb/Makefile.lufa b/keyboard/hbkb/Makefile.lufa
index c73a0ca7d..33366d720 100644
--- a/keyboard/hbkb/Makefile.lufa
+++ b/keyboard/hbkb/Makefile.lufa
@@ -99,6 +99,7 @@ F_USB = $(F_CPU)
99# 99#
100MOUSEKEY_ENABLE = yes # Mouse keys 100MOUSEKEY_ENABLE = yes # Mouse keys
101EXTRAKEY_ENABLE = yes # Audio control and System control 101EXTRAKEY_ENABLE = yes # Audio control and System control
102CONSOLE_ENABLE = yes # Console for debug
102#NKRO_ENABLE = yes # USB Nkey Rollover 103#NKRO_ENABLE = yes # USB Nkey Rollover
103#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support 104#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
104 105
diff --git a/keyboard/hbkb/matrix.c b/keyboard/hbkb/matrix.c
index d7c066364..a24d24b8c 100644
--- a/keyboard/hbkb/matrix.c
+++ b/keyboard/hbkb/matrix.c
@@ -148,18 +148,6 @@ bool matrix_is_modified(void)
148} 148}
149 149
150inline 150inline
151bool matrix_has_ghost(void)
152{
153#ifdef MATRIX_HAS_GHOST
154 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
155 if (matrix_has_ghost_in_row(i))
156 return true;
157 }
158#endif
159 return false;
160}
161
162inline
163bool matrix_is_on(uint8_t row, uint8_t col) 151bool matrix_is_on(uint8_t row, uint8_t col)
164{ 152{
165 return (matrix[row] & (1<<col)); 153 return (matrix[row] & (1<<col));
@@ -194,19 +182,6 @@ void matrix_print(void)
194 } 182 }
195} 183}
196 184
197uint8_t matrix_key_count(void)
198{
199 uint8_t count = 0;
200 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
201#if (MATRIX_COLS <= 8)
202 count += bitpop(matrix[i]);
203#else
204 count += bitpop16(matrix[i]);
205#endif
206 }
207 return count;
208}
209
210#ifdef MATRIX_HAS_GHOST 185#ifdef MATRIX_HAS_GHOST
211inline 186inline
212static bool matrix_has_ghost_in_row(uint8_t row) 187static bool matrix_has_ghost_in_row(uint8_t row)
@@ -217,7 +192,7 @@ static bool matrix_has_ghost_in_row(uint8_t row)
217 192
218 // ghost exists in case same state as other row 193 // ghost exists in case same state as other row
219 for (uint8_t i=0; i < MATRIX_ROWS; i++) { 194 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
220 if (i != row && (matrix[i] & matrix[row]) == matrix[row]) 195 if (i != row && (matrix[i] & matrix[row]))
221 return true; 196 return true;
222 } 197 }
223 return false; 198 return false;