Browse Source

[Docs] Update the KC_MAKE example in Userspace docs (#5337)

This includes a much more feature rich version of the code, as well as updating for changes that have occurred in QMK Firmware
pjones-keymap
Drashna Jaelre 4 months ago
parent
commit
3d446c6050
1 changed files with 39 additions and 15 deletions
  1. 39
    15
      docs/feature_userspace.md

+ 39
- 15
docs/feature_userspace.md View File

@@ -201,27 +201,51 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
201 201
 
202 202
 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
203 203
   switch (keycode) {
204
-  case KC_MAKE:
205
-    if (!record->event.pressed) {
206
-      SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
207
-#if  (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
208
-       ":dfu "
209
-#elif defined(BOOTLOADER_HALFKAY)
210
-      ":teensy "
211
-#elif defined(BOOTLOADER_CATERINA)
212
-       ":avrdude "
213
-#endif
214
-        SS_TAP(X_ENTER));
215
-    }
216
-    return false;
217
-    break;
204
+    case KC_MAKE:  // Compiles the firmware, and adds the flash command based on keyboard bootloader
205
+            if (!record->event.pressed) {
206
+            uint8_t temp_mod = get_mods();
207
+            uint8_t temp_osm = get_oneshot_mods();
208
+            clear_mods(); clear_oneshot_mods();
209
+            SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP);
210
+    #ifndef FLASH_BOOTLOADER
211
+            if ( (temp_mod | temp_osm) & MOD_MASK_SHIFT ) 
212
+    #endif
213
+            { // 
214
+                #if defined(__arm__)  // only run for ARM boards
215
+                    SEND_STRING(":dfu-util");
216
+                #elif defined(BOOTLOADER_DFU) // only run for DFU boards
217
+                    SEND_STRING(":dfu");
218
+                #elif defined(BOOTLOADER_HALFKAY) // only run for teensy boards
219
+                    SEND_STRING(":teensy");
220
+                #elif defined(BOOTLOADER_CATERINA) // only run for Pro Micros
221
+                    SEND_STRING(":avrdude");
222
+                #endif // bootloader options
223
+            }
224
+            if ( (temp_mod | temp_osm) & MOD_MASK_CTRL) { 
225
+                SEND_STRING(" -j8 --output-sync"); 
226
+            }
227
+            SEND_STRING(SS_TAP(X_ENTER));
228
+            set_mods(temp_mod);
229
+        }
230
+        break;
231
+
218 232
   }
219 233
   return process_record_keymap(keycode, record);
220 234
 }
221 235
 ```
222 236
 
237
+For boards that may not have a shift button (such as on a macro pad), we need a way to always include the bootloader option.  To do that, add the following to the `rules.mk` in your userspace folder: 
238
+
239
+```make 
240
+ifeq ($(strip $(FLASH_BOOTLOADER)), yes)
241
+    OPT_DEFS += -DFLASH_BOOTLOADER
242
+endif
243
+```
244
+
223 245
 This will add a new `KC_MAKE` keycode that can be used in any of your keymaps.  And this keycode will output `make <keyboard>:<keymap>`, making frequent compiling easier.  And this will work with any keyboard and any keymap as it will output the current boards info, so that you don't have to type this out every time.
224 246
 
225
-Additionally, this should flash the newly compiled firmware automatically, using the correct utility, based on the bootloader settings (or default to just generating the HEX file). However, it should be noted that this may not work on all systems. AVRDUDE doesn't work on WSL, namely (and will dump the HEX in the ".build" folder instead).
247
+Also, holding `shift` will add the appropriate flashing command (`:dfu`, `:teensy`, `:avrdude`, `:dfu-util`) for a majority of keyboards.  Holding `control` will add some commands that will speed up compiling time by processing multiple files at once. 
226 248
 
249
+And for the boards that lack a shift key, or that you want to always attempt the flashing part, you can add `FLASH_BOOTLOADER = yes` to the `rules.mk` of that keymap.
227 250
 
251
+?> This should flash the newly compiled firmware automatically, using the correct utility, based on the bootloader settings (or default to just generating the HEX file). However, it should be noted that this may not work on all systems. AVRDUDE doesn't work on WSL, namely. And this doesn't support BootloadHID or mdloader. 

Loading…
Cancel
Save