| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431 |
- /*
- Copyright 2011 Jun Wako <wakojun@gmail.com>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <stdint.h>
- #include <avr/wdt.h>
- #include <usbdrv/usbdrv.h>
- #include "compiler_support.h"
- #include "usbconfig.h"
- #include "host.h"
- #include "report.h"
- #include "host_driver.h"
- #include "vusb.h"
- #include "print.h"
- #include "debug.h"
- #include "wait.h"
- #include "usb_descriptor_common.h"
- #include "usb_device_state.h"
- #ifdef RAW_ENABLE
- # include "raw_hid.h"
- #endif
- #ifdef JOYSTICK_ENABLE
- # include "joystick.h"
- #endif
- #ifdef XAP_ENABLE
- # include "xap.h"
- # include <string.h>
- #endif
- #if defined(CONSOLE_ENABLE)
- # define RBUF_SIZE 128
- # include "ring_buffer.h"
- #endif
- #ifdef OS_DETECTION_ENABLE
- # include "os_detection.h"
- #endif
- /*
- * Interface indexes
- */
- enum usb_interfaces {
- #ifndef KEYBOARD_SHARED_EP
- KEYBOARD_INTERFACE,
- #else
- SHARED_INTERFACE,
- # define KEYBOARD_INTERFACE SHARED_INTERFACE
- #endif
- // It is important that the Raw HID interface is at a constant
- // 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,
- #endif
- #ifdef PLOVER_HID_ENABLE
- PLOVER_HID_INTERFACE,
- #endif
- #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
- SHARED_INTERFACE,
- #endif
- #ifdef CONSOLE_ENABLE
- CONSOLE_INTERFACE,
- #endif
- #ifdef XAP_ENABLE
- XAP_INTERFACE,
- #endif
- TOTAL_INTERFACES
- };
- #define MAX_INTERFACES 3
- 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
- #if defined(PLOVER_HID_ENABLE) && defined(RAW_ENABLE)
- # error Plover HID shares an endpoint with Raw HID. Please disable one of the two.
- #endif
- static report_keyboard_t keyboard_report_sent;
- static void send_report_fragment(uint8_t endpoint, void *data, size_t size) {
- for (uint8_t retries = 5; retries > 0; retries--) {
- switch (endpoint) {
- case 1:
- if (usbInterruptIsReady()) {
- usbSetInterrupt(data, size);
- return;
- }
- break;
- case USB_CFG_EP3_NUMBER:
- if (usbInterruptIsReady3()) {
- usbSetInterrupt3(data, size);
- return;
- }
- break;
- case USB_CFG_EP4_NUMBER:
- if (usbInterruptIsReady4()) {
- usbSetInterrupt4(data, size);
- return;
- }
- break;
- default:
- return;
- }
- usbPoll();
- wait_ms(5);
- }
- }
- static void send_report(uint8_t endpoint, void *report, size_t size) {
- uint8_t *temp = (uint8_t *)report;
- // Send as many full packets as possible
- for (uint8_t i = 0; i < size / 8; i++) {
- send_report_fragment(endpoint, temp, 8);
- temp += 8;
- }
- // Send any data left over
- uint8_t remainder = size % 8;
- if (remainder) {
- send_report_fragment(endpoint, temp, remainder);
- }
- }
- /*------------------------------------------------------------------*
- * RAW HID
- *------------------------------------------------------------------*/
- #ifdef RAW_ENABLE
- # define RAW_BUFFER_SIZE 32
- # define RAW_EPSIZE 8
- static uint8_t raw_output_buffer[RAW_BUFFER_SIZE];
- static uint8_t raw_output_received_bytes = 0;
- static void send_raw_hid(uint8_t *data, uint8_t length) {
- if (length != RAW_BUFFER_SIZE) {
- return;
- }
- send_report(4, data, RAW_BUFFER_SIZE);
- }
- void raw_hid_task(void) {
- usbPoll();
- if (!usbConfiguration || !usbInterruptIsReady4()) {
- return;
- }
- if (raw_output_received_bytes == RAW_BUFFER_SIZE) {
- raw_hid_receive(raw_output_buffer, RAW_BUFFER_SIZE);
- raw_output_received_bytes = 0;
- }
- }
- #endif
- /*------------------------------------------------------------------*
- * XAP
- *------------------------------------------------------------------*/
- #ifdef XAP_ENABLE
- # define XAP_BUFFER_SIZE 64
- # define XAP_EPSIZE 8
- static uint8_t xap_output_buffer[XAP_BUFFER_SIZE];
- static uint8_t xap_output_received_bytes = 0;
- extern void xap_receive(xap_token_t token, const uint8_t *data, size_t length);
- void xap_send_base(uint8_t *data, uint8_t length) {
- if (length != XAP_BUFFER_SIZE) {
- return;
- }
- send_report(4, data, XAP_BUFFER_SIZE);
- }
- void xap_send(xap_token_t token, xap_response_flags_t response_flags, const void *data, size_t length) {
- uint8_t rdata[XAP_BUFFER_SIZE] = {0};
- xap_response_header_t *header = (xap_response_header_t *)&rdata[0];
- header->token = token;
- if (length > (XAP_BUFFER_SIZE - sizeof(xap_response_header_t))) response_flags &= ~(XAP_RESPONSE_FLAG_SUCCESS);
- header->flags = response_flags;
- if (response_flags & (XAP_RESPONSE_FLAG_SUCCESS)) {
- header->length = (uint8_t)length;
- if (data != NULL) {
- memcpy(&rdata[sizeof(xap_response_header_t)], data, length);
- }
- }
- xap_send_base(rdata, sizeof(rdata));
- }
- void xap_broadcast(uint8_t type, const void *data, size_t length) {
- uint8_t rdata[XAP_BUFFER_SIZE] = {0};
- xap_broadcast_header_t *header = (xap_broadcast_header_t *)&rdata[0];
- header->token = XAP_BROADCAST_TOKEN;
- header->type = type;
- if (length > (XAP_BUFFER_SIZE - sizeof(xap_broadcast_header_t))) return;
- header->length = (uint8_t)length;
- if (data != NULL) {
- memcpy(&rdata[sizeof(xap_broadcast_header_t)], data, length);
- }
- xap_send_base(rdata, sizeof(rdata));
- }
- void xap_receive_base(const void *data) {
- const uint8_t *u8data = (const uint8_t *)data;
- xap_request_header_t *header = (xap_request_header_t *)&u8data[0];
- if (header->length <= (XAP_BUFFER_SIZE - sizeof(xap_request_header_t))) {
- xap_receive(header->token, &u8data[sizeof(xap_request_header_t)], header->length);
- }
- }
- void xap_task(void) {
- usbPoll();
- if (!usbConfiguration || !usbInterruptIsReady4()) {
- return;
- }
- if (xap_output_received_bytes == XAP_BUFFER_SIZE) {
- xap_receive_base(xap_output_buffer);
- xap_output_received_bytes = 0;
- }
- }
- #endif
- /*------------------------------------------------------------------*
- * Console
- *------------------------------------------------------------------*/
- #ifdef CONSOLE_ENABLE
- # define CONSOLE_BUFFER_SIZE 32
- # define CONSOLE_EPSIZE 8
- int8_t sendchar(uint8_t c) {
- rbuf_enqueue(c);
- return 0;
- }
- void console_task(void) {
- usbPoll();
- if (!usbConfiguration || !usbInterruptIsReady3()) {
- return;
- }
- if (!rbuf_has_data()) {
- return;
- }
- // Send in chunks of 8 padded to 32
- char send_buf[CONSOLE_BUFFER_SIZE] = {0};
- uint8_t send_buf_count = 0;
- while (rbuf_has_data() && send_buf_count < CONSOLE_EPSIZE) {
- send_buf[send_buf_count++] = rbuf_dequeue();
- }
- send_report(3, send_buf, CONSOLE_BUFFER_SIZE);
- }
- #endif
- /*------------------------------------------------------------------*
- * Host driver
- *------------------------------------------------------------------*/
- 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);
- #ifdef RAW_ENABLE
- static void send_raw_hid(uint8_t *data, uint8_t length);
- #endif
- static host_driver_t driver = {
- .keyboard_leds = usb_device_state_get_leds,
- .send_keyboard = send_keyboard,
- .send_nkro = send_nkro,
- .send_mouse = send_mouse,
- .send_extra = send_extra,
- #ifdef RAW_ENABLE
- .send_raw_hid = send_raw_hid,
- #endif
- };
- host_driver_t *vusb_driver(void) {
- return &driver;
- }
- static void send_keyboard(report_keyboard_t *report) {
- if (usb_device_state_get_protocol() == USB_PROTOCOL_BOOT) {
- send_report(1, &report->mods, 8);
- } else {
- send_report(1, report, sizeof(report_keyboard_t));
- }
- keyboard_report_sent = *report;
- }
- #ifndef KEYBOARD_SHARED_EP
- # define MOUSE_IN_EPNUM 3
- # define SHARED_IN_EPNUM 3
- #else
- # define MOUSE_IN_EPNUM 1
- # define SHARED_IN_EPNUM 1
- #endif
- static void send_nkro(report_nkro_t *report) {
- #ifdef NKRO_ENABLE
- send_report(3, report, sizeof(report_nkro_t));
- #endif
- }
- static void send_mouse(report_mouse_t *report) {
- #ifdef MOUSE_ENABLE
- send_report(MOUSE_IN_EPNUM, report, sizeof(report_mouse_t));
- #endif
- }
- static void send_extra(report_extra_t *report) {
- #ifdef EXTRAKEY_ENABLE
- send_report(SHARED_IN_EPNUM, report, sizeof(report_extra_t));
- #endif
- }
- void send_joystick(report_joystick_t *report) {
- #ifdef JOYSTICK_ENABLE
- send_report(SHARED_IN_EPNUM, report, sizeof(report_joystick_t));
- #endif
- }
- void send_digitizer(report_digitizer_t *report) {
- #ifdef DIGITIZER_ENABLE
- send_report(SHARED_IN_EPNUM, report, sizeof(report_digitizer_t));
- #endif
- }
- void send_programmable_button(report_programmable_button_t *report) {
- #ifdef PROGRAMMABLE_BUTTON_ENABLE
- send_report(SHARED_IN_EPNUM, report, sizeof(report_programmable_button_t));
- #endif
- }
- #define PLOVER_HID_EPSIZE 9
- void send_plover_hid(report_plover_hid_t *report) {
- #ifdef PLOVER_HID_ENABLE
- send_report(4, report, sizeof(report_plover_hid_t));
- #endif
- }
- /*------------------------------------------------------------------*
- * Request from host *
- *------------------------------------------------------------------*/
- static struct {
- uint16_t len;
- enum { NONE, SET_LED } kind;
- } last_req;
- usbMsgLen_t usbFunctionSetup(uchar data[8]) {
- usbRequest_t *rq = (void *)data;
- if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
- 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:");
- static uint8_t keyboard_idle;
- keyboard_idle = usb_device_state_get_idle_rate();
- usbMsgPtr = (usbMsgPtr_t)&keyboard_idle;
- return 1;
- case USBRQ_HID_GET_PROTOCOL:
- dprint("GET_PROTOCOL:");
- static uint8_t keyboard_protocol;
- keyboard_protocol = usb_device_state_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:
- usb_device_state_set_idle_rate(rq->wValue.word >> 8);
- dprintf("SET_IDLE: %02X", usb_device_state_get_idle_rate());
- break;
- case USBRQ_HID_SET_PROTOCOL:
- if (rq->wIndex.word == KEYBOARD_INTERFACE) {
- usb_device_state_set_protocol(rq->wValue.word & 0xFF);
- dprintf("SET_PROTOCOL: %02X", usb_device_state_get_protocol());
- }
- break;
- default:
- dprint("UNKNOWN:");
- break;
- }
- } else {
- dprint("VENDOR:");
- /* no vendor specific requests implemented */
- }
- dprint("\n");
- return 0; /* default for not implemented requests: return no data back to host */
- }
- uchar usbFunctionWrite(uchar *data, uchar len) {
- if (last_req.len == 0) {
- return -1;
- }
- switch (last_req.kind) {
- case SET_LED:
- usb_device_state_set_leds(data[0]);
- dprintf("SET_LED: %02X\n", usb_device_state_get_leds());
- last_req.len = 0;
- return 1;
- break;
- case NONE:
- default:
- return -1;
- break;
- }
- return 1;
- }
- void usbFunctionWriteOut(uchar *data, uchar len) {
- #ifdef RAW_ENABLE
- // Data from host must be divided every 8bytes
- if (len != 8) {
- dprint("RAW: invalid length\n");
- raw_output_received_bytes = 0;
- return;
- }
- if (raw_output_received_bytes + len > RAW_BUFFER_SIZE) {
- dprint("RAW: buffer full\n");
- raw_output_received_bytes = 0;
- } else {
- for (uint8_t i = 0; i < 8; i++) {
- raw_output_buffer[raw_output_received_bytes + i] = data[i];
- }
- raw_output_received_bytes += len;
- }
- #endif
- #ifdef XAP_ENABLE
- // Data from host must be divided every 8bytes
- if (len != 8) {
- dprint("XAP: invalid length\n");
- xap_output_received_bytes = 0;
- return;
- }
- if (xap_output_received_bytes + len > XAP_BUFFER_SIZE) {
- dprint("XAP: buffer full\n");
- xap_output_received_bytes = 0;
- } else {
- for (uint8_t i = 0; i < 8; i++) {
- xap_output_buffer[xap_output_received_bytes + i] = data[i];
- }
- xap_output_received_bytes += len;
- }
- #endif
- }
- /*------------------------------------------------------------------*
- * Descriptors *
- *------------------------------------------------------------------*/
- #ifdef KEYBOARD_SHARED_EP
- const PROGMEM uchar shared_hid_report[] = {
- # define SHARED_REPORT_STARTED
- #else
- const PROGMEM uchar keyboard_hid_report[] = {
- #endif
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x06, // Usage (Keyboard)
- 0xA1, 0x01, // Collection (Application)
- #ifdef KEYBOARD_SHARED_EP
- 0x85, REPORT_ID_KEYBOARD, // Report ID
- #endif
- // Modifiers (8 bits)
- 0x05, 0x07, // Usage Page (Keyboard/Keypad)
- 0x19, 0xE0, // Usage Minimum (Keyboard Left Control)
- 0x29, 0xE7, // Usage Maximum (Keyboard Right GUI)
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x95, 0x08, // Report Count (8)
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- // Reserved (1 byte)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x03, // Input (Constant)
- // Keycodes (6 bytes)
- 0x05, 0x07, // Usage Page (Keyboard/Keypad)
- 0x19, 0x00, // Usage Minimum (0)
- 0x29, 0xFF, // Usage Maximum (255)
- 0x15, 0x00, // Logical Minimum (0)
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
- 0x95, 0x06, // Report Count (6)
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x00, // Input (Data, Array, Absolute)
- // Status LEDs (5 bits)
- 0x05, 0x08, // Usage Page (LED)
- 0x19, 0x01, // Usage Minimum (Num Lock)
- 0x29, 0x05, // Usage Maximum (Kana)
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x95, 0x05, // Report Count (5)
- 0x75, 0x01, // Report Size (1)
- 0x91, 0x02, // Output (Data, Variable, Absolute)
- // LED padding (3 bits)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x03, // Report Size (3)
- 0x91, 0x03, // Output (Constant)
- 0xC0, // End Collection
- #ifndef KEYBOARD_SHARED_EP
- };
- #endif
- #if defined(SHARED_EP_ENABLE) && !defined(SHARED_REPORT_STARTED)
- const PROGMEM uchar shared_hid_report[] = {
- # define SHARED_REPORT_STARTED
- #endif
- #ifdef NKRO_ENABLE
- // NKRO report descriptor
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x06, // Usage (Keyboard)
- 0xA1, 0x01, // Collection (Application)
- 0x85, REPORT_ID_NKRO, // Report ID
- // Modifiers (8 bits)
- 0x05, 0x07, // Usage Page (Keyboard/Keypad)
- 0x19, 0xE0, // Usage Minimum (Keyboard Left Control)
- 0x29, 0xE7, // Usage Maximum (Keyboard Right GUI)
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x95, 0x08, // Report Count (8)
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- // Keycodes
- 0x05, 0x07, // Usage Page (Keyboard/Keypad)
- 0x19, 0x00, // Usage Minimum (0)
- 0x29, NKRO_REPORT_BITS * 8 - 1, // Usage Maximum
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x95, NKRO_REPORT_BITS * 8, // Report Count
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- // Status LEDs (5 bits)
- 0x05, 0x08, // Usage Page (LED)
- 0x19, 0x01, // Usage Minimum (Num Lock)
- 0x29, 0x05, // Usage Maximum (Kana)
- 0x95, 0x05, // Report Count (5)
- 0x75, 0x01, // Report Size (1)
- 0x91, 0x02, // Output (Data, Variable, Absolute)
- // LED padding (3 bits)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x03, // Report Size (3)
- 0x91, 0x03, // Output (Constant)
- 0xC0, // End Collection
- #endif
- #ifdef MOUSE_ENABLE
- // Mouse report descriptor
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x02, // Usage (Mouse)
- 0xA1, 0x01, // Collection (Application)
- 0x85, REPORT_ID_MOUSE, // Report ID
- 0x09, 0x01, // Usage (Pointer)
- 0xA1, 0x00, // Collection (Physical)
- // Buttons (8 bits)
- 0x05, 0x09, // Usage Page (Button)
- 0x19, 0x01, // Usage Minimum (Button 1)
- 0x29, 0x08, // Usage Maximum (Button 8)
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x95, 0x08, // Report Count (8)
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- # ifdef MOUSE_EXTENDED_REPORT
- // Boot protocol XY ignored in Report protocol
- 0x95, 0x02, // Report Count (2)
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x03, // Input (Constant)
- # endif
- // X/Y position (2 or 4 bytes)
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x30, // Usage (X)
- 0x09, 0x31, // Usage (Y)
- # ifndef MOUSE_EXTENDED_REPORT
- 0x15, MOUSE_REPORT_XY_MIN, // Logical Minimum (-127)
- 0x25, MOUSE_REPORT_XY_MAX, // Logical Maximum (127)
- 0x95, 0x02, // Report Count (2)
- 0x75, 0x08, // Report Size (8)
- # else
- 0x16, 0x01, HID_VALUE_16(MOUSE_REPORT_XY_MIN), // Logical Minimum (-32767)
- 0x26, 0xFF, HID_VALUE_16(MOUSE_REPORT_XY_MAX), // Logical Maximum (32767)
- 0x95, 0x02, // Report Count (2)
- 0x75, 0x10, // Report Size (16)
- # endif
- 0x81, 0x06, // Input (Data, Variable, Relative)
- # ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
- // Feature report and padding (1 byte)
- 0xA1, 0x02, // Collection (Logical)
- 0x09, 0x48, // Usage (Resolution Multiplier)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x02, // Report Size (2)
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x35, 0x01, // Physical Minimum (1)
- 0x45, POINTING_DEVICE_HIRES_SCROLL_MULTIPLIER, // Physical Maximum (POINTING_DEVICE_HIRES_SCROLL_MULTIPLIER)
- 0x55, POINTING_DEVICE_HIRES_SCROLL_EXPONENT, // Unit Exponent (POINTING_DEVICE_HIRES_SCROLL_EXPONENT)
- 0xB1, 0x02, // Feature (Data, Variable, Absolute)
- 0x35, 0x00, // Physical Minimum (0)
- 0x45, 0x00, // Physical Maximum (0)
- 0x75, 0x06, // Report Size (6)
- 0xB1, 0x03, // Feature (Constant)
- # endif
- // Vertical wheel (1 or 2 bytes)
- 0x09, 0x38, // Usage (Wheel)
- # ifndef WHEEL_EXTENDED_REPORT
- 0x15, MOUSE_REPORT_HV_MIN, // Logical Minimum (-127)
- 0x25, MOUSE_REPORT_HV_MAX, // Logical Maximum (127)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x08, // Report Size (8)
- # else
- 0x16, 0x01, HID_VALUE_16(MOUSE_REPORT_HV_MIN), // Logical Minimum (-32767)
- 0x26, 0xFF, HID_VALUE_16(MOUSE_REPORT_HV_MAX), // Logical Maximum (32767)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x10, // Report Size (16)
- # endif
- 0x81, 0x06, // Input (Data, Variable, Relative)
- // Horizontal wheel (1 or 2 bytes)
- 0x05, 0x0C, // Usage Page (Consumer)
- 0x0A, 0x38, 0x02, // Usage (AC Pan)
- # ifndef WHEEL_EXTENDED_REPORT
- 0x15, MOUSE_REPORT_HV_MIN, // Logical Minimum (-127)
- 0x25, MOUSE_REPORT_HV_MAX, // Logical Maximum (127)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x08, // Report Size (8)
- # else
- 0x16, 0x01, HID_VALUE_16(MOUSE_REPORT_HV_MIN), // Logical Minimum (-32767)
- 0x26, 0xFF, HID_VALUE_16(MOUSE_REPORT_HV_MAX), // Logical Maximum (32767)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x10, // Report Size (16)
- # endif
- 0x81, 0x06, // Input (Data, Variable, Relative)
- # ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
- 0xC0, // End Collection
- # endif
- 0xC0, // End Collection
- 0xC0, // End Collection
- #endif
- #ifdef EXTRAKEY_ENABLE
- // Extrakeys report descriptor
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x80, // Usage (System Control)
- 0xA1, 0x01, // Collection (Application)
- 0x85, REPORT_ID_SYSTEM, // Report ID
- 0x1A, HID_VALUE_16(SYSTEM_CONTROL_USAGE_MINIMUM), // Usage Minimum
- 0x2A, HID_VALUE_16(SYSTEM_CONTROL_USAGE_MAXIMUM), // Usage Maximum
- 0x16, HID_VALUE_16(SYSTEM_CONTROL_USAGE_MINIMUM), // Logical Minimum
- 0x26, HID_VALUE_16(SYSTEM_CONTROL_USAGE_MAXIMUM), // Logical Maximum
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x10, // Report Size (16)
- 0x81, 0x00, // Input (Data, Array, Absolute)
- 0xC0, // End Collection
- 0x05, 0x0C, // Usage Page (Consumer)
- 0x09, 0x01, // Usage (Consumer Control)
- 0xA1, 0x01, // Collection (Application)
- 0x85, REPORT_ID_CONSUMER, // Report ID
- 0x19, 0x01, // Usage Minimum (Consumer Control)
- 0x2A, 0xA0, 0x02, // Usage Maximum (AC Desktop Show All Applications)
- 0x15, 0x01, // Logical Minimum
- 0x26, 0xA0, 0x02, // Logical Maximum
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x10, // Report Size (16)
- 0x81, 0x00, // Input (Data, Array, Absolute)
- 0xC0, // End Collection
- #endif
- #ifdef JOYSTICK_ENABLE
- // Joystick report descriptor
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x04, // Usage (Joystick)
- 0xA1, 0x01, // Collection (Application)
- 0x85, REPORT_ID_JOYSTICK, // Report ID
- 0xA1, 0x00, // Collection (Physical)
- # if JOYSTICK_AXIS_COUNT > 0
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x30, // Usage (X)
- # if JOYSTICK_AXIS_COUNT > 1
- 0x09, 0x31, // Usage (Y)
- # endif
- # if JOYSTICK_AXIS_COUNT > 2
- 0x09, 0x32, // Usage (Z)
- # endif
- # if JOYSTICK_AXIS_COUNT > 3
- 0x09, 0x33, // Usage (Rx)
- # endif
- # if JOYSTICK_AXIS_COUNT > 4
- 0x09, 0x34, // Usage (Ry)
- # endif
- # if JOYSTICK_AXIS_COUNT > 5
- 0x09, 0x35, // Usage (Rz)
- # endif
- # if JOYSTICK_AXIS_RESOLUTION == 8
- 0x15, -JOYSTICK_MAX_VALUE, // Logical Minimum
- 0x25, JOYSTICK_MAX_VALUE, // Logical Maximum
- 0x95, JOYSTICK_AXIS_COUNT, // Report Count
- 0x75, 0x08, // Report Size (8)
- # else
- 0x16, HID_VALUE_16(-JOYSTICK_MAX_VALUE), // Logical Minimum
- 0x26, HID_VALUE_16(JOYSTICK_MAX_VALUE), // Logical Maximum
- 0x95, JOYSTICK_AXIS_COUNT, // Report Count
- 0x75, 0x10, // Report Size (16)
- # endif
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- # endif
- # ifdef JOYSTICK_HAS_HAT
- // Hat Switch (4 bits)
- 0x09, 0x39, // Usage (Hat Switch)
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x07, // Logical Maximum (7)
- 0x35, 0x00, // Physical Minimum (0)
- 0x46, 0x3B, 0x01, // Physical Maximum (315)
- 0x65, 0x14, // Unit (Degree, English Rotation)
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x04, // Report Size (4)
- 0x81, 0x42, // Input (Data, Variable, Absolute, Null State)
- // Padding (4 bits)
- 0x95, 0x04, // Report Count (4)
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x01, // Input (Constant)
- # endif
- # if JOYSTICK_BUTTON_COUNT > 0
- 0x05, 0x09, // Usage Page (Button)
- 0x19, 0x01, // Usage Minimum (Button 1)
- 0x29, JOYSTICK_BUTTON_COUNT, // Usage Maximum
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x95, JOYSTICK_BUTTON_COUNT, // Report Count
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- # if (JOYSTICK_BUTTON_COUNT % 8) != 0
- 0x95, 8 - (JOYSTICK_BUTTON_COUNT % 8), // Report Count
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x03, // Input (Constant)
- # endif
- # endif
- 0xC0, // End Collection
- 0xC0, // End Collection
- #endif
- #ifdef DIGITIZER_ENABLE
- // Digitizer report descriptor
- 0x05, 0x0D, // Usage Page (Digitizers)
- 0x09, 0x01, // Usage (Digitizer)
- 0xA1, 0x01, // Collection (Application)
- 0x85, REPORT_ID_DIGITIZER, // Report ID
- 0x09, 0x20, // Usage (Stylus)
- 0xA1, 0x00, // Collection (Physical)
- // In Range, Tip Switch & Barrel Switch (3 bits)
- 0x09, 0x32, // Usage (In Range)
- 0x09, 0x42, // Usage (Tip Switch)
- 0x09, 0x44, // Usage (Barrel Switch)
- 0x15, 0x00, // Logical Minimum
- 0x25, 0x01, // Logical Maximum
- 0x95, 0x03, // Report Count (3)
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- // Padding (5 bits)
- 0x95, 0x05, // Report Count (5)
- 0x81, 0x03, // Input (Constant)
- // X/Y Position (4 bytes)
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x30, // Usage (X)
- 0x09, 0x31, // Usage (Y)
- 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
- 0x95, 0x02, // Report Count (2)
- 0x75, 0x10, // Report Size (16)
- 0x65, 0x13, // Unit (Inch, English Linear)
- 0x55, 0x0E, // Unit Exponent (-2)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- 0xC0, // End Collection
- 0xC0, // End Collection
- #endif
- #ifdef PROGRAMMABLE_BUTTON_ENABLE
- // Programmable buttons report descriptor
- 0x05, 0x0C, // Usage Page (Consumer)
- 0x09, 0x01, // Usage (Consumer Control)
- 0xA1, 0x01, // Collection (Application)
- 0x85, REPORT_ID_PROGRAMMABLE_BUTTON, // Report ID
- 0x09, 0x03, // Usage (Programmable Buttons)
- 0xA1, 0x04, // Collection (Named Array)
- 0x05, 0x09, // Usage Page (Button)
- 0x19, 0x01, // Usage Minimum (Button 1)
- 0x29, 0x20, // Usage Maximum (Button 32)
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x95, 0x20, // Report Count (32)
- 0x75, 0x01, // Report Size (1)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- 0xC0, // End Collection
- 0xC0, // End Collection
- #endif
- #ifdef SHARED_EP_ENABLE
- };
- #endif
- #ifdef RAW_ENABLE
- const PROGMEM uchar raw_hid_report[] = {
- 0x06, HID_VALUE_16(RAW_USAGE_PAGE), // Usage Page (Vendor Defined)
- 0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
- 0xA1, 0x01, // Collection (Application)
- // Data to host
- 0x09, 0x62, // Usage (Vendor Defined)
- 0x15, 0x00, // Logical Minimum (0)
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
- 0x95, RAW_BUFFER_SIZE, // Report Count
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- // Data from host
- 0x09, 0x63, // Usage (Vendor Defined)
- 0x15, 0x00, // Logical Minimum (0)
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
- 0x95, RAW_BUFFER_SIZE, // Report Count
- 0x75, 0x08, // Report Size (8)
- 0x91, 0x02, // Output (Data, Variable, Absolute)
- 0xC0 // End Collection
- };
- #endif
- #ifdef PLOVER_HID_ENABLE
- // clang-format off
- const PROGMEM uchar plover_hid_report[] = {
- 0x06, 0x50, 0xFF, // Usage Page (Vendor Defined)
- 0x0A, 0x56, 0x4C, // Usage (Vendor Defined) (0xff P L V)
- 0xA1, 0x01, // Collection (Application)
- 0x85, REPORT_ID_PLOVER_HID, // Report ID
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x75, 0x01, // Report Size (1)
- 0x95, 0x40, // Report Count (43)
- 0x05, 0x0A, // Usage Page: Ordinal
- 0x19, 0x00, // Usage Minimum
- 0x29, 0x3F, // Usage Maximum (63)
- 0x81, 0x02, // Output (Data, Variable, Absolute)
- 0xC0 // End Collection
- };
- // clang-format on
- #endif
- #if defined(CONSOLE_ENABLE)
- const PROGMEM uchar console_hid_report[] = {
- 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible)
- 0x09, 0x74, // Usage (Vendor Defined - PJRC Teensy compatible)
- 0xA1, 0x01, // Collection (Application)
- // Data to host
- 0x09, 0x75, // Usage (Vendor Defined)
- 0x15, 0x00, // Logical Minimum (0x00)
- 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF)
- 0x95, CONSOLE_BUFFER_SIZE, // Report Count
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- 0xC0 // End Collection
- };
- #endif
- #ifdef XAP_ENABLE
- const PROGMEM uchar xap_report[] = {
- 0x06, 0x51, 0xFF, // Usage Page (Vendor Defined)
- 0x09, 0x58, // Usage (Vendor Defined)
- 0xA1, 0x01, // Collection (Application)
- // Data to host
- 0x09, 0x62, // Usage (Vendor Defined)
- 0x15, 0x00, // Logical Minimum (0)
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
- 0x95, XAP_BUFFER_SIZE, // Report Count
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- // Data from host
- 0x09, 0x63, // Usage (Vendor Defined)
- 0x15, 0x00, // Logical Minimum (0)
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
- 0x95, XAP_BUFFER_SIZE, // Report Count
- 0x75, 0x08, // Report Size (8)
- 0x91, 0x02, // Output (Data, Variable, Absolute)
- 0xC0 // End Collection
- };
- #endif
- #ifndef USB_MAX_POWER_CONSUMPTION
- # define USB_MAX_POWER_CONSUMPTION 500
- #endif
- #ifndef USB_POLLING_INTERVAL_MS
- # define USB_POLLING_INTERVAL_MS 1
- #endif
- // clang-format off
- const PROGMEM usbStringDescriptor_t usbStringDescriptorZero = {
- .header = {
- .bLength = 4,
- .bDescriptorType = USBDESCR_STRING
- },
- .bString = {0x0409} // US English
- };
- const PROGMEM usbStringDescriptor_t usbStringDescriptorManufacturer = {
- .header = {
- .bLength = sizeof(USBSTR(MANUFACTURER)),
- .bDescriptorType = USBDESCR_STRING
- },
- .bString = USBSTR(MANUFACTURER)
- };
- const PROGMEM usbStringDescriptor_t usbStringDescriptorProduct = {
- .header = {
- .bLength = sizeof(USBSTR(PRODUCT)),
- .bDescriptorType = USBDESCR_STRING
- },
- .bString = USBSTR(PRODUCT)
- };
- #if defined(SERIAL_NUMBER)
- const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = {
- .header = {
- .bLength = sizeof(USBSTR(SERIAL_NUMBER)),
- .bDescriptorType = USBDESCR_STRING
- },
- .bString = USBSTR(SERIAL_NUMBER)
- };
- #endif
- /*
- * Device descriptor
- */
- const PROGMEM usbDeviceDescriptor_t usbDeviceDescriptor = {
- .header = {
- .bLength = sizeof(usbDeviceDescriptor_t),
- .bDescriptorType = USBDESCR_DEVICE
- },
- .bcdUSB = 0x0110,
- .bDeviceClass = 0x00,
- .bDeviceSubClass = 0x00,
- .bDeviceProtocol = 0x00,
- .bMaxPacketSize0 = 8,
- .idVendor = VENDOR_ID,
- .idProduct = PRODUCT_ID,
- .bcdDevice = DEVICE_VER,
- .iManufacturer = 0x01,
- .iProduct = 0x02,
- #if defined(SERIAL_NUMBER)
- .iSerialNumber = 0x03,
- #else
- .iSerialNumber = 0x00,
- #endif
- .bNumConfigurations = 1
- };
- /*
- * Configuration descriptors
- */
- const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
- .header = {
- .header = {
- .bLength = sizeof(usbConfigurationDescriptorHeader_t),
- .bDescriptorType = USBDESCR_CONFIG
- },
- .wTotalLength = sizeof(usbConfigurationDescriptor_t),
- .bNumInterfaces = TOTAL_INTERFACES,
- .bConfigurationValue = 0x01,
- .iConfiguration = 0x00,
- .bmAttributes = (1 << 7) | USBATTR_REMOTEWAKE,
- .bMaxPower = USB_MAX_POWER_CONSUMPTION / 2
- },
- # ifndef KEYBOARD_SHARED_EP
- /*
- * Keyboard
- */
- .keyboardInterface = {
- .header = {
- .bLength = sizeof(usbInterfaceDescriptor_t),
- .bDescriptorType = USBDESCR_INTERFACE
- },
- .bInterfaceNumber = KEYBOARD_INTERFACE,
- .bAlternateSetting = 0x00,
- .bNumEndpoints = 1,
- .bInterfaceClass = 0x03,
- .bInterfaceSubClass = 0x01,
- .bInterfaceProtocol = 0x01,
- .iInterface = 0x00
- },
- .keyboardHID = {
- .header = {
- .bLength = sizeof(usbHIDDescriptor_t),
- .bDescriptorType = USBDESCR_HID
- },
- .bcdHID = 0x0101,
- .bCountryCode = 0x00,
- .bNumDescriptors = 1,
- .bDescriptorType = USBDESCR_HID_REPORT,
- .wDescriptorLength = sizeof(keyboard_hid_report)
- },
- .keyboardINEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | 1),
- .bmAttributes = 0x03,
- .wMaxPacketSize = 8,
- .bInterval = USB_POLLING_INTERVAL_MS
- },
- # endif
- # if defined(RAW_ENABLE)
- /*
- * RAW HID
- */
- .rawInterface = {
- .header = {
- .bLength = sizeof(usbInterfaceDescriptor_t),
- .bDescriptorType = USBDESCR_INTERFACE
- },
- .bInterfaceNumber = RAW_INTERFACE,
- .bAlternateSetting = 0x00,
- .bNumEndpoints = 2,
- .bInterfaceClass = 0x03,
- .bInterfaceSubClass = 0x00,
- .bInterfaceProtocol = 0x00,
- .iInterface = 0x00
- },
- .rawHID = {
- .header = {
- .bLength = sizeof(usbHIDDescriptor_t),
- .bDescriptorType = USBDESCR_HID
- },
- .bcdHID = 0x0101,
- .bCountryCode = 0x00,
- .bNumDescriptors = 1,
- .bDescriptorType = USBDESCR_HID_REPORT,
- .wDescriptorLength = sizeof(raw_hid_report)
- },
- .rawINEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP4_NUMBER),
- .bmAttributes = 0x03,
- .wMaxPacketSize = RAW_EPSIZE,
- .bInterval = USB_POLLING_INTERVAL_MS
- },
- .rawOUTEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP4_NUMBER),
- .bmAttributes = 0x03,
- .wMaxPacketSize = RAW_EPSIZE,
- .bInterval = USB_POLLING_INTERVAL_MS
- },
- # endif
- # if defined(PLOVER_HID_ENABLE)
- /*
- * Plover HID
- */
- .ploverInterface = {
- .header = {
- .bLength = sizeof(usbInterfaceDescriptor_t),
- .bDescriptorType = USBDESCR_INTERFACE
- },
- .bInterfaceNumber = PLOVER_HID_INTERFACE,
- .bAlternateSetting = 0x00,
- .bNumEndpoints = 1,
- .bInterfaceClass = 0x03,
- .bInterfaceSubClass = 0x00,
- .bInterfaceProtocol = 0x00,
- .iInterface = 0x00
- },
- .ploverHID = {
- .header = {
- .bLength = sizeof(usbHIDDescriptor_t),
- .bDescriptorType = USBDESCR_HID
- },
- .bcdHID = 0x0101,
- .bCountryCode = 0x00,
- .bNumDescriptors = 1,
- .bDescriptorType = USBDESCR_HID_REPORT,
- .wDescriptorLength = sizeof(plover_hid_report)
- },
- .ploverINEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP4_NUMBER),
- .bmAttributes = 0x03,
- .wMaxPacketSize = PLOVER_HID_EPSIZE,
- .bInterval = 0x01
- },
- # endif
- # ifdef SHARED_EP_ENABLE
- /*
- * Shared
- */
- .sharedInterface = {
- .header = {
- .bLength = sizeof(usbInterfaceDescriptor_t),
- .bDescriptorType = USBDESCR_INTERFACE
- },
- .bInterfaceNumber = SHARED_INTERFACE,
- .bAlternateSetting = 0x00,
- .bNumEndpoints = 1,
- .bInterfaceClass = 0x03,
- # ifdef KEYBOARD_SHARED_EP
- .bInterfaceSubClass = 0x01,
- .bInterfaceProtocol = 0x01,
- # else
- .bInterfaceSubClass = 0x00,
- .bInterfaceProtocol = 0x00,
- # endif
- .iInterface = 0x00
- },
- .sharedHID = {
- .header = {
- .bLength = sizeof(usbHIDDescriptor_t),
- .bDescriptorType = USBDESCR_HID
- },
- .bcdHID = 0x0101,
- .bCountryCode = 0x00,
- .bNumDescriptors = 1,
- .bDescriptorType = USBDESCR_HID_REPORT,
- .wDescriptorLength = sizeof(shared_hid_report)
- },
- .sharedINEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- # ifdef KEYBOARD_SHARED_EP
- .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | 1),
- # else
- .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
- # endif
- .bmAttributes = 0x03,
- .wMaxPacketSize = 8,
- .bInterval = USB_POLLING_INTERVAL_MS
- },
- # endif
- # if defined(CONSOLE_ENABLE)
- /*
- * Console
- */
- .consoleInterface = {
- .header = {
- .bLength = sizeof(usbInterfaceDescriptor_t),
- .bDescriptorType = USBDESCR_INTERFACE
- },
- .bInterfaceNumber = CONSOLE_INTERFACE,
- .bAlternateSetting = 0x00,
- .bNumEndpoints = 2,
- .bInterfaceClass = 0x03,
- .bInterfaceSubClass = 0x00,
- .bInterfaceProtocol = 0x00,
- .iInterface = 0x00
- },
- .consoleHID = {
- .header = {
- .bLength = sizeof(usbHIDDescriptor_t),
- .bDescriptorType = USBDESCR_HID
- },
- .bcdHID = 0x0111,
- .bCountryCode = 0x00,
- .bNumDescriptors = 1,
- .bDescriptorType = USBDESCR_HID_REPORT,
- .wDescriptorLength = sizeof(console_hid_report)
- },
- .consoleINEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
- .bmAttributes = 0x03,
- .wMaxPacketSize = CONSOLE_EPSIZE,
- .bInterval = 0x01
- },
- # endif
- # if defined(XAP_ENABLE)
- /*
- * XAP
- */
- .xapInterface = {
- .header = {
- .bLength = sizeof(usbInterfaceDescriptor_t),
- .bDescriptorType = USBDESCR_INTERFACE
- },
- .bInterfaceNumber = XAP_INTERFACE,
- .bAlternateSetting = 0x00,
- .bNumEndpoints = 2,
- .bInterfaceClass = 0x03,
- .bInterfaceSubClass = 0x00,
- .bInterfaceProtocol = 0x00,
- .iInterface = 0x00
- },
- .xapHID = {
- .header = {
- .bLength = sizeof(usbHIDDescriptor_t),
- .bDescriptorType = USBDESCR_HID
- },
- .bcdHID = 0x0101,
- .bCountryCode = 0x00,
- .bNumDescriptors = 1,
- .bDescriptorType = USBDESCR_HID_REPORT,
- .wDescriptorLength = sizeof(xap_report)
- },
- .xapINEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP4_NUMBER),
- .bmAttributes = 0x03,
- .wMaxPacketSize = XAP_EPSIZE,
- .bInterval = USB_POLLING_INTERVAL_MS
- },
- .xapOUTEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP4_NUMBER),
- .bmAttributes = 0x03,
- .wMaxPacketSize = XAP_EPSIZE,
- .bInterval = USB_POLLING_INTERVAL_MS
- },
- # endif
- };
- // clang-format on
- USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
- usbMsgLen_t len = 0;
- switch (rq->wValue.bytes[1]) {
- case USBDESCR_DEVICE:
- usbMsgPtr = (usbMsgPtr_t)&usbDeviceDescriptor;
- len = sizeof(usbDeviceDescriptor_t);
- break;
- case USBDESCR_CONFIG:
- usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor;
- len = sizeof(usbConfigurationDescriptor_t);
- break;
- case USBDESCR_STRING:
- switch (rq->wValue.bytes[0]) {
- case 0:
- usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorZero;
- len = usbStringDescriptorZero.header.bLength;
- break;
- case 1: // iManufacturer
- usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorManufacturer;
- len = usbStringDescriptorManufacturer.header.bLength;
- break;
- case 2: // iProduct
- usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorProduct;
- len = usbStringDescriptorProduct.header.bLength;
- break;
- #if defined(SERIAL_NUMBER)
- case 3: // iSerialNumber
- usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorSerial;
- len = usbStringDescriptorSerial.header.bLength;
- break;
- #endif
- }
- #ifdef OS_DETECTION_ENABLE
- process_wlength(rq->wLength.word);
- #endif
- break;
- case USBDESCR_HID:
- switch (rq->wIndex.word) {
- #ifndef KEYBOARD_SHARED_EP
- case KEYBOARD_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.keyboardHID;
- len = sizeof(usbHIDDescriptor_t);
- break;
- #endif
- #if defined(RAW_ENABLE)
- case RAW_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.rawHID;
- len = sizeof(usbHIDDescriptor_t);
- break;
- #endif
- #ifdef SHARED_EP_ENABLE
- case SHARED_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.sharedHID;
- len = sizeof(usbHIDDescriptor_t);
- break;
- #endif
- #if defined(CONSOLE_ENABLE)
- case CONSOLE_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.consoleHID;
- len = sizeof(usbHIDDescriptor_t);
- break;
- #endif
- #if defined(XAP_ENABLE)
- case XAP_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.xapHID;
- len = sizeof(usbHIDDescriptor_t);
- break;
- #endif
- }
- break;
- case USBDESCR_HID_REPORT:
- /* interface index */
- switch (rq->wIndex.word) {
- #ifndef KEYBOARD_SHARED_EP
- case KEYBOARD_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)keyboard_hid_report;
- len = sizeof(keyboard_hid_report);
- break;
- #endif
- #if defined(RAW_ENABLE)
- case RAW_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)raw_hid_report;
- len = sizeof(raw_hid_report);
- break;
- #endif
- #if defined(PLOVER_HID_ENABLE)
- case PLOVER_HID_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)plover_hid_report;
- len = sizeof(plover_hid_report);
- break;
- #endif
- #ifdef SHARED_EP_ENABLE
- case SHARED_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)shared_hid_report;
- len = sizeof(shared_hid_report);
- break;
- #endif
- #if defined(CONSOLE_ENABLE)
- case CONSOLE_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)console_hid_report;
- len = sizeof(console_hid_report);
- break;
- #endif
- #if defined(XAP_ENABLE)
- case XAP_INTERFACE:
- usbMsgPtr = (usbMsgPtr_t)xap_report;
- len = sizeof(xap_report);
- break;
- #endif
- }
- break;
- }
- return len;
- }
|