summaryrefslogtreecommitdiff
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 cee3f04c8f..794664293c 100644
--- a/users/drashna/split/transport_sync.c
+++ b/users/drashna/split/transport_sync.c
@@ -1,22 +1,12 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
#include "transport_sync.h"
#include "transactions.h"
#include <string.h>
+#ifdef __AVR__
+# include <avr/wdt.h>
+#endif
#ifdef CUSTOM_UNICODE_ENABLE
#include "process_unicode_common.h"
@@ -33,6 +23,10 @@ extern bool tap_toggling;
#ifdef SWAP_HANDS_ENABLE
extern bool swap_hands;
#endif
+
+static bool watchdog_ping_done = false;
+static uint32_t watchdog_timer = 0;
+
extern userspace_config_t userspace_config;
extern bool host_driver_disabled;
@@ -57,11 +51,20 @@ void user_config_sync(uint8_t initiator2target_buffer_size, const void* initiato
}
}
+void watchdog_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { watchdog_ping_done = true; }
+
+
void keyboard_post_init_transport_sync(void) {
// Register keyboard state sync split transaction
transaction_register_rpc(RPC_ID_USER_STATE_SYNC, user_state_sync);
transaction_register_rpc(RPC_ID_USER_KEYMAP_SYNC, user_keymap_sync);
transaction_register_rpc(RPC_ID_USER_CONFIG_SYNC, user_config_sync);
+
+#ifdef __AVR__
+ wdt_disable();
+#endif
+ transaction_register_rpc(RPC_ID_USER_WATCHDOG_SYNC, watchdog_handler);
+ watchdog_timer = timer_read32();
}
void user_transport_update(void) {
@@ -163,6 +166,30 @@ void user_transport_sync(void) {
}
}
}
+
+ if (!watchdog_ping_done) {
+ if (is_keyboard_master()) {
+ if (timer_elapsed32(watchdog_timer) > 100) {
+ uint8_t any_data = 1;
+ if (transaction_rpc_send(RPC_ID_USER_WATCHDOG_SYNC, sizeof(any_data), &any_data)) {
+ watchdog_ping_done = true; // successful ping
+ } else {
+ dprint("Watchdog ping failed!\n");
+ }
+ watchdog_timer = timer_read32();
+ }
+ } else {
+ if (timer_elapsed32(watchdog_timer) > 3500) {
+#ifdef __AVR__
+ wdt_enable(WDTO_250MS);
+#else
+ NVIC_SystemReset();
+#endif
+ while (1) {
+ }
+ }
+ }
+ }
}
void housekeeping_task_user(void) {