summaryrefslogtreecommitdiff
path: root/tmk_core
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 /tmk_core
parenta2aed8ebd7f7501cc33af4cae26608447209a65b (diff)
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 'tmk_core')
-rw-r--r--tmk_core/common/keyboard.c13
-rw-r--r--tmk_core/common/keyboard.h3
2 files changed, 10 insertions, 6 deletions
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index a1fbc01da6..aea09169fb 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/>.
# include "dip_switch.h"
#endif
+static uint32_t last_matrix_modification_time = 0;
+uint32_t last_matrix_activity_time(void) { return last_matrix_modification_time; }
+uint32_t last_matrix_activity_elapsed(void) { return timer_elapsed32(last_matrix_modification_time); }
+
// Only enable this if console is enabled to print to
#if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE)
static uint32_t matrix_timer = 0;
@@ -338,11 +342,8 @@ void keyboard_task(void) {
housekeeping_task_kb();
housekeeping_task_user();
-#if defined(OLED_DRIVER_ENABLE) && !defined(OLED_DISABLE_TIMEOUT)
- uint8_t ret = matrix_scan();
-#else
- matrix_scan();
-#endif
+ uint8_t matrix_changed = matrix_scan();
+ if (matrix_changed) last_matrix_modification_time = timer_read32();
if (should_process_keypress()) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
@@ -409,7 +410,7 @@ MATRIX_LOOP_END:
oled_task();
# ifndef OLED_DISABLE_TIMEOUT
// Wake up oled if user is using those fabulous keys!
- if (ret) oled_on();
+ if (matrix_changed) oled_on();
# endif
#endif
diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h
index d04e685cdb..cc5b2e5e42 100644
--- a/tmk_core/common/keyboard.h
+++ b/tmk_core/common/keyboard.h
@@ -73,6 +73,9 @@ void keyboard_post_init_user(void);
void housekeeping_task_kb(void);
void housekeeping_task_user(void);
+uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity
+uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity
+
#ifdef __cplusplus
}
#endif