]> git.gir.st - tmk_keyboard.git/blob - common/keyboard.c
Fix action of system and consumer usage.
[tmk_keyboard.git] / common / keyboard.c
1 /*
2 Copyright 2011,2012 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "keyboard.h"
18 #include "matrix.h"
19 #include "keymap.h"
20 #include "host.h"
21 #include "led.h"
22 #include "keycode.h"
23 #include "timer.h"
24 #include "print.h"
25 #include "debug.h"
26 #include "command.h"
27 #include "util.h"
28 #include "sendchar.h"
29 #ifdef MOUSEKEY_ENABLE
30 #include "mousekey.h"
31 #endif
32
33
34 void keyboard_init(void)
35 {
36 // TODO: to enable debug print magic key bind on boot time
37
38 // TODO: configuration of sendchar impl
39 print_sendchar_func = sendchar;
40
41 timer_init();
42 matrix_init();
43 #ifdef PS2_MOUSE_ENABLE
44 ps2_mouse_init();
45 #endif
46 }
47
48 /*
49 * Do keyboard routine jobs: scan mantrix, light LEDs, ...
50 * This is repeatedly called as fast as possible.
51 */
52 void keyboard_task(void)
53 {
54 static matrix_row_t matrix_prev[MATRIX_ROWS];
55 static uint8_t led_status = 0;
56 matrix_row_t matrix_row = 0;
57 matrix_row_t matrix_change = 0;
58
59 matrix_scan();
60 for (int r = 0; r < MATRIX_ROWS; r++) {
61 matrix_row = matrix_get_row(r);
62 matrix_change = matrix_row ^ matrix_prev[r];
63 if (matrix_change) {
64 if (debug_matrix) matrix_print();
65
66 for (int c = 0; c < MATRIX_COLS; c++) {
67 if (matrix_change & (1<<c)) {
68 keymap_process_event((keyevent_t){
69 .key = (keypos_t){ .row = r, .col = c },
70 .pressed = (matrix_row & (1<<c))
71 });
72 // record a processed key
73 matrix_prev[r] ^= (1<<c);
74 // process a key per task call
75 goto MATRIX_LOOP_END;
76 }
77 }
78 }
79 }
80 MATRIX_LOOP_END:
81
82 #ifdef MOUSEKEY_ENABLE
83 // mousekey repeat & acceleration
84 mousekey_task();
85 #endif
86
87 // update LED
88 if (led_status != host_keyboard_leds()) {
89 led_status = host_keyboard_leds();
90 keyboard_set_leds(led_status);
91 }
92
93 return;
94 }
95
96 void keyboard_set_leds(uint8_t leds)
97 {
98 led_set(leds);
99 }
Imprint / Impressum