aboutsummaryrefslogtreecommitdiff
path: root/key_process.c
diff options
context:
space:
mode:
Diffstat (limited to 'key_process.c')
-rw-r--r--key_process.c110
1 files changed, 55 insertions, 55 deletions
diff --git a/key_process.c b/key_process.c
index bb1bca02d..f3b65d101 100644
--- a/key_process.c
+++ b/key_process.c
@@ -15,29 +15,18 @@
15#include "layer.h" 15#include "layer.h"
16#include "matrix_skel.h" 16#include "matrix_skel.h"
17#include "keymap_skel.h" 17#include "keymap_skel.h"
18#include "controller.h"
19#include "key_process.h" 18#include "key_process.h"
20 19#ifdef MOUSEKEY_ENABLE
21 20# include "mousekey.h"
22#define MOUSE_MOVE_UNIT 10 21#endif
23#define MOUSE_MOVE_ACCEL (mouse_repeat < 50 ? mouse_repeat/5 : 10) 22#ifdef PS2_MOUSE_ENABLE
24 23# include "ps2_mouse.h"
25#ifndef MOUSE_DELAY_TIME
26# define MOUSE_DELAY_TIME 255
27#endif 24#endif
28#define MOUSE_DELAY_MS (MOUSE_DELAY_TIME >> (mouse_repeat < 5 ? mouse_repeat : 4))
29 25
30 26
31// TODO: refactoring 27// TODO: refactoring
32void proc_matrix(void) { 28void proc_matrix(void) {
33 static int mouse_repeat = 0;
34
35 bool modified = false; 29 bool modified = false;
36 uint8_t mouse_btn = 0;
37 int8_t mouse_x = 0;
38 int8_t mouse_y = 0;
39 int8_t mouse_vwheel = 0;
40 int8_t mouse_hwheel = 0;
41 uint8_t fn_bits = 0; 30 uint8_t fn_bits = 0;
42 31
43 matrix_scan(); 32 matrix_scan();
@@ -73,19 +62,9 @@ void proc_matrix(void) {
73 } else if (IS_FN(code)) { 62 } else if (IS_FN(code)) {
74 fn_bits |= FN_BIT(code); 63 fn_bits |= FN_BIT(code);
75 } else if (IS_MOUSE(code)) { 64 } else if (IS_MOUSE(code)) {
76 if (code == MS_UP) mouse_y -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; 65#ifdef MOUSEKEY_ENABLE
77 if (code == MS_DOWN) mouse_y += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; 66 mousekey_decode(code);
78 if (code == MS_LEFT) mouse_x -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; 67#endif
79 if (code == MS_RGHT) mouse_x += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL;
80 if (code == MS_BTN1) mouse_btn |= BIT_BTN1;
81 if (code == MS_BTN2) mouse_btn |= BIT_BTN2;
82 if (code == MS_BTN3) mouse_btn |= BIT_BTN3;
83 if (code == MS_BTN4) mouse_btn |= BIT_BTN4;
84 if (code == MS_BTN5) mouse_btn |= BIT_BTN5;
85 if (code == MS_WH_U) mouse_vwheel += 1;
86 if (code == MS_WH_D) mouse_vwheel -= 1;
87 if (code == MS_WH_L) mouse_hwheel -= 1;
88 if (code == MS_WH_R) mouse_hwheel += 1;
89 } 68 }
90 69
91 // audio control & system control 70 // audio control & system control
@@ -143,13 +122,39 @@ void proc_matrix(void) {
143 print("t: print timer count\n"); 122 print("t: print timer count\n");
144 print("s: print status\n"); 123 print("s: print status\n");
145 print("`: toggle protcol(boot/report)\n"); 124 print("`: toggle protcol(boot/report)\n");
146#ifdef NKRO_ENABLE 125#ifdef USB_NKRO_ENABLE
147 print("n: toggle NKRO\n"); 126 print("n: toggle USB_NKRO\n");
148#endif 127#endif
149 print("ESC: power down/wake up\n"); 128 print("ESC: power down/wake up\n");
129#ifdef PS2_MOUSE_ENABLE
130 print("1: ps2_mouse_init \n");
131 print("2: ps2_mouse_read \n");
132#endif
150 _delay_ms(500); 133 _delay_ms(500);
151 print_enable = false; 134 print_enable = false;
152 break; 135 break;
136#ifdef PS2_MOUSE_ENABLE
137 case KB_1:
138 usb_keyboard_clear_report();
139 usb_keyboard_send();
140 print_enable = true;
141 print("ps2_mouse_init...\n");
142 _delay_ms(500);
143 ps2_mouse_init();
144 break;
145 case KB_2:
146 usb_keyboard_clear_report();
147 usb_keyboard_send();
148 print_enable = true;
149 print("ps2_mouse_read[btn x y]: ");
150 _delay_ms(100);
151 ps2_mouse_read();
152 phex(ps2_mouse_btn); print(" ");
153 phex(ps2_mouse_x); print(" ");
154 phex(ps2_mouse_y); print("\n");
155 print("ps2_mouse_error_count: "); phex(ps2_mouse_error_count); print("\n");
156 break;
157#endif
153 case KB_B: // bootloader 158 case KB_B: // bootloader
154 usb_keyboard_clear_report(); 159 usb_keyboard_clear_report();
155 usb_keyboard_send(); 160 usb_keyboard_send();
@@ -243,29 +248,29 @@ void proc_matrix(void) {
243 print("usb_keyboard_protocol:"); phex(usb_keyboard_protocol); print("\n"); 248 print("usb_keyboard_protocol:"); phex(usb_keyboard_protocol); print("\n");
244 print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n"); 249 print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n");
245 print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n"); 250 print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n");
246 print("mouse_protocol:"); phex(mouse_protocol); print("\n"); 251 print("usb_mouse_protocol:"); phex(usb_mouse_protocol); print("\n");
247 if (usb_keyboard_nkro) print("NKRO: enabled\n"); else print("NKRO: disabled\n"); 252 if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n");
248 _delay_ms(500); 253 _delay_ms(500);
249 break; 254 break;
250 case KB_GRV: 255 case KB_GRV:
251 usb_keyboard_clear_report(); 256 usb_keyboard_clear_report();
252 usb_keyboard_send(); 257 usb_keyboard_send();
253 usb_keyboard_protocol = !usb_keyboard_protocol; 258 usb_keyboard_protocol = !usb_keyboard_protocol;
254 mouse_protocol = !mouse_protocol; 259 usb_mouse_protocol = !usb_mouse_protocol;
255 print("keyboard protcol: "); 260 print("keyboard protcol: ");
256 if (usb_keyboard_protocol) print("report"); else print("boot"); 261 if (usb_keyboard_protocol) print("report"); else print("boot");
257 print("\n"); 262 print("\n");
258 print("mouse protcol: "); 263 print("mouse protcol: ");
259 if (mouse_protocol) print("report"); else print("boot"); 264 if (usb_mouse_protocol) print("report"); else print("boot");
260 print("\n"); 265 print("\n");
261 _delay_ms(1000); 266 _delay_ms(1000);
262 break; 267 break;
263#ifdef NKRO_ENABLE 268#ifdef USB_NKRO_ENABLE
264 case KB_N: 269 case KB_N:
265 usb_keyboard_clear_report(); 270 usb_keyboard_clear_report();
266 usb_keyboard_send(); 271 usb_keyboard_send();
267 usb_keyboard_nkro = !usb_keyboard_nkro; 272 usb_keyboard_nkro = !usb_keyboard_nkro;
268 if (usb_keyboard_nkro) print("NKRO: enabled\n"); else print("NKRO: disabled\n"); 273 if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n");
269 _delay_ms(1000); 274 _delay_ms(1000);
270 break; 275 break;
271#endif 276#endif
@@ -283,25 +288,20 @@ void proc_matrix(void) {
283 } 288 }
284 289
285 290
286 // send mouse packet to host
287 if (mouse_x || mouse_y || mouse_vwheel || mouse_hwheel || mouse_btn != mouse_buttons) {
288 mouse_buttons = mouse_btn;
289 if (mouse_x && mouse_y)
290 usb_mouse_move(mouse_x*0.7, mouse_y*0.7, mouse_vwheel, mouse_hwheel);
291 else
292 usb_mouse_move(mouse_x, mouse_y, mouse_vwheel, mouse_hwheel);
293 usb_mouse_print(mouse_x, mouse_y, mouse_vwheel, mouse_hwheel);
294
295 // acceleration
296 _delay_ms(MOUSE_DELAY_MS);
297 mouse_repeat++;
298 } else {
299 mouse_repeat = 0;
300 }
301
302
303 // send key packet to host
304 if (modified) { 291 if (modified) {
305 usb_keyboard_send(); 292 usb_keyboard_send();
306 } 293 }
294
295#ifdef MOUSEKEY_ENABLE
296 // mouse keys
297 mousekey_usb_send();
298#endif
299
300#ifdef PS2_MOUSE_ENABLE
301 // ps2 mouse
302 //if (ps2_mouse_error_count > 10) {
303 ps2_mouse_read();
304 ps2_mouse_usb_send();
305 //}
306#endif
307} 307}