diff options
| author | Drashna Jaelre <drashna@drashna.net> | 2023-03-30 18:27:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-30 18:27:39 -0700 |
| commit | 297779385fd53e93c33861e2d3107cb88efbde81 (patch) | |
| tree | 21b10a2cc50505ba31a634045f00df40b2196a50 | |
| parent | 8686c527f76ff794c51ff55377c029ac3c38f683 (diff) | |
Add last activity functions for pointing device (#20079)
| -rw-r--r-- | quantum/keyboard.c | 52 | ||||
| -rw-r--r-- | quantum/keyboard.h | 9 | ||||
| -rw-r--r-- | quantum/pointing_device/pointing_device.c | 28 | ||||
| -rw-r--r-- | quantum/pointing_device/pointing_device.h | 4 | ||||
| -rw-r--r-- | quantum/split_common/transactions.c | 7 | ||||
| -rw-r--r-- | quantum/split_common/transport.h | 1 |
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 | ||
| 142 | void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp) { | 142 | static uint32_t last_pointing_device_modification_time = 0; |
| 143 | last_matrix_modification_time = matrix_timestamp; | 143 | uint32_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 | } |
| 146 | uint32_t last_pointing_device_activity_elapsed(void) { | ||
| 147 | return sync_timer_elapsed32(last_pointing_device_modification_time); | ||
| 148 | } | ||
| 149 | void last_pointing_device_activity_trigger(void) { | ||
| 150 | last_pointing_device_modification_time = last_input_modification_time = sync_timer_read32(); | ||
| 151 | } | ||
| 152 | |||
| 153 | void 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. */ |
| 600 | void keyboard_task(void) { | 612 | void 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 | |||
| 111 | void housekeeping_task_kb(void); // To be overridden by keyboard-level code | 111 | void housekeeping_task_kb(void); // To be overridden by keyboard-level code |
| 112 | void housekeeping_task_user(void); // To be overridden by user/keymap-level code | 112 | void housekeeping_task_user(void); // To be overridden by user/keymap-level code |
| 113 | 113 | ||
| 114 | uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity | 114 | uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder or pointing device activity |
| 115 | uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity | 115 | uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder or pointing device activity |
| 116 | 116 | ||
| 117 | uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity | 117 | uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity |
| 118 | uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity | 118 | uint32_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 | |||
| 120 | uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity | 120 | uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity |
| 121 | uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity | 121 | uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity |
| 122 | 122 | ||
| 123 | void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp); // Set the timestamps of the last matrix and encoder activity | 123 | uint32_t last_pointing_device_activity_time(void); // Timestamp of the last pointing device activity |
| 124 | uint32_t last_pointing_device_activity_elapsed(void); // Number of milliseconds since the last pointing device activity | ||
| 125 | |||
| 126 | void 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 | ||
| 125 | uint32_t get_matrix_scan_rate(void); | 128 | uint32_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 | ||
| 77 | static report_mouse_t local_mouse_report = {}; | 77 | static report_mouse_t local_mouse_report = {}; |
| 78 | static bool pointing_device_force_send = false; | ||
| 78 | 79 | ||
| 79 | extern const pointing_device_driver_t pointing_device_driver; | 80 | extern 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 | */ |
| 306 | void pointing_device_set_report(report_mouse_t mouse_report) { | 313 | void 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 | ||
| 99 | void pointing_device_init(void); | 99 | void pointing_device_init(void); |
| 100 | void pointing_device_task(void); | 100 | bool pointing_device_task(void); |
| 101 | void pointing_device_send(void); | 101 | bool pointing_device_send(void); |
| 102 | report_mouse_t pointing_device_get_report(void); | 102 | report_mouse_t pointing_device_get_report(void); |
| 103 | void pointing_device_set_report(report_mouse_t mouse_report); | 103 | void pointing_device_set_report(report_mouse_t mouse_report); |
| 104 | uint16_t pointing_device_get_cpi(void); | 104 | uint16_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 | |||
| 795 | static bool activity_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { | 795 | static 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 | ||
| 803 | static void activity_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { | 804 | static 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 { | |||
| 127 | typedef struct _split_slave_activity_sync_t { | 127 | typedef 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 | ||
