diff options
Diffstat (limited to 'quantum/os_detection.c')
-rw-r--r-- | quantum/os_detection.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/quantum/os_detection.c b/quantum/os_detection.c index 84bbeeed54..552375f61c 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -68,14 +68,28 @@ 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; +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(); @@ -96,12 +110,17 @@ void os_detection_task(void) { if (detected_os != reported_os || first_report) { first_report = false; reported_os = detected_os; + process_detected_host_os_modules(detected_os); process_detected_host_os_kb(detected_os); } } } } +__attribute__((weak)) bool process_detected_host_os_modules(os_variant_t os) { + return true; +} + __attribute__((weak)) bool process_detected_host_os_kb(os_variant_t detected_os) { return process_detected_host_os_user(detected_os); } @@ -180,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) |