]>
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_extra.h"
12 #include "usb_keycodes.h"
14 #include "matrix_skel.h"
15 #include "keymap_skel.h"
16 #include "controller.h"
17 #include "key_process.h"
20 #define MOUSE_MOVE_UNIT 10
21 #define MOUSE_MOVE_ACCEL (mouse_repeat < 50 ? mouse_repeat/5 : 10)
23 #ifndef MOUSE_DELAY_TIME
24 # define MOUSE_DELAY_TIME 255
26 #define MOUSE_DELAY_MS (MOUSE_DELAY_TIME >> (mouse_repeat < 5 ? mouse_repeat : 4))
30 void proc_matrix(void) {
31 static int mouse_repeat
= 0;
33 bool modified
= false;
34 //bool has_ghost = false;
36 uint8_t mouse_btn
= 0;
39 int8_t mouse_vwheel
= 0;
40 int8_t mouse_hwheel
= 0;
44 modified
= matrix_is_modified();
47 if (debug_matrix
) matrix_print();
49 // LED flash for debug
55 if (matrix_has_ghost()) {
57 debug("matrix has ghost!!\n");
61 usb_keyboard_clear_report();
62 for (int row
= 0; row
< matrix_rows(); row
++) {
63 for (int col
= 0; col
< matrix_cols(); col
++) {
64 if (!matrix_is_on(row
, col
)) continue;
66 uint8_t code
= layer_get_keycode(row
, col
);
69 } else if (IS_MOD(code
)) {
70 usb_keyboard_mods
|= MOD_BIT(code
);
71 } else if (IS_MOUSE(code
)) {
74 mouse_y
-= MOUSE_MOVE_UNIT
+ MOUSE_MOVE_ACCEL
;
76 mouse_y
+= MOUSE_MOVE_UNIT
+ MOUSE_MOVE_ACCEL
;
78 mouse_x
-= MOUSE_MOVE_UNIT
+ MOUSE_MOVE_ACCEL
;
80 mouse_x
+= MOUSE_MOVE_UNIT
+ MOUSE_MOVE_ACCEL
;
81 if (code
== MS_BTN1
) mouse_btn
|= BIT_BTN1
;
82 if (code
== MS_BTN2
) mouse_btn
|= BIT_BTN2
;
83 if (code
== MS_BTN3
) mouse_btn
|= BIT_BTN3
;
84 if (code
== MS_BTN4
) mouse_btn
|= BIT_BTN4
;
85 if (code
== MS_BTN5
) mouse_btn
|= BIT_BTN5
;
86 if (code
== MS_WH_UP
) mouse_vwheel
+= 1;
87 if (code
== MS_WH_DOWN
) mouse_vwheel
-= 1;
88 if (code
== MS_WH_LEFT
) mouse_hwheel
-= 1;
89 if (code
== MS_WH_RIGHT
) mouse_hwheel
+= 1;
90 } else if (IS_FN(code
)) {
91 fn_bits
|= FN_BIT(code
);
92 } else if (code
== KB_MUTE
) {
93 usb_extra_send(AUDIO_MUTE
);
96 } else if (code
== KB_VOLU
) {
97 usb_extra_send(AUDIO_VOL_UP
);
100 } else if (code
== KB_VOLD
) {
101 usb_extra_send(AUDIO_VOL_DOWN
);
107 usb_keyboard_keys
[key_index
] = code
;
115 // LED flash for debug
121 layer_switching(fn_bits
);
123 // when 4 left modifier keys down
124 if (keymap_is_special_mode(fn_bits
)) {
125 switch (usb_keyboard_keys
[0]) {
128 print("b: jump to bootloader\n");
129 print("d: debug print toggle\n");
130 print("k: keyboard debug toggle\n");
131 print("m: mouse debug toggle\n");
132 print("x: matrix debug toggle\n");
133 print("v: print version\n");
134 print("t: print timer count\n");
135 print("p: print enable toggle\n");
137 print_enable
= false;
139 case KB_B
: // bootloader
140 usb_keyboard_clear_report();
143 print("jump to bootloader...\n");
145 jump_bootloader(); // not return
147 case KB_D
: // debug all toggle
148 usb_keyboard_clear_report();
150 debug_enable
= !debug_enable
;
153 print("debug enabled.\n");
155 debug_keyboard
= true;
158 print("debug disabled.\n");
159 print_enable
= false;
160 debug_matrix
= false;
161 debug_keyboard
= false;
166 case KB_X
: // debug matrix toggle
167 usb_keyboard_clear_report();
169 debug_matrix
= !debug_matrix
;
171 print("debug matrix enabled.\n");
173 print("debug matrix disabled.\n");
176 case KB_K
: // debug keyboard toggle
177 usb_keyboard_clear_report();
179 debug_keyboard
= !debug_keyboard
;
181 print("debug keyboard enabled.\n");
183 print("debug keyboard disabled.\n");
186 case KB_M
: // debug mouse toggle
187 usb_keyboard_clear_report();
189 debug_mouse
= !debug_mouse
;
191 print("debug mouse enabled.\n");
193 print("debug mouse disabled.\n");
196 case KB_V
: // print version & information
197 usb_keyboard_clear_report();
200 print(STR(DESCRIPTION
) "\n");
203 case KB_T
: // print timer
204 usb_keyboard_clear_report();
207 print("timer: "); phex16(timer_count
); print("\n");
210 case KB_P
: // print toggle
211 usb_keyboard_clear_report();
214 print("print disabled.\n");
215 print_enable
= false;
218 print("print enabled.\n");
226 // send mouse packet to host
227 if (mouse_x
|| mouse_y
|| mouse_vwheel
|| mouse_hwheel
|| mouse_btn
!= mouse_buttons
) {
228 mouse_buttons
= mouse_btn
;
229 if (mouse_x
&& mouse_y
)
230 usb_mouse_move(mouse_x
*0.7, mouse_y
*0.7, mouse_vwheel
, mouse_hwheel
);
232 usb_mouse_move(mouse_x
, mouse_y
, mouse_vwheel
, mouse_hwheel
);
233 usb_mouse_print(mouse_x
, mouse_y
, mouse_vwheel
, mouse_hwheel
);
236 _delay_ms(MOUSE_DELAY_MS
);
243 // send key packet to host