No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

1637 líneas
75KB

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