]>
git.gir.st - tmk_keyboard.git/blob - key_process.c
3 #include <avr/interrupt.h>
4 #include <util/delay.h>
9 #include "jump_bootloader.h"
10 #include "usb_keyboard.h"
11 #include "usb_mouse.h"
12 #include "usb_extra.h"
13 #include "usb_keycodes.h"
16 #include "matrix_skel.h"
17 #include "keymap_skel.h"
18 #include "key_process.h"
19 #ifdef MOUSEKEY_ENABLE
20 # include "mousekey.h"
22 #ifdef PS2_MOUSE_ENABLE
23 # include "ps2_mouse.h"
28 void proc_matrix(void) {
29 bool modified
= false;
33 modified
= matrix_is_modified();
36 if (debug_matrix
) matrix_print();
38 // LED flash for debug
44 if (matrix_has_ghost()) {
46 debug("matrix has ghost!!\n");
50 usb_keyboard_swap_report();
51 usb_keyboard_clear_report();
52 for (int row
= 0; row
< matrix_rows(); row
++) {
53 for (int col
= 0; col
< matrix_cols(); col
++) {
54 if (!matrix_is_on(row
, col
)) continue;
57 uint8_t code
= layer_get_keycode(row
, col
);
60 } else if (IS_MOD(code
)) {
61 usb_keyboard_add_mod(code
);
62 } else if (IS_FN(code
)) {
63 fn_bits
|= FN_BIT(code
);
64 } else if (IS_MOUSE(code
)) {
65 #ifdef MOUSEKEY_ENABLE
66 mousekey_decode(code
);
70 // audio control & system control
71 else if (code
== KB_MUTE
) {
72 usb_extra_audio_send(AUDIO_MUTE
);
73 usb_extra_audio_send(0);
75 } else if (code
== KB_VOLU
) {
76 usb_extra_audio_send(AUDIO_VOL_UP
);
77 usb_extra_audio_send(0);
79 } else if (code
== KB_VOLD
) {
80 usb_extra_audio_send(AUDIO_VOL_DOWN
);
81 usb_extra_audio_send(0);
83 } else if (code
== KB_PWR
) {
84 if (suspend
&& remote_wakeup
) {
87 usb_extra_system_send(SYSTEM_POWER_DOWN
);
94 usb_keyboard_add_key(code
);
101 // LED flash for debug
107 layer_switching(fn_bits
);
110 // special mode for control, develop and debug
111 if (keymap_is_special_mode(fn_bits
)) {
112 switch (usb_keyboard_get_key()) {
115 print("b: jump to bootloader\n");
116 print("d: toggle debug enable\n");
117 print("x: toggle matrix debug\n");
118 print("k: toggle keyboard debug\n");
119 print("m: toggle mouse debug\n");
120 print("p: toggle print enable\n");
121 print("v: print version\n");
122 print("t: print timer count\n");
123 print("s: print status\n");
124 print("`: toggle protcol(boot/report)\n");
125 #ifdef USB_NKRO_ENABLE
126 print("n: toggle USB_NKRO\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 print("3: ps2_mouse: on/off toggle \n");
135 print_enable
= false;
137 #ifdef PS2_MOUSE_ENABLE
139 usb_keyboard_clear_report();
142 print("ps2_mouse_init...\n");
147 usb_keyboard_clear_report();
150 print("ps2_mouse_read[btn x y]: ");
153 phex(ps2_mouse_btn
); print(" ");
154 phex(ps2_mouse_x
); print(" ");
155 phex(ps2_mouse_y
); print("\n");
156 print("ps2_mouse_error_count: "); phex(ps2_mouse_error_count
); print("\n");
159 ps2_mouse_enable
= !ps2_mouse_enable
;
160 print("ps2_mouse: ");
161 if (ps2_mouse_enable
)
169 case KB_B
: // bootloader
170 usb_keyboard_clear_report();
173 print("jump to bootloader...\n");
175 jump_bootloader(); // not return
177 case KB_D
: // debug all toggle
178 usb_keyboard_clear_report();
180 debug_enable
= !debug_enable
;
183 print("debug enabled.\n");
185 debug_keyboard
= true;
188 print("debug disabled.\n");
189 print_enable
= false;
190 debug_matrix
= false;
191 debug_keyboard
= false;
196 case KB_X
: // debug matrix toggle
197 usb_keyboard_clear_report();
199 debug_matrix
= !debug_matrix
;
201 print("debug matrix enabled.\n");
203 print("debug matrix disabled.\n");
206 case KB_K
: // debug keyboard toggle
207 usb_keyboard_clear_report();
209 debug_keyboard
= !debug_keyboard
;
211 print("debug keyboard enabled.\n");
213 print("debug keyboard disabled.\n");
216 case KB_M
: // debug mouse toggle
217 usb_keyboard_clear_report();
219 debug_mouse
= !debug_mouse
;
221 print("debug mouse enabled.\n");
223 print("debug mouse disabled.\n");
226 case KB_V
: // print version & information
227 usb_keyboard_clear_report();
230 print(STR(DESCRIPTION
) "\n");
233 case KB_T
: // print timer
234 usb_keyboard_clear_report();
237 print("timer: "); phex16(timer_count
); print("\n");
240 case KB_P
: // print toggle
241 usb_keyboard_clear_report();
244 print("print disabled.\n");
245 print_enable
= false;
248 print("print enabled.\n");
253 usb_keyboard_clear_report();
255 print("UDCON: "); phex(UDCON
); print("\n");
256 print("UDIEN: "); phex(UDIEN
); print("\n");
257 print("UDINT: "); phex(UDINT
); print("\n");
258 print("usb_keyboard_leds:"); phex(usb_keyboard_leds
); print("\n");
259 print("usb_keyboard_protocol:"); phex(usb_keyboard_protocol
); print("\n");
260 print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config
); print("\n");
261 print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count
); print("\n");
262 print("usb_mouse_protocol:"); phex(usb_mouse_protocol
); print("\n");
263 if (usb_keyboard_nkro
) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n");
267 usb_keyboard_clear_report();
269 usb_keyboard_protocol
= !usb_keyboard_protocol
;
270 usb_mouse_protocol
= !usb_mouse_protocol
;
271 print("keyboard protcol: ");
272 if (usb_keyboard_protocol
) print("report"); else print("boot");
274 print("mouse protcol: ");
275 if (usb_mouse_protocol
) print("report"); else print("boot");
279 #ifdef USB_NKRO_ENABLE
281 usb_keyboard_clear_report();
283 usb_keyboard_nkro
= !usb_keyboard_nkro
;
284 if (usb_keyboard_nkro
) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n");
289 usb_keyboard_clear_report();
291 if (suspend
&& remote_wakeup
) {
294 usb_extra_system_send(SYSTEM_POWER_DOWN
);
306 #ifdef MOUSEKEY_ENABLE
311 #ifdef PS2_MOUSE_ENABLE
313 if (ps2_mouse_read() == 0)
314 ps2_mouse_usb_send();