diff options
Diffstat (limited to 'quantum/split_common/matrix.c')
| -rw-r--r-- | quantum/split_common/matrix.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 51bf8b109..bad762b49 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c | |||
| @@ -114,9 +114,9 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
| 114 | // Start with a clear matrix row | 114 | // Start with a clear matrix row |
| 115 | matrix_row_t current_row_value = 0; | 115 | matrix_row_t current_row_value = 0; |
| 116 | 116 | ||
| 117 | // Select row and wait for row selecton to stabilize | 117 | // Select row |
| 118 | select_row(current_row); | 118 | select_row(current_row); |
| 119 | matrix_io_delay(); | 119 | matrix_output_select_delay(); |
| 120 | 120 | ||
| 121 | // For each col... | 121 | // For each col... |
| 122 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 122 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { |
| @@ -129,6 +129,9 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
| 129 | 129 | ||
| 130 | // Unselect row | 130 | // Unselect row |
| 131 | unselect_row(current_row); | 131 | unselect_row(current_row); |
| 132 | if (current_row + 1 < MATRIX_ROWS) { | ||
| 133 | matrix_output_unselect_delay(); // wait for row signal to go HIGH | ||
| 134 | } | ||
| 132 | 135 | ||
| 133 | // If the row has changed, store the row and return the changed flag. | 136 | // If the row has changed, store the row and return the changed flag. |
| 134 | if (current_matrix[current_row] != current_row_value) { | 137 | if (current_matrix[current_row] != current_row_value) { |
| @@ -160,9 +163,9 @@ static void init_pins(void) { | |||
| 160 | static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | 163 | static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { |
| 161 | bool matrix_changed = false; | 164 | bool matrix_changed = false; |
| 162 | 165 | ||
| 163 | // Select col and wait for col selecton to stabilize | 166 | // Select col |
| 164 | select_col(current_col); | 167 | select_col(current_col); |
| 165 | matrix_io_delay(); | 168 | matrix_output_select_delay(); |
| 166 | 169 | ||
| 167 | // For each row... | 170 | // For each row... |
| 168 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { | 171 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { |
| @@ -188,6 +191,9 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) | |||
| 188 | 191 | ||
| 189 | // Unselect col | 192 | // Unselect col |
| 190 | unselect_col(current_col); | 193 | unselect_col(current_col); |
| 194 | if (current_col + 1 < MATRIX_COLS) { | ||
| 195 | matrix_output_unselect_delay(); // wait for col signal to go HIGH | ||
| 196 | } | ||
| 191 | 197 | ||
| 192 | return matrix_changed; | 198 | return matrix_changed; |
| 193 | } | 199 | } |
| @@ -245,21 +251,33 @@ void matrix_init(void) { | |||
| 245 | split_post_init(); | 251 | split_post_init(); |
| 246 | } | 252 | } |
| 247 | 253 | ||
| 248 | void matrix_post_scan(void) { | 254 | bool matrix_post_scan(void) { |
| 255 | bool changed = false; | ||
| 249 | if (is_keyboard_master()) { | 256 | if (is_keyboard_master()) { |
| 250 | static uint8_t error_count; | 257 | static uint8_t error_count; |
| 251 | 258 | ||
| 252 | if (!transport_master(matrix + thatHand)) { | 259 | matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; |
| 260 | if (!transport_master(slave_matrix)) { | ||
| 253 | error_count++; | 261 | error_count++; |
| 254 | 262 | ||
| 255 | if (error_count > ERROR_DISCONNECT_COUNT) { | 263 | if (error_count > ERROR_DISCONNECT_COUNT) { |
| 256 | // reset other half if disconnected | 264 | // reset other half if disconnected |
| 257 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 265 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
| 258 | matrix[thatHand + i] = 0; | 266 | matrix[thatHand + i] = 0; |
| 267 | slave_matrix[i] = 0; | ||
| 259 | } | 268 | } |
| 269 | |||
| 270 | changed = true; | ||
| 260 | } | 271 | } |
| 261 | } else { | 272 | } else { |
| 262 | error_count = 0; | 273 | error_count = 0; |
| 274 | |||
| 275 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 276 | if (matrix[thatHand + i] != slave_matrix[i]) { | ||
| 277 | matrix[thatHand + i] = slave_matrix[i]; | ||
| 278 | changed = true; | ||
| 279 | } | ||
| 280 | } | ||
| 263 | } | 281 | } |
| 264 | 282 | ||
| 265 | matrix_scan_quantum(); | 283 | matrix_scan_quantum(); |
| @@ -268,25 +286,27 @@ void matrix_post_scan(void) { | |||
| 268 | 286 | ||
| 269 | matrix_slave_scan_user(); | 287 | matrix_slave_scan_user(); |
| 270 | } | 288 | } |
| 289 | |||
| 290 | return changed; | ||
| 271 | } | 291 | } |
| 272 | 292 | ||
| 273 | uint8_t matrix_scan(void) { | 293 | uint8_t matrix_scan(void) { |
| 274 | bool changed = false; | 294 | bool local_changed = false; |
| 275 | 295 | ||
| 276 | #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) | 296 | #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) |
| 277 | // Set row, read cols | 297 | // Set row, read cols |
| 278 | for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { | 298 | for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { |
| 279 | changed |= read_cols_on_row(raw_matrix, current_row); | 299 | local_changed |= read_cols_on_row(raw_matrix, current_row); |
| 280 | } | 300 | } |
| 281 | #elif (DIODE_DIRECTION == ROW2COL) | 301 | #elif (DIODE_DIRECTION == ROW2COL) |
| 282 | // Set col, read rows | 302 | // Set col, read rows |
| 283 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | 303 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { |
| 284 | changed |= read_rows_on_col(raw_matrix, current_col); | 304 | local_changed |= read_rows_on_col(raw_matrix, current_col); |
| 285 | } | 305 | } |
| 286 | #endif | 306 | #endif |
| 287 | 307 | ||
| 288 | debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); | 308 | debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, local_changed); |
| 289 | 309 | ||
| 290 | matrix_post_scan(); | 310 | bool remote_changed = matrix_post_scan(); |
| 291 | return (uint8_t)changed; | 311 | return (uint8_t)(local_changed || remote_changed); |
| 292 | } | 312 | } |
