vusb.c 37 KB

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