Overhaul bootmagic logic to have single entrypoint (#8532)
* Relocate bootmagic logic to have single entrypoint * Align init of layer state
This commit is contained in:
parent
02dc3b6722
commit
a3cbc8a004
15 changed files with 227 additions and 153 deletions
|
@ -1,163 +0,0 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "wait.h"
|
||||
#include "matrix.h"
|
||||
#include "bootloader.h"
|
||||
#include "debug.h"
|
||||
#include "keymap.h"
|
||||
#include "host.h"
|
||||
#include "action_layer.h"
|
||||
#include "eeconfig.h"
|
||||
#include "bootmagic.h"
|
||||
|
||||
keymap_config_t keymap_config;
|
||||
|
||||
/** \brief Bootmagic
|
||||
*
|
||||
* FIXME: needs doc
|
||||
*/
|
||||
void bootmagic(void) {
|
||||
/* check signature */
|
||||
if (!eeconfig_is_enabled()) {
|
||||
eeconfig_init();
|
||||
}
|
||||
|
||||
/* do scans in case of bounce */
|
||||
print("bootmagic scan: ... ");
|
||||
uint8_t scan = 100;
|
||||
while (scan--) {
|
||||
matrix_scan();
|
||||
wait_ms(10);
|
||||
}
|
||||
print("done.\n");
|
||||
|
||||
/* bootmagic skip */
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* eeconfig clear */
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
|
||||
eeconfig_init();
|
||||
}
|
||||
|
||||
/* bootloader */
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
|
||||
bootloader_jump();
|
||||
}
|
||||
|
||||
/* debug enable */
|
||||
debug_config.raw = eeconfig_read_debug();
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
|
||||
debug_config.matrix = !debug_config.matrix;
|
||||
} else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
|
||||
debug_config.keyboard = !debug_config.keyboard;
|
||||
} else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
|
||||
debug_config.mouse = !debug_config.mouse;
|
||||
} else {
|
||||
debug_config.enable = !debug_config.enable;
|
||||
}
|
||||
}
|
||||
eeconfig_update_debug(debug_config.raw);
|
||||
|
||||
/* keymap config */
|
||||
keymap_config.raw = eeconfig_read_keymap();
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
|
||||
keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
|
||||
keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
|
||||
keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
|
||||
keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
|
||||
keymap_config.no_gui = !keymap_config.no_gui;
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
|
||||
keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
|
||||
keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) {
|
||||
keymap_config.nkro = !keymap_config.nkro;
|
||||
}
|
||||
eeconfig_update_keymap(keymap_config.raw);
|
||||
|
||||
/* default layer */
|
||||
uint8_t default_layer = 0;
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) {
|
||||
default_layer |= (1 << 0);
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
|
||||
default_layer |= (1 << 1);
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
|
||||
default_layer |= (1 << 2);
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) {
|
||||
default_layer |= (1 << 3);
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) {
|
||||
default_layer |= (1 << 4);
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) {
|
||||
default_layer |= (1 << 5);
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) {
|
||||
default_layer |= (1 << 6);
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) {
|
||||
default_layer |= (1 << 7);
|
||||
}
|
||||
if (default_layer) {
|
||||
eeconfig_update_default_layer(default_layer);
|
||||
default_layer_set((layer_state_t)default_layer);
|
||||
} else {
|
||||
default_layer = eeconfig_read_default_layer();
|
||||
default_layer_set((layer_state_t)default_layer);
|
||||
}
|
||||
/* Also initialize layer state to trigger callback functions for layer_state */
|
||||
layer_state_set_kb((layer_state_t)layer_state);
|
||||
|
||||
/* EE_HANDS handedness */
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) {
|
||||
eeconfig_update_handedness(true);
|
||||
}
|
||||
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) {
|
||||
eeconfig_update_handedness(false);
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief Scan Keycode
|
||||
*
|
||||
* FIXME: needs doc
|
||||
*/
|
||||
static bool scan_keycode(uint8_t keycode) {
|
||||
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
|
||||
matrix_row_t matrix_row = matrix_get_row(r);
|
||||
for (uint8_t c = 0; c < MATRIX_COLS; c++) {
|
||||
if (matrix_row & ((matrix_row_t)1 << c)) {
|
||||
if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** \brief Bootmagic Scan Keycode
|
||||
*
|
||||
* FIXME: needs doc
|
||||
*/
|
||||
bool bootmagic_scan_keycode(uint8_t keycode) {
|
||||
if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
|
||||
|
||||
return scan_keycode(keycode);
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
/* FIXME: Add special doxygen comments for defines here. */
|
||||
|
||||
/* bootmagic salt key */
|
||||
#ifndef BOOTMAGIC_KEY_SALT
|
||||
# define BOOTMAGIC_KEY_SALT KC_SPACE
|
||||
#endif
|
||||
|
||||
/* skip bootmagic and eeconfig */
|
||||
#ifndef BOOTMAGIC_KEY_SKIP
|
||||
# define BOOTMAGIC_KEY_SKIP KC_ESC
|
||||
#endif
|
||||
|
||||
/* eeprom clear */
|
||||
#ifndef BOOTMAGIC_KEY_EEPROM_CLEAR
|
||||
# define BOOTMAGIC_KEY_EEPROM_CLEAR KC_BSPACE
|
||||
#endif
|
||||
|
||||
/* kick up bootloader */
|
||||
#ifndef BOOTMAGIC_KEY_BOOTLOADER
|
||||
# define BOOTMAGIC_KEY_BOOTLOADER KC_B
|
||||
#endif
|
||||
|
||||
/* debug enable */
|
||||
#ifndef BOOTMAGIC_KEY_DEBUG_ENABLE
|
||||
# define BOOTMAGIC_KEY_DEBUG_ENABLE KC_D
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEBUG_MATRIX
|
||||
# define BOOTMAGIC_KEY_DEBUG_MATRIX KC_X
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEBUG_KEYBOARD
|
||||
# define BOOTMAGIC_KEY_DEBUG_KEYBOARD KC_K
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEBUG_MOUSE
|
||||
# define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_EE_HANDS_LEFT
|
||||
# define BOOTMAGIC_KEY_EE_HANDS_LEFT KC_L
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_EE_HANDS_RIGHT
|
||||
# define BOOTMAGIC_KEY_EE_HANDS_RIGHT KC_R
|
||||
#endif
|
||||
|
||||
/*
|
||||
* keymap config
|
||||
*/
|
||||
#ifndef BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK
|
||||
# define BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK KC_LCTRL
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL
|
||||
# define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL KC_CAPSLOCK
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_SWAP_LALT_LGUI
|
||||
# define BOOTMAGIC_KEY_SWAP_LALT_LGUI KC_LALT
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_SWAP_RALT_RGUI
|
||||
# define BOOTMAGIC_KEY_SWAP_RALT_RGUI KC_RALT
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_NO_GUI
|
||||
# define BOOTMAGIC_KEY_NO_GUI KC_LGUI
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_SWAP_GRAVE_ESC
|
||||
# define BOOTMAGIC_KEY_SWAP_GRAVE_ESC KC_GRAVE
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE
|
||||
# define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_HOST_NKRO
|
||||
# define BOOTMAGIC_HOST_NKRO KC_N
|
||||
#endif
|
||||
|
||||
/*
|
||||
* change default layer
|
||||
*/
|
||||
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_0
|
||||
# define BOOTMAGIC_KEY_DEFAULT_LAYER_0 KC_0
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_1
|
||||
# define BOOTMAGIC_KEY_DEFAULT_LAYER_1 KC_1
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_2
|
||||
# define BOOTMAGIC_KEY_DEFAULT_LAYER_2 KC_2
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_3
|
||||
# define BOOTMAGIC_KEY_DEFAULT_LAYER_3 KC_3
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_4
|
||||
# define BOOTMAGIC_KEY_DEFAULT_LAYER_4 KC_4
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_5
|
||||
# define BOOTMAGIC_KEY_DEFAULT_LAYER_5 KC_5
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_6
|
||||
# define BOOTMAGIC_KEY_DEFAULT_LAYER_6 KC_6
|
||||
#endif
|
||||
#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7
|
||||
# define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7
|
||||
#endif
|
||||
|
||||
void bootmagic(void);
|
||||
bool bootmagic_scan_keycode(uint8_t keycode);
|
|
@ -1,49 +0,0 @@
|
|||
#include "quantum.h"
|
||||
|
||||
/** \brief Reset eeprom
|
||||
*
|
||||
* ...just incase someone wants to only change the eeprom behaviour
|
||||
*/
|
||||
__attribute__((weak)) void bootmagic_lite_reset_eeprom(void) {
|
||||
#if defined(VIA_ENABLE)
|
||||
via_eeprom_reset();
|
||||
#else
|
||||
eeconfig_disable();
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \brief The lite version of TMK's bootmagic based on Wilba.
|
||||
*
|
||||
* 100% less potential for accidentally making the keyboard do stupid things.
|
||||
*/
|
||||
__attribute__((weak)) void bootmagic_lite(void) {
|
||||
// We need multiple scans because debouncing can't be turned off.
|
||||
matrix_scan();
|
||||
#if defined(DEBOUNCE) && DEBOUNCE > 0
|
||||
wait_ms(DEBOUNCE * 2);
|
||||
#else
|
||||
wait_ms(30);
|
||||
#endif
|
||||
matrix_scan();
|
||||
|
||||
// If the configured key (commonly Esc) is held down on power up,
|
||||
// reset the EEPROM valid state and jump to bootloader.
|
||||
// This isn't very generalized, but we need something that doesn't
|
||||
// rely on user's keymaps in firmware or EEPROM.
|
||||
uint8_t row = BOOTMAGIC_LITE_ROW;
|
||||
uint8_t col = BOOTMAGIC_LITE_COLUMN;
|
||||
|
||||
#if defined(SPLIT_KEYBOARD) && defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT)
|
||||
if (!is_keyboard_left()) {
|
||||
row = BOOTMAGIC_LITE_ROW_RIGHT;
|
||||
col = BOOTMAGIC_LITE_COLUMN_RIGHT;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (matrix_get_row(row) & (1 << col)) {
|
||||
bootmagic_lite_reset_eeprom();
|
||||
|
||||
// Jump to bootloader.
|
||||
bootloader_jump();
|
||||
}
|
||||
}
|
|
@ -34,11 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#ifdef BACKLIGHT_ENABLE
|
||||
# include "backlight.h"
|
||||
#endif
|
||||
#ifdef BOOTMAGIC_ENABLE
|
||||
# include "bootmagic.h"
|
||||
#else
|
||||
# include "magic.h"
|
||||
#endif
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
# include "mousekey.h"
|
||||
#endif
|
||||
|
@ -296,11 +291,6 @@ void keyboard_init(void) {
|
|||
#ifdef ADB_MOUSE_ENABLE
|
||||
adb_mouse_init();
|
||||
#endif
|
||||
#ifdef BOOTMAGIC_ENABLE
|
||||
bootmagic();
|
||||
#else
|
||||
magic();
|
||||
#endif
|
||||
#ifdef BACKLIGHT_ENABLE
|
||||
backlight_init();
|
||||
#endif
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#if defined(__AVR__)
|
||||
# include <util/delay.h>
|
||||
#endif
|
||||
#include "matrix.h"
|
||||
#include "bootloader.h"
|
||||
#include "debug.h"
|
||||
#include "keymap.h"
|
||||
#include "host.h"
|
||||
#include "action_layer.h"
|
||||
#include "eeconfig.h"
|
||||
#include "magic.h"
|
||||
|
||||
keymap_config_t keymap_config;
|
||||
|
||||
/** \brief Magic
|
||||
*
|
||||
* FIXME: Needs doc
|
||||
*/
|
||||
void magic(void) {
|
||||
/* check signature */
|
||||
if (!eeconfig_is_enabled()) {
|
||||
eeconfig_init();
|
||||
}
|
||||
|
||||
/* debug enable */
|
||||
debug_config.raw = eeconfig_read_debug();
|
||||
|
||||
/* keymap config */
|
||||
keymap_config.raw = eeconfig_read_keymap();
|
||||
|
||||
uint8_t default_layer = 0;
|
||||
default_layer = eeconfig_read_default_layer();
|
||||
default_layer_set((layer_state_t)default_layer);
|
||||
|
||||
/* Also initialize layer state to trigger callback functions for layer_state */
|
||||
layer_state_set_kb((layer_state_t)layer_state);
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
void magic(void);
|
Loading…
Add table
Add a link
Reference in a new issue