diff options
| author | Joakim Tufvegren <104522+firetech@users.noreply.github.com> | 2021-09-18 09:29:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-18 17:29:22 +1000 |
| commit | 8130690a286cb9d3ca1f19473ca4bdcb6933e1f6 (patch) | |
| tree | 70f598bd4da1f25ad2007dea0ad095d9d948b858 /quantum | |
| parent | 7c10d00ca6ec07f169d6f5e3c83bd7449a578ac0 (diff) | |
| download | qmk_firmware-8130690a286cb9d3ca1f19473ca4bdcb6933e1f6.tar.gz qmk_firmware-8130690a286cb9d3ca1f19473ca4bdcb6933e1f6.zip | |
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>
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/matrix.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c index 33586c431..4fbcc2419 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
| @@ -288,10 +288,8 @@ void matrix_init(void) { | |||
| 288 | matrix_init_pins(); | 288 | matrix_init_pins(); |
| 289 | 289 | ||
| 290 | // initialize matrix state: all keys off | 290 | // initialize matrix state: all keys off |
| 291 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 291 | memset(matrix, 0, sizeof(matrix)); |
| 292 | raw_matrix[i] = 0; | 292 | memset(raw_matrix, 0, sizeof(raw_matrix)); |
| 293 | matrix[i] = 0; | ||
| 294 | } | ||
| 295 | 293 | ||
| 296 | debounce_init(ROWS_PER_HAND); | 294 | debounce_init(ROWS_PER_HAND); |
| 297 | 295 | ||
| @@ -312,24 +310,22 @@ __attribute__((weak)) bool transport_master_if_connected(matrix_row_t master_mat | |||
| 312 | bool matrix_post_scan(void) { | 310 | bool matrix_post_scan(void) { |
| 313 | bool changed = false; | 311 | bool changed = false; |
| 314 | if (is_keyboard_master()) { | 312 | if (is_keyboard_master()) { |
| 313 | static bool last_connected = false; | ||
| 315 | matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; | 314 | matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; |
| 316 | if (transport_master_if_connected(matrix + thisHand, slave_matrix)) { | 315 | if (transport_master_if_connected(matrix + thisHand, slave_matrix)) { |
| 317 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 316 | changed = memcmp(matrix + thatHand, slave_matrix, sizeof(slave_matrix)) != 0; |
| 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 | } | ||
| 329 | 317 | ||
| 318 | last_connected = true; | ||
| 319 | } else if (last_connected) { | ||
| 320 | // reset other half when disconnected | ||
| 321 | memset(slave_matrix, 0, sizeof(slave_matrix)); | ||
| 330 | changed = true; | 322 | changed = true; |
| 323 | |||
| 324 | last_connected = false; | ||
| 331 | } | 325 | } |
| 332 | 326 | ||
| 327 | if (changed) memcpy(matrix + thatHand, slave_matrix, sizeof(slave_matrix)); | ||
| 328 | |||
| 333 | matrix_scan_quantum(); | 329 | matrix_scan_quantum(); |
| 334 | } else { | 330 | } else { |
| 335 | transport_slave(matrix + thatHand, matrix + thisHand); | 331 | transport_slave(matrix + thatHand, matrix + thisHand); |
