123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include <avr/interrupt.h>
- #include <avr/pgmspace.h>
- #include "keycode.h"
- #include "usb_keyboard.h"
- #include "print.h"
- #include "debug.h"
- #include "util.h"
- #include "host.h"
- uint8_t keyboard_protocol=1;
- uint8_t keyboard_idle=125;
- uint8_t usb_keyboard_idle_count=0;
- volatile uint8_t usb_keyboard_leds=0;
- static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, uint8_t keys_start, uint8_t keys_end);
- int8_t usb_keyboard_send_report(report_keyboard_t *report)
- {
- int8_t result = 0;
- #ifdef NKRO_ENABLE
- if (keyboard_nkro)
- result = send_report(report, KBD2_ENDPOINT, 0, KBD2_SIZE);
- else
- #endif
- {
- result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE);
- }
- if (result) return result;
- usb_keyboard_idle_count = 0;
- usb_keyboard_print_report(report);
- return 0;
- }
- void usb_keyboard_print_report(report_keyboard_t *report)
- {
- if (!debug_keyboard) return;
- print("keys: ");
- for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) { phex(report->keys[i]); print(" "); }
- print(" mods: "); phex(report->mods); print("\n");
- }
- static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, uint8_t keys_start, uint8_t keys_end)
- {
- uint8_t intr_state, timeout;
- if (!usb_configured()) return -1;
- intr_state = SREG;
- cli();
- UENUM = endpoint;
- timeout = UDFNUML + 50;
- while (1) {
-
- if (UEINTX & (1<<RWAL)) break;
- SREG = intr_state;
-
- if (!usb_configured()) return -1;
-
- if (UDFNUML == timeout) return -1;
-
- intr_state = SREG;
- cli();
- UENUM = endpoint;
- }
- for (uint8_t i = keys_start; i < keys_end; i++) {
- UEDATX = report->raw[i];
- }
- UEINTX = 0x3A;
- SREG = intr_state;
- return 0;
- }
|