summaryrefslogtreecommitdiff
path: root/usb_keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'usb_keyboard.c')
-rw-r--r--usb_keyboard.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/usb_keyboard.c b/usb_keyboard.c
index 8212c60..e6638ec 100644
--- a/usb_keyboard.c
+++ b/usb_keyboard.c
@@ -21,7 +21,7 @@ static uint8_t kbd_ifc = 0;
void usb_keyboard_init() {
if (kbd_ifc)
return;
- usb_common_init();
+ usb_common_earlyinit();
kbd_ifc = usb_add_interface(cfgnum_std, TUD_HID_DESC_LEN, (uint8_t[]){
/* USB-HID input-only descriptor for inclusion in the config descriptor; consisting of 3 parts:
@@ -42,38 +42,41 @@ void usb_keyboard_init() {
static uint8_t ascii2keycode[128][2] = { HID_ASCII_TO_KEYCODE };
-void usb_keyboard_cr(void *_stack) {
- usb_keyboard_stack_t *stack = _stack;
-
+COROUTINE usb_keyboard_cr(void *_chan) {
+ usb_keyboard_chan_t *chan = _chan;
cr_begin();
+ uint8_t report_id = 0;
+ uint8_t modifier = 0;
+ uint8_t keycodes[6] = {0};
for (;;) {
while (!tud_hid_n_ready(kbd_ifc))
cr_yield();
- if (cr_chan_have_req(stack->chan)) {
- cr_chan_recv_req(stack->chan, &stack->rune);
+ if (cr_chan_have_req(chan)) {
+ uint32_t rune;
+ cr_chan_recv_req(chan, &rune);
- stack->modifier = ascii2keycode[stack->rune][0] ? KEYBOARD_MODIFIER_LEFTSHIFT : 0;
- stack->keycodes[0] = ascii2keycode[stack->rune][1];
- tud_hid_n_keyboard_report(kbd_ifc, stack->report_id, stack->modifier, stack->keycodes);
+ modifier = ascii2keycode[rune][0] ? KEYBOARD_MODIFIER_LEFTSHIFT : 0;
+ keycodes[0] = ascii2keycode[rune][1];
+ tud_hid_n_keyboard_report(kbd_ifc, report_id, modifier, keycodes);
while (!tud_hid_n_ready(kbd_ifc))
cr_yield();
- stack->modifier = 0;
- stack->keycodes[0] = 0;
- tud_hid_n_keyboard_report(kbd_ifc, stack->report_id, stack->modifier, stack->keycodes);
+ modifier = 0;
+ keycodes[0] = 0;
+ tud_hid_n_keyboard_report(kbd_ifc, report_id, modifier, keycodes);
- cr_chan_send_resp(stack->chan, 1);
+ cr_chan_send_resp(chan, 1);
} else {
- stack->modifier = 0;
- stack->keycodes[0] = 0;
- tud_hid_n_keyboard_report(kbd_ifc, stack->report_id, stack->modifier, stack->keycodes);
+ modifier = 0;
+ keycodes[0] = 0;
+ tud_hid_n_keyboard_report(kbd_ifc, report_id, modifier, keycodes);
}
}
- cr_end()
+ cr_end();
}
/**