]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Add Bootmagic Lite to QMK (#4215)
authorDrashna Jaelre <drashna@live.com>
Sat, 27 Oct 2018 18:53:50 +0000 (11:53 -0700)
committerJack Humbert <jack.humb@gmail.com>
Sat, 27 Oct 2018 18:53:50 +0000 (14:53 -0400)
* 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

docs/feature_bootmagic.md
quantum/quantum.c
quantum/quantum.h
quantum/template/avr/config.h
quantum/template/ps2avrgb/config.h
tmk_core/common.mk
users/drashna/drashna.c

index 586b5d837082fba8d98ecf05ed0a03bb71751262..20c76d9b745d35791135673af1c6cba78acc1328 100644 (file)
@@ -11,7 +11,15 @@ There are three separate but related features that allow you to change the behav
 On some keyboards Bootmagic is disabled by default. If this is the case, it must be explicitly enabled in your `rules.mk` with:
 
 ```make
-BOOTMAGIC_ENABLE = yes
+BOOTMAGIC_ENABLE = full
+```
+
+?> 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.
+
+Additionally, you can use [Bootmagic Lite](#bootmagic-lite) (a scaled down, very basic version of Bootmagic) by adding the following to your `rules.mk` file:
+
+```make
+BOOTMAGIC_ENABLE = lite
 ```
 
 ## Hotkeys
@@ -99,3 +107,45 @@ If you would like to change the hotkey assignments for Bootmagic, `#define` thes
 |`BOOTMAGIC_KEY_DEFAULT_LAYER_5`         |`KC_5`       |Make layer 5 the default layer                     |
 |`BOOTMAGIC_KEY_DEFAULT_LAYER_6`         |`KC_6`       |Make layer 6 the default layer                     |
 |`BOOTMAGIC_KEY_DEFAULT_LAYER_7`         |`KC_7`       |Make layer 7 the default layer                     |
+
+# 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.
+
+To enable this version of Bootmagic, you need to enable it in your `rules.mk` with:
+
+```make
+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:
+
+```c
+#define BOOTMAGIC_LITE_ROW 0
+#define BOOTMAGIC_LITE_COLUMN 1
+```
+
+By default, these are set to 0 and 0, which is usually the "ESC" key on a majority of keyboards.
+
+And to trigger the bootloader, you hold this key down when plugging the keyboard in. Just the single key. 
+
+## 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.
+
+To replace the function, all you need to do is add something like this to your code:
+
+```c
+void bootmagic_lite(void) {
+    matrix_scan();
+    wait_ms(DEBOUNCING_DELAY * 2);
+    matrix_scan();
+
+    if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
+      // Jump to bootloader.
+      bootloader_jump();
+    }
+}
+```
+
+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.
index c9bec6740baaaafc893b98d2b97c67da7e1d4be3..5f1a691c88413d69d4c62193ad67fe8607e07208 100644 (file)
@@ -949,8 +949,40 @@ 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(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
+    wait_ms(DEBOUNCING_DELAY * 2);
+  #elif 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() {
-  if (!eeconfig_is_enabled() && !eeconfig_is_disabled()) {
+  #ifdef BOOTMAGIC_LITE
+    bootmagic_lite();
+  #endif
+  if (!eeconfig_is_enabled()) {
     eeconfig_init();
   }
   #ifdef BACKLIGHT_ENABLE
index 87a61356c7dcaef83f7938cf9c92203c1c78dd38..1d3ee033fd09543fd6c7655eb606e175de3c1ee1 100644 (file)
@@ -224,6 +224,15 @@ bool process_action_kb(keyrecord_t *record);
 bool process_record_kb(uint16_t keycode, keyrecord_t *record);
 bool process_record_user(uint16_t keycode, keyrecord_t *record);
 
+#ifndef BOOTMAGIC_LITE_COLUMN
+  #define BOOTMAGIC_LITE_COLUMN 0
+#endif
+#ifndef BOOTMAGIC_LITE_ROW
+  #define BOOTMAGIC_LITE_ROW 0
+#endif
+
+void bootmagic_lite(void);
+
 void reset_keyboard(void);
 
 void startup_user(void);
index caa72af0c2f8960bd503e2e6a00d64d58a230ccb..56395f376f65f1fac494c71a79e25083deec1b31 100644 (file)
@@ -222,3 +222,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #endif
 */
 
+/* Bootmagic Lite key configuration */
+// #define BOOTMAGIC_LITE_ROW 0
+// #define BOOTMAGIC_LITE_COLUMN 0
index d2c83781fafb075751e52373d217b1a9688a4604..4ff3513bc76aa84f3fe37b06c4422df6cc1d7c8c 100644 (file)
@@ -44,3 +44,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /* key combination for command */
 #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))
+
+/* Bootmagic Lite key configuration */
+// #define BOOTMAGIC_LITE_ROW 0
+// #define BOOTMAGIC_LITE_COLUMN 0
index 33bcc97b2ed131768df7e49b6d202cc561a95359..3844b13d48db2f0a6402c5900b05d9ea522011c6 100644 (file)
@@ -61,14 +61,26 @@ endif
 
 
 # Option modules
-ifeq ($(strip $(BOOTMAGIC_ENABLE)), yes)
+BOOTMAGIC_ENABLE ?= no
+VALID_MAGIC_TYPES := yes full lite
+ifneq ($(strip $(BOOTMAGIC_ENABLE)), no)
+  ifeq ($(filter $(BOOTMAGIC_ENABLE),$(VALID_MAGIC_TYPES)),)
+    $(error BOOTMAGIC_ENABLE="$(BOOTMAGIC_ENABLE)" is not a valid type of magic)
+  endif
+  ifeq ($(strip $(BOOTMAGIC_ENABLE)), lite)
+      TMK_COMMON_DEFS += -DBOOTMAGIC_LITE
+      TMK_COMMON_DEFS += -DMAGIC_ENABLE
+      TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
+  else
     TMK_COMMON_DEFS += -DBOOTMAGIC_ENABLE
     TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic.c
+  endif
 else
     TMK_COMMON_DEFS += -DMAGIC_ENABLE
     TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
 endif
 
+
 ifeq ($(strip $(MOUSEKEY_ENABLE)), yes)
     TMK_COMMON_SRC += $(COMMON_DIR)/mousekey.c
     TMK_COMMON_DEFS += -DMOUSEKEY_ENABLE
index 5b6620cf33d6a9db2dc6d1b903a42dfdac92b1bc..7c280e2dddc4c5f358624452c0bdf095838353c6 100644 (file)
@@ -424,3 +424,19 @@ void eeconfig_init_user(void) {
   userspace_config.raw = 0;
   eeconfig_update_user(userspace_config.raw);
 }
+
+void bootmagic_lite(void) {
+  matrix_scan();
+  #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
+    wait_ms(DEBOUNCING_DELAY * 2);
+  #elif defined(DEBOUNCE) && DEBOUNCE > 0
+    wait_ms(DEBOUNCE * 2);
+  #else
+    wait_ms(30);
+  #endif
+  matrix_scan();
+
+  if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
+    bootloader_jump();
+  }
+}