diff options
| author | Jeremiah <barrar@users.noreply.github.com> | 2017-05-14 15:36:44 -0700 |
|---|---|---|
| committer | Jeremiah <barrar@users.noreply.github.com> | 2017-05-14 15:36:44 -0700 |
| commit | 25c6ca750fc74376a2bea7612c0e05401d3ecf5e (patch) | |
| tree | 2ae4ab66a78439ac9c6699a70f36efafc8cec295 /tmk_core | |
| parent | 84395e8a0427bcb51c4ef4ff24c7901d1fbb0764 (diff) | |
| download | qmk_firmware-25c6ca750fc74376a2bea7612c0e05401d3ecf5e.tar.gz qmk_firmware-25c6ca750fc74376a2bea7612c0e05401d3ecf5e.zip | |
added comments and made function name clearer
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/common/keyboard.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index a3fe559f3..97a8f1cd8 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c | |||
| @@ -61,39 +61,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 61 | # include "visualizer/visualizer.h" | 61 | # include "visualizer/visualizer.h" |
| 62 | #endif | 62 | #endif |
| 63 | 63 | ||
| 64 | |||
| 65 | #ifdef MATRIX_HAS_GHOST | 64 | #ifdef MATRIX_HAS_GHOST |
| 66 | extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; | 65 | extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; |
| 67 | static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata){ | 66 | static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata){ |
| 68 | matrix_row_t out = 0; | 67 | matrix_row_t out = 0; |
| 69 | for (int col = 0; col < MATRIX_COLS; col++) { | 68 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { |
| 69 | //read each key in the row data and check if the keymap defines it as a real key | ||
| 70 | if (pgm_read_byte(&keymaps[0][row][col]) && (rowdata & (1<<col))){ | 70 | if (pgm_read_byte(&keymaps[0][row][col]) && (rowdata & (1<<col))){ |
| 71 | //this creates new row data, if a key is defined in the keymap, it will be set here | ||
| 71 | out |= 1<<col; | 72 | out |= 1<<col; |
| 72 | } | 73 | } |
| 73 | } | 74 | } |
| 74 | return out; | 75 | return out; |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | static inline bool countones(matrix_row_t row) | 78 | static inline bool popcount_more_than_one(matrix_row_t rowdata) |
| 78 | { | 79 | { |
| 79 | row &= row-1; | 80 | rowdata &= rowdata-1; //if there are less than two bits (keys) set, rowdata will become zero |
| 80 | return row; | 81 | return rowdata; |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) | 84 | static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) |
| 84 | { | 85 | { |
| 85 | rowdata = get_real_keys(row, rowdata); | ||
| 86 | if ((countones(rowdata)) == 0){ | ||
| 87 | return false; | ||
| 88 | } | ||
| 89 | /* No ghost exists when less than 2 keys are down on the row. | 86 | /* No ghost exists when less than 2 keys are down on the row. |
| 90 | If there are "active" blanks in the matrix, the key can't be pressed by the user, | 87 | If there are "active" blanks in the matrix, the key can't be pressed by the user, |
| 91 | there is no doubt as to which keys are really being pressed. | 88 | there is no doubt as to which keys are really being pressed. |
| 92 | The ghosts will be ignored, they are KC_NO. */ | 89 | The ghosts will be ignored, they are KC_NO. */ |
| 93 | // Ghost occurs when the row shares column line with other row, blanks in the matrix don't matter | 90 | rowdata = get_real_keys(row, rowdata); |
| 94 | // If there are more than two real keys pressed and they match another row's real keys, the row will be ignored. | 91 | if ((popcount_more_than_one(rowdata)) == 0){ |
| 92 | return false; | ||
| 93 | } | ||
| 94 | /* Ghost occurs when the row shares a column line with other row, | ||
| 95 | and two columns are read on each row. Blanks in the matrix don't matter, | ||
| 96 | so they are filtered out. | ||
| 97 | If there are two or more real keys pressed and they match columns with | ||
| 98 | at least two of another row's real keys, the row will be ignored. Keep in mind, | ||
| 99 | we are checking one row at a time, not all of them at once. | ||
| 100 | */ | ||
| 95 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | 101 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { |
| 96 | if (i != row && countones(get_real_keys(i, matrix_get_row(i)) & rowdata)){ | 102 | if (i != row && popcount_more_than_one(get_real_keys(i, matrix_get_row(i)) & rowdata)){ |
| 97 | return true; | 103 | return true; |
| 98 | } | 104 | } |
| 99 | } | 105 | } |
| @@ -102,7 +108,6 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) | |||
| 102 | 108 | ||
| 103 | #endif | 109 | #endif |
| 104 | 110 | ||
| 105 | |||
| 106 | __attribute__ ((weak)) | 111 | __attribute__ ((weak)) |
| 107 | void matrix_setup(void) { | 112 | void matrix_setup(void) { |
| 108 | } | 113 | } |
