forked from forks/qmk_firmware
OS Detection - Entire file should not be wrapped with ifdef (#23108)
This commit is contained in:
parent
8df2e70ae4
commit
9f95577ef2
|
@ -16,15 +16,13 @@
|
||||||
|
|
||||||
#include "os_detection.h"
|
#include "os_detection.h"
|
||||||
|
|
||||||
#ifdef OS_DETECTION_ENABLE
|
#include <string.h>
|
||||||
|
#include "timer.h"
|
||||||
# include <string.h>
|
#ifdef OS_DETECTION_KEYBOARD_RESET
|
||||||
# include "timer.h"
|
|
||||||
# ifdef OS_DETECTION_KEYBOARD_RESET
|
|
||||||
# include "quantum.h"
|
# include "quantum.h"
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
# ifdef OS_DETECTION_DEBUG_ENABLE
|
#ifdef OS_DETECTION_DEBUG_ENABLE
|
||||||
# include "eeconfig.h"
|
# include "eeconfig.h"
|
||||||
# include "eeprom.h"
|
# include "eeprom.h"
|
||||||
# include "print.h"
|
# include "print.h"
|
||||||
|
@ -33,7 +31,17 @@
|
||||||
# define EEPROM_USER_OFFSET (uint8_t*)EECONFIG_SIZE
|
# 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,15 +170,15 @@ 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);
|
||||||
|
@ -201,6 +197,4 @@ void store_setups_in_eeprom(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# endif // OS_DETECTION_DEBUG_ENABLE
|
#endif // OS_DETECTION_DEBUG_ENABLE
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
Loading…
Reference in a new issue