aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2020-03-21 23:10:39 +0000
committerGitHub <noreply@github.com>2020-03-21 23:10:39 +0000
commit789e19945038c3b98d6e80bc29166d493a8b1056 (patch)
treed3d5159d9390365a2374d72cf61bd9c7ecd37ae0
parenta747c1c3dee728f5124a8effb8f52819f643de5f (diff)
downloadqmk_firmware-789e19945038c3b98d6e80bc29166d493a8b1056.tar.gz
qmk_firmware-789e19945038c3b98d6e80bc29166d493a8b1056.zip
Add support for Bootmagic lite when using SPLIT_HAND_PIN (#8347)
* Add support for Bootmagic lite when using SPLIT_HAND_PIN * Deduplicate bootmagic_lite logic from within via * Revert location of defaults so that user overrides still work for now * Tidy up code slightly
-rw-r--r--docs/feature_bootmagic.md19
-rw-r--r--quantum/quantum.c26
-rw-r--r--quantum/via.c30
-rw-r--r--tmk_core/common.mk2
-rw-r--r--tmk_core/common/bootmagic_lite.c51
5 files changed, 68 insertions, 60 deletions
diff --git a/docs/feature_bootmagic.md b/docs/feature_bootmagic.md
index 54ebd0867..f084052cc 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
123 123
124# Bootmagic Lite :id=bootmagic-lite 124# Bootmagic Lite :id=bootmagic-lite
125 125
126In 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. 126In 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.
127 127
128To enable this version of Bootmagic, you need to enable it in your `rules.mk` with: 128To enable this version of Bootmagic, you need to enable it in your `rules.mk` with:
129 129
@@ -131,7 +131,7 @@ To enable this version of Bootmagic, you need to enable it in your `rules.mk` wi
131BOOTMAGIC_ENABLE = lite 131BOOTMAGIC_ENABLE = lite
132``` 132```
133 133
134Additionally, 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: 134Additionally, 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:
135 135
136```c 136```c
137#define BOOTMAGIC_LITE_ROW 0 137#define BOOTMAGIC_LITE_ROW 0
@@ -144,9 +144,20 @@ And to trigger the bootloader, you hold this key down when plugging the keyboard
144 144
145!> Using bootmagic lite will **always reset** the EEPROM, so you will lose any settings that have been saved. 145!> Using bootmagic lite will **always reset** the EEPROM, so you will lose any settings that have been saved.
146 146
147## Split Keyboards
148
149When 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:
150
151```c
152#define BOOTMAGIC_LITE_ROW_RIGHT 4
153#define BOOTMAGIC_LITE_COLUMN_RIGHT 1
154```
155
156By default, these values are not set.
157
147## Advanced Bootmagic Lite 158## Advanced Bootmagic Lite
148 159
149The `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. 160The `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.
150 161
151To replace the function, all you need to do is add something like this to your code: 162To replace the function, all you need to do is add something like this to your code:
152 163
@@ -163,4 +174,4 @@ void bootmagic_lite(void) {
163} 174}
164``` 175```
165 176
166You 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. 177You 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 e06448d9e..749a08eea 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -581,32 +581,6 @@ void tap_random_base64(void) {
581 } 581 }
582} 582}
583 583
584__attribute__((weak)) void bootmagic_lite(void) {
585 // The lite version of TMK's bootmagic based on Wilba.
586 // 100% less potential for accidentally making the
587 // keyboard do stupid things.
588
589 // We need multiple scans because debouncing can't be turned off.
590 matrix_scan();
591#if defined(DEBOUNCE) && DEBOUNCE > 0
592 wait_ms(DEBOUNCE * 2);
593#else
594 wait_ms(30);
595#endif
596 matrix_scan();
597
598 // If the Esc and space bar are held down on power up,
599 // reset the EEPROM valid state and jump to bootloader.
600 // Assumes Esc is at [0,0].
601 // This isn't very generalized, but we need something that doesn't
602 // rely on user's keymaps in firmware or EEPROM.
603 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
604 eeconfig_disable();
605 // Jump to bootloader.
606 bootloader_jump();
607 }
608}
609
610void matrix_init_quantum() { 584void matrix_init_quantum() {
611#ifdef BOOTMAGIC_LITE 585#ifdef BOOTMAGIC_LITE
612 bootmagic_lite(); 586 bootmagic_lite();
diff --git a/quantum/via.c b/quantum/via.c
index f85af8d9e..288299ada 100644
--- a/quantum/via.c
+++ b/quantum/via.c
@@ -92,36 +92,6 @@ void via_eeprom_reset(void) {
92 eeconfig_disable(); 92 eeconfig_disable();
93} 93}
94 94
95// Override bootmagic_lite() so it can flag EEPROM as invalid
96// as well as jump to bootloader, thus performing a "factory reset"
97// of dynamic keymaps and optionally backlight/other settings.
98void bootmagic_lite(void) {
99 // The lite version of TMK's bootmagic based on Wilba.
100 // 100% less potential for accidentally making the
101 // keyboard do stupid things.
102
103 // We need multiple scans because debouncing can't be turned off.
104 matrix_scan();
105#if defined(DEBOUNCE) && DEBOUNCE > 0
106 wait_ms(DEBOUNCE * 2);
107#else
108 wait_ms(30);
109#endif
110 matrix_scan();
111
112 // If the Esc and space bar are held down on power up,
113 // reset the EEPROM valid state and jump to bootloader.
114 // Assumes Esc is at [0,0].
115 // This isn't very generalized, but we need something that doesn't
116 // rely on user's keymaps in firmware or EEPROM.
117 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
118 // This is the only difference from the default implementation.
119 via_eeprom_reset();
120 // Jump to bootloader.
121 bootloader_jump();
122 }
123}
124
125// Override this at the keyboard code level to check 95// Override this at the keyboard code level to check
126// VIA's EEPROM valid state and reset to defaults as needed. 96// VIA's EEPROM valid state and reset to defaults as needed.
127// Used by keyboards that store their own state in EEPROM, 97// Used by keyboards that store their own state in EEPROM,
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index b766ebe97..3cc72a845 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -34,6 +34,8 @@ ifneq ($(strip $(BOOTMAGIC_ENABLE)), no)
34 endif 34 endif
35 ifeq ($(strip $(BOOTMAGIC_ENABLE)), lite) 35 ifeq ($(strip $(BOOTMAGIC_ENABLE)), lite)
36 TMK_COMMON_DEFS += -DBOOTMAGIC_LITE 36 TMK_COMMON_DEFS += -DBOOTMAGIC_LITE
37 TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic_lite.c
38
37 TMK_COMMON_DEFS += -DMAGIC_ENABLE 39 TMK_COMMON_DEFS += -DMAGIC_ENABLE
38 TMK_COMMON_SRC += $(COMMON_DIR)/magic.c 40 TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
39 else 41 else
diff --git a/tmk_core/common/bootmagic_lite.c b/tmk_core/common/bootmagic_lite.c
new file mode 100644
index 000000000..53bd7b1c7
--- /dev/null
+++ b/tmk_core/common/bootmagic_lite.c
@@ -0,0 +1,51 @@
1#include "quantum.h"
2
3bool is_keyboard_left(void);
4
5/** \brief Reset eeprom
6 *
7 * ...just incase someone wants to only change the eeprom behaviour
8 */
9__attribute__((weak)) void bootmagic_lite_reset_eeprom(void) {
10#if defined(VIA_ENABLE)
11 via_eeprom_reset();
12#else
13 eeconfig_disable();
14#endif
15}
16
17/** \brief The lite version of TMK's bootmagic based on Wilba.
18 *
19 * 100% less potential for accidentally making the keyboard do stupid things.
20 */
21__attribute__((weak)) void bootmagic_lite(void) {
22 // We need multiple scans because debouncing can't be turned off.
23 matrix_scan();
24#if defined(DEBOUNCE) && DEBOUNCE > 0
25 wait_ms(DEBOUNCE * 2);
26#else
27 wait_ms(30);
28#endif
29 matrix_scan();
30
31 // If the configured key (commonly Esc) is held down on power up,
32 // reset the EEPROM valid state and jump to bootloader.
33 // This isn't very generalized, but we need something that doesn't
34 // rely on user's keymaps in firmware or EEPROM.
35 uint8_t row = BOOTMAGIC_LITE_ROW;
36 uint8_t col = BOOTMAGIC_LITE_COLUMN;
37
38#if defined(SPLIT_KEYBOARD) && defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT)
39 if (!is_keyboard_left()) {
40 row = BOOTMAGIC_LITE_ROW_RIGHT;
41 col = BOOTMAGIC_LITE_COLUMN_RIGHT;
42 }
43#endif
44
45 if (matrix_get_row(row) & (1 << col)) {
46 bootmagic_lite_reset_eeprom();
47
48 // Jump to bootloader.
49 bootloader_jump();
50 }
51} \ No newline at end of file