Skip to content

Commit de6de2f

Browse files
firetechKarlK90
authored andcommitted
Improvements to handling of disconnected split keyboards. (qmk#14033)
* Use memcmp and memcpy to compare and copy slave matrix. ...and memset to initialize `matrix` and `raw_matrix`. Increased my scan rate (while connected) by ~100 (on Ergodox Infinity). Effect on AVR is unknown. Co-authored-by: Stefan Kerkmann <[email protected]> * Fix `matrix_post_scan` signalling change on every scan while disconnected. * Undo removal of initialization of `slave_matrix`. This has the effect of increasing my Ergodox Infinity firmware size by 8 bytes instead of decreasing by 8 bytes, and lowers the scan rate while connected back to the initial value before these changes, but _might_ solve some issues on AVR. Co-authored-by: Stefan Kerkmann <[email protected]>
1 parent 2d0b03b commit de6de2f

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

quantum/matrix.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,8 @@ void matrix_init(void) {
288288
matrix_init_pins();
289289

290290
// initialize matrix state: all keys off
291-
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
292-
raw_matrix[i] = 0;
293-
matrix[i] = 0;
294-
}
291+
memset(matrix, 0, sizeof(matrix));
292+
memset(raw_matrix, 0, sizeof(raw_matrix));
295293

296294
debounce_init(ROWS_PER_HAND);
297295

@@ -312,24 +310,22 @@ __attribute__((weak)) bool transport_master_if_connected(matrix_row_t master_mat
312310
bool matrix_post_scan(void) {
313311
bool changed = false;
314312
if (is_keyboard_master()) {
313+
static bool last_connected = false;
315314
matrix_row_t slave_matrix[ROWS_PER_HAND] = {0};
316315
if (transport_master_if_connected(matrix + thisHand, slave_matrix)) {
317-
for (int i = 0; i < ROWS_PER_HAND; ++i) {
318-
if (matrix[thatHand + i] != slave_matrix[i]) {
319-
matrix[thatHand + i] = slave_matrix[i];
320-
changed = true;
321-
}
322-
}
323-
} else {
324-
// reset other half if disconnected
325-
for (int i = 0; i < ROWS_PER_HAND; ++i) {
326-
matrix[thatHand + i] = 0;
327-
slave_matrix[i] = 0;
328-
}
316+
changed = memcmp(matrix + thatHand, slave_matrix, sizeof(slave_matrix)) != 0;
329317

318+
last_connected = true;
319+
} else if (last_connected) {
320+
// reset other half when disconnected
321+
memset(slave_matrix, 0, sizeof(slave_matrix));
330322
changed = true;
323+
324+
last_connected = false;
331325
}
332326

327+
if (changed) memcpy(matrix + thatHand, slave_matrix, sizeof(slave_matrix));
328+
333329
matrix_scan_quantum();
334330
} else {
335331
transport_slave(matrix + thatHand, matrix + thisHand);

0 commit comments

Comments
 (0)