aboutsummaryrefslogtreecommitdiff
path: root/users/drashna/split/transport_sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/drashna/split/transport_sync.c')
-rw-r--r--users/drashna/split/transport_sync.c57
1 files changed, 42 insertions, 15 deletions
diff --git a/users/drashna/split/transport_sync.c b/users/drashna/split/transport_sync.c
index cee3f04c8..794664293 100644
--- a/users/drashna/split/transport_sync.c
+++ b/users/drashna/split/transport_sync.c
@@ -1,22 +1,12 @@
1/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> 1// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
2 * 2// SPDX-License-Identifier: GPL-2.0-or-later
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 3
17#include "transport_sync.h" 4#include "transport_sync.h"
18#include "transactions.h" 5#include "transactions.h"
19#include <string.h> 6#include <string.h>
7#ifdef __AVR__
8# include <avr/wdt.h>
9#endif
20 10
21#ifdef CUSTOM_UNICODE_ENABLE 11#ifdef CUSTOM_UNICODE_ENABLE
22#include "process_unicode_common.h" 12#include "process_unicode_common.h"
@@ -33,6 +23,10 @@ extern bool tap_toggling;
33#ifdef SWAP_HANDS_ENABLE 23#ifdef SWAP_HANDS_ENABLE
34extern bool swap_hands; 24extern bool swap_hands;
35#endif 25#endif
26
27static bool watchdog_ping_done = false;
28static uint32_t watchdog_timer = 0;
29
36extern userspace_config_t userspace_config; 30extern userspace_config_t userspace_config;
37extern bool host_driver_disabled; 31extern bool host_driver_disabled;
38 32
@@ -57,11 +51,20 @@ void user_config_sync(uint8_t initiator2target_buffer_size, const void* initiato
57 } 51 }
58} 52}
59 53
54void watchdog_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { watchdog_ping_done = true; }
55
56
60void keyboard_post_init_transport_sync(void) { 57void keyboard_post_init_transport_sync(void) {
61 // Register keyboard state sync split transaction 58 // Register keyboard state sync split transaction
62 transaction_register_rpc(RPC_ID_USER_STATE_SYNC, user_state_sync); 59 transaction_register_rpc(RPC_ID_USER_STATE_SYNC, user_state_sync);
63 transaction_register_rpc(RPC_ID_USER_KEYMAP_SYNC, user_keymap_sync); 60 transaction_register_rpc(RPC_ID_USER_KEYMAP_SYNC, user_keymap_sync);
64 transaction_register_rpc(RPC_ID_USER_CONFIG_SYNC, user_config_sync); 61 transaction_register_rpc(RPC_ID_USER_CONFIG_SYNC, user_config_sync);
62
63#ifdef __AVR__
64 wdt_disable();
65#endif
66 transaction_register_rpc(RPC_ID_USER_WATCHDOG_SYNC, watchdog_handler);
67 watchdog_timer = timer_read32();
65} 68}
66 69
67void user_transport_update(void) { 70void user_transport_update(void) {
@@ -163,6 +166,30 @@ void user_transport_sync(void) {
163 } 166 }
164 } 167 }
165 } 168 }
169
170 if (!watchdog_ping_done) {
171 if (is_keyboard_master()) {
172 if (timer_elapsed32(watchdog_timer) > 100) {
173 uint8_t any_data = 1;
174 if (transaction_rpc_send(RPC_ID_USER_WATCHDOG_SYNC, sizeof(any_data), &any_data)) {
175 watchdog_ping_done = true; // successful ping
176 } else {
177 dprint("Watchdog ping failed!\n");
178 }
179 watchdog_timer = timer_read32();
180 }
181 } else {
182 if (timer_elapsed32(watchdog_timer) > 3500) {
183#ifdef __AVR__
184 wdt_enable(WDTO_250MS);
185#else
186 NVIC_SystemReset();
187#endif
188 while (1) {
189 }
190 }
191 }
192 }
166} 193}
167 194
168void housekeeping_task_user(void) { 195void housekeeping_task_user(void) {