aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-10-27 11:53:50 -0700
committerJack Humbert <jack.humb@gmail.com>2018-10-27 14:53:50 -0400
commit4ffcacd92086870eb7a3102d54178a7af64edb0c (patch)
treeb30479a70abc0d0dcd6c287383eb64e8f2fee104
parent5be438f03d0ae3ebdb9e24d249fdfd7f5c573634 (diff)
downloadqmk_firmware-4ffcacd92086870eb7a3102d54178a7af64edb0c.tar.gz
qmk_firmware-4ffcacd92086870eb7a3102d54178a7af64edb0c.zip
Add Bootmagic Lite to QMK (#4215)
* Preliminary additon of bootmagic lite functionality * Cleanup code * Clean up bootmagic code * Add documentation and clean up code * Make 'lite' an option for BOOTMAGIC_ENABLE * Update Templates with note about Bootmagic Lite option * Detect Debounce variable * Make sure debounce is a non-zero number * Capitalize Bootmagic * Capitalize bootmagic * Update wording * Re-add EEPROM reset, by popular demand And add eeprom-less version to drashna userspace for his sanity * Fix spacing * Set BOOTMAGIC_ENABLE to use full/lite/off And default yes to "full" for compatibility * Add Bootmagic lite info to templates * Remove text from makefiles * Cleanup of makefile * mention yes in bootmagic docs * Wordsmitthing the docs * Fix white spaces * Readd default bootmagic setting, because it's necessary
-rw-r--r--docs/feature_bootmagic.md52
-rw-r--r--quantum/quantum.c34
-rw-r--r--quantum/quantum.h9
-rw-r--r--quantum/template/avr/config.h3
-rw-r--r--quantum/template/ps2avrgb/config.h4
-rw-r--r--tmk_core/common.mk14
-rw-r--r--users/drashna/drashna.c16
7 files changed, 129 insertions, 3 deletions
diff --git a/docs/feature_bootmagic.md b/docs/feature_bootmagic.md
index 586b5d837..20c76d9b7 100644
--- a/docs/feature_bootmagic.md
+++ b/docs/feature_bootmagic.md
@@ -11,7 +11,15 @@ There are three separate but related features that allow you to change the behav
11On some keyboards Bootmagic is disabled by default. If this is the case, it must be explicitly enabled in your `rules.mk` with: 11On some keyboards Bootmagic is disabled by default. If this is the case, it must be explicitly enabled in your `rules.mk` with:
12 12
13```make 13```make
14BOOTMAGIC_ENABLE = yes 14BOOTMAGIC_ENABLE = full
15```
16
17?> You may see `yes` being used in place of `full`, and this is okay. However, `yes` is deprecated, and ideally `full` (or `lite`) ideally should be used instead.
18
19Additionally, you can use [Bootmagic Lite](#bootmagic-lite) (a scaled down, very basic version of Bootmagic) by adding the following to your `rules.mk` file:
20
21```make
22BOOTMAGIC_ENABLE = lite
15``` 23```
16 24
17## Hotkeys 25## Hotkeys
@@ -99,3 +107,45 @@ If you would like to change the hotkey assignments for Bootmagic, `#define` thes
99|`BOOTMAGIC_KEY_DEFAULT_LAYER_5` |`KC_5` |Make layer 5 the default layer | 107|`BOOTMAGIC_KEY_DEFAULT_LAYER_5` |`KC_5` |Make layer 5 the default layer |
100|`BOOTMAGIC_KEY_DEFAULT_LAYER_6` |`KC_6` |Make layer 6 the default layer | 108|`BOOTMAGIC_KEY_DEFAULT_LAYER_6` |`KC_6` |Make layer 6 the default layer |
101|`BOOTMAGIC_KEY_DEFAULT_LAYER_7` |`KC_7` |Make layer 7 the default layer | 109|`BOOTMAGIC_KEY_DEFAULT_LAYER_7` |`KC_7` |Make layer 7 the default layer |
110
111# Bootmagic Lite
112
113In 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.
114
115To enable this version of Bootmagic, you need to enable it in your `rules.mk` with:
116
117```make
118BOOTMAGIC_ENABLE = lite
119```
120
121Additionally, 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:
122
123```c
124#define BOOTMAGIC_LITE_ROW 0
125#define BOOTMAGIC_LITE_COLUMN 1
126```
127
128By default, these are set to 0 and 0, which is usually the "ESC" key on a majority of keyboards.
129
130And to trigger the bootloader, you hold this key down when plugging the keyboard in. Just the single key.
131
132## Advanced Bootmagic Lite
133
134The `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.
135
136To replace the function, all you need to do is add something like this to your code:
137
138```c
139void bootmagic_lite(void) {
140 matrix_scan();
141 wait_ms(DEBOUNCING_DELAY * 2);
142 matrix_scan();
143
144 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
145 // Jump to bootloader.
146 bootloader_jump();
147 }
148}
149```
150
151You 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 c9bec6740..5f1a691c8 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -949,8 +949,40 @@ void tap_random_base64(void) {
949 } 949 }
950} 950}
951 951
952__attribute__((weak))
953void bootmagic_lite(void) {
954 // The lite version of TMK's bootmagic based on Wilba.
955 // 100% less potential for accidentally making the
956 // keyboard do stupid things.
957
958 // We need multiple scans because debouncing can't be turned off.
959 matrix_scan();
960 #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
961 wait_ms(DEBOUNCING_DELAY * 2);
962 #elif defined(DEBOUNCE) && DEBOUNCE > 0
963 wait_ms(DEBOUNCE * 2);
964 #else
965 wait_ms(30);
966 #endif
967 matrix_scan();
968
969 // If the Esc and space bar are held down on power up,
970 // reset the EEPROM valid state and jump to bootloader.
971 // Assumes Esc is at [0,0].
972 // This isn't very generalized, but we need something that doesn't
973 // rely on user's keymaps in firmware or EEPROM.
974 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
975 eeconfig_disable();
976 // Jump to bootloader.
977 bootloader_jump();
978 }
979}
980
952void matrix_init_quantum() { 981void matrix_init_quantum() {
953 if (!eeconfig_is_enabled() && !eeconfig_is_disabled()) { 982 #ifdef BOOTMAGIC_LITE
983 bootmagic_lite();
984 #endif
985 if (!eeconfig_is_enabled()) {
954 eeconfig_init(); 986 eeconfig_init();
955 } 987 }
956 #ifdef BACKLIGHT_ENABLE 988 #ifdef BACKLIGHT_ENABLE
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 87a61356c..1d3ee033f 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -224,6 +224,15 @@ bool process_action_kb(keyrecord_t *record);
224bool process_record_kb(uint16_t keycode, keyrecord_t *record); 224bool process_record_kb(uint16_t keycode, keyrecord_t *record);
225bool process_record_user(uint16_t keycode, keyrecord_t *record); 225bool process_record_user(uint16_t keycode, keyrecord_t *record);
226 226
227#ifndef BOOTMAGIC_LITE_COLUMN
228 #define BOOTMAGIC_LITE_COLUMN 0
229#endif
230#ifndef BOOTMAGIC_LITE_ROW
231 #define BOOTMAGIC_LITE_ROW 0
232#endif
233
234void bootmagic_lite(void);
235
227void reset_keyboard(void); 236void reset_keyboard(void);
228 237
229void startup_user(void); 238void startup_user(void);
diff --git a/quantum/template/avr/config.h b/quantum/template/avr/config.h
index caa72af0c..56395f376 100644
--- a/quantum/template/avr/config.h
+++ b/quantum/template/avr/config.h
@@ -222,3 +222,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
222#endif 222#endif
223*/ 223*/
224 224
225/* Bootmagic Lite key configuration */
226// #define BOOTMAGIC_LITE_ROW 0
227// #define BOOTMAGIC_LITE_COLUMN 0
diff --git a/quantum/template/ps2avrgb/config.h b/quantum/template/ps2avrgb/config.h
index d2c83781f..4ff3513bc 100644
--- a/quantum/template/ps2avrgb/config.h
+++ b/quantum/template/ps2avrgb/config.h
@@ -44,3 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
44 44
45/* key combination for command */ 45/* key combination for command */
46#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) 46#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))
47
48/* Bootmagic Lite key configuration */
49// #define BOOTMAGIC_LITE_ROW 0
50// #define BOOTMAGIC_LITE_COLUMN 0
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 33bcc97b2..3844b13d4 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -61,14 +61,26 @@ endif
61 61
62 62
63# Option modules 63# Option modules
64ifeq ($(strip $(BOOTMAGIC_ENABLE)), yes) 64BOOTMAGIC_ENABLE ?= no
65VALID_MAGIC_TYPES := yes full lite
66ifneq ($(strip $(BOOTMAGIC_ENABLE)), no)
67 ifeq ($(filter $(BOOTMAGIC_ENABLE),$(VALID_MAGIC_TYPES)),)
68 $(error BOOTMAGIC_ENABLE="$(BOOTMAGIC_ENABLE)" is not a valid type of magic)
69 endif
70 ifeq ($(strip $(BOOTMAGIC_ENABLE)), lite)
71 TMK_COMMON_DEFS += -DBOOTMAGIC_LITE
72 TMK_COMMON_DEFS += -DMAGIC_ENABLE
73 TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
74 else
65 TMK_COMMON_DEFS += -DBOOTMAGIC_ENABLE 75 TMK_COMMON_DEFS += -DBOOTMAGIC_ENABLE
66 TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic.c 76 TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic.c
77 endif
67else 78else
68 TMK_COMMON_DEFS += -DMAGIC_ENABLE 79 TMK_COMMON_DEFS += -DMAGIC_ENABLE
69 TMK_COMMON_SRC += $(COMMON_DIR)/magic.c 80 TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
70endif 81endif
71 82
83
72ifeq ($(strip $(MOUSEKEY_ENABLE)), yes) 84ifeq ($(strip $(MOUSEKEY_ENABLE)), yes)
73 TMK_COMMON_SRC += $(COMMON_DIR)/mousekey.c 85 TMK_COMMON_SRC += $(COMMON_DIR)/mousekey.c
74 TMK_COMMON_DEFS += -DMOUSEKEY_ENABLE 86 TMK_COMMON_DEFS += -DMOUSEKEY_ENABLE
diff --git a/users/drashna/drashna.c b/users/drashna/drashna.c
index 5b6620cf3..7c280e2dd 100644
--- a/users/drashna/drashna.c
+++ b/users/drashna/drashna.c
@@ -424,3 +424,19 @@ void eeconfig_init_user(void) {
424 userspace_config.raw = 0; 424 userspace_config.raw = 0;
425 eeconfig_update_user(userspace_config.raw); 425 eeconfig_update_user(userspace_config.raw);
426} 426}
427
428void bootmagic_lite(void) {
429 matrix_scan();
430 #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
431 wait_ms(DEBOUNCING_DELAY * 2);
432 #elif defined(DEBOUNCE) && DEBOUNCE > 0
433 wait_ms(DEBOUNCE * 2);
434 #else
435 wait_ms(30);
436 #endif
437 matrix_scan();
438
439 if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
440 bootloader_jump();
441 }
442}