diff options
| -rw-r--r-- | Makefile.rules | 11 | ||||
| -rw-r--r-- | command.c | 4 | ||||
| -rw-r--r-- | key_process.c | 392 | ||||
| -rw-r--r-- | key_process.h | 7 | ||||
| -rw-r--r-- | keyboard.c | 10 | ||||
| -rw-r--r-- | keymap.h (renamed from keymap_skel.h) | 7 | ||||
| -rw-r--r-- | layer.c | 2 | ||||
| -rw-r--r-- | main_pjrc.c | 97 | ||||
| -rw-r--r-- | matrix.h (renamed from matrix_skel.h) | 4 | ||||
| -rw-r--r-- | ps2.c | 12 | ||||
| -rw-r--r-- | ps2_usb/Makefile | 56 | ||||
| -rw-r--r-- | ps2_usb/Makefile.vusb (renamed from ps2_vusb/Makefile) | 10 | ||||
| -rw-r--r-- | ps2_usb/README | 15 | ||||
| -rw-r--r-- | ps2_usb/config_pjrc.h (renamed from ps2_usb/config.h) | 16 | ||||
| -rw-r--r-- | ps2_usb/config_vusb.h (renamed from ps2_vusb/config.h) | 6 | ||||
| -rw-r--r-- | ps2_usb/keymap.c | 9 | ||||
| -rw-r--r-- | ps2_usb/led.c (renamed from ps2_vusb/led.c) | 0 | ||||
| -rw-r--r-- | ps2_usb/main_vusb.c (renamed from ps2_vusb/main.c) | 2 | ||||
| -rw-r--r-- | ps2_usb/matrix.c | 50 | ||||
| -rw-r--r-- | ps2_usb/ps2_usart.c (renamed from ps2_vusb/ps2_usart.c) | 0 | ||||
| -rw-r--r-- | ps2_usb/sendchar_dummy.c (renamed from ps2_vusb/sendchar_dummy.c) | 0 | ||||
| -rw-r--r-- | ps2_usb/sendchar_usart.c (renamed from ps2_vusb/sendchar_usart.c) | 0 | ||||
| -rw-r--r-- | ps2_usb/usbconfig.h (renamed from ps2_vusb/usbconfig.h) | 2 | ||||
| -rw-r--r-- | ps2_vusb/README | 12 | ||||
| -rw-r--r-- | ps2_vusb/keymap.c | 189 | ||||
| -rw-r--r-- | ps2_vusb/matrix.c | 444 | ||||
| -rw-r--r-- | tmk.c | 2 |
27 files changed, 176 insertions, 1183 deletions
diff --git a/Makefile.rules b/Makefile.rules index 96d1d7e1e..f1d0a301c 100644 --- a/Makefile.rules +++ b/Makefile.rules | |||
| @@ -47,7 +47,7 @@ FORMAT = ihex | |||
| 47 | # Object files directory | 47 | # Object files directory |
| 48 | # To put object files in current directory, use a dot (.), do NOT make | 48 | # To put object files in current directory, use a dot (.), do NOT make |
| 49 | # this an empty or blank macro! | 49 | # this an empty or blank macro! |
| 50 | OBJDIR = obj | 50 | OBJDIR = obj_$(TARGET) |
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | # Optimization level, can be [0, 1, 2, 3, s]. | 53 | # Optimization level, can be [0, 1, 2, 3, s]. |
| @@ -121,7 +121,7 @@ CFLAGS += -Wstrict-prototypes | |||
| 121 | CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) | 121 | CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) |
| 122 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | 122 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
| 123 | CFLAGS += $(CSTANDARD) | 123 | CFLAGS += $(CSTANDARD) |
| 124 | CFLAGS += -include config.h | 124 | CFLAGS += -include $(CONFIG_H) |
| 125 | 125 | ||
| 126 | 126 | ||
| 127 | #---------------- Compiler Options C++ ---------------- | 127 | #---------------- Compiler Options C++ ---------------- |
| @@ -149,7 +149,7 @@ CPPFLAGS += -Wundef | |||
| 149 | CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) | 149 | CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) |
| 150 | CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | 150 | CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
| 151 | #CPPFLAGS += $(CSTANDARD) | 151 | #CPPFLAGS += $(CSTANDARD) |
| 152 | CPPFLAGS += -include config.h | 152 | CPPFLAGS += -include $(CONFIG_H) |
| 153 | 153 | ||
| 154 | 154 | ||
| 155 | #---------------- Assembler Options ---------------- | 155 | #---------------- Assembler Options ---------------- |
| @@ -162,7 +162,7 @@ CPPFLAGS += -include config.h | |||
| 162 | # -listing-cont-lines: Sets the maximum number of continuation lines of hex | 162 | # -listing-cont-lines: Sets the maximum number of continuation lines of hex |
| 163 | # dump that will be displayed for a given single line of source input. | 163 | # dump that will be displayed for a given single line of source input. |
| 164 | ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 | 164 | ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 |
| 165 | ASFLAGS += -include config.h | 165 | ASFLAGS += -include $(CONFIG_H) |
| 166 | 166 | ||
| 167 | 167 | ||
| 168 | #---------------- Library Options ---------------- | 168 | #---------------- Library Options ---------------- |
| @@ -273,7 +273,6 @@ OBJDUMP = avr-objdump | |||
| 273 | SIZE = avr-size | 273 | SIZE = avr-size |
| 274 | AR = avr-ar rcs | 274 | AR = avr-ar rcs |
| 275 | NM = avr-nm | 275 | NM = avr-nm |
| 276 | AVRDUDE = avrdude | ||
| 277 | REMOVE = rm -f | 276 | REMOVE = rm -f |
| 278 | REMOVEDIR = rmdir | 277 | REMOVEDIR = rmdir |
| 279 | COPY = cp | 278 | COPY = cp |
| @@ -377,7 +376,7 @@ gccversion : | |||
| 377 | 376 | ||
| 378 | # Program the device. | 377 | # Program the device. |
| 379 | program: $(TARGET).hex $(TARGET).eep | 378 | program: $(TARGET).hex $(TARGET).eep |
| 380 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) | 379 | $(PROGRAM_CMD) |
| 381 | 380 | ||
| 382 | 381 | ||
| 383 | # Generate avr-gdb config/init file which does the following: | 382 | # Generate avr-gdb config/init file which does the following: |
| @@ -8,7 +8,7 @@ | |||
| 8 | #include "util.h" | 8 | #include "util.h" |
| 9 | #include "timer.h" | 9 | #include "timer.h" |
| 10 | #include "layer.h" | 10 | #include "layer.h" |
| 11 | #include "matrix_skel.h" | 11 | #include "matrix.h" |
| 12 | #include "command.h" | 12 | #include "command.h" |
| 13 | 13 | ||
| 14 | #ifdef HOST_PJRC | 14 | #ifdef HOST_PJRC |
| @@ -107,6 +107,8 @@ uint8_t command_proc(void) | |||
| 107 | break; | 107 | break; |
| 108 | #ifdef USB_NKRO_ENABLE | 108 | #ifdef USB_NKRO_ENABLE |
| 109 | case KB_N: | 109 | case KB_N: |
| 110 | host_clear_keyboard_report(); | ||
| 111 | host_send_keyboard_report(); | ||
| 110 | keyboard_nkro = !keyboard_nkro; | 112 | keyboard_nkro = !keyboard_nkro; |
| 111 | if (keyboard_nkro) | 113 | if (keyboard_nkro) |
| 112 | print("USB_NKRO: enabled\n"); | 114 | print("USB_NKRO: enabled\n"); |
diff --git a/key_process.c b/key_process.c deleted file mode 100644 index 4367f471d..000000000 --- a/key_process.c +++ /dev/null | |||
| @@ -1,392 +0,0 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <avr/io.h> | ||
| 3 | #include <avr/interrupt.h> | ||
| 4 | #include <util/delay.h> | ||
| 5 | #include "print.h" | ||
| 6 | #include "debug.h" | ||
| 7 | #include "timer.h" | ||
| 8 | #include "util.h" | ||
| 9 | #include "jump_bootloader.h" | ||
| 10 | #include "usb_keyboard.h" | ||
| 11 | #include "usb_keycodes.h" | ||
| 12 | #include "usb.h" | ||
| 13 | #include "layer.h" | ||
| 14 | #include "matrix_skel.h" | ||
| 15 | #include "keymap_skel.h" | ||
| 16 | #include "key_process.h" | ||
| 17 | #ifdef MOUSEKEY_ENABLE | ||
| 18 | # include "mousekey.h" | ||
| 19 | #endif | ||
| 20 | #ifdef PS2_MOUSE_ENABLE | ||
| 21 | # include "ps2_mouse.h" | ||
| 22 | #endif | ||
| 23 | #ifdef USB_EXTRA_ENABLE | ||
| 24 | # include "usb_extra.h" | ||
| 25 | #endif | ||
| 26 | #ifdef USB_MOUSE_ENABLE | ||
| 27 | # include "usb_mouse.h" | ||
| 28 | #endif | ||
| 29 | |||
| 30 | |||
| 31 | // TODO: refactoring | ||
| 32 | void proc_matrix(void) { | ||
| 33 | bool modified = false; | ||
| 34 | uint8_t fn_bits = 0; | ||
| 35 | |||
| 36 | matrix_scan(); | ||
| 37 | modified = matrix_is_modified(); | ||
| 38 | |||
| 39 | if (modified) { | ||
| 40 | if (debug_matrix) matrix_print(); | ||
| 41 | #ifdef DEBUG_LED | ||
| 42 | // LED flash for debug | ||
| 43 | DEBUG_LED_CONFIG; | ||
| 44 | DEBUG_LED_ON; | ||
| 45 | #endif | ||
| 46 | } | ||
| 47 | |||
| 48 | if (matrix_has_ghost()) { | ||
| 49 | // should send error? | ||
| 50 | debug("matrix has ghost!!\n"); | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | |||
| 54 | usb_keyboard_swap_report(); | ||
| 55 | usb_keyboard_clear_report(); | ||
| 56 | for (int row = 0; row < matrix_rows(); row++) { | ||
| 57 | for (int col = 0; col < matrix_cols(); col++) { | ||
| 58 | if (!matrix_is_on(row, col)) continue; | ||
| 59 | |||
| 60 | uint8_t code = layer_get_keycode(row, col); | ||
| 61 | if (code == KB_NO) { | ||
| 62 | // do nothing | ||
| 63 | } else if (IS_MOD(code)) { | ||
| 64 | usb_keyboard_add_mod(code); | ||
| 65 | } else if (IS_FN(code)) { | ||
| 66 | fn_bits |= FN_BIT(code); | ||
| 67 | } | ||
| 68 | #ifdef MOUSEKEY_ENABLE | ||
| 69 | else if (IS_MOUSEKEY(code)) { | ||
| 70 | mousekey_decode(code); | ||
| 71 | } | ||
| 72 | #endif | ||
| 73 | #ifdef USB_EXTRA_ENABLE | ||
| 74 | // audio control & system control | ||
| 75 | else if (code == KB_MUTE) { | ||
| 76 | usb_extra_audio_send(AUDIO_MUTE); | ||
| 77 | usb_extra_audio_send(0); | ||
| 78 | _delay_ms(500); | ||
| 79 | } else if (code == KB_VOLU) { | ||
| 80 | usb_extra_audio_send(AUDIO_VOL_UP); | ||
| 81 | usb_extra_audio_send(0); | ||
| 82 | _delay_ms(200); | ||
| 83 | } else if (code == KB_VOLD) { | ||
| 84 | usb_extra_audio_send(AUDIO_VOL_DOWN); | ||
| 85 | usb_extra_audio_send(0); | ||
| 86 | _delay_ms(200); | ||
| 87 | } else if (code == KB_PWR) { | ||
| 88 | if (suspend && remote_wakeup) { | ||
| 89 | usb_remote_wakeup(); | ||
| 90 | } else { | ||
| 91 | usb_extra_system_send(SYSTEM_POWER_DOWN); | ||
| 92 | } | ||
| 93 | _delay_ms(1000); | ||
| 94 | } | ||
| 95 | #endif | ||
| 96 | // normal key | ||
| 97 | else if (IS_KEY(code)) { | ||
| 98 | usb_keyboard_add_key(code); | ||
| 99 | } else { | ||
| 100 | debug("ignore keycode: "); debug_hex(code); debug("\n"); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | if (modified) { | ||
| 106 | #ifdef DEBUG_LED | ||
| 107 | // LED flash for debug | ||
| 108 | DEBUG_LED_CONFIG; | ||
| 109 | DEBUG_LED_OFF; | ||
| 110 | #endif | ||
| 111 | } | ||
| 112 | |||
| 113 | layer_switching(fn_bits); | ||
| 114 | |||
| 115 | // TODO: clean code | ||
| 116 | // special mode for control, develop and debug | ||
| 117 | if (keymap_is_special_mode(fn_bits)) { | ||
| 118 | switch (usb_keyboard_get_key()) { | ||
| 119 | case KB_H: // help | ||
| 120 | usb_keyboard_clear_report(); | ||
| 121 | usb_keyboard_send(); | ||
| 122 | print_enable = true; | ||
| 123 | print("b: jump to bootloader\n"); | ||
| 124 | print("d: toggle debug enable\n"); | ||
| 125 | print("x: toggle matrix debug\n"); | ||
| 126 | print("k: toggle keyboard debug\n"); | ||
| 127 | print("m: toggle mouse debug\n"); | ||
| 128 | print("p: toggle print enable\n"); | ||
| 129 | print("v: print version\n"); | ||
| 130 | print("t: print timer count\n"); | ||
| 131 | print("s: print status\n"); | ||
| 132 | print("`: toggle protcol(boot/report)\n"); | ||
| 133 | #ifdef USB_NKRO_ENABLE | ||
| 134 | print("n: toggle USB_NKRO\n"); | ||
| 135 | #endif | ||
| 136 | print("Backspace: clear matrix\n"); | ||
| 137 | print("ESC: power down/wake up\n"); | ||
| 138 | print("0: switch to Layer0 \n"); | ||
| 139 | print("1: switch to Layer1 \n"); | ||
| 140 | print("2: switch to Layer2 \n"); | ||
| 141 | print("3: switch to Layer3 \n"); | ||
| 142 | print("4: switch to Layer4 \n"); | ||
| 143 | #ifdef PS2_MOUSE_ENABLE | ||
| 144 | print("[: ps2_mouse_init \n"); | ||
| 145 | print("]: ps2_mouse_read \n"); | ||
| 146 | print("\: ps2_mouse: on/off toggle \n"); | ||
| 147 | #endif | ||
| 148 | _delay_ms(500); | ||
| 149 | print_enable = false; | ||
| 150 | break; | ||
| 151 | case KB_BSPC: | ||
| 152 | usb_keyboard_clear_report(); | ||
| 153 | usb_keyboard_send(); | ||
| 154 | matrix_init(); | ||
| 155 | print("clear matrix\n"); | ||
| 156 | _delay_ms(500); | ||
| 157 | break; | ||
| 158 | case KB_0: | ||
| 159 | usb_keyboard_clear_report(); | ||
| 160 | usb_keyboard_send(); | ||
| 161 | print("current_layer: "); phex(current_layer); print("\n"); | ||
| 162 | print("default_layer: "); phex(default_layer); print("\n"); | ||
| 163 | current_layer = 0; | ||
| 164 | default_layer = 0; | ||
| 165 | print("switch to Layer0 \n"); | ||
| 166 | _delay_ms(500); | ||
| 167 | break; | ||
| 168 | case KB_1: | ||
| 169 | usb_keyboard_clear_report(); | ||
| 170 | usb_keyboard_send(); | ||
| 171 | print("current_layer: "); phex(current_layer); print("\n"); | ||
| 172 | print("default_layer: "); phex(default_layer); print("\n"); | ||
| 173 | current_layer = 1; | ||
| 174 | default_layer = 1; | ||
| 175 | print("switch to Layer1 \n"); | ||
| 176 | _delay_ms(500); | ||
| 177 | break; | ||
| 178 | case KB_2: | ||
| 179 | usb_keyboard_clear_report(); | ||
| 180 | usb_keyboard_send(); | ||
| 181 | print("current_layer: "); phex(current_layer); print("\n"); | ||
| 182 | print("default_layer: "); phex(default_layer); print("\n"); | ||
| 183 | current_layer = 2; | ||
| 184 | default_layer = 2; | ||
| 185 | print("switch to Layer2 \n"); | ||
| 186 | _delay_ms(500); | ||
| 187 | break; | ||
| 188 | case KB_3: | ||
| 189 | usb_keyboard_clear_report(); | ||
| 190 | usb_keyboard_send(); | ||
| 191 | print("current_layer: "); phex(current_layer); print("\n"); | ||
| 192 | print("default_layer: "); phex(default_layer); print("\n"); | ||
| 193 | current_layer = 3; | ||
| 194 | default_layer = 3; | ||
| 195 | print("switch to Layer3 \n"); | ||
| 196 | _delay_ms(500); | ||
| 197 | break; | ||
| 198 | case KB_4: | ||
| 199 | usb_keyboard_clear_report(); | ||
| 200 | usb_keyboard_send(); | ||
| 201 | print("current_layer: "); phex(current_layer); print("\n"); | ||
| 202 | print("default_layer: "); phex(default_layer); print("\n"); | ||
| 203 | current_layer = 4; | ||
| 204 | default_layer = 4; | ||
| 205 | print("switch to Layer4 \n"); | ||
| 206 | _delay_ms(500); | ||
| 207 | break; | ||
| 208 | #ifdef PS2_MOUSE_ENABLE | ||
| 209 | case KB_LBRC: | ||
| 210 | usb_keyboard_clear_report(); | ||
| 211 | usb_keyboard_send(); | ||
| 212 | print_enable = true; | ||
| 213 | print("ps2_mouse_init...\n"); | ||
| 214 | _delay_ms(500); | ||
| 215 | ps2_mouse_init(); | ||
| 216 | break; | ||
| 217 | case KB_RBRC: | ||
| 218 | usb_keyboard_clear_report(); | ||
| 219 | usb_keyboard_send(); | ||
| 220 | print_enable = true; | ||
| 221 | print("ps2_mouse_read[btn x y]: "); | ||
| 222 | _delay_ms(100); | ||
| 223 | ps2_mouse_read(); | ||
| 224 | phex(ps2_mouse_btn); print(" "); | ||
| 225 | phex(ps2_mouse_x); print(" "); | ||
| 226 | phex(ps2_mouse_y); print("\n"); | ||
| 227 | print("ps2_mouse_error_count: "); phex(ps2_mouse_error_count); print("\n"); | ||
| 228 | break; | ||
| 229 | case KB_BSLS: | ||
| 230 | ps2_mouse_enable = !ps2_mouse_enable; | ||
| 231 | print("ps2_mouse: "); | ||
| 232 | if (ps2_mouse_enable) | ||
| 233 | print("on"); | ||
| 234 | else | ||
| 235 | print("off"); | ||
| 236 | print("\n"); | ||
| 237 | _delay_ms(500); | ||
| 238 | break; | ||
| 239 | #endif | ||
| 240 | case KB_B: // bootloader | ||
| 241 | usb_keyboard_clear_report(); | ||
| 242 | usb_keyboard_send(); | ||
| 243 | print_enable = true; | ||
| 244 | print("jump to bootloader...\n"); | ||
| 245 | _delay_ms(1000); | ||
| 246 | jump_bootloader(); // not return | ||
| 247 | break; | ||
| 248 | case KB_D: // debug all toggle | ||
| 249 | usb_keyboard_clear_report(); | ||
| 250 | usb_keyboard_send(); | ||
| 251 | debug_enable = !debug_enable; | ||
| 252 | if (debug_enable) { | ||
| 253 | print_enable = true; | ||
| 254 | print("debug enabled.\n"); | ||
| 255 | //debug_matrix = true; | ||
| 256 | //debug_keyboard = true; | ||
| 257 | //debug_mouse = true; | ||
| 258 | } else { | ||
| 259 | print("debug disabled.\n"); | ||
| 260 | print_enable = false; | ||
| 261 | //debug_matrix = false; | ||
| 262 | //debug_keyboard = false; | ||
| 263 | //debug_mouse = false; | ||
| 264 | } | ||
| 265 | _delay_ms(1000); | ||
| 266 | break; | ||
| 267 | case KB_X: // debug matrix toggle | ||
| 268 | usb_keyboard_clear_report(); | ||
| 269 | usb_keyboard_send(); | ||
| 270 | debug_matrix = !debug_matrix; | ||
| 271 | if (debug_matrix) | ||
| 272 | print("debug matrix enabled.\n"); | ||
| 273 | else | ||
| 274 | print("debug matrix disabled.\n"); | ||
| 275 | _delay_ms(1000); | ||
| 276 | break; | ||
| 277 | case KB_K: // debug keyboard toggle | ||
| 278 | usb_keyboard_clear_report(); | ||
| 279 | usb_keyboard_send(); | ||
| 280 | debug_keyboard = !debug_keyboard; | ||
| 281 | if (debug_keyboard) | ||
| 282 | print("debug keyboard enabled.\n"); | ||
| 283 | else | ||
| 284 | print("debug keyboard disabled.\n"); | ||
| 285 | _delay_ms(1000); | ||
| 286 | break; | ||
| 287 | case KB_M: // debug mouse toggle | ||
| 288 | usb_keyboard_clear_report(); | ||
| 289 | usb_keyboard_send(); | ||
| 290 | debug_mouse = !debug_mouse; | ||
| 291 | if (debug_mouse) | ||
| 292 | print("debug mouse enabled.\n"); | ||
| 293 | else | ||
| 294 | print("debug mouse disabled.\n"); | ||
| 295 | _delay_ms(1000); | ||
| 296 | break; | ||
| 297 | case KB_V: // print version & information | ||
| 298 | usb_keyboard_clear_report(); | ||
| 299 | usb_keyboard_send(); | ||
| 300 | print_enable = true; | ||
| 301 | print(STR(DESCRIPTION) "\n"); | ||
| 302 | _delay_ms(1000); | ||
| 303 | break; | ||
| 304 | case KB_T: // print timer | ||
| 305 | usb_keyboard_clear_report(); | ||
| 306 | usb_keyboard_send(); | ||
| 307 | print_enable = true; | ||
| 308 | print("timer: "); phex16(timer_count); print("\n"); | ||
| 309 | _delay_ms(500); | ||
| 310 | break; | ||
| 311 | case KB_P: // print toggle | ||
| 312 | usb_keyboard_clear_report(); | ||
| 313 | usb_keyboard_send(); | ||
| 314 | if (print_enable) { | ||
| 315 | print("print disabled.\n"); | ||
| 316 | print_enable = false; | ||
| 317 | } else { | ||
| 318 | print_enable = true; | ||
| 319 | print("print enabled.\n"); | ||
| 320 | } | ||
| 321 | _delay_ms(1000); | ||
| 322 | break; | ||
| 323 | case KB_S: | ||
| 324 | usb_keyboard_clear_report(); | ||
| 325 | usb_keyboard_send(); | ||
| 326 | print("UDCON: "); phex(UDCON); print("\n"); | ||
| 327 | print("UDIEN: "); phex(UDIEN); print("\n"); | ||
| 328 | print("UDINT: "); phex(UDINT); print("\n"); | ||
| 329 | print("usb_keyboard_leds:"); phex(usb_keyboard_leds); print("\n"); | ||
| 330 | print("usb_keyboard_protocol:"); phex(usb_keyboard_protocol); print("\n"); | ||
| 331 | print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n"); | ||
| 332 | print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n"); | ||
| 333 | #ifdef USB_MOUSE_ENABLE | ||
| 334 | print("usb_mouse_protocol:"); phex(usb_mouse_protocol); print("\n"); | ||
| 335 | #endif | ||
| 336 | if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n"); | ||
| 337 | _delay_ms(500); | ||
| 338 | break; | ||
| 339 | case KB_GRV: | ||
| 340 | usb_keyboard_clear_report(); | ||
| 341 | usb_keyboard_send(); | ||
| 342 | usb_keyboard_protocol = !usb_keyboard_protocol; | ||
| 343 | print("keyboard protcol: "); | ||
| 344 | if (usb_keyboard_protocol) print("report"); else print("boot"); | ||
| 345 | print("\n"); | ||
| 346 | |||
| 347 | #ifdef USB_MOUSE_ENABLE | ||
| 348 | usb_mouse_protocol = !usb_mouse_protocol; | ||
| 349 | print("mouse protcol: "); | ||
| 350 | if (usb_mouse_protocol) print("report"); else print("boot"); | ||
| 351 | print("\n"); | ||
| 352 | #endif | ||
| 353 | _delay_ms(1000); | ||
| 354 | break; | ||
| 355 | #ifdef USB_NKRO_ENABLE | ||
| 356 | case KB_N: | ||
| 357 | usb_keyboard_clear_report(); | ||
| 358 | usb_keyboard_send(); | ||
| 359 | usb_keyboard_nkro = !usb_keyboard_nkro; | ||
| 360 | if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n"); | ||
| 361 | _delay_ms(1000); | ||
| 362 | break; | ||
| 363 | #endif | ||
| 364 | #ifdef USB_EXTRA_ENABLE | ||
| 365 | case KB_ESC: | ||
| 366 | usb_keyboard_clear_report(); | ||
| 367 | usb_keyboard_send(); | ||
| 368 | if (suspend && remote_wakeup) { | ||
| 369 | usb_remote_wakeup(); | ||
| 370 | } else { | ||
| 371 | usb_extra_system_send(SYSTEM_POWER_DOWN); | ||
| 372 | } | ||
| 373 | _delay_ms(1000); | ||
| 374 | break; | ||
| 375 | #endif | ||
| 376 | } | ||
| 377 | } | ||
| 378 | |||
| 379 | |||
| 380 | if (modified) { | ||
| 381 | usb_keyboard_send(); | ||
| 382 | } | ||
| 383 | |||
| 384 | #ifdef MOUSEKEY_ENABLE | ||
| 385 | mousekey_usb_send(); | ||
| 386 | #endif | ||
| 387 | |||
| 388 | #ifdef PS2_MOUSE_ENABLE | ||
| 389 | if (ps2_mouse_read() == 0) | ||
| 390 | ps2_mouse_usb_send(); | ||
| 391 | #endif | ||
| 392 | } | ||
diff --git a/key_process.h b/key_process.h deleted file mode 100644 index bfc0218f3..000000000 --- a/key_process.h +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | #ifndef KEY_PROCESS_H | ||
| 2 | #define KEY_PROCESS_H 1 | ||
| 3 | |||
| 4 | |||
| 5 | void proc_matrix(void); | ||
| 6 | |||
| 7 | #endif | ||
diff --git a/keyboard.c b/keyboard.c index 25948ddf7..03db3257a 100644 --- a/keyboard.c +++ b/keyboard.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #include "keyboard.h" | 1 | #include "keyboard.h" |
| 2 | #include "host.h" | 2 | #include "host.h" |
| 3 | #include "layer.h" | 3 | #include "layer.h" |
| 4 | #include "matrix_skel.h" | 4 | #include "matrix.h" |
| 5 | #include "led.h" | 5 | #include "led.h" |
| 6 | #include "usb_keycodes.h" | 6 | #include "usb_keycodes.h" |
| 7 | #include "timer.h" | 7 | #include "timer.h" |
| @@ -11,6 +11,11 @@ | |||
| 11 | #ifdef MOUSEKEY_ENABLE | 11 | #ifdef MOUSEKEY_ENABLE |
| 12 | #include "mousekey.h" | 12 | #include "mousekey.h" |
| 13 | #endif | 13 | #endif |
| 14 | /* TODO: shoud make new API */ | ||
| 15 | #ifdef USB_EXTRA_ENABLE | ||
| 16 | #include "usb_extra.h" | ||
| 17 | #include <util/delay.h> | ||
| 18 | #endif | ||
| 14 | 19 | ||
| 15 | 20 | ||
| 16 | static uint8_t last_leds = 0; | 21 | static uint8_t last_leds = 0; |
| @@ -61,7 +66,6 @@ void keyboard_proc(void) | |||
| 61 | fn_bits |= FN_BIT(code); | 66 | fn_bits |= FN_BIT(code); |
| 62 | } | 67 | } |
| 63 | #ifdef USB_EXTRA_ENABLE | 68 | #ifdef USB_EXTRA_ENABLE |
| 64 | /* TODO: use new API | ||
| 65 | // audio control & system control | 69 | // audio control & system control |
| 66 | else if (code == KB_MUTE) { | 70 | else if (code == KB_MUTE) { |
| 67 | usb_extra_audio_send(AUDIO_MUTE); | 71 | usb_extra_audio_send(AUDIO_MUTE); |
| @@ -83,7 +87,6 @@ void keyboard_proc(void) | |||
| 83 | } | 87 | } |
| 84 | _delay_ms(1000); | 88 | _delay_ms(1000); |
| 85 | } | 89 | } |
| 86 | */ | ||
| 87 | #endif | 90 | #endif |
| 88 | else if (IS_KEY(code)) { | 91 | else if (IS_KEY(code)) { |
| 89 | host_add_key(code); | 92 | host_add_key(code); |
| @@ -102,7 +105,6 @@ void keyboard_proc(void) | |||
| 102 | layer_switching(fn_bits); | 105 | layer_switching(fn_bits); |
| 103 | 106 | ||
| 104 | if (command_proc()) { | 107 | if (command_proc()) { |
| 105 | // not send report | ||
| 106 | return; | 108 | return; |
| 107 | } | 109 | } |
| 108 | 110 | ||
diff --git a/keymap_skel.h b/keymap.h index 300801ff6..79ef0359d 100644 --- a/keymap_skel.h +++ b/keymap.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #ifndef KEYMAP_SKEL_H | 1 | #ifndef KEYMAP_H |
| 2 | #define KEYMAP_SKEL_H 1 | 2 | #define KEYMAP_H |
| 3 | 3 | ||
| 4 | #include <stdint.h> | 4 | #include <stdint.h> |
| 5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| @@ -15,7 +15,4 @@ uint8_t keymap_fn_layer(uint8_t fn_bits); | |||
| 15 | /* keycode to send when release Fn key without using */ | 15 | /* keycode to send when release Fn key without using */ |
| 16 | uint8_t keymap_fn_keycode(uint8_t fn_bits); | 16 | uint8_t keymap_fn_keycode(uint8_t fn_bits); |
| 17 | 17 | ||
| 18 | /* whether special key combination */ | ||
| 19 | bool keymap_is_special_mode(uint8_t fn_bits); | ||
| 20 | |||
| 21 | #endif | 18 | #endif |
| @@ -1,4 +1,4 @@ | |||
| 1 | #include "keymap_skel.h" | 1 | #include "keymap.h" |
| 2 | #include "host.h" | 2 | #include "host.h" |
| 3 | #include "debug.h" | 3 | #include "debug.h" |
| 4 | #include "timer.h" | 4 | #include "timer.h" |
diff --git a/main_pjrc.c b/main_pjrc.c new file mode 100644 index 000000000..18a05ffdf --- /dev/null +++ b/main_pjrc.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* 2010/08/23 noname | ||
| 2 | * keyboard firmware based on PJRC USB keyboard example | ||
| 3 | */ | ||
| 4 | /* Keyboard example with debug channel, for Teensy USB Development Board | ||
| 5 | * http://www.pjrc.com/teensy/usb_keyboard.html | ||
| 6 | * Copyright (c) 2008 PJRC.COM, LLC | ||
| 7 | * | ||
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 9 | * of this software and associated documentation files (the "Software"), to deal | ||
| 10 | * in the Software without restriction, including without limitation the rights | ||
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 12 | * copies of the Software, and to permit persons to whom the Software is | ||
| 13 | * furnished to do so, subject to the following conditions: | ||
| 14 | * | ||
| 15 | * The above copyright notice and this permission notice shall be included in | ||
| 16 | * all copies or substantial portions of the Software. | ||
| 17 | * | ||
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 24 | * THE SOFTWARE. | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include <stdbool.h> | ||
| 28 | #include <avr/io.h> | ||
| 29 | #include <avr/interrupt.h> | ||
| 30 | #include <util/delay.h> | ||
| 31 | #include "keyboard.h" | ||
| 32 | #include "usb.h" | ||
| 33 | #include "matrix.h" | ||
| 34 | #include "print.h" | ||
| 35 | #include "debug.h" | ||
| 36 | #include "util.h" | ||
| 37 | #include "jump_bootloader.h" | ||
| 38 | #ifdef PS2_MOUSE_ENABLE | ||
| 39 | # include "ps2_mouse.h" | ||
| 40 | #endif | ||
| 41 | |||
| 42 | |||
| 43 | #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) | ||
| 44 | |||
| 45 | |||
| 46 | bool debug_enable = false; | ||
| 47 | bool debug_matrix = false; | ||
| 48 | bool debug_keyboard = false; | ||
| 49 | bool debug_mouse = false; | ||
| 50 | |||
| 51 | |||
| 52 | int main(void) | ||
| 53 | { | ||
| 54 | DEBUG_LED_CONFIG; | ||
| 55 | DEBUG_LED_OFF; | ||
| 56 | |||
| 57 | // set for 16 MHz clock | ||
| 58 | CPU_PRESCALE(0); | ||
| 59 | |||
| 60 | // Initialize the USB, and then wait for the host to set configuration. | ||
| 61 | // If the Teensy is powered without a PC connected to the USB port, | ||
| 62 | // this will wait forever. | ||
| 63 | usb_init(); | ||
| 64 | while (!usb_configured()) /* wait */ ; | ||
| 65 | |||
| 66 | keyboard_init(); | ||
| 67 | matrix_scan(); | ||
| 68 | if (matrix_key_count() >= 3) { | ||
| 69 | #ifdef DEBUG_LED | ||
| 70 | for (int i = 0; i < 6; i++) { | ||
| 71 | DEBUG_LED_CONFIG; | ||
| 72 | DEBUG_LED_ON; | ||
| 73 | _delay_ms(500); | ||
| 74 | DEBUG_LED_OFF; | ||
| 75 | _delay_ms(500); | ||
| 76 | } | ||
| 77 | #else | ||
| 78 | _delay_ms(5000); | ||
| 79 | #endif | ||
| 80 | print_enable = true; | ||
| 81 | debug_enable = true; | ||
| 82 | debug_matrix = true; | ||
| 83 | debug_keyboard = true; | ||
| 84 | debug_mouse = true; | ||
| 85 | print("debug enabled.\n"); | ||
| 86 | } | ||
| 87 | if (matrix_key_count() >= 4) { | ||
| 88 | print("jump to bootloader...\n"); | ||
| 89 | _delay_ms(1000); | ||
| 90 | jump_bootloader(); // not return | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | while (1) { | ||
| 95 | keyboard_proc(); | ||
| 96 | } | ||
| 97 | } | ||
diff --git a/matrix_skel.h b/matrix.h index 2379ce44a..1bcd0915f 100644 --- a/matrix_skel.h +++ b/matrix.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #ifndef MATRIX_SKEL_H | 1 | #ifndef MATRIX_H |
| 2 | #define MATRIX_SKEL_H 1 | 2 | #define MATRIX_H |
| 3 | 3 | ||
| 4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
| 5 | 5 | ||
| @@ -187,6 +187,9 @@ static inline void pbuf_enqueue(uint8_t data) | |||
| 187 | { | 187 | { |
| 188 | if (!data) | 188 | if (!data) |
| 189 | return; | 189 | return; |
| 190 | |||
| 191 | uint8_t sreg = SREG; | ||
| 192 | cli(); | ||
| 190 | uint8_t next = (pbuf_head + 1) % PBUF_SIZE; | 193 | uint8_t next = (pbuf_head + 1) % PBUF_SIZE; |
| 191 | if (next != pbuf_tail) { | 194 | if (next != pbuf_tail) { |
| 192 | pbuf[pbuf_head] = data; | 195 | pbuf[pbuf_head] = data; |
| @@ -194,10 +197,12 @@ static inline void pbuf_enqueue(uint8_t data) | |||
| 194 | } else { | 197 | } else { |
| 195 | debug("pbuf: full\n"); | 198 | debug("pbuf: full\n"); |
| 196 | } | 199 | } |
| 200 | SREG = sreg; | ||
| 197 | } | 201 | } |
| 198 | static inline uint8_t pbuf_dequeue(void) | 202 | static inline uint8_t pbuf_dequeue(void) |
| 199 | { | 203 | { |
| 200 | uint8_t val = 0; | 204 | uint8_t val = 0; |
| 205 | |||
| 201 | uint8_t sreg = SREG; | 206 | uint8_t sreg = SREG; |
| 202 | cli(); | 207 | cli(); |
| 203 | if (pbuf_head != pbuf_tail) { | 208 | if (pbuf_head != pbuf_tail) { |
| @@ -205,17 +210,20 @@ static inline uint8_t pbuf_dequeue(void) | |||
| 205 | pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE; | 210 | pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE; |
| 206 | } | 211 | } |
| 207 | SREG = sreg; | 212 | SREG = sreg; |
| 213 | |||
| 208 | return val; | 214 | return val; |
| 209 | } | 215 | } |
| 210 | 216 | ||
| 211 | /* get data received by interrupt */ | 217 | /* get data received by interrupt */ |
| 212 | uint8_t ps2_host_recv(void) | 218 | uint8_t ps2_host_recv(void) |
| 213 | { | 219 | { |
| 214 | // TODO: release clock line after 100us when inhibited by error | ||
| 215 | if (ps2_error) { | 220 | if (ps2_error) { |
| 221 | print("x"); | ||
| 222 | phex(ps2_error); | ||
| 216 | ps2_host_send(0xFE); // request to resend | 223 | ps2_host_send(0xFE); // request to resend |
| 217 | ps2_error = PS2_ERR_NONE; | 224 | ps2_error = PS2_ERR_NONE; |
| 218 | } | 225 | } |
| 226 | idle(); | ||
| 219 | return pbuf_dequeue(); | 227 | return pbuf_dequeue(); |
| 220 | } | 228 | } |
| 221 | 229 | ||
| @@ -281,7 +289,7 @@ ISR(PS2_INT_VECT) | |||
| 281 | } | 289 | } |
| 282 | goto RETURN; | 290 | goto RETURN; |
| 283 | ERROR: | 291 | ERROR: |
| 284 | DEBUGP(0xFF); | 292 | DEBUGP(0x0F); |
| 285 | inhibit(); | 293 | inhibit(); |
| 286 | ps2_error = state; | 294 | ps2_error = state; |
| 287 | DONE: | 295 | DONE: |
diff --git a/ps2_usb/Makefile b/ps2_usb/Makefile index bd9a76eb8..af73be2c9 100644 --- a/ps2_usb/Makefile +++ b/ps2_usb/Makefile | |||
| @@ -1,46 +1,5 @@ | |||
| 1 | # Hey Emacs, this is a -*- makefile -*- | ||
| 2 | #---------------------------------------------------------------------------- | ||
| 3 | # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. | ||
| 4 | # | ||
| 5 | # Released to the Public Domain | ||
| 6 | # | ||
| 7 | # Additional material for this makefile was written by: | ||
| 8 | # Peter Fleury | ||
| 9 | # Tim Henigan | ||
| 10 | # Colin O'Flynn | ||
| 11 | # Reiner Patommel | ||
| 12 | # Markus Pfaff | ||
| 13 | # Sander Pool | ||
| 14 | # Frederik Rouleau | ||
| 15 | # Carlos Lamas | ||
| 16 | # | ||
| 17 | #---------------------------------------------------------------------------- | ||
| 18 | # On command line: | ||
| 19 | # | ||
| 20 | # make all = Make software. | ||
| 21 | # | ||
| 22 | # make clean = Clean out built project files. | ||
| 23 | # | ||
| 24 | # make coff = Convert ELF to AVR COFF. | ||
| 25 | # | ||
| 26 | # make extcoff = Convert ELF to AVR Extended COFF. | ||
| 27 | # | ||
| 28 | # make program = Download the hex file to the device, using avrdude. | ||
| 29 | # Please customize the avrdude settings below first! | ||
| 30 | # | ||
| 31 | # make debug = Start either simulavr or avarice as specified for debugging, | ||
| 32 | # with avr-gdb or avr-insight as the front end for debugging. | ||
| 33 | # | ||
| 34 | # make filename.s = Just compile filename.c into the assembler code only. | ||
| 35 | # | ||
| 36 | # make filename.i = Create a preprocessed source file for use in submitting | ||
| 37 | # bug reports to the GCC project. | ||
| 38 | # | ||
| 39 | # To rebuild project do "make clean" then "make all". | ||
| 40 | #---------------------------------------------------------------------------- | ||
| 41 | |||
| 42 | # Target file name (without extension). | 1 | # Target file name (without extension). |
| 43 | TARGET = tmk_ps2_usb | 2 | TARGET = ps2_usb |
| 44 | 3 | ||
| 45 | # Directory common source filess exist | 4 | # Directory common source filess exist |
| 46 | COMMON_DIR = .. | 5 | COMMON_DIR = .. |
| @@ -49,10 +8,14 @@ COMMON_DIR = .. | |||
| 49 | TARGET_DIR = . | 8 | TARGET_DIR = . |
| 50 | 9 | ||
| 51 | # keyboard dependent files | 10 | # keyboard dependent files |
| 52 | TARGET_SRC = keymap.c \ | 11 | TARGET_SRC = main_pjrc.c \ |
| 12 | keymap.c \ | ||
| 53 | matrix.c \ | 13 | matrix.c \ |
| 14 | led.c \ | ||
| 54 | ps2.c | 15 | ps2.c |
| 55 | 16 | ||
| 17 | CONFIG_H = config_pjrc.h | ||
| 18 | |||
| 56 | 19 | ||
| 57 | # MCU name, you MUST set this to match the board you are using | 20 | # MCU name, you MUST set this to match the board you are using |
| 58 | # type "make clean" after changing this, so all files will be rebuilt | 21 | # type "make clean" after changing this, so all files will be rebuilt |
| @@ -78,4 +41,11 @@ USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System c | |||
| 78 | USB_NKRO_ENABLE = yes # USB Nkey Rollover | 41 | USB_NKRO_ENABLE = yes # USB Nkey Rollover |
| 79 | 42 | ||
| 80 | 43 | ||
| 44 | |||
| 45 | #---------------- Programming Options -------------------------- | ||
| 46 | PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex | ||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | include $(COMMON_DIR)/Makefile.pjrc | ||
| 81 | include $(COMMON_DIR)/Makefile.common | 51 | include $(COMMON_DIR)/Makefile.common |
diff --git a/ps2_vusb/Makefile b/ps2_usb/Makefile.vusb index 6901d1f5c..7b69dc27b 100644 --- a/ps2_vusb/Makefile +++ b/ps2_usb/Makefile.vusb | |||
| @@ -8,7 +8,7 @@ COMMON_DIR = .. | |||
| 8 | TARGET_DIR = . | 8 | TARGET_DIR = . |
| 9 | 9 | ||
| 10 | # keyboard dependent files | 10 | # keyboard dependent files |
| 11 | TARGET_SRC = main.c \ | 11 | TARGET_SRC = main_vusb.c \ |
| 12 | keymap.c \ | 12 | keymap.c \ |
| 13 | matrix.c \ | 13 | matrix.c \ |
| 14 | led.c \ | 14 | led.c \ |
| @@ -16,6 +16,9 @@ TARGET_SRC = main.c \ | |||
| 16 | sendchar_dummy.c | 16 | sendchar_dummy.c |
| 17 | # sendchar_usart.c | 17 | # sendchar_usart.c |
| 18 | 18 | ||
| 19 | CONFIG_H = config_vusb.h | ||
| 20 | |||
| 21 | |||
| 19 | OPT_DEFS = -DDEBUG_LEVEL=0 | 22 | OPT_DEFS = -DDEBUG_LEVEL=0 |
| 20 | 23 | ||
| 21 | 24 | ||
| @@ -45,7 +48,8 @@ MOUSEKEY_ENABLE = yes # Mouse keys | |||
| 45 | 48 | ||
| 46 | 49 | ||
| 47 | 50 | ||
| 48 | #---------------- Programming Options (avrdude) ---------------- | 51 | #---------------- Programming Options -------------------------- |
| 52 | AVRDUDE = avrdude | ||
| 49 | # Type: avrdude -c ? to get a full listing. | 53 | # Type: avrdude -c ? to get a full listing. |
| 50 | AVRDUDE_PROGRAMMER = usbasp | 54 | AVRDUDE_PROGRAMMER = usbasp |
| 51 | AVRDUDE_PORT = | 55 | AVRDUDE_PORT = |
| @@ -72,6 +76,8 @@ AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) | |||
| 72 | AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) | 76 | AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
| 73 | AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) | 77 | AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
| 74 | 78 | ||
| 79 | PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) | ||
| 80 | |||
| 75 | 81 | ||
| 76 | 82 | ||
| 77 | include $(COMMON_DIR)/Makefile.vusb | 83 | include $(COMMON_DIR)/Makefile.vusb |
diff --git a/ps2_usb/README b/ps2_usb/README index 3c9eb1428..ad5c6c431 100644 --- a/ps2_usb/README +++ b/ps2_usb/README | |||
| @@ -47,10 +47,10 @@ Keymap customization | |||
| 47 | You can customize keymaps easily by editing source code. | 47 | You can customize keymaps easily by editing source code. |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | Build | 50 | Build for Teensy |
| 51 | ----- | 51 | ---------------- |
| 52 | 0. Connect PS/2 keyboard to Teensy by 4 lines(Vcc, GND, Data, Clock). | 52 | 0. Connect PS/2 keyboard to Teensy by 4 lines(Vcc, GND, Data, Clock). |
| 53 | 1. Define following macros for PS/2 connection in config.h: | 53 | 1. Define following macros for PS/2 connection in config_pjrc.h: |
| 54 | PS2_DATA_PORT | 54 | PS2_DATA_PORT |
| 55 | PS2_DATA_PIN | 55 | PS2_DATA_PIN |
| 56 | PS2_DATA_DDR | 56 | PS2_DATA_DDR |
| @@ -65,6 +65,15 @@ Build | |||
| 65 | http://www.pjrc.com/teensy/loader.html | 65 | http://www.pjrc.com/teensy/loader.html |
| 66 | 66 | ||
| 67 | 67 | ||
| 68 | Build for V-USB | ||
| 69 | --------------- | ||
| 70 | 0. Build V-USB controller board and connect PS/2 keyboard. | ||
| 71 | 1. Define macros in config_vusb.h if needed. | ||
| 72 | 2. Edit Makefile.vusb for build options and MCU setting. | ||
| 73 | 3. make -f Makefile.vusb | ||
| 74 | 4. program your V-USB controller. | ||
| 75 | |||
| 76 | |||
| 68 | Keymap | 77 | Keymap |
| 69 | ------ | 78 | ------ |
| 70 | You can change a keymap by editing code of keymap.c like following. | 79 | You can change a keymap by editing code of keymap.c like following. |
diff --git a/ps2_usb/config.h b/ps2_usb/config_pjrc.h index be96f004a..6205c4801 100644 --- a/ps2_usb/config.h +++ b/ps2_usb/config_pjrc.h | |||
| @@ -10,22 +10,26 @@ | |||
| 10 | #define PRODUCT PS/2 keyboard converter | 10 | #define PRODUCT PS/2 keyboard converter |
| 11 | #define DESCRIPTION convert PS/2 keyboard to USB | 11 | #define DESCRIPTION convert PS/2 keyboard to USB |
| 12 | 12 | ||
| 13 | |||
| 13 | /* matrix size */ | 14 | /* matrix size */ |
| 14 | #define MATRIX_ROWS 32 // keycode bit: 3-0 | 15 | #define MATRIX_ROWS 32 // keycode bit: 3-0 |
| 15 | #define MATRIX_COLS 8 // keycode bit: 6-4 | 16 | #define MATRIX_COLS 8 // keycode bit: 6-4 |
| 16 | /* define if matrix has ghost */ | ||
| 17 | //#define MATRIX_HAS_GHOST | ||
| 18 | 17 | ||
| 19 | /* USB NKey Rollover */ | 18 | |
| 20 | #ifdef USB_NKRO_ENABLE | 19 | /* key combination for command */ |
| 21 | #endif | 20 | #define IS_COMMAND() ( \ |
| 21 | keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ | ||
| 22 | keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ | ||
| 23 | ) | ||
| 24 | |||
| 22 | 25 | ||
| 23 | /* mouse keys */ | 26 | /* mouse keys */ |
| 24 | #ifdef MOUSEKEY_ENABLE | 27 | #ifdef MOUSEKEY_ENABLE |
| 25 | # define MOUSEKEY_DELAY_TIME 255 | 28 | # define MOUSEKEY_DELAY_TIME 255 |
| 26 | #endif | 29 | #endif |
| 27 | 30 | ||
| 28 | /* PS/2 mouse */ | 31 | |
| 32 | /* PS/2 lines */ | ||
| 29 | #define PS2_CLOCK_PORT PORTF | 33 | #define PS2_CLOCK_PORT PORTF |
| 30 | #define PS2_CLOCK_PIN PINF | 34 | #define PS2_CLOCK_PIN PINF |
| 31 | #define PS2_CLOCK_DDR DDRF | 35 | #define PS2_CLOCK_DDR DDRF |
diff --git a/ps2_vusb/config.h b/ps2_usb/config_vusb.h index 9447dd936..0463f68ba 100644 --- a/ps2_vusb/config.h +++ b/ps2_usb/config_vusb.h | |||
| @@ -10,10 +10,12 @@ | |||
| 10 | #define PRODUCT PS/2 keyboard converter | 10 | #define PRODUCT PS/2 keyboard converter |
| 11 | #define DESCRIPTION convert PS/2 keyboard to USB | 11 | #define DESCRIPTION convert PS/2 keyboard to USB |
| 12 | 12 | ||
| 13 | |||
| 13 | /* matrix size */ | 14 | /* matrix size */ |
| 14 | #define MATRIX_ROWS 32 // keycode bit: 3-0 | 15 | #define MATRIX_ROWS 32 // keycode bit: 3-0 |
| 15 | #define MATRIX_COLS 8 // keycode bit: 6-4 | 16 | #define MATRIX_COLS 8 // keycode bit: 6-4 |
| 16 | 17 | ||
| 18 | |||
| 17 | /* key combination for command */ | 19 | /* key combination for command */ |
| 18 | #define IS_COMMAND() ( \ | 20 | #define IS_COMMAND() ( \ |
| 19 | keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ | 21 | keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ |
| @@ -21,10 +23,6 @@ | |||
| 21 | ) | 23 | ) |
| 22 | 24 | ||
| 23 | 25 | ||
| 24 | /* USB NKey Rollover */ | ||
| 25 | #ifdef USB_NKRO_ENABLE | ||
| 26 | #endif | ||
| 27 | |||
| 28 | /* mouse keys */ | 26 | /* mouse keys */ |
| 29 | #ifdef MOUSEKEY_ENABLE | 27 | #ifdef MOUSEKEY_ENABLE |
| 30 | # define MOUSEKEY_DELAY_TIME 255 | 28 | # define MOUSEKEY_DELAY_TIME 255 |
diff --git a/ps2_usb/keymap.c b/ps2_usb/keymap.c index 47db18bfa..253351f69 100644 --- a/ps2_usb/keymap.c +++ b/ps2_usb/keymap.c | |||
| @@ -4,12 +4,11 @@ | |||
| 4 | #include <stdint.h> | 4 | #include <stdint.h> |
| 5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| 6 | #include <avr/pgmspace.h> | 6 | #include <avr/pgmspace.h> |
| 7 | #include "usb_keyboard.h" | ||
| 8 | #include "usb_keycodes.h" | 7 | #include "usb_keycodes.h" |
| 9 | #include "print.h" | 8 | #include "print.h" |
| 10 | #include "debug.h" | 9 | #include "debug.h" |
| 11 | #include "util.h" | 10 | #include "util.h" |
| 12 | #include "keymap_skel.h" | 11 | #include "keymap.h" |
| 13 | 12 | ||
| 14 | 13 | ||
| 15 | #define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) | 14 | #define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) |
| @@ -181,9 +180,3 @@ uint8_t keymap_fn_keycode(uint8_t fn_bits) | |||
| 181 | { | 180 | { |
| 182 | return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); | 181 | return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); |
| 183 | } | 182 | } |
| 184 | |||
| 185 | // define a condition to enter special function mode | ||
| 186 | bool keymap_is_special_mode(uint8_t fn_bits) | ||
| 187 | { | ||
| 188 | return usb_keyboard_mods == (BIT_LSHIFT | BIT_RSHIFT) || usb_keyboard_mods == (BIT_LCTRL | BIT_RSHIFT); | ||
| 189 | } | ||
diff --git a/ps2_vusb/led.c b/ps2_usb/led.c index d69b1c675..d69b1c675 100644 --- a/ps2_vusb/led.c +++ b/ps2_usb/led.c | |||
diff --git a/ps2_vusb/main.c b/ps2_usb/main_vusb.c index 1ffe5e6ec..ec7c5797a 100644 --- a/ps2_vusb/main.c +++ b/ps2_usb/main_vusb.c | |||
| @@ -46,10 +46,10 @@ int main(void) | |||
| 46 | _delay_ms(1); | 46 | _delay_ms(1); |
| 47 | } | 47 | } |
| 48 | usbDeviceConnect(); | 48 | usbDeviceConnect(); |
| 49 | sei(); | ||
| 50 | 49 | ||
| 51 | keyboard_init(); | 50 | keyboard_init(); |
| 52 | 51 | ||
| 52 | sei(); | ||
| 53 | while (1) { | 53 | while (1) { |
| 54 | DEBUGP(0x1); | 54 | DEBUGP(0x1); |
| 55 | wdt_reset(); | 55 | wdt_reset(); |
diff --git a/ps2_usb/matrix.c b/ps2_usb/matrix.c index aaf89719e..52479d975 100644 --- a/ps2_usb/matrix.c +++ b/ps2_usb/matrix.c | |||
| @@ -9,8 +9,7 @@ | |||
| 9 | #include "util.h" | 9 | #include "util.h" |
| 10 | #include "debug.h" | 10 | #include "debug.h" |
| 11 | #include "ps2.h" | 11 | #include "ps2.h" |
| 12 | #include "usb_keyboard.h" | 12 | #include "matrix.h" |
| 13 | #include "matrix_skel.h" | ||
| 14 | 13 | ||
| 15 | 14 | ||
| 16 | #if (MATRIX_COLS > 16) | 15 | #if (MATRIX_COLS > 16) |
| @@ -60,8 +59,6 @@ static bool matrix_has_ghost_in_row(uint8_t row); | |||
| 60 | #endif | 59 | #endif |
| 61 | static void matrix_make(uint8_t code); | 60 | static void matrix_make(uint8_t code); |
| 62 | static void matrix_break(uint8_t code); | 61 | static void matrix_break(uint8_t code); |
| 63 | static void ps2_reset(void); | ||
| 64 | static void ps2_set_leds(uint8_t leds); | ||
| 65 | 62 | ||
| 66 | 63 | ||
| 67 | inline | 64 | inline |
| @@ -78,20 +75,8 @@ uint8_t matrix_cols(void) | |||
| 78 | 75 | ||
| 79 | void matrix_init(void) | 76 | void matrix_init(void) |
| 80 | { | 77 | { |
| 81 | print_enable = true; | ||
| 82 | ps2_host_init(); | 78 | ps2_host_init(); |
| 83 | 79 | ||
| 84 | ps2_reset(); | ||
| 85 | |||
| 86 | // flush LEDs | ||
| 87 | ps2_set_leds(1<<PS2_LED_NUM_LOCK); | ||
| 88 | _delay_ms(100); | ||
| 89 | ps2_set_leds(1<<PS2_LED_NUM_LOCK|1<<PS2_LED_CAPS_LOCK); | ||
| 90 | _delay_ms(100); | ||
| 91 | ps2_set_leds(1<<PS2_LED_NUM_LOCK|1<<PS2_LED_CAPS_LOCK|1<<PS2_LED_SCROLL_LOCK); | ||
| 92 | _delay_ms(300); | ||
| 93 | ps2_set_leds(0x00); | ||
| 94 | |||
| 95 | // initialize matrix state: all keys off | 80 | // initialize matrix state: all keys off |
| 96 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; | 81 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; |
| 97 | 82 | ||
| @@ -191,7 +176,6 @@ uint8_t matrix_scan(void) | |||
| 191 | 176 | ||
| 192 | uint8_t code; | 177 | uint8_t code; |
| 193 | while ((code = ps2_host_recv())) { | 178 | while ((code = ps2_host_recv())) { |
| 194 | debug_hex(code); debug(" "); | ||
| 195 | switch (state) { | 179 | switch (state) { |
| 196 | case INIT: | 180 | case INIT: |
| 197 | switch (code) { | 181 | switch (code) { |
| @@ -349,22 +333,6 @@ debug_hex(code); debug(" "); | |||
| 349 | state = INIT; | 333 | state = INIT; |
| 350 | } | 334 | } |
| 351 | } | 335 | } |
| 352 | |||
| 353 | // handle LED indicators | ||
| 354 | static uint8_t prev_leds = 0; | ||
| 355 | if (prev_leds != usb_keyboard_leds) { | ||
| 356 | uint8_t leds = 0; | ||
| 357 | if (usb_keyboard_leds&(1<<USB_LED_SCROLL_LOCK)) | ||
| 358 | leds |= (1<<PS2_LED_SCROLL_LOCK); | ||
| 359 | if (usb_keyboard_leds&(1<<USB_LED_NUM_LOCK)) | ||
| 360 | leds |= (1<<PS2_LED_NUM_LOCK); | ||
| 361 | if (usb_keyboard_leds&(1<<USB_LED_CAPS_LOCK)) | ||
| 362 | leds |= (1<<PS2_LED_CAPS_LOCK); | ||
| 363 | |||
| 364 | ps2_set_leds(leds); | ||
| 365 | prev_leds = usb_keyboard_leds; | ||
| 366 | } | ||
| 367 | |||
| 368 | return 1; | 336 | return 1; |
| 369 | } | 337 | } |
| 370 | 338 | ||
| @@ -472,19 +440,3 @@ static void matrix_break(uint8_t code) | |||
| 472 | is_modified = true; | 440 | is_modified = true; |
| 473 | } | 441 | } |
| 474 | } | 442 | } |
| 475 | |||
| 476 | static void ps2_reset(void) | ||
| 477 | { | ||
| 478 | ps2_host_send(0xFF); | ||
| 479 | ps2_host_recv(); // 0xFA | ||
| 480 | ps2_host_recv(); // 0xAA | ||
| 481 | _delay_ms(1000); | ||
| 482 | } | ||
| 483 | |||
| 484 | static void ps2_set_leds(uint8_t leds) | ||
| 485 | { | ||
| 486 | ps2_host_send(0xED); | ||
| 487 | ps2_host_recv(); // 0xFA | ||
| 488 | ps2_host_send(leds); | ||
| 489 | ps2_host_recv(); // 0xFA | ||
| 490 | } | ||
diff --git a/ps2_vusb/ps2_usart.c b/ps2_usb/ps2_usart.c index e45b94c93..e45b94c93 100644 --- a/ps2_vusb/ps2_usart.c +++ b/ps2_usb/ps2_usart.c | |||
diff --git a/ps2_vusb/sendchar_dummy.c b/ps2_usb/sendchar_dummy.c index 8c9e583f1..8c9e583f1 100644 --- a/ps2_vusb/sendchar_dummy.c +++ b/ps2_usb/sendchar_dummy.c | |||
diff --git a/ps2_vusb/sendchar_usart.c b/ps2_usb/sendchar_usart.c index fe18177a3..fe18177a3 100644 --- a/ps2_vusb/sendchar_usart.c +++ b/ps2_usb/sendchar_usart.c | |||
diff --git a/ps2_vusb/usbconfig.h b/ps2_usb/usbconfig.h index 34807066f..9038f1eb8 100644 --- a/ps2_vusb/usbconfig.h +++ b/ps2_usb/usbconfig.h | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #ifndef __usbconfig_h_included__ | 11 | #ifndef __usbconfig_h_included__ |
| 12 | #define __usbconfig_h_included__ | 12 | #define __usbconfig_h_included__ |
| 13 | 13 | ||
| 14 | #include "config.h" | 14 | #include "config_vusb.h" |
| 15 | 15 | ||
| 16 | /* | 16 | /* |
| 17 | General Description: | 17 | General Description: |
diff --git a/ps2_vusb/README b/ps2_vusb/README deleted file mode 100644 index 7d4512a48..000000000 --- a/ps2_vusb/README +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | PS/2 to USB keyboard converter with V-USB | ||
| 2 | ========================================= | ||
| 3 | 2011/02/07 | ||
| 4 | |||
| 5 | NOT COMPLETED | ||
| 6 | development was suspended. | ||
| 7 | |||
| 8 | TODO: | ||
| 9 | PS/2 library: losts data from keyboard occasionally, | ||
| 10 | should use interrupt thoroughly for communication. | ||
| 11 | |||
| 12 | Code cleaning: merge code changed here to other subprojects and common modules. | ||
diff --git a/ps2_vusb/keymap.c b/ps2_vusb/keymap.c deleted file mode 100644 index d64e377bd..000000000 --- a/ps2_vusb/keymap.c +++ /dev/null | |||
| @@ -1,189 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Keymap for PS/2 keyboard | ||
| 3 | */ | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | #include <avr/pgmspace.h> | ||
| 7 | #include "usb_keycodes.h" | ||
| 8 | #include "host.h" | ||
| 9 | #include "print.h" | ||
| 10 | #include "debug.h" | ||
| 11 | #include "util.h" | ||
| 12 | #include "keymap_skel.h" | ||
| 13 | |||
| 14 | |||
| 15 | #define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) | ||
| 16 | |||
| 17 | // Convert physical keyboard layout to matrix array. | ||
| 18 | // This is a macro to define keymap easily in keyboard layout form. | ||
| 19 | #define KEYMAP( \ | ||
| 20 | K76, K05,K06,K04,K0C, K03,K0B,K83,K0A, K01,K09,K78,K07, KFC,K7E,KFE, KB7,KBF,KDE, \ | ||
| 21 | K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ | ||
| 22 | K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ | ||
| 23 | K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ | ||
| 24 | K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ | ||
| 25 | K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA \ | ||
| 26 | ) { \ | ||
| 27 | { KB_NO, KB_##K01, KB_NO, KB_##K03, KB_##K04, KB_##K05, KB_##K06, KB_##K07 }, \ | ||
| 28 | { KB_NO, KB_##K09, KB_##K0A, KB_##K0B, KB_##K0C, KB_##K0D, KB_##K0E, KB_NO }, \ | ||
| 29 | { KB_NO, KB_##K11, KB_##K12, KB_NO, KB_##K14, KB_##K15, KB_##K16, KB_NO }, \ | ||
| 30 | { KB_NO, KB_NO, KB_##K1A, KB_##K1B, KB_##K1C, KB_##K1D, KB_##K1E, KB_NO }, \ | ||
| 31 | { KB_NO, KB_##K21, KB_##K22, KB_##K23, KB_##K24, KB_##K25, KB_##K26, KB_NO }, \ | ||
| 32 | { KB_NO, KB_##K29, KB_##K2A, KB_##K2B, KB_##K2C, KB_##K2D, KB_##K2E, KB_NO }, \ | ||
| 33 | { KB_NO, KB_##K31, KB_##K32, KB_##K33, KB_##K34, KB_##K35, KB_##K36, KB_NO }, \ | ||
| 34 | { KB_NO, KB_NO, KB_##K3A, KB_##K3B, KB_##K3C, KB_##K3D, KB_##K3E, KB_NO }, \ | ||
| 35 | { KB_NO, KB_##K41, KB_##K42, KB_##K43, KB_##K44, KB_##K45, KB_##K46, KB_NO }, \ | ||
| 36 | { KB_NO, KB_##K49, KB_##K4A, KB_##K4B, KB_##K4C, KB_##K4D, KB_##K4E, KB_NO }, \ | ||
| 37 | { KB_NO, KB_NO, KB_##K52, KB_NO, KB_##K54, KB_##K55, KB_NO, KB_NO }, \ | ||
| 38 | { KB_##K58, KB_##K59, KB_##K5A, KB_##K5B, KB_NO, KB_##K5D, KB_NO, KB_NO }, \ | ||
| 39 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##K66, KB_NO }, \ | ||
| 40 | { KB_NO, KB_##K69, KB_NO, KB_##K6B, KB_##K6C, KB_NO, KB_NO, KB_NO }, \ | ||
| 41 | { KB_##K70, KB_##K71, KB_##K72, KB_##K73, KB_##K74, KB_##K75, KB_##K76, KB_##K77 }, \ | ||
| 42 | { KB_##K78, KB_##K79, KB_##K7A, KB_##K7B, KB_##K7C, KB_##K7D, KB_##K7E, KB_NO }, \ | ||
| 43 | { KB_NO, KB_NO, KB_NO, KB_##K83, KB_NO, KB_NO, KB_NO, KB_NO }, \ | ||
| 44 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ | ||
| 45 | { KB_NO, KB_##K91, KB_NO, KB_NO, KB_##K94, KB_NO, KB_NO, KB_NO }, \ | ||
| 46 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##K9F }, \ | ||
| 47 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##KA7 }, \ | ||
| 48 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##KAF }, \ | ||
| 49 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##KB7 }, \ | ||
| 50 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##KBF }, \ | ||
| 51 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ | ||
| 52 | { KB_NO, KB_NO, KB_##KCA, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ | ||
| 53 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ | ||
| 54 | { KB_NO, KB_NO, KB_##KDA, KB_NO, KB_NO, KB_NO, KB_##KDE, KB_NO }, \ | ||
| 55 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ | ||
| 56 | { KB_NO, KB_##KE9, KB_NO, KB_##KEB, KB_##KEC, KB_NO, KB_NO, KB_NO }, \ | ||
| 57 | { KB_##KF0, KB_##KF1, KB_##KF2, KB_NO, KB_##KF4, KB_##KF5, KB_NO, KB_NO }, \ | ||
| 58 | { KB_NO, KB_NO, KB_##KFA, KB_NO, KB_##KFC, KB_##KFD, KB_##KFE, KB_NO }, \ | ||
| 59 | } | ||
| 60 | |||
| 61 | |||
| 62 | // Assign Fn key(0-7) to a layer to which switch with the Fn key pressed. | ||
| 63 | static const uint8_t PROGMEM fn_layer[] = { | ||
| 64 | 5, // Fn0 | ||
| 65 | 6, // Fn1 | ||
| 66 | 5, // Fn2 | ||
| 67 | 0, // Fn3 | ||
| 68 | 0, // Fn4 | ||
| 69 | 0, // Fn5 | ||
| 70 | 0, // Fn6 | ||
| 71 | 0 // Fn7 | ||
| 72 | }; | ||
| 73 | |||
| 74 | // Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer. | ||
| 75 | // See layer.c for details. | ||
| 76 | static const uint8_t PROGMEM fn_keycode[] = { | ||
| 77 | KB_SCLN, // Fn0 | ||
| 78 | KB_SLSH, // Fn1 | ||
| 79 | KB_A, // Fn2 | ||
| 80 | KB_NO, // Fn3 | ||
| 81 | KB_NO, // Fn4 | ||
| 82 | KB_NO, // Fn5 | ||
| 83 | KB_NO, // Fn6 | ||
| 84 | KB_NO // Fn7 | ||
| 85 | }; | ||
| 86 | |||
| 87 | static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 88 | /* keymap | ||
| 89 | * ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,-----------. | ||
| 90 | * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|Slp|Wak| | ||
| 91 | * `---' `---------------' `---------------' `---------------' `-----------' `-----------' | ||
| 92 | * ,-----------------------------------------------------------. ,-----------. ,---------------. | ||
| 93 | * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| |Ins|Hom|PgU| |NmL| /| *| -| | ||
| 94 | * |-----------------------------------------------------------| |-----------| |---------------| | ||
| 95 | * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | 7| 8| 9| | | ||
| 96 | * |-----------------------------------------------------------| `-----------' |-----------| +| | ||
| 97 | * |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return | | 4| 5| 6| | | ||
| 98 | * |-----------------------------------------------------------| ,---. |---------------| | ||
| 99 | * |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shift | |Up | | 1| 2| 3| | | ||
| 100 | * |-----------------------------------------------------------| ,-----------. |-----------|Ent| | ||
| 101 | * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| |Lef|Dow|Rig| | 0| .| | | ||
| 102 | * `-----------------------------------------------------------' `-----------' `---------------' | ||
| 103 | */ | ||
| 104 | /* 0: default */ | ||
| 105 | KEYMAP( | ||
| 106 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, | ||
| 107 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 108 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, | ||
| 109 | CAPS,FN2, S, D, F, G, H, J, K, L, FN0, QUOT, ENT, P4, P5, P6, PPLS, | ||
| 110 | LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, UP, P1, P2, P3, | ||
| 111 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
| 112 | ), | ||
| 113 | /* 1: plain Qwerty without layer switching */ | ||
| 114 | KEYMAP( | ||
| 115 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, | ||
| 116 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 117 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, | ||
| 118 | CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, PPLS, | ||
| 119 | LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, | ||
| 120 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
| 121 | ), | ||
| 122 | /* 2: Colemak http://colemak.com */ | ||
| 123 | KEYMAP( | ||
| 124 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, | ||
| 125 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 126 | TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, | ||
| 127 | BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, P4, P5, P6, PPLS, | ||
| 128 | LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, | ||
| 129 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
| 130 | ), | ||
| 131 | /* 3: Dvorak http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard */ | ||
| 132 | KEYMAP( | ||
| 133 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, | ||
| 134 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 135 | TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, DEL, END, PGDN, P7, P8, P9, | ||
| 136 | CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, P4, P5, P6, PPLS, | ||
| 137 | LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, UP, P1, P2, P3, | ||
| 138 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
| 139 | ), | ||
| 140 | /* 4: Workman http://viralintrospection.wordpress.com/2010/09/06/a-different-philosophy-in-designing-keyboard-layouts/ */ | ||
| 141 | KEYMAP( | ||
| 142 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, | ||
| 143 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 144 | TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, | ||
| 145 | BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, P4, P5, P6, PPLS, | ||
| 146 | LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, | ||
| 147 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
| 148 | ), | ||
| 149 | /* 5: Mouse keys */ | ||
| 150 | KEYMAP( | ||
| 151 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, | ||
| 152 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 153 | TAB, WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, | ||
| 154 | CAPS,FN2, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN0, NO, ENT, P4, P5, P6, PPLS, | ||
| 155 | LSFT,VOLD,VOLU,MUTE,BTN2,BTN3,BTN2,BTN1,VOLD,VOLU,MUTE, RSFT, UP, P1, P2, P3, | ||
| 156 | LCTL,LGUI,LALT, BTN1, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
| 157 | ), | ||
| 158 | /* 6: Cursor keys */ | ||
| 159 | KEYMAP( | ||
| 160 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, | ||
| 161 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 162 | TAB, NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, | ||
| 163 | CAPS,NO, NO, NO, NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, P4, P5, P6, PPLS, | ||
| 164 | LSFT,VOLD,VOLU,MUTE,NO, NO, HOME,PGDN,PGUP,END, FN1, RSFT, UP, P1, P2, P3, | ||
| 165 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
| 166 | ), | ||
| 167 | }; | ||
| 168 | |||
| 169 | |||
| 170 | uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) | ||
| 171 | { | ||
| 172 | return KEYCODE(layer, row, col); | ||
| 173 | } | ||
| 174 | |||
| 175 | uint8_t keymap_fn_layer(uint8_t fn_bits) | ||
| 176 | { | ||
| 177 | return pgm_read_byte(&fn_layer[biton(fn_bits)]); | ||
| 178 | } | ||
| 179 | |||
| 180 | uint8_t keymap_fn_keycode(uint8_t fn_bits) | ||
| 181 | { | ||
| 182 | return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); | ||
| 183 | } | ||
| 184 | |||
| 185 | // define a condition to enter special function mode | ||
| 186 | bool keymap_is_special_mode(uint8_t fn_bits) | ||
| 187 | { | ||
| 188 | return host_get_mods() == (BIT_LSHIFT | BIT_RSHIFT) || host_get_mods() == (BIT_LCTRL | BIT_RSHIFT); | ||
| 189 | } | ||
diff --git a/ps2_vusb/matrix.c b/ps2_vusb/matrix.c deleted file mode 100644 index ca3e0ef3e..000000000 --- a/ps2_vusb/matrix.c +++ /dev/null | |||
| @@ -1,444 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * scan matrix | ||
| 3 | */ | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | #include <avr/io.h> | ||
| 7 | #include <util/delay.h> | ||
| 8 | #include "print.h" | ||
| 9 | #include "util.h" | ||
| 10 | #include "debug.h" | ||
| 11 | #include "ps2.h" | ||
| 12 | #include "matrix_skel.h" | ||
| 13 | |||
| 14 | |||
| 15 | #if (MATRIX_COLS > 16) | ||
| 16 | # error "MATRIX_COLS must not exceed 16" | ||
| 17 | #endif | ||
| 18 | #if (MATRIX_ROWS > 255) | ||
| 19 | # error "MATRIX_ROWS must not exceed 255" | ||
| 20 | #endif | ||
| 21 | |||
| 22 | |||
| 23 | /* | ||
| 24 | * Matrix usage: | ||
| 25 | * "PS/2 Scan Codes Set 2" is assigned to 256(32x8)cells matrix. | ||
| 26 | * Hmm, It is very sparse and not efficient :( | ||
| 27 | * | ||
| 28 | * 8bit | ||
| 29 | * --------- | ||
| 30 | * 0| | | ||
| 31 | * :| XX | 00-7F for normal codes(without E0-prefix) | ||
| 32 | * f|_________| | ||
| 33 | * 10| | | ||
| 34 | * :| E0 XX | 80-FF for E0-prefix codes(use (XX|0x80) as code) | ||
| 35 | * 1f| | | ||
| 36 | * --------- | ||
| 37 | * exceptions: | ||
| 38 | * 83: F8[0x83](normal codes but > 0x7F) | ||
| 39 | * FC: PrintScreen[E0 7C or 84] | ||
| 40 | * FE: Puause | ||
| 41 | */ | ||
| 42 | #define F8 (0x83) | ||
| 43 | #define PRINT_SCREEN (0xFC) | ||
| 44 | #define PAUSE (0xFE) | ||
| 45 | #define ROW(code) (code>>3) | ||
| 46 | #define COL(code) (code&0x07) | ||
| 47 | |||
| 48 | static bool is_modified = false; | ||
| 49 | |||
| 50 | // matrix state buffer(1:on, 0:off) | ||
| 51 | #if (MATRIX_COLS <= 8) | ||
| 52 | static uint8_t matrix[MATRIX_ROWS]; | ||
| 53 | #else | ||
| 54 | static uint16_t matrix[MATRIX_ROWS]; | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #ifdef MATRIX_HAS_GHOST | ||
| 58 | static bool matrix_has_ghost_in_row(uint8_t row); | ||
| 59 | #endif | ||
| 60 | static void matrix_make(uint8_t code); | ||
| 61 | static void matrix_break(uint8_t code); | ||
| 62 | |||
| 63 | |||
| 64 | inline | ||
| 65 | uint8_t matrix_rows(void) | ||
| 66 | { | ||
| 67 | return MATRIX_ROWS; | ||
| 68 | } | ||
| 69 | |||
| 70 | inline | ||
| 71 | uint8_t matrix_cols(void) | ||
| 72 | { | ||
| 73 | return MATRIX_COLS; | ||
| 74 | } | ||
| 75 | |||
| 76 | void matrix_init(void) | ||
| 77 | { | ||
| 78 | ps2_host_init(); | ||
| 79 | |||
| 80 | // initialize matrix state: all keys off | ||
| 81 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; | ||
| 82 | |||
| 83 | return; | ||
| 84 | } | ||
| 85 | |||
| 86 | /* | ||
| 87 | * PS/2 Scan Code Set 2: Exceptional Handling | ||
| 88 | * | ||
| 89 | * There are several keys to be handled exceptionally. | ||
| 90 | * The scan code for these keys are varied or prefix/postfix'd | ||
| 91 | * depending on modifier key state. | ||
| 92 | * | ||
| 93 | * References: | ||
| 94 | * http://www.microsoft.com/whdc/archive/scancode.mspx | ||
| 95 | * http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc | ||
| 96 | * | ||
| 97 | * | ||
| 98 | * Insert, Delete, Home, End, PageUp, PageDown, Up, Down, Right, Left: | ||
| 99 | * Num Lock: off | ||
| 100 | * modifiers | make | break | ||
| 101 | * ----------+---------------------------+---------------------- | ||
| 102 | * Ohter | <make> | <break> | ||
| 103 | * LShift | E0 F0 12 <make> | <break> E0 12 | ||
| 104 | * RShift | E0 F0 59 <make> | <break> E0 59 | ||
| 105 | * L+RShift | E0 F0 12 E0 F0 59 <make> | <break> E0 59 E0 12 | ||
| 106 | * | ||
| 107 | * Num Lock: on | ||
| 108 | * modifiers | make | break | ||
| 109 | * ----------+---------------------------+---------------------- | ||
| 110 | * Other | E0 12 <make> | <break> E0 F0 12 | ||
| 111 | * Shift'd | <make> | <break> | ||
| 112 | * | ||
| 113 | * Handling: ignore these prefix/postfix codes | ||
| 114 | * | ||
| 115 | * | ||
| 116 | * Keypad-/: | ||
| 117 | * modifiers | make | break | ||
| 118 | * ----------+---------------------------+---------------------- | ||
| 119 | * Ohter | <make> | <break> | ||
| 120 | * LShift | E0 F0 12 <make> | <break> E0 12 | ||
| 121 | * RShift | E0 F0 59 <make> | <break> E0 59 | ||
| 122 | * L+RShift | E0 F0 12 E0 F0 59 <make> | <break> E0 59 E0 12 | ||
| 123 | * | ||
| 124 | * Handling: ignore these prefix/postfix codes | ||
| 125 | * | ||
| 126 | * | ||
| 127 | * PrintScreen: | ||
| 128 | * With hoding down modifiers, the scan code is sent as following: | ||
| 129 | * | ||
| 130 | * modifiers | make | break | ||
| 131 | * ----------+--------------+----------------------------------- | ||
| 132 | * Other | E0 12 E0 7C | E0 F0 7C E0 F0 12 | ||
| 133 | * Shift'd | E0 7C | E0 F0 7C | ||
| 134 | * Control'd | E0 7C | E0 F0 7C | ||
| 135 | * Alt'd | 84 | F0 84 | ||
| 136 | * | ||
| 137 | * Handling: ignore prefix/postfix codes and treat both scan code | ||
| 138 | * E0 7C and 84 as PrintScreen. | ||
| 139 | * | ||
| 140 | * Pause: | ||
| 141 | * With hoding down modifiers, the scan code is sent as following: | ||
| 142 | * | ||
| 143 | * modifiers | make(no break code) | ||
| 144 | * ----------+-------------------------------------------------- | ||
| 145 | * no mods | E1 14 77 E1 F0 14 F0 77 | ||
| 146 | * Control'd | E0 7E E0 F0 7E | ||
| 147 | * | ||
| 148 | * Handling: treat these two code sequence as Pause | ||
| 149 | * | ||
| 150 | */ | ||
| 151 | uint8_t matrix_scan(void) | ||
| 152 | { | ||
| 153 | |||
| 154 | static enum { | ||
| 155 | INIT, | ||
| 156 | F0, | ||
| 157 | E0, | ||
| 158 | E0_F0, | ||
| 159 | // states for Pause/Break | ||
| 160 | E1, | ||
| 161 | E1_14, | ||
| 162 | E1_14_77, | ||
| 163 | E1_14_77_E1, | ||
| 164 | E1_14_77_E1_F0, | ||
| 165 | E1_14_77_E1_F0_14, | ||
| 166 | E1_14_77_E1_F0_14_F0, | ||
| 167 | } state = INIT; | ||
| 168 | |||
| 169 | |||
| 170 | is_modified = false; | ||
| 171 | |||
| 172 | // Pause/Break off(PS/2 has no break for this key) | ||
| 173 | if (matrix_is_on(ROW(PAUSE), COL(PAUSE))) { | ||
| 174 | matrix_break(PAUSE); | ||
| 175 | } | ||
| 176 | |||
| 177 | uint8_t code; | ||
| 178 | while ((code = ps2_host_recv())) { | ||
| 179 | switch (state) { | ||
| 180 | case INIT: | ||
| 181 | switch (code) { | ||
| 182 | case 0xE0: // 2byte make | ||
| 183 | state = E0; | ||
| 184 | break; | ||
| 185 | case 0xF0: // break code | ||
| 186 | state = F0; | ||
| 187 | break; | ||
| 188 | case 0xE1: // Pause/Break | ||
| 189 | state = E1; | ||
| 190 | break; | ||
| 191 | case 0x83: // F8 | ||
| 192 | matrix_make(F8); | ||
| 193 | state = INIT; | ||
| 194 | break; | ||
| 195 | case 0x84: // PrintScreen | ||
| 196 | matrix_make(PRINT_SCREEN); | ||
| 197 | state = INIT; | ||
| 198 | break; | ||
| 199 | default: // normal key make | ||
| 200 | if (code < 0x80) { | ||
| 201 | matrix_make(code); | ||
| 202 | } else { | ||
| 203 | debug("unexpected scan code at INIT: "); debug_hex(code); debug("\n"); | ||
| 204 | } | ||
| 205 | state = INIT; | ||
| 206 | } | ||
| 207 | break; | ||
| 208 | case E0: | ||
| 209 | switch (code) { | ||
| 210 | case 0x12: // postfix/postfix code for exceptional keys | ||
| 211 | case 0x59: // postfix/postfix code for exceptional keys | ||
| 212 | // ignore | ||
| 213 | state = INIT; | ||
| 214 | break; | ||
| 215 | case 0x7E: // former part of Control-Pause[E0 7E E0 F0 7E] | ||
| 216 | matrix_make(PAUSE); | ||
| 217 | state = INIT; | ||
| 218 | break; | ||
| 219 | case 0xF0: // E0 break | ||
| 220 | state = E0_F0; | ||
| 221 | break; | ||
| 222 | default: // E0 make | ||
| 223 | if (code < 0x80) { | ||
| 224 | matrix_make(code|0x80); | ||
| 225 | } else { | ||
| 226 | debug("unexpected scan code at E0: "); debug_hex(code); debug("\n"); | ||
| 227 | } | ||
| 228 | state = INIT; | ||
| 229 | } | ||
| 230 | break; | ||
| 231 | case F0: | ||
| 232 | switch (code) { | ||
| 233 | case 0x83: | ||
| 234 | matrix_break(F8); | ||
| 235 | state = INIT; | ||
| 236 | break; | ||
| 237 | case 0x84: | ||
| 238 | matrix_break(PRINT_SCREEN); | ||
| 239 | state = INIT; | ||
| 240 | break; | ||
| 241 | default: | ||
| 242 | if (code < 0x80) { | ||
| 243 | matrix_break(code); | ||
| 244 | } else { | ||
| 245 | debug("unexpected scan code at F0: "); debug_hex(code); debug("\n"); | ||
| 246 | } | ||
| 247 | state = INIT; | ||
| 248 | } | ||
| 249 | break; | ||
| 250 | case E0_F0: // E0 break | ||
| 251 | switch (code) { | ||
| 252 | case 0x12: // postfix/postfix code for exceptional keys | ||
| 253 | case 0x59: // postfix/postfix code for exceptional keys | ||
| 254 | case 0x7E: // latter part of Control-Pause[E0 7E E0 F0 7E] | ||
| 255 | // ignore | ||
| 256 | state = INIT; | ||
| 257 | break; | ||
| 258 | default: | ||
| 259 | if (code < 0x80) { | ||
| 260 | matrix_break(code|0x80); | ||
| 261 | } else { | ||
| 262 | debug("unexpected scan code at E0_F0: "); debug_hex(code); debug("\n"); | ||
| 263 | } | ||
| 264 | state = INIT; | ||
| 265 | } | ||
| 266 | break; | ||
| 267 | /* Pause */ | ||
| 268 | case E1: | ||
| 269 | switch (code) { | ||
| 270 | case 0x14: | ||
| 271 | state = E1_14; | ||
| 272 | break; | ||
| 273 | default: | ||
| 274 | state = INIT; | ||
| 275 | } | ||
| 276 | break; | ||
| 277 | case E1_14: | ||
| 278 | switch (code) { | ||
| 279 | case 0x77: | ||
| 280 | state = E1_14_77; | ||
| 281 | break; | ||
| 282 | default: | ||
| 283 | state = INIT; | ||
| 284 | } | ||
| 285 | break; | ||
| 286 | case E1_14_77: | ||
| 287 | switch (code) { | ||
| 288 | case 0xE1: | ||
| 289 | state = E1_14_77_E1; | ||
| 290 | break; | ||
| 291 | default: | ||
| 292 | state = INIT; | ||
| 293 | } | ||
| 294 | break; | ||
| 295 | case E1_14_77_E1: | ||
| 296 | switch (code) { | ||
| 297 | case 0xF0: | ||
| 298 | state = E1_14_77_E1_F0; | ||
| 299 | break; | ||
| 300 | default: | ||
| 301 | state = INIT; | ||
| 302 | } | ||
| 303 | break; | ||
| 304 | case E1_14_77_E1_F0: | ||
| 305 | switch (code) { | ||
| 306 | case 0x14: | ||
| 307 | state = E1_14_77_E1_F0_14; | ||
| 308 | break; | ||
| 309 | default: | ||
| 310 | state = INIT; | ||
| 311 | } | ||
| 312 | break; | ||
| 313 | case E1_14_77_E1_F0_14: | ||
| 314 | switch (code) { | ||
| 315 | case 0xF0: | ||
| 316 | state = E1_14_77_E1_F0_14_F0; | ||
| 317 | break; | ||
| 318 | default: | ||
| 319 | state = INIT; | ||
| 320 | } | ||
| 321 | break; | ||
| 322 | case E1_14_77_E1_F0_14_F0: | ||
| 323 | switch (code) { | ||
| 324 | case 0x77: | ||
| 325 | matrix_make(PAUSE); | ||
| 326 | state = INIT; | ||
| 327 | break; | ||
| 328 | default: | ||
| 329 | state = INIT; | ||
| 330 | } | ||
| 331 | break; | ||
| 332 | default: | ||
| 333 | state = INIT; | ||
| 334 | } | ||
| 335 | } | ||
| 336 | return 1; | ||
| 337 | } | ||
| 338 | |||
| 339 | bool matrix_is_modified(void) | ||
| 340 | { | ||
| 341 | return is_modified; | ||
| 342 | } | ||
| 343 | |||
| 344 | inline | ||
| 345 | bool matrix_has_ghost(void) | ||
| 346 | { | ||
| 347 | #ifdef MATRIX_HAS_GHOST | ||
| 348 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 349 | if (matrix_has_ghost_in_row(i)) | ||
| 350 | return true; | ||
| 351 | } | ||
| 352 | #endif | ||
| 353 | return false; | ||
| 354 | } | ||
| 355 | |||
| 356 | inline | ||
| 357 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 358 | { | ||
| 359 | return (matrix[row] & (1<<col)); | ||
| 360 | } | ||
| 361 | |||
| 362 | inline | ||
| 363 | #if (MATRIX_COLS <= 8) | ||
| 364 | uint8_t matrix_get_row(uint8_t row) | ||
| 365 | #else | ||
| 366 | uint16_t matrix_get_row(uint8_t row) | ||
| 367 | #endif | ||
| 368 | { | ||
| 369 | return matrix[row]; | ||
| 370 | } | ||
| 371 | |||
| 372 | void matrix_print(void) | ||
| 373 | { | ||
| 374 | #if (MATRIX_COLS <= 8) | ||
| 375 | print("\nr/c 01234567\n"); | ||
| 376 | #else | ||
| 377 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 378 | #endif | ||
| 379 | for (uint8_t row = 0; row < matrix_rows(); row++) { | ||
| 380 | phex(row); print(": "); | ||
| 381 | #if (MATRIX_COLS <= 8) | ||
| 382 | pbin_reverse(matrix_get_row(row)); | ||
| 383 | #else | ||
| 384 | pbin_reverse16(matrix_get_row(row)); | ||
| 385 | #endif | ||
| 386 | #ifdef MATRIX_HAS_GHOST | ||
| 387 | if (matrix_has_ghost_in_row(row)) { | ||
| 388 | print(" <ghost"); | ||
| 389 | } | ||
| 390 | #endif | ||
| 391 | print("\n"); | ||
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | uint8_t matrix_key_count(void) | ||
| 396 | { | ||
| 397 | uint8_t count = 0; | ||
| 398 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 399 | #if (MATRIX_COLS <= 8) | ||
| 400 | count += bitpop(matrix[i]); | ||
| 401 | #else | ||
| 402 | count += bitpop16(matrix[i]); | ||
| 403 | #endif | ||
| 404 | } | ||
| 405 | return count; | ||
| 406 | } | ||
| 407 | |||
| 408 | #ifdef MATRIX_HAS_GHOST | ||
| 409 | inline | ||
| 410 | static bool matrix_has_ghost_in_row(uint8_t row) | ||
| 411 | { | ||
| 412 | // no ghost exists in case less than 2 keys on | ||
| 413 | if (((matrix[row] - 1) & matrix[row]) == 0) | ||
| 414 | return false; | ||
| 415 | |||
| 416 | // ghost exists in case same state as other row | ||
| 417 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 418 | if (i != row && (matrix[i] & matrix[row]) == matrix[row]) | ||
| 419 | return true; | ||
| 420 | } | ||
| 421 | return false; | ||
| 422 | } | ||
| 423 | #endif | ||
| 424 | |||
| 425 | |||
| 426 | inline | ||
| 427 | static void matrix_make(uint8_t code) | ||
| 428 | { | ||
| 429 | if (!matrix_is_on(ROW(code), COL(code))) { | ||
| 430 | matrix[ROW(code)] |= 1<<COL(code); | ||
| 431 | is_modified = true; | ||
| 432 | //print("matrix_make: "); phex(code); print("\n"); | ||
| 433 | } | ||
| 434 | } | ||
| 435 | |||
| 436 | inline | ||
| 437 | static void matrix_break(uint8_t code) | ||
| 438 | { | ||
| 439 | if (matrix_is_on(ROW(code), COL(code))) { | ||
| 440 | matrix[ROW(code)] &= ~(1<<COL(code)); | ||
| 441 | is_modified = true; | ||
| 442 | //print("matrix_break: "); phex(code); print("\n"); | ||
| 443 | } | ||
| 444 | } | ||
| @@ -30,7 +30,7 @@ | |||
| 30 | #include <util/delay.h> | 30 | #include <util/delay.h> |
| 31 | #include "keyboard.h" | 31 | #include "keyboard.h" |
| 32 | #include "usb.h" | 32 | #include "usb.h" |
| 33 | #include "matrix_skel.h" | 33 | #include "matrix.h" |
| 34 | #include "print.h" | 34 | #include "print.h" |
| 35 | #include "debug.h" | 35 | #include "debug.h" |
| 36 | #include "util.h" | 36 | #include "util.h" |
