aboutsummaryrefslogtreecommitdiff
path: root/quantum/os_detection.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/os_detection.c')
-rw-r--r--quantum/os_detection.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/quantum/os_detection.c b/quantum/os_detection.c
index 0dd048a8c4..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);
}
@@ -133,7 +152,7 @@ void process_wlength(const uint16_t w_length) {
} else if (setups_data.count == setups_data.cnt_ff) {
// Linux has 3 packets with 0xFF.
guessed = OS_LINUX;
- } else if (setups_data.count == 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff == 1 && setups_data.cnt_02 == 2) {
+ } else if (setups_data.count >= 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff >= 1 && setups_data.cnt_02 >= 2) {
guessed = OS_MACOS;
} else if (setups_data.count == 4 && setups_data.cnt_ff == 0 && setups_data.cnt_02 == 2) {
// iOS and iPadOS don't have the last 0xFF packet.
@@ -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)