]>
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
;
99 layer_switching(fn_bits
);
101 // when 4 left modifier keys down
102 if (keymap_is_special_mode(fn_bits
)) {
103 switch (usb_keyboard_keys
[0]) {
106 print("b: jump to bootloader\n");
107 print("d: debug print toggle\n");
108 print("k: keyboard debug toggle\n");
109 print("m: mouse debug toggle\n");
110 print("x: matrix debug toggle\n");
111 print("v: print version\n");
112 print("t: print timer count\n");
113 print("p: print enable toggle\n");
115 print_enable
= false;
117 case KB_B
: // bootloader
118 usb_keyboard_clear_report();
121 print("jump to bootloader...\n");
123 jump_bootloader(); // not return
125 case KB_D
: // debug all toggle
126 usb_keyboard_clear_report();
128 debug_enable
= !debug_enable
;
131 print("debug enabled.\n");
133 debug_keyboard
= true;
136 print("debug disabled.\n");
137 print_enable
= false;
138 debug_matrix
= false;
139 debug_keyboard
= false;
144 case KB_X
: // debug matrix toggle
145 usb_keyboard_clear_report();
147 debug_matrix
= !debug_matrix
;
149 print("debug matrix enabled.\n");
151 print("debug matrix disabled.\n");
154 case KB_K
: // debug keyboard toggle
155 usb_keyboard_clear_report();
157 debug_keyboard
= !debug_keyboard
;
159 print("debug keyboard enabled.\n");
161 print("debug keyboard disabled.\n");
164 case KB_M
: // debug mouse toggle
165 usb_keyboard_clear_report();
167 debug_mouse
= !debug_mouse
;
169 print("debug mouse enabled.\n");
171 print("debug mouse disabled.\n");
174 case KB_V
: // print version & information
175 usb_keyboard_clear_report();
178 print(STR(DESCRIPTION
) "\n");
181 case KB_T
: // print timer
182 usb_keyboard_clear_report();
185 print("timer: "); phex16(timer_count
); print("\n");
188 case KB_P
: // print toggle
189 usb_keyboard_clear_report();
192 print("print disabled.\n");
193 print_enable
= false;
196 print("print enabled.\n");
204 // send mouse packet to host
205 if (mouse_x
|| mouse_y
|| mouse_vwheel
|| mouse_hwheel
|| mouse_btn
!= mouse_buttons
) {
206 mouse_buttons
= mouse_btn
;
207 if (mouse_x
&& mouse_y
)
208 usb_mouse_move(mouse_x
*0.7, mouse_y
*0.7, mouse_vwheel
, mouse_hwheel
);
210 usb_mouse_move(mouse_x
, mouse_y
, mouse_vwheel
, mouse_hwheel
);
211 usb_mouse_print(mouse_x
, mouse_y
, mouse_vwheel
, mouse_hwheel
);
214 _delay_ms(MOUSE_DELAY_MS
);
221 // send key packet to host
228 // LED flash for debug