summaryrefslogtreecommitdiffstats
path: root/quantum/split_common/split_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/split_common/split_util.c')
-rw-r--r--quantum/split_common/split_util.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index 0b3338ed6f..9f57c7b9fc 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -74,6 +74,46 @@ static inline bool usbIsActive(void) {
}
#endif
+#if defined(SPLIT_WATCHDOG_ENABLE)
+# if !defined(SPLIT_WATCHDOG_TIMEOUT)
+# if defined(SPLIT_USB_TIMEOUT)
+# define SPLIT_WATCHDOG_TIMEOUT (SPLIT_USB_TIMEOUT + 100)
+# else
+# define SPLIT_WATCHDOG_TIMEOUT 3000
+# endif
+# endif
+# if defined(SPLIT_USB_DETECT)
+_Static_assert(SPLIT_USB_TIMEOUT < SPLIT_WATCHDOG_TIMEOUT, "SPLIT_WATCHDOG_TIMEOUT should not be below SPLIT_USB_TIMEOUT.");
+# endif
+_Static_assert(SPLIT_MAX_CONNECTION_ERRORS > 0, "SPLIT_WATCHDOG_ENABLE requires SPLIT_MAX_CONNECTION_ERRORS be above 0 for a functioning disconnection check.");
+
+static uint32_t split_watchdog_started = 0;
+static bool split_watchdog_done = false;
+
+void split_watchdog_init(void) {
+ split_watchdog_started = timer_read32();
+}
+
+void split_watchdog_update(bool done) {
+ split_watchdog_done = done;
+}
+
+bool split_watchdog_check(void) {
+ if (!is_transport_connected()) {
+ split_watchdog_done = false;
+ }
+ return split_watchdog_done;
+}
+
+void split_watchdog_task(void) {
+ if (!split_watchdog_done && !is_keyboard_master()) {
+ if (timer_elapsed32(split_watchdog_started) > SPLIT_WATCHDOG_TIMEOUT) {
+ mcu_reset();
+ }
+ }
+}
+#endif // defined(SPLIT_WATCHDOG_ENABLE)
+
#ifdef SPLIT_HAND_MATRIX_GRID
void matrix_io_delay(void);
@@ -179,6 +219,9 @@ void split_pre_init(void) {
void split_post_init(void) {
if (!is_keyboard_master()) {
transport_slave_init();
+#if defined(SPLIT_WATCHDOG_ENABLE)
+ split_watchdog_init();
+#endif
}
}