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 USB_EXTRA_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 USB_EXTRA_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 #ifdef USB_EXTRA_ENABLE
87 else if (code == KB_SYSTEM_POWER) {
89 if (suspend && remote_wakeup) {
92 host_system_send(SYSTEM_POWER_DOWN);
95 host_system_send(SYSTEM_POWER_DOWN);
99 } else if (code == KB_SYSTEM_SLEEP) {
100 host_system_send(SYSTEM_SLEEP);
103 } else if (code == KB_SYSTEM_WAKE) {
104 host_system_send(SYSTEM_WAKE_UP);
109 else if (code == KB_AUDIO_MUTE) {
110 consumer_code = AUDIO_MUTE;
111 } else if (code == KB_AUDIO_VOL_UP) {
112 consumer_code = AUDIO_VOL_UP;
113 } else if (code == KB_AUDIO_VOL_DOWN) {
114 consumer_code = AUDIO_VOL_DOWN;
116 else if (code == KB_MEDIA_NEXT_TRACK) {
117 consumer_code = TRANSPORT_NEXT_TRACK;
118 } else if (code == KB_MEDIA_PREV_TRACK) {
119 consumer_code = TRANSPORT_PREV_TRACK;
120 } else if (code == KB_MEDIA_STOP) {
121 consumer_code = TRANSPORT_STOP;
122 } else if (code == KB_MEDIA_PLAY_PAUSE) {
123 consumer_code = TRANSPORT_PLAY_PAUSE;
124 } else if (code == KB_MEDIA_SELECT) {
125 consumer_code = AL_CC_CONFIG;
127 else if (code == KB_MAIL) {
128 consumer_code = AL_EMAIL;
129 } else if (code == KB_CALCULATOR) {
130 consumer_code = AL_CALCULATOR;
131 } else if (code == KB_MY_COMPUTER) {
132 consumer_code = AL_LOCAL_BROWSER;
134 else if (code == KB_WWW_SEARCH) {
135 consumer_code = AC_SEARCH;
136 } else if (code == KB_WWW_HOME) {
137 consumer_code = AC_HOME;
138 } else if (code == KB_WWW_BACK) {
139 consumer_code = AC_BACK;
140 } else if (code == KB_WWW_FORWARD) {
141 consumer_code = AC_FORWARD;
142 } else if (code == KB_WWW_STOP) {
143 consumer_code = AC_STOP;
144 } else if (code == KB_WWW_REFRESH) {
145 consumer_code = AC_REFRESH;
146 } else if (code == KB_WWW_FAVORITES) {
147 consumer_code = AC_BOOKMARKS;
150 else if (IS_KEY(code)) {
153 #ifdef MOUSEKEY_ENABLE
154 else if (IS_MOUSEKEY(code)) {
155 mousekey_decode(code);
159 debug("ignore keycode: "); debug_hex(code); debug("\n");
164 layer_switching(fn_bits);
166 if (command_proc()) {
170 // TODO: should send only when changed from last report
171 if (matrix_is_modified()) {
172 host_send_keyboard_report();
173 #ifdef USB_EXTRA_ENABLE
174 host_consumer_send(consumer_code);
177 // LED flash for debug
183 #ifdef MOUSEKEY_ENABLE
187 #ifdef PS2_MOUSE_ENABLE
188 // TODO: should comform new API
189 if (ps2_mouse_read() == 0)
190 ps2_mouse_usb_send();
193 if (last_leds != host_keyboard_leds()) {
194 keyboard_set_leds(host_keyboard_leds());
195 last_leds = host_keyboard_leds();
199 void keyboard_set_leds(uint8_t leds)