Improvements to handling of disconnected split keyboards. (#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 <karlk90@pm.me> * 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 <karlk90@pm.me>master
parent
7c10d00ca6
commit
8130690a28
|
@ -288,10 +288,8 @@ void matrix_init(void) {
|
||||||
matrix_init_pins();
|
matrix_init_pins();
|
||||||
|
|
||||||
// initialize matrix state: all keys off
|
// initialize matrix state: all keys off
|
||||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
memset(matrix, 0, sizeof(matrix));
|
||||||
raw_matrix[i] = 0;
|
memset(raw_matrix, 0, sizeof(raw_matrix));
|
||||||
matrix[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
debounce_init(ROWS_PER_HAND);
|
debounce_init(ROWS_PER_HAND);
|
||||||
|
|
||||||
|
@ -312,23 +310,21 @@ __attribute__((weak)) bool transport_master_if_connected(matrix_row_t master_mat
|
||||||
bool matrix_post_scan(void) {
|
bool matrix_post_scan(void) {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
if (is_keyboard_master()) {
|
if (is_keyboard_master()) {
|
||||||
|
static bool last_connected = false;
|
||||||
matrix_row_t slave_matrix[ROWS_PER_HAND] = {0};
|
matrix_row_t slave_matrix[ROWS_PER_HAND] = {0};
|
||||||
if (transport_master_if_connected(matrix + thisHand, slave_matrix)) {
|
if (transport_master_if_connected(matrix + thisHand, slave_matrix)) {
|
||||||
for (int i = 0; i < ROWS_PER_HAND; ++i) {
|
changed = memcmp(matrix + thatHand, slave_matrix, sizeof(slave_matrix)) != 0;
|
||||||
if (matrix[thatHand + i] != slave_matrix[i]) {
|
|
||||||
matrix[thatHand + i] = slave_matrix[i];
|
last_connected = true;
|
||||||
|
} else if (last_connected) {
|
||||||
|
// reset other half when disconnected
|
||||||
|
memset(slave_matrix, 0, sizeof(slave_matrix));
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
|
||||||
}
|
last_connected = false;
|
||||||
} else {
|
|
||||||
// reset other half if disconnected
|
|
||||||
for (int i = 0; i < ROWS_PER_HAND; ++i) {
|
|
||||||
matrix[thatHand + i] = 0;
|
|
||||||
slave_matrix[i] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
changed = true;
|
if (changed) memcpy(matrix + thatHand, slave_matrix, sizeof(slave_matrix));
|
||||||
}
|
|
||||||
|
|
||||||
matrix_scan_quantum();
|
matrix_scan_quantum();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue