]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/command.c
Merge pull request #1 from J3RN/vim-navigation
[qmk_firmware.git] / tmk_core / common / command.c
1 /*
2 Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include <util/delay.h>
20 #include "keycode.h"
21 #include "host.h"
22 #include "keymap.h"
23 #include "print.h"
24 #include "debug.h"
25 #include "util.h"
26 #include "timer.h"
27 #include "keyboard.h"
28 #include "bootloader.h"
29 #include "action_layer.h"
30 #include "action_util.h"
31 #include "eeconfig.h"
32 #include "sleep_led.h"
33 #include "led.h"
34 #include "command.h"
35 #include "backlight.h"
36
37 #ifdef MOUSEKEY_ENABLE
38 #include "mousekey.h"
39 #endif
40
41 #ifdef PROTOCOL_PJRC
42 #   include "usb_keyboard.h"
43 #   ifdef EXTRAKEY_ENABLE
44 #       include "usb_extra.h"
45 #   endif
46 #endif
47
48 #ifdef PROTOCOL_VUSB
49 #   include "usbdrv.h"
50 #endif
51
52
53 static bool command_common(uint8_t code);
54 static void command_common_help(void);
55 static void print_version(void);
56 static void print_status(void);
57 static bool command_console(uint8_t code);
58 static void command_console_help(void);
59 #ifdef MOUSEKEY_ENABLE
60 static bool mousekey_console(uint8_t code);
61 static void mousekey_console_help(void);
62 #endif
63
64 static uint8_t numkey2num(uint8_t code);
65 static void switch_default_layer(uint8_t layer);
66
67
68 command_state_t command_state = ONESHOT;
69
70
71 bool command_proc(uint8_t code)
72 {
73     switch (command_state) {
74         case ONESHOT:
75             if (!IS_COMMAND())
76                 return false;
77             return (command_extra(code) || command_common(code));
78             break;
79         case CONSOLE:
80             if (IS_COMMAND())
81                 return (command_extra(code) || command_common(code));
82             else
83                 return (command_console_extra(code) || command_console(code));
84             break;
85 #ifdef MOUSEKEY_ENABLE
86         case MOUSEKEY:
87             mousekey_console(code);
88             break;
89 #endif
90         default:
91             command_state = ONESHOT;
92             return false;
93     }
94     return true;
95 }
96
97 /* TODO: Refactoring is needed. */
98 /* This allows to define extra commands. return false when not processed. */
99 bool command_extra(uint8_t code) __attribute__ ((weak));
100 bool command_extra(uint8_t code)
101 {
102     return false;
103 }
104
105 bool command_console_extra(uint8_t code) __attribute__ ((weak));
106 bool command_console_extra(uint8_t code)
107 {
108     return false;
109 }
110
111
112 /***********************************************************
113  * Command common
114  ***********************************************************/
115 static void command_common_help(void)
116 {
117         print(                            "\n\t- Magic -\n"
118                 STR(MAGIC_KEY_DEBUG       ) ":  Debug Message Toggle\n"
119                 STR(MAGIC_KEY_DEBUG_MATRIX) ":  Matrix Debug Mode Toggle - Show keypresses in matrix grid\n"
120                 STR(MAGIC_KEY_DEBUG_KBD   ) ":  Keyboard Debug Toggle - Show keypress report\n"
121                 STR(MAGIC_KEY_DEBUG_MOUSE ) ":  Debug Mouse Toggle\n"
122                 STR(MAGIC_KEY_VERSION     ) ":  Version\n"
123                 STR(MAGIC_KEY_STATUS      ) ":  Status\n"
124                 STR(MAGIC_KEY_CONSOLE     ) ":  Activate Console Mode\n"
125                 
126 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
127                 STR(MAGIC_KEY_LAYER0      ) ":  Switch to Layer 0\n"
128                 STR(MAGIC_KEY_LAYER1      ) ":  Switch to Layer 1\n"
129                 STR(MAGIC_KEY_LAYER2      ) ":  Switch to Layer 2\n"
130                 STR(MAGIC_KEY_LAYER3      ) ":  Switch to Layer 3\n"
131                 STR(MAGIC_KEY_LAYER4      ) ":  Switch to Layer 4\n"
132                 STR(MAGIC_KEY_LAYER5      ) ":  Switch to Layer 5\n"
133                 STR(MAGIC_KEY_LAYER6      ) ":  Switch to Layer 6\n"
134                 STR(MAGIC_KEY_LAYER7      ) ":  Switch to Layer 7\n"
135                 STR(MAGIC_KEY_LAYER8      ) ":  Switch to Layer 8\n"
136                 STR(MAGIC_KEY_LAYER9      ) ":  Switch to Layer 9\n"
137 #endif
138
139 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS                                                   
140                                             "F1-F10:    Switch to Layer 0-9 (F10 = L0)\n"
141 #endif
142
143 #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS                                                   
144                                             "0-9:       Switch to Layer 0-9\n"
145 #endif
146
147                 STR(MAGIC_KEY_LAYER0_ALT1 ) ":  Switch to Layer 0 (alternate key 1)\n"
148                 STR(MAGIC_KEY_LAYER0_ALT2 ) ":  Switch to Layer 0 (alternate key 2)\n"
149                 STR(MAGIC_KEY_BOOTLOADER  ) ":  Jump to Bootloader (Reset)\n"
150
151 #ifdef KEYBOARD_LOCK_ENABLE
152                 STR(MAGIC_KEY_LOCK        ) ":  Lock\n"
153 #endif
154
155 #ifdef BOOTMAGIC_ENABLE
156                 STR(MAGIC_KEY_EEPROM      ) ":  Print EEPROM Settings\n"
157 #endif
158
159 #ifdef NKRO_ENABLE
160                 STR(MAGIC_KEY_NKRO        ) ":  NKRO Toggle\n"
161 #endif
162
163 #ifdef SLEEP_LED_ENABLE
164                 STR(MAGIC_KEY_SLEEP_LED   ) ":  Sleep LED Test\n"
165 #endif
166     );
167 }
168
169 static void print_version(void)
170 {
171         // print version & information
172     print("\n\t- Version -\n");
173     print("DESC: " STR(DESCRIPTION) "\n");
174     print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
175           "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
176           "VER: " STR(DEVICE_VER) "\n");
177     print("BUILD: " STR(VERSION) " (" __TIME__ " " __DATE__ ")\n");
178
179     /* build options */
180     print("OPTIONS:"
181
182 #ifdef PROTOCOL_PJRC
183             " PJRC"
184 #endif
185 #ifdef PROTOCOL_LUFA
186             " LUFA"
187 #endif
188 #ifdef PROTOCOL_VUSB
189             " VUSB"
190 #endif
191 #ifdef BOOTMAGIC_ENABLE
192             " BOOTMAGIC"
193 #endif
194 #ifdef MOUSEKEY_ENABLE
195             " MOUSEKEY"
196 #endif
197 #ifdef EXTRAKEY_ENABLE
198             " EXTRAKEY"
199 #endif
200 #ifdef CONSOLE_ENABLE
201             " CONSOLE"
202 #endif
203 #ifdef COMMAND_ENABLE
204             " COMMAND"
205 #endif
206 #ifdef NKRO_ENABLE
207             " NKRO"
208 #endif
209 #ifdef KEYMAP_SECTION_ENABLE
210             " KEYMAP_SECTION"
211 #endif
212
213             " " STR(BOOTLOADER_SIZE) "\n");
214
215     print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__)
216           " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__
217           " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n");
218
219         return;
220 }
221
222 static void print_status(void)
223 {
224
225     print("\n\t- Status -\n");
226
227     print_val_hex8(host_keyboard_leds());
228     print_val_hex8(keyboard_protocol);
229     print_val_hex8(keyboard_idle);
230 #ifdef NKRO_ENABLE
231     print_val_hex8(keyboard_nkro);
232 #endif
233     print_val_hex32(timer_count);
234
235 #ifdef PROTOCOL_PJRC
236     print_val_hex8(UDCON);
237     print_val_hex8(UDIEN);
238     print_val_hex8(UDINT);
239     print_val_hex8(usb_keyboard_leds);
240     print_val_hex8(usb_keyboard_idle_count);
241 #endif
242
243 #ifdef PROTOCOL_PJRC
244 #   if USB_COUNT_SOF
245     print_val_hex8(usbSofCount);
246 #   endif
247 #endif
248         return;
249 }
250
251 #ifdef BOOTMAGIC_ENABLE
252 static void print_eeconfig(void)
253 {
254     print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");
255
256     debug_config_t dc;
257     dc.raw = eeconfig_read_debug();
258     print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
259     print(".enable: "); print_dec(dc.enable); print("\n");
260     print(".matrix: "); print_dec(dc.matrix); print("\n");
261     print(".keyboard: "); print_dec(dc.keyboard); print("\n");
262     print(".mouse: "); print_dec(dc.mouse); print("\n");
263
264     keymap_config_t kc;
265     kc.raw = eeconfig_read_keymap();
266     print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
267     print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
268     print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
269     print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
270     print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
271     print(".no_gui: "); print_dec(kc.no_gui); print("\n");
272     print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
273     print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
274     print(".nkro: "); print_dec(kc.nkro); print("\n");
275
276 #ifdef BACKLIGHT_ENABLE
277     backlight_config_t bc;
278     bc.raw = eeconfig_read_backlight();
279     print("backlight_config.raw: "); print_hex8(bc.raw); print("\n");
280     print(".enable: "); print_dec(bc.enable); print("\n");
281     print(".level: "); print_dec(bc.level); print("\n");
282 #endif
283 }
284 #endif
285
286 static bool command_common(uint8_t code)
287 {
288
289 #ifdef KEYBOARD_LOCK_ENABLE
290     static host_driver_t *host_driver = 0;
291 #endif
292
293     switch (code) {
294
295 #ifdef SLEEP_LED_ENABLE
296
297                 // test breathing sleep LED
298         case MAGIC_KC(MAGIC_KEY_SLEEP_LED):
299             print("Sleep LED Test\n");
300             sleep_led_toggle();
301             led_set(host_keyboard_leds());
302             break;
303 #endif
304
305 #ifdef BOOTMAGIC_ENABLE
306
307                 // print stored eeprom config
308         case MAGIC_KC(MAGIC_KEY_EEPROM):        
309             print("eeconfig:\n");
310             print_eeconfig();
311             break;
312 #endif
313
314 #ifdef KEYBOARD_LOCK_ENABLE
315
316                 // lock/unlock keyboard
317         case MAGIC_KC(MAGIC_KEY_LOCK):
318             if (host_get_driver()) {
319                 host_driver = host_get_driver();
320                 clear_keyboard();
321                 host_set_driver(0);
322                 print("Locked.\n");
323             } else {
324                 host_set_driver(host_driver);
325                 print("Unlocked.\n");
326             }
327             break;
328 #endif
329
330                 // print help
331         case MAGIC_KC(MAGIC_KEY_HELP1):
332         case MAGIC_KC(MAGIC_KEY_HELP2):
333             command_common_help();
334             break;
335
336                 // activate console
337         case MAGIC_KC(MAGIC_KEY_CONSOLE):
338             debug_matrix   = false;
339             debug_keyboard = false;
340             debug_mouse    = false;
341             debug_enable   = false;
342             command_console_help();
343             print("C> ");
344             command_state = CONSOLE;
345             break;
346
347         // jump to bootloader
348         case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
349             clear_keyboard(); // clear to prevent stuck keys
350             print("\n\nJumping to bootloader... ");
351             _delay_ms(1000);
352             bootloader_jump(); // not return
353             break;
354
355         // debug toggle
356         case MAGIC_KC(MAGIC_KEY_DEBUG):
357             debug_enable = !debug_enable;
358             if (debug_enable) {
359                 print("\ndebug: on\n");
360                 debug_matrix   = true;
361                 debug_keyboard = true;
362                 debug_mouse    = true;
363             } else {
364                 print("\ndebug: off\n");
365                 debug_matrix   = false;
366                 debug_keyboard = false;
367                 debug_mouse    = false;
368             }
369             break;
370
371         // debug matrix toggle
372         case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX): 
373             debug_matrix = !debug_matrix;
374             if (debug_matrix) {
375                 print("\nmatrix: on\n");
376                 debug_enable = true;
377             } else {
378                 print("\nmatrix: off\n");
379             }
380             break;
381
382         // debug keyboard toggle
383         case MAGIC_KC(MAGIC_KEY_DEBUG_KBD): 
384             debug_keyboard = !debug_keyboard;
385             if (debug_keyboard) {
386                 print("\nkeyboard: on\n");
387                 debug_enable = true;
388             } else {
389                 print("\nkeyboard: off\n");
390             }
391             break;
392
393         // debug mouse toggle
394         case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE):
395             debug_mouse = !debug_mouse;
396             if (debug_mouse) {
397                 print("\nmouse: on\n");
398                 debug_enable = true;
399             } else {
400                                 print("\nmouse: off\n");
401             }
402             break;
403
404                 // print version
405         case MAGIC_KC(MAGIC_KEY_VERSION):
406                 print_version();
407                     break;
408
409                 // print status
410                 case MAGIC_KC(MAGIC_KEY_STATUS):
411                         print_status();
412             break;
413
414 #ifdef NKRO_ENABLE
415
416                 // NKRO toggle
417         case MAGIC_KC(MAGIC_KEY_NKRO):
418             clear_keyboard(); // clear to prevent stuck keys
419             keyboard_nkro = !keyboard_nkro;
420             if (keyboard_nkro)
421                 print("NKRO: on\n");
422             else
423                 print("NKRO: off\n");
424             break;
425 #endif
426
427                 // switch layers
428
429                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT1):
430                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT2):
431             switch_default_layer(0);
432             break;
433
434 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
435
436                 case MAGIC_KC(MAGIC_KEY_LAYER0):
437             switch_default_layer(0);
438             break;
439
440                 case MAGIC_KC(MAGIC_KEY_LAYER1):
441             switch_default_layer(1);
442             break;
443
444                 case MAGIC_KC(MAGIC_KEY_LAYER2):
445             switch_default_layer(2);
446             break;
447
448                 case MAGIC_KC(MAGIC_KEY_LAYER3):
449             switch_default_layer(3);
450             break;
451
452                 case MAGIC_KC(MAGIC_KEY_LAYER4):
453             switch_default_layer(4);
454             break;
455
456                 case MAGIC_KC(MAGIC_KEY_LAYER5):
457             switch_default_layer(5);
458             break;
459
460                 case MAGIC_KC(MAGIC_KEY_LAYER6):
461             switch_default_layer(6);
462             break;
463
464                 case MAGIC_KC(MAGIC_KEY_LAYER7):
465             switch_default_layer(7);
466             break;
467
468                 case MAGIC_KC(MAGIC_KEY_LAYER8):
469             switch_default_layer(8);
470             break;
471
472                 case MAGIC_KC(MAGIC_KEY_LAYER9):
473             switch_default_layer(9);
474             break;
475 #endif
476
477
478 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
479
480         case KC_F1 ... KC_F9:
481             switch_default_layer((code - KC_F1) + 1);
482             break;
483         case KC_F10:
484             switch_default_layer(0);
485             break;
486 #endif
487
488 #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
489
490         case KC_1 ... KC_9:
491             switch_default_layer((code - KC_1) + 1);
492             break;
493         case KC_0:
494             switch_default_layer(0);
495             break;
496 #endif
497
498         default:
499             print("?");
500             return false;
501     }
502     return true;
503 }
504
505
506 /***********************************************************
507  * Command console
508  ***********************************************************/
509 static void command_console_help(void)
510 {
511     print("\n\t- Console -\n"
512           "ESC/q:       quit\n"
513 #ifdef MOUSEKEY_ENABLE
514           "m:   mousekey\n"
515 #endif
516     );
517 }
518
519 static bool command_console(uint8_t code)
520 {
521     switch (code) {
522         case KC_H:
523         case KC_SLASH: /* ? */
524             command_console_help();
525             break;
526         case KC_Q:
527         case KC_ESC:
528             command_state = ONESHOT;
529             return false;
530 #ifdef MOUSEKEY_ENABLE
531         case KC_M:
532             mousekey_console_help();
533             print("M> ");
534             command_state = MOUSEKEY;
535             return true;
536 #endif
537         default:
538             print("?");
539             return false;
540     }
541     print("C> ");
542     return true;
543 }
544
545
546 #ifdef MOUSEKEY_ENABLE
547 /***********************************************************
548  * Mousekey console
549  ***********************************************************/
550 static uint8_t mousekey_param = 0;
551
552 static void mousekey_param_print(void)
553 {
554     print("\n\t- Values -\n");
555     print("1: delay(*10ms): "); pdec(mk_delay); print("\n");
556     print("2: interval(ms): "); pdec(mk_interval); print("\n");
557     print("3: max_speed: "); pdec(mk_max_speed); print("\n");
558     print("4: time_to_max: "); pdec(mk_time_to_max); print("\n");
559     print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
560     print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
561 }
562
563 //#define PRINT_SET_VAL(v)  print(#v " = "); print_dec(v); print("\n");
564 #define PRINT_SET_VAL(v)  xprintf(#v " = %d\n", (v))
565 static void mousekey_param_inc(uint8_t param, uint8_t inc)
566 {
567     switch (param) {
568         case 1:
569             if (mk_delay + inc < UINT8_MAX)
570                 mk_delay += inc;
571             else
572                 mk_delay = UINT8_MAX;
573             PRINT_SET_VAL(mk_delay);
574             break;
575         case 2:
576             if (mk_interval + inc < UINT8_MAX)
577                 mk_interval += inc;
578             else
579                 mk_interval = UINT8_MAX;
580             PRINT_SET_VAL(mk_interval);
581             break;
582         case 3:
583             if (mk_max_speed + inc < UINT8_MAX)
584                 mk_max_speed += inc;
585             else
586                 mk_max_speed = UINT8_MAX;
587             PRINT_SET_VAL(mk_max_speed);
588             break;
589         case 4:
590             if (mk_time_to_max + inc < UINT8_MAX)
591                 mk_time_to_max += inc;
592             else
593                 mk_time_to_max = UINT8_MAX;
594             PRINT_SET_VAL(mk_time_to_max);
595             break;
596         case 5:
597             if (mk_wheel_max_speed + inc < UINT8_MAX)
598                 mk_wheel_max_speed += inc;
599             else
600                 mk_wheel_max_speed = UINT8_MAX;
601             PRINT_SET_VAL(mk_wheel_max_speed);
602             break;
603         case 6:
604             if (mk_wheel_time_to_max + inc < UINT8_MAX)
605                 mk_wheel_time_to_max += inc;
606             else
607                 mk_wheel_time_to_max = UINT8_MAX;
608             PRINT_SET_VAL(mk_wheel_time_to_max);
609             break;
610     }
611 }
612
613 static void mousekey_param_dec(uint8_t param, uint8_t dec)
614 {
615     switch (param) {
616         case 1:
617             if (mk_delay > dec)
618                 mk_delay -= dec;
619             else
620                 mk_delay = 0;
621             PRINT_SET_VAL(mk_delay);
622             break;
623         case 2:
624             if (mk_interval > dec)
625                 mk_interval -= dec;
626             else
627                 mk_interval = 0;
628             PRINT_SET_VAL(mk_interval);
629             break;
630         case 3:
631             if (mk_max_speed > dec)
632                 mk_max_speed -= dec;
633             else
634                 mk_max_speed = 0;
635             PRINT_SET_VAL(mk_max_speed);
636             break;
637         case 4:
638             if (mk_time_to_max > dec)
639                 mk_time_to_max -= dec;
640             else
641                 mk_time_to_max = 0;
642             PRINT_SET_VAL(mk_time_to_max);
643             break;
644         case 5:
645             if (mk_wheel_max_speed > dec)
646                 mk_wheel_max_speed -= dec;
647             else
648                 mk_wheel_max_speed = 0;
649             PRINT_SET_VAL(mk_wheel_max_speed);
650             break;
651         case 6:
652             if (mk_wheel_time_to_max > dec)
653                 mk_wheel_time_to_max -= dec;
654             else
655                 mk_wheel_time_to_max = 0;
656             PRINT_SET_VAL(mk_wheel_time_to_max);
657             break;
658     }
659 }
660
661 static void mousekey_console_help(void)
662 {
663     print("\n\t- Mousekey -\n"
664           "ESC/q:       quit\n"
665           "1:   delay(*10ms)\n"
666           "2:   interval(ms)\n"
667           "3:   max_speed\n"
668           "4:   time_to_max\n"
669           "5:   wheel_max_speed\n"
670           "6:   wheel_time_to_max\n"
671           "\n"
672           "p:   print values\n"
673           "d:   set defaults\n"
674           "up:  +1\n"
675           "down:        -1\n"
676           "pgup:        +10\n"
677           "pgdown:      -10\n"
678           "\n"
679           "speed = delta * max_speed * (repeat / time_to_max)\n");
680     xprintf("where delta: cursor=%d, wheel=%d\n" 
681             "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA,  MOUSEKEY_WHEEL_DELTA);
682 }
683
684 static bool mousekey_console(uint8_t code)
685 {
686     switch (code) {
687         case KC_H:
688         case KC_SLASH: /* ? */
689             mousekey_console_help();
690             break;
691         case KC_Q:
692         case KC_ESC:
693             if (mousekey_param) {
694                 mousekey_param = 0;
695             } else {
696                 print("C> ");
697                 command_state = CONSOLE;
698                 return false;
699             }
700             break;
701         case KC_P:
702             mousekey_param_print();
703             break;
704         case KC_1:
705         case KC_2:
706         case KC_3:
707         case KC_4:
708         case KC_5:
709         case KC_6:
710             mousekey_param = numkey2num(code);
711             break;
712         case KC_UP:
713             mousekey_param_inc(mousekey_param, 1);
714             break;
715         case KC_DOWN:
716             mousekey_param_dec(mousekey_param, 1);
717             break;
718         case KC_PGUP:
719             mousekey_param_inc(mousekey_param, 10);
720             break;
721         case KC_PGDN:
722             mousekey_param_dec(mousekey_param, 10);
723             break;
724         case KC_D:
725             mk_delay = MOUSEKEY_DELAY/10;
726             mk_interval = MOUSEKEY_INTERVAL;
727             mk_max_speed = MOUSEKEY_MAX_SPEED;
728             mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
729             mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
730             mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
731             print("set default\n");
732             break;
733         default:
734             print("?");
735             return false;
736     }
737     if (mousekey_param)
738         xprintf("M%d> ", mousekey_param);
739     else
740         print("M>" );
741     return true;
742 }
743 #endif
744
745
746 /***********************************************************
747  * Utilities
748  ***********************************************************/
749 static uint8_t numkey2num(uint8_t code)
750 {
751     switch (code) {
752         case KC_1: return 1;
753         case KC_2: return 2;
754         case KC_3: return 3;
755         case KC_4: return 4;
756         case KC_5: return 5;
757         case KC_6: return 6;
758         case KC_7: return 7;
759         case KC_8: return 8;
760         case KC_9: return 9;
761         case KC_0: return 0;
762     }
763     return 0;
764 }
765
766 static void switch_default_layer(uint8_t layer)
767 {
768     xprintf("L%d\n", layer);
769     default_layer_set(1UL<<layer);
770     clear_keyboard();
771 }