diff options
| author | Drashna Jaelre <drashna@live.com> | 2021-12-14 20:53:36 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-14 20:53:36 -0800 |
| commit | 3fa592a4024a24a636fa0c562e6761667a94f565 (patch) | |
| tree | 4ce826128e29e36dfe606fa2b5a3d25b3bd0afcc /users/drashna/split | |
| parent | c10bc9f91e737dd3675b2e4492daa09092655af9 (diff) | |
| download | qmk_firmware-3fa592a4024a24a636fa0c562e6761667a94f565.tar.gz qmk_firmware-3fa592a4024a24a636fa0c562e6761667a94f565.zip | |
[Keymap] Unicode and Pointing Device and Autocorect for drashna keymaps (#15415)
Diffstat (limited to 'users/drashna/split')
| -rw-r--r-- | users/drashna/split/transport_sync.c | 174 | ||||
| -rw-r--r-- | users/drashna/split/transport_sync.h | 36 |
2 files changed, 210 insertions, 0 deletions
diff --git a/users/drashna/split/transport_sync.c b/users/drashna/split/transport_sync.c new file mode 100644 index 000000000..cee3f04c8 --- /dev/null +++ b/users/drashna/split/transport_sync.c | |||
| @@ -0,0 +1,174 @@ | |||
| 1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "transport_sync.h" | ||
| 18 | #include "transactions.h" | ||
| 19 | #include <string.h> | ||
| 20 | |||
| 21 | #ifdef CUSTOM_UNICODE_ENABLE | ||
| 22 | #include "process_unicode_common.h" | ||
| 23 | extern unicode_config_t unicode_config; | ||
| 24 | #endif | ||
| 25 | #ifdef AUDIO_ENABLE | ||
| 26 | # include "audio.h" | ||
| 27 | extern audio_config_t audio_config; | ||
| 28 | extern bool delayed_tasks_run; | ||
| 29 | #endif | ||
| 30 | #if defined(POINTING_DEVICE_ENABLE) && defined(KEYBOARD_handwired_tractyl_manuform) | ||
| 31 | extern bool tap_toggling; | ||
| 32 | #endif | ||
| 33 | #ifdef SWAP_HANDS_ENABLE | ||
| 34 | extern bool swap_hands; | ||
| 35 | #endif | ||
| 36 | extern userspace_config_t userspace_config; | ||
| 37 | extern bool host_driver_disabled; | ||
| 38 | |||
| 39 | uint16_t transport_keymap_config = 0; | ||
| 40 | uint32_t transport_userspace_config = 0, transport_user_state = 0; | ||
| 41 | |||
| 42 | user_runtime_config_t user_state; | ||
| 43 | |||
| 44 | void user_state_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { | ||
| 45 | if (initiator2target_buffer_size == sizeof(transport_user_state)) { | ||
| 46 | memcpy(&transport_user_state, initiator2target_buffer, initiator2target_buffer_size); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | void user_keymap_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { | ||
| 50 | if (initiator2target_buffer_size == sizeof(transport_keymap_config)) { | ||
| 51 | memcpy(&transport_keymap_config, initiator2target_buffer, initiator2target_buffer_size); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | void user_config_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { | ||
| 55 | if (initiator2target_buffer_size == sizeof(transport_userspace_config)) { | ||
| 56 | memcpy(&transport_userspace_config, initiator2target_buffer, initiator2target_buffer_size); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | void keyboard_post_init_transport_sync(void) { | ||
| 61 | // Register keyboard state sync split transaction | ||
| 62 | transaction_register_rpc(RPC_ID_USER_STATE_SYNC, user_state_sync); | ||
| 63 | transaction_register_rpc(RPC_ID_USER_KEYMAP_SYNC, user_keymap_sync); | ||
| 64 | transaction_register_rpc(RPC_ID_USER_CONFIG_SYNC, user_config_sync); | ||
| 65 | } | ||
| 66 | |||
| 67 | void user_transport_update(void) { | ||
| 68 | if (is_keyboard_master()) { | ||
| 69 | transport_keymap_config = keymap_config.raw; | ||
| 70 | transport_userspace_config = userspace_config.raw; | ||
| 71 | #ifdef AUDIO_ENABLE | ||
| 72 | user_state.audio_enable = is_audio_on(); | ||
| 73 | user_state.audio_clicky_enable = is_clicky_on(); | ||
| 74 | #endif | ||
| 75 | #if defined(POINTING_DEVICE_ENABLE) && defined(KEYBOARD_handwired_tractyl_manuform) | ||
| 76 | user_state.tap_toggling = tap_toggling; | ||
| 77 | #endif | ||
| 78 | #ifdef UNICODE_ENABLE | ||
| 79 | user_state.unicode_mode = unicode_config.input_mode; | ||
| 80 | #endif | ||
| 81 | #ifdef SWAP_HANDS_ENABLE | ||
| 82 | user_state.swap_hands = swap_hands; | ||
| 83 | #endif | ||
| 84 | user_state.host_driver_disabled = host_driver_disabled; | ||
| 85 | |||
| 86 | transport_user_state = user_state.raw; | ||
| 87 | } else { | ||
| 88 | keymap_config.raw = transport_keymap_config; | ||
| 89 | userspace_config.raw = transport_userspace_config; | ||
| 90 | user_state.raw = transport_user_state; | ||
| 91 | #ifdef UNICODE_ENABLE | ||
| 92 | unicode_config.input_mode = user_state.unicode_mode; | ||
| 93 | #endif | ||
| 94 | #if defined(POINTING_DEVICE_ENABLE) && defined(KEYBOARD_handwired_tractyl_manuform) | ||
| 95 | tap_toggling = user_state.tap_toggling; | ||
| 96 | #endif | ||
| 97 | #ifdef SWAP_HANDS_ENABLE | ||
| 98 | swap_hands = user_state.swap_hands; | ||
| 99 | #endif | ||
| 100 | host_driver_disabled = user_state.host_driver_disabled; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | void user_transport_sync(void) { | ||
| 105 | if (is_keyboard_master()) { | ||
| 106 | // Keep track of the last state, so that we can tell if we need to propagate to slave | ||
| 107 | static uint16_t last_keymap = 0; | ||
| 108 | static uint32_t last_config = 0, last_sync[3], last_user_state = 0; | ||
| 109 | bool needs_sync = false; | ||
| 110 | |||
| 111 | // Check if the state values are different | ||
| 112 | if (memcmp(&transport_user_state, &last_user_state, sizeof(transport_user_state))) { | ||
| 113 | needs_sync = true; | ||
| 114 | memcpy(&last_user_state, &transport_user_state, sizeof(transport_user_state)); | ||
| 115 | } | ||
| 116 | // Send to slave every 500ms regardless of state change | ||
| 117 | if (timer_elapsed32(last_sync[0]) > 250) { | ||
| 118 | needs_sync = true; | ||
| 119 | } | ||
| 120 | |||
| 121 | // Perform the sync if requested | ||
| 122 | if (needs_sync) { | ||
| 123 | if (transaction_rpc_send(RPC_ID_USER_STATE_SYNC, sizeof(user_state), &user_state)) { | ||
| 124 | last_sync[0] = timer_read32(); | ||
| 125 | } | ||
| 126 | needs_sync = false; | ||
| 127 | } | ||
| 128 | |||
| 129 | // Check if the state values are different | ||
| 130 | if (memcmp(&transport_keymap_config, &last_keymap, sizeof(transport_keymap_config))) { | ||
| 131 | needs_sync = true; | ||
| 132 | memcpy(&last_keymap, &transport_keymap_config, sizeof(transport_keymap_config)); | ||
| 133 | } | ||
| 134 | |||
| 135 | // Send to slave every 500ms regardless of state change | ||
| 136 | if (timer_elapsed32(last_sync[1]) > 250) { | ||
| 137 | needs_sync = true; | ||
| 138 | } | ||
| 139 | |||
| 140 | // Perform the sync if requested | ||
| 141 | if (needs_sync) { | ||
| 142 | if (transaction_rpc_send(RPC_ID_USER_KEYMAP_SYNC, sizeof(transport_keymap_config), &transport_keymap_config)) { | ||
| 143 | last_sync[1] = timer_read32(); | ||
| 144 | } | ||
| 145 | needs_sync = false; | ||
| 146 | } | ||
| 147 | |||
| 148 | // Check if the state values are different | ||
| 149 | if (memcmp(&user_state, &last_config, sizeof(transport_userspace_config))) { | ||
| 150 | needs_sync = true; | ||
| 151 | memcpy(&last_config, &user_state, sizeof(transport_userspace_config)); | ||
| 152 | } | ||
| 153 | |||
| 154 | // Send to slave every 500ms regardless of state change | ||
| 155 | if (timer_elapsed32(last_sync[2]) > 250) { | ||
| 156 | needs_sync = true; | ||
| 157 | } | ||
| 158 | |||
| 159 | // Perform the sync if requested | ||
| 160 | if (needs_sync) { | ||
| 161 | if (transaction_rpc_send(RPC_ID_USER_CONFIG_SYNC, sizeof(transport_userspace_config), &transport_userspace_config)) { | ||
| 162 | last_sync[2] = timer_read32(); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | void housekeeping_task_user(void) { | ||
| 169 | // Update kb_state so we can send to slave | ||
| 170 | user_transport_update(); | ||
| 171 | |||
| 172 | // Data sync from master to slave | ||
| 173 | user_transport_sync(); | ||
| 174 | } | ||
diff --git a/users/drashna/split/transport_sync.h b/users/drashna/split/transport_sync.h new file mode 100644 index 000000000..70b6ea522 --- /dev/null +++ b/users/drashna/split/transport_sync.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | |||
| 2 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | ||
| 3 | * | ||
| 4 | * This program is free software: you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation, either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #pragma once | ||
| 19 | |||
| 20 | #include "drashna.h" | ||
| 21 | |||
| 22 | typedef union { | ||
| 23 | uint32_t raw; | ||
| 24 | struct { | ||
| 25 | bool audio_enable :1; | ||
| 26 | bool audio_clicky_enable :1; | ||
| 27 | bool tap_toggling :1; | ||
| 28 | bool unicode_mode :1; | ||
| 29 | bool swap_hands :1; | ||
| 30 | bool host_driver_disabled :1; | ||
| 31 | }; | ||
| 32 | } user_runtime_config_t; | ||
| 33 | |||
| 34 | extern user_runtime_config_t user_state; | ||
| 35 | |||
| 36 | void keyboard_post_init_transport_sync(void); | ||
