2 #include "usb_keycodes.h"
3 #include "usb_keyboard.h"
10 bool keyboard_nkro = false;
13 static report_keyboard_t report0;
14 static report_keyboard_t report1;
15 report_keyboard_t *keyboard_report = &report0;
16 report_keyboard_t *keyboard_report_prev = &report1;
18 static inline void add_key_byte(uint8_t code);
19 static inline void add_key_bit(uint8_t code);
22 uint8_t host_keyboard_leds(void)
24 return usb_keyboard_leds;
27 /* keyboard report operations */
28 void host_add_key(uint8_t key)
30 #ifdef USB_NKRO_ENABLE
39 void host_add_mod_bit(uint8_t mod)
41 keyboard_report->mods |= mod;
44 void host_set_mods(uint8_t mods)
46 keyboard_report->mods = mods;
49 void host_add_code(uint8_t code)
52 host_add_mod_bit(MOD_BIT(code));
58 void host_swap_keyboard_report(void)
60 report_keyboard_t *tmp = keyboard_report_prev;
61 keyboard_report_prev = keyboard_report;
62 keyboard_report = tmp;
65 void host_clear_keyboard_report(void)
67 keyboard_report->mods = 0;
68 for (int8_t i = 0; i < REPORT_KEYS; i++) {
69 keyboard_report->keys[i] = 0;
73 uint8_t host_has_anykey(void)
76 for (int i = 0; i < REPORT_KEYS; i++) {
77 if (keyboard_report->keys[i])
83 uint8_t *host_get_keys(void)
85 return keyboard_report->keys;
88 uint8_t host_get_mods(void)
90 return keyboard_report->mods;
94 void host_send_keyboard_report(void)
96 usb_keyboard_send_report(keyboard_report);
99 void host_mouse_send(report_mouse_t *report)
101 usb_mouse_send(report->x, report->y, report->v, report->h, report->buttons);
105 static inline void add_key_byte(uint8_t code)
107 // TODO: fix ugly code
110 for (; i < REPORT_KEYS; i++) {
111 if (keyboard_report_prev->keys[i] == code) {
112 keyboard_report->keys[i] = code;
116 keyboard_report_prev->keys[i] == 0 &&
117 keyboard_report->keys[i] == 0) {
121 if (i == REPORT_KEYS) {
123 keyboard_report->keys[empty] = code;
128 static inline void add_key_bit(uint8_t code)
130 if ((code>>3) < REPORT_KEYS) {
131 keyboard_report->keys[code>>3] |= 1<<(code&7);
133 debug("add_key_bit: can't add: "); phex(code); debug("\n");