summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quantum/keyboard.c52
-rw-r--r--quantum/keyboard.h9
-rw-r--r--quantum/pointing_device/pointing_device.c28
-rw-r--r--quantum/pointing_device/pointing_device.h4
-rw-r--r--quantum/split_common/transactions.c7
-rw-r--r--quantum/split_common/transport.h1
6 files changed, 61 insertions, 40 deletions
diff --git a/quantum/keyboard.c b/quantum/keyboard.c
index 3f030d8845..6f1ad33b61 100644
--- a/quantum/keyboard.c
+++ b/quantum/keyboard.c
@@ -139,10 +139,22 @@ void last_encoder_activity_trigger(void) {
139 last_encoder_modification_time = last_input_modification_time = sync_timer_read32(); 139 last_encoder_modification_time = last_input_modification_time = sync_timer_read32();
140} 140}
141 141
142void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp) { 142static uint32_t last_pointing_device_modification_time = 0;
143 last_matrix_modification_time = matrix_timestamp; 143uint32_t last_pointing_device_activity_time(void) {
144 last_encoder_modification_time = encoder_timestamp; 144 return last_pointing_device_modification_time;
145 last_input_modification_time = MAX(matrix_timestamp, encoder_timestamp); 145}
146uint32_t last_pointing_device_activity_elapsed(void) {
147 return sync_timer_elapsed32(last_pointing_device_modification_time);
148}
149void last_pointing_device_activity_trigger(void) {
150 last_pointing_device_modification_time = last_input_modification_time = sync_timer_read32();
151}
152
153void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp, uint32_t pointing_device_timestamp) {
154 last_matrix_modification_time = matrix_timestamp;
155 last_encoder_modification_time = encoder_timestamp;
156 last_pointing_device_modification_time = pointing_device_timestamp;
157 last_input_modification_time = MAX(matrix_timestamp, MAX(encoder_timestamp, pointing_device_timestamp));
146} 158}
147 159
148// Only enable this if console is enabled to print to 160// Only enable this if console is enabled to print to
@@ -598,9 +610,10 @@ void quantum_task(void) {
598 610
599/** \brief Main task that is repeatedly called as fast as possible. */ 611/** \brief Main task that is repeatedly called as fast as possible. */
600void keyboard_task(void) { 612void keyboard_task(void) {
601 const bool matrix_changed = matrix_task(); 613 __attribute__((unused)) bool activity_has_occurred = false;
602 if (matrix_changed) { 614 if (matrix_task()) {
603 last_matrix_activity_trigger(); 615 last_matrix_activity_trigger();
616 activity_has_occurred = true;
604 } 617 }
605 618
606 quantum_task(); 619 quantum_task();
@@ -627,9 +640,16 @@ void keyboard_task(void) {
627#endif 640#endif
628 641
629#ifdef ENCODER_ENABLE 642#ifdef ENCODER_ENABLE
630 const bool encoders_changed = encoder_read(); 643 if (encoder_read()) {
631 if (encoders_changed) {
632 last_encoder_activity_trigger(); 644 last_encoder_activity_trigger();
645 activity_has_occurred = true;
646 }
647#endif
648
649#ifdef POINTING_DEVICE_ENABLE
650 if (pointing_device_task()) {
651 last_pointing_device_activity_trigger();
652 activity_has_occurred = true;
633 } 653 }
634#endif 654#endif
635 655
@@ -637,11 +657,7 @@ void keyboard_task(void) {
637 oled_task(); 657 oled_task();
638# if OLED_TIMEOUT > 0 658# if OLED_TIMEOUT > 0
639 // Wake up oled if user is using those fabulous keys or spinning those encoders! 659 // Wake up oled if user is using those fabulous keys or spinning those encoders!
640# ifdef ENCODER_ENABLE 660 if (activity_has_occurred) oled_on();
641 if (matrix_changed || encoders_changed) oled_on();
642# else
643 if (matrix_changed) oled_on();
644# endif
645# endif 661# endif
646#endif 662#endif
647 663
@@ -649,11 +665,7 @@ void keyboard_task(void) {
649 st7565_task(); 665 st7565_task();
650# if ST7565_TIMEOUT > 0 666# if ST7565_TIMEOUT > 0
651 // Wake up display if user is using those fabulous keys or spinning those encoders! 667 // Wake up display if user is using those fabulous keys or spinning those encoders!
652# ifdef ENCODER_ENABLE 668 if (activity_has_occurred) st7565_on();
653 if (matrix_changed || encoders_changed) st7565_on();
654# else
655 if (matrix_changed) st7565_on();
656# endif
657# endif 669# endif
658#endif 670#endif
659 671
@@ -666,10 +678,6 @@ void keyboard_task(void) {
666 ps2_mouse_task(); 678 ps2_mouse_task();
667#endif 679#endif
668 680
669#ifdef POINTING_DEVICE_ENABLE
670 pointing_device_task();
671#endif
672
673#ifdef MIDI_ENABLE 681#ifdef MIDI_ENABLE
674 midi_task(); 682 midi_task();
675#endif 683#endif
diff --git a/quantum/keyboard.h b/quantum/keyboard.h
index caf0fbd466..f82f2fa58a 100644
--- a/quantum/keyboard.h
+++ b/quantum/keyboard.h
@@ -111,8 +111,8 @@ void housekeeping_task(void); // To be executed by the main loop in each ba
111void housekeeping_task_kb(void); // To be overridden by keyboard-level code 111void housekeeping_task_kb(void); // To be overridden by keyboard-level code
112void housekeeping_task_user(void); // To be overridden by user/keymap-level code 112void housekeeping_task_user(void); // To be overridden by user/keymap-level code
113 113
114uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity 114uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder or pointing device activity
115uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity 115uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder or pointing device activity
116 116
117uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity 117uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity
118uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity 118uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity
@@ -120,7 +120,10 @@ uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the
120uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity 120uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity
121uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity 121uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity
122 122
123void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp); // Set the timestamps of the last matrix and encoder activity 123uint32_t last_pointing_device_activity_time(void); // Timestamp of the last pointing device activity
124uint32_t last_pointing_device_activity_elapsed(void); // Number of milliseconds since the last pointing device activity
125
126void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp, uint32_t pointing_device_timestamp); // Set the timestamps of the last matrix and encoder activity
124 127
125uint32_t get_matrix_scan_rate(void); 128uint32_t get_matrix_scan_rate(void);
126 129
diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c
index 75bb5f81fc..abb3817b5f 100644
--- a/quantum/pointing_device/pointing_device.c
+++ b/quantum/pointing_device/pointing_device.c
@@ -74,7 +74,8 @@ uint16_t pointing_device_get_shared_cpi(void) {
74 74
75#endif // defined(SPLIT_POINTING_ENABLE) 75#endif // defined(SPLIT_POINTING_ENABLE)
76 76
77static report_mouse_t local_mouse_report = {}; 77static report_mouse_t local_mouse_report = {};
78static bool pointing_device_force_send = false;
78 79
79extern const pointing_device_driver_t pointing_device_driver; 80extern const pointing_device_driver_t pointing_device_driver;
80 81
@@ -163,11 +164,11 @@ __attribute__((weak)) void pointing_device_init(void) {
163 * This sends the mouse report generated by pointing_device_task if changed since the last report. Once send zeros mouse report except buttons. 164 * This sends the mouse report generated by pointing_device_task if changed since the last report. Once send zeros mouse report except buttons.
164 * 165 *
165 */ 166 */
166__attribute__((weak)) void pointing_device_send(void) { 167__attribute__((weak)) bool pointing_device_send(void) {
167 static report_mouse_t old_report = {}; 168 static report_mouse_t old_report = {};
169 bool should_send_report = has_mouse_report_changed(&local_mouse_report, &old_report);
168 170
169 // If you need to do other things, like debugging, this is the place to do it. 171 if (should_send_report) {
170 if (has_mouse_report_changed(&local_mouse_report, &old_report)) {
171 host_mouse_send(&local_mouse_report); 172 host_mouse_send(&local_mouse_report);
172 } 173 }
173 // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device 174 // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
@@ -175,6 +176,8 @@ __attribute__((weak)) void pointing_device_send(void) {
175 memset(&local_mouse_report, 0, sizeof(local_mouse_report)); 176 memset(&local_mouse_report, 0, sizeof(local_mouse_report));
176 local_mouse_report.buttons = buttons; 177 local_mouse_report.buttons = buttons;
177 memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report)); 178 memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report));
179
180 return should_send_report || buttons;
178} 181}
179 182
180/** 183/**
@@ -220,18 +223,18 @@ report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) {
220 * It applies any optional configuration e.g. rotation or axis inversion and then initiates a send. 223 * It applies any optional configuration e.g. rotation or axis inversion and then initiates a send.
221 * 224 *
222 */ 225 */
223__attribute__((weak)) void pointing_device_task(void) { 226__attribute__((weak)) bool pointing_device_task(void) {
224#if defined(SPLIT_POINTING_ENABLE) 227#if defined(SPLIT_POINTING_ENABLE)
225 // Don't poll the target side pointing device. 228 // Don't poll the target side pointing device.
226 if (!is_keyboard_master()) { 229 if (!is_keyboard_master()) {
227 return; 230 return false;
228 }; 231 };
229#endif 232#endif
230 233
231#if (POINTING_DEVICE_TASK_THROTTLE_MS > 0) 234#if (POINTING_DEVICE_TASK_THROTTLE_MS > 0)
232 static uint32_t last_exec = 0; 235 static uint32_t last_exec = 0;
233 if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { 236 if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) {
234 return; 237 return false;
235 } 238 }
236 last_exec = timer_read32(); 239 last_exec = timer_read32();
237#endif 240#endif
@@ -286,7 +289,11 @@ __attribute__((weak)) void pointing_device_task(void) {
286 report_mouse_t mousekey_report = mousekey_get_report(); 289 report_mouse_t mousekey_report = mousekey_get_report();
287 local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons; 290 local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons;
288#endif 291#endif
289 pointing_device_send(); 292
293 const bool send_report = pointing_device_send() || pointing_device_force_send;
294 pointing_device_force_send = false;
295
296 return send_report;
290} 297}
291 298
292/** 299/**
@@ -304,7 +311,8 @@ report_mouse_t pointing_device_get_report(void) {
304 * @param[in] mouse_report 311 * @param[in] mouse_report
305 */ 312 */
306void pointing_device_set_report(report_mouse_t mouse_report) { 313void pointing_device_set_report(report_mouse_t mouse_report) {
307 local_mouse_report = mouse_report; 314 pointing_device_force_send = has_mouse_report_changed(&local_mouse_report, &mouse_report);
315 memcpy(&local_mouse_report, &mouse_report, sizeof(local_mouse_report));
308} 316}
309 317
310/** 318/**
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h
index d430e6cfa4..eacc6418dd 100644
--- a/quantum/pointing_device/pointing_device.h
+++ b/quantum/pointing_device/pointing_device.h
@@ -97,8 +97,8 @@ typedef int16_t clamp_range_t;
97#endif 97#endif
98 98
99void pointing_device_init(void); 99void pointing_device_init(void);
100void pointing_device_task(void); 100bool pointing_device_task(void);
101void pointing_device_send(void); 101bool pointing_device_send(void);
102report_mouse_t pointing_device_get_report(void); 102report_mouse_t pointing_device_get_report(void);
103void pointing_device_set_report(report_mouse_t mouse_report); 103void pointing_device_set_report(report_mouse_t mouse_report);
104uint16_t pointing_device_get_cpi(void); 104uint16_t pointing_device_get_cpi(void);
diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c
index ec34bbba60..0ae91ba363 100644
--- a/quantum/split_common/transactions.c
+++ b/quantum/split_common/transactions.c
@@ -795,13 +795,14 @@ static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla
795static bool activity_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { 795static bool activity_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
796 static uint32_t last_update = 0; 796 static uint32_t last_update = 0;
797 split_slave_activity_sync_t activity_sync; 797 split_slave_activity_sync_t activity_sync;
798 activity_sync.matrix_timestamp = last_matrix_activity_time(); 798 activity_sync.matrix_timestamp = last_matrix_activity_time();
799 activity_sync.encoder_timestamp = last_encoder_activity_time(); 799 activity_sync.encoder_timestamp = last_encoder_activity_time();
800 activity_sync.pointing_device_timestamp = last_pointing_device_activity_time();
800 return send_if_data_mismatch(PUT_ACTIVITY, &last_update, &activity_sync, &split_shmem->activity_sync, sizeof(activity_sync)); 801 return send_if_data_mismatch(PUT_ACTIVITY, &last_update, &activity_sync, &split_shmem->activity_sync, sizeof(activity_sync));
801} 802}
802 803
803static void activity_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { 804static void activity_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
804 set_activity_timestamps(split_shmem->activity_sync.matrix_timestamp, split_shmem->activity_sync.encoder_timestamp); 805 set_activity_timestamps(split_shmem->activity_sync.matrix_timestamp, split_shmem->activity_sync.encoder_timestamp, split_shmem->activity_sync.pointing_device_timestamp);
805} 806}
806 807
807// clang-format off 808// clang-format off
diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h
index 8f8c38461e..13b1e56814 100644
--- a/quantum/split_common/transport.h
+++ b/quantum/split_common/transport.h
@@ -127,6 +127,7 @@ typedef struct _split_slave_haptic_sync_t {
127typedef struct _split_slave_activity_sync_t { 127typedef struct _split_slave_activity_sync_t {
128 uint32_t matrix_timestamp; 128 uint32_t matrix_timestamp;
129 uint32_t encoder_timestamp; 129 uint32_t encoder_timestamp;
130 uint32_t pointing_device_timestamp;
130} split_slave_activity_sync_t; 131} split_slave_activity_sync_t;
131#endif // defined(SPLIT_ACTIVITY_ENABLE) 132#endif // defined(SPLIT_ACTIVITY_ENABLE)
132 133