logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

vusb.c (39724B)


  1. /*
  2. Copyright 2011 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdint.h>
  15. #include <avr/wdt.h>
  16. #include <usbdrv/usbdrv.h>
  17. #include "compiler_support.h"
  18. #include "usbconfig.h"
  19. #include "host.h"
  20. #include "report.h"
  21. #include "host_driver.h"
  22. #include "vusb.h"
  23. #include "print.h"
  24. #include "debug.h"
  25. #include "wait.h"
  26. #include "usb_descriptor_common.h"
  27. #include "usb_device_state.h"
  28. #ifdef RAW_ENABLE
  29. # include "raw_hid.h"
  30. #endif
  31. #ifdef JOYSTICK_ENABLE
  32. # include "joystick.h"
  33. #endif
  34. #if defined(CONSOLE_ENABLE)
  35. # define RBUF_SIZE 128
  36. # include "ring_buffer.h"
  37. #endif
  38. #ifdef OS_DETECTION_ENABLE
  39. # include "os_detection.h"
  40. #endif
  41. /*
  42. * Interface indexes
  43. */
  44. enum usb_interfaces {
  45. #ifndef KEYBOARD_SHARED_EP
  46. KEYBOARD_INTERFACE,
  47. #else
  48. SHARED_INTERFACE,
  49. # define KEYBOARD_INTERFACE SHARED_INTERFACE
  50. #endif
  51. // It is important that the Raw HID interface is at a constant
  52. // interface number, to support Linux/OSX platforms and chrome.hid
  53. // If Raw HID is enabled, let it be always 1.
  54. #ifdef RAW_ENABLE
  55. RAW_INTERFACE,
  56. #endif
  57. #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
  58. SHARED_INTERFACE,
  59. #endif
  60. #ifdef CONSOLE_ENABLE
  61. CONSOLE_INTERFACE,
  62. #endif
  63. TOTAL_INTERFACES
  64. };
  65. #define MAX_INTERFACES 3
  66. 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.");
  67. #if (defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)) && CONSOLE_ENABLE
  68. # error Mouse/Extra Keys share an endpoint with Console. Please disable one of the two.
  69. #endif
  70. static report_keyboard_t keyboard_report_sent;
  71. static void send_report_fragment(uint8_t endpoint, void *data, size_t size) {
  72. for (uint8_t retries = 5; retries > 0; retries--) {
  73. switch (endpoint) {
  74. case 1:
  75. if (usbInterruptIsReady()) {
  76. usbSetInterrupt(data, size);
  77. return;
  78. }
  79. break;
  80. case USB_CFG_EP3_NUMBER:
  81. if (usbInterruptIsReady3()) {
  82. usbSetInterrupt3(data, size);
  83. return;
  84. }
  85. break;
  86. case USB_CFG_EP4_NUMBER:
  87. if (usbInterruptIsReady4()) {
  88. usbSetInterrupt4(data, size);
  89. return;
  90. }
  91. break;
  92. default:
  93. return;
  94. }
  95. usbPoll();
  96. wait_ms(5);
  97. }
  98. }
  99. static void send_report(uint8_t endpoint, void *report, size_t size) {
  100. uint8_t *temp = (uint8_t *)report;
  101. // Send as many full packets as possible
  102. for (uint8_t i = 0; i < size / 8; i++) {
  103. send_report_fragment(endpoint, temp, 8);
  104. temp += 8;
  105. }
  106. // Send any data left over
  107. uint8_t remainder = size % 8;
  108. if (remainder) {
  109. send_report_fragment(endpoint, temp, remainder);
  110. }
  111. }
  112. /*------------------------------------------------------------------*
  113. * RAW HID
  114. *------------------------------------------------------------------*/
  115. #ifdef RAW_ENABLE
  116. # define RAW_BUFFER_SIZE 32
  117. # define RAW_EPSIZE 8
  118. static uint8_t raw_output_buffer[RAW_BUFFER_SIZE];
  119. static uint8_t raw_output_received_bytes = 0;
  120. static void send_raw_hid(uint8_t *data, uint8_t length) {
  121. if (length != RAW_BUFFER_SIZE) {
  122. return;
  123. }
  124. send_report(4, data, 32);
  125. }
  126. void raw_hid_task(void) {
  127. usbPoll();
  128. if (!usbConfiguration || !usbInterruptIsReady4()) {
  129. return;
  130. }
  131. if (raw_output_received_bytes == RAW_BUFFER_SIZE) {
  132. raw_hid_receive(raw_output_buffer, RAW_BUFFER_SIZE);
  133. raw_output_received_bytes = 0;
  134. }
  135. }
  136. #endif
  137. /*------------------------------------------------------------------*
  138. * Console
  139. *------------------------------------------------------------------*/
  140. #ifdef CONSOLE_ENABLE
  141. # define CONSOLE_BUFFER_SIZE 32
  142. # define CONSOLE_EPSIZE 8
  143. int8_t sendchar(uint8_t c) {
  144. rbuf_enqueue(c);
  145. return 0;
  146. }
  147. void console_task(void) {
  148. usbPoll();
  149. if (!usbConfiguration || !usbInterruptIsReady3()) {
  150. return;
  151. }
  152. if (!rbuf_has_data()) {
  153. return;
  154. }
  155. // Send in chunks of 8 padded to 32
  156. char send_buf[CONSOLE_BUFFER_SIZE] = {0};
  157. uint8_t send_buf_count = 0;
  158. while (rbuf_has_data() && send_buf_count < CONSOLE_EPSIZE) {
  159. send_buf[send_buf_count++] = rbuf_dequeue();
  160. }
  161. send_report(3, send_buf, CONSOLE_BUFFER_SIZE);
  162. }
  163. #endif
  164. /*------------------------------------------------------------------*
  165. * Host driver
  166. *------------------------------------------------------------------*/
  167. static void send_keyboard(report_keyboard_t *report);
  168. static void send_nkro(report_nkro_t *report);
  169. static void send_mouse(report_mouse_t *report);
  170. static void send_extra(report_extra_t *report);
  171. #ifdef RAW_ENABLE
  172. static void send_raw_hid(uint8_t *data, uint8_t length);
  173. #endif
  174. static host_driver_t driver = {
  175. .keyboard_leds = usb_device_state_get_leds,
  176. .send_keyboard = send_keyboard,
  177. .send_nkro = send_nkro,
  178. .send_mouse = send_mouse,
  179. .send_extra = send_extra,
  180. #ifdef RAW_ENABLE
  181. .send_raw_hid = send_raw_hid,
  182. #endif
  183. };
  184. host_driver_t *vusb_driver(void) {
  185. return &driver;
  186. }
  187. static void send_keyboard(report_keyboard_t *report) {
  188. if (usb_device_state_get_protocol() == USB_PROTOCOL_BOOT) {
  189. send_report(1, &report->mods, 8);
  190. } else {
  191. send_report(1, report, sizeof(report_keyboard_t));
  192. }
  193. keyboard_report_sent = *report;
  194. }
  195. #ifndef KEYBOARD_SHARED_EP
  196. # define MOUSE_IN_EPNUM 3
  197. # define SHARED_IN_EPNUM 3
  198. #else
  199. # define MOUSE_IN_EPNUM 1
  200. # define SHARED_IN_EPNUM 1
  201. #endif
  202. static void send_nkro(report_nkro_t *report) {
  203. #ifdef NKRO_ENABLE
  204. send_report(3, report, sizeof(report_nkro_t));
  205. #endif
  206. }
  207. static void send_mouse(report_mouse_t *report) {
  208. #ifdef MOUSE_ENABLE
  209. send_report(MOUSE_IN_EPNUM, report, sizeof(report_mouse_t));
  210. #endif
  211. }
  212. static void send_extra(report_extra_t *report) {
  213. #ifdef EXTRAKEY_ENABLE
  214. send_report(SHARED_IN_EPNUM, report, sizeof(report_extra_t));
  215. #endif
  216. }
  217. void send_joystick(report_joystick_t *report) {
  218. #ifdef JOYSTICK_ENABLE
  219. send_report(SHARED_IN_EPNUM, report, sizeof(report_joystick_t));
  220. #endif
  221. }
  222. void send_digitizer(report_digitizer_t *report) {
  223. #ifdef DIGITIZER_ENABLE
  224. send_report(SHARED_IN_EPNUM, report, sizeof(report_digitizer_t));
  225. #endif
  226. }
  227. void send_programmable_button(report_programmable_button_t *report) {
  228. #ifdef PROGRAMMABLE_BUTTON_ENABLE
  229. send_report(SHARED_IN_EPNUM, report, sizeof(report_programmable_button_t));
  230. #endif
  231. }
  232. /*------------------------------------------------------------------*
  233. * Request from host *
  234. *------------------------------------------------------------------*/
  235. static struct {
  236. uint16_t len;
  237. enum { NONE, SET_LED } kind;
  238. } last_req;
  239. usbMsgLen_t usbFunctionSetup(uchar data[8]) {
  240. usbRequest_t *rq = (void *)data;
  241. if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
  242. switch (rq->bRequest) {
  243. case USBRQ_HID_GET_REPORT:
  244. dprint("GET_REPORT:");
  245. if (rq->wIndex.word == KEYBOARD_INTERFACE) {
  246. usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent;
  247. return sizeof(keyboard_report_sent);
  248. }
  249. break;
  250. case USBRQ_HID_GET_IDLE:
  251. dprint("GET_IDLE:");
  252. static uint8_t keyboard_idle;
  253. keyboard_idle = usb_device_state_get_idle_rate();
  254. usbMsgPtr = (usbMsgPtr_t)&keyboard_idle;
  255. return 1;
  256. case USBRQ_HID_GET_PROTOCOL:
  257. dprint("GET_PROTOCOL:");
  258. static uint8_t keyboard_protocol;
  259. keyboard_protocol = usb_device_state_get_protocol();
  260. usbMsgPtr = (usbMsgPtr_t)&keyboard_protocol;
  261. return 1;
  262. case USBRQ_HID_SET_REPORT:
  263. dprint("SET_REPORT:");
  264. // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
  265. if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) {
  266. dprint("SET_LED:");
  267. last_req.kind = SET_LED;
  268. last_req.len = rq->wLength.word;
  269. }
  270. return USB_NO_MSG; // to get data in usbFunctionWrite
  271. case USBRQ_HID_SET_IDLE:
  272. usb_device_state_set_idle_rate(rq->wValue.word >> 8);
  273. dprintf("SET_IDLE: %02X", usb_device_state_get_idle_rate());
  274. break;
  275. case USBRQ_HID_SET_PROTOCOL:
  276. if (rq->wIndex.word == KEYBOARD_INTERFACE) {
  277. usb_device_state_set_protocol(rq->wValue.word & 0xFF);
  278. dprintf("SET_PROTOCOL: %02X", usb_device_state_get_protocol());
  279. }
  280. break;
  281. default:
  282. dprint("UNKNOWN:");
  283. break;
  284. }
  285. } else {
  286. dprint("VENDOR:");
  287. /* no vendor specific requests implemented */
  288. }
  289. dprint("\n");
  290. return 0; /* default for not implemented requests: return no data back to host */
  291. }
  292. uchar usbFunctionWrite(uchar *data, uchar len) {
  293. if (last_req.len == 0) {
  294. return -1;
  295. }
  296. switch (last_req.kind) {
  297. case SET_LED:
  298. usb_device_state_set_leds(data[0]);
  299. dprintf("SET_LED: %02X\n", usb_device_state_get_leds());
  300. last_req.len = 0;
  301. return 1;
  302. break;
  303. case NONE:
  304. default:
  305. return -1;
  306. break;
  307. }
  308. return 1;
  309. }
  310. void usbFunctionWriteOut(uchar *data, uchar len) {
  311. #ifdef RAW_ENABLE
  312. // Data from host must be divided every 8bytes
  313. if (len != 8) {
  314. dprint("RAW: invalid length\n");
  315. raw_output_received_bytes = 0;
  316. return;
  317. }
  318. if (raw_output_received_bytes + len > RAW_BUFFER_SIZE) {
  319. dprint("RAW: buffer full\n");
  320. raw_output_received_bytes = 0;
  321. } else {
  322. for (uint8_t i = 0; i < 8; i++) {
  323. raw_output_buffer[raw_output_received_bytes + i] = data[i];
  324. }
  325. raw_output_received_bytes += len;
  326. }
  327. #endif
  328. }
  329. /*------------------------------------------------------------------*
  330. * Descriptors *
  331. *------------------------------------------------------------------*/
  332. #ifdef KEYBOARD_SHARED_EP
  333. const PROGMEM uchar shared_hid_report[] = {
  334. # define SHARED_REPORT_STARTED
  335. #else
  336. const PROGMEM uchar keyboard_hid_report[] = {
  337. #endif
  338. 0x05, 0x01, // Usage Page (Generic Desktop)
  339. 0x09, 0x06, // Usage (Keyboard)
  340. 0xA1, 0x01, // Collection (Application)
  341. #ifdef KEYBOARD_SHARED_EP
  342. 0x85, REPORT_ID_KEYBOARD, // Report ID
  343. #endif
  344. // Modifiers (8 bits)
  345. 0x05, 0x07, // Usage Page (Keyboard/Keypad)
  346. 0x19, 0xE0, // Usage Minimum (Keyboard Left Control)
  347. 0x29, 0xE7, // Usage Maximum (Keyboard Right GUI)
  348. 0x15, 0x00, // Logical Minimum (0)
  349. 0x25, 0x01, // Logical Maximum (1)
  350. 0x95, 0x08, // Report Count (8)
  351. 0x75, 0x01, // Report Size (1)
  352. 0x81, 0x02, // Input (Data, Variable, Absolute)
  353. // Reserved (1 byte)
  354. 0x95, 0x01, // Report Count (1)
  355. 0x75, 0x08, // Report Size (8)
  356. 0x81, 0x03, // Input (Constant)
  357. // Keycodes (6 bytes)
  358. 0x05, 0x07, // Usage Page (Keyboard/Keypad)
  359. 0x19, 0x00, // Usage Minimum (0)
  360. 0x29, 0xFF, // Usage Maximum (255)
  361. 0x15, 0x00, // Logical Minimum (0)
  362. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  363. 0x95, 0x06, // Report Count (6)
  364. 0x75, 0x08, // Report Size (8)
  365. 0x81, 0x00, // Input (Data, Array, Absolute)
  366. // Status LEDs (5 bits)
  367. 0x05, 0x08, // Usage Page (LED)
  368. 0x19, 0x01, // Usage Minimum (Num Lock)
  369. 0x29, 0x05, // Usage Maximum (Kana)
  370. 0x15, 0x00, // Logical Minimum (0)
  371. 0x25, 0x01, // Logical Maximum (1)
  372. 0x95, 0x05, // Report Count (5)
  373. 0x75, 0x01, // Report Size (1)
  374. 0x91, 0x02, // Output (Data, Variable, Absolute)
  375. // LED padding (3 bits)
  376. 0x95, 0x01, // Report Count (1)
  377. 0x75, 0x03, // Report Size (3)
  378. 0x91, 0x03, // Output (Constant)
  379. 0xC0, // End Collection
  380. #ifndef KEYBOARD_SHARED_EP
  381. };
  382. #endif
  383. #if defined(SHARED_EP_ENABLE) && !defined(SHARED_REPORT_STARTED)
  384. const PROGMEM uchar shared_hid_report[] = {
  385. # define SHARED_REPORT_STARTED
  386. #endif
  387. #ifdef NKRO_ENABLE
  388. // NKRO report descriptor
  389. 0x05, 0x01, // Usage Page (Generic Desktop)
  390. 0x09, 0x06, // Usage (Keyboard)
  391. 0xA1, 0x01, // Collection (Application)
  392. 0x85, REPORT_ID_NKRO, // Report ID
  393. // Modifiers (8 bits)
  394. 0x05, 0x07, // Usage Page (Keyboard/Keypad)
  395. 0x19, 0xE0, // Usage Minimum (Keyboard Left Control)
  396. 0x29, 0xE7, // Usage Maximum (Keyboard Right GUI)
  397. 0x15, 0x00, // Logical Minimum (0)
  398. 0x25, 0x01, // Logical Maximum (1)
  399. 0x95, 0x08, // Report Count (8)
  400. 0x75, 0x01, // Report Size (1)
  401. 0x81, 0x02, // Input (Data, Variable, Absolute)
  402. // Keycodes
  403. 0x05, 0x07, // Usage Page (Keyboard/Keypad)
  404. 0x19, 0x00, // Usage Minimum (0)
  405. 0x29, NKRO_REPORT_BITS * 8 - 1, // Usage Maximum
  406. 0x15, 0x00, // Logical Minimum (0)
  407. 0x25, 0x01, // Logical Maximum (1)
  408. 0x95, NKRO_REPORT_BITS * 8, // Report Count
  409. 0x75, 0x01, // Report Size (1)
  410. 0x81, 0x02, // Input (Data, Variable, Absolute)
  411. // Status LEDs (5 bits)
  412. 0x05, 0x08, // Usage Page (LED)
  413. 0x19, 0x01, // Usage Minimum (Num Lock)
  414. 0x29, 0x05, // Usage Maximum (Kana)
  415. 0x95, 0x05, // Report Count (5)
  416. 0x75, 0x01, // Report Size (1)
  417. 0x91, 0x02, // Output (Data, Variable, Absolute)
  418. // LED padding (3 bits)
  419. 0x95, 0x01, // Report Count (1)
  420. 0x75, 0x03, // Report Size (3)
  421. 0x91, 0x03, // Output (Constant)
  422. 0xC0, // End Collection
  423. #endif
  424. #ifdef MOUSE_ENABLE
  425. // Mouse report descriptor
  426. 0x05, 0x01, // Usage Page (Generic Desktop)
  427. 0x09, 0x02, // Usage (Mouse)
  428. 0xA1, 0x01, // Collection (Application)
  429. 0x85, REPORT_ID_MOUSE, // Report ID
  430. 0x09, 0x01, // Usage (Pointer)
  431. 0xA1, 0x00, // Collection (Physical)
  432. // Buttons (8 bits)
  433. 0x05, 0x09, // Usage Page (Button)
  434. 0x19, 0x01, // Usage Minimum (Button 1)
  435. 0x29, 0x08, // Usage Maximum (Button 8)
  436. 0x15, 0x00, // Logical Minimum (0)
  437. 0x25, 0x01, // Logical Maximum (1)
  438. 0x95, 0x08, // Report Count (8)
  439. 0x75, 0x01, // Report Size (1)
  440. 0x81, 0x02, // Input (Data, Variable, Absolute)
  441. # ifdef MOUSE_EXTENDED_REPORT
  442. // Boot protocol XY ignored in Report protocol
  443. 0x95, 0x02, // Report Count (2)
  444. 0x75, 0x08, // Report Size (8)
  445. 0x81, 0x03, // Input (Constant)
  446. # endif
  447. // X/Y position (2 or 4 bytes)
  448. 0x05, 0x01, // Usage Page (Generic Desktop)
  449. 0x09, 0x30, // Usage (X)
  450. 0x09, 0x31, // Usage (Y)
  451. # ifndef MOUSE_EXTENDED_REPORT
  452. 0x15, 0x81, // Logical Minimum (-127)
  453. 0x25, 0x7F, // Logical Maximum (127)
  454. 0x95, 0x02, // Report Count (2)
  455. 0x75, 0x08, // Report Size (8)
  456. # else
  457. 0x16, 0x01, 0x80, // Logical Minimum (-32767)
  458. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  459. 0x95, 0x02, // Report Count (2)
  460. 0x75, 0x10, // Report Size (16)
  461. # endif
  462. 0x81, 0x06, // Input (Data, Variable, Relative)
  463. # ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
  464. // Feature report and padding (1 byte)
  465. 0xA1, 0x02, // Collection (Logical)
  466. 0x09, 0x48, // Usage (Resolution Multiplier)
  467. 0x95, 0x01, // Report Count (1)
  468. 0x75, 0x02, // Report Size (2)
  469. 0x15, 0x00, // Logical Minimum (0)
  470. 0x25, 0x01, // Logical Maximum (1)
  471. 0x35, 0x01, // Physical Minimum (1)
  472. 0x45, POINTING_DEVICE_HIRES_SCROLL_MULTIPLIER, // Physical Maximum (POINTING_DEVICE_HIRES_SCROLL_MULTIPLIER)
  473. 0x55, POINTING_DEVICE_HIRES_SCROLL_EXPONENT, // Unit Exponent (POINTING_DEVICE_HIRES_SCROLL_EXPONENT)
  474. 0xB1, 0x02, // Feature (Data, Variable, Absolute)
  475. 0x35, 0x00, // Physical Minimum (0)
  476. 0x45, 0x00, // Physical Maximum (0)
  477. 0x75, 0x06, // Report Size (6)
  478. 0xB1, 0x03, // Feature (Constant)
  479. # endif
  480. // Vertical wheel (1 or 2 bytes)
  481. 0x09, 0x38, // Usage (Wheel)
  482. # ifndef WHEEL_EXTENDED_REPORT
  483. 0x15, 0x81, // Logical Minimum (-127)
  484. 0x25, 0x7F, // Logical Maximum (127)
  485. 0x95, 0x01, // Report Count (1)
  486. 0x75, 0x08, // Report Size (8)
  487. # else
  488. 0x16, 0x01, 0x80, // Logical Minimum (-32767)
  489. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  490. 0x95, 0x01, // Report Count (1)
  491. 0x75, 0x10, // Report Size (16)
  492. # endif
  493. 0x81, 0x06, // Input (Data, Variable, Relative)
  494. // Horizontal wheel (1 or 2 bytes)
  495. 0x05, 0x0C, // Usage Page (Consumer)
  496. 0x0A, 0x38, 0x02, // Usage (AC Pan)
  497. # ifndef WHEEL_EXTENDED_REPORT
  498. 0x15, 0x81, // Logical Minimum (-127)
  499. 0x25, 0x7F, // Logical Maximum (127)
  500. 0x95, 0x01, // Report Count (1)
  501. 0x75, 0x08, // Report Size (8)
  502. # else
  503. 0x16, 0x01, 0x80, // Logical Minimum (-32767)
  504. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  505. 0x95, 0x01, // Report Count (1)
  506. 0x75, 0x10, // Report Size (16)
  507. # endif
  508. 0x81, 0x06, // Input (Data, Variable, Relative)
  509. # ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
  510. 0xC0, // End Collection
  511. # endif
  512. 0xC0, // End Collection
  513. 0xC0, // End Collection
  514. #endif
  515. #ifdef EXTRAKEY_ENABLE
  516. // Extrakeys report descriptor
  517. 0x05, 0x01, // Usage Page (Generic Desktop)
  518. 0x09, 0x80, // Usage (System Control)
  519. 0xA1, 0x01, // Collection (Application)
  520. 0x85, REPORT_ID_SYSTEM, // Report ID
  521. 0x19, 0x01, // Usage Minimum (Pointer)
  522. 0x2A, 0xB7, 0x00, // Usage Maximum (System Display LCD Autoscale)
  523. 0x15, 0x01, // Logical Minimum
  524. 0x26, 0xB7, 0x00, // Logical Maximum
  525. 0x95, 0x01, // Report Count (1)
  526. 0x75, 0x10, // Report Size (16)
  527. 0x81, 0x00, // Input (Data, Array, Absolute)
  528. 0xC0, // End Collection
  529. 0x05, 0x0C, // Usage Page (Consumer)
  530. 0x09, 0x01, // Usage (Consumer Control)
  531. 0xA1, 0x01, // Collection (Application)
  532. 0x85, REPORT_ID_CONSUMER, // Report ID
  533. 0x19, 0x01, // Usage Minimum (Consumer Control)
  534. 0x2A, 0xA0, 0x02, // Usage Maximum (AC Desktop Show All Applications)
  535. 0x15, 0x01, // Logical Minimum
  536. 0x26, 0xA0, 0x02, // Logical Maximum
  537. 0x95, 0x01, // Report Count (1)
  538. 0x75, 0x10, // Report Size (16)
  539. 0x81, 0x00, // Input (Data, Array, Absolute)
  540. 0xC0, // End Collection
  541. #endif
  542. #ifdef JOYSTICK_ENABLE
  543. // Joystick report descriptor
  544. 0x05, 0x01, // Usage Page (Generic Desktop)
  545. 0x09, 0x04, // Usage (Joystick)
  546. 0xA1, 0x01, // Collection (Application)
  547. 0x85, REPORT_ID_JOYSTICK, // Report ID
  548. 0xA1, 0x00, // Collection (Physical)
  549. # if JOYSTICK_AXIS_COUNT > 0
  550. 0x05, 0x01, // Usage Page (Generic Desktop)
  551. 0x09, 0x30, // Usage (X)
  552. # if JOYSTICK_AXIS_COUNT > 1
  553. 0x09, 0x31, // Usage (Y)
  554. # endif
  555. # if JOYSTICK_AXIS_COUNT > 2
  556. 0x09, 0x32, // Usage (Z)
  557. # endif
  558. # if JOYSTICK_AXIS_COUNT > 3
  559. 0x09, 0x33, // Usage (Rx)
  560. # endif
  561. # if JOYSTICK_AXIS_COUNT > 4
  562. 0x09, 0x34, // Usage (Ry)
  563. # endif
  564. # if JOYSTICK_AXIS_COUNT > 5
  565. 0x09, 0x35, // Usage (Rz)
  566. # endif
  567. # if JOYSTICK_AXIS_RESOLUTION == 8
  568. 0x15, -JOYSTICK_MAX_VALUE, // Logical Minimum
  569. 0x25, JOYSTICK_MAX_VALUE, // Logical Maximum
  570. 0x95, JOYSTICK_AXIS_COUNT, // Report Count
  571. 0x75, 0x08, // Report Size (8)
  572. # else
  573. 0x16, HID_VALUE_16(-JOYSTICK_MAX_VALUE), // Logical Minimum
  574. 0x26, HID_VALUE_16(JOYSTICK_MAX_VALUE), // Logical Maximum
  575. 0x95, JOYSTICK_AXIS_COUNT, // Report Count
  576. 0x75, 0x10, // Report Size (16)
  577. # endif
  578. 0x81, 0x02, // Input (Data, Variable, Absolute)
  579. # endif
  580. # ifdef JOYSTICK_HAS_HAT
  581. // Hat Switch (4 bits)
  582. 0x09, 0x39, // Usage (Hat Switch)
  583. 0x15, 0x00, // Logical Minimum (0)
  584. 0x25, 0x07, // Logical Maximum (7)
  585. 0x35, 0x00, // Physical Minimum (0)
  586. 0x46, 0x3B, 0x01, // Physical Maximum (315)
  587. 0x65, 0x14, // Unit (Degree, English Rotation)
  588. 0x95, 0x01, // Report Count (1)
  589. 0x75, 0x04, // Report Size (4)
  590. 0x81, 0x42, // Input (Data, Variable, Absolute, Null State)
  591. // Padding (4 bits)
  592. 0x95, 0x04, // Report Count (4)
  593. 0x75, 0x01, // Report Size (1)
  594. 0x81, 0x01, // Input (Constant)
  595. # endif
  596. # if JOYSTICK_BUTTON_COUNT > 0
  597. 0x05, 0x09, // Usage Page (Button)
  598. 0x19, 0x01, // Usage Minimum (Button 1)
  599. 0x29, JOYSTICK_BUTTON_COUNT, // Usage Maximum
  600. 0x15, 0x00, // Logical Minimum (0)
  601. 0x25, 0x01, // Logical Maximum (1)
  602. 0x95, JOYSTICK_BUTTON_COUNT, // Report Count
  603. 0x75, 0x01, // Report Size (1)
  604. 0x81, 0x02, // Input (Data, Variable, Absolute)
  605. # if (JOYSTICK_BUTTON_COUNT % 8) != 0
  606. 0x95, 8 - (JOYSTICK_BUTTON_COUNT % 8), // Report Count
  607. 0x75, 0x01, // Report Size (1)
  608. 0x81, 0x03, // Input (Constant)
  609. # endif
  610. # endif
  611. 0xC0, // End Collection
  612. 0xC0, // End Collection
  613. #endif
  614. #ifdef DIGITIZER_ENABLE
  615. // Digitizer report descriptor
  616. 0x05, 0x0D, // Usage Page (Digitizers)
  617. 0x09, 0x01, // Usage (Digitizer)
  618. 0xA1, 0x01, // Collection (Application)
  619. 0x85, REPORT_ID_DIGITIZER, // Report ID
  620. 0x09, 0x20, // Usage (Stylus)
  621. 0xA1, 0x00, // Collection (Physical)
  622. // In Range, Tip Switch & Barrel Switch (3 bits)
  623. 0x09, 0x32, // Usage (In Range)
  624. 0x09, 0x42, // Usage (Tip Switch)
  625. 0x09, 0x44, // Usage (Barrel Switch)
  626. 0x15, 0x00, // Logical Minimum
  627. 0x25, 0x01, // Logical Maximum
  628. 0x95, 0x03, // Report Count (3)
  629. 0x75, 0x01, // Report Size (1)
  630. 0x81, 0x02, // Input (Data, Variable, Absolute)
  631. // Padding (5 bits)
  632. 0x95, 0x05, // Report Count (5)
  633. 0x81, 0x03, // Input (Constant)
  634. // X/Y Position (4 bytes)
  635. 0x05, 0x01, // Usage Page (Generic Desktop)
  636. 0x09, 0x30, // Usage (X)
  637. 0x09, 0x31, // Usage (Y)
  638. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  639. 0x95, 0x02, // Report Count (2)
  640. 0x75, 0x10, // Report Size (16)
  641. 0x65, 0x13, // Unit (Inch, English Linear)
  642. 0x55, 0x0E, // Unit Exponent (-2)
  643. 0x81, 0x02, // Input (Data, Variable, Absolute)
  644. 0xC0, // End Collection
  645. 0xC0, // End Collection
  646. #endif
  647. #ifdef PROGRAMMABLE_BUTTON_ENABLE
  648. // Programmable buttons report descriptor
  649. 0x05, 0x0C, // Usage Page (Consumer)
  650. 0x09, 0x01, // Usage (Consumer Control)
  651. 0xA1, 0x01, // Collection (Application)
  652. 0x85, REPORT_ID_PROGRAMMABLE_BUTTON, // Report ID
  653. 0x09, 0x03, // Usage (Programmable Buttons)
  654. 0xA1, 0x04, // Collection (Named Array)
  655. 0x05, 0x09, // Usage Page (Button)
  656. 0x19, 0x01, // Usage Minimum (Button 1)
  657. 0x29, 0x20, // Usage Maximum (Button 32)
  658. 0x15, 0x00, // Logical Minimum (0)
  659. 0x25, 0x01, // Logical Maximum (1)
  660. 0x95, 0x20, // Report Count (32)
  661. 0x75, 0x01, // Report Size (1)
  662. 0x81, 0x02, // Input (Data, Variable, Absolute)
  663. 0xC0, // End Collection
  664. 0xC0, // End Collection
  665. #endif
  666. #ifdef SHARED_EP_ENABLE
  667. };
  668. #endif
  669. #ifdef RAW_ENABLE
  670. const PROGMEM uchar raw_hid_report[] = {
  671. 0x06, HID_VALUE_16(RAW_USAGE_PAGE), // Usage Page (Vendor Defined)
  672. 0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
  673. 0xA1, 0x01, // Collection (Application)
  674. // Data to host
  675. 0x09, 0x62, // Usage (Vendor Defined)
  676. 0x15, 0x00, // Logical Minimum (0)
  677. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  678. 0x95, RAW_BUFFER_SIZE, // Report Count
  679. 0x75, 0x08, // Report Size (8)
  680. 0x81, 0x02, // Input (Data, Variable, Absolute)
  681. // Data from host
  682. 0x09, 0x63, // Usage (Vendor Defined)
  683. 0x15, 0x00, // Logical Minimum (0)
  684. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  685. 0x95, RAW_BUFFER_SIZE, // Report Count
  686. 0x75, 0x08, // Report Size (8)
  687. 0x91, 0x02, // Output (Data, Variable, Absolute)
  688. 0xC0 // End Collection
  689. };
  690. #endif
  691. #if defined(CONSOLE_ENABLE)
  692. const PROGMEM uchar console_hid_report[] = {
  693. 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible)
  694. 0x09, 0x74, // Usage (Vendor Defined - PJRC Teensy compatible)
  695. 0xA1, 0x01, // Collection (Application)
  696. // Data to host
  697. 0x09, 0x75, // Usage (Vendor Defined)
  698. 0x15, 0x00, // Logical Minimum (0x00)
  699. 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF)
  700. 0x95, CONSOLE_BUFFER_SIZE, // Report Count
  701. 0x75, 0x08, // Report Size (8)
  702. 0x81, 0x02, // Input (Data, Variable, Absolute)
  703. 0xC0 // End Collection
  704. };
  705. #endif
  706. #ifndef USB_MAX_POWER_CONSUMPTION
  707. # define USB_MAX_POWER_CONSUMPTION 500
  708. #endif
  709. #ifndef USB_POLLING_INTERVAL_MS
  710. # define USB_POLLING_INTERVAL_MS 1
  711. #endif
  712. // clang-format off
  713. const PROGMEM usbStringDescriptor_t usbStringDescriptorZero = {
  714. .header = {
  715. .bLength = 4,
  716. .bDescriptorType = USBDESCR_STRING
  717. },
  718. .bString = {0x0409} // US English
  719. };
  720. const PROGMEM usbStringDescriptor_t usbStringDescriptorManufacturer = {
  721. .header = {
  722. .bLength = sizeof(USBSTR(MANUFACTURER)),
  723. .bDescriptorType = USBDESCR_STRING
  724. },
  725. .bString = USBSTR(MANUFACTURER)
  726. };
  727. const PROGMEM usbStringDescriptor_t usbStringDescriptorProduct = {
  728. .header = {
  729. .bLength = sizeof(USBSTR(PRODUCT)),
  730. .bDescriptorType = USBDESCR_STRING
  731. },
  732. .bString = USBSTR(PRODUCT)
  733. };
  734. #if defined(SERIAL_NUMBER)
  735. const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = {
  736. .header = {
  737. .bLength = sizeof(USBSTR(SERIAL_NUMBER)),
  738. .bDescriptorType = USBDESCR_STRING
  739. },
  740. .bString = USBSTR(SERIAL_NUMBER)
  741. };
  742. #endif
  743. /*
  744. * Device descriptor
  745. */
  746. const PROGMEM usbDeviceDescriptor_t usbDeviceDescriptor = {
  747. .header = {
  748. .bLength = sizeof(usbDeviceDescriptor_t),
  749. .bDescriptorType = USBDESCR_DEVICE
  750. },
  751. .bcdUSB = 0x0110,
  752. .bDeviceClass = 0x00,
  753. .bDeviceSubClass = 0x00,
  754. .bDeviceProtocol = 0x00,
  755. .bMaxPacketSize0 = 8,
  756. .idVendor = VENDOR_ID,
  757. .idProduct = PRODUCT_ID,
  758. .bcdDevice = DEVICE_VER,
  759. .iManufacturer = 0x01,
  760. .iProduct = 0x02,
  761. #if defined(SERIAL_NUMBER)
  762. .iSerialNumber = 0x03,
  763. #else
  764. .iSerialNumber = 0x00,
  765. #endif
  766. .bNumConfigurations = 1
  767. };
  768. /*
  769. * Configuration descriptors
  770. */
  771. const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
  772. .header = {
  773. .header = {
  774. .bLength = sizeof(usbConfigurationDescriptorHeader_t),
  775. .bDescriptorType = USBDESCR_CONFIG
  776. },
  777. .wTotalLength = sizeof(usbConfigurationDescriptor_t),
  778. .bNumInterfaces = TOTAL_INTERFACES,
  779. .bConfigurationValue = 0x01,
  780. .iConfiguration = 0x00,
  781. .bmAttributes = (1 << 7) | USBATTR_REMOTEWAKE,
  782. .bMaxPower = USB_MAX_POWER_CONSUMPTION / 2
  783. },
  784. # ifndef KEYBOARD_SHARED_EP
  785. /*
  786. * Keyboard
  787. */
  788. .keyboardInterface = {
  789. .header = {
  790. .bLength = sizeof(usbInterfaceDescriptor_t),
  791. .bDescriptorType = USBDESCR_INTERFACE
  792. },
  793. .bInterfaceNumber = KEYBOARD_INTERFACE,
  794. .bAlternateSetting = 0x00,
  795. .bNumEndpoints = 1,
  796. .bInterfaceClass = 0x03,
  797. .bInterfaceSubClass = 0x01,
  798. .bInterfaceProtocol = 0x01,
  799. .iInterface = 0x00
  800. },
  801. .keyboardHID = {
  802. .header = {
  803. .bLength = sizeof(usbHIDDescriptor_t),
  804. .bDescriptorType = USBDESCR_HID
  805. },
  806. .bcdHID = 0x0101,
  807. .bCountryCode = 0x00,
  808. .bNumDescriptors = 1,
  809. .bDescriptorType = USBDESCR_HID_REPORT,
  810. .wDescriptorLength = sizeof(keyboard_hid_report)
  811. },
  812. .keyboardINEndpoint = {
  813. .header = {
  814. .bLength = sizeof(usbEndpointDescriptor_t),
  815. .bDescriptorType = USBDESCR_ENDPOINT
  816. },
  817. .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | 1),
  818. .bmAttributes = 0x03,
  819. .wMaxPacketSize = 8,
  820. .bInterval = USB_POLLING_INTERVAL_MS
  821. },
  822. # endif
  823. # if defined(RAW_ENABLE)
  824. /*
  825. * RAW HID
  826. */
  827. .rawInterface = {
  828. .header = {
  829. .bLength = sizeof(usbInterfaceDescriptor_t),
  830. .bDescriptorType = USBDESCR_INTERFACE
  831. },
  832. .bInterfaceNumber = RAW_INTERFACE,
  833. .bAlternateSetting = 0x00,
  834. .bNumEndpoints = 2,
  835. .bInterfaceClass = 0x03,
  836. .bInterfaceSubClass = 0x00,
  837. .bInterfaceProtocol = 0x00,
  838. .iInterface = 0x00
  839. },
  840. .rawHID = {
  841. .header = {
  842. .bLength = sizeof(usbHIDDescriptor_t),
  843. .bDescriptorType = USBDESCR_HID
  844. },
  845. .bcdHID = 0x0101,
  846. .bCountryCode = 0x00,
  847. .bNumDescriptors = 1,
  848. .bDescriptorType = USBDESCR_HID_REPORT,
  849. .wDescriptorLength = sizeof(raw_hid_report)
  850. },
  851. .rawINEndpoint = {
  852. .header = {
  853. .bLength = sizeof(usbEndpointDescriptor_t),
  854. .bDescriptorType = USBDESCR_ENDPOINT
  855. },
  856. .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP4_NUMBER),
  857. .bmAttributes = 0x03,
  858. .wMaxPacketSize = RAW_EPSIZE,
  859. .bInterval = USB_POLLING_INTERVAL_MS
  860. },
  861. .rawOUTEndpoint = {
  862. .header = {
  863. .bLength = sizeof(usbEndpointDescriptor_t),
  864. .bDescriptorType = USBDESCR_ENDPOINT
  865. },
  866. .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP4_NUMBER),
  867. .bmAttributes = 0x03,
  868. .wMaxPacketSize = RAW_EPSIZE,
  869. .bInterval = USB_POLLING_INTERVAL_MS
  870. },
  871. # endif
  872. # ifdef SHARED_EP_ENABLE
  873. /*
  874. * Shared
  875. */
  876. .sharedInterface = {
  877. .header = {
  878. .bLength = sizeof(usbInterfaceDescriptor_t),
  879. .bDescriptorType = USBDESCR_INTERFACE
  880. },
  881. .bInterfaceNumber = SHARED_INTERFACE,
  882. .bAlternateSetting = 0x00,
  883. .bNumEndpoints = 1,
  884. .bInterfaceClass = 0x03,
  885. # ifdef KEYBOARD_SHARED_EP
  886. .bInterfaceSubClass = 0x01,
  887. .bInterfaceProtocol = 0x01,
  888. # else
  889. .bInterfaceSubClass = 0x00,
  890. .bInterfaceProtocol = 0x00,
  891. # endif
  892. .iInterface = 0x00
  893. },
  894. .sharedHID = {
  895. .header = {
  896. .bLength = sizeof(usbHIDDescriptor_t),
  897. .bDescriptorType = USBDESCR_HID
  898. },
  899. .bcdHID = 0x0101,
  900. .bCountryCode = 0x00,
  901. .bNumDescriptors = 1,
  902. .bDescriptorType = USBDESCR_HID_REPORT,
  903. .wDescriptorLength = sizeof(shared_hid_report)
  904. },
  905. .sharedINEndpoint = {
  906. .header = {
  907. .bLength = sizeof(usbEndpointDescriptor_t),
  908. .bDescriptorType = USBDESCR_ENDPOINT
  909. },
  910. # ifdef KEYBOARD_SHARED_EP
  911. .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | 1),
  912. # else
  913. .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
  914. # endif
  915. .bmAttributes = 0x03,
  916. .wMaxPacketSize = 8,
  917. .bInterval = USB_POLLING_INTERVAL_MS
  918. },
  919. # endif
  920. # if defined(CONSOLE_ENABLE)
  921. /*
  922. * Console
  923. */
  924. .consoleInterface = {
  925. .header = {
  926. .bLength = sizeof(usbInterfaceDescriptor_t),
  927. .bDescriptorType = USBDESCR_INTERFACE
  928. },
  929. .bInterfaceNumber = CONSOLE_INTERFACE,
  930. .bAlternateSetting = 0x00,
  931. .bNumEndpoints = 2,
  932. .bInterfaceClass = 0x03,
  933. .bInterfaceSubClass = 0x00,
  934. .bInterfaceProtocol = 0x00,
  935. .iInterface = 0x00
  936. },
  937. .consoleHID = {
  938. .header = {
  939. .bLength = sizeof(usbHIDDescriptor_t),
  940. .bDescriptorType = USBDESCR_HID
  941. },
  942. .bcdHID = 0x0111,
  943. .bCountryCode = 0x00,
  944. .bNumDescriptors = 1,
  945. .bDescriptorType = USBDESCR_HID_REPORT,
  946. .wDescriptorLength = sizeof(console_hid_report)
  947. },
  948. .consoleINEndpoint = {
  949. .header = {
  950. .bLength = sizeof(usbEndpointDescriptor_t),
  951. .bDescriptorType = USBDESCR_ENDPOINT
  952. },
  953. .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
  954. .bmAttributes = 0x03,
  955. .wMaxPacketSize = CONSOLE_EPSIZE,
  956. .bInterval = 0x01
  957. },
  958. # endif
  959. };
  960. // clang-format on
  961. USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
  962. usbMsgLen_t len = 0;
  963. switch (rq->wValue.bytes[1]) {
  964. case USBDESCR_DEVICE:
  965. usbMsgPtr = (usbMsgPtr_t)&usbDeviceDescriptor;
  966. len = sizeof(usbDeviceDescriptor_t);
  967. break;
  968. case USBDESCR_CONFIG:
  969. usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor;
  970. len = sizeof(usbConfigurationDescriptor_t);
  971. break;
  972. case USBDESCR_STRING:
  973. switch (rq->wValue.bytes[0]) {
  974. case 0:
  975. usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorZero;
  976. len = usbStringDescriptorZero.header.bLength;
  977. break;
  978. case 1: // iManufacturer
  979. usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorManufacturer;
  980. len = usbStringDescriptorManufacturer.header.bLength;
  981. break;
  982. case 2: // iProduct
  983. usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorProduct;
  984. len = usbStringDescriptorProduct.header.bLength;
  985. break;
  986. #if defined(SERIAL_NUMBER)
  987. case 3: // iSerialNumber
  988. usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorSerial;
  989. len = usbStringDescriptorSerial.header.bLength;
  990. break;
  991. #endif
  992. }
  993. #ifdef OS_DETECTION_ENABLE
  994. process_wlength(rq->wLength.word);
  995. #endif
  996. break;
  997. case USBDESCR_HID:
  998. switch (rq->wIndex.word) {
  999. #ifndef KEYBOARD_SHARED_EP
  1000. case KEYBOARD_INTERFACE:
  1001. usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.keyboardHID;
  1002. len = sizeof(usbHIDDescriptor_t);
  1003. break;
  1004. #endif
  1005. #if defined(RAW_ENABLE)
  1006. case RAW_INTERFACE:
  1007. usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.rawHID;
  1008. len = sizeof(usbHIDDescriptor_t);
  1009. break;
  1010. #endif
  1011. #ifdef SHARED_EP_ENABLE
  1012. case SHARED_INTERFACE:
  1013. usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.sharedHID;
  1014. len = sizeof(usbHIDDescriptor_t);
  1015. break;
  1016. #endif
  1017. #if defined(CONSOLE_ENABLE)
  1018. case CONSOLE_INTERFACE:
  1019. usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.consoleHID;
  1020. len = sizeof(usbHIDDescriptor_t);
  1021. break;
  1022. #endif
  1023. }
  1024. break;
  1025. case USBDESCR_HID_REPORT:
  1026. /* interface index */
  1027. switch (rq->wIndex.word) {
  1028. #ifndef KEYBOARD_SHARED_EP
  1029. case KEYBOARD_INTERFACE:
  1030. usbMsgPtr = (usbMsgPtr_t)keyboard_hid_report;
  1031. len = sizeof(keyboard_hid_report);
  1032. break;
  1033. #endif
  1034. #if defined(RAW_ENABLE)
  1035. case RAW_INTERFACE:
  1036. usbMsgPtr = (usbMsgPtr_t)raw_hid_report;
  1037. len = sizeof(raw_hid_report);
  1038. break;
  1039. #endif
  1040. #ifdef SHARED_EP_ENABLE
  1041. case SHARED_INTERFACE:
  1042. usbMsgPtr = (usbMsgPtr_t)shared_hid_report;
  1043. len = sizeof(shared_hid_report);
  1044. break;
  1045. #endif
  1046. #if defined(CONSOLE_ENABLE)
  1047. case CONSOLE_INTERFACE:
  1048. usbMsgPtr = (usbMsgPtr_t)console_hid_report;
  1049. len = sizeof(console_hid_report);
  1050. break;
  1051. #endif
  1052. }
  1053. break;
  1054. }
  1055. return len;
  1056. }