X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=command.c;h=e325a5d847e144c3ba1c6d384f1b17fbb04ac2b6;hb=e65575d4a5f03a90adfa9850cb71a5d0448098cd;hp=ca149dbd08e4954404c37c3eeda8c048d5230f2a;hpb=74f7e19863ced21bf5d27c1fb1207f79f2195e24;p=max%2Ftmk_keyboard.git diff --git a/command.c b/command.c old mode 100755 new mode 100644 index ca149dbd..e325a5d8 --- a/command.c +++ b/command.c @@ -1,3 +1,19 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ #include #include #include @@ -9,41 +25,65 @@ #include "timer.h" #include "layer.h" #include "matrix.h" +#include "bootloader.h" #include "command.h" #ifdef HOST_PJRC -# include "jump_bootloader.h" # include "usb_keyboard.h" -# ifdef USB_EXTRA_ENABLE +# ifdef EXTRAKEY_ENABLE # include "usb_extra.h" # endif #endif +#ifdef HOST_VUSB +# include "usbdrv.h" +#endif + +static uint8_t command_common(void); static void help(void); static void switch_layer(uint8_t layer); +static bool last_print_enable; uint8_t command_proc(void) { + uint8_t processed = 0; + last_print_enable = print_enable; + if (!IS_COMMAND()) return 0; - uint8_t processed = 1; - bool last_print_enable = print_enable; print_enable = true; + if (command_extra() || command_common()) { + processed = 1; + _delay_ms(500); + } + print_enable = last_print_enable; + return processed; +} + +/* This allows to define extra commands. return 0 when not processed. */ +uint8_t command_extra(void) __attribute__ ((weak)); +uint8_t command_extra(void) +{ + return 0; +} + + +static uint8_t command_common(void) +{ switch (host_get_first_key()) { case KB_H: help(); break; case KB_B: -#ifdef HOST_PJRC host_clear_keyboard_report(); host_send_keyboard_report(); - print("jump to bootloader...\n"); + print("jump to bootloader... "); _delay_ms(1000); - jump_bootloader(); // not return -#endif + bootloader_jump(); // not return + print("not supported.\n"); break; case KB_D: debug_enable = !debug_enable; @@ -106,30 +146,42 @@ uint8_t command_proc(void) print("usb_keyboard_protocol: "); phex(usb_keyboard_protocol); print("\n"); print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n"); print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n"); +#endif + +#ifdef HOST_VUSB +# if USB_COUNT_SOF + print("usbSofCount: "); phex(usbSofCount); print("\n"); +# endif #endif break; -#ifdef USB_NKRO_ENABLE +#ifdef NKRO_ENABLE case KB_N: // send empty report before change host_clear_keyboard_report(); host_send_keyboard_report(); keyboard_nkro = !keyboard_nkro; if (keyboard_nkro) - print("USB_NKRO: enabled\n"); + print("NKRO: enabled\n"); else - print("USB_NKRO: disabled\n"); + print("NKRO: disabled\n"); break; #endif -#ifdef USB_EXTRA_ENABLE +#ifdef EXTRAKEY_ENABLE case KB_ESC: + host_clear_keyboard_report(); + host_send_keyboard_report(); #ifdef HOST_PJRC if (suspend && remote_wakeup) { usb_remote_wakeup(); } else { host_system_send(SYSTEM_POWER_DOWN); + host_system_send(0); + _delay_ms(500); } #else host_system_send(SYSTEM_POWER_DOWN); + host_system_send(0); + _delay_ms(500); #endif break; #endif @@ -153,12 +205,9 @@ uint8_t command_proc(void) switch_layer(4); break; default: - processed = 0; + return 0; } - if (processed) - _delay_ms(500); - print_enable = last_print_enable; - return processed; + return 1; } static void help(void) @@ -172,8 +221,8 @@ static void help(void) print("v: print version\n"); print("t: print timer count\n"); print("s: print status\n"); -#ifdef USB_NKRO_ENABLE - print("n: toggle USB_NKRO\n"); +#ifdef NKRO_ENABLE + print("n: toggle NKRO\n"); #endif print("Backspace: clear matrix\n"); print("ESC: power down/wake up\n");