diff options
Diffstat (limited to 'key_process.c')
| -rw-r--r-- | key_process.c | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/key_process.c b/key_process.c index 243f4aad8..0bd202806 100644 --- a/key_process.c +++ b/key_process.c | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "usb_mouse.h" | 10 | #include "usb_mouse.h" |
| 11 | #include "usb_extra.h" | 11 | #include "usb_extra.h" |
| 12 | #include "usb_keycodes.h" | 12 | #include "usb_keycodes.h" |
| 13 | #include "usb.h" | ||
| 13 | #include "layer.h" | 14 | #include "layer.h" |
| 14 | #include "matrix_skel.h" | 15 | #include "matrix_skel.h" |
| 15 | #include "keymap_skel.h" | 16 | #include "keymap_skel.h" |
| @@ -31,7 +32,6 @@ void proc_matrix(void) { | |||
| 31 | static int mouse_repeat = 0; | 32 | static int mouse_repeat = 0; |
| 32 | 33 | ||
| 33 | bool modified = false; | 34 | bool modified = false; |
| 34 | //bool has_ghost = false; | ||
| 35 | int key_index = 0; | 35 | int key_index = 0; |
| 36 | uint8_t mouse_btn = 0; | 36 | uint8_t mouse_btn = 0; |
| 37 | int8_t mouse_x = 0; | 37 | int8_t mouse_x = 0; |
| @@ -42,7 +42,7 @@ void proc_matrix(void) { | |||
| 42 | 42 | ||
| 43 | matrix_scan(); | 43 | matrix_scan(); |
| 44 | modified = matrix_is_modified(); | 44 | modified = matrix_is_modified(); |
| 45 | 45 | ||
| 46 | if (modified) { | 46 | if (modified) { |
| 47 | if (debug_matrix) matrix_print(); | 47 | if (debug_matrix) matrix_print(); |
| 48 | #ifdef DEBUG_LED | 48 | #ifdef DEBUG_LED |
| @@ -63,46 +63,54 @@ void proc_matrix(void) { | |||
| 63 | for (int col = 0; col < matrix_cols(); col++) { | 63 | for (int col = 0; col < matrix_cols(); col++) { |
| 64 | if (!matrix_is_on(row, col)) continue; | 64 | if (!matrix_is_on(row, col)) continue; |
| 65 | 65 | ||
| 66 | // TODO: clean code | ||
| 66 | uint8_t code = layer_get_keycode(row, col); | 67 | uint8_t code = layer_get_keycode(row, col); |
| 67 | if (code == KB_NO) { | 68 | if (code == KB_NO) { |
| 68 | // do nothing | 69 | // do nothing |
| 69 | } else if (IS_MOD(code)) { | 70 | } else if (IS_MOD(code)) { |
| 70 | usb_keyboard_mods |= MOD_BIT(code); | 71 | usb_keyboard_mods |= MOD_BIT(code); |
| 72 | } else if (IS_FN(code)) { | ||
| 73 | fn_bits |= FN_BIT(code); | ||
| 71 | } else if (IS_MOUSE(code)) { | 74 | } else if (IS_MOUSE(code)) { |
| 72 | // mouse | 75 | if (code == MS_UP) mouse_y -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; |
| 73 | if (code == MS_UP) | 76 | if (code == MS_DOWN) mouse_y += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; |
| 74 | mouse_y -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; | 77 | if (code == MS_LEFT) mouse_x -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; |
| 75 | if (code == MS_DOWN) | 78 | if (code == MS_RGHT) mouse_x += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; |
| 76 | mouse_y += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; | ||
| 77 | if (code == MS_LEFT) | ||
| 78 | mouse_x -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; | ||
| 79 | if (code == MS_RIGHT) | ||
| 80 | mouse_x += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; | ||
| 81 | if (code == MS_BTN1) mouse_btn |= BIT_BTN1; | 79 | if (code == MS_BTN1) mouse_btn |= BIT_BTN1; |
| 82 | if (code == MS_BTN2) mouse_btn |= BIT_BTN2; | 80 | if (code == MS_BTN2) mouse_btn |= BIT_BTN2; |
| 83 | if (code == MS_BTN3) mouse_btn |= BIT_BTN3; | 81 | if (code == MS_BTN3) mouse_btn |= BIT_BTN3; |
| 84 | if (code == MS_BTN4) mouse_btn |= BIT_BTN4; | 82 | if (code == MS_BTN4) mouse_btn |= BIT_BTN4; |
| 85 | if (code == MS_BTN5) mouse_btn |= BIT_BTN5; | 83 | if (code == MS_BTN5) mouse_btn |= BIT_BTN5; |
| 86 | if (code == MS_WH_UP) mouse_vwheel += 1; | 84 | if (code == MS_WH_U) mouse_vwheel += 1; |
| 87 | if (code == MS_WH_DOWN) mouse_vwheel -= 1; | 85 | if (code == MS_WH_D) mouse_vwheel -= 1; |
| 88 | if (code == MS_WH_LEFT) mouse_hwheel -= 1; | 86 | if (code == MS_WH_L) mouse_hwheel -= 1; |
| 89 | if (code == MS_WH_RIGHT) mouse_hwheel += 1; | 87 | if (code == MS_WH_R) mouse_hwheel += 1; |
| 90 | } else if (IS_FN(code)) { | 88 | } |
| 91 | fn_bits |= FN_BIT(code); | 89 | |
| 92 | } else if (code == KB_MUTE) { | 90 | // audio control & system control |
| 93 | usb_extra_send(AUDIO_MUTE); | 91 | else if (code == KB_MUTE) { |
| 94 | usb_extra_send(0); | 92 | usb_extra_audio_send(AUDIO_MUTE); |
| 93 | usb_extra_audio_send(0); | ||
| 95 | _delay_ms(500); | 94 | _delay_ms(500); |
| 96 | } else if (code == KB_VOLU) { | 95 | } else if (code == KB_VOLU) { |
| 97 | usb_extra_send(AUDIO_VOL_UP); | 96 | usb_extra_audio_send(AUDIO_VOL_UP); |
| 98 | usb_extra_send(0); | 97 | usb_extra_audio_send(0); |
| 99 | _delay_ms(100); | 98 | _delay_ms(100); |
| 100 | } else if (code == KB_VOLD) { | 99 | } else if (code == KB_VOLD) { |
| 101 | usb_extra_send(AUDIO_VOL_DOWN); | 100 | usb_extra_audio_send(AUDIO_VOL_DOWN); |
| 102 | usb_extra_send(0); | 101 | usb_extra_audio_send(0); |
| 103 | _delay_ms(100); | 102 | _delay_ms(100); |
| 104 | } else { | 103 | } else if (code == KB_PWR) { |
| 105 | // normal keys | 104 | if (suspend && remote_wakeup) { |
| 105 | usb_remote_wakeup(); | ||
| 106 | } else { | ||
| 107 | usb_extra_system_send(SYSTEM_POWER_DOWN); | ||
| 108 | } | ||
| 109 | _delay_ms(1000); | ||
| 110 | } | ||
| 111 | |||
| 112 | // normal keys | ||
| 113 | else { | ||
| 106 | if (key_index < 6) | 114 | if (key_index < 6) |
| 107 | usb_keyboard_keys[key_index] = code; | 115 | usb_keyboard_keys[key_index] = code; |
| 108 | key_index++; | 116 | key_index++; |
| @@ -120,6 +128,7 @@ void proc_matrix(void) { | |||
| 120 | 128 | ||
| 121 | layer_switching(fn_bits); | 129 | layer_switching(fn_bits); |
| 122 | 130 | ||
| 131 | // TODO: clean code | ||
| 123 | // when 4 left modifier keys down | 132 | // when 4 left modifier keys down |
| 124 | if (keymap_is_special_mode(fn_bits)) { | 133 | if (keymap_is_special_mode(fn_bits)) { |
| 125 | switch (usb_keyboard_keys[0]) { | 134 | switch (usb_keyboard_keys[0]) { |
| @@ -127,12 +136,14 @@ void proc_matrix(void) { | |||
| 127 | print_enable = true; | 136 | print_enable = true; |
| 128 | print("b: jump to bootloader\n"); | 137 | print("b: jump to bootloader\n"); |
| 129 | print("d: debug print toggle\n"); | 138 | print("d: debug print toggle\n"); |
| 139 | print("x: matrix debug toggle\n"); | ||
| 130 | print("k: keyboard debug toggle\n"); | 140 | print("k: keyboard debug toggle\n"); |
| 131 | print("m: mouse debug toggle\n"); | 141 | print("m: mouse debug toggle\n"); |
| 132 | print("x: matrix debug toggle\n"); | 142 | print("p: print enable toggle\n"); |
| 133 | print("v: print version\n"); | 143 | print("v: print version\n"); |
| 134 | print("t: print timer count\n"); | 144 | print("t: print timer count\n"); |
| 135 | print("p: print enable toggle\n"); | 145 | print("r: print registers\n"); |
| 146 | print("ESC: power down/wake up\n"); | ||
| 136 | _delay_ms(500); | 147 | _delay_ms(500); |
| 137 | print_enable = false; | 148 | print_enable = false; |
| 138 | break; | 149 | break; |
| @@ -219,6 +230,23 @@ void proc_matrix(void) { | |||
| 219 | } | 230 | } |
| 220 | _delay_ms(1000); | 231 | _delay_ms(1000); |
| 221 | break; | 232 | break; |
| 233 | case KB_R: | ||
| 234 | usb_keyboard_clear_report(); | ||
| 235 | usb_keyboard_send(); | ||
| 236 | print("UDIEN: "); phex(UDIEN); print("\n"); | ||
| 237 | print("UDINT: "); phex(UDINT); print("\n"); | ||
| 238 | _delay_ms(1000); | ||
| 239 | break; | ||
| 240 | case KB_ESC: | ||
| 241 | usb_keyboard_clear_report(); | ||
| 242 | usb_keyboard_send(); | ||
| 243 | if (suspend && remote_wakeup) { | ||
| 244 | usb_remote_wakeup(); | ||
| 245 | } else { | ||
| 246 | usb_extra_system_send(SYSTEM_POWER_DOWN); | ||
| 247 | } | ||
| 248 | _delay_ms(1000); | ||
| 249 | break; | ||
| 222 | } | 250 | } |
| 223 | } | 251 | } |
| 224 | 252 | ||
