diff options
Diffstat (limited to 'quantum/split_common/matrix.c')
-rw-r--r-- | quantum/split_common/matrix.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 95ee2433a..5bad9db08 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c | |||
@@ -61,17 +61,22 @@ static void init_pins(void) { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 63 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
64 | matrix_row_t last_row_value = current_matrix[current_row]; | 64 | // Start with a clear matrix row |
65 | current_matrix[current_row] = 0; | 65 | matrix_row_t current_row_value = 0; |
66 | 66 | ||
67 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 67 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { |
68 | pin_t pin = direct_pins[current_row][col_index]; | 68 | pin_t pin = direct_pins[current_row][col_index]; |
69 | if (pin != NO_PIN) { | 69 | if (pin != NO_PIN) { |
70 | current_matrix[current_row] |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); | 70 | current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); |
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | return (last_row_value != current_matrix[current_row]); | 74 | // If the row has changed, store the row and return the changed flag. |
75 | if (current_matrix[current_row] != current_row_value) { | ||
76 | current_matrix[current_row] = current_row_value; | ||
77 | return true; | ||
78 | } | ||
79 | return false; | ||
75 | } | 80 | } |
76 | 81 | ||
77 | #elif defined(DIODE_DIRECTION) | 82 | #elif defined(DIODE_DIRECTION) |
@@ -98,11 +103,8 @@ static void init_pins(void) { | |||
98 | } | 103 | } |
99 | 104 | ||
100 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 105 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
101 | // Store last value of row prior to reading | 106 | // Start with a clear matrix row |
102 | matrix_row_t last_row_value = current_matrix[current_row]; | 107 | matrix_row_t current_row_value = 0; |
103 | |||
104 | // Clear data in matrix row | ||
105 | current_matrix[current_row] = 0; | ||
106 | 108 | ||
107 | // Select row and wait for row selecton to stabilize | 109 | // Select row and wait for row selecton to stabilize |
108 | select_row(current_row); | 110 | select_row(current_row); |
@@ -114,13 +116,18 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
114 | uint8_t pin_state = readPin(col_pins[col_index]); | 116 | uint8_t pin_state = readPin(col_pins[col_index]); |
115 | 117 | ||
116 | // Populate the matrix row with the state of the col pin | 118 | // Populate the matrix row with the state of the col pin |
117 | current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); | 119 | current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); |
118 | } | 120 | } |
119 | 121 | ||
120 | // Unselect row | 122 | // Unselect row |
121 | unselect_row(current_row); | 123 | unselect_row(current_row); |
122 | 124 | ||
123 | return (last_row_value != current_matrix[current_row]); | 125 | // If the row has changed, store the row and return the changed flag. |
126 | if (current_matrix[current_row] != current_row_value) { | ||
127 | current_matrix[current_row] = current_row_value; | ||
128 | return true; | ||
129 | } | ||
130 | return false; | ||
124 | } | 131 | } |
125 | 132 | ||
126 | # elif (DIODE_DIRECTION == ROW2COL) | 133 | # elif (DIODE_DIRECTION == ROW2COL) |
@@ -155,20 +162,22 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) | |||
155 | // For each row... | 162 | // For each row... |
156 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { | 163 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { |
157 | // Store last value of row prior to reading | 164 | // Store last value of row prior to reading |
158 | matrix_row_t last_row_value = current_matrix[row_index]; | 165 | matrix_row_t last_row_value = current_matrix[row_index]; |
166 | matrix_row_t current_row_value = last_row_value; | ||
159 | 167 | ||
160 | // Check row pin state | 168 | // Check row pin state |
161 | if (readPin(row_pins[row_index]) == 0) { | 169 | if (readPin(row_pins[row_index]) == 0) { |
162 | // Pin LO, set col bit | 170 | // Pin LO, set col bit |
163 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); | 171 | current_row_value |= (MATRIX_ROW_SHIFTER << current_col); |
164 | } else { | 172 | } else { |
165 | // Pin HI, clear col bit | 173 | // Pin HI, clear col bit |
166 | current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); | 174 | current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); |
167 | } | 175 | } |
168 | 176 | ||
169 | // Determine if the matrix changed state | 177 | // Determine if the matrix changed state |
170 | if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) { | 178 | if ((last_row_value != current_row_value)) { |
171 | matrix_changed = true; | 179 | matrix_changed |= true; |
180 | current_matrix[row_index] = current_row_value; | ||
172 | } | 181 | } |
173 | } | 182 | } |
174 | 183 | ||