diff --git a/docs/feature_bootmagic.md b/docs/feature_bootmagic.md index 54ebd0867a..f084052cc7 100644 --- a/docs/feature_bootmagic.md +++ b/docs/feature_bootmagic.md @@ -123,7 +123,7 @@ If you would like to change the hotkey assignments for Bootmagic, `#define` thes # Bootmagic Lite :id=bootmagic-lite -In addition to the full blown Bootmagic feature, is the Bootmagic Lite feature that only handles jumping into the bootloader. This is great for boards that don't have a physical reset button but you need a way to jump into the bootloader, and don't want to deal with the headache that Bootmagic can cause. +In addition to the full blown Bootmagic feature, is the Bootmagic Lite feature that only handles jumping into the bootloader. This is great for boards that don't have a physical reset button but you need a way to jump into the bootloader, and don't want to deal with the headache that Bootmagic can cause. To enable this version of Bootmagic, you need to enable it in your `rules.mk` with: @@ -131,7 +131,7 @@ To enable this version of Bootmagic, you need to enable it in your `rules.mk` wi BOOTMAGIC_ENABLE = lite ``` -Additionally, you may want to specify which key to use. This is especially useful for keyboards that have unusual matrices. To do so, you need to specify the row and column of the key that you want to use. Add these entries to your `config.h` file: +Additionally, you may want to specify which key to use. This is especially useful for keyboards that have unusual matrices. To do so, you need to specify the row and column of the key that you want to use. Add these entries to your `config.h` file: ```c #define BOOTMAGIC_LITE_ROW 0 @@ -144,9 +144,20 @@ And to trigger the bootloader, you hold this key down when plugging the keyboard !> Using bootmagic lite will **always reset** the EEPROM, so you will lose any settings that have been saved. +## Split Keyboards + +When handedness is predetermined via an option like `SPLIT_HAND_PIN`, you might need to configure a different key between halves. This To do so, add these entries to your `config.h` file: + +```c +#define BOOTMAGIC_LITE_ROW_RIGHT 4 +#define BOOTMAGIC_LITE_COLUMN_RIGHT 1 +``` + +By default, these values are not set. + ## Advanced Bootmagic Lite -The `bootmagic_lite` function is defined weakly, so that you can replace this in your code, if you need. A great example of this is the Zeal60 boards that have some additional handling needed. +The `bootmagic_lite` function is defined weakly, so that you can replace this in your code, if you need. A great example of this is the Zeal60 boards that have some additional handling needed. To replace the function, all you need to do is add something like this to your code: @@ -163,4 +174,4 @@ void bootmagic_lite(void) { } ``` -You can additional feature here. For instance, resetting the eeprom or requiring additional keys to be pressed to trigger bootmagic. Keep in mind that `bootmagic_lite` is called before a majority of features are initialized in the firmware. +You can additional feature here. For instance, resetting the eeprom or requiring additional keys to be pressed to trigger bootmagic. Keep in mind that `bootmagic_lite` is called before a majority of features are initialized in the firmware. diff --git a/quantum/quantum.c b/quantum/quantum.c index e06448d9e4..749a08eea9 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -581,32 +581,6 @@ void tap_random_base64(void) { } } -__attribute__((weak)) void bootmagic_lite(void) { - // The lite version of TMK's bootmagic based on Wilba. - // 100% less potential for accidentally making the - // keyboard do stupid things. - - // 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 Esc and space bar are held down on power up, - // reset the EEPROM valid state and jump to bootloader. - // Assumes Esc is at [0,0]. - // This isn't very generalized, but we need something that doesn't - // rely on user's keymaps in firmware or EEPROM. - if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) { - eeconfig_disable(); - // Jump to bootloader. - bootloader_jump(); - } -} - void matrix_init_quantum() { #ifdef BOOTMAGIC_LITE bootmagic_lite(); diff --git a/quantum/via.c b/quantum/via.c index f85af8d9e1..288299ada8 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -92,36 +92,6 @@ void via_eeprom_reset(void) { eeconfig_disable(); } -// Override bootmagic_lite() so it can flag EEPROM as invalid -// as well as jump to bootloader, thus performing a "factory reset" -// of dynamic keymaps and optionally backlight/other settings. -void bootmagic_lite(void) { - // The lite version of TMK's bootmagic based on Wilba. - // 100% less potential for accidentally making the - // keyboard do stupid things. - - // 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 Esc and space bar are held down on power up, - // reset the EEPROM valid state and jump to bootloader. - // Assumes Esc is at [0,0]. - // This isn't very generalized, but we need something that doesn't - // rely on user's keymaps in firmware or EEPROM. - if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) { - // This is the only difference from the default implementation. - via_eeprom_reset(); - // Jump to bootloader. - bootloader_jump(); - } -} - // Override this at the keyboard code level to check // VIA's EEPROM valid state and reset to defaults as needed. // Used by keyboards that store their own state in EEPROM, diff --git a/tmk_core/common.mk b/tmk_core/common.mk index b766ebe97e..3cc72a8458 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -34,6 +34,8 @@ ifneq ($(strip $(BOOTMAGIC_ENABLE)), no) endif ifeq ($(strip $(BOOTMAGIC_ENABLE)), lite) TMK_COMMON_DEFS += -DBOOTMAGIC_LITE + TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic_lite.c + TMK_COMMON_DEFS += -DMAGIC_ENABLE TMK_COMMON_SRC += $(COMMON_DIR)/magic.c else diff --git a/tmk_core/common/bootmagic_lite.c b/tmk_core/common/bootmagic_lite.c new file mode 100644 index 0000000000..53bd7b1c78 --- /dev/null +++ b/tmk_core/common/bootmagic_lite.c @@ -0,0 +1,51 @@ +#include "quantum.h" + +bool is_keyboard_left(void); + +/** \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(); + } +} \ No newline at end of file