diff options
Diffstat (limited to 'common/command.c')
| -rw-r--r-- | common/command.c | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/common/command.c b/common/command.c new file mode 100644 index 000000000..e325a5d84 --- /dev/null +++ b/common/command.c | |||
| @@ -0,0 +1,243 @@ | |||
| 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 "usb_keycodes.h" | ||
| 21 | #include "host.h" | ||
| 22 | #include "print.h" | ||
| 23 | #include "debug.h" | ||
| 24 | #include "util.h" | ||
| 25 | #include "timer.h" | ||
| 26 | #include "layer.h" | ||
| 27 | #include "matrix.h" | ||
| 28 | #include "bootloader.h" | ||
| 29 | #include "command.h" | ||
| 30 | |||
| 31 | #ifdef HOST_PJRC | ||
| 32 | # include "usb_keyboard.h" | ||
| 33 | # ifdef EXTRAKEY_ENABLE | ||
| 34 | # include "usb_extra.h" | ||
| 35 | # endif | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifdef HOST_VUSB | ||
| 39 | # include "usbdrv.h" | ||
| 40 | #endif | ||
| 41 | |||
| 42 | |||
| 43 | static uint8_t command_common(void); | ||
| 44 | static void help(void); | ||
| 45 | static void switch_layer(uint8_t layer); | ||
| 46 | |||
| 47 | static bool last_print_enable; | ||
| 48 | |||
| 49 | uint8_t command_proc(void) | ||
| 50 | { | ||
| 51 | uint8_t processed = 0; | ||
| 52 | last_print_enable = print_enable; | ||
| 53 | |||
| 54 | if (!IS_COMMAND()) | ||
| 55 | return 0; | ||
| 56 | |||
| 57 | print_enable = true; | ||
| 58 | if (command_extra() || command_common()) { | ||
| 59 | processed = 1; | ||
| 60 | _delay_ms(500); | ||
| 61 | } | ||
| 62 | print_enable = last_print_enable; | ||
| 63 | return processed; | ||
| 64 | } | ||
| 65 | |||
| 66 | /* This allows to define extra commands. return 0 when not processed. */ | ||
| 67 | uint8_t command_extra(void) __attribute__ ((weak)); | ||
| 68 | uint8_t command_extra(void) | ||
| 69 | { | ||
| 70 | return 0; | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | static uint8_t command_common(void) | ||
| 75 | { | ||
| 76 | switch (host_get_first_key()) { | ||
| 77 | case KB_H: | ||
| 78 | help(); | ||
| 79 | break; | ||
| 80 | case KB_B: | ||
| 81 | host_clear_keyboard_report(); | ||
| 82 | host_send_keyboard_report(); | ||
| 83 | print("jump to bootloader... "); | ||
| 84 | _delay_ms(1000); | ||
| 85 | bootloader_jump(); // not return | ||
| 86 | print("not supported.\n"); | ||
| 87 | break; | ||
| 88 | case KB_D: | ||
| 89 | debug_enable = !debug_enable; | ||
| 90 | if (debug_enable) { | ||
| 91 | last_print_enable = true; | ||
| 92 | print("debug enabled.\n"); | ||
| 93 | debug_matrix = true; | ||
| 94 | debug_keyboard = true; | ||
| 95 | debug_mouse = true; | ||
| 96 | } else { | ||
| 97 | print("debug disabled.\n"); | ||
| 98 | last_print_enable = false; | ||
| 99 | debug_matrix = false; | ||
| 100 | debug_keyboard = false; | ||
| 101 | debug_mouse = false; | ||
| 102 | } | ||
| 103 | break; | ||
| 104 | case KB_X: // debug matrix toggle | ||
| 105 | debug_matrix = !debug_matrix; | ||
| 106 | if (debug_matrix) | ||
| 107 | print("debug matrix enabled.\n"); | ||
| 108 | else | ||
| 109 | print("debug matrix disabled.\n"); | ||
| 110 | break; | ||
| 111 | case KB_K: // debug keyboard toggle | ||
| 112 | debug_keyboard = !debug_keyboard; | ||
| 113 | if (debug_keyboard) | ||
| 114 | print("debug keyboard enabled.\n"); | ||
| 115 | else | ||
| 116 | print("debug keyboard disabled.\n"); | ||
| 117 | break; | ||
| 118 | case KB_M: // debug mouse toggle | ||
| 119 | debug_mouse = !debug_mouse; | ||
| 120 | if (debug_mouse) | ||
| 121 | print("debug mouse enabled.\n"); | ||
| 122 | else | ||
| 123 | print("debug mouse disabled.\n"); | ||
| 124 | break; | ||
| 125 | case KB_V: // print version & information | ||
| 126 | print(STR(DESCRIPTION) "\n"); | ||
| 127 | break; | ||
| 128 | case KB_T: // print timer | ||
| 129 | print("timer: "); phex16(timer_count); print("\n"); | ||
| 130 | break; | ||
| 131 | case KB_P: // print toggle | ||
| 132 | if (last_print_enable) { | ||
| 133 | print("print disabled.\n"); | ||
| 134 | last_print_enable = false; | ||
| 135 | } else { | ||
| 136 | last_print_enable = true; | ||
| 137 | print("print enabled.\n"); | ||
| 138 | } | ||
| 139 | break; | ||
| 140 | case KB_S: | ||
| 141 | #ifdef HOST_PJRC | ||
| 142 | print("UDCON: "); phex(UDCON); print("\n"); | ||
| 143 | print("UDIEN: "); phex(UDIEN); print("\n"); | ||
| 144 | print("UDINT: "); phex(UDINT); print("\n"); | ||
| 145 | print("usb_keyboard_leds:"); phex(usb_keyboard_leds); print("\n"); | ||
| 146 | print("usb_keyboard_protocol: "); phex(usb_keyboard_protocol); print("\n"); | ||
| 147 | print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n"); | ||
| 148 | print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n"); | ||
| 149 | #endif | ||
| 150 | |||
| 151 | #ifdef HOST_VUSB | ||
| 152 | # if USB_COUNT_SOF | ||
| 153 | print("usbSofCount: "); phex(usbSofCount); print("\n"); | ||
| 154 | # endif | ||
| 155 | #endif | ||
| 156 | break; | ||
| 157 | #ifdef NKRO_ENABLE | ||
| 158 | case KB_N: | ||
| 159 | // send empty report before change | ||
| 160 | host_clear_keyboard_report(); | ||
| 161 | host_send_keyboard_report(); | ||
| 162 | keyboard_nkro = !keyboard_nkro; | ||
| 163 | if (keyboard_nkro) | ||
| 164 | print("NKRO: enabled\n"); | ||
| 165 | else | ||
| 166 | print("NKRO: disabled\n"); | ||
| 167 | break; | ||
| 168 | #endif | ||
| 169 | #ifdef EXTRAKEY_ENABLE | ||
| 170 | case KB_ESC: | ||
| 171 | host_clear_keyboard_report(); | ||
| 172 | host_send_keyboard_report(); | ||
| 173 | #ifdef HOST_PJRC | ||
| 174 | if (suspend && remote_wakeup) { | ||
| 175 | usb_remote_wakeup(); | ||
| 176 | } else { | ||
| 177 | host_system_send(SYSTEM_POWER_DOWN); | ||
| 178 | host_system_send(0); | ||
| 179 | _delay_ms(500); | ||
| 180 | } | ||
| 181 | #else | ||
| 182 | host_system_send(SYSTEM_POWER_DOWN); | ||
| 183 | host_system_send(0); | ||
| 184 | _delay_ms(500); | ||
| 185 | #endif | ||
| 186 | break; | ||
| 187 | #endif | ||
| 188 | case KB_BSPC: | ||
| 189 | matrix_init(); | ||
| 190 | print("clear matrix\n"); | ||
| 191 | break; | ||
| 192 | case KB_0: | ||
| 193 | switch_layer(0); | ||
| 194 | break; | ||
| 195 | case KB_1: | ||
| 196 | switch_layer(1); | ||
| 197 | break; | ||
| 198 | case KB_2: | ||
| 199 | switch_layer(2); | ||
| 200 | break; | ||
| 201 | case KB_3: | ||
| 202 | switch_layer(3); | ||
| 203 | break; | ||
| 204 | case KB_4: | ||
| 205 | switch_layer(4); | ||
| 206 | break; | ||
| 207 | default: | ||
| 208 | return 0; | ||
| 209 | } | ||
| 210 | return 1; | ||
| 211 | } | ||
| 212 | |||
| 213 | static void help(void) | ||
| 214 | { | ||
| 215 | print("b: jump to bootloader\n"); | ||
| 216 | print("d: toggle debug enable\n"); | ||
| 217 | print("x: toggle matrix debug\n"); | ||
| 218 | print("k: toggle keyboard debug\n"); | ||
| 219 | print("m: toggle mouse debug\n"); | ||
| 220 | print("p: toggle print enable\n"); | ||
| 221 | print("v: print version\n"); | ||
| 222 | print("t: print timer count\n"); | ||
| 223 | print("s: print status\n"); | ||
| 224 | #ifdef NKRO_ENABLE | ||
| 225 | print("n: toggle NKRO\n"); | ||
| 226 | #endif | ||
| 227 | print("Backspace: clear matrix\n"); | ||
| 228 | print("ESC: power down/wake up\n"); | ||
| 229 | print("0: switch to Layer0 \n"); | ||
| 230 | print("1: switch to Layer1 \n"); | ||
| 231 | print("2: switch to Layer2 \n"); | ||
| 232 | print("3: switch to Layer3 \n"); | ||
| 233 | print("4: switch to Layer4 \n"); | ||
| 234 | } | ||
| 235 | |||
| 236 | static void switch_layer(uint8_t layer) | ||
| 237 | { | ||
| 238 | print("current_layer: "); phex(current_layer); print("\n"); | ||
| 239 | print("default_layer: "); phex(default_layer); print("\n"); | ||
| 240 | current_layer = layer; | ||
| 241 | default_layer = layer; | ||
| 242 | print("switch to Layer: "); phex(layer); print("\n"); | ||
| 243 | } | ||
