- uint8_t i, intr_state, timeout;
-
- if (!usb_configured()) return -1;
- intr_state = SREG;
- cli();
- UENUM = KEYBOARD_ENDPOINT;
- timeout = UDFNUML + 50;
- while (1) {
- // are we ready to transmit?
- if (UEINTX & (1<<RWAL)) break;
- SREG = intr_state;
- // has the USB gone offline?
- if (!usb_configured()) return -1;
- // have we waited too long?
- if (UDFNUML == timeout) return -1;
- // get ready to try checking again
- intr_state = SREG;
- cli();
- UENUM = KEYBOARD_ENDPOINT;
- }
- UEDATX = report->mods;
- UEDATX = 0;
- for (i = 0; i < 6; i++) {
- UEDATX = report->keys[i];
- }
- UEINTX = 0x3A;
- SREG = intr_state;
-
- 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<<RWAL)) break;
- SREG = intr_state;
- // has the USB gone offline?
- if (!usb_configured()) return -1;
- // have we waited too long?
- if (UDFNUML == timeout) return -1;
- // get ready to try checking again
- intr_state = SREG;
- cli();
- UENUM = KEYBOARD_ENDPOINT2;
- }
- UEDATX = 0;
- UEDATX = 0;
- for (i = 6; i < 12; i++) {
- UEDATX = report->keys[i];
- }
- UEINTX = 0x3A;
- SREG = intr_state;
-
- usb_keyboard_idle_count = 0;
- report->is_sent =true;
- usb_keyboard_print_report(report);
- return 0;
+ int8_t result = 0;
+
+#ifdef USB_NKRO_ENABLE
+ if (usb_keyboard_nkro)
+ result = _send_report(report, KBD2_ENDPOINT, 0, KBD2_REPORT_KEYS);
+ else
+#endif
+ {
+ if (usb_keyboard_protocol)
+ result = _send_report(report, KBD_ENDPOINT, 0, KBD_REPORT_KEYS);
+ else
+ result = _send_report(report, KBD_ENDPOINT, 0, 6);
+ }
+
+ if (result) return result;
+ usb_keyboard_idle_count = 0;
+ report->is_sent =true;
+ usb_keyboard_print_report(report);
+ return 0;