diff options
author | Matti Hiljanen <[email protected]> | 2025-05-12 05:15:40 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2025-05-12 12:15:40 +1000 |
commit | 070dea4a9cfa7f154a99a57212929dfc4f492268 (patch) | |
tree | c138d62b0ca2b44e3f9d67d9846291142193b0fe /quantum/os_detection.c | |
parent | f4171412a676ae3cbd1cd50e859a7deb1a554e15 (diff) | |
download | qmk_firmware-070dea4a9cfa7f154a99a57212929dfc4f492268.tar.gz qmk_firmware-070dea4a9cfa7f154a99a57212929dfc4f492268.zip |
Fix OS_DETECTION_KEYBOARD_RESET (#25015)
Co-authored-by: Nick Brassel <[email protected]>
Diffstat (limited to 'quantum/os_detection.c')
-rw-r--r-- | quantum/os_detection.c | 26 |
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) |