6 #include "usb_keycodes.h"
11 #ifdef MOUSEKEY_ENABLE
14 #ifdef USB_EXTRA_ENABLE
15 #include <util/delay.h>
19 static uint8_t last_leds = 0;
22 void keyboard_init(void)
26 #ifdef PS2_MOUSE_ENABLE
31 void keyboard_proc(void)
34 #ifdef USB_EXTRA_ENABLE
35 uint16_t consumer_code = 0;
40 if (matrix_is_modified()) {
41 if (debug_matrix) matrix_print();
43 // LED flash for debug
49 if (matrix_has_ghost()) {
51 debug("matrix has ghost!!\n");
55 host_swap_keyboard_report();
56 host_clear_keyboard_report();
57 for (int row = 0; row < matrix_rows(); row++) {
58 for (int col = 0; col < matrix_cols(); col++) {
59 if (!matrix_is_on(row, col)) continue;
61 uint8_t code = layer_get_keycode(row, col);
64 } else if (IS_MOD(code)) {
65 host_add_mod_bit(MOD_BIT(code));
66 } else if (IS_FN(code)) {
67 fn_bits |= FN_BIT(code);
69 #ifdef USB_EXTRA_ENABLE
71 else if (code == KB_SYSTEM_POWER) {
73 if (suspend && remote_wakeup) {
76 host_system_send(SYSTEM_POWER_DOWN);
79 host_system_send(SYSTEM_POWER_DOWN);
83 } else if (code == KB_SYSTEM_SLEEP) {
84 host_system_send(SYSTEM_SLEEP);
87 } else if (code == KB_SYSTEM_WAKE) {
88 host_system_send(SYSTEM_WAKE_UP);
93 else if (code == KB_AUDIO_MUTE) {
94 consumer_code = AUDIO_MUTE;
95 } else if (code == KB_AUDIO_VOL_UP) {
96 consumer_code = AUDIO_VOL_UP;
97 } else if (code == KB_AUDIO_VOL_DOWN) {
98 consumer_code = AUDIO_VOL_DOWN;
100 else if (code == KB_MEDIA_NEXT_TRACK) {
101 consumer_code = TRANSPORT_NEXT_TRACK;
102 } else if (code == KB_MEDIA_PREV_TRACK) {
103 consumer_code = TRANSPORT_PREV_TRACK;
104 } else if (code == KB_MEDIA_STOP) {
105 consumer_code = TRANSPORT_STOP;
106 } else if (code == KB_MEDIA_PLAY_PAUSE) {
107 consumer_code = TRANSPORT_PLAY_PAUSE;
108 } else if (code == KB_MEDIA_SELECT) {
109 consumer_code = AL_CC_CONFIG;
111 else if (code == KB_MAIL) {
112 consumer_code = AL_EMAIL;
113 } else if (code == KB_CALCULATOR) {
114 consumer_code = AL_CALCULATOR;
115 } else if (code == KB_MY_COMPUTER) {
116 consumer_code = AL_LOCAL_BROWSER;
118 else if (code == KB_WWW_SEARCH) {
119 consumer_code = AC_SEARCH;
120 } else if (code == KB_WWW_HOME) {
121 consumer_code = AC_HOME;
122 } else if (code == KB_WWW_BACK) {
123 consumer_code = AC_BACK;
124 } else if (code == KB_WWW_FORWARD) {
125 consumer_code = AC_FORWARD;
126 } else if (code == KB_WWW_STOP) {
127 consumer_code = AC_STOP;
128 } else if (code == KB_WWW_REFRESH) {
129 consumer_code = AC_REFRESH;
130 } else if (code == KB_WWW_FAVORITES) {
131 consumer_code = AC_BOOKMARKS;
134 else if (IS_KEY(code)) {
137 #ifdef MOUSEKEY_ENABLE
138 else if (IS_MOUSEKEY(code)) {
139 mousekey_decode(code);
143 debug("ignore keycode: "); debug_hex(code); debug("\n");
148 layer_switching(fn_bits);
150 if (command_proc()) {
154 // TODO: should send only when changed from last report
155 if (matrix_is_modified()) {
156 host_send_keyboard_report();
157 #ifdef USB_EXTRA_ENABLE
158 host_consumer_send(consumer_code);
161 // LED flash for debug
167 #ifdef MOUSEKEY_ENABLE
171 #ifdef PS2_MOUSE_ENABLE
172 // TODO: should comform new API
173 if (ps2_mouse_read() == 0)
174 ps2_mouse_usb_send();
177 if (last_leds != host_keyboard_leds()) {
178 keyboard_set_leds(host_keyboard_leds());
179 last_leds = host_keyboard_leds();
183 void keyboard_set_leds(uint8_t leds)