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