From 9e9a85c1426650148d0d83c900e432003ff174fb Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 5 Mar 2013 19:18:01 +0900 Subject: Fix ghost block and remove matrix_has_ghost() --- common/keyboard.c | 25 ++++++++++++++++++++++++- common/matrix.h | 2 -- keyboard/hbkb/Makefile.lufa | 1 + keyboard/hbkb/matrix.c | 15 ++------------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/common/keyboard.c b/common/keyboard.c index 432ea89347..91f321d9ca 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -34,6 +34,24 @@ along with this program. If not, see . #endif +#ifdef MATRIX_HAS_GHOST +static bool has_ghost_in_row(uint8_t row) +{ + matrix_row_t matrix_row = matrix_get_row(row); + // No ghost exists when less than 2 keys are down on the row + if (((matrix_row - 1) & matrix_row) == 0) + return false; + + // Ghost occurs when the row shares column line with other row + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + if (i != row && (matrix_get_row(i) & matrix_row)) + return true; + } + return false; +} +#endif + + void keyboard_init(void) { // TODO: configuration of sendchar impl @@ -81,7 +99,12 @@ void keyboard_task(void) matrix_change = matrix_row ^ matrix_prev[r]; if (matrix_change) { if (debug_matrix) matrix_print(); - +#ifdef MATRIX_HAS_GHOST + if (has_ghost_in_row(r)) { + matrix_prev[r] = matrix_row; + continue; + } +#endif for (uint8_t c = 0; c < MATRIX_COLS; c++) { if (matrix_change & ((matrix_row_t)1< Date: Tue, 5 Mar 2013 21:20:39 +0900 Subject: Remove matrix_key_count() from matrix.h --- common/matrix.h | 2 -- keyboard/hbkb/matrix.c | 14 -------------- 2 files changed, 16 deletions(-) diff --git a/common/matrix.h b/common/matrix.h index 48203c71dc..d62acb6683 100644 --- a/common/matrix.h +++ b/common/matrix.h @@ -49,8 +49,6 @@ bool matrix_is_modified(void); bool matrix_is_on(uint8_t row, uint8_t col); /* matrix state on row */ matrix_row_t matrix_get_row(uint8_t row); -/* count keys pressed */ -uint8_t matrix_key_count(void); /* print matrix for debug */ void matrix_print(void); diff --git a/keyboard/hbkb/matrix.c b/keyboard/hbkb/matrix.c index f3a0cde5f3..a24d24b8c3 100644 --- a/keyboard/hbkb/matrix.c +++ b/keyboard/hbkb/matrix.c @@ -182,19 +182,6 @@ void matrix_print(void) } } -uint8_t matrix_key_count(void) -{ - uint8_t count = 0; - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { -#if (MATRIX_COLS <= 8) - count += bitpop(matrix[i]); -#else - count += bitpop16(matrix[i]); -#endif - } - return count; -} - #ifdef MATRIX_HAS_GHOST inline static bool matrix_has_ghost_in_row(uint8_t row) @@ -205,7 +192,6 @@ static bool matrix_has_ghost_in_row(uint8_t row) // ghost exists in case same state as other row for (uint8_t i=0; i < MATRIX_ROWS; i++) { - //if (i != row && (matrix[i] & matrix[row]) == matrix[row]) if (i != row && (matrix[i] & matrix[row])) return true; } -- cgit v1.2.3