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.

1665 lines
76KB

  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 MIDI_INTERFACE_DESC_POS CDC2_DATA_INTERFACE_DESC_POS+CDC2_DATA_INTERFACE_DESC_SIZE
  466. #ifdef MIDI_INTERFACE
  467. #if !defined(MIDI_NUM_CABLES) || MIDI_NUM_CABLES < 1 || MIDI_NUM_CABLES > 16
  468. #error "MIDI_NUM_CABLES must be defined between 1 to 16"
  469. #endif
  470. #define MIDI_INTERFACE_DESC_SIZE 9+7+((6+6+9+9)*MIDI_NUM_CABLES)+(9+4+MIDI_NUM_CABLES)*2
  471. #else
  472. #define MIDI_INTERFACE_DESC_SIZE 0
  473. #endif
  474. #define KEYBOARD_INTERFACE_DESC_POS MIDI_INTERFACE_DESC_POS+MIDI_INTERFACE_DESC_SIZE
  475. #ifdef KEYBOARD_INTERFACE
  476. #define KEYBOARD_INTERFACE_DESC_SIZE 9+9+7
  477. #define KEYBOARD_HID_DESC_OFFSET KEYBOARD_INTERFACE_DESC_POS+9
  478. #else
  479. #define KEYBOARD_INTERFACE_DESC_SIZE 0
  480. #endif
  481. #define MOUSE_INTERFACE_DESC_POS KEYBOARD_INTERFACE_DESC_POS+KEYBOARD_INTERFACE_DESC_SIZE
  482. #ifdef MOUSE_INTERFACE
  483. #define MOUSE_INTERFACE_DESC_SIZE 9+9+7
  484. #define MOUSE_HID_DESC_OFFSET MOUSE_INTERFACE_DESC_POS+9
  485. #else
  486. #define MOUSE_INTERFACE_DESC_SIZE 0
  487. #endif
  488. #define RAWHID_INTERFACE_DESC_POS MOUSE_INTERFACE_DESC_POS+MOUSE_INTERFACE_DESC_SIZE
  489. #ifdef RAWHID_INTERFACE
  490. #define RAWHID_INTERFACE_DESC_SIZE 9+9+7+7
  491. #define RAWHID_HID_DESC_OFFSET RAWHID_INTERFACE_DESC_POS+9
  492. #else
  493. #define RAWHID_INTERFACE_DESC_SIZE 0
  494. #endif
  495. #define FLIGHTSIM_INTERFACE_DESC_POS RAWHID_INTERFACE_DESC_POS+RAWHID_INTERFACE_DESC_SIZE
  496. #ifdef FLIGHTSIM_INTERFACE
  497. #define FLIGHTSIM_INTERFACE_DESC_SIZE 9+9+7+7
  498. #define FLIGHTSIM_HID_DESC_OFFSET FLIGHTSIM_INTERFACE_DESC_POS+9
  499. #else
  500. #define FLIGHTSIM_INTERFACE_DESC_SIZE 0
  501. #endif
  502. #define SEREMU_INTERFACE_DESC_POS FLIGHTSIM_INTERFACE_DESC_POS+FLIGHTSIM_INTERFACE_DESC_SIZE
  503. #ifdef SEREMU_INTERFACE
  504. #define SEREMU_INTERFACE_DESC_SIZE 9+9+7+7
  505. #define SEREMU_HID_DESC_OFFSET SEREMU_INTERFACE_DESC_POS+9
  506. #else
  507. #define SEREMU_INTERFACE_DESC_SIZE 0
  508. #endif
  509. #define JOYSTICK_INTERFACE_DESC_POS SEREMU_INTERFACE_DESC_POS+SEREMU_INTERFACE_DESC_SIZE
  510. #ifdef JOYSTICK_INTERFACE
  511. #define JOYSTICK_INTERFACE_DESC_SIZE 9+9+7
  512. #define JOYSTICK_HID_DESC_OFFSET JOYSTICK_INTERFACE_DESC_POS+9
  513. #else
  514. #define JOYSTICK_INTERFACE_DESC_SIZE 0
  515. #endif
  516. #define MTP_INTERFACE_DESC_POS JOYSTICK_INTERFACE_DESC_POS+JOYSTICK_INTERFACE_DESC_SIZE
  517. #ifdef MTP_INTERFACE
  518. #define MTP_INTERFACE_DESC_SIZE 9+7+7+7
  519. #else
  520. #define MTP_INTERFACE_DESC_SIZE 0
  521. #endif
  522. #define KEYMEDIA_INTERFACE_DESC_POS MTP_INTERFACE_DESC_POS+MTP_INTERFACE_DESC_SIZE
  523. #ifdef KEYMEDIA_INTERFACE
  524. #define KEYMEDIA_INTERFACE_DESC_SIZE 9+9+7
  525. #define KEYMEDIA_HID_DESC_OFFSET KEYMEDIA_INTERFACE_DESC_POS+9
  526. #else
  527. #define KEYMEDIA_INTERFACE_DESC_SIZE 0
  528. #endif
  529. #define AUDIO_INTERFACE_DESC_POS KEYMEDIA_INTERFACE_DESC_POS+KEYMEDIA_INTERFACE_DESC_SIZE
  530. #ifdef AUDIO_INTERFACE
  531. #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
  532. #else
  533. #define AUDIO_INTERFACE_DESC_SIZE 0
  534. #endif
  535. #define MULTITOUCH_INTERFACE_DESC_POS AUDIO_INTERFACE_DESC_POS+AUDIO_INTERFACE_DESC_SIZE
  536. #ifdef MULTITOUCH_INTERFACE
  537. #define MULTITOUCH_INTERFACE_DESC_SIZE 9+9+7
  538. #define MULTITOUCH_HID_DESC_OFFSET MULTITOUCH_INTERFACE_DESC_POS+9
  539. #else
  540. #define MULTITOUCH_INTERFACE_DESC_SIZE 0
  541. #endif
  542. #define CONFIG_DESC_SIZE MULTITOUCH_INTERFACE_DESC_POS+MULTITOUCH_INTERFACE_DESC_SIZE
  543. // **************************************************************
  544. // USB Configuration
  545. // **************************************************************
  546. #define EMIT_CDC_IAD_DESCRIPTOR(prefix) \
  547. /* interface association descriptor, USB ECN, Table 9-Z */ \
  548. 8, /* bLength */ \
  549. 11, /* bDescriptorType */ \
  550. prefix ## _STATUS_INTERFACE, /* bFirstInterface */ \
  551. 2, /* bInterfaceCount */ \
  552. 0x02, /* bFunctionClass */ \
  553. 0x02, /* bFunctionSubClass */ \
  554. 0x01, /* bFunctionProtocol */ \
  555. 0 /* iFunction */
  556. #define EMIT_CDC_DESCRIPTORS(prefix) \
  557. /* interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 */ \
  558. 9, /* bLength */ \
  559. 4, /* bDescriptorType */ \
  560. prefix ## _STATUS_INTERFACE, /* bInterfaceNumber */ \
  561. 0, /* bAlternateSetting */ \
  562. 1, /* bNumEndpoints */ \
  563. 0x02, /* bInterfaceClass */ \
  564. 0x02, /* bInterfaceSubClass */ \
  565. 0x01, /* bInterfaceProtocol */ \
  566. 0, /* iInterface */ \
  567. /* CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26 */ \
  568. 5, /* bFunctionLength */ \
  569. 0x24, /* bDescriptorType */ \
  570. 0x00, /* bDescriptorSubtype */ \
  571. 0x10, 0x01, /* bcdCDC */ \
  572. /* Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27 */\
  573. 5, /* bFunctionLength */ \
  574. 0x24, /* bDescriptorType */ \
  575. 0x01, /* bDescriptorSubtype */ \
  576. 0x01, /* bmCapabilities */ \
  577. 1, /* bDataInterface */ \
  578. /* Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28 */\
  579. 4, /* bFunctionLength */ \
  580. 0x24, /* bDescriptorType */ \
  581. 0x02, /* bDescriptorSubtype */ \
  582. 0x06, /* bmCapabilities */ \
  583. /* Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33 */ \
  584. 5, /* bFunctionLength */ \
  585. 0x24, /* bDescriptorType */ \
  586. 0x06, /* bDescriptorSubtype */ \
  587. prefix ## _STATUS_INTERFACE, /* bMasterInterface */ \
  588. prefix ## _DATA_INTERFACE, /* bSlaveInterface0 */ \
  589. /* endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 */ \
  590. 7, /* bLength */ \
  591. 5, /* bDescriptorType */ \
  592. prefix ## _ACM_ENDPOINT | 0x80, /* bEndpointAddress */ \
  593. 0x03, /* bmAttributes (0x03=intr) */ \
  594. prefix ## _ACM_SIZE, 0, /* wMaxPacketSize */ \
  595. 64, /* bInterval */ \
  596. /* interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 */ \
  597. 9, /* bLength */ \
  598. 4, /* bDescriptorType */ \
  599. prefix ## _DATA_INTERFACE, /* bInterfaceNumber */ \
  600. 0, /* bAlternateSetting */ \
  601. 2, /* bNumEndpoints */ \
  602. 0x0A, /* bInterfaceClass */ \
  603. 0x00, /* bInterfaceSubClass */ \
  604. 0x00, /* bInterfaceProtocol */ \
  605. 0, /* iInterface */ \
  606. /* endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 */ \
  607. 7, /* bLength */ \
  608. 5, /* bDescriptorType */ \
  609. prefix ## _RX_ENDPOINT, /* bEndpointAddress */ \
  610. 0x02, /* bmAttributes (0x02=bulk) */ \
  611. prefix ## _RX_SIZE, 0, /* wMaxPacketSize */ \
  612. 0, /* bInterval */ \
  613. /* endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 */ \
  614. 7, /* bLength */ \
  615. 5, /* bDescriptorType */ \
  616. prefix ## _TX_ENDPOINT | 0x80, /* bEndpointAddress */ \
  617. 0x02, /* bmAttributes (0x02=bulk) */ \
  618. prefix ## _TX_SIZE, 0, /* wMaxPacketSize */ \
  619. 0 /* bInterval */ \
  620. // USB Configuration Descriptor. This huge descriptor tells all
  621. // of the devices capbilities.
  622. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  623. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  624. 9, // bLength;
  625. 2, // bDescriptorType;
  626. LSB(CONFIG_DESC_SIZE), // wTotalLength
  627. MSB(CONFIG_DESC_SIZE),
  628. NUM_INTERFACE, // bNumInterfaces
  629. 1, // bConfigurationValue
  630. 0, // iConfiguration
  631. 0xC0, // bmAttributes
  632. 50, // bMaxPower
  633. #ifdef CDC_IAD_DESCRIPTOR
  634. EMIT_CDC_IAD_DESCRIPTOR(CDC),
  635. #endif
  636. #ifdef CDC_DATA_INTERFACE
  637. EMIT_CDC_DESCRIPTORS(CDC),
  638. #endif // CDC_DATA_INTERFACE
  639. #ifdef CDC2_DATA_INTERFACE
  640. EMIT_CDC_IAD_DESCRIPTOR(CDC2),
  641. EMIT_CDC_DESCRIPTORS(CDC2),
  642. #endif // CDC2_DATA_INTERFACE
  643. #ifdef MIDI_INTERFACE
  644. // Standard MS Interface Descriptor,
  645. 9, // bLength
  646. 4, // bDescriptorType
  647. MIDI_INTERFACE, // bInterfaceNumber
  648. 0, // bAlternateSetting
  649. 2, // bNumEndpoints
  650. 0x01, // bInterfaceClass (0x01 = Audio)
  651. 0x03, // bInterfaceSubClass (0x03 = MIDI)
  652. 0x00, // bInterfaceProtocol (unused for MIDI)
  653. 0, // iInterface
  654. // MIDI MS Interface Header, USB MIDI 6.1.2.1, page 21, Table 6-2
  655. 7, // bLength
  656. 0x24, // bDescriptorType = CS_INTERFACE
  657. 0x01, // bDescriptorSubtype = MS_HEADER
  658. 0x00, 0x01, // bcdMSC = revision 01.00
  659. LSB(7+(6+6+9+9)*MIDI_NUM_CABLES), // wTotalLength
  660. MSB(7+(6+6+9+9)*MIDI_NUM_CABLES),
  661. // MIDI IN Jack Descriptor, B.4.3, Table B-7 (embedded), page 40
  662. 6, // bLength
  663. 0x24, // bDescriptorType = CS_INTERFACE
  664. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  665. 0x01, // bJackType = EMBEDDED
  666. 1, // bJackID, ID = 1
  667. 0, // iJack
  668. // MIDI IN Jack Descriptor, B.4.3, Table B-8 (external), page 40
  669. 6, // bLength
  670. 0x24, // bDescriptorType = CS_INTERFACE
  671. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  672. 0x02, // bJackType = EXTERNAL
  673. 2, // bJackID, ID = 2
  674. 0, // iJack
  675. // MIDI OUT Jack Descriptor, B.4.4, Table B-9, page 41
  676. 9,
  677. 0x24, // bDescriptorType = CS_INTERFACE
  678. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  679. 0x01, // bJackType = EMBEDDED
  680. 3, // bJackID, ID = 3
  681. 1, // bNrInputPins = 1 pin
  682. 2, // BaSourceID(1) = 2
  683. 1, // BaSourcePin(1) = first pin
  684. 0, // iJack
  685. // MIDI OUT Jack Descriptor, B.4.4, Table B-10, page 41
  686. 9,
  687. 0x24, // bDescriptorType = CS_INTERFACE
  688. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  689. 0x02, // bJackType = EXTERNAL
  690. 4, // bJackID, ID = 4
  691. 1, // bNrInputPins = 1 pin
  692. 1, // BaSourceID(1) = 1
  693. 1, // BaSourcePin(1) = first pin
  694. 0, // iJack
  695. #if MIDI_NUM_CABLES >= 2
  696. #define MIDI_INTERFACE_JACK_PAIR(a, b, c, d) \
  697. 6, 0x24, 0x02, 0x01, (a), 0, \
  698. 6, 0x24, 0x02, 0x02, (b), 0, \
  699. 9, 0x24, 0x03, 0x01, (c), 1, (b), 1, 0, \
  700. 9, 0x24, 0x03, 0x02, (d), 1, (a), 1, 0,
  701. MIDI_INTERFACE_JACK_PAIR(5, 6, 7, 8)
  702. #endif
  703. #if MIDI_NUM_CABLES >= 3
  704. MIDI_INTERFACE_JACK_PAIR(9, 10, 11, 12)
  705. #endif
  706. #if MIDI_NUM_CABLES >= 4
  707. MIDI_INTERFACE_JACK_PAIR(13, 14, 15, 16)
  708. #endif
  709. #if MIDI_NUM_CABLES >= 5
  710. MIDI_INTERFACE_JACK_PAIR(17, 18, 19, 20)
  711. #endif
  712. #if MIDI_NUM_CABLES >= 6
  713. MIDI_INTERFACE_JACK_PAIR(21, 22, 23, 24)
  714. #endif
  715. #if MIDI_NUM_CABLES >= 7
  716. MIDI_INTERFACE_JACK_PAIR(25, 26, 27, 28)
  717. #endif
  718. #if MIDI_NUM_CABLES >= 8
  719. MIDI_INTERFACE_JACK_PAIR(29, 30, 31, 32)
  720. #endif
  721. #if MIDI_NUM_CABLES >= 9
  722. MIDI_INTERFACE_JACK_PAIR(33, 34, 35, 36)
  723. #endif
  724. #if MIDI_NUM_CABLES >= 10
  725. MIDI_INTERFACE_JACK_PAIR(37, 38, 39, 40)
  726. #endif
  727. #if MIDI_NUM_CABLES >= 11
  728. MIDI_INTERFACE_JACK_PAIR(41, 42, 43, 44)
  729. #endif
  730. #if MIDI_NUM_CABLES >= 12
  731. MIDI_INTERFACE_JACK_PAIR(45, 46, 47, 48)
  732. #endif
  733. #if MIDI_NUM_CABLES >= 13
  734. MIDI_INTERFACE_JACK_PAIR(49, 50, 51, 52)
  735. #endif
  736. #if MIDI_NUM_CABLES >= 14
  737. MIDI_INTERFACE_JACK_PAIR(53, 54, 55, 56)
  738. #endif
  739. #if MIDI_NUM_CABLES >= 15
  740. MIDI_INTERFACE_JACK_PAIR(57, 58, 59, 60)
  741. #endif
  742. #if MIDI_NUM_CABLES >= 16
  743. MIDI_INTERFACE_JACK_PAIR(61, 62, 63, 64)
  744. #endif
  745. // Standard Bulk OUT Endpoint Descriptor, B.5.1, Table B-11, pae 42
  746. 9, // bLength
  747. 5, // bDescriptorType = ENDPOINT
  748. MIDI_RX_ENDPOINT, // bEndpointAddress
  749. 0x02, // bmAttributes (0x02=bulk)
  750. MIDI_RX_SIZE, 0, // wMaxPacketSize
  751. 0, // bInterval
  752. 0, // bRefresh
  753. 0, // bSynchAddress
  754. // Class-specific MS Bulk OUT Endpoint Descriptor, B.5.2, Table B-12, page 42
  755. 4+MIDI_NUM_CABLES, // bLength
  756. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  757. 0x01, // bJackType = MS_GENERAL
  758. MIDI_NUM_CABLES, // bNumEmbMIDIJack = number of jacks
  759. 1, // BaAssocJackID(1) = jack ID #1
  760. #if MIDI_NUM_CABLES >= 2
  761. 5,
  762. #endif
  763. #if MIDI_NUM_CABLES >= 3
  764. 9,
  765. #endif
  766. #if MIDI_NUM_CABLES >= 4
  767. 13,
  768. #endif
  769. #if MIDI_NUM_CABLES >= 5
  770. 17,
  771. #endif
  772. #if MIDI_NUM_CABLES >= 6
  773. 21,
  774. #endif
  775. #if MIDI_NUM_CABLES >= 7
  776. 25,
  777. #endif
  778. #if MIDI_NUM_CABLES >= 8
  779. 29,
  780. #endif
  781. #if MIDI_NUM_CABLES >= 9
  782. 33,
  783. #endif
  784. #if MIDI_NUM_CABLES >= 10
  785. 37,
  786. #endif
  787. #if MIDI_NUM_CABLES >= 11
  788. 41,
  789. #endif
  790. #if MIDI_NUM_CABLES >= 12
  791. 45,
  792. #endif
  793. #if MIDI_NUM_CABLES >= 13
  794. 49,
  795. #endif
  796. #if MIDI_NUM_CABLES >= 14
  797. 53,
  798. #endif
  799. #if MIDI_NUM_CABLES >= 15
  800. 57,
  801. #endif
  802. #if MIDI_NUM_CABLES >= 16
  803. 61,
  804. #endif
  805. // Standard Bulk IN Endpoint Descriptor, B.5.1, Table B-11, pae 42
  806. 9, // bLength
  807. 5, // bDescriptorType = ENDPOINT
  808. MIDI_TX_ENDPOINT | 0x80, // bEndpointAddress
  809. 0x02, // bmAttributes (0x02=bulk)
  810. MIDI_TX_SIZE, 0, // wMaxPacketSize
  811. 0, // bInterval
  812. 0, // bRefresh
  813. 0, // bSynchAddress
  814. // Class-specific MS Bulk IN Endpoint Descriptor, B.5.2, Table B-12, page 42
  815. 4+MIDI_NUM_CABLES, // bLength
  816. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  817. 0x01, // bJackType = MS_GENERAL
  818. MIDI_NUM_CABLES, // bNumEmbMIDIJack = number of jacks
  819. 3, // BaAssocJackID(1) = jack ID #3
  820. #if MIDI_NUM_CABLES >= 2
  821. 7,
  822. #endif
  823. #if MIDI_NUM_CABLES >= 3
  824. 11,
  825. #endif
  826. #if MIDI_NUM_CABLES >= 4
  827. 15,
  828. #endif
  829. #if MIDI_NUM_CABLES >= 5
  830. 19,
  831. #endif
  832. #if MIDI_NUM_CABLES >= 6
  833. 23,
  834. #endif
  835. #if MIDI_NUM_CABLES >= 7
  836. 27,
  837. #endif
  838. #if MIDI_NUM_CABLES >= 8
  839. 31,
  840. #endif
  841. #if MIDI_NUM_CABLES >= 9
  842. 35,
  843. #endif
  844. #if MIDI_NUM_CABLES >= 10
  845. 39,
  846. #endif
  847. #if MIDI_NUM_CABLES >= 11
  848. 43,
  849. #endif
  850. #if MIDI_NUM_CABLES >= 12
  851. 47,
  852. #endif
  853. #if MIDI_NUM_CABLES >= 13
  854. 51,
  855. #endif
  856. #if MIDI_NUM_CABLES >= 14
  857. 55,
  858. #endif
  859. #if MIDI_NUM_CABLES >= 15
  860. 59,
  861. #endif
  862. #if MIDI_NUM_CABLES >= 16
  863. 63,
  864. #endif
  865. #endif // MIDI_INTERFACE
  866. #ifdef KEYBOARD_INTERFACE
  867. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  868. 9, // bLength
  869. 4, // bDescriptorType
  870. KEYBOARD_INTERFACE, // bInterfaceNumber
  871. 0, // bAlternateSetting
  872. 1, // bNumEndpoints
  873. 0x03, // bInterfaceClass (0x03 = HID)
  874. 0x01, // bInterfaceSubClass (0x01 = Boot)
  875. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  876. 0, // iInterface
  877. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  878. 9, // bLength
  879. 0x21, // bDescriptorType
  880. 0x11, 0x01, // bcdHID
  881. 0, // bCountryCode
  882. 1, // bNumDescriptors
  883. 0x22, // bDescriptorType
  884. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  885. MSB(sizeof(keyboard_report_desc)),
  886. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  887. 7, // bLength
  888. 5, // bDescriptorType
  889. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  890. 0x03, // bmAttributes (0x03=intr)
  891. KEYBOARD_SIZE, 0, // wMaxPacketSize
  892. KEYBOARD_INTERVAL, // bInterval
  893. #endif // KEYBOARD_INTERFACE
  894. #ifdef MOUSE_INTERFACE
  895. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  896. 9, // bLength
  897. 4, // bDescriptorType
  898. MOUSE_INTERFACE, // bInterfaceNumber
  899. 0, // bAlternateSetting
  900. 1, // bNumEndpoints
  901. 0x03, // bInterfaceClass (0x03 = HID)
  902. 0x00, // bInterfaceSubClass (0x01 = Boot)
  903. 0x00, // bInterfaceProtocol (0x02 = Mouse)
  904. 0, // iInterface
  905. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  906. 9, // bLength
  907. 0x21, // bDescriptorType
  908. 0x11, 0x01, // bcdHID
  909. 0, // bCountryCode
  910. 1, // bNumDescriptors
  911. 0x22, // bDescriptorType
  912. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  913. MSB(sizeof(mouse_report_desc)),
  914. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  915. 7, // bLength
  916. 5, // bDescriptorType
  917. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  918. 0x03, // bmAttributes (0x03=intr)
  919. MOUSE_SIZE, 0, // wMaxPacketSize
  920. MOUSE_INTERVAL, // bInterval
  921. #endif // MOUSE_INTERFACE
  922. #ifdef RAWHID_INTERFACE
  923. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  924. 9, // bLength
  925. 4, // bDescriptorType
  926. RAWHID_INTERFACE, // bInterfaceNumber
  927. 0, // bAlternateSetting
  928. 2, // bNumEndpoints
  929. 0x03, // bInterfaceClass (0x03 = HID)
  930. 0x00, // bInterfaceSubClass
  931. 0x00, // bInterfaceProtocol
  932. 0, // iInterface
  933. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  934. 9, // bLength
  935. 0x21, // bDescriptorType
  936. 0x11, 0x01, // bcdHID
  937. 0, // bCountryCode
  938. 1, // bNumDescriptors
  939. 0x22, // bDescriptorType
  940. LSB(sizeof(rawhid_report_desc)), // wDescriptorLength
  941. MSB(sizeof(rawhid_report_desc)),
  942. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  943. 7, // bLength
  944. 5, // bDescriptorType
  945. RAWHID_TX_ENDPOINT | 0x80, // bEndpointAddress
  946. 0x03, // bmAttributes (0x03=intr)
  947. RAWHID_TX_SIZE, 0, // wMaxPacketSize
  948. RAWHID_TX_INTERVAL, // bInterval
  949. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  950. 7, // bLength
  951. 5, // bDescriptorType
  952. RAWHID_RX_ENDPOINT, // bEndpointAddress
  953. 0x03, // bmAttributes (0x03=intr)
  954. RAWHID_RX_SIZE, 0, // wMaxPacketSize
  955. RAWHID_RX_INTERVAL, // bInterval
  956. #endif // RAWHID_INTERFACE
  957. #ifdef FLIGHTSIM_INTERFACE
  958. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  959. 9, // bLength
  960. 4, // bDescriptorType
  961. FLIGHTSIM_INTERFACE, // bInterfaceNumber
  962. 0, // bAlternateSetting
  963. 2, // bNumEndpoints
  964. 0x03, // bInterfaceClass (0x03 = HID)
  965. 0x00, // bInterfaceSubClass
  966. 0x00, // bInterfaceProtocol
  967. 0, // iInterface
  968. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  969. 9, // bLength
  970. 0x21, // bDescriptorType
  971. 0x11, 0x01, // bcdHID
  972. 0, // bCountryCode
  973. 1, // bNumDescriptors
  974. 0x22, // bDescriptorType
  975. LSB(sizeof(flightsim_report_desc)), // wDescriptorLength
  976. MSB(sizeof(flightsim_report_desc)),
  977. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  978. 7, // bLength
  979. 5, // bDescriptorType
  980. FLIGHTSIM_TX_ENDPOINT | 0x80, // bEndpointAddress
  981. 0x03, // bmAttributes (0x03=intr)
  982. FLIGHTSIM_TX_SIZE, 0, // wMaxPacketSize
  983. FLIGHTSIM_TX_INTERVAL, // bInterval
  984. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  985. 7, // bLength
  986. 5, // bDescriptorType
  987. FLIGHTSIM_RX_ENDPOINT, // bEndpointAddress
  988. 0x03, // bmAttributes (0x03=intr)
  989. FLIGHTSIM_RX_SIZE, 0, // wMaxPacketSize
  990. FLIGHTSIM_RX_INTERVAL, // bInterval
  991. #endif // FLIGHTSIM_INTERFACE
  992. #ifdef SEREMU_INTERFACE
  993. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  994. 9, // bLength
  995. 4, // bDescriptorType
  996. SEREMU_INTERFACE, // bInterfaceNumber
  997. 0, // bAlternateSetting
  998. 2, // bNumEndpoints
  999. 0x03, // bInterfaceClass (0x03 = HID)
  1000. 0x00, // bInterfaceSubClass
  1001. 0x00, // bInterfaceProtocol
  1002. 0, // iInterface
  1003. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1004. 9, // bLength
  1005. 0x21, // bDescriptorType
  1006. 0x11, 0x01, // bcdHID
  1007. 0, // bCountryCode
  1008. 1, // bNumDescriptors
  1009. 0x22, // bDescriptorType
  1010. LSB(sizeof(seremu_report_desc)), // wDescriptorLength
  1011. MSB(sizeof(seremu_report_desc)),
  1012. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1013. 7, // bLength
  1014. 5, // bDescriptorType
  1015. SEREMU_TX_ENDPOINT | 0x80, // bEndpointAddress
  1016. 0x03, // bmAttributes (0x03=intr)
  1017. SEREMU_TX_SIZE, 0, // wMaxPacketSize
  1018. SEREMU_TX_INTERVAL, // bInterval
  1019. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1020. 7, // bLength
  1021. 5, // bDescriptorType
  1022. SEREMU_RX_ENDPOINT, // bEndpointAddress
  1023. 0x03, // bmAttributes (0x03=intr)
  1024. SEREMU_RX_SIZE, 0, // wMaxPacketSize
  1025. SEREMU_RX_INTERVAL, // bInterval
  1026. #endif // SEREMU_INTERFACE
  1027. #ifdef JOYSTICK_INTERFACE
  1028. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1029. 9, // bLength
  1030. 4, // bDescriptorType
  1031. JOYSTICK_INTERFACE, // bInterfaceNumber
  1032. 0, // bAlternateSetting
  1033. 1, // bNumEndpoints
  1034. 0x03, // bInterfaceClass (0x03 = HID)
  1035. 0x00, // bInterfaceSubClass
  1036. 0x00, // bInterfaceProtocol
  1037. 0, // iInterface
  1038. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1039. 9, // bLength
  1040. 0x21, // bDescriptorType
  1041. 0x11, 0x01, // bcdHID
  1042. 0, // bCountryCode
  1043. 1, // bNumDescriptors
  1044. 0x22, // bDescriptorType
  1045. LSB(sizeof(joystick_report_desc)), // wDescriptorLength
  1046. MSB(sizeof(joystick_report_desc)),
  1047. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1048. 7, // bLength
  1049. 5, // bDescriptorType
  1050. JOYSTICK_ENDPOINT | 0x80, // bEndpointAddress
  1051. 0x03, // bmAttributes (0x03=intr)
  1052. JOYSTICK_SIZE, 0, // wMaxPacketSize
  1053. JOYSTICK_INTERVAL, // bInterval
  1054. #endif // JOYSTICK_INTERFACE
  1055. #ifdef MTP_INTERFACE
  1056. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1057. 9, // bLength
  1058. 4, // bDescriptorType
  1059. MTP_INTERFACE, // bInterfaceNumber
  1060. 0, // bAlternateSetting
  1061. 3, // bNumEndpoints
  1062. 0x06, // bInterfaceClass (0x06 = still image)
  1063. 0x01, // bInterfaceSubClass
  1064. 0x01, // bInterfaceProtocol
  1065. 0, // iInterface
  1066. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1067. 7, // bLength
  1068. 5, // bDescriptorType
  1069. MTP_TX_ENDPOINT | 0x80, // bEndpointAddress
  1070. 0x02, // bmAttributes (0x02=bulk)
  1071. MTP_TX_SIZE, 0, // wMaxPacketSize
  1072. 0, // bInterval
  1073. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1074. 7, // bLength
  1075. 5, // bDescriptorType
  1076. MTP_RX_ENDPOINT, // bEndpointAddress
  1077. 0x02, // bmAttributes (0x02=bulk)
  1078. MTP_RX_SIZE, 0, // wMaxPacketSize
  1079. 0, // bInterval
  1080. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1081. 7, // bLength
  1082. 5, // bDescriptorType
  1083. MTP_EVENT_ENDPOINT | 0x80, // bEndpointAddress
  1084. 0x03, // bmAttributes (0x03=intr)
  1085. MTP_EVENT_SIZE, 0, // wMaxPacketSize
  1086. MTP_EVENT_INTERVAL, // bInterval
  1087. #endif // MTP_INTERFACE
  1088. #ifdef KEYMEDIA_INTERFACE
  1089. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1090. 9, // bLength
  1091. 4, // bDescriptorType
  1092. KEYMEDIA_INTERFACE, // bInterfaceNumber
  1093. 0, // bAlternateSetting
  1094. 1, // bNumEndpoints
  1095. 0x03, // bInterfaceClass (0x03 = HID)
  1096. 0x00, // bInterfaceSubClass
  1097. 0x00, // bInterfaceProtocol
  1098. 0, // iInterface
  1099. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1100. 9, // bLength
  1101. 0x21, // bDescriptorType
  1102. 0x11, 0x01, // bcdHID
  1103. 0, // bCountryCode
  1104. 1, // bNumDescriptors
  1105. 0x22, // bDescriptorType
  1106. LSB(sizeof(keymedia_report_desc)), // wDescriptorLength
  1107. MSB(sizeof(keymedia_report_desc)),
  1108. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1109. 7, // bLength
  1110. 5, // bDescriptorType
  1111. KEYMEDIA_ENDPOINT | 0x80, // bEndpointAddress
  1112. 0x03, // bmAttributes (0x03=intr)
  1113. KEYMEDIA_SIZE, 0, // wMaxPacketSize
  1114. KEYMEDIA_INTERVAL, // bInterval
  1115. #endif // KEYMEDIA_INTERFACE
  1116. #ifdef AUDIO_INTERFACE
  1117. // interface association descriptor, USB ECN, Table 9-Z
  1118. 8, // bLength
  1119. 11, // bDescriptorType
  1120. AUDIO_INTERFACE, // bFirstInterface
  1121. 3, // bInterfaceCount
  1122. 0x01, // bFunctionClass
  1123. 0x01, // bFunctionSubClass
  1124. 0x00, // bFunctionProtocol
  1125. 0, // iFunction
  1126. // Standard AudioControl (AC) Interface Descriptor
  1127. // USB DCD for Audio Devices 1.0, Table 4-1, page 36
  1128. 9, // bLength
  1129. 4, // bDescriptorType, 4 = INTERFACE
  1130. AUDIO_INTERFACE, // bInterfaceNumber
  1131. 0, // bAlternateSetting
  1132. 0, // bNumEndpoints
  1133. 1, // bInterfaceClass, 1 = AUDIO
  1134. 1, // bInterfaceSubclass, 1 = AUDIO_CONTROL
  1135. 0, // bInterfaceProtocol
  1136. 0, // iInterface
  1137. // Class-specific AC Interface Header Descriptor
  1138. // USB DCD for Audio Devices 1.0, Table 4-2, page 37-38
  1139. 10, // bLength
  1140. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1141. 0x01, // bDescriptorSubtype, 1 = HEADER
  1142. 0x00, 0x01, // bcdADC (version 1.0)
  1143. LSB(62), MSB(62), // wTotalLength
  1144. 2, // bInCollection
  1145. AUDIO_INTERFACE+1, // baInterfaceNr(1) - Transmit to PC
  1146. AUDIO_INTERFACE+2, // baInterfaceNr(2) - Receive from PC
  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. 0x02, // bDescriptorSubType, 2 = INPUT_TERMINAL
  1152. 1, // bTerminalID
  1153. //0x01, 0x02, // wTerminalType, 0x0201 = MICROPHONE
  1154. //0x03, 0x06, // wTerminalType, 0x0603 = Line Connector
  1155. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  1156. 0, // bAssocTerminal, 0 = unidirectional
  1157. 2, // bNrChannels
  1158. 0x03, 0x00, // wChannelConfig, 0x0003 = Left & Right Front
  1159. 0, // iChannelNames
  1160. 0, // iTerminal
  1161. // Output Terminal Descriptor
  1162. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  1163. 9, // bLength
  1164. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1165. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  1166. 2, // bTerminalID
  1167. 0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
  1168. 0, // bAssocTerminal, 0 = unidirectional
  1169. 1, // bCSourceID, connected to input terminal, ID=1
  1170. 0, // iTerminal
  1171. // Input Terminal Descriptor
  1172. // USB DCD for Audio Devices 1.0, Table 4-3, page 39
  1173. 12, // bLength
  1174. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1175. 2, // bDescriptorSubType, 2 = INPUT_TERMINAL
  1176. 3, // bTerminalID
  1177. 0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
  1178. 0, // bAssocTerminal, 0 = unidirectional
  1179. 2, // bNrChannels
  1180. 0x03, 0x00, // wChannelConfig, 0x0003 = Left & Right Front
  1181. 0, // iChannelNames
  1182. 0, // iTerminal
  1183. // Volume feature descriptor
  1184. 10, // bLength
  1185. 0x24, // bDescriptorType = CS_INTERFACE
  1186. 0x06, // bDescriptorSubType = FEATURE_UNIT
  1187. 0x31, // bUnitID
  1188. 0x03, // bSourceID (Input Terminal)
  1189. 0x01, // bControlSize (each channel is 1 byte, 3 channels)
  1190. 0x01, // bmaControls(0) Master: Mute
  1191. 0x02, // bmaControls(1) Left: Volume
  1192. 0x02, // bmaControls(2) Right: Volume
  1193. 0x00, // iFeature
  1194. // Output Terminal Descriptor
  1195. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  1196. 9, // bLength
  1197. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1198. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  1199. 4, // bTerminalID
  1200. //0x02, 0x03, // wTerminalType, 0x0302 = Headphones
  1201. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  1202. 0, // bAssocTerminal, 0 = unidirectional
  1203. 0x31, // bCSourceID, connected to feature, ID=31
  1204. 0, // iTerminal
  1205. // Standard AS Interface Descriptor
  1206. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  1207. // Alternate 0: default setting, disabled zero bandwidth
  1208. 9, // bLenght
  1209. 4, // bDescriptorType = INTERFACE
  1210. AUDIO_INTERFACE+1, // bInterfaceNumber
  1211. 0, // bAlternateSetting
  1212. 0, // bNumEndpoints
  1213. 1, // bInterfaceClass, 1 = AUDIO
  1214. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1215. 0, // bInterfaceProtocol
  1216. 0, // iInterface
  1217. // Alternate 1: streaming data
  1218. 9, // bLenght
  1219. 4, // bDescriptorType = INTERFACE
  1220. AUDIO_INTERFACE+1, // bInterfaceNumber
  1221. 1, // bAlternateSetting
  1222. 1, // bNumEndpoints
  1223. 1, // bInterfaceClass, 1 = AUDIO
  1224. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1225. 0, // bInterfaceProtocol
  1226. 0, // iInterface
  1227. // Class-Specific AS Interface Descriptor
  1228. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  1229. 7, // bLength
  1230. 0x24, // bDescriptorType = CS_INTERFACE
  1231. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  1232. 2, // bTerminalLink: Terminal ID = 2
  1233. 3, // bDelay (approx 3ms delay, audio lib updates)
  1234. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  1235. // Type I Format Descriptor
  1236. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  1237. 11, // bLength
  1238. 0x24, // bDescriptorType = CS_INTERFACE
  1239. 2, // bDescriptorSubtype = FORMAT_TYPE
  1240. 1, // bFormatType = FORMAT_TYPE_I
  1241. 2, // bNrChannels = 2
  1242. 2, // bSubFrameSize = 2 byte
  1243. 16, // bBitResolution = 16 bits
  1244. 1, // bSamFreqType = 1 frequency
  1245. LSB(44100), MSB(44100), 0, // tSamFreq
  1246. // Standard AS Isochronous Audio Data Endpoint Descriptor
  1247. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  1248. 9, // bLength
  1249. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1250. AUDIO_TX_ENDPOINT | 0x80, // bEndpointAddress
  1251. 0x09, // bmAttributes = isochronous, adaptive
  1252. LSB(AUDIO_TX_SIZE), MSB(AUDIO_TX_SIZE), // wMaxPacketSize
  1253. 1, // bInterval, 1 = every frame
  1254. 0, // bRefresh
  1255. 0, // bSynchAddress
  1256. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  1257. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  1258. 7, // bLength
  1259. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  1260. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  1261. 0x00, // bmAttributes
  1262. 0, // bLockDelayUnits, 1 = ms
  1263. 0x00, 0x00, // wLockDelay
  1264. // Standard AS Interface Descriptor
  1265. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  1266. // Alternate 0: default setting, disabled zero bandwidth
  1267. 9, // bLenght
  1268. 4, // bDescriptorType = INTERFACE
  1269. AUDIO_INTERFACE+2, // bInterfaceNumber
  1270. 0, // bAlternateSetting
  1271. 0, // bNumEndpoints
  1272. 1, // bInterfaceClass, 1 = AUDIO
  1273. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1274. 0, // bInterfaceProtocol
  1275. 0, // iInterface
  1276. // Alternate 1: streaming data
  1277. 9, // bLenght
  1278. 4, // bDescriptorType = INTERFACE
  1279. AUDIO_INTERFACE+2, // bInterfaceNumber
  1280. 1, // bAlternateSetting
  1281. 2, // bNumEndpoints
  1282. 1, // bInterfaceClass, 1 = AUDIO
  1283. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1284. 0, // bInterfaceProtocol
  1285. 0, // iInterface
  1286. // Class-Specific AS Interface Descriptor
  1287. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  1288. 7, // bLength
  1289. 0x24, // bDescriptorType = CS_INTERFACE
  1290. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  1291. 3, // bTerminalLink: Terminal ID = 3
  1292. 3, // bDelay (approx 3ms delay, audio lib updates)
  1293. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  1294. // Type I Format Descriptor
  1295. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  1296. 11, // bLength
  1297. 0x24, // bDescriptorType = CS_INTERFACE
  1298. 2, // bDescriptorSubtype = FORMAT_TYPE
  1299. 1, // bFormatType = FORMAT_TYPE_I
  1300. 2, // bNrChannels = 2
  1301. 2, // bSubFrameSize = 2 byte
  1302. 16, // bBitResolution = 16 bits
  1303. 1, // bSamFreqType = 1 frequency
  1304. LSB(44100), MSB(44100), 0, // tSamFreq
  1305. // Standard AS Isochronous Audio Data Endpoint Descriptor
  1306. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  1307. 9, // bLength
  1308. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1309. AUDIO_RX_ENDPOINT, // bEndpointAddress
  1310. 0x05, // bmAttributes = isochronous, asynchronous
  1311. LSB(AUDIO_RX_SIZE), MSB(AUDIO_RX_SIZE), // wMaxPacketSize
  1312. 1, // bInterval, 1 = every frame
  1313. 0, // bRefresh
  1314. AUDIO_SYNC_ENDPOINT | 0x80, // bSynchAddress
  1315. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  1316. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  1317. 7, // bLength
  1318. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  1319. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  1320. 0x00, // bmAttributes
  1321. 0, // bLockDelayUnits, 1 = ms
  1322. 0x00, 0x00, // wLockDelay
  1323. // Standard AS Isochronous Audio Synch Endpoint Descriptor
  1324. // USB DCD for Audio Devices 1.0, Section 4.6.2.1, Table 4-22, page 63-64
  1325. 9, // bLength
  1326. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1327. AUDIO_SYNC_ENDPOINT | 0x80, // bEndpointAddress
  1328. 0x11, // bmAttributes = isochronous, feedback
  1329. 3, 0, // wMaxPacketSize, 3 bytes
  1330. 1, // bInterval, 1 = every frame
  1331. 5, // bRefresh, 5 = 32ms
  1332. 0, // bSynchAddress
  1333. #endif
  1334. #ifdef MULTITOUCH_INTERFACE
  1335. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1336. 9, // bLength
  1337. 4, // bDescriptorType
  1338. MULTITOUCH_INTERFACE, // bInterfaceNumber
  1339. 0, // bAlternateSetting
  1340. 1, // bNumEndpoints
  1341. 0x03, // bInterfaceClass (0x03 = HID)
  1342. 0x00, // bInterfaceSubClass
  1343. 0x00, // bInterfaceProtocol
  1344. 0, // iInterface
  1345. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1346. 9, // bLength
  1347. 0x21, // bDescriptorType
  1348. 0x11, 0x01, // bcdHID
  1349. 0, // bCountryCode
  1350. 1, // bNumDescriptors
  1351. 0x22, // bDescriptorType
  1352. LSB(sizeof(multitouch_report_desc)), // wDescriptorLength
  1353. MSB(sizeof(multitouch_report_desc)),
  1354. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1355. 7, // bLength
  1356. 5, // bDescriptorType
  1357. MULTITOUCH_ENDPOINT | 0x80, // bEndpointAddress
  1358. 0x03, // bmAttributes (0x03=intr)
  1359. MULTITOUCH_SIZE, 0, // wMaxPacketSize
  1360. 1, // bInterval
  1361. #endif // KEYMEDIA_INTERFACE
  1362. };
  1363. // **************************************************************
  1364. // String Descriptors
  1365. // **************************************************************
  1366. // The descriptors above can provide human readable strings,
  1367. // referenced by index numbers. These descriptors are the
  1368. // actual string data
  1369. /* defined in usb_names.h
  1370. struct usb_string_descriptor_struct {
  1371. uint8_t bLength;
  1372. uint8_t bDescriptorType;
  1373. uint16_t wString[];
  1374. };
  1375. */
  1376. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  1377. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  1378. extern struct usb_string_descriptor_struct usb_string_product_name
  1379. __attribute__ ((weak, alias("usb_string_product_name_default")));
  1380. extern struct usb_string_descriptor_struct usb_string_serial_number
  1381. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  1382. struct usb_string_descriptor_struct string0 = {
  1383. 4,
  1384. 3,
  1385. {0x0409}
  1386. };
  1387. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  1388. 2 + MANUFACTURER_NAME_LEN * 2,
  1389. 3,
  1390. MANUFACTURER_NAME
  1391. };
  1392. struct usb_string_descriptor_struct usb_string_product_name_default = {
  1393. 2 + PRODUCT_NAME_LEN * 2,
  1394. 3,
  1395. PRODUCT_NAME
  1396. };
  1397. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  1398. 12,
  1399. 3,
  1400. {0,0,0,0,0,0,0,0,0,0}
  1401. };
  1402. #ifdef MTP_INTERFACE
  1403. struct usb_string_descriptor_struct usb_string_mtp = {
  1404. 2 + 3 * 2,
  1405. 3,
  1406. {'M','T','P'}
  1407. };
  1408. #endif
  1409. void usb_init_serialnumber(void)
  1410. {
  1411. char buf[11];
  1412. uint32_t i, num;
  1413. __disable_irq();
  1414. #if defined(HAS_KINETIS_FLASH_FTFA) || defined(HAS_KINETIS_FLASH_FTFL)
  1415. FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
  1416. FTFL_FCCOB0 = 0x41;
  1417. FTFL_FCCOB1 = 15;
  1418. FTFL_FSTAT = FTFL_FSTAT_CCIF;
  1419. while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
  1420. num = *(uint32_t *)&FTFL_FCCOB7;
  1421. #elif defined(HAS_KINETIS_FLASH_FTFE)
  1422. kinetis_hsrun_disable();
  1423. FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
  1424. *(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
  1425. FTFL_FSTAT = FTFL_FSTAT_CCIF;
  1426. while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
  1427. num = *(uint32_t *)&FTFL_FCCOBB;
  1428. kinetis_hsrun_enable();
  1429. #endif
  1430. __enable_irq();
  1431. // add extra zero to work around OS-X CDC-ACM driver bug
  1432. if (num < 10000000) num = num * 10;
  1433. ultoa(num, buf, 10);
  1434. for (i=0; i<10; i++) {
  1435. char c = buf[i];
  1436. if (!c) break;
  1437. usb_string_serial_number_default.wString[i] = c;
  1438. }
  1439. usb_string_serial_number_default.bLength = i * 2 + 2;
  1440. }
  1441. // **************************************************************
  1442. // Descriptors List
  1443. // **************************************************************
  1444. // This table provides access to all the descriptor data above.
  1445. const usb_descriptor_list_t usb_descriptor_list[] = {
  1446. //wValue, wIndex, address, length
  1447. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  1448. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  1449. #ifdef SEREMU_INTERFACE
  1450. {0x2200, SEREMU_INTERFACE, seremu_report_desc, sizeof(seremu_report_desc)},
  1451. {0x2100, SEREMU_INTERFACE, config_descriptor+SEREMU_HID_DESC_OFFSET, 9},
  1452. #endif
  1453. #ifdef KEYBOARD_INTERFACE
  1454. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  1455. {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_HID_DESC_OFFSET, 9},
  1456. #endif
  1457. #ifdef MOUSE_INTERFACE
  1458. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  1459. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_HID_DESC_OFFSET, 9},
  1460. #endif
  1461. #ifdef JOYSTICK_INTERFACE
  1462. {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
  1463. {0x2100, JOYSTICK_INTERFACE, config_descriptor+JOYSTICK_HID_DESC_OFFSET, 9},
  1464. #endif
  1465. #ifdef RAWHID_INTERFACE
  1466. {0x2200, RAWHID_INTERFACE, rawhid_report_desc, sizeof(rawhid_report_desc)},
  1467. {0x2100, RAWHID_INTERFACE, config_descriptor+RAWHID_HID_DESC_OFFSET, 9},
  1468. #endif
  1469. #ifdef FLIGHTSIM_INTERFACE
  1470. {0x2200, FLIGHTSIM_INTERFACE, flightsim_report_desc, sizeof(flightsim_report_desc)},
  1471. {0x2100, FLIGHTSIM_INTERFACE, config_descriptor+FLIGHTSIM_HID_DESC_OFFSET, 9},
  1472. #endif
  1473. #ifdef KEYMEDIA_INTERFACE
  1474. {0x2200, KEYMEDIA_INTERFACE, keymedia_report_desc, sizeof(keymedia_report_desc)},
  1475. {0x2100, KEYMEDIA_INTERFACE, config_descriptor+KEYMEDIA_HID_DESC_OFFSET, 9},
  1476. #endif
  1477. #ifdef MULTITOUCH_INTERFACE
  1478. {0x2200, MULTITOUCH_INTERFACE, multitouch_report_desc, sizeof(multitouch_report_desc)},
  1479. {0x2100, MULTITOUCH_INTERFACE, config_descriptor+MULTITOUCH_HID_DESC_OFFSET, 9},
  1480. #endif
  1481. #ifdef MTP_INTERFACE
  1482. {0x0304, 0x0409, (const uint8_t *)&usb_string_mtp, 0},
  1483. #endif
  1484. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  1485. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  1486. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  1487. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  1488. {0, 0, NULL, 0}
  1489. };
  1490. // **************************************************************
  1491. // Endpoint Configuration
  1492. // **************************************************************
  1493. #if 0
  1494. // 0x00 = not used
  1495. // 0x19 = Recieve only
  1496. // 0x15 = Transmit only
  1497. // 0x1D = Transmit & Recieve
  1498. //
  1499. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1500. {
  1501. 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
  1502. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1503. };
  1504. #endif
  1505. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1506. {
  1507. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  1508. ENDPOINT1_CONFIG,
  1509. #elif (NUM_ENDPOINTS >= 1)
  1510. ENDPOINT_UNUSED,
  1511. #endif
  1512. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  1513. ENDPOINT2_CONFIG,
  1514. #elif (NUM_ENDPOINTS >= 2)
  1515. ENDPOINT_UNUSED,
  1516. #endif
  1517. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  1518. ENDPOINT3_CONFIG,
  1519. #elif (NUM_ENDPOINTS >= 3)
  1520. ENDPOINT_UNUSED,
  1521. #endif
  1522. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  1523. ENDPOINT4_CONFIG,
  1524. #elif (NUM_ENDPOINTS >= 4)
  1525. ENDPOINT_UNUSED,
  1526. #endif
  1527. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  1528. ENDPOINT5_CONFIG,
  1529. #elif (NUM_ENDPOINTS >= 5)
  1530. ENDPOINT_UNUSED,
  1531. #endif
  1532. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  1533. ENDPOINT6_CONFIG,
  1534. #elif (NUM_ENDPOINTS >= 6)
  1535. ENDPOINT_UNUSED,
  1536. #endif
  1537. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  1538. ENDPOINT7_CONFIG,
  1539. #elif (NUM_ENDPOINTS >= 7)
  1540. ENDPOINT_UNUSED,
  1541. #endif
  1542. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  1543. ENDPOINT8_CONFIG,
  1544. #elif (NUM_ENDPOINTS >= 8)
  1545. ENDPOINT_UNUSED,
  1546. #endif
  1547. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  1548. ENDPOINT9_CONFIG,
  1549. #elif (NUM_ENDPOINTS >= 9)
  1550. ENDPOINT_UNUSED,
  1551. #endif
  1552. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  1553. ENDPOINT10_CONFIG,
  1554. #elif (NUM_ENDPOINTS >= 10)
  1555. ENDPOINT_UNUSED,
  1556. #endif
  1557. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  1558. ENDPOINT11_CONFIG,
  1559. #elif (NUM_ENDPOINTS >= 11)
  1560. ENDPOINT_UNUSED,
  1561. #endif
  1562. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  1563. ENDPOINT12_CONFIG,
  1564. #elif (NUM_ENDPOINTS >= 12)
  1565. ENDPOINT_UNUSED,
  1566. #endif
  1567. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  1568. ENDPOINT13_CONFIG,
  1569. #elif (NUM_ENDPOINTS >= 13)
  1570. ENDPOINT_UNUSED,
  1571. #endif
  1572. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  1573. ENDPOINT14_CONFIG,
  1574. #elif (NUM_ENDPOINTS >= 14)
  1575. ENDPOINT_UNUSED,
  1576. #endif
  1577. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  1578. ENDPOINT15_CONFIG,
  1579. #elif (NUM_ENDPOINTS >= 15)
  1580. ENDPOINT_UNUSED,
  1581. #endif
  1582. };
  1583. #endif // NUM_ENDPOINTS
  1584. #endif // F_CPU >= 20 MHz