diff options
Diffstat (limited to 'users/drashna/split/transport_sync.c')
-rw-r--r-- | users/drashna/split/transport_sync.c | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/users/drashna/split/transport_sync.c b/users/drashna/split/transport_sync.c index 794664293..2509e448c 100644 --- a/users/drashna/split/transport_sync.c +++ b/users/drashna/split/transport_sync.c | |||
@@ -9,7 +9,7 @@ | |||
9 | #endif | 9 | #endif |
10 | 10 | ||
11 | #ifdef CUSTOM_UNICODE_ENABLE | 11 | #ifdef CUSTOM_UNICODE_ENABLE |
12 | #include "process_unicode_common.h" | 12 | # include "process_unicode_common.h" |
13 | extern unicode_config_t unicode_config; | 13 | extern unicode_config_t unicode_config; |
14 | #endif | 14 | #endif |
15 | #ifdef AUDIO_ENABLE | 15 | #ifdef AUDIO_ENABLE |
@@ -24,8 +24,10 @@ extern bool tap_toggling; | |||
24 | extern bool swap_hands; | 24 | extern bool swap_hands; |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | static bool watchdog_ping_done = false; | 27 | #if defined(SPLIT_WATCHDOG_TIMEOUT) |
28 | static uint32_t watchdog_timer = 0; | 28 | static bool watchdog_ping_done = false; |
29 | static uint32_t watchdog_timer = 0; | ||
30 | #endif | ||
29 | 31 | ||
30 | extern userspace_config_t userspace_config; | 32 | extern userspace_config_t userspace_config; |
31 | extern bool host_driver_disabled; | 33 | extern bool host_driver_disabled; |
@@ -51,20 +53,35 @@ void user_config_sync(uint8_t initiator2target_buffer_size, const void* initiato | |||
51 | } | 53 | } |
52 | } | 54 | } |
53 | 55 | ||
56 | #if defined(SPLIT_WATCHDOG_TIMEOUT) | ||
54 | void watchdog_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { watchdog_ping_done = true; } | 57 | void watchdog_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { watchdog_ping_done = true; } |
58 | #endif | ||
55 | 59 | ||
60 | #ifdef OLED_ENABLE | ||
61 | #include "oled/oled_stuff.h" | ||
62 | void keylogger_string_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { | ||
63 | if (initiator2target_buffer_size == OLED_KEYLOGGER_LENGTH) { | ||
64 | memcpy(&keylog_str, initiator2target_buffer, initiator2target_buffer_size); | ||
65 | } | ||
66 | } | ||
67 | #endif | ||
56 | 68 | ||
57 | void keyboard_post_init_transport_sync(void) { | 69 | void keyboard_post_init_transport_sync(void) { |
58 | // Register keyboard state sync split transaction | 70 | // Register keyboard state sync split transaction |
59 | transaction_register_rpc(RPC_ID_USER_STATE_SYNC, user_state_sync); | 71 | transaction_register_rpc(RPC_ID_USER_STATE_SYNC, user_state_sync); |
60 | transaction_register_rpc(RPC_ID_USER_KEYMAP_SYNC, user_keymap_sync); | 72 | transaction_register_rpc(RPC_ID_USER_KEYMAP_SYNC, user_keymap_sync); |
61 | transaction_register_rpc(RPC_ID_USER_CONFIG_SYNC, user_config_sync); | 73 | transaction_register_rpc(RPC_ID_USER_CONFIG_SYNC, user_config_sync); |
74 | #ifdef OLED_ENABLE | ||
75 | transaction_register_rpc(RPC_ID_USER_KEYLOG_STR, keylogger_string_sync); | ||
76 | #endif | ||
62 | 77 | ||
63 | #ifdef __AVR__ | 78 | #if defined(SPLIT_WATCHDOG_TIMEOUT) |
79 | # if defined(PROTOCOL_LUFA) | ||
64 | wdt_disable(); | 80 | wdt_disable(); |
65 | #endif | 81 | # endif |
66 | transaction_register_rpc(RPC_ID_USER_WATCHDOG_SYNC, watchdog_handler); | 82 | transaction_register_rpc(RPC_ID_USER_WATCHDOG_SYNC, watchdog_handler); |
67 | watchdog_timer = timer_read32(); | 83 | watchdog_timer = timer_read32(); |
84 | #endif | ||
68 | } | 85 | } |
69 | 86 | ||
70 | void user_transport_update(void) { | 87 | void user_transport_update(void) { |
@@ -107,9 +124,12 @@ void user_transport_update(void) { | |||
107 | void user_transport_sync(void) { | 124 | void user_transport_sync(void) { |
108 | if (is_keyboard_master()) { | 125 | if (is_keyboard_master()) { |
109 | // Keep track of the last state, so that we can tell if we need to propagate to slave | 126 | // Keep track of the last state, so that we can tell if we need to propagate to slave |
110 | static uint16_t last_keymap = 0; | 127 | static uint16_t last_keymap = 0; |
111 | static uint32_t last_config = 0, last_sync[3], last_user_state = 0; | 128 | static uint32_t last_config = 0, last_sync[4], last_user_state = 0; |
112 | bool needs_sync = false; | 129 | bool needs_sync = false; |
130 | #ifdef OLED_ENABLE | ||
131 | static char keylog_temp[OLED_KEYLOGGER_LENGTH] = { 0 }; | ||
132 | #endif | ||
113 | 133 | ||
114 | // Check if the state values are different | 134 | // Check if the state values are different |
115 | if (memcmp(&transport_user_state, &last_user_state, sizeof(transport_user_state))) { | 135 | if (memcmp(&transport_user_state, &last_user_state, sizeof(transport_user_state))) { |
@@ -164,9 +184,30 @@ void user_transport_sync(void) { | |||
164 | if (transaction_rpc_send(RPC_ID_USER_CONFIG_SYNC, sizeof(transport_userspace_config), &transport_userspace_config)) { | 184 | if (transaction_rpc_send(RPC_ID_USER_CONFIG_SYNC, sizeof(transport_userspace_config), &transport_userspace_config)) { |
165 | last_sync[2] = timer_read32(); | 185 | last_sync[2] = timer_read32(); |
166 | } | 186 | } |
187 | needs_sync = false; | ||
188 | } | ||
189 | |||
190 | #ifdef OLED_ENABLE | ||
191 | // Check if the state values are different | ||
192 | if (memcmp(&keylog_str, &keylog_temp, OLED_KEYLOGGER_LENGTH)) { | ||
193 | needs_sync = true; | ||
194 | memcpy(&keylog_temp, &keylog_str, OLED_KEYLOGGER_LENGTH); | ||
195 | } | ||
196 | if (timer_elapsed32(last_sync[3]) > 250) { | ||
197 | needs_sync = true; | ||
198 | } | ||
199 | |||
200 | // Perform the sync if requested | ||
201 | if (needs_sync) { | ||
202 | if (transaction_rpc_send(RPC_ID_USER_KEYLOG_STR, OLED_KEYLOGGER_LENGTH, &keylog_str)) { | ||
203 | last_sync[3] = timer_read32(); | ||
204 | } | ||
205 | needs_sync = false; | ||
167 | } | 206 | } |
207 | #endif | ||
168 | } | 208 | } |
169 | 209 | ||
210 | #if defined(SPLIT_WATCHDOG_TIMEOUT) | ||
170 | if (!watchdog_ping_done) { | 211 | if (!watchdog_ping_done) { |
171 | if (is_keyboard_master()) { | 212 | if (is_keyboard_master()) { |
172 | if (timer_elapsed32(watchdog_timer) > 100) { | 213 | if (timer_elapsed32(watchdog_timer) > 100) { |
@@ -180,16 +221,14 @@ void user_transport_sync(void) { | |||
180 | } | 221 | } |
181 | } else { | 222 | } else { |
182 | if (timer_elapsed32(watchdog_timer) > 3500) { | 223 | if (timer_elapsed32(watchdog_timer) > 3500) { |
183 | #ifdef __AVR__ | 224 | software_reset(); |
184 | wdt_enable(WDTO_250MS); | ||
185 | #else | ||
186 | NVIC_SystemReset(); | ||
187 | #endif | ||
188 | while (1) { | 225 | while (1) { |
189 | } | 226 | } |
190 | } | 227 | } |
191 | } | 228 | } |
192 | } | 229 | } |
230 | #endif | ||
231 | |||
193 | } | 232 | } |
194 | 233 | ||
195 | void housekeeping_task_user(void) { | 234 | void housekeeping_task_user(void) { |