Teensy 4.1 core updated for C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1811 lines
85KB

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