]>
git.gir.st - tmk_keyboard.git/blob - key_process.c
3 #include <util/delay.h>
8 #include "jump_bootloader.h"
9 #include "usb_keyboard.h"
10 #include "usb_mouse.h"
11 #include "usb_keycodes.h"
13 #include "matrix_skel.h"
14 #include "keymap_skel.h"
15 #include "controller.h"
16 #include "key_process.h"
19 #define MOUSE_MOVE_UNIT 10
20 #define MOUSE_MOVE_ACCEL (mouse_repeat < 50 ? mouse_repeat/5 : 10)
22 #ifndef MOUSE_DELAY_TIME
23 # define MOUSE_DELAY_TIME 255
25 #define MOUSE_DELAY_MS (MOUSE_DELAY_TIME >> (mouse_repeat < 5 ? mouse_repeat : 4))
29 void proc_matrix(void) {
30 static int mouse_repeat
= 0;
32 bool modified
= false;
33 //bool has_ghost = false;
35 uint8_t mouse_btn
= 0;
38 int8_t mouse_vwheel
= 0;
39 int8_t mouse_hwheel
= 0;
43 modified
= matrix_is_modified();
46 if (debug_matrix
) matrix_print();
48 // LED flash for debug
54 if (matrix_has_ghost()) {
56 debug("matrix has ghost!!\n");
60 usb_keyboard_clear_report();
61 for (int row
= 0; row
< matrix_rows(); row
++) {
62 for (int col
= 0; col
< matrix_cols(); col
++) {
63 if (!matrix_is_on(row
, col
)) continue;
65 uint8_t code
= layer_get_keycode(row
, col
);
68 } else if (IS_MOD(code
)) {
69 usb_keyboard_mods
|= MOD_BIT(code
);
70 } else if (IS_MOUSE(code
)) {
73 mouse_y
-= MOUSE_MOVE_UNIT
+ MOUSE_MOVE_ACCEL
;
75 mouse_y
+= MOUSE_MOVE_UNIT
+ MOUSE_MOVE_ACCEL
;
77 mouse_x
-= MOUSE_MOVE_UNIT
+ MOUSE_MOVE_ACCEL
;
79 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_UP
) mouse_vwheel
+= 1;
86 if (code
== MS_WH_DOWN
) mouse_vwheel
-= 1;
87 if (code
== MS_WH_LEFT
) mouse_hwheel
-= 1;
88 if (code
== MS_WH_RIGHT
) mouse_hwheel
+= 1;
89 } else if (IS_FN(code
)) {
90 fn_bits
|= FN_BIT(code
);
94 usb_keyboard_keys
[key_index
] = code
;
102 // LED flash for debug
108 layer_switching(fn_bits
);
110 // when 4 left modifier keys down
111 if (keymap_is_special_mode(fn_bits
)) {
112 switch (usb_keyboard_keys
[0]) {
115 print("b: jump to bootloader\n");
116 print("d: debug print toggle\n");
117 print("k: keyboard debug toggle\n");
118 print("m: mouse debug toggle\n");
119 print("x: matrix debug toggle\n");
120 print("v: print version\n");
121 print("t: print timer count\n");
122 print("p: print enable toggle\n");
124 print_enable
= false;
126 case KB_B
: // bootloader
127 usb_keyboard_clear_report();
130 print("jump to bootloader...\n");
132 jump_bootloader(); // not return
134 case KB_D
: // debug all toggle
135 usb_keyboard_clear_report();
137 debug_enable
= !debug_enable
;
140 print("debug enabled.\n");
142 debug_keyboard
= true;
145 print("debug disabled.\n");
146 print_enable
= false;
147 debug_matrix
= false;
148 debug_keyboard
= false;
153 case KB_X
: // debug matrix toggle
154 usb_keyboard_clear_report();
156 debug_matrix
= !debug_matrix
;
158 print("debug matrix enabled.\n");
160 print("debug matrix disabled.\n");
163 case KB_K
: // debug keyboard toggle
164 usb_keyboard_clear_report();
166 debug_keyboard
= !debug_keyboard
;
168 print("debug keyboard enabled.\n");
170 print("debug keyboard disabled.\n");
173 case KB_M
: // debug mouse toggle
174 usb_keyboard_clear_report();
176 debug_mouse
= !debug_mouse
;
178 print("debug mouse enabled.\n");
180 print("debug mouse disabled.\n");
183 case KB_V
: // print version & information
184 usb_keyboard_clear_report();
187 print(STR(DESCRIPTION
) "\n");
190 case KB_T
: // print timer
191 usb_keyboard_clear_report();
194 print("timer: "); phex16(timer_count
); print("\n");
197 case KB_P
: // print toggle
198 usb_keyboard_clear_report();
201 print("print disabled.\n");
202 print_enable
= false;
205 print("print enabled.\n");
213 // send mouse packet to host
214 if (mouse_x
|| mouse_y
|| mouse_vwheel
|| mouse_hwheel
|| mouse_btn
!= mouse_buttons
) {
215 mouse_buttons
= mouse_btn
;
216 if (mouse_x
&& mouse_y
)
217 usb_mouse_move(mouse_x
*0.7, mouse_y
*0.7, mouse_vwheel
, mouse_hwheel
);
219 usb_mouse_move(mouse_x
, mouse_y
, mouse_vwheel
, mouse_hwheel
);
220 usb_mouse_print(mouse_x
, mouse_y
, mouse_vwheel
, mouse_hwheel
);
223 _delay_ms(MOUSE_DELAY_MS
);
230 // send key packet to host