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;
52 uint16_t system_code = 0;
57 if (matrix_is_modified()) {
58 if (debug_matrix) matrix_print();
60 // LED flash for debug
66 if (matrix_has_ghost()) {
68 debug("matrix has ghost!!\n");
72 host_swap_keyboard_report();
73 host_clear_keyboard_report();
74 for (int row = 0; row < matrix_rows(); row++) {
75 for (int col = 0; col < matrix_cols(); col++) {
76 if (!matrix_is_on(row, col)) continue;
78 uint8_t code = layer_get_keycode(row, col);
81 } else if (IS_MOD(code)) {
82 host_add_mod_bit(MOD_BIT(code));
83 } else if (IS_FN(code)) {
84 fn_bits |= FN_BIT(code);
86 // TODO: use table or something
87 #ifdef EXTRAKEY_ENABLE
89 else if (code == KB_SYSTEM_POWER) {
91 if (suspend && remote_wakeup) {
95 system_code = SYSTEM_POWER_DOWN;
96 } else if (code == KB_SYSTEM_SLEEP) {
97 system_code = SYSTEM_SLEEP;
98 } else if (code == KB_SYSTEM_WAKE) {
99 system_code = SYSTEM_WAKE_UP;
102 else if (code == KB_AUDIO_MUTE) {
103 consumer_code = AUDIO_MUTE;
104 } else if (code == KB_AUDIO_VOL_UP) {
105 consumer_code = AUDIO_VOL_UP;
106 } else if (code == KB_AUDIO_VOL_DOWN) {
107 consumer_code = AUDIO_VOL_DOWN;
109 else if (code == KB_MEDIA_NEXT_TRACK) {
110 consumer_code = TRANSPORT_NEXT_TRACK;
111 } else if (code == KB_MEDIA_PREV_TRACK) {
112 consumer_code = TRANSPORT_PREV_TRACK;
113 } else if (code == KB_MEDIA_STOP) {
114 consumer_code = TRANSPORT_STOP;
115 } else if (code == KB_MEDIA_PLAY_PAUSE) {
116 consumer_code = TRANSPORT_PLAY_PAUSE;
117 } else if (code == KB_MEDIA_SELECT) {
118 consumer_code = AL_CC_CONFIG;
120 else if (code == KB_MAIL) {
121 consumer_code = AL_EMAIL;
122 } else if (code == KB_CALCULATOR) {
123 consumer_code = AL_CALCULATOR;
124 } else if (code == KB_MY_COMPUTER) {
125 consumer_code = AL_LOCAL_BROWSER;
127 else if (code == KB_WWW_SEARCH) {
128 consumer_code = AC_SEARCH;
129 } else if (code == KB_WWW_HOME) {
130 consumer_code = AC_HOME;
131 } else if (code == KB_WWW_BACK) {
132 consumer_code = AC_BACK;
133 } else if (code == KB_WWW_FORWARD) {
134 consumer_code = AC_FORWARD;
135 } else if (code == KB_WWW_STOP) {
136 consumer_code = AC_STOP;
137 } else if (code == KB_WWW_REFRESH) {
138 consumer_code = AC_REFRESH;
139 } else if (code == KB_WWW_FAVORITES) {
140 consumer_code = AC_BOOKMARKS;
143 else if (IS_KEY(code)) {
146 #ifdef MOUSEKEY_ENABLE
147 else if (IS_MOUSEKEY(code)) {
148 mousekey_decode(code);
152 debug("ignore keycode: "); debug_hex(code); debug("\n");
157 layer_switching(fn_bits);
159 if (command_proc()) {
163 // TODO: should send only when changed from last report
164 if (matrix_is_modified()) {
165 host_send_keyboard_report();
166 #ifdef EXTRAKEY_ENABLE
167 host_consumer_send(consumer_code);
168 host_system_send(system_code);
171 // LED flash for debug
177 #ifdef MOUSEKEY_ENABLE
181 #ifdef PS2_MOUSE_ENABLE
182 // TODO: should comform new API
183 if (ps2_mouse_read() == 0)
184 ps2_mouse_usb_send();
187 if (last_leds != host_keyboard_leds()) {
188 keyboard_set_leds(host_keyboard_leds());
189 last_leds = host_keyboard_leds();
193 void keyboard_set_leds(uint8_t leds)