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.

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