]>
git.gir.st - tmk_keyboard.git/blob - keyboard.c
2 Copyright 2011 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/>.
22 #include "usb_keycodes.h"
27 #ifdef MOUSEKEY_ENABLE
30 #ifdef EXTRAKEY_ENABLE
31 #include <util/delay.h>
35 static uint8_t last_leds
= 0;
38 void keyboard_init(void)
42 #ifdef PS2_MOUSE_ENABLE
47 void keyboard_proc(void)
50 #ifdef EXTRAKEY_ENABLE
51 uint16_t consumer_code
= 0;
56 if (matrix_is_modified()) {
57 if (debug_matrix
) matrix_print();
59 // LED flash for debug
65 if (matrix_has_ghost()) {
67 debug("matrix has ghost!!\n");
71 host_swap_keyboard_report();
72 host_clear_keyboard_report();
73 for (int row
= 0; row
< matrix_rows(); row
++) {
74 for (int col
= 0; col
< matrix_cols(); col
++) {
75 if (!matrix_is_on(row
, col
)) continue;
77 uint8_t code
= layer_get_keycode(row
, col
);
80 } else if (IS_MOD(code
)) {
81 host_add_mod_bit(MOD_BIT(code
));
82 } else if (IS_FN(code
)) {
83 fn_bits
|= FN_BIT(code
);
85 // TODO: use table or something
86 #ifdef EXTRAKEY_ENABLE
88 else if (code
== KB_SYSTEM_POWER
) {
90 if (suspend
&& remote_wakeup
) {
93 host_system_send(SYSTEM_POWER_DOWN
);
96 host_system_send(SYSTEM_POWER_DOWN
);
100 } else if (code
== KB_SYSTEM_SLEEP
) {
101 host_system_send(SYSTEM_SLEEP
);
104 } else if (code
== KB_SYSTEM_WAKE
) {
105 host_system_send(SYSTEM_WAKE_UP
);
110 else if (code
== KB_AUDIO_MUTE
) {
111 consumer_code
= AUDIO_MUTE
;
112 } else if (code
== KB_AUDIO_VOL_UP
) {
113 consumer_code
= AUDIO_VOL_UP
;
114 } else if (code
== KB_AUDIO_VOL_DOWN
) {
115 consumer_code
= AUDIO_VOL_DOWN
;
117 else if (code
== KB_MEDIA_NEXT_TRACK
) {
118 consumer_code
= TRANSPORT_NEXT_TRACK
;
119 } else if (code
== KB_MEDIA_PREV_TRACK
) {
120 consumer_code
= TRANSPORT_PREV_TRACK
;
121 } else if (code
== KB_MEDIA_STOP
) {
122 consumer_code
= TRANSPORT_STOP
;
123 } else if (code
== KB_MEDIA_PLAY_PAUSE
) {
124 consumer_code
= TRANSPORT_PLAY_PAUSE
;
125 } else if (code
== KB_MEDIA_SELECT
) {
126 consumer_code
= AL_CC_CONFIG
;
128 else if (code
== KB_MAIL
) {
129 consumer_code
= AL_EMAIL
;
130 } else if (code
== KB_CALCULATOR
) {
131 consumer_code
= AL_CALCULATOR
;
132 } else if (code
== KB_MY_COMPUTER
) {
133 consumer_code
= AL_LOCAL_BROWSER
;
135 else if (code
== KB_WWW_SEARCH
) {
136 consumer_code
= AC_SEARCH
;
137 } else if (code
== KB_WWW_HOME
) {
138 consumer_code
= AC_HOME
;
139 } else if (code
== KB_WWW_BACK
) {
140 consumer_code
= AC_BACK
;
141 } else if (code
== KB_WWW_FORWARD
) {
142 consumer_code
= AC_FORWARD
;
143 } else if (code
== KB_WWW_STOP
) {
144 consumer_code
= AC_STOP
;
145 } else if (code
== KB_WWW_REFRESH
) {
146 consumer_code
= AC_REFRESH
;
147 } else if (code
== KB_WWW_FAVORITES
) {
148 consumer_code
= AC_BOOKMARKS
;
151 else if (IS_KEY(code
)) {
154 #ifdef MOUSEKEY_ENABLE
155 else if (IS_MOUSEKEY(code
)) {
156 mousekey_decode(code
);
160 debug("ignore keycode: "); debug_hex(code
); debug("\n");
165 layer_switching(fn_bits
);
167 if (command_proc()) {
171 // TODO: should send only when changed from last report
172 if (matrix_is_modified()) {
173 host_send_keyboard_report();
174 #ifdef EXTRAKEY_ENABLE
175 host_consumer_send(consumer_code
);
178 // LED flash for debug
184 #ifdef MOUSEKEY_ENABLE
188 #ifdef PS2_MOUSE_ENABLE
189 // TODO: should comform new API
190 if (ps2_mouse_read() == 0)
191 ps2_mouse_usb_send();
194 if (last_leds
!= host_keyboard_leds()) {
195 keyboard_set_leds(host_keyboard_leds());
196 last_leds
= host_keyboard_leds();
200 void keyboard_set_leds(uint8_t leds
)