summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2024-02-19 15:37:51 +0000
committerGitHub <noreply@github.com>2024-02-19 15:37:51 +0000
commit9f95577ef2bfff55bf4f5d19c3dc58ea0f09e014 (patch)
tree9cab3a01fd4e1f8f6b99cdddd0b9ff49631962bb /quantum
parent8df2e70ae475841543e468c7d1660957367fe74d (diff)
OS Detection - Entire file should not be wrapped with ifdef (#23108)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/os_detection.c70
-rw-r--r--quantum/os_detection.h18
2 files changed, 39 insertions, 49 deletions
diff --git a/quantum/os_detection.c b/quantum/os_detection.c
index b674f05b35..96b026e247 100644
--- a/quantum/os_detection.c
+++ b/quantum/os_detection.c
@@ -16,24 +16,32 @@
16 16
17#include "os_detection.h" 17#include "os_detection.h"
18 18
19#ifdef OS_DETECTION_ENABLE 19#include <string.h>
20 20#include "timer.h"
21# include <string.h> 21#ifdef OS_DETECTION_KEYBOARD_RESET
22# include "timer.h" 22# include "quantum.h"
23# ifdef OS_DETECTION_KEYBOARD_RESET 23#endif
24# include "quantum.h"
25# endif
26 24
27# ifdef OS_DETECTION_DEBUG_ENABLE 25#ifdef OS_DETECTION_DEBUG_ENABLE
28# include "eeconfig.h" 26# include "eeconfig.h"
29# include "eeprom.h" 27# include "eeprom.h"
30# include "print.h" 28# include "print.h"
31 29
32# define STORED_USB_SETUPS 50 30# define STORED_USB_SETUPS 50
33# define EEPROM_USER_OFFSET (uint8_t*)EECONFIG_SIZE 31# define EEPROM_USER_OFFSET (uint8_t*)EECONFIG_SIZE
34 32
35static uint16_t usb_setups[STORED_USB_SETUPS]; 33static uint16_t usb_setups[STORED_USB_SETUPS];
36# endif 34#endif
35
36#ifndef OS_DETECTION_DEBOUNCE
37# define OS_DETECTION_DEBOUNCE 200
38#endif
39
40// 2s should always be more than enough (otherwise, you may have other issues)
41#if OS_DETECTION_DEBOUNCE > 2000
42# undef OS_DETECTION_DEBOUNCE
43# define OS_DETECTION_DEBOUNCE 2000
44#endif
37 45
38struct setups_data_t { 46struct setups_data_t {
39 uint8_t count; 47 uint8_t count;
@@ -50,18 +58,6 @@ struct setups_data_t setups_data = {
50 .cnt_ff = 0, 58 .cnt_ff = 0,
51}; 59};
52 60
53# ifndef OS_DETECTION_DEBOUNCE
54# define OS_DETECTION_DEBOUNCE 200
55# endif
56
57// 2s should always be more than enough (otherwise, you may have other issues)
58# if OS_DETECTION_DEBOUNCE > 2000
59# undef OS_DETECTION_DEBOUNCE
60# define OS_DETECTION_DEBOUNCE 2000
61# endif
62
63typedef uint16_t debouncing_t;
64
65static volatile os_variant_t detected_os = OS_UNSURE; 61static volatile os_variant_t detected_os = OS_UNSURE;
66static os_variant_t reported_os = OS_UNSURE; 62static os_variant_t reported_os = OS_UNSURE;
67 63
@@ -89,13 +85,13 @@ void os_detection_task(void) {
89 } 85 }
90 } 86 }
91 } 87 }
92# ifdef OS_DETECTION_KEYBOARD_RESET 88#ifdef OS_DETECTION_KEYBOARD_RESET
93 // resetting the keyboard on the USB device state change callback results in instability, so delegate that to this task 89 // resetting the keyboard on the USB device state change callback results in instability, so delegate that to this task
94 // only take action if it's been stable at least once, to avoid issues with some KVMs 90 // only take action if it's been stable at least once, to avoid issues with some KVMs
95 else if (current_usb_device_state == USB_DEVICE_STATE_INIT && reported_usb_device_state != USB_DEVICE_STATE_INIT) { 91 else if (current_usb_device_state == USB_DEVICE_STATE_INIT && reported_usb_device_state != USB_DEVICE_STATE_INIT) {
96 soft_reset_keyboard(); 92 soft_reset_keyboard();
97 } 93 }
98# endif 94#endif
99} 95}
100 96
101__attribute__((weak)) bool process_detected_host_os_kb(os_variant_t detected_os) { 97__attribute__((weak)) bool process_detected_host_os_kb(os_variant_t detected_os) {
@@ -108,9 +104,9 @@ __attribute__((weak)) bool process_detected_host_os_user(os_variant_t detected_o
108 104
109// Some collected sequences of wLength can be found in tests. 105// Some collected sequences of wLength can be found in tests.
110void process_wlength(const uint16_t w_length) { 106void process_wlength(const uint16_t w_length) {
111# ifdef OS_DETECTION_DEBUG_ENABLE 107#ifdef OS_DETECTION_DEBUG_ENABLE
112 usb_setups[setups_data.count] = w_length; 108 usb_setups[setups_data.count] = w_length;
113# endif 109#endif
114 setups_data.count++; 110 setups_data.count++;
115 setups_data.last_wlength = w_length; 111 setups_data.last_wlength = w_length;
116 if (w_length == 0x2) { 112 if (w_length == 0x2) {
@@ -174,23 +170,23 @@ void os_detection_notify_usb_device_state_change(enum usb_device_state usb_devic
174 debouncing = true; 170 debouncing = true;
175} 171}
176 172
177# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) 173#if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE)
178void slave_update_detected_host_os(os_variant_t os) { 174void slave_update_detected_host_os(os_variant_t os) {
179 detected_os = os; 175 detected_os = os;
180 last_time = timer_read_fast(); 176 last_time = timer_read_fast();
181 debouncing = true; 177 debouncing = true;
182} 178}
183# endif 179#endif
184 180
185# ifdef OS_DETECTION_DEBUG_ENABLE 181#ifdef OS_DETECTION_DEBUG_ENABLE
186void print_stored_setups(void) { 182void print_stored_setups(void) {
187# ifdef CONSOLE_ENABLE 183# ifdef CONSOLE_ENABLE
188 uint8_t cnt = eeprom_read_byte(EEPROM_USER_OFFSET); 184 uint8_t cnt = eeprom_read_byte(EEPROM_USER_OFFSET);
189 for (uint16_t i = 0; i < cnt; ++i) { 185 for (uint16_t i = 0; i < cnt; ++i) {
190 uint16_t* addr = (uint16_t*)EEPROM_USER_OFFSET + i * sizeof(uint16_t) + sizeof(uint8_t); 186 uint16_t* addr = (uint16_t*)EEPROM_USER_OFFSET + i * sizeof(uint16_t) + sizeof(uint8_t);
191 xprintf("i: %d, wLength: 0x%02X\n", i, eeprom_read_word(addr)); 187 xprintf("i: %d, wLength: 0x%02X\n", i, eeprom_read_word(addr));
192 } 188 }
193# endif 189# endif
194} 190}
195 191
196void store_setups_in_eeprom(void) { 192void store_setups_in_eeprom(void) {
@@ -201,6 +197,4 @@ void store_setups_in_eeprom(void) {
201 } 197 }
202} 198}
203 199
204# endif // OS_DETECTION_DEBUG_ENABLE 200#endif // OS_DETECTION_DEBUG_ENABLE
205
206#endif
diff --git a/quantum/os_detection.h b/quantum/os_detection.h
index 470f30943a..b8cd898335 100644
--- a/quantum/os_detection.h
+++ b/quantum/os_detection.h
@@ -16,11 +16,9 @@
16 16
17#pragma once 17#pragma once
18 18
19#ifdef OS_DETECTION_ENABLE 19#include <stdint.h>
20 20#include <stdbool.h>
21# include <stdint.h> 21#include "usb_device_state.h"
22# include <stdbool.h>
23# include "usb_device_state.h"
24 22
25typedef enum { 23typedef enum {
26 OS_UNSURE, 24 OS_UNSURE,
@@ -40,13 +38,11 @@ void os_detection_task(void);
40bool process_detected_host_os_kb(os_variant_t os); 38bool process_detected_host_os_kb(os_variant_t os);
41bool process_detected_host_os_user(os_variant_t os); 39bool process_detected_host_os_user(os_variant_t os);
42 40
43# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) 41#if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE)
44void slave_update_detected_host_os(os_variant_t os); 42void slave_update_detected_host_os(os_variant_t os);
45# endif 43#endif
46 44
47# ifdef OS_DETECTION_DEBUG_ENABLE 45#ifdef OS_DETECTION_DEBUG_ENABLE
48void print_stored_setups(void); 46void print_stored_setups(void);
49void store_setups_in_eeprom(void); 47void store_setups_in_eeprom(void);
50# endif 48#endif
51
52#endif // OS_DETECTION_ENABLE