aboutsummaryrefslogtreecommitdiff
path: root/quantum/split_common/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/split_common/matrix.c')
-rw-r--r--quantum/split_common/matrix.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index 22ff89bfc..631e960ea 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -251,21 +251,33 @@ void matrix_init(void) {
251 split_post_init(); 251 split_post_init();
252} 252}
253 253
254void matrix_post_scan(void) { 254bool matrix_post_scan(void) {
255 bool changed = false;
255 if (is_keyboard_master()) { 256 if (is_keyboard_master()) {
256 static uint8_t error_count; 257 static uint8_t error_count;
257 258
258 if (!transport_master(matrix + thatHand)) { 259 matrix_row_t slave_matrix[ROWS_PER_HAND] = {0};
260 if (!transport_master(slave_matrix)) {
259 error_count++; 261 error_count++;
260 262
261 if (error_count > ERROR_DISCONNECT_COUNT) { 263 if (error_count > ERROR_DISCONNECT_COUNT) {
262 // reset other half if disconnected 264 // reset other half if disconnected
263 for (int i = 0; i < ROWS_PER_HAND; ++i) { 265 for (int i = 0; i < ROWS_PER_HAND; ++i) {
264 matrix[thatHand + i] = 0; 266 matrix[thatHand + i] = 0;
267 slave_matrix[i] = 0;
265 } 268 }
269
270 changed = true;
266 } 271 }
267 } else { 272 } else {
268 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 }
269 } 281 }
270 282
271 matrix_scan_quantum(); 283 matrix_scan_quantum();
@@ -274,25 +286,27 @@ void matrix_post_scan(void) {
274 286
275 matrix_slave_scan_user(); 287 matrix_slave_scan_user();
276 } 288 }
289
290 return changed;
277} 291}
278 292
279uint8_t matrix_scan(void) { 293uint8_t matrix_scan(void) {
280 bool changed = false; 294 bool local_changed = false;
281 295
282#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) 296#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW)
283 // Set row, read cols 297 // Set row, read cols
284 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++) {
285 changed |= read_cols_on_row(raw_matrix, current_row); 299 local_changed |= read_cols_on_row(raw_matrix, current_row);
286 } 300 }
287#elif (DIODE_DIRECTION == ROW2COL) 301#elif (DIODE_DIRECTION == ROW2COL)
288 // Set col, read rows 302 // Set col, read rows
289 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++) {
290 changed |= read_rows_on_col(raw_matrix, current_col); 304 local_changed |= read_rows_on_col(raw_matrix, current_col);
291 } 305 }
292#endif 306#endif
293 307
294 debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); 308 debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, local_changed);
295 309
296 matrix_post_scan(); 310 bool remote_changed = matrix_post_scan();
297 return (uint8_t)changed; 311 return (uint8_t)(local_changed || remote_changed);
298} 312}