diff options
Diffstat (limited to 'tmk_core/protocol/vusb')
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 92 | 
1 files changed, 54 insertions, 38 deletions
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index d74f375f66..3502d9e644 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -48,16 +48,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #    include "os_detection.h"  #endif -#define NEXT_INTERFACE __COUNTER__ -  /*   * Interface indexes   */  enum usb_interfaces {  #ifndef KEYBOARD_SHARED_EP -    KEYBOARD_INTERFACE = NEXT_INTERFACE, +    KEYBOARD_INTERFACE,  #else -    SHARED_INTERFACE = NEXT_INTERFACE, +    SHARED_INTERFACE,  #    define KEYBOARD_INTERFACE SHARED_INTERFACE  #endif @@ -65,32 +63,31 @@ enum usb_interfaces {  // interface number, to support Linux/OSX platforms and chrome.hid  // If Raw HID is enabled, let it be always 1.  #ifdef RAW_ENABLE -    RAW_INTERFACE = NEXT_INTERFACE, +    RAW_INTERFACE,  #endif  #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP) -    SHARED_INTERFACE = NEXT_INTERFACE, +    SHARED_INTERFACE,  #endif  #ifdef CONSOLE_ENABLE -    CONSOLE_INTERFACE = NEXT_INTERFACE, +    CONSOLE_INTERFACE,  #endif -    TOTAL_INTERFACES = NEXT_INTERFACE +    TOTAL_INTERFACES  };  #define MAX_INTERFACES 3 -#if (NEXT_INTERFACE - 1) > MAX_INTERFACES -#    error There are not enough available interfaces to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Raw HID, Console -#endif +_Static_assert(TOTAL_INTERFACES <= MAX_INTERFACES, "There are not enough available interfaces to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Raw HID, Console.");  #if (defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)) && CONSOLE_ENABLE  #    error Mouse/Extra Keys share an endpoint with Console. Please disable one of the two.  #endif  static uint8_t keyboard_led_state = 0; -static uint8_t vusb_idle_rate     = 0; +uint8_t        keyboard_idle      = 0; +uint8_t        keyboard_protocol  = 1;  /* Keyboard report send buffer */  #define KBUF_SIZE 16 @@ -231,10 +228,11 @@ void console_task(void) {   *------------------------------------------------------------------*/  static uint8_t keyboard_leds(void);  static void    send_keyboard(report_keyboard_t *report); +static void    send_nkro(report_nkro_t *report);  static void    send_mouse(report_mouse_t *report);  static void    send_extra(report_extra_t *report); -static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_extra}; +static host_driver_t driver = {keyboard_leds, send_keyboard, send_nkro, send_mouse, send_extra};  host_driver_t *vusb_driver(void) {      return &driver; @@ -259,6 +257,10 @@ static void send_keyboard(report_keyboard_t *report) {      keyboard_report_sent = *report;  } +static void send_nkro(report_nkro_t *report) { +    // TODO: Implement NKRO +} +  #ifndef KEYBOARD_SHARED_EP  #    define usbInterruptIsReadyShared usbInterruptIsReady3  #    define usbSetInterruptShared usbSetInterrupt3 @@ -319,30 +321,44 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {      usbRequest_t *rq = (void *)data;      if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */ -        if (rq->bRequest == USBRQ_HID_GET_REPORT) { -            dprint("GET_REPORT:"); -            if (rq->wIndex.word == KEYBOARD_INTERFACE) { -                usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent; -                return sizeof(keyboard_report_sent); -            } -        } else if (rq->bRequest == USBRQ_HID_GET_IDLE) { -            dprint("GET_IDLE:"); -            usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate; -            return 1; -        } else if (rq->bRequest == USBRQ_HID_SET_IDLE) { -            vusb_idle_rate = rq->wValue.bytes[1]; -            dprintf("SET_IDLE: %02X", vusb_idle_rate); -        } else if (rq->bRequest == USBRQ_HID_SET_REPORT) { -            dprint("SET_REPORT:"); -            // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) -            if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) { -                dprint("SET_LED:"); -                last_req.kind = SET_LED; -                last_req.len  = rq->wLength.word; -            } -            return USB_NO_MSG; // to get data in usbFunctionWrite -        } else { -            dprint("UNKNOWN:"); +        switch (rq->bRequest) { +            case USBRQ_HID_GET_REPORT: +                dprint("GET_REPORT:"); +                if (rq->wIndex.word == KEYBOARD_INTERFACE) { +                    usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent; +                    return sizeof(keyboard_report_sent); +                } +                break; +            case USBRQ_HID_GET_IDLE: +                dprint("GET_IDLE:"); +                usbMsgPtr = (usbMsgPtr_t)&keyboard_idle; +                return 1; +            case USBRQ_HID_GET_PROTOCOL: +                dprint("GET_PROTOCOL:"); +                usbMsgPtr = (usbMsgPtr_t)&keyboard_protocol; +                return 1; +            case USBRQ_HID_SET_REPORT: +                dprint("SET_REPORT:"); +                // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) +                if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) { +                    dprint("SET_LED:"); +                    last_req.kind = SET_LED; +                    last_req.len  = rq->wLength.word; +                } +                return USB_NO_MSG; // to get data in usbFunctionWrite +            case USBRQ_HID_SET_IDLE: +                keyboard_idle = (rq->wValue.word & 0xFF00) >> 8; +                dprintf("SET_IDLE: %02X", keyboard_idle); +                break; +            case USBRQ_HID_SET_PROTOCOL: +                if (rq->wIndex.word == KEYBOARD_INTERFACE) { +                    keyboard_protocol = rq->wValue.word & 0xFF; +                    dprintf("SET_PROTOCOL: %02X", keyboard_protocol); +                } +                break; +            default: +                dprint("UNKNOWN:"); +                break;          }      } else {          dprint("VENDOR:"); @@ -1024,7 +1040,7 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {  #endif              break;          case USBDESCR_HID: -            switch (rq->wValue.bytes[0]) { +            switch (rq->wIndex.word) {  #ifndef KEYBOARD_SHARED_EP                  case KEYBOARD_INTERFACE:                      usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.keyboardHID;  | 
