aboutsummaryrefslogtreecommitdiff
path: root/quantum/os_detection.c
diff options
context:
space:
mode:
authorNick Brassel <[email protected]>2025-05-26 21:41:49 +1000
committerNick Brassel <[email protected]>2025-05-26 21:41:49 +1000
commit75a037d2f0f9c54bad8e2f68ae82134559c92f22 (patch)
tree2b264de0e7a724c30cca511a9bac7ad29705d1a2 /quantum/os_detection.c
parent28720c4d343a9c5e9f5a62dbd583dbf536a2e61e (diff)
parent3703699757b6ce938ff412aca0a8b064927c0cdb (diff)
downloadqmk_firmware-75a037d2f0f9c54bad8e2f68ae82134559c92f22.tar.gz
qmk_firmware-75a037d2f0f9c54bad8e2f68ae82134559c92f22.zip
Merge remote-tracking branch 'upstream/develop'0.29.0
Diffstat (limited to 'quantum/os_detection.c')
-rw-r--r--quantum/os_detection.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/quantum/os_detection.c b/quantum/os_detection.c
index 9a9f9052f2..552375f61c 100644
--- a/quantum/os_detection.c
+++ b/quantum/os_detection.c
@@ -68,6 +68,15 @@ static volatile bool first_report = true;
static volatile struct usb_device_state current_usb_device_state = {.configure_state = USB_DEVICE_STATE_NO_INIT};
static volatile struct usb_device_state maxprev_usb_device_state = {.configure_state = USB_DEVICE_STATE_NO_INIT};
+// to reset the keyboard on USB state change
+#ifdef OS_DETECTION_KEYBOARD_RESET
+# ifndef OS_DETECTION_RESET_DEBOUNCE
+# define OS_DETECTION_RESET_DEBOUNCE OS_DETECTION_DEBOUNCE
+# endif
+static volatile fast_timer_t configured_since = 0;
+static volatile bool reset_pending = false;
+#endif
+
// the OS detection might be unstable for a while, "debounce" it
static volatile bool debouncing = false;
static volatile fast_timer_t last_time = 0;
@@ -77,7 +86,10 @@ bool process_detected_host_os_modules(os_variant_t os);
void os_detection_task(void) {
#ifdef OS_DETECTION_KEYBOARD_RESET
// resetting the keyboard on the USB device state change callback results in instability, so delegate that to this task
- // only take action if it's been stable at least once, to avoid issues with some KVMs
+ if (reset_pending) {
+ soft_reset_keyboard();
+ }
+ // reset the keyboard if it is stuck in the init state for longer than debounce duration, which can happen with some KVMs
if (current_usb_device_state.configure_state <= USB_DEVICE_STATE_INIT && maxprev_usb_device_state.configure_state >= USB_DEVICE_STATE_CONFIGURED) {
if (debouncing && timer_elapsed_fast(last_time) >= OS_DETECTION_DEBOUNCE) {
soft_reset_keyboard();
@@ -187,6 +199,18 @@ void os_detection_notify_usb_device_state_change(struct usb_device_state usb_dev
current_usb_device_state = usb_device_state;
last_time = timer_read_fast();
debouncing = true;
+
+#ifdef OS_DETECTION_KEYBOARD_RESET
+ if (configured_since == 0 && current_usb_device_state.configure_state == USB_DEVICE_STATE_CONFIGURED) {
+ configured_since = timer_read_fast();
+ } else if (current_usb_device_state.configure_state == USB_DEVICE_STATE_INIT) {
+ // reset the keyboard only if it's been stable for at least debounce duration, to avoid issues with some KVMs
+ if (configured_since > 0 && timer_elapsed_fast(configured_since) >= OS_DETECTION_RESET_DEBOUNCE) {
+ reset_pending = true;
+ }
+ configured_since = 0;
+ }
+#endif
}
#if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE)