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)
37 if (matrix_is_modified()) {
38 if (debug_matrix) matrix_print();
40 // LED flash for debug
46 if (matrix_has_ghost()) {
48 debug("matrix has ghost!!\n");
52 host_swap_keyboard_report();
53 host_clear_keyboard_report();
54 for (int row = 0; row < matrix_rows(); row++) {
55 for (int col = 0; col < matrix_cols(); col++) {
56 if (!matrix_is_on(row, col)) continue;
58 uint8_t code = layer_get_keycode(row, col);
61 } else if (IS_MOD(code)) {
62 host_add_mod_bit(MOD_BIT(code));
63 } else if (IS_FN(code)) {
64 fn_bits |= FN_BIT(code);
66 #ifdef USB_EXTRA_ENABLE
67 // audio control & system control
68 else if (code == KB_MUTE) {
69 host_audio_send(AUDIO_MUTE);
72 } else if (code == KB_VOLU) {
73 host_audio_send(AUDIO_VOL_UP);
76 } else if (code == KB_VOLD) {
77 host_audio_send(AUDIO_VOL_DOWN);
80 } else if (code == KB_PWR) {
82 if (suspend && remote_wakeup) {
85 host_system_send(SYSTEM_POWER_DOWN);
88 host_system_send(SYSTEM_POWER_DOWN);
93 else if (IS_KEY(code)) {
96 #ifdef MOUSEKEY_ENABLE
97 else if (IS_MOUSEKEY(code)) {
98 mousekey_decode(code);
102 debug("ignore keycode: "); debug_hex(code); debug("\n");
107 layer_switching(fn_bits);
109 if (command_proc()) {
113 // TODO: should send only when changed from last report
114 if (matrix_is_modified()) {
115 host_send_keyboard_report();
117 // LED flash for debug
123 #ifdef MOUSEKEY_ENABLE
127 #ifdef PS2_MOUSE_ENABLE
128 // TODO: should comform new API
129 if (ps2_mouse_read() == 0)
130 ps2_mouse_usb_send();
133 if (last_leds != host_keyboard_leds()) {
134 keyboard_set_leds(host_keyboard_leds());
135 last_leds = host_keyboard_leds();
139 void keyboard_set_leds(uint8_t leds)