2 Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com>
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.
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.
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/>.
29 #include "bootloader.h"
30 #ifdef MOUSEKEY_ENABLE
35 void keyboard_init(void)
37 // TODO: configuration of sendchar impl
38 print_sendchar_func = sendchar;
43 /* boot magic keys goes here */
45 #ifdef IS_BOOTMAGIC_BOOTLOADER
46 /* kick up bootloader */
47 if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump();
49 #ifdef IS_BOOTMAGIC_DEBUG
50 if (IS_BOOTMAGIC_DEBUG()) debug_enable = true;
53 #ifdef PS2_MOUSE_ENABLE
59 * Do keyboard routine jobs: scan mantrix, light LEDs, ...
60 * This is repeatedly called as fast as possible.
62 void keyboard_task(void)
64 static matrix_row_t matrix_prev[MATRIX_ROWS];
65 static uint8_t led_status = 0;
66 matrix_row_t matrix_row = 0;
67 matrix_row_t matrix_change = 0;
70 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
71 matrix_row = matrix_get_row(r);
72 matrix_change = matrix_row ^ matrix_prev[r];
74 if (debug_matrix) matrix_print();
76 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
77 if (matrix_change & ((matrix_row_t)1<<c)) {
78 action_exec((keyevent_t){
79 .key.pos = (keypos_t){ .row = r, .col = c },
80 .pressed = (matrix_row & (1<<c)),
81 .time = (timer_read() | 1) /* time should not be 0 */
83 // record a processed key
84 matrix_prev[r] ^= ((matrix_row_t)1<<c);
85 // process a key per task call
91 // call with pseudo tick event when no real key event.
95 #ifdef MOUSEKEY_ENABLE
96 // mousekey repeat & acceleration
100 if (led_status != host_keyboard_leds()) {
101 led_status = host_keyboard_leds();
102 keyboard_set_leds(led_status);
106 void keyboard_set_leds(uint8_t leds)