summaryrefslogtreecommitdiff
path: root/quantum/os_detection.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/os_detection.c')
-rw-r--r--quantum/os_detection.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/quantum/os_detection.c b/quantum/os_detection.c
index b1511afb14..e606227136 100644
--- a/quantum/os_detection.c
+++ b/quantum/os_detection.c
@@ -31,53 +31,53 @@ uint16_t usb_setups[STORED_USB_SETUPS];
#ifdef OS_DETECTION_ENABLE
struct setups_data_t {
- uint8_t count;
- uint8_t cnt_02;
- uint8_t cnt_04;
- uint8_t cnt_ff;
- uint16_t last_wlength;
- os_variant_t detected_os;
+ uint8_t count;
+ uint8_t cnt_02;
+ uint8_t cnt_04;
+ uint8_t cnt_ff;
+ uint16_t last_wlength;
};
struct setups_data_t setups_data = {
- .count = 0,
- .cnt_02 = 0,
- .cnt_04 = 0,
- .cnt_ff = 0,
- .detected_os = OS_UNSURE,
+ .count = 0,
+ .cnt_02 = 0,
+ .cnt_04 = 0,
+ .cnt_ff = 0,
};
+os_variant_t detected_os = OS_UNSURE;
+
// Some collected sequences of wLength can be found in tests.
void make_guess(void) {
if (setups_data.count < 3) {
return;
}
if (setups_data.cnt_ff >= 2 && setups_data.cnt_04 >= 1) {
- setups_data.detected_os = OS_WINDOWS;
+ detected_os = OS_WINDOWS;
return;
}
if (setups_data.count == setups_data.cnt_ff) {
// Linux has 3 packets with 0xFF.
- setups_data.detected_os = OS_LINUX;
+ detected_os = OS_LINUX;
return;
}
if (setups_data.count == 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff == 1 && setups_data.cnt_02 == 2) {
- setups_data.detected_os = OS_MACOS;
+ detected_os = OS_MACOS;
return;
}
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.
- setups_data.detected_os = OS_IOS;
+ detected_os = OS_IOS;
return;
}
if (setups_data.cnt_ff == 0 && setups_data.cnt_02 == 3 && setups_data.cnt_04 == 1) {
// This is actually PS5.
- setups_data.detected_os = OS_LINUX;
+ detected_os = OS_LINUX;
return;
}
if (setups_data.cnt_ff >= 1 && setups_data.cnt_02 == 0 && setups_data.cnt_04 == 0) {
// This is actually Quest 2 or Nintendo Switch.
- setups_data.detected_os = OS_LINUX;
+ detected_os = OS_LINUX;
return;
}
}
@@ -99,13 +99,20 @@ void process_wlength(const uint16_t w_length) {
}
os_variant_t detected_host_os(void) {
- return setups_data.detected_os;
+ return detected_os;
}
void erase_wlength_data(void) {
memset(&setups_data, 0, sizeof(setups_data));
+ detected_os = OS_UNSURE;
+}
+
+# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE)
+void slave_update_detected_host_os(os_variant_t os) {
+ detected_os = os;
}
-#endif // OS_DETECTION_ENABLE
+# endif // defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE)
+#endif // OS_DETECTION_ENABLE
#ifdef OS_DETECTION_DEBUG_ENABLE
void print_stored_setups(void) {