Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

1600 lines
74KB

  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2017 PJRC.COM, LLC.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * 1. The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * 2. If the Software is incorporated into a build system that allows
  17. * selection among a list of target devices, then similar target
  18. * devices manufactured by PJRC.COM must be included in the list of
  19. * target devices and selectable in the same manner.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  25. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  26. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  27. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. */
  30. //#if F_CPU >= 20000000
  31. #define USB_DESC_LIST_DEFINE
  32. #include "usb_desc.h"
  33. #ifdef NUM_ENDPOINTS
  34. #include "usb_names.h"
  35. #include "imxrt.h"
  36. #include "avr_functions.h"
  37. // USB Descriptors are binary data which the USB host reads to
  38. // automatically detect a USB device's capabilities. The format
  39. // and meaning of every field is documented in numerous USB
  40. // standards. When working with USB descriptors, despite the
  41. // complexity of the standards and poor writing quality in many
  42. // of those documents, remember descriptors are nothing more
  43. // than constant binary data that tells the USB host what the
  44. // device can do. Computers will load drivers based on this data.
  45. // Those drivers then communicate on the endpoints specified by
  46. // the descriptors.
  47. // To configure a new combination of interfaces or make minor
  48. // changes to existing configuration (eg, change the name or ID
  49. // numbers), usually you would edit "usb_desc.h". This file
  50. // is meant to be configured by the header, so generally it is
  51. // only edited to add completely new USB interfaces or features.
  52. // **************************************************************
  53. // USB Device
  54. // **************************************************************
  55. #define LSB(n) ((n) & 255)
  56. #define MSB(n) (((n) >> 8) & 255)
  57. // USB Device Descriptor. The USB host reads this first, to learn
  58. // what type of device is connected.
  59. static uint8_t device_descriptor[] = {
  60. 18, // bLength
  61. 1, // bDescriptorType
  62. 0x10, 0x01, // bcdUSB
  63. #ifdef DEVICE_CLASS
  64. DEVICE_CLASS, // bDeviceClass
  65. #else
  66. 0,
  67. #endif
  68. #ifdef DEVICE_SUBCLASS
  69. DEVICE_SUBCLASS, // bDeviceSubClass
  70. #else
  71. 0,
  72. #endif
  73. #ifdef DEVICE_PROTOCOL
  74. DEVICE_PROTOCOL, // bDeviceProtocol
  75. #else
  76. 0,
  77. #endif
  78. EP0_SIZE, // bMaxPacketSize0
  79. LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
  80. LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct
  81. #ifdef BCD_DEVICE
  82. LSB(BCD_DEVICE), MSB(BCD_DEVICE), // bcdDevice
  83. #else
  84. // For USB types that don't explicitly define BCD_DEVICE,
  85. // use the minor version number to help teensy_ports
  86. // identify which Teensy model is used.
  87. #if defined(__MKL26Z64__)
  88. 0x73, 0x02,
  89. #elif defined(__MK20DX128__)
  90. 0x74, 0x02,
  91. #elif defined(__MK20DX256__)
  92. 0x75, 0x02,
  93. #elif defined(__MK64FX512__)
  94. 0x76, 0x02,
  95. #elif defined(__MK66FX1M0__)
  96. 0x77, 0x02,
  97. #elif defined(__IMXRT1052__)
  98. 0x78, 0x02, // Teensy 4.0 Beta #1
  99. #else
  100. 0x79, 0x02, // Teensy 4.0 Beta #2
  101. //0x00, 0x02,
  102. #endif
  103. #endif
  104. 1, // iManufacturer
  105. 2, // iProduct
  106. 3, // iSerialNumber
  107. 1 // bNumConfigurations
  108. };
  109. // These descriptors must NOT be "const", because the USB DMA
  110. // has trouble accessing flash memory with enough bandwidth
  111. // while the processor is executing from flash.
  112. // **************************************************************
  113. // HID Report Descriptors
  114. // **************************************************************
  115. // Each HID interface needs a special report descriptor that tells
  116. // the meaning and format of the data.
  117. #ifdef KEYBOARD_INTERFACE
  118. // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
  119. static uint8_t keyboard_report_desc[] = {
  120. 0x05, 0x01, // Usage Page (Generic Desktop),
  121. 0x09, 0x06, // Usage (Keyboard),
  122. 0xA1, 0x01, // Collection (Application),
  123. 0x75, 0x01, // Report Size (1),
  124. 0x95, 0x08, // Report Count (8),
  125. 0x05, 0x07, // Usage Page (Key Codes),
  126. 0x19, 0xE0, // Usage Minimum (224),
  127. 0x29, 0xE7, // Usage Maximum (231),
  128. 0x15, 0x00, // Logical Minimum (0),
  129. 0x25, 0x01, // Logical Maximum (1),
  130. 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier keys
  131. 0x95, 0x01, // Report Count (1),
  132. 0x75, 0x08, // Report Size (8),
  133. 0x81, 0x03, // Input (Constant), ;Reserved byte
  134. 0x95, 0x05, // Report Count (5),
  135. 0x75, 0x01, // Report Size (1),
  136. 0x05, 0x08, // Usage Page (LEDs),
  137. 0x19, 0x01, // Usage Minimum (1),
  138. 0x29, 0x05, // Usage Maximum (5),
  139. 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
  140. 0x95, 0x01, // Report Count (1),
  141. 0x75, 0x03, // Report Size (3),
  142. 0x91, 0x03, // Output (Constant), ;LED report padding
  143. 0x95, 0x06, // Report Count (6),
  144. 0x75, 0x08, // Report Size (8),
  145. 0x15, 0x00, // Logical Minimum (0),
  146. 0x25, 0x7F, // Logical Maximum(104),
  147. 0x05, 0x07, // Usage Page (Key Codes),
  148. 0x19, 0x00, // Usage Minimum (0),
  149. 0x29, 0x7F, // Usage Maximum (104),
  150. 0x81, 0x00, // Input (Data, Array), ;Normal keys
  151. 0xC0 // End Collection
  152. };
  153. #endif
  154. #ifdef KEYMEDIA_INTERFACE
  155. static uint8_t keymedia_report_desc[] = {
  156. 0x05, 0x0C, // Usage Page (Consumer)
  157. 0x09, 0x01, // Usage (Consumer Controls)
  158. 0xA1, 0x01, // Collection (Application)
  159. 0x75, 0x0A, // Report Size (10)
  160. 0x95, 0x04, // Report Count (4)
  161. 0x19, 0x00, // Usage Minimum (0)
  162. 0x2A, 0x9C, 0x02, // Usage Maximum (0x29C)
  163. 0x15, 0x00, // Logical Minimum (0)
  164. 0x26, 0x9C, 0x02, // Logical Maximum (0x29C)
  165. 0x81, 0x00, // Input (Data, Array)
  166. 0x05, 0x01, // Usage Page (Generic Desktop)
  167. 0x75, 0x08, // Report Size (8)
  168. 0x95, 0x03, // Report Count (3)
  169. 0x19, 0x00, // Usage Minimum (0)
  170. 0x29, 0xB7, // Usage Maximum (0xB7)
  171. 0x15, 0x00, // Logical Minimum (0)
  172. 0x26, 0xB7, 0x00, // Logical Maximum (0xB7)
  173. 0x81, 0x00, // Input (Data, Array)
  174. 0xC0 // End Collection
  175. };
  176. #endif
  177. #ifdef MOUSE_INTERFACE
  178. // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
  179. static uint8_t mouse_report_desc[] = {
  180. 0x05, 0x01, // Usage Page (Generic Desktop)
  181. 0x09, 0x02, // Usage (Mouse)
  182. 0xA1, 0x01, // Collection (Application)
  183. 0x85, 0x01, // REPORT_ID (1)
  184. 0x05, 0x09, // Usage Page (Button)
  185. 0x19, 0x01, // Usage Minimum (Button #1)
  186. 0x29, 0x08, // Usage Maximum (Button #8)
  187. 0x15, 0x00, // Logical Minimum (0)
  188. 0x25, 0x01, // Logical Maximum (1)
  189. 0x95, 0x08, // Report Count (8)
  190. 0x75, 0x01, // Report Size (1)
  191. 0x81, 0x02, // Input (Data, Variable, Absolute)
  192. 0x05, 0x01, // Usage Page (Generic Desktop)
  193. 0x09, 0x30, // Usage (X)
  194. 0x09, 0x31, // Usage (Y)
  195. 0x09, 0x38, // Usage (Wheel)
  196. 0x15, 0x81, // Logical Minimum (-127)
  197. 0x25, 0x7F, // Logical Maximum (127)
  198. 0x75, 0x08, // Report Size (8),
  199. 0x95, 0x03, // Report Count (3),
  200. 0x81, 0x06, // Input (Data, Variable, Relative)
  201. 0x05, 0x0C, // Usage Page (Consumer)
  202. 0x0A, 0x38, 0x02, // Usage (AC Pan)
  203. 0x15, 0x81, // Logical Minimum (-127)
  204. 0x25, 0x7F, // Logical Maximum (127)
  205. 0x75, 0x08, // Report Size (8),
  206. 0x95, 0x01, // Report Count (1),
  207. 0x81, 0x06, // Input (Data, Variable, Relative)
  208. 0xC0, // End Collection
  209. 0x05, 0x01, // Usage Page (Generic Desktop)
  210. 0x09, 0x02, // Usage (Mouse)
  211. 0xA1, 0x01, // Collection (Application)
  212. 0x85, 0x02, // REPORT_ID (2)
  213. 0x05, 0x01, // Usage Page (Generic Desktop)
  214. 0x09, 0x30, // Usage (X)
  215. 0x09, 0x31, // Usage (Y)
  216. 0x15, 0x00, // Logical Minimum (0)
  217. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  218. 0x75, 0x10, // Report Size (16),
  219. 0x95, 0x02, // Report Count (2),
  220. 0x81, 0x02, // Input (Data, Variable, Absolute)
  221. 0xC0 // End Collection
  222. };
  223. #endif
  224. #ifdef JOYSTICK_INTERFACE
  225. #if JOYSTICK_SIZE == 12
  226. static uint8_t joystick_report_desc[] = {
  227. 0x05, 0x01, // Usage Page (Generic Desktop)
  228. 0x09, 0x04, // Usage (Joystick)
  229. 0xA1, 0x01, // Collection (Application)
  230. 0x15, 0x00, // Logical Minimum (0)
  231. 0x25, 0x01, // Logical Maximum (1)
  232. 0x75, 0x01, // Report Size (1)
  233. 0x95, 0x20, // Report Count (32)
  234. 0x05, 0x09, // Usage Page (Button)
  235. 0x19, 0x01, // Usage Minimum (Button #1)
  236. 0x29, 0x20, // Usage Maximum (Button #32)
  237. 0x81, 0x02, // Input (variable,absolute)
  238. 0x15, 0x00, // Logical Minimum (0)
  239. 0x25, 0x07, // Logical Maximum (7)
  240. 0x35, 0x00, // Physical Minimum (0)
  241. 0x46, 0x3B, 0x01, // Physical Maximum (315)
  242. 0x75, 0x04, // Report Size (4)
  243. 0x95, 0x01, // Report Count (1)
  244. 0x65, 0x14, // Unit (20)
  245. 0x05, 0x01, // Usage Page (Generic Desktop)
  246. 0x09, 0x39, // Usage (Hat switch)
  247. 0x81, 0x42, // Input (variable,absolute,null_state)
  248. 0x05, 0x01, // Usage Page (Generic Desktop)
  249. 0x09, 0x01, // Usage (Pointer)
  250. 0xA1, 0x00, // Collection ()
  251. 0x15, 0x00, // Logical Minimum (0)
  252. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  253. 0x75, 0x0A, // Report Size (10)
  254. 0x95, 0x04, // Report Count (4)
  255. 0x09, 0x30, // Usage (X)
  256. 0x09, 0x31, // Usage (Y)
  257. 0x09, 0x32, // Usage (Z)
  258. 0x09, 0x35, // Usage (Rz)
  259. 0x81, 0x02, // Input (variable,absolute)
  260. 0xC0, // End Collection
  261. 0x15, 0x00, // Logical Minimum (0)
  262. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  263. 0x75, 0x0A, // Report Size (10)
  264. 0x95, 0x02, // Report Count (2)
  265. 0x09, 0x36, // Usage (Slider)
  266. 0x09, 0x36, // Usage (Slider)
  267. 0x81, 0x02, // Input (variable,absolute)
  268. 0xC0 // End Collection
  269. };
  270. #elif JOYSTICK_SIZE == 64
  271. // extreme joystick (to use this, edit JOYSTICK_SIZE to 64 in usb_desc.h)
  272. // 128 buttons 16
  273. // 6 axes 12
  274. // 17 sliders 34
  275. // 4 pov 2
  276. static uint8_t joystick_report_desc[] = {
  277. 0x05, 0x01, // Usage Page (Generic Desktop)
  278. 0x09, 0x04, // Usage (Joystick)
  279. 0xA1, 0x01, // Collection (Application)
  280. 0x15, 0x00, // Logical Minimum (0)
  281. 0x25, 0x01, // Logical Maximum (1)
  282. 0x75, 0x01, // Report Size (1)
  283. 0x95, 0x80, // Report Count (128)
  284. 0x05, 0x09, // Usage Page (Button)
  285. 0x19, 0x01, // Usage Minimum (Button #1)
  286. 0x29, 0x80, // Usage Maximum (Button #128)
  287. 0x81, 0x02, // Input (variable,absolute)
  288. 0x05, 0x01, // Usage Page (Generic Desktop)
  289. 0x09, 0x01, // Usage (Pointer)
  290. 0xA1, 0x00, // Collection ()
  291. 0x15, 0x00, // Logical Minimum (0)
  292. 0x27, 0xFF, 0xFF, 0, 0, // Logical Maximum (65535)
  293. 0x75, 0x10, // Report Size (16)
  294. 0x95, 23, // Report Count (23)
  295. 0x09, 0x30, // Usage (X)
  296. 0x09, 0x31, // Usage (Y)
  297. 0x09, 0x32, // Usage (Z)
  298. 0x09, 0x33, // Usage (Rx)
  299. 0x09, 0x34, // Usage (Ry)
  300. 0x09, 0x35, // Usage (Rz)
  301. 0x09, 0x36, // Usage (Slider)
  302. 0x09, 0x36, // Usage (Slider)
  303. 0x09, 0x36, // Usage (Slider)
  304. 0x09, 0x36, // Usage (Slider)
  305. 0x09, 0x36, // Usage (Slider)
  306. 0x09, 0x36, // Usage (Slider)
  307. 0x09, 0x36, // Usage (Slider)
  308. 0x09, 0x36, // Usage (Slider)
  309. 0x09, 0x36, // Usage (Slider)
  310. 0x09, 0x36, // Usage (Slider)
  311. 0x09, 0x36, // Usage (Slider)
  312. 0x09, 0x36, // Usage (Slider)
  313. 0x09, 0x36, // Usage (Slider)
  314. 0x09, 0x36, // Usage (Slider)
  315. 0x09, 0x36, // Usage (Slider)
  316. 0x09, 0x36, // Usage (Slider)
  317. 0x09, 0x36, // Usage (Slider)
  318. 0x81, 0x02, // Input (variable,absolute)
  319. 0xC0, // End Collection
  320. 0x15, 0x00, // Logical Minimum (0)
  321. 0x25, 0x07, // Logical Maximum (7)
  322. 0x35, 0x00, // Physical Minimum (0)
  323. 0x46, 0x3B, 0x01, // Physical Maximum (315)
  324. 0x75, 0x04, // Report Size (4)
  325. 0x95, 0x04, // Report Count (4)
  326. 0x65, 0x14, // Unit (20)
  327. 0x05, 0x01, // Usage Page (Generic Desktop)
  328. 0x09, 0x39, // Usage (Hat switch)
  329. 0x09, 0x39, // Usage (Hat switch)
  330. 0x09, 0x39, // Usage (Hat switch)
  331. 0x09, 0x39, // Usage (Hat switch)
  332. 0x81, 0x42, // Input (variable,absolute,null_state)
  333. 0xC0 // End Collection
  334. };
  335. #endif // JOYSTICK_SIZE
  336. #endif // JOYSTICK_INTERFACE
  337. #ifdef MULTITOUCH_INTERFACE
  338. // https://forum.pjrc.com/threads/32331-USB-HID-Touchscreen-support-needed
  339. // https://msdn.microsoft.com/en-us/library/windows/hardware/jj151563%28v=vs.85%29.aspx
  340. // https://msdn.microsoft.com/en-us/library/windows/hardware/jj151565%28v=vs.85%29.aspx
  341. // https://msdn.microsoft.com/en-us/library/windows/hardware/ff553734%28v=vs.85%29.aspx
  342. // https://msdn.microsoft.com/en-us/library/windows/hardware/jj151564%28v=vs.85%29.aspx
  343. // download.microsoft.com/download/a/d/f/adf1347d-08dc-41a4-9084-623b1194d4b2/digitizerdrvs_touch.docx
  344. static uint8_t multitouch_report_desc[] = {
  345. 0x05, 0x0D, // Usage Page (Digitizer)
  346. 0x09, 0x04, // Usage (Touch Screen)
  347. 0xa1, 0x01, // Collection (Application)
  348. 0x09, 0x22, // Usage (Finger)
  349. 0xA1, 0x02, // Collection (Logical)
  350. 0x09, 0x42, // Usage (Tip Switch)
  351. 0x15, 0x00, // Logical Minimum (0)
  352. 0x25, 0x01, // Logical Maximum (1)
  353. 0x75, 0x01, // Report Size (1)
  354. 0x95, 0x01, // Report Count (1)
  355. 0x81, 0x02, // Input (variable,absolute)
  356. 0x09, 0x51, // Usage (Contact Identifier)
  357. 0x25, 0x7F, // Logical Maximum (127)
  358. 0x75, 0x07, // Report Size (7)
  359. 0x95, 0x01, // Report Count (1)
  360. 0x81, 0x02, // Input (variable,absolute)
  361. 0x09, 0x30, // Usage (Pressure)
  362. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  363. 0x75, 0x08, // Report Size (8)
  364. 0x95, 0x01, // Report Count (1)
  365. 0x81, 0x02, // Input (variable,absolute)
  366. 0x05, 0x01, // Usage Page (Generic Desktop)
  367. 0x09, 0x30, // Usage (X)
  368. 0x09, 0x31, // Usage (Y)
  369. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  370. 0x65, 0x00, // Unit (None) <-- probably needs real units?
  371. 0x75, 0x10, // Report Size (16)
  372. 0x95, 0x02, // Report Count (2)
  373. 0x81, 0x02, // Input (variable,absolute)
  374. 0xC0, // End Collection
  375. 0x05, 0x0D, // Usage Page (Digitizer)
  376. 0x27, 0xFF, 0xFF, 0, 0, // Logical Maximum (65535)
  377. 0x75, 0x10, // Report Size (16)
  378. 0x95, 0x01, // Report Count (1)
  379. 0x09, 0x56, // Usage (Scan Time)
  380. 0x81, 0x02, // Input (variable,absolute)
  381. 0x05, 0x0D, // Usage Page (Digitizers)
  382. 0x09, 0x55, // Usage (Contact Count Maximum)
  383. 0x25, MULTITOUCH_FINGERS, // Logical Maximum (10)
  384. 0x75, 0x08, // Report Size (8)
  385. 0x95, 0x01, // Report Count (1)
  386. 0xB1, 0x02, // Feature (variable,absolute)
  387. 0xC0 // End Collection
  388. };
  389. #endif
  390. #ifdef SEREMU_INTERFACE
  391. static uint8_t seremu_report_desc[] = {
  392. 0x06, 0xC9, 0xFF, // Usage Page 0xFFC9 (vendor defined)
  393. 0x09, 0x04, // Usage 0x04
  394. 0xA1, 0x5C, // Collection 0x5C
  395. 0x75, 0x08, // report size = 8 bits (global)
  396. 0x15, 0x00, // logical minimum = 0 (global)
  397. 0x26, 0xFF, 0x00, // logical maximum = 255 (global)
  398. 0x95, SEREMU_TX_SIZE, // report count (global)
  399. 0x09, 0x75, // usage (local)
  400. 0x81, 0x02, // Input
  401. 0x95, SEREMU_RX_SIZE, // report count (global)
  402. 0x09, 0x76, // usage (local)
  403. 0x91, 0x02, // Output
  404. 0x95, 0x04, // report count (global)
  405. 0x09, 0x76, // usage (local)
  406. 0xB1, 0x02, // Feature
  407. 0xC0 // end collection
  408. };
  409. #endif
  410. #ifdef RAWHID_INTERFACE
  411. static uint8_t rawhid_report_desc[] = {
  412. 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),
  413. 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
  414. 0xA1, 0x01, // Collection 0x01
  415. 0x75, 0x08, // report size = 8 bits
  416. 0x15, 0x00, // logical minimum = 0
  417. 0x26, 0xFF, 0x00, // logical maximum = 255
  418. 0x95, RAWHID_TX_SIZE, // report count
  419. 0x09, 0x01, // usage
  420. 0x81, 0x02, // Input (array)
  421. 0x95, RAWHID_RX_SIZE, // report count
  422. 0x09, 0x02, // usage
  423. 0x91, 0x02, // Output (array)
  424. 0xC0 // end collection
  425. };
  426. #endif
  427. #ifdef FLIGHTSIM_INTERFACE
  428. static uint8_t flightsim_report_desc[] = {
  429. 0x06, 0x1C, 0xFF, // Usage page = 0xFF1C
  430. 0x0A, 0x39, 0xA7, // Usage = 0xA739
  431. 0xA1, 0x01, // Collection 0x01
  432. 0x75, 0x08, // report size = 8 bits
  433. 0x15, 0x00, // logical minimum = 0
  434. 0x26, 0xFF, 0x00, // logical maximum = 255
  435. 0x95, FLIGHTSIM_TX_SIZE, // report count
  436. 0x09, 0x01, // usage
  437. 0x81, 0x02, // Input (array)
  438. 0x95, FLIGHTSIM_RX_SIZE, // report count
  439. 0x09, 0x02, // usage
  440. 0x91, 0x02, // Output (array)
  441. 0xC0 // end collection
  442. };
  443. #endif
  444. // **************************************************************
  445. // USB Descriptor Sizes
  446. // **************************************************************
  447. // pre-compute the size and position of everything in the config descriptor
  448. //
  449. #define CONFIG_HEADER_DESCRIPTOR_SIZE 9
  450. #define CDC_IAD_DESCRIPTOR_POS CONFIG_HEADER_DESCRIPTOR_SIZE
  451. #ifdef CDC_IAD_DESCRIPTOR
  452. #define CDC_IAD_DESCRIPTOR_SIZE 8
  453. #else
  454. #define CDC_IAD_DESCRIPTOR_SIZE 0
  455. #endif
  456. #define CDC_DATA_INTERFACE_DESC_POS CDC_IAD_DESCRIPTOR_POS+CDC_IAD_DESCRIPTOR_SIZE
  457. #ifdef CDC_DATA_INTERFACE
  458. #define CDC_DATA_INTERFACE_DESC_SIZE 9+5+5+4+5+7+9+7+7
  459. #else
  460. #define CDC_DATA_INTERFACE_DESC_SIZE 0
  461. #endif
  462. #define MIDI_INTERFACE_DESC_POS CDC_DATA_INTERFACE_DESC_POS+CDC_DATA_INTERFACE_DESC_SIZE
  463. #ifdef MIDI_INTERFACE
  464. #if !defined(MIDI_NUM_CABLES) || MIDI_NUM_CABLES < 1 || MIDI_NUM_CABLES > 16
  465. #error "MIDI_NUM_CABLES must be defined between 1 to 16"
  466. #endif
  467. #define MIDI_INTERFACE_DESC_SIZE 9+7+((6+6+9+9)*MIDI_NUM_CABLES)+(9+4+MIDI_NUM_CABLES)*2
  468. #else
  469. #define MIDI_INTERFACE_DESC_SIZE 0
  470. #endif
  471. #define KEYBOARD_INTERFACE_DESC_POS MIDI_INTERFACE_DESC_POS+MIDI_INTERFACE_DESC_SIZE
  472. #ifdef KEYBOARD_INTERFACE
  473. #define KEYBOARD_INTERFACE_DESC_SIZE 9+9+7
  474. #define KEYBOARD_HID_DESC_OFFSET KEYBOARD_INTERFACE_DESC_POS+9
  475. #else
  476. #define KEYBOARD_INTERFACE_DESC_SIZE 0
  477. #endif
  478. #define MOUSE_INTERFACE_DESC_POS KEYBOARD_INTERFACE_DESC_POS+KEYBOARD_INTERFACE_DESC_SIZE
  479. #ifdef MOUSE_INTERFACE
  480. #define MOUSE_INTERFACE_DESC_SIZE 9+9+7
  481. #define MOUSE_HID_DESC_OFFSET MOUSE_INTERFACE_DESC_POS+9
  482. #else
  483. #define MOUSE_INTERFACE_DESC_SIZE 0
  484. #endif
  485. #define RAWHID_INTERFACE_DESC_POS MOUSE_INTERFACE_DESC_POS+MOUSE_INTERFACE_DESC_SIZE
  486. #ifdef RAWHID_INTERFACE
  487. #define RAWHID_INTERFACE_DESC_SIZE 9+9+7+7
  488. #define RAWHID_HID_DESC_OFFSET RAWHID_INTERFACE_DESC_POS+9
  489. #else
  490. #define RAWHID_INTERFACE_DESC_SIZE 0
  491. #endif
  492. #define FLIGHTSIM_INTERFACE_DESC_POS RAWHID_INTERFACE_DESC_POS+RAWHID_INTERFACE_DESC_SIZE
  493. #ifdef FLIGHTSIM_INTERFACE
  494. #define FLIGHTSIM_INTERFACE_DESC_SIZE 9+9+7+7
  495. #define FLIGHTSIM_HID_DESC_OFFSET FLIGHTSIM_INTERFACE_DESC_POS+9
  496. #else
  497. #define FLIGHTSIM_INTERFACE_DESC_SIZE 0
  498. #endif
  499. #define SEREMU_INTERFACE_DESC_POS FLIGHTSIM_INTERFACE_DESC_POS+FLIGHTSIM_INTERFACE_DESC_SIZE
  500. #ifdef SEREMU_INTERFACE
  501. #define SEREMU_INTERFACE_DESC_SIZE 9+9+7+7
  502. #define SEREMU_HID_DESC_OFFSET SEREMU_INTERFACE_DESC_POS+9
  503. #else
  504. #define SEREMU_INTERFACE_DESC_SIZE 0
  505. #endif
  506. #define JOYSTICK_INTERFACE_DESC_POS SEREMU_INTERFACE_DESC_POS+SEREMU_INTERFACE_DESC_SIZE
  507. #ifdef JOYSTICK_INTERFACE
  508. #define JOYSTICK_INTERFACE_DESC_SIZE 9+9+7
  509. #define JOYSTICK_HID_DESC_OFFSET JOYSTICK_INTERFACE_DESC_POS+9
  510. #else
  511. #define JOYSTICK_INTERFACE_DESC_SIZE 0
  512. #endif
  513. #define MTP_INTERFACE_DESC_POS JOYSTICK_INTERFACE_DESC_POS+JOYSTICK_INTERFACE_DESC_SIZE
  514. #ifdef MTP_INTERFACE
  515. #define MTP_INTERFACE_DESC_SIZE 9+7+7+7
  516. #else
  517. #define MTP_INTERFACE_DESC_SIZE 0
  518. #endif
  519. #define KEYMEDIA_INTERFACE_DESC_POS MTP_INTERFACE_DESC_POS+MTP_INTERFACE_DESC_SIZE
  520. #ifdef KEYMEDIA_INTERFACE
  521. #define KEYMEDIA_INTERFACE_DESC_SIZE 9+9+7
  522. #define KEYMEDIA_HID_DESC_OFFSET KEYMEDIA_INTERFACE_DESC_POS+9
  523. #else
  524. #define KEYMEDIA_INTERFACE_DESC_SIZE 0
  525. #endif
  526. #define AUDIO_INTERFACE_DESC_POS KEYMEDIA_INTERFACE_DESC_POS+KEYMEDIA_INTERFACE_DESC_SIZE
  527. #ifdef AUDIO_INTERFACE
  528. #define AUDIO_INTERFACE_DESC_SIZE 8 + 9+10+12+9+12+10+9 + 9+9+7+11+9+7 + 9+9+7+11+9+7+9
  529. #else
  530. #define AUDIO_INTERFACE_DESC_SIZE 0
  531. #endif
  532. #define MULTITOUCH_INTERFACE_DESC_POS AUDIO_INTERFACE_DESC_POS+AUDIO_INTERFACE_DESC_SIZE
  533. #ifdef MULTITOUCH_INTERFACE
  534. #define MULTITOUCH_INTERFACE_DESC_SIZE 9+9+7
  535. #define MULTITOUCH_HID_DESC_OFFSET MULTITOUCH_INTERFACE_DESC_POS+9
  536. #else
  537. #define MULTITOUCH_INTERFACE_DESC_SIZE 0
  538. #endif
  539. #define CONFIG_DESC_SIZE MULTITOUCH_INTERFACE_DESC_POS+MULTITOUCH_INTERFACE_DESC_SIZE
  540. // **************************************************************
  541. // USB Configuration
  542. // **************************************************************
  543. // USB Configuration Descriptor. This huge descriptor tells all
  544. // of the devices capbilities.
  545. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  546. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  547. 9, // bLength;
  548. 2, // bDescriptorType;
  549. LSB(CONFIG_DESC_SIZE), // wTotalLength
  550. MSB(CONFIG_DESC_SIZE),
  551. NUM_INTERFACE, // bNumInterfaces
  552. 1, // bConfigurationValue
  553. 0, // iConfiguration
  554. 0xC0, // bmAttributes
  555. 50, // bMaxPower
  556. #ifdef CDC_IAD_DESCRIPTOR
  557. // interface association descriptor, USB ECN, Table 9-Z
  558. 8, // bLength
  559. 11, // bDescriptorType
  560. CDC_STATUS_INTERFACE, // bFirstInterface
  561. 2, // bInterfaceCount
  562. 0x02, // bFunctionClass
  563. 0x02, // bFunctionSubClass
  564. 0x01, // bFunctionProtocol
  565. 4, // iFunction
  566. #endif
  567. #ifdef CDC_DATA_INTERFACE
  568. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  569. 9, // bLength
  570. 4, // bDescriptorType
  571. CDC_STATUS_INTERFACE, // bInterfaceNumber
  572. 0, // bAlternateSetting
  573. 1, // bNumEndpoints
  574. 0x02, // bInterfaceClass
  575. 0x02, // bInterfaceSubClass
  576. 0x01, // bInterfaceProtocol
  577. 0, // iInterface
  578. // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
  579. 5, // bFunctionLength
  580. 0x24, // bDescriptorType
  581. 0x00, // bDescriptorSubtype
  582. 0x10, 0x01, // bcdCDC
  583. // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
  584. 5, // bFunctionLength
  585. 0x24, // bDescriptorType
  586. 0x01, // bDescriptorSubtype
  587. 0x01, // bmCapabilities
  588. 1, // bDataInterface
  589. // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
  590. 4, // bFunctionLength
  591. 0x24, // bDescriptorType
  592. 0x02, // bDescriptorSubtype
  593. 0x06, // bmCapabilities
  594. // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
  595. 5, // bFunctionLength
  596. 0x24, // bDescriptorType
  597. 0x06, // bDescriptorSubtype
  598. CDC_STATUS_INTERFACE, // bMasterInterface
  599. CDC_DATA_INTERFACE, // bSlaveInterface0
  600. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  601. 7, // bLength
  602. 5, // bDescriptorType
  603. CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
  604. 0x03, // bmAttributes (0x03=intr)
  605. CDC_ACM_SIZE, 0, // wMaxPacketSize
  606. 64, // bInterval
  607. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  608. 9, // bLength
  609. 4, // bDescriptorType
  610. CDC_DATA_INTERFACE, // bInterfaceNumber
  611. 0, // bAlternateSetting
  612. 2, // bNumEndpoints
  613. 0x0A, // bInterfaceClass
  614. 0x00, // bInterfaceSubClass
  615. 0x00, // bInterfaceProtocol
  616. 0, // iInterface
  617. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  618. 7, // bLength
  619. 5, // bDescriptorType
  620. CDC_RX_ENDPOINT, // bEndpointAddress
  621. 0x02, // bmAttributes (0x02=bulk)
  622. CDC_RX_SIZE, 0, // wMaxPacketSize
  623. 0, // bInterval
  624. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  625. 7, // bLength
  626. 5, // bDescriptorType
  627. CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
  628. 0x02, // bmAttributes (0x02=bulk)
  629. CDC_TX_SIZE, 0, // wMaxPacketSize
  630. 0, // bInterval
  631. #endif // CDC_DATA_INTERFACE
  632. #ifdef MIDI_INTERFACE
  633. // Standard MS Interface Descriptor,
  634. 9, // bLength
  635. 4, // bDescriptorType
  636. MIDI_INTERFACE, // bInterfaceNumber
  637. 0, // bAlternateSetting
  638. 2, // bNumEndpoints
  639. 0x01, // bInterfaceClass (0x01 = Audio)
  640. 0x03, // bInterfaceSubClass (0x03 = MIDI)
  641. 0x00, // bInterfaceProtocol (unused for MIDI)
  642. 0, // iInterface
  643. // MIDI MS Interface Header, USB MIDI 6.1.2.1, page 21, Table 6-2
  644. 7, // bLength
  645. 0x24, // bDescriptorType = CS_INTERFACE
  646. 0x01, // bDescriptorSubtype = MS_HEADER
  647. 0x00, 0x01, // bcdMSC = revision 01.00
  648. LSB(7+(6+6+9+9)*MIDI_NUM_CABLES), // wTotalLength
  649. MSB(7+(6+6+9+9)*MIDI_NUM_CABLES),
  650. // MIDI IN Jack Descriptor, B.4.3, Table B-7 (embedded), page 40
  651. 6, // bLength
  652. 0x24, // bDescriptorType = CS_INTERFACE
  653. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  654. 0x01, // bJackType = EMBEDDED
  655. 1, // bJackID, ID = 1
  656. 0, // iJack
  657. // MIDI IN Jack Descriptor, B.4.3, Table B-8 (external), page 40
  658. 6, // bLength
  659. 0x24, // bDescriptorType = CS_INTERFACE
  660. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  661. 0x02, // bJackType = EXTERNAL
  662. 2, // bJackID, ID = 2
  663. 0, // iJack
  664. // MIDI OUT Jack Descriptor, B.4.4, Table B-9, page 41
  665. 9,
  666. 0x24, // bDescriptorType = CS_INTERFACE
  667. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  668. 0x01, // bJackType = EMBEDDED
  669. 3, // bJackID, ID = 3
  670. 1, // bNrInputPins = 1 pin
  671. 2, // BaSourceID(1) = 2
  672. 1, // BaSourcePin(1) = first pin
  673. 0, // iJack
  674. // MIDI OUT Jack Descriptor, B.4.4, Table B-10, page 41
  675. 9,
  676. 0x24, // bDescriptorType = CS_INTERFACE
  677. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  678. 0x02, // bJackType = EXTERNAL
  679. 4, // bJackID, ID = 4
  680. 1, // bNrInputPins = 1 pin
  681. 1, // BaSourceID(1) = 1
  682. 1, // BaSourcePin(1) = first pin
  683. 0, // iJack
  684. #if MIDI_NUM_CABLES >= 2
  685. #define MIDI_INTERFACE_JACK_PAIR(a, b, c, d) \
  686. 6, 0x24, 0x02, 0x01, (a), 0, \
  687. 6, 0x24, 0x02, 0x02, (b), 0, \
  688. 9, 0x24, 0x03, 0x01, (c), 1, (b), 1, 0, \
  689. 9, 0x24, 0x03, 0x02, (d), 1, (a), 1, 0,
  690. MIDI_INTERFACE_JACK_PAIR(5, 6, 7, 8)
  691. #endif
  692. #if MIDI_NUM_CABLES >= 3
  693. MIDI_INTERFACE_JACK_PAIR(9, 10, 11, 12)
  694. #endif
  695. #if MIDI_NUM_CABLES >= 4
  696. MIDI_INTERFACE_JACK_PAIR(13, 14, 15, 16)
  697. #endif
  698. #if MIDI_NUM_CABLES >= 5
  699. MIDI_INTERFACE_JACK_PAIR(17, 18, 19, 20)
  700. #endif
  701. #if MIDI_NUM_CABLES >= 6
  702. MIDI_INTERFACE_JACK_PAIR(21, 22, 23, 24)
  703. #endif
  704. #if MIDI_NUM_CABLES >= 7
  705. MIDI_INTERFACE_JACK_PAIR(25, 26, 27, 28)
  706. #endif
  707. #if MIDI_NUM_CABLES >= 8
  708. MIDI_INTERFACE_JACK_PAIR(29, 30, 31, 32)
  709. #endif
  710. #if MIDI_NUM_CABLES >= 9
  711. MIDI_INTERFACE_JACK_PAIR(33, 34, 35, 36)
  712. #endif
  713. #if MIDI_NUM_CABLES >= 10
  714. MIDI_INTERFACE_JACK_PAIR(37, 38, 39, 40)
  715. #endif
  716. #if MIDI_NUM_CABLES >= 11
  717. MIDI_INTERFACE_JACK_PAIR(41, 42, 43, 44)
  718. #endif
  719. #if MIDI_NUM_CABLES >= 12
  720. MIDI_INTERFACE_JACK_PAIR(45, 46, 47, 48)
  721. #endif
  722. #if MIDI_NUM_CABLES >= 13
  723. MIDI_INTERFACE_JACK_PAIR(49, 50, 51, 52)
  724. #endif
  725. #if MIDI_NUM_CABLES >= 14
  726. MIDI_INTERFACE_JACK_PAIR(53, 54, 55, 56)
  727. #endif
  728. #if MIDI_NUM_CABLES >= 15
  729. MIDI_INTERFACE_JACK_PAIR(57, 58, 59, 60)
  730. #endif
  731. #if MIDI_NUM_CABLES >= 16
  732. MIDI_INTERFACE_JACK_PAIR(61, 62, 63, 64)
  733. #endif
  734. // Standard Bulk OUT Endpoint Descriptor, B.5.1, Table B-11, pae 42
  735. 9, // bLength
  736. 5, // bDescriptorType = ENDPOINT
  737. MIDI_RX_ENDPOINT, // bEndpointAddress
  738. 0x02, // bmAttributes (0x02=bulk)
  739. MIDI_RX_SIZE, 0, // wMaxPacketSize
  740. 0, // bInterval
  741. 0, // bRefresh
  742. 0, // bSynchAddress
  743. // Class-specific MS Bulk OUT Endpoint Descriptor, B.5.2, Table B-12, page 42
  744. 4+MIDI_NUM_CABLES, // bLength
  745. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  746. 0x01, // bJackType = MS_GENERAL
  747. MIDI_NUM_CABLES, // bNumEmbMIDIJack = number of jacks
  748. 1, // BaAssocJackID(1) = jack ID #1
  749. #if MIDI_NUM_CABLES >= 2
  750. 5,
  751. #endif
  752. #if MIDI_NUM_CABLES >= 3
  753. 9,
  754. #endif
  755. #if MIDI_NUM_CABLES >= 4
  756. 13,
  757. #endif
  758. #if MIDI_NUM_CABLES >= 5
  759. 17,
  760. #endif
  761. #if MIDI_NUM_CABLES >= 6
  762. 21,
  763. #endif
  764. #if MIDI_NUM_CABLES >= 7
  765. 25,
  766. #endif
  767. #if MIDI_NUM_CABLES >= 8
  768. 29,
  769. #endif
  770. #if MIDI_NUM_CABLES >= 9
  771. 33,
  772. #endif
  773. #if MIDI_NUM_CABLES >= 10
  774. 37,
  775. #endif
  776. #if MIDI_NUM_CABLES >= 11
  777. 41,
  778. #endif
  779. #if MIDI_NUM_CABLES >= 12
  780. 45,
  781. #endif
  782. #if MIDI_NUM_CABLES >= 13
  783. 49,
  784. #endif
  785. #if MIDI_NUM_CABLES >= 14
  786. 53,
  787. #endif
  788. #if MIDI_NUM_CABLES >= 15
  789. 57,
  790. #endif
  791. #if MIDI_NUM_CABLES >= 16
  792. 61,
  793. #endif
  794. // Standard Bulk IN Endpoint Descriptor, B.5.1, Table B-11, pae 42
  795. 9, // bLength
  796. 5, // bDescriptorType = ENDPOINT
  797. MIDI_TX_ENDPOINT | 0x80, // bEndpointAddress
  798. 0x02, // bmAttributes (0x02=bulk)
  799. MIDI_TX_SIZE, 0, // wMaxPacketSize
  800. 0, // bInterval
  801. 0, // bRefresh
  802. 0, // bSynchAddress
  803. // Class-specific MS Bulk IN Endpoint Descriptor, B.5.2, Table B-12, page 42
  804. 4+MIDI_NUM_CABLES, // bLength
  805. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  806. 0x01, // bJackType = MS_GENERAL
  807. MIDI_NUM_CABLES, // bNumEmbMIDIJack = number of jacks
  808. 3, // BaAssocJackID(1) = jack ID #3
  809. #if MIDI_NUM_CABLES >= 2
  810. 7,
  811. #endif
  812. #if MIDI_NUM_CABLES >= 3
  813. 11,
  814. #endif
  815. #if MIDI_NUM_CABLES >= 4
  816. 15,
  817. #endif
  818. #if MIDI_NUM_CABLES >= 5
  819. 19,
  820. #endif
  821. #if MIDI_NUM_CABLES >= 6
  822. 23,
  823. #endif
  824. #if MIDI_NUM_CABLES >= 7
  825. 27,
  826. #endif
  827. #if MIDI_NUM_CABLES >= 8
  828. 31,
  829. #endif
  830. #if MIDI_NUM_CABLES >= 9
  831. 35,
  832. #endif
  833. #if MIDI_NUM_CABLES >= 10
  834. 39,
  835. #endif
  836. #if MIDI_NUM_CABLES >= 11
  837. 43,
  838. #endif
  839. #if MIDI_NUM_CABLES >= 12
  840. 47,
  841. #endif
  842. #if MIDI_NUM_CABLES >= 13
  843. 51,
  844. #endif
  845. #if MIDI_NUM_CABLES >= 14
  846. 55,
  847. #endif
  848. #if MIDI_NUM_CABLES >= 15
  849. 59,
  850. #endif
  851. #if MIDI_NUM_CABLES >= 16
  852. 63,
  853. #endif
  854. #endif // MIDI_INTERFACE
  855. #ifdef KEYBOARD_INTERFACE
  856. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  857. 9, // bLength
  858. 4, // bDescriptorType
  859. KEYBOARD_INTERFACE, // bInterfaceNumber
  860. 0, // bAlternateSetting
  861. 1, // bNumEndpoints
  862. 0x03, // bInterfaceClass (0x03 = HID)
  863. 0x01, // bInterfaceSubClass (0x01 = Boot)
  864. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  865. 0, // iInterface
  866. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  867. 9, // bLength
  868. 0x21, // bDescriptorType
  869. 0x11, 0x01, // bcdHID
  870. 0, // bCountryCode
  871. 1, // bNumDescriptors
  872. 0x22, // bDescriptorType
  873. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  874. MSB(sizeof(keyboard_report_desc)),
  875. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  876. 7, // bLength
  877. 5, // bDescriptorType
  878. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  879. 0x03, // bmAttributes (0x03=intr)
  880. KEYBOARD_SIZE, 0, // wMaxPacketSize
  881. KEYBOARD_INTERVAL, // bInterval
  882. #endif // KEYBOARD_INTERFACE
  883. #ifdef MOUSE_INTERFACE
  884. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  885. 9, // bLength
  886. 4, // bDescriptorType
  887. MOUSE_INTERFACE, // bInterfaceNumber
  888. 0, // bAlternateSetting
  889. 1, // bNumEndpoints
  890. 0x03, // bInterfaceClass (0x03 = HID)
  891. 0x00, // bInterfaceSubClass (0x01 = Boot)
  892. 0x00, // bInterfaceProtocol (0x02 = Mouse)
  893. 0, // iInterface
  894. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  895. 9, // bLength
  896. 0x21, // bDescriptorType
  897. 0x11, 0x01, // bcdHID
  898. 0, // bCountryCode
  899. 1, // bNumDescriptors
  900. 0x22, // bDescriptorType
  901. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  902. MSB(sizeof(mouse_report_desc)),
  903. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  904. 7, // bLength
  905. 5, // bDescriptorType
  906. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  907. 0x03, // bmAttributes (0x03=intr)
  908. MOUSE_SIZE, 0, // wMaxPacketSize
  909. MOUSE_INTERVAL, // bInterval
  910. #endif // MOUSE_INTERFACE
  911. #ifdef RAWHID_INTERFACE
  912. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  913. 9, // bLength
  914. 4, // bDescriptorType
  915. RAWHID_INTERFACE, // bInterfaceNumber
  916. 0, // bAlternateSetting
  917. 2, // bNumEndpoints
  918. 0x03, // bInterfaceClass (0x03 = HID)
  919. 0x00, // bInterfaceSubClass
  920. 0x00, // bInterfaceProtocol
  921. 0, // iInterface
  922. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  923. 9, // bLength
  924. 0x21, // bDescriptorType
  925. 0x11, 0x01, // bcdHID
  926. 0, // bCountryCode
  927. 1, // bNumDescriptors
  928. 0x22, // bDescriptorType
  929. LSB(sizeof(rawhid_report_desc)), // wDescriptorLength
  930. MSB(sizeof(rawhid_report_desc)),
  931. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  932. 7, // bLength
  933. 5, // bDescriptorType
  934. RAWHID_TX_ENDPOINT | 0x80, // bEndpointAddress
  935. 0x03, // bmAttributes (0x03=intr)
  936. RAWHID_TX_SIZE, 0, // wMaxPacketSize
  937. RAWHID_TX_INTERVAL, // bInterval
  938. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  939. 7, // bLength
  940. 5, // bDescriptorType
  941. RAWHID_RX_ENDPOINT, // bEndpointAddress
  942. 0x03, // bmAttributes (0x03=intr)
  943. RAWHID_RX_SIZE, 0, // wMaxPacketSize
  944. RAWHID_RX_INTERVAL, // bInterval
  945. #endif // RAWHID_INTERFACE
  946. #ifdef FLIGHTSIM_INTERFACE
  947. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  948. 9, // bLength
  949. 4, // bDescriptorType
  950. FLIGHTSIM_INTERFACE, // bInterfaceNumber
  951. 0, // bAlternateSetting
  952. 2, // bNumEndpoints
  953. 0x03, // bInterfaceClass (0x03 = HID)
  954. 0x00, // bInterfaceSubClass
  955. 0x00, // bInterfaceProtocol
  956. 0, // iInterface
  957. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  958. 9, // bLength
  959. 0x21, // bDescriptorType
  960. 0x11, 0x01, // bcdHID
  961. 0, // bCountryCode
  962. 1, // bNumDescriptors
  963. 0x22, // bDescriptorType
  964. LSB(sizeof(flightsim_report_desc)), // wDescriptorLength
  965. MSB(sizeof(flightsim_report_desc)),
  966. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  967. 7, // bLength
  968. 5, // bDescriptorType
  969. FLIGHTSIM_TX_ENDPOINT | 0x80, // bEndpointAddress
  970. 0x03, // bmAttributes (0x03=intr)
  971. FLIGHTSIM_TX_SIZE, 0, // wMaxPacketSize
  972. FLIGHTSIM_TX_INTERVAL, // bInterval
  973. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  974. 7, // bLength
  975. 5, // bDescriptorType
  976. FLIGHTSIM_RX_ENDPOINT, // bEndpointAddress
  977. 0x03, // bmAttributes (0x03=intr)
  978. FLIGHTSIM_RX_SIZE, 0, // wMaxPacketSize
  979. FLIGHTSIM_RX_INTERVAL, // bInterval
  980. #endif // FLIGHTSIM_INTERFACE
  981. #ifdef SEREMU_INTERFACE
  982. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  983. 9, // bLength
  984. 4, // bDescriptorType
  985. SEREMU_INTERFACE, // bInterfaceNumber
  986. 0, // bAlternateSetting
  987. 2, // bNumEndpoints
  988. 0x03, // bInterfaceClass (0x03 = HID)
  989. 0x00, // bInterfaceSubClass
  990. 0x00, // bInterfaceProtocol
  991. 0, // iInterface
  992. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  993. 9, // bLength
  994. 0x21, // bDescriptorType
  995. 0x11, 0x01, // bcdHID
  996. 0, // bCountryCode
  997. 1, // bNumDescriptors
  998. 0x22, // bDescriptorType
  999. LSB(sizeof(seremu_report_desc)), // wDescriptorLength
  1000. MSB(sizeof(seremu_report_desc)),
  1001. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1002. 7, // bLength
  1003. 5, // bDescriptorType
  1004. SEREMU_TX_ENDPOINT | 0x80, // bEndpointAddress
  1005. 0x03, // bmAttributes (0x03=intr)
  1006. SEREMU_TX_SIZE, 0, // wMaxPacketSize
  1007. SEREMU_TX_INTERVAL, // bInterval
  1008. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1009. 7, // bLength
  1010. 5, // bDescriptorType
  1011. SEREMU_RX_ENDPOINT, // bEndpointAddress
  1012. 0x03, // bmAttributes (0x03=intr)
  1013. SEREMU_RX_SIZE, 0, // wMaxPacketSize
  1014. SEREMU_RX_INTERVAL, // bInterval
  1015. #endif // SEREMU_INTERFACE
  1016. #ifdef JOYSTICK_INTERFACE
  1017. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1018. 9, // bLength
  1019. 4, // bDescriptorType
  1020. JOYSTICK_INTERFACE, // bInterfaceNumber
  1021. 0, // bAlternateSetting
  1022. 1, // bNumEndpoints
  1023. 0x03, // bInterfaceClass (0x03 = HID)
  1024. 0x00, // bInterfaceSubClass
  1025. 0x00, // bInterfaceProtocol
  1026. 0, // iInterface
  1027. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1028. 9, // bLength
  1029. 0x21, // bDescriptorType
  1030. 0x11, 0x01, // bcdHID
  1031. 0, // bCountryCode
  1032. 1, // bNumDescriptors
  1033. 0x22, // bDescriptorType
  1034. LSB(sizeof(joystick_report_desc)), // wDescriptorLength
  1035. MSB(sizeof(joystick_report_desc)),
  1036. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1037. 7, // bLength
  1038. 5, // bDescriptorType
  1039. JOYSTICK_ENDPOINT | 0x80, // bEndpointAddress
  1040. 0x03, // bmAttributes (0x03=intr)
  1041. JOYSTICK_SIZE, 0, // wMaxPacketSize
  1042. JOYSTICK_INTERVAL, // bInterval
  1043. #endif // JOYSTICK_INTERFACE
  1044. #ifdef MTP_INTERFACE
  1045. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1046. 9, // bLength
  1047. 4, // bDescriptorType
  1048. MTP_INTERFACE, // bInterfaceNumber
  1049. 0, // bAlternateSetting
  1050. 3, // bNumEndpoints
  1051. 0x06, // bInterfaceClass (0x06 = still image)
  1052. 0x01, // bInterfaceSubClass
  1053. 0x01, // bInterfaceProtocol
  1054. 4, // iInterface
  1055. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1056. 7, // bLength
  1057. 5, // bDescriptorType
  1058. MTP_TX_ENDPOINT | 0x80, // bEndpointAddress
  1059. 0x02, // bmAttributes (0x02=bulk)
  1060. MTP_TX_SIZE, 0, // wMaxPacketSize
  1061. 0, // bInterval
  1062. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1063. 7, // bLength
  1064. 5, // bDescriptorType
  1065. MTP_RX_ENDPOINT, // bEndpointAddress
  1066. 0x02, // bmAttributes (0x02=bulk)
  1067. MTP_RX_SIZE, 0, // wMaxPacketSize
  1068. 0, // bInterval
  1069. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1070. 7, // bLength
  1071. 5, // bDescriptorType
  1072. MTP_EVENT_ENDPOINT | 0x80, // bEndpointAddress
  1073. 0x03, // bmAttributes (0x03=intr)
  1074. MTP_EVENT_SIZE, 0, // wMaxPacketSize
  1075. MTP_EVENT_INTERVAL, // bInterval
  1076. #endif // MTP_INTERFACE
  1077. #ifdef KEYMEDIA_INTERFACE
  1078. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1079. 9, // bLength
  1080. 4, // bDescriptorType
  1081. KEYMEDIA_INTERFACE, // bInterfaceNumber
  1082. 0, // bAlternateSetting
  1083. 1, // bNumEndpoints
  1084. 0x03, // bInterfaceClass (0x03 = HID)
  1085. 0x00, // bInterfaceSubClass
  1086. 0x00, // bInterfaceProtocol
  1087. 0, // iInterface
  1088. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1089. 9, // bLength
  1090. 0x21, // bDescriptorType
  1091. 0x11, 0x01, // bcdHID
  1092. 0, // bCountryCode
  1093. 1, // bNumDescriptors
  1094. 0x22, // bDescriptorType
  1095. LSB(sizeof(keymedia_report_desc)), // wDescriptorLength
  1096. MSB(sizeof(keymedia_report_desc)),
  1097. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1098. 7, // bLength
  1099. 5, // bDescriptorType
  1100. KEYMEDIA_ENDPOINT | 0x80, // bEndpointAddress
  1101. 0x03, // bmAttributes (0x03=intr)
  1102. KEYMEDIA_SIZE, 0, // wMaxPacketSize
  1103. KEYMEDIA_INTERVAL, // bInterval
  1104. #endif // KEYMEDIA_INTERFACE
  1105. #ifdef AUDIO_INTERFACE
  1106. // interface association descriptor, USB ECN, Table 9-Z
  1107. 8, // bLength
  1108. 11, // bDescriptorType
  1109. AUDIO_INTERFACE, // bFirstInterface
  1110. 3, // bInterfaceCount
  1111. 0x01, // bFunctionClass
  1112. 0x01, // bFunctionSubClass
  1113. 0x00, // bFunctionProtocol
  1114. 0, // iFunction
  1115. // Standard AudioControl (AC) Interface Descriptor
  1116. // USB DCD for Audio Devices 1.0, Table 4-1, page 36
  1117. 9, // bLength
  1118. 4, // bDescriptorType, 4 = INTERFACE
  1119. AUDIO_INTERFACE, // bInterfaceNumber
  1120. 0, // bAlternateSetting
  1121. 0, // bNumEndpoints
  1122. 1, // bInterfaceClass, 1 = AUDIO
  1123. 1, // bInterfaceSubclass, 1 = AUDIO_CONTROL
  1124. 0, // bInterfaceProtocol
  1125. 0, // iInterface
  1126. // Class-specific AC Interface Header Descriptor
  1127. // USB DCD for Audio Devices 1.0, Table 4-2, page 37-38
  1128. 10, // bLength
  1129. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1130. 0x01, // bDescriptorSubtype, 1 = HEADER
  1131. 0x00, 0x01, // bcdADC (version 1.0)
  1132. LSB(62), MSB(62), // wTotalLength
  1133. 2, // bInCollection
  1134. AUDIO_INTERFACE+1, // baInterfaceNr(1) - Transmit to PC
  1135. AUDIO_INTERFACE+2, // baInterfaceNr(2) - Receive from PC
  1136. // Input Terminal Descriptor
  1137. // USB DCD for Audio Devices 1.0, Table 4-3, page 39
  1138. 12, // bLength
  1139. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1140. 0x02, // bDescriptorSubType, 2 = INPUT_TERMINAL
  1141. 1, // bTerminalID
  1142. //0x01, 0x02, // wTerminalType, 0x0201 = MICROPHONE
  1143. //0x03, 0x06, // wTerminalType, 0x0603 = Line Connector
  1144. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  1145. 0, // bAssocTerminal, 0 = unidirectional
  1146. 2, // bNrChannels
  1147. 0x03, 0x00, // wChannelConfig, 0x0003 = Left & Right Front
  1148. 0, // iChannelNames
  1149. 0, // iTerminal
  1150. // Output Terminal Descriptor
  1151. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  1152. 9, // bLength
  1153. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1154. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  1155. 2, // bTerminalID
  1156. 0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
  1157. 0, // bAssocTerminal, 0 = unidirectional
  1158. 1, // bCSourceID, connected to input terminal, ID=1
  1159. 0, // iTerminal
  1160. // Input Terminal Descriptor
  1161. // USB DCD for Audio Devices 1.0, Table 4-3, page 39
  1162. 12, // bLength
  1163. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1164. 2, // bDescriptorSubType, 2 = INPUT_TERMINAL
  1165. 3, // bTerminalID
  1166. 0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
  1167. 0, // bAssocTerminal, 0 = unidirectional
  1168. 2, // bNrChannels
  1169. 0x03, 0x00, // wChannelConfig, 0x0003 = Left & Right Front
  1170. 0, // iChannelNames
  1171. 0, // iTerminal
  1172. // Volume feature descriptor
  1173. 10, // bLength
  1174. 0x24, // bDescriptorType = CS_INTERFACE
  1175. 0x06, // bDescriptorSubType = FEATURE_UNIT
  1176. 0x31, // bUnitID
  1177. 0x03, // bSourceID (Input Terminal)
  1178. 0x01, // bControlSize (each channel is 1 byte, 3 channels)
  1179. 0x01, // bmaControls(0) Master: Mute
  1180. 0x02, // bmaControls(1) Left: Volume
  1181. 0x02, // bmaControls(2) Right: Volume
  1182. 0x00, // iFeature
  1183. // Output Terminal Descriptor
  1184. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  1185. 9, // bLength
  1186. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1187. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  1188. 4, // bTerminalID
  1189. //0x02, 0x03, // wTerminalType, 0x0302 = Headphones
  1190. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  1191. 0, // bAssocTerminal, 0 = unidirectional
  1192. 0x31, // bCSourceID, connected to feature, ID=31
  1193. 0, // iTerminal
  1194. // Standard AS Interface Descriptor
  1195. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  1196. // Alternate 0: default setting, disabled zero bandwidth
  1197. 9, // bLenght
  1198. 4, // bDescriptorType = INTERFACE
  1199. AUDIO_INTERFACE+1, // bInterfaceNumber
  1200. 0, // bAlternateSetting
  1201. 0, // bNumEndpoints
  1202. 1, // bInterfaceClass, 1 = AUDIO
  1203. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1204. 0, // bInterfaceProtocol
  1205. 0, // iInterface
  1206. // Alternate 1: streaming data
  1207. 9, // bLenght
  1208. 4, // bDescriptorType = INTERFACE
  1209. AUDIO_INTERFACE+1, // bInterfaceNumber
  1210. 1, // bAlternateSetting
  1211. 1, // bNumEndpoints
  1212. 1, // bInterfaceClass, 1 = AUDIO
  1213. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1214. 0, // bInterfaceProtocol
  1215. 0, // iInterface
  1216. // Class-Specific AS Interface Descriptor
  1217. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  1218. 7, // bLength
  1219. 0x24, // bDescriptorType = CS_INTERFACE
  1220. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  1221. 2, // bTerminalLink: Terminal ID = 2
  1222. 3, // bDelay (approx 3ms delay, audio lib updates)
  1223. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  1224. // Type I Format Descriptor
  1225. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  1226. 11, // bLength
  1227. 0x24, // bDescriptorType = CS_INTERFACE
  1228. 2, // bDescriptorSubtype = FORMAT_TYPE
  1229. 1, // bFormatType = FORMAT_TYPE_I
  1230. 2, // bNrChannels = 2
  1231. 2, // bSubFrameSize = 2 byte
  1232. 16, // bBitResolution = 16 bits
  1233. 1, // bSamFreqType = 1 frequency
  1234. LSB(44100), MSB(44100), 0, // tSamFreq
  1235. // Standard AS Isochronous Audio Data Endpoint Descriptor
  1236. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  1237. 9, // bLength
  1238. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1239. AUDIO_TX_ENDPOINT | 0x80, // bEndpointAddress
  1240. 0x09, // bmAttributes = isochronous, adaptive
  1241. LSB(AUDIO_TX_SIZE), MSB(AUDIO_TX_SIZE), // wMaxPacketSize
  1242. 1, // bInterval, 1 = every frame
  1243. 0, // bRefresh
  1244. 0, // bSynchAddress
  1245. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  1246. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  1247. 7, // bLength
  1248. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  1249. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  1250. 0x00, // bmAttributes
  1251. 0, // bLockDelayUnits, 1 = ms
  1252. 0x00, 0x00, // wLockDelay
  1253. // Standard AS Interface Descriptor
  1254. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  1255. // Alternate 0: default setting, disabled zero bandwidth
  1256. 9, // bLenght
  1257. 4, // bDescriptorType = INTERFACE
  1258. AUDIO_INTERFACE+2, // bInterfaceNumber
  1259. 0, // bAlternateSetting
  1260. 0, // bNumEndpoints
  1261. 1, // bInterfaceClass, 1 = AUDIO
  1262. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1263. 0, // bInterfaceProtocol
  1264. 0, // iInterface
  1265. // Alternate 1: streaming data
  1266. 9, // bLenght
  1267. 4, // bDescriptorType = INTERFACE
  1268. AUDIO_INTERFACE+2, // bInterfaceNumber
  1269. 1, // bAlternateSetting
  1270. 2, // bNumEndpoints
  1271. 1, // bInterfaceClass, 1 = AUDIO
  1272. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1273. 0, // bInterfaceProtocol
  1274. 0, // iInterface
  1275. // Class-Specific AS Interface Descriptor
  1276. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  1277. 7, // bLength
  1278. 0x24, // bDescriptorType = CS_INTERFACE
  1279. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  1280. 3, // bTerminalLink: Terminal ID = 3
  1281. 3, // bDelay (approx 3ms delay, audio lib updates)
  1282. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  1283. // Type I Format Descriptor
  1284. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  1285. 11, // bLength
  1286. 0x24, // bDescriptorType = CS_INTERFACE
  1287. 2, // bDescriptorSubtype = FORMAT_TYPE
  1288. 1, // bFormatType = FORMAT_TYPE_I
  1289. 2, // bNrChannels = 2
  1290. 2, // bSubFrameSize = 2 byte
  1291. 16, // bBitResolution = 16 bits
  1292. 1, // bSamFreqType = 1 frequency
  1293. LSB(44100), MSB(44100), 0, // tSamFreq
  1294. // Standard AS Isochronous Audio Data Endpoint Descriptor
  1295. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  1296. 9, // bLength
  1297. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1298. AUDIO_RX_ENDPOINT, // bEndpointAddress
  1299. 0x05, // bmAttributes = isochronous, asynchronous
  1300. LSB(AUDIO_RX_SIZE), MSB(AUDIO_RX_SIZE), // wMaxPacketSize
  1301. 1, // bInterval, 1 = every frame
  1302. 0, // bRefresh
  1303. AUDIO_SYNC_ENDPOINT | 0x80, // bSynchAddress
  1304. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  1305. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  1306. 7, // bLength
  1307. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  1308. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  1309. 0x00, // bmAttributes
  1310. 0, // bLockDelayUnits, 1 = ms
  1311. 0x00, 0x00, // wLockDelay
  1312. // Standard AS Isochronous Audio Synch Endpoint Descriptor
  1313. // USB DCD for Audio Devices 1.0, Section 4.6.2.1, Table 4-22, page 63-64
  1314. 9, // bLength
  1315. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1316. AUDIO_SYNC_ENDPOINT | 0x80, // bEndpointAddress
  1317. 0x11, // bmAttributes = isochronous, feedback
  1318. 3, 0, // wMaxPacketSize, 3 bytes
  1319. 1, // bInterval, 1 = every frame
  1320. 5, // bRefresh, 5 = 32ms
  1321. 0, // bSynchAddress
  1322. #endif
  1323. #ifdef MULTITOUCH_INTERFACE
  1324. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1325. 9, // bLength
  1326. 4, // bDescriptorType
  1327. MULTITOUCH_INTERFACE, // bInterfaceNumber
  1328. 0, // bAlternateSetting
  1329. 1, // bNumEndpoints
  1330. 0x03, // bInterfaceClass (0x03 = HID)
  1331. 0x00, // bInterfaceSubClass
  1332. 0x00, // bInterfaceProtocol
  1333. 0, // iInterface
  1334. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1335. 9, // bLength
  1336. 0x21, // bDescriptorType
  1337. 0x11, 0x01, // bcdHID
  1338. 0, // bCountryCode
  1339. 1, // bNumDescriptors
  1340. 0x22, // bDescriptorType
  1341. LSB(sizeof(multitouch_report_desc)), // wDescriptorLength
  1342. MSB(sizeof(multitouch_report_desc)),
  1343. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1344. 7, // bLength
  1345. 5, // bDescriptorType
  1346. MULTITOUCH_ENDPOINT | 0x80, // bEndpointAddress
  1347. 0x03, // bmAttributes (0x03=intr)
  1348. MULTITOUCH_SIZE, 0, // wMaxPacketSize
  1349. 1, // bInterval
  1350. #endif // KEYMEDIA_INTERFACE
  1351. };
  1352. // **************************************************************
  1353. // String Descriptors
  1354. // **************************************************************
  1355. // The descriptors above can provide human readable strings,
  1356. // referenced by index numbers. These descriptors are the
  1357. // actual string data
  1358. /* defined in usb_names.h
  1359. struct usb_string_descriptor_struct {
  1360. uint8_t bLength;
  1361. uint8_t bDescriptorType;
  1362. uint16_t wString[];
  1363. };
  1364. */
  1365. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  1366. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  1367. extern struct usb_string_descriptor_struct usb_string_product_name
  1368. __attribute__ ((weak, alias("usb_string_product_name_default")));
  1369. extern struct usb_string_descriptor_struct usb_string_serial_number
  1370. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  1371. struct usb_string_descriptor_struct string0 = {
  1372. 4,
  1373. 3,
  1374. {0x0409}
  1375. };
  1376. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  1377. 2 + MANUFACTURER_NAME_LEN * 2,
  1378. 3,
  1379. MANUFACTURER_NAME
  1380. };
  1381. struct usb_string_descriptor_struct usb_string_product_name_default = {
  1382. 2 + PRODUCT_NAME_LEN * 2,
  1383. 3,
  1384. PRODUCT_NAME
  1385. };
  1386. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  1387. 12,
  1388. 3,
  1389. {0,0,0,0,0,0,0,0,0,0}
  1390. };
  1391. #ifdef MTP_INTERFACE
  1392. struct usb_string_descriptor_struct usb_string_mtp = {
  1393. 2 + 3 * 2,
  1394. 3,
  1395. {'M','T','P'}
  1396. };
  1397. #endif
  1398. void usb_init_serialnumber(void)
  1399. {
  1400. #if 1
  1401. char buf[11];
  1402. uint32_t i, num;
  1403. num = HW_OCOTP_MAC0 & 0xFFFFFF;
  1404. // add extra zero to work around OS-X CDC-ACM driver bug
  1405. if (num < 10000000) num = num * 10;
  1406. ultoa(num, buf, 10);
  1407. for (i=0; i<10; i++) {
  1408. char c = buf[i];
  1409. if (!c) break;
  1410. usb_string_serial_number_default.wString[i] = c;
  1411. }
  1412. usb_string_serial_number_default.bLength = i * 2 + 2;
  1413. #else
  1414. usb_string_serial_number_default.wString[0] = '1';
  1415. usb_string_serial_number_default.wString[1] = '2';
  1416. usb_string_serial_number_default.wString[2] = '3';
  1417. usb_string_serial_number_default.bLength = 3 * 2 + 2;
  1418. #endif
  1419. }
  1420. // **************************************************************
  1421. // Descriptors List
  1422. // **************************************************************
  1423. // This table provides access to all the descriptor data above.
  1424. const usb_descriptor_list_t usb_descriptor_list[] = {
  1425. //wValue, wIndex, address, length
  1426. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  1427. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  1428. #ifdef SEREMU_INTERFACE
  1429. {0x2200, SEREMU_INTERFACE, seremu_report_desc, sizeof(seremu_report_desc)},
  1430. {0x2100, SEREMU_INTERFACE, config_descriptor+SEREMU_HID_DESC_OFFSET, 9},
  1431. #endif
  1432. #ifdef KEYBOARD_INTERFACE
  1433. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  1434. {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_HID_DESC_OFFSET, 9},
  1435. #endif
  1436. #ifdef MOUSE_INTERFACE
  1437. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  1438. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_HID_DESC_OFFSET, 9},
  1439. #endif
  1440. #ifdef JOYSTICK_INTERFACE
  1441. {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
  1442. {0x2100, JOYSTICK_INTERFACE, config_descriptor+JOYSTICK_HID_DESC_OFFSET, 9},
  1443. #endif
  1444. #ifdef RAWHID_INTERFACE
  1445. {0x2200, RAWHID_INTERFACE, rawhid_report_desc, sizeof(rawhid_report_desc)},
  1446. {0x2100, RAWHID_INTERFACE, config_descriptor+RAWHID_HID_DESC_OFFSET, 9},
  1447. #endif
  1448. #ifdef FLIGHTSIM_INTERFACE
  1449. {0x2200, FLIGHTSIM_INTERFACE, flightsim_report_desc, sizeof(flightsim_report_desc)},
  1450. {0x2100, FLIGHTSIM_INTERFACE, config_descriptor+FLIGHTSIM_HID_DESC_OFFSET, 9},
  1451. #endif
  1452. #ifdef KEYMEDIA_INTERFACE
  1453. {0x2200, KEYMEDIA_INTERFACE, keymedia_report_desc, sizeof(keymedia_report_desc)},
  1454. {0x2100, KEYMEDIA_INTERFACE, config_descriptor+KEYMEDIA_HID_DESC_OFFSET, 9},
  1455. #endif
  1456. #ifdef MULTITOUCH_INTERFACE
  1457. {0x2200, MULTITOUCH_INTERFACE, multitouch_report_desc, sizeof(multitouch_report_desc)},
  1458. {0x2100, MULTITOUCH_INTERFACE, config_descriptor+MULTITOUCH_HID_DESC_OFFSET, 9},
  1459. #endif
  1460. #ifdef MTP_INTERFACE
  1461. {0x0304, 0x0409, (const uint8_t *)&usb_string_mtp, 0},
  1462. #endif
  1463. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  1464. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  1465. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  1466. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  1467. {0, 0, NULL, 0}
  1468. };
  1469. // **************************************************************
  1470. // Endpoint Configuration
  1471. // **************************************************************
  1472. #if 0
  1473. // 0x00 = not used
  1474. // 0x19 = Recieve only
  1475. // 0x15 = Transmit only
  1476. // 0x1D = Transmit & Recieve
  1477. //
  1478. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1479. {
  1480. 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
  1481. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1482. };
  1483. #endif
  1484. const uint32_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1485. {
  1486. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  1487. ENDPOINT1_CONFIG,
  1488. #elif (NUM_ENDPOINTS >= 1)
  1489. ENDPOINT_TRANSMIT_UNUSED + ENDPOINT_RECEIVE_UNUSED,
  1490. #endif
  1491. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  1492. ENDPOINT2_CONFIG,
  1493. #elif (NUM_ENDPOINTS >= 2)
  1494. ENDPOINT_TRANSMIT_UNUSED + ENDPOINT_RECEIVE_UNUSED,
  1495. #endif
  1496. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  1497. ENDPOINT3_CONFIG,
  1498. #elif (NUM_ENDPOINTS >= 3)
  1499. ENDPOINT_TRANSMIT_UNUSED + ENDPOINT_RECEIVE_UNUSED,
  1500. #endif
  1501. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  1502. ENDPOINT4_CONFIG,
  1503. #elif (NUM_ENDPOINTS >= 4)
  1504. ENDPOINT_TRANSMIT_UNUSED + ENDPOINT_RECEIVE_UNUSED,
  1505. #endif
  1506. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  1507. ENDPOINT5_CONFIG,
  1508. #elif (NUM_ENDPOINTS >= 5)
  1509. ENDPOINT_TRANSMIT_UNUSED + ENDPOINT_RECEIVE_UNUSED,
  1510. #endif
  1511. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  1512. ENDPOINT6_CONFIG,
  1513. #elif (NUM_ENDPOINTS >= 6)
  1514. ENDPOINT_TRANSMIT_UNUSED + ENDPOINT_RECEIVE_UNUSED,
  1515. #endif
  1516. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  1517. ENDPOINT7_CONFIG,
  1518. #elif (NUM_ENDPOINTS >= 7)
  1519. ENDPOINT_TRANSMIT_UNUSED + ENDPOINT_RECEIVE_UNUSED,
  1520. #endif
  1521. };
  1522. #endif // NUM_ENDPOINTS
  1523. //#endif // F_CPU >= 20 MHz