DEBUG: Working BIOS hotkeys

Works from cold boot and from reboot in windows.

Signed-off-by: Daniel Schaefer <dhs@frame.work>
This commit is contained in:
Daniel Schaefer 2023-11-27 12:55:38 +08:00
parent 324b8d7736
commit c6ba5ad0a2
8 changed files with 132 additions and 19 deletions

View File

@ -79,7 +79,7 @@ void handle_factory_command(uint8_t *data) {
rgb_matrix_sethsv_noeeprom(0, 0, 0xFF);
rgb_matrix_mode_noeeprom(1);
#endif
bios_mode = false;
//bios_mode = false;
writePin(GP24, 0);
}
break;

View File

@ -3,6 +3,7 @@
#include "quantum.h"
#include "framework.h"
#include "os_detection.h"
void keyboard_post_init_kb(void) {
keyboard_post_init_user();
@ -65,7 +66,7 @@ void suspend_wakeup_init_kb(void) {
}
// If in BIOS mode, no matter what the keys have been remapped to, always send them as the F keys
bool bios_mode = false;
bool bios_mode = true;
bool handle_bios_hotkeys(uint16_t keycode, keyrecord_t *record) {
// Not in bios mode, no special handling, handle as normal
if (!bios_mode)
@ -174,6 +175,66 @@ bool handle_bios_hotkeys(uint16_t keycode, keyrecord_t *record) {
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
process_record_user(keycode, record);
os_variant_t os = detected_host_os();
#if defined(RGB_MATRIX_ENABLE)
//rgb_matrix_mode_noeeprom(1);
#endif
bios_mode = true;
writePin(GP24, 0);
//#if defined(RGB_MATRIX_ENABLE)
// switch (os) {
// case OS_UNSURE:
// //rgb_matrix_sethsv(0, 0, 255); // White
// break;
// case OS_LINUX:
// bios_mode = false
// writePin(GP24, 0);
// // Works on laptop and android
// //rgb_matrix_sethsv(213, 255, 255); // purple
// break;
// case OS_WINDOWS:
// bios_mode = false
// writePin(GP24, 0);
// // works
// //rgb_matrix_sethsv(170, 255, 255); // blue
// break;
// case OS_MACOS:
// //rgb_matrix_sethsv(85, 255, 255); // green
// break;
// case OS_UEFI:
// case OS_IOS:
// bios_mode = true
// writePin(GP24, 1)
// // works on M1 mac
// //rgb_matrix_sethsv(43, 255, 255); // yellow
// break;
// default:
// //rgb_matrix_sethsv(125, 255, 255); // cyan
// break;
// }
//#else
switch (os) {
case OS_UNSURE:
break;
case OS_LINUX:
//bios_mode = false;
//writePin(GP24, 1);
break;
case OS_WINDOWS:
bios_mode = false;
writePin(GP24, 1);
break;
case OS_MACOS:
break;
case OS_UEFI:
case OS_IOS:
bios_mode = true;
writePin(GP24, 0);
// works on M1 mac
break;
}
//#endif
if (!handle_bios_hotkeys(keycode, record)) {
return false;
}
@ -233,6 +294,8 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
default:
return true; // Process all other keycodes normally
}
return true;
}
bool led_update_kb(led_t led_state) {

View File

@ -313,10 +313,26 @@ bool handle_idle(void) {
return false;
}
#ifdef RGB_MATRIX_ENABLE
static bool rgb_init = false;
static uint16_t rgb_init_timer = 0;
#endif
/**
* Overriding behavior of matrix_scan from quantum/matrix.c
*/
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
#ifdef RGB_MATRIX_ENABLE
if (!rgb_init) {
if (!bios_mode) {
//if (rgb_init_timer > 0 && TIMER_DIFF_16(timer_read(), rgb_init_timer) >= 10000) {
//if (rgb_init_timer > 0 && TIMER_DIFF_16(timer_read(), rgb_init_timer) >= 100) {
//if (!bios_mode || rgb_init_timer > 0 && TIMER_DIFF_16(timer_read(), rgb_init_timer) >= 10000) {
rgb_matrix_init();
rgb_init = true;
}
}
#endif
bool changed = false;
adc10ksample_t voltages[MATRIX_ROWS][MATRIX_COLS] = {};
@ -436,4 +452,8 @@ void matrix_init_custom(void) {
// Set unused pins to input to avoid interfering. They're hooked up to rows 5 and 6
setPinInput(GP6);
setPinInput(GP7);
#ifdef RGB_MATRIX_ENABLE
rgb_init_timer = timer_read();
#endif
}

View File

@ -12,6 +12,9 @@ RAW_ENABLE = no
BACKLIGHT_ENABLE = yes
BACKLIGHT_DRIVER = pwm
OS_DETECTION_ENABLE = yes
#OS_DETECTION_DEBUG_ENABLE = yes
# Custom matrix scanning code via ADC
CUSTOM_MATRIX = lite
SRC += matrix.c analog.c

View File

@ -384,19 +384,20 @@ void quantum_init(void) {
backlight_init_ports();
#endif
#ifdef AUDIO_ENABLE
audio_init();
audio_init()
#endif
#ifdef LED_MATRIX_ENABLE
led_matrix_init();
led_matrix_init()
#endif
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_init();
// Here
//rgb_matrix_init();
#endif
#if defined(UNICODE_COMMON_ENABLE)
unicode_input_mode_init();
unicode_input_mode_init()
#endif
#ifdef HAPTIC_ENABLE
haptic_init();
haptic_init()
#endif
}
@ -408,13 +409,13 @@ void keyboard_init(void) {
timer_init();
sync_timer_init();
#ifdef VIA_ENABLE
via_init();
//via_init();
#endif
#ifdef SPLIT_KEYBOARD
split_pre_init();
split_pre_init()
#endif
#ifdef ENCODER_ENABLE
encoder_init();
encoder_init()
#endif
matrix_init();
quantum_init();
@ -428,39 +429,39 @@ void keyboard_init(void) {
st7565_init(DISPLAY_ROTATION_0);
#endif
#ifdef PS2_MOUSE_ENABLE
ps2_mouse_init();
ps2_mouse_init()
#endif
#ifdef BACKLIGHT_ENABLE
backlight_init();
#endif
#ifdef RGBLIGHT_ENABLE
rgblight_init();
rgblight_init()
#endif
#ifdef STENO_ENABLE_ALL
steno_init();
steno_init()
#endif
#if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw);
#endif
#ifdef DIP_SWITCH_ENABLE
dip_switch_init();
dip_switch_init()
#endif
#ifdef SLEEP_LED_ENABLE
sleep_led_init();
sleep_led_init()
#endif
#ifdef VIRTSER_ENABLE
virtser_init();
#endif
#ifdef SPLIT_KEYBOARD
split_post_init();
split_post_init()
#endif
#ifdef POINTING_DEVICE_ENABLE
// init after split init
pointing_device_init();
#endif
#ifdef BLUETOOTH_ENABLE
bluetooth_init();
bluetooth_init()
#endif
#if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE)

View File

@ -35,6 +35,7 @@ struct setups_data_t {
uint8_t cnt_02;
uint8_t cnt_04;
uint8_t cnt_ff;
uint8_t cnt_zoid;
uint16_t last_wlength;
};
@ -43,20 +44,30 @@ struct setups_data_t setups_data = {
.cnt_02 = 0,
.cnt_04 = 0,
.cnt_ff = 0,
.cnt_zoid = 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) {
//if (setups_data.count < 3 && setups_data.cnt_zoid != 0) {
// return;
//}
//if (setups_data.cnt_zoid == 0) {
// detected_os = OS_UEFI;
// return;
//}
if (setups_data.cnt_zoid == 0) {
detected_os = OS_UEFI;
return;
}
if (setups_data.cnt_ff >= 2 && setups_data.cnt_04 >= 1) {
detected_os = OS_WINDOWS;
return;
}
if (setups_data.count == setups_data.cnt_ff) {
// I changed this
if (setups_data.count > 3 && setups_data.count == setups_data.cnt_ff) {
// Linux has 3 packets with 0xFF.
detected_os = OS_LINUX;
return;
@ -80,6 +91,15 @@ void make_guess(void) {
detected_os = OS_LINUX;
return;
}
if (setups_data.cnt_zoid == 0) {
detected_os = OS_UEFI;
return;
}
}
void process_zoid(const uint16_t zoid) {
setups_data.cnt_zoid = zoid;
make_guess();
}
void process_wlength(const uint16_t w_length) {
@ -99,6 +119,7 @@ void process_wlength(const uint16_t w_length) {
}
os_variant_t detected_host_os(void) {
make_guess();
return detected_os;
}

View File

@ -25,8 +25,10 @@ typedef enum {
OS_WINDOWS,
OS_MACOS,
OS_IOS,
OS_UEFI,
} os_variant_t;
void process_zoid(const uint16_t zoid);
void process_wlength(const uint16_t w_length);
os_variant_t detected_host_os(void);
void erase_wlength_data(void);

View File

@ -1177,6 +1177,9 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
if (wLength >= sizeof(USB_Descriptor_Bos_t)) {
Size = sizeof(USB_Descriptor_Bos_t);
}
#ifdef OS_DETECTION_ENABLE
process_zoid(31);
#endif
break;
case DTYPE_String: