X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=usb_keyboard.c;h=7f32a9083e47867cce3c65a1cd84cd3d78905820;hb=d6da5546879f9979d043a0b223597af7e8dedbf8;hp=d289af8e0aebc6db0b9667d3f88f7b05372586e3;hpb=a31b31e717a2fa67642be33b321cde4b9b3b496a;p=max%2Ftmk_keyboard.git diff --git a/usb_keyboard.c b/usb_keyboard.c index d289af8e..7f32a908 100644 --- a/usb_keyboard.c +++ b/usb_keyboard.c @@ -7,10 +7,10 @@ // keyboard report. -static usb_keyboard_report_t _report0 = { {0,0,0,0,0,0}, 0 }; -static usb_keyboard_report_t _report1 = { {0,0,0,0,0,0}, 0 }; +static usb_keyboard_report_t _report0 = { {0}, 0 }; +static usb_keyboard_report_t _report1 = { {0}, 0 }; usb_keyboard_report_t *usb_keyboard_report = &_report0; -usb_keyboard_report_t *usb_keyboard_report_back = &_report1; +usb_keyboard_report_t *usb_keyboard_report_prev = &_report1; // protocol setting from the host. We use exactly the same report // either way, so this variable only stores the setting since we @@ -58,22 +58,47 @@ int8_t usb_keyboard_send_report(usb_keyboard_report_t *report) } UEDATX = report->mods; UEDATX = 0; - for (i=0; i<6; i++) { + for (i = 0; i < 6; i++) { UEDATX = report->keys[i]; } UEINTX = 0x3A; - usb_keyboard_idle_count = 0; SREG = intr_state; - report->is_sent =true; + if (!usb_configured()) return -1; + intr_state = SREG; + cli(); + UENUM = KEYBOARD_ENDPOINT2; + timeout = UDFNUML + 50; + while (1) { + // are we ready to transmit? + if (UEINTX & (1<keys[i]; + } + UEINTX = 0x3A; + SREG = intr_state; + usb_keyboard_idle_count = 0; + report->is_sent =true; usb_keyboard_print_report(report); return 0; } void usb_keyboard_swap_report(void) { - usb_keyboard_report_t *tmp = usb_keyboard_report_back; - usb_keyboard_report_back = usb_keyboard_report; + usb_keyboard_report_t *tmp = usb_keyboard_report_prev; + usb_keyboard_report_prev = usb_keyboard_report; usb_keyboard_report = tmp; } @@ -84,7 +109,7 @@ void usb_keyboard_clear_report(void) { } void usb_keyboard_clear_keys(void) { - for (int i = 0; i < 6; i++) usb_keyboard_report->keys[i] = 0; + for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) usb_keyboard_report->keys[i] = 0; } void usb_keyboard_clear_mods(void) @@ -103,7 +128,7 @@ void usb_keyboard_add_code(uint8_t code) void usb_keyboard_add_key(uint8_t code) { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) { if (!usb_keyboard_report->keys[i]) { usb_keyboard_report->keys[i] = code; return; @@ -111,9 +136,9 @@ void usb_keyboard_add_key(uint8_t code) } } -void usb_keyboard_set_keys(uint8_t keys[6]) +void usb_keyboard_set_keys(uint8_t *keys) { - for (int i = 0; i < 6; i++) + for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) usb_keyboard_report->keys[i] = keys[i]; } @@ -138,7 +163,7 @@ void usb_keyboard_del_code(uint8_t code) void usb_keyboard_del_key(uint8_t code) { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) { if (usb_keyboard_report->keys[i] == code) { usb_keyboard_report->keys[i] = KB_NO; return; @@ -159,7 +184,7 @@ bool usb_keyboard_is_sent(void) bool usb_keyboard_has_key(void) { uint8_t keys = 0; - for (int i = 0; i < 6; i++) keys |= usb_keyboard_report->keys[i]; + for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) keys |= usb_keyboard_report->keys[i]; return keys ? true : false; } @@ -172,6 +197,6 @@ void usb_keyboard_print_report(usb_keyboard_report_t *report) { if (!debug_keyboard) return; print("keys: "); - for (int i = 0; i < 6; i++) { phex(report->keys[i]); print(" "); } + for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) { phex(report->keys[i]); print(" "); } print(" mods: "); phex(report->mods); print("\n"); }