1
0
Fork 0
forked from forks/qmk_firmware

OS Detection - Entire file should not be wrapped with ifdef (#23108)

This commit is contained in:
Joel Challis 2024-02-19 15:37:51 +00:00 committed by GitHub
parent 8df2e70ae4
commit 9f95577ef2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 49 deletions

View file

@ -16,24 +16,32 @@
#include "os_detection.h" #include "os_detection.h"
#ifdef OS_DETECTION_ENABLE #include <string.h>
#include "timer.h"
#ifdef OS_DETECTION_KEYBOARD_RESET
# include "quantum.h"
#endif
# include <string.h> #ifdef OS_DETECTION_DEBUG_ENABLE
# include "timer.h" # include "eeconfig.h"
# ifdef OS_DETECTION_KEYBOARD_RESET # include "eeprom.h"
# include "quantum.h" # include "print.h"
# endif
# ifdef OS_DETECTION_DEBUG_ENABLE # define STORED_USB_SETUPS 50
# include "eeconfig.h" # define EEPROM_USER_OFFSET (uint8_t*)EECONFIG_SIZE
# include "eeprom.h"
# include "print.h"
# define STORED_USB_SETUPS 50
# define EEPROM_USER_OFFSET (uint8_t*)EECONFIG_SIZE
static uint16_t usb_setups[STORED_USB_SETUPS]; static uint16_t usb_setups[STORED_USB_SETUPS];
# endif #endif
#ifndef OS_DETECTION_DEBOUNCE
# define OS_DETECTION_DEBOUNCE 200
#endif
// 2s should always be more than enough (otherwise, you may have other issues)
#if OS_DETECTION_DEBOUNCE > 2000
# undef OS_DETECTION_DEBOUNCE
# define OS_DETECTION_DEBOUNCE 2000
#endif
struct setups_data_t { struct setups_data_t {
uint8_t count; uint8_t count;
@ -50,18 +58,6 @@ struct setups_data_t setups_data = {
.cnt_ff = 0, .cnt_ff = 0,
}; };
# ifndef OS_DETECTION_DEBOUNCE
# define OS_DETECTION_DEBOUNCE 200
# endif
// 2s should always be more than enough (otherwise, you may have other issues)
# if OS_DETECTION_DEBOUNCE > 2000
# undef OS_DETECTION_DEBOUNCE
# define OS_DETECTION_DEBOUNCE 2000
# endif
typedef uint16_t debouncing_t;
static volatile os_variant_t detected_os = OS_UNSURE; static volatile os_variant_t detected_os = OS_UNSURE;
static os_variant_t reported_os = OS_UNSURE; static os_variant_t reported_os = OS_UNSURE;
@ -89,13 +85,13 @@ void os_detection_task(void) {
} }
} }
} }
# ifdef OS_DETECTION_KEYBOARD_RESET #ifdef OS_DETECTION_KEYBOARD_RESET
// resetting the keyboard on the USB device state change callback results in instability, so delegate that to this task // 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 // only take action if it's been stable at least once, to avoid issues with some KVMs
else if (current_usb_device_state == USB_DEVICE_STATE_INIT && reported_usb_device_state != USB_DEVICE_STATE_INIT) { else if (current_usb_device_state == USB_DEVICE_STATE_INIT && reported_usb_device_state != USB_DEVICE_STATE_INIT) {
soft_reset_keyboard(); soft_reset_keyboard();
} }
# endif #endif
} }
__attribute__((weak)) bool process_detected_host_os_kb(os_variant_t detected_os) { __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
// Some collected sequences of wLength can be found in tests. // Some collected sequences of wLength can be found in tests.
void process_wlength(const uint16_t w_length) { void process_wlength(const uint16_t w_length) {
# ifdef OS_DETECTION_DEBUG_ENABLE #ifdef OS_DETECTION_DEBUG_ENABLE
usb_setups[setups_data.count] = w_length; usb_setups[setups_data.count] = w_length;
# endif #endif
setups_data.count++; setups_data.count++;
setups_data.last_wlength = w_length; setups_data.last_wlength = w_length;
if (w_length == 0x2) { if (w_length == 0x2) {
@ -174,23 +170,23 @@ void os_detection_notify_usb_device_state_change(enum usb_device_state usb_devic
debouncing = true; debouncing = true;
} }
# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) #if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE)
void slave_update_detected_host_os(os_variant_t os) { void slave_update_detected_host_os(os_variant_t os) {
detected_os = os; detected_os = os;
last_time = timer_read_fast(); last_time = timer_read_fast();
debouncing = true; debouncing = true;
} }
# endif #endif
# ifdef OS_DETECTION_DEBUG_ENABLE #ifdef OS_DETECTION_DEBUG_ENABLE
void print_stored_setups(void) { void print_stored_setups(void) {
# ifdef CONSOLE_ENABLE # ifdef CONSOLE_ENABLE
uint8_t cnt = eeprom_read_byte(EEPROM_USER_OFFSET); uint8_t cnt = eeprom_read_byte(EEPROM_USER_OFFSET);
for (uint16_t i = 0; i < cnt; ++i) { for (uint16_t i = 0; i < cnt; ++i) {
uint16_t* addr = (uint16_t*)EEPROM_USER_OFFSET + i * sizeof(uint16_t) + sizeof(uint8_t); uint16_t* addr = (uint16_t*)EEPROM_USER_OFFSET + i * sizeof(uint16_t) + sizeof(uint8_t);
xprintf("i: %d, wLength: 0x%02X\n", i, eeprom_read_word(addr)); xprintf("i: %d, wLength: 0x%02X\n", i, eeprom_read_word(addr));
} }
# endif # endif
} }
void store_setups_in_eeprom(void) { void store_setups_in_eeprom(void) {
@ -201,6 +197,4 @@ void store_setups_in_eeprom(void) {
} }
} }
# endif // OS_DETECTION_DEBUG_ENABLE #endif // OS_DETECTION_DEBUG_ENABLE
#endif

View file

@ -16,11 +16,9 @@
#pragma once #pragma once
#ifdef OS_DETECTION_ENABLE #include <stdint.h>
#include <stdbool.h>
# include <stdint.h> #include "usb_device_state.h"
# include <stdbool.h>
# include "usb_device_state.h"
typedef enum { typedef enum {
OS_UNSURE, OS_UNSURE,
@ -40,13 +38,11 @@ void os_detection_task(void);
bool process_detected_host_os_kb(os_variant_t os); bool process_detected_host_os_kb(os_variant_t os);
bool process_detected_host_os_user(os_variant_t os); bool process_detected_host_os_user(os_variant_t os);
# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) #if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE)
void slave_update_detected_host_os(os_variant_t os); void slave_update_detected_host_os(os_variant_t os);
# endif #endif
# ifdef OS_DETECTION_DEBUG_ENABLE #ifdef OS_DETECTION_DEBUG_ENABLE
void print_stored_setups(void); void print_stored_setups(void);
void store_setups_in_eeprom(void); void store_setups_in_eeprom(void);
# endif #endif
#endif // OS_DETECTION_ENABLE