aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2021-01-18 05:01:38 +1100
committerGitHub <noreply@github.com>2021-01-18 05:01:38 +1100
commite702c7f1b4cfa8fe1579498ef2877994baa64056 (patch)
tree6fcb6c74a1e69f7f981303659cae857f50d0a208
parentd6d15b91f3a43b74f177fea9fd2f632eaf303696 (diff)
downloadqmk_firmware-e702c7f1b4cfa8fe1579498ef2877994baa64056.tar.gz
qmk_firmware-e702c7f1b4cfa8fe1579498ef2877994baa64056.zip
Keep track of last matrix activity. (#11552)
Co-authored-by: Dasky <daskygit@users.noreply.github.com> Co-authored-by: Dasky <daskygit@users.noreply.github.com>
-rw-r--r--quantum/split_common/matrix.c30
-rw-r--r--tmk_core/common/keyboard.c13
-rw-r--r--tmk_core/common/keyboard.h3
3 files changed, 32 insertions, 14 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}
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index a1fbc01da..aea09169f 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -97,6 +97,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
97# include "dip_switch.h" 97# include "dip_switch.h"
98#endif 98#endif
99 99
100static uint32_t last_matrix_modification_time = 0;
101uint32_t last_matrix_activity_time(void) { return last_matrix_modification_time; }
102uint32_t last_matrix_activity_elapsed(void) { return timer_elapsed32(last_matrix_modification_time); }
103
100// Only enable this if console is enabled to print to 104// Only enable this if console is enabled to print to
101#if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE) 105#if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE)
102static uint32_t matrix_timer = 0; 106static uint32_t matrix_timer = 0;
@@ -338,11 +342,8 @@ void keyboard_task(void) {
338 housekeeping_task_kb(); 342 housekeeping_task_kb();
339 housekeeping_task_user(); 343 housekeeping_task_user();
340 344
341#if defined(OLED_DRIVER_ENABLE) && !defined(OLED_DISABLE_TIMEOUT) 345 uint8_t matrix_changed = matrix_scan();
342 uint8_t ret = matrix_scan(); 346 if (matrix_changed) last_matrix_modification_time = timer_read32();
343#else
344 matrix_scan();
345#endif
346 347
347 if (should_process_keypress()) { 348 if (should_process_keypress()) {
348 for (uint8_t r = 0; r < MATRIX_ROWS; r++) { 349 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
@@ -409,7 +410,7 @@ MATRIX_LOOP_END:
409 oled_task(); 410 oled_task();
410# ifndef OLED_DISABLE_TIMEOUT 411# ifndef OLED_DISABLE_TIMEOUT
411 // Wake up oled if user is using those fabulous keys! 412 // Wake up oled if user is using those fabulous keys!
412 if (ret) oled_on(); 413 if (matrix_changed) oled_on();
413# endif 414# endif
414#endif 415#endif
415 416
diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h
index d04e685cd..cc5b2e5e4 100644
--- a/tmk_core/common/keyboard.h
+++ b/tmk_core/common/keyboard.h
@@ -73,6 +73,9 @@ void keyboard_post_init_user(void);
73void housekeeping_task_kb(void); 73void housekeeping_task_kb(void);
74void housekeeping_task_user(void); 74void housekeeping_task_user(void);
75 75
76uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity
77uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity
78
76#ifdef __cplusplus 79#ifdef __cplusplus
77} 80}
78#endif 81#endif