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.

1615 lines
74KB

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