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