aboutsummaryrefslogtreecommitdiff
path: root/quantum/split_common/matrix.c
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2021-01-12 19:48:24 +1100
committerGitHub <noreply@github.com>2021-01-12 19:48:24 +1100
commit79d1db332477963555416d9fff82ecac4399bd52 (patch)
tree1d5465b40e857c60e13a855d4667923d6eee0521 /quantum/split_common/matrix.c
parenta2aed8ebd7f7501cc33af4cae26608447209a65b (diff)
downloadqmk_firmware-79d1db332477963555416d9fff82ecac4399bd52.tar.gz
qmk_firmware-79d1db332477963555416d9fff82ecac4399bd52.zip
Keep track of last matrix activity (#10730)
* Allow recording of the last matrix activity time, to simplify implementation of display timeouts and the like. * Add requested changes from code review. * Simplify split matrix last changed.
Diffstat (limited to 'quantum/split_common/matrix.c')
-rw-r--r--quantum/split_common/matrix.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index 51bf8b109..06bab734e 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -245,48 +245,59 @@ void matrix_init(void) {
245 split_post_init(); 245 split_post_init();
246} 246}
247 247
248void matrix_post_scan(void) { 248bool matrix_post_scan(void) {
249 bool changed = false;
249 if (is_keyboard_master()) { 250 if (is_keyboard_master()) {
250 static uint8_t error_count; 251 static uint8_t error_count;
251 252
252 if (!transport_master(matrix + thatHand)) { 253 matrix_row_t slave_matrix[ROWS_PER_HAND] = {0};
254 if (!transport_master(slave_matrix)) {
253 error_count++; 255 error_count++;
254 256
255 if (error_count > ERROR_DISCONNECT_COUNT) { 257 if (error_count > ERROR_DISCONNECT_COUNT) {
256 // reset other half if disconnected 258 // reset other half if disconnected
257 for (int i = 0; i < ROWS_PER_HAND; ++i) { 259 for (int i = 0; i < ROWS_PER_HAND; ++i) {
258 matrix[thatHand + i] = 0; 260 slave_matrix[i] = 0;
259 } 261 }
260 } 262 }
261 } else { 263 } else {
262 error_count = 0; 264 error_count = 0;
263 } 265 }
264 266
267 for (int i = 0; i < ROWS_PER_HAND; ++i) {
268 if (matrix[thatHand + i] != slave_matrix[i]) {
269 matrix[thatHand + i] = slave_matrix[i];
270 changed = true;
271 }
272 }
273
265 matrix_scan_quantum(); 274 matrix_scan_quantum();
266 } else { 275 } else {
267 transport_slave(matrix + thisHand); 276 transport_slave(matrix + thisHand);
268 277
269 matrix_slave_scan_user(); 278 matrix_slave_scan_user();
270 } 279 }
280
281 return changed;
271} 282}
272 283
273uint8_t matrix_scan(void) { 284uint8_t matrix_scan(void) {
274 bool changed = false; 285 bool local_changed = false;
275 286
276#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) 287#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW)
277 // Set row, read cols 288 // Set row, read cols
278 for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { 289 for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) {
279 changed |= read_cols_on_row(raw_matrix, current_row); 290 local_changed |= read_cols_on_row(raw_matrix, current_row);
280 } 291 }
281#elif (DIODE_DIRECTION == ROW2COL) 292#elif (DIODE_DIRECTION == ROW2COL)
282 // Set col, read rows 293 // Set col, read rows
283 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { 294 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
284 changed |= read_rows_on_col(raw_matrix, current_col); 295 local_changed |= read_rows_on_col(raw_matrix, current_col);
285 } 296 }
286#endif 297#endif
287 298
288 debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); 299 debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, local_changed);
289 300
290 matrix_post_scan(); 301 bool remote_changed = matrix_post_scan();
291 return (uint8_t)changed; 302 return (uint8_t)(local_changed || remote_changed);
292} 303}