From 21fd6d199c389f1e43f44eb6812807f74f4b1324 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 17 Jul 2023 13:03:14 +0800 Subject: [PATCH] fl16: Implement BIOS mode When enabled, overrides whatever keyboard layout and always makes the keys in the physical location of F2, F10 and F12 send the keycodes for F2/F10/F12. BIOS is supposed to enable this right after USB enumeration, so that the BIOS hot keys always work, even if FN-lock is enabled or the user has remapped their keyboard. BIOS mode is exited either by the keyboard resetting or by sending the disable message. How to send: 1. Find USB devices with Framework VID 0x32AC 2. Filter by interface number == 0x01 and usage page == 0xFF60 3. Set HID report with the following body: Enable: 0x00 0x0B 0x05 0x01 0xFE 0xFE ... pad the 32 byte buffer with 0xFE Disable: 0x00 0x0B 0x05 0x00 0xFE 0xFE ... pad the 32 byte buffer with 0xFE Where the first byte is the report ID 0x00 TODO: - [ ] Test on ANSI keyboard - [x] Test on ISO keyboard - [ ] Test on JIS keyboard - [ ] Add method to get current status Signed-off-by: Daniel Schaefer --- keyboards/framework/factory.c | 7 ++++++ keyboards/framework/framework.c | 41 +++++++++++++++++++++++++++++++++ keyboards/framework/framework.h | 2 ++ 3 files changed, 50 insertions(+) diff --git a/keyboards/framework/factory.c b/keyboards/framework/factory.c index bc6d601e26..c3f3e84b23 100644 --- a/keyboards/framework/factory.c +++ b/keyboards/framework/factory.c @@ -15,6 +15,7 @@ enum factory_commands { f_emu_keypress = 0x01, // Next byte is keycode f_serialnum = 0x04, // Read device serial number + f_bios_mode = 0x05, // Read device serial number f_bootloader = 0xFE, }; @@ -61,6 +62,12 @@ void handle_factory_command(uint8_t *data) { uprintf("Serial number unavailable\n"); #endif break; + case f_bios_mode: + if (command_data[0] == 0x01) + bios_mode = true; + else + bios_mode = false; + break; default: uprintf("Unknown factory command: %u\n", factory_command_id); break; diff --git a/keyboards/framework/framework.c b/keyboards/framework/framework.c index 1b4e123e56..f3d1616f25 100644 --- a/keyboards/framework/framework.c +++ b/keyboards/framework/framework.c @@ -59,9 +59,50 @@ void suspend_wakeup_init_kb(void) { #endif } +// 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 handle_bios_hotkeys(uint16_t keycode, keyrecord_t *record) { + // Not in bios mode, no special handling, handle as normal + if (!bios_mode) + return true; + + if (record->event.key.col == 5 && record->event.key.row == 2) { + if (record->event.pressed) { + register_code(KC_F2); + } else { + unregister_code(KC_F2); + } + return false; + } + + if (record->event.key.col == 8 && record->event.key.row == 4) { + if (record->event.pressed) { + register_code(KC_F10); + } else { + unregister_code(KC_F10); + } + return false; + } + + if (record->event.key.col == 13 && record->event.key.row == 3) { + if (record->event.pressed) { + register_code(KC_F12); + } else { + unregister_code(KC_F12); + } + return false; + } + + return true; +} + bool process_record_kb(uint16_t keycode, keyrecord_t *record) { process_record_user(keycode, record); + if (!handle_bios_hotkeys(keycode, record)) { + return false; + } + #ifdef RGB_MATRIX_ENABLE uint8_t h; uint8_t s; diff --git a/keyboards/framework/framework.h b/keyboards/framework/framework.h index 68fd53b5c1..7624af1d41 100644 --- a/keyboards/framework/framework.h +++ b/keyboards/framework/framework.h @@ -23,6 +23,8 @@ enum framework_keycodes { FN_LOCK, }; +extern bool bios_mode; + #define SLEEP_GPIO GP0 #define MUX_ENABLE_GPIO GP4 #define BOOT_DONE_GPIO GP5