Teensy 4.1 core updated for C++20
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1275 lines
60KB

  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 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. 0x00, 0x02, // 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. 0x00, 0x02, // bcdDevice
  82. 1, // iManufacturer
  83. 2, // iProduct
  84. 3, // iSerialNumber
  85. 1 // bNumConfigurations
  86. };
  87. // These descriptors must NOT be "const", because the USB DMA
  88. // has trouble accessing flash memory with enough bandwidth
  89. // while the processor is executing from flash.
  90. // **************************************************************
  91. // HID Report Descriptors
  92. // **************************************************************
  93. // Each HID interface needs a special report descriptor that tells
  94. // the meaning and format of the data.
  95. #ifdef KEYBOARD_INTERFACE
  96. // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
  97. static uint8_t keyboard_report_desc[] = {
  98. 0x05, 0x01, // Usage Page (Generic Desktop),
  99. 0x09, 0x06, // Usage (Keyboard),
  100. 0xA1, 0x01, // Collection (Application),
  101. 0x75, 0x01, // Report Size (1),
  102. 0x95, 0x08, // Report Count (8),
  103. 0x05, 0x07, // Usage Page (Key Codes),
  104. 0x19, 0xE0, // Usage Minimum (224),
  105. 0x29, 0xE7, // Usage Maximum (231),
  106. 0x15, 0x00, // Logical Minimum (0),
  107. 0x25, 0x01, // Logical Maximum (1),
  108. 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier keys
  109. 0x95, 0x01, // Report Count (1),
  110. 0x75, 0x08, // Report Size (8),
  111. 0x81, 0x03, // Input (Constant), ;Reserved byte
  112. 0x95, 0x05, // Report Count (5),
  113. 0x75, 0x01, // Report Size (1),
  114. 0x05, 0x08, // Usage Page (LEDs),
  115. 0x19, 0x01, // Usage Minimum (1),
  116. 0x29, 0x05, // Usage Maximum (5),
  117. 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
  118. 0x95, 0x01, // Report Count (1),
  119. 0x75, 0x03, // Report Size (3),
  120. 0x91, 0x03, // Output (Constant), ;LED report padding
  121. 0x95, 0x06, // Report Count (6),
  122. 0x75, 0x08, // Report Size (8),
  123. 0x15, 0x00, // Logical Minimum (0),
  124. 0x25, 0x7F, // Logical Maximum(104),
  125. 0x05, 0x07, // Usage Page (Key Codes),
  126. 0x19, 0x00, // Usage Minimum (0),
  127. 0x29, 0x7F, // Usage Maximum (104),
  128. 0x81, 0x00, // Input (Data, Array), ;Normal keys
  129. 0xC0 // End Collection
  130. };
  131. #endif
  132. #ifdef KEYMEDIA_INTERFACE
  133. static uint8_t keymedia_report_desc[] = {
  134. 0x05, 0x0C, // Usage Page (Consumer)
  135. 0x09, 0x01, // Usage (Consumer Controls)
  136. 0xA1, 0x01, // Collection (Application)
  137. 0x75, 0x0A, // Report Size (10)
  138. 0x95, 0x04, // Report Count (4)
  139. 0x19, 0x00, // Usage Minimum (0)
  140. 0x2A, 0x9C, 0x02, // Usage Maximum (0x29C)
  141. 0x15, 0x00, // Logical Minimum (0)
  142. 0x26, 0x9C, 0x02, // Logical Maximum (0x29C)
  143. 0x81, 0x00, // Input (Data, Array)
  144. 0x05, 0x01, // Usage Page (Generic Desktop)
  145. 0x75, 0x08, // Report Size (8)
  146. 0x95, 0x03, // Report Count (3)
  147. 0x19, 0x00, // Usage Minimum (0)
  148. 0x29, 0xB7, // Usage Maximum (0xB7)
  149. 0x15, 0x00, // Logical Minimum (0)
  150. 0x26, 0xB7, 0x00, // Logical Maximum (0xB7)
  151. 0x81, 0x00, // Input (Data, Array)
  152. 0xC0 // End Collection
  153. };
  154. #endif
  155. #ifdef MOUSE_INTERFACE
  156. // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
  157. static uint8_t mouse_report_desc[] = {
  158. 0x05, 0x01, // Usage Page (Generic Desktop)
  159. 0x09, 0x02, // Usage (Mouse)
  160. 0xA1, 0x01, // Collection (Application)
  161. 0x85, 0x01, // REPORT_ID (1)
  162. 0x05, 0x09, // Usage Page (Button)
  163. 0x19, 0x01, // Usage Minimum (Button #1)
  164. 0x29, 0x08, // Usage Maximum (Button #8)
  165. 0x15, 0x00, // Logical Minimum (0)
  166. 0x25, 0x01, // Logical Maximum (1)
  167. 0x95, 0x08, // Report Count (8)
  168. 0x75, 0x01, // Report Size (1)
  169. 0x81, 0x02, // Input (Data, Variable, Absolute)
  170. 0x05, 0x01, // Usage Page (Generic Desktop)
  171. 0x09, 0x30, // Usage (X)
  172. 0x09, 0x31, // Usage (Y)
  173. 0x09, 0x38, // Usage (Wheel)
  174. 0x15, 0x81, // Logical Minimum (-127)
  175. 0x25, 0x7F, // Logical Maximum (127)
  176. 0x75, 0x08, // Report Size (8),
  177. 0x95, 0x03, // Report Count (3),
  178. 0x81, 0x06, // Input (Data, Variable, Relative)
  179. 0xC0, // End Collection
  180. 0x05, 0x01, // Usage Page (Generic Desktop)
  181. 0x09, 0x02, // Usage (Mouse)
  182. 0xA1, 0x01, // Collection (Application)
  183. 0x85, 0x02, // REPORT_ID (2)
  184. 0x05, 0x01, // Usage Page (Generic Desktop)
  185. 0x09, 0x30, // Usage (X)
  186. 0x09, 0x31, // Usage (Y)
  187. 0x15, 0x00, // Logical Minimum (0)
  188. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  189. 0x75, 0x10, // Report Size (16),
  190. 0x95, 0x02, // Report Count (2),
  191. 0x81, 0x02, // Input (Data, Variable, Absolute)
  192. 0xC0 // End Collection
  193. };
  194. #endif
  195. #ifdef JOYSTICK_INTERFACE
  196. static uint8_t joystick_report_desc[] = {
  197. 0x05, 0x01, // Usage Page (Generic Desktop)
  198. 0x09, 0x04, // Usage (Joystick)
  199. 0xA1, 0x01, // Collection (Application)
  200. 0x15, 0x00, // Logical Minimum (0)
  201. 0x25, 0x01, // Logical Maximum (1)
  202. 0x75, 0x01, // Report Size (1)
  203. 0x95, 0x20, // Report Count (32)
  204. 0x05, 0x09, // Usage Page (Button)
  205. 0x19, 0x01, // Usage Minimum (Button #1)
  206. 0x29, 0x20, // Usage Maximum (Button #32)
  207. 0x81, 0x02, // Input (variable,absolute)
  208. 0x15, 0x00, // Logical Minimum (0)
  209. 0x25, 0x07, // Logical Maximum (7)
  210. 0x35, 0x00, // Physical Minimum (0)
  211. 0x46, 0x3B, 0x01, // Physical Maximum (315)
  212. 0x75, 0x04, // Report Size (4)
  213. 0x95, 0x01, // Report Count (1)
  214. 0x65, 0x14, // Unit (20)
  215. 0x05, 0x01, // Usage Page (Generic Desktop)
  216. 0x09, 0x39, // Usage (Hat switch)
  217. 0x81, 0x42, // Input (variable,absolute,null_state)
  218. 0x05, 0x01, // Usage Page (Generic Desktop)
  219. 0x09, 0x01, // Usage (Pointer)
  220. 0xA1, 0x00, // Collection ()
  221. 0x15, 0x00, // Logical Minimum (0)
  222. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  223. 0x75, 0x0A, // Report Size (10)
  224. 0x95, 0x04, // Report Count (4)
  225. 0x09, 0x30, // Usage (X)
  226. 0x09, 0x31, // Usage (Y)
  227. 0x09, 0x32, // Usage (Z)
  228. 0x09, 0x35, // Usage (Rz)
  229. 0x81, 0x02, // Input (variable,absolute)
  230. 0xC0, // End Collection
  231. 0x15, 0x00, // Logical Minimum (0)
  232. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  233. 0x75, 0x0A, // Report Size (10)
  234. 0x95, 0x02, // Report Count (2)
  235. 0x09, 0x36, // Usage (Slider)
  236. 0x09, 0x36, // Usage (Slider)
  237. 0x81, 0x02, // Input (variable,absolute)
  238. 0xC0 // End Collection
  239. };
  240. #endif
  241. #ifdef SEREMU_INTERFACE
  242. static uint8_t seremu_report_desc[] = {
  243. 0x06, 0xC9, 0xFF, // Usage Page 0xFFC9 (vendor defined)
  244. 0x09, 0x04, // Usage 0x04
  245. 0xA1, 0x5C, // Collection 0x5C
  246. 0x75, 0x08, // report size = 8 bits (global)
  247. 0x15, 0x00, // logical minimum = 0 (global)
  248. 0x26, 0xFF, 0x00, // logical maximum = 255 (global)
  249. 0x95, SEREMU_TX_SIZE, // report count (global)
  250. 0x09, 0x75, // usage (local)
  251. 0x81, 0x02, // Input
  252. 0x95, SEREMU_RX_SIZE, // report count (global)
  253. 0x09, 0x76, // usage (local)
  254. 0x91, 0x02, // Output
  255. 0x95, 0x04, // report count (global)
  256. 0x09, 0x76, // usage (local)
  257. 0xB1, 0x02, // Feature
  258. 0xC0 // end collection
  259. };
  260. #endif
  261. #ifdef RAWHID_INTERFACE
  262. static uint8_t rawhid_report_desc[] = {
  263. 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),
  264. 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
  265. 0xA1, 0x01, // Collection 0x01
  266. 0x75, 0x08, // report size = 8 bits
  267. 0x15, 0x00, // logical minimum = 0
  268. 0x26, 0xFF, 0x00, // logical maximum = 255
  269. 0x95, RAWHID_TX_SIZE, // report count
  270. 0x09, 0x01, // usage
  271. 0x81, 0x02, // Input (array)
  272. 0x95, RAWHID_RX_SIZE, // report count
  273. 0x09, 0x02, // usage
  274. 0x91, 0x02, // Output (array)
  275. 0xC0 // end collection
  276. };
  277. #endif
  278. #ifdef FLIGHTSIM_INTERFACE
  279. static uint8_t flightsim_report_desc[] = {
  280. 0x06, 0x1C, 0xFF, // Usage page = 0xFF1C
  281. 0x0A, 0x39, 0xA7, // Usage = 0xA739
  282. 0xA1, 0x01, // Collection 0x01
  283. 0x75, 0x08, // report size = 8 bits
  284. 0x15, 0x00, // logical minimum = 0
  285. 0x26, 0xFF, 0x00, // logical maximum = 255
  286. 0x95, FLIGHTSIM_TX_SIZE, // report count
  287. 0x09, 0x01, // usage
  288. 0x81, 0x02, // Input (array)
  289. 0x95, FLIGHTSIM_RX_SIZE, // report count
  290. 0x09, 0x02, // usage
  291. 0x91, 0x02, // Output (array)
  292. 0xC0 // end collection
  293. };
  294. #endif
  295. // **************************************************************
  296. // USB Descriptor Sizes
  297. // **************************************************************
  298. // pre-compute the size and position of everything in the config descriptor
  299. //
  300. #define CONFIG_HEADER_DESCRIPTOR_SIZE 9
  301. #define CDC_IAD_DESCRIPTOR_POS CONFIG_HEADER_DESCRIPTOR_SIZE
  302. #ifdef CDC_IAD_DESCRIPTOR
  303. #define CDC_IAD_DESCRIPTOR_SIZE 8
  304. #else
  305. #define CDC_IAD_DESCRIPTOR_SIZE 0
  306. #endif
  307. #define CDC_DATA_INTERFACE_DESC_POS CDC_IAD_DESCRIPTOR_POS+CDC_IAD_DESCRIPTOR_SIZE
  308. #ifdef CDC_DATA_INTERFACE
  309. #define CDC_DATA_INTERFACE_DESC_SIZE 9+5+5+4+5+7+9+7+7
  310. #else
  311. #define CDC_DATA_INTERFACE_DESC_SIZE 0
  312. #endif
  313. #define MIDI_INTERFACE_DESC_POS CDC_DATA_INTERFACE_DESC_POS+CDC_DATA_INTERFACE_DESC_SIZE
  314. #ifdef MIDI_INTERFACE
  315. #define MIDI_INTERFACE_DESC_SIZE 9+7+6+6+9+9+9+5+9+5
  316. #else
  317. #define MIDI_INTERFACE_DESC_SIZE 0
  318. #endif
  319. #define KEYBOARD_INTERFACE_DESC_POS MIDI_INTERFACE_DESC_POS+MIDI_INTERFACE_DESC_SIZE
  320. #ifdef KEYBOARD_INTERFACE
  321. #define KEYBOARD_INTERFACE_DESC_SIZE 9+9+7
  322. #define KEYBOARD_HID_DESC_OFFSET KEYBOARD_INTERFACE_DESC_POS+9
  323. #else
  324. #define KEYBOARD_INTERFACE_DESC_SIZE 0
  325. #endif
  326. #define MOUSE_INTERFACE_DESC_POS KEYBOARD_INTERFACE_DESC_POS+KEYBOARD_INTERFACE_DESC_SIZE
  327. #ifdef MOUSE_INTERFACE
  328. #define MOUSE_INTERFACE_DESC_SIZE 9+9+7
  329. #define MOUSE_HID_DESC_OFFSET MOUSE_INTERFACE_DESC_POS+9
  330. #else
  331. #define MOUSE_INTERFACE_DESC_SIZE 0
  332. #endif
  333. #define RAWHID_INTERFACE_DESC_POS MOUSE_INTERFACE_DESC_POS+MOUSE_INTERFACE_DESC_SIZE
  334. #ifdef RAWHID_INTERFACE
  335. #define RAWHID_INTERFACE_DESC_SIZE 9+9+7+7
  336. #define RAWHID_HID_DESC_OFFSET RAWHID_INTERFACE_DESC_POS+9
  337. #else
  338. #define RAWHID_INTERFACE_DESC_SIZE 0
  339. #endif
  340. #define FLIGHTSIM_INTERFACE_DESC_POS RAWHID_INTERFACE_DESC_POS+RAWHID_INTERFACE_DESC_SIZE
  341. #ifdef FLIGHTSIM_INTERFACE
  342. #define FLIGHTSIM_INTERFACE_DESC_SIZE 9+9+7+7
  343. #define FLIGHTSIM_HID_DESC_OFFSET FLIGHTSIM_INTERFACE_DESC_POS+9
  344. #else
  345. #define FLIGHTSIM_INTERFACE_DESC_SIZE 0
  346. #endif
  347. #define SEREMU_INTERFACE_DESC_POS FLIGHTSIM_INTERFACE_DESC_POS+FLIGHTSIM_INTERFACE_DESC_SIZE
  348. #ifdef SEREMU_INTERFACE
  349. #define SEREMU_INTERFACE_DESC_SIZE 9+9+7+7
  350. #define SEREMU_HID_DESC_OFFSET SEREMU_INTERFACE_DESC_POS+9
  351. #else
  352. #define SEREMU_INTERFACE_DESC_SIZE 0
  353. #endif
  354. #define JOYSTICK_INTERFACE_DESC_POS SEREMU_INTERFACE_DESC_POS+SEREMU_INTERFACE_DESC_SIZE
  355. #ifdef JOYSTICK_INTERFACE
  356. #define JOYSTICK_INTERFACE_DESC_SIZE 9+9+7
  357. #define JOYSTICK_HID_DESC_OFFSET JOYSTICK_INTERFACE_DESC_POS+9
  358. #else
  359. #define JOYSTICK_INTERFACE_DESC_SIZE 0
  360. #endif
  361. #define MTP_INTERFACE_DESC_POS JOYSTICK_INTERFACE_DESC_POS+JOYSTICK_INTERFACE_DESC_SIZE
  362. #ifdef MTP_INTERFACE
  363. #define MTP_INTERFACE_DESC_SIZE 9+7+7+7
  364. #else
  365. #define MTP_INTERFACE_DESC_SIZE 0
  366. #endif
  367. #define KEYMEDIA_INTERFACE_DESC_POS MTP_INTERFACE_DESC_POS+MTP_INTERFACE_DESC_SIZE
  368. #ifdef KEYMEDIA_INTERFACE
  369. #define KEYMEDIA_INTERFACE_DESC_SIZE 9+9+7
  370. #define KEYMEDIA_HID_DESC_OFFSET KEYMEDIA_INTERFACE_DESC_POS+9
  371. #else
  372. #define KEYMEDIA_INTERFACE_DESC_SIZE 0
  373. #endif
  374. #define AUDIO_INTERFACE_DESC_POS KEYMEDIA_INTERFACE_DESC_POS+KEYMEDIA_INTERFACE_DESC_SIZE
  375. #ifdef AUDIO_INTERFACE
  376. #define AUDIO_INTERFACE_DESC_SIZE 9+10+12+9+12+9 + 9+9+7+11+9+7 + 9+9+7+11+9+7+9
  377. #else
  378. #define AUDIO_INTERFACE_DESC_SIZE 0
  379. #endif
  380. #define CONFIG_DESC_SIZE AUDIO_INTERFACE_DESC_POS+AUDIO_INTERFACE_DESC_SIZE
  381. // **************************************************************
  382. // USB Configuration
  383. // **************************************************************
  384. // USB Configuration Descriptor. This huge descriptor tells all
  385. // of the devices capbilities.
  386. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  387. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  388. 9, // bLength;
  389. 2, // bDescriptorType;
  390. LSB(CONFIG_DESC_SIZE), // wTotalLength
  391. MSB(CONFIG_DESC_SIZE),
  392. NUM_INTERFACE, // bNumInterfaces
  393. 1, // bConfigurationValue
  394. 0, // iConfiguration
  395. 0xC0, // bmAttributes
  396. 50, // bMaxPower
  397. #ifdef CDC_IAD_DESCRIPTOR
  398. // interface association descriptor, USB ECN, Table 9-Z
  399. 8, // bLength
  400. 11, // bDescriptorType
  401. CDC_STATUS_INTERFACE, // bFirstInterface
  402. 2, // bInterfaceCount
  403. 0x02, // bFunctionClass
  404. 0x02, // bFunctionSubClass
  405. 0x01, // bFunctionProtocol
  406. 4, // iFunction
  407. #endif
  408. #ifdef CDC_DATA_INTERFACE
  409. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  410. 9, // bLength
  411. 4, // bDescriptorType
  412. CDC_STATUS_INTERFACE, // bInterfaceNumber
  413. 0, // bAlternateSetting
  414. 1, // bNumEndpoints
  415. 0x02, // bInterfaceClass
  416. 0x02, // bInterfaceSubClass
  417. 0x01, // bInterfaceProtocol
  418. 0, // iInterface
  419. // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
  420. 5, // bFunctionLength
  421. 0x24, // bDescriptorType
  422. 0x00, // bDescriptorSubtype
  423. 0x10, 0x01, // bcdCDC
  424. // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
  425. 5, // bFunctionLength
  426. 0x24, // bDescriptorType
  427. 0x01, // bDescriptorSubtype
  428. 0x01, // bmCapabilities
  429. 1, // bDataInterface
  430. // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
  431. 4, // bFunctionLength
  432. 0x24, // bDescriptorType
  433. 0x02, // bDescriptorSubtype
  434. 0x06, // bmCapabilities
  435. // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
  436. 5, // bFunctionLength
  437. 0x24, // bDescriptorType
  438. 0x06, // bDescriptorSubtype
  439. CDC_STATUS_INTERFACE, // bMasterInterface
  440. CDC_DATA_INTERFACE, // bSlaveInterface0
  441. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  442. 7, // bLength
  443. 5, // bDescriptorType
  444. CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
  445. 0x03, // bmAttributes (0x03=intr)
  446. CDC_ACM_SIZE, 0, // wMaxPacketSize
  447. 64, // bInterval
  448. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  449. 9, // bLength
  450. 4, // bDescriptorType
  451. CDC_DATA_INTERFACE, // bInterfaceNumber
  452. 0, // bAlternateSetting
  453. 2, // bNumEndpoints
  454. 0x0A, // bInterfaceClass
  455. 0x00, // bInterfaceSubClass
  456. 0x00, // bInterfaceProtocol
  457. 0, // iInterface
  458. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  459. 7, // bLength
  460. 5, // bDescriptorType
  461. CDC_RX_ENDPOINT, // bEndpointAddress
  462. 0x02, // bmAttributes (0x02=bulk)
  463. CDC_RX_SIZE, 0, // wMaxPacketSize
  464. 0, // bInterval
  465. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  466. 7, // bLength
  467. 5, // bDescriptorType
  468. CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
  469. 0x02, // bmAttributes (0x02=bulk)
  470. CDC_TX_SIZE, 0, // wMaxPacketSize
  471. 0, // bInterval
  472. #endif // CDC_DATA_INTERFACE
  473. #ifdef MIDI_INTERFACE
  474. // Standard MS Interface Descriptor,
  475. 9, // bLength
  476. 4, // bDescriptorType
  477. MIDI_INTERFACE, // bInterfaceNumber
  478. 0, // bAlternateSetting
  479. 2, // bNumEndpoints
  480. 0x01, // bInterfaceClass (0x01 = Audio)
  481. 0x03, // bInterfaceSubClass (0x03 = MIDI)
  482. 0x00, // bInterfaceProtocol (unused for MIDI)
  483. 0, // iInterface
  484. // MIDI MS Interface Header, USB MIDI 6.1.2.1, page 21, Table 6-2
  485. 7, // bLength
  486. 0x24, // bDescriptorType = CS_INTERFACE
  487. 0x01, // bDescriptorSubtype = MS_HEADER
  488. 0x00, 0x01, // bcdMSC = revision 01.00
  489. 0x41, 0x00, // wTotalLength
  490. // MIDI IN Jack Descriptor, B.4.3, Table B-7 (embedded), page 40
  491. 6, // bLength
  492. 0x24, // bDescriptorType = CS_INTERFACE
  493. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  494. 0x01, // bJackType = EMBEDDED
  495. 1, // bJackID, ID = 1
  496. 0, // iJack
  497. // MIDI IN Jack Descriptor, B.4.3, Table B-8 (external), page 40
  498. 6, // bLength
  499. 0x24, // bDescriptorType = CS_INTERFACE
  500. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  501. 0x02, // bJackType = EXTERNAL
  502. 2, // bJackID, ID = 2
  503. 0, // iJack
  504. // MIDI OUT Jack Descriptor, B.4.4, Table B-9, page 41
  505. 9,
  506. 0x24, // bDescriptorType = CS_INTERFACE
  507. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  508. 0x01, // bJackType = EMBEDDED
  509. 3, // bJackID, ID = 3
  510. 1, // bNrInputPins = 1 pin
  511. 2, // BaSourceID(1) = 2
  512. 1, // BaSourcePin(1) = first pin
  513. 0, // iJack
  514. // MIDI OUT Jack Descriptor, B.4.4, Table B-10, page 41
  515. 9,
  516. 0x24, // bDescriptorType = CS_INTERFACE
  517. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  518. 0x02, // bJackType = EXTERNAL
  519. 4, // bJackID, ID = 4
  520. 1, // bNrInputPins = 1 pin
  521. 1, // BaSourceID(1) = 1
  522. 1, // BaSourcePin(1) = first pin
  523. 0, // iJack
  524. // Standard Bulk OUT Endpoint Descriptor, B.5.1, Table B-11, pae 42
  525. 9, // bLength
  526. 5, // bDescriptorType = ENDPOINT
  527. MIDI_RX_ENDPOINT, // bEndpointAddress
  528. 0x02, // bmAttributes (0x02=bulk)
  529. MIDI_RX_SIZE, 0, // wMaxPacketSize
  530. 0, // bInterval
  531. 0, // bRefresh
  532. 0, // bSynchAddress
  533. // Class-specific MS Bulk OUT Endpoint Descriptor, B.5.2, Table B-12, page 42
  534. 5, // bLength
  535. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  536. 0x01, // bJackType = MS_GENERAL
  537. 1, // bNumEmbMIDIJack = 1 jack
  538. 1, // BaAssocJackID(1) = jack ID #1
  539. // Standard Bulk IN Endpoint Descriptor, B.5.1, Table B-11, pae 42
  540. 9, // bLength
  541. 5, // bDescriptorType = ENDPOINT
  542. MIDI_TX_ENDPOINT | 0x80, // bEndpointAddress
  543. 0x02, // bmAttributes (0x02=bulk)
  544. MIDI_TX_SIZE, 0, // wMaxPacketSize
  545. 0, // bInterval
  546. 0, // bRefresh
  547. 0, // bSynchAddress
  548. // Class-specific MS Bulk IN Endpoint Descriptor, B.5.2, Table B-12, page 42
  549. 5, // bLength
  550. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  551. 0x01, // bJackType = MS_GENERAL
  552. 1, // bNumEmbMIDIJack = 1 jack
  553. 3, // BaAssocJackID(1) = jack ID #3
  554. #endif // MIDI_INTERFACE
  555. #ifdef KEYBOARD_INTERFACE
  556. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  557. 9, // bLength
  558. 4, // bDescriptorType
  559. KEYBOARD_INTERFACE, // bInterfaceNumber
  560. 0, // bAlternateSetting
  561. 1, // bNumEndpoints
  562. 0x03, // bInterfaceClass (0x03 = HID)
  563. 0x01, // bInterfaceSubClass (0x01 = Boot)
  564. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  565. 0, // iInterface
  566. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  567. 9, // bLength
  568. 0x21, // bDescriptorType
  569. 0x11, 0x01, // bcdHID
  570. 0, // bCountryCode
  571. 1, // bNumDescriptors
  572. 0x22, // bDescriptorType
  573. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  574. MSB(sizeof(keyboard_report_desc)),
  575. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  576. 7, // bLength
  577. 5, // bDescriptorType
  578. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  579. 0x03, // bmAttributes (0x03=intr)
  580. KEYBOARD_SIZE, 0, // wMaxPacketSize
  581. KEYBOARD_INTERVAL, // bInterval
  582. #endif // KEYBOARD_INTERFACE
  583. #ifdef MOUSE_INTERFACE
  584. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  585. 9, // bLength
  586. 4, // bDescriptorType
  587. MOUSE_INTERFACE, // bInterfaceNumber
  588. 0, // bAlternateSetting
  589. 1, // bNumEndpoints
  590. 0x03, // bInterfaceClass (0x03 = HID)
  591. 0x00, // bInterfaceSubClass (0x01 = Boot)
  592. 0x00, // bInterfaceProtocol (0x02 = Mouse)
  593. 0, // iInterface
  594. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  595. 9, // bLength
  596. 0x21, // bDescriptorType
  597. 0x11, 0x01, // bcdHID
  598. 0, // bCountryCode
  599. 1, // bNumDescriptors
  600. 0x22, // bDescriptorType
  601. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  602. MSB(sizeof(mouse_report_desc)),
  603. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  604. 7, // bLength
  605. 5, // bDescriptorType
  606. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  607. 0x03, // bmAttributes (0x03=intr)
  608. MOUSE_SIZE, 0, // wMaxPacketSize
  609. MOUSE_INTERVAL, // bInterval
  610. #endif // MOUSE_INTERFACE
  611. #ifdef RAWHID_INTERFACE
  612. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  613. 9, // bLength
  614. 4, // bDescriptorType
  615. RAWHID_INTERFACE, // bInterfaceNumber
  616. 0, // bAlternateSetting
  617. 2, // bNumEndpoints
  618. 0x03, // bInterfaceClass (0x03 = HID)
  619. 0x00, // bInterfaceSubClass
  620. 0x00, // bInterfaceProtocol
  621. 0, // iInterface
  622. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  623. 9, // bLength
  624. 0x21, // bDescriptorType
  625. 0x11, 0x01, // bcdHID
  626. 0, // bCountryCode
  627. 1, // bNumDescriptors
  628. 0x22, // bDescriptorType
  629. LSB(sizeof(rawhid_report_desc)), // wDescriptorLength
  630. MSB(sizeof(rawhid_report_desc)),
  631. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  632. 7, // bLength
  633. 5, // bDescriptorType
  634. RAWHID_TX_ENDPOINT | 0x80, // bEndpointAddress
  635. 0x03, // bmAttributes (0x03=intr)
  636. RAWHID_TX_SIZE, 0, // wMaxPacketSize
  637. RAWHID_TX_INTERVAL, // bInterval
  638. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  639. 7, // bLength
  640. 5, // bDescriptorType
  641. RAWHID_RX_ENDPOINT, // bEndpointAddress
  642. 0x03, // bmAttributes (0x03=intr)
  643. RAWHID_RX_SIZE, 0, // wMaxPacketSize
  644. RAWHID_RX_INTERVAL, // bInterval
  645. #endif // RAWHID_INTERFACE
  646. #ifdef FLIGHTSIM_INTERFACE
  647. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  648. 9, // bLength
  649. 4, // bDescriptorType
  650. FLIGHTSIM_INTERFACE, // bInterfaceNumber
  651. 0, // bAlternateSetting
  652. 2, // bNumEndpoints
  653. 0x03, // bInterfaceClass (0x03 = HID)
  654. 0x00, // bInterfaceSubClass
  655. 0x00, // bInterfaceProtocol
  656. 0, // iInterface
  657. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  658. 9, // bLength
  659. 0x21, // bDescriptorType
  660. 0x11, 0x01, // bcdHID
  661. 0, // bCountryCode
  662. 1, // bNumDescriptors
  663. 0x22, // bDescriptorType
  664. LSB(sizeof(flightsim_report_desc)), // wDescriptorLength
  665. MSB(sizeof(flightsim_report_desc)),
  666. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  667. 7, // bLength
  668. 5, // bDescriptorType
  669. FLIGHTSIM_TX_ENDPOINT | 0x80, // bEndpointAddress
  670. 0x03, // bmAttributes (0x03=intr)
  671. FLIGHTSIM_TX_SIZE, 0, // wMaxPacketSize
  672. FLIGHTSIM_TX_INTERVAL, // bInterval
  673. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  674. 7, // bLength
  675. 5, // bDescriptorType
  676. FLIGHTSIM_RX_ENDPOINT, // bEndpointAddress
  677. 0x03, // bmAttributes (0x03=intr)
  678. FLIGHTSIM_RX_SIZE, 0, // wMaxPacketSize
  679. FLIGHTSIM_RX_INTERVAL, // bInterval
  680. #endif // FLIGHTSIM_INTERFACE
  681. #ifdef SEREMU_INTERFACE
  682. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  683. 9, // bLength
  684. 4, // bDescriptorType
  685. SEREMU_INTERFACE, // bInterfaceNumber
  686. 0, // bAlternateSetting
  687. 2, // bNumEndpoints
  688. 0x03, // bInterfaceClass (0x03 = HID)
  689. 0x00, // bInterfaceSubClass
  690. 0x00, // bInterfaceProtocol
  691. 0, // iInterface
  692. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  693. 9, // bLength
  694. 0x21, // bDescriptorType
  695. 0x11, 0x01, // bcdHID
  696. 0, // bCountryCode
  697. 1, // bNumDescriptors
  698. 0x22, // bDescriptorType
  699. LSB(sizeof(seremu_report_desc)), // wDescriptorLength
  700. MSB(sizeof(seremu_report_desc)),
  701. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  702. 7, // bLength
  703. 5, // bDescriptorType
  704. SEREMU_TX_ENDPOINT | 0x80, // bEndpointAddress
  705. 0x03, // bmAttributes (0x03=intr)
  706. SEREMU_TX_SIZE, 0, // wMaxPacketSize
  707. SEREMU_TX_INTERVAL, // bInterval
  708. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  709. 7, // bLength
  710. 5, // bDescriptorType
  711. SEREMU_RX_ENDPOINT, // bEndpointAddress
  712. 0x03, // bmAttributes (0x03=intr)
  713. SEREMU_RX_SIZE, 0, // wMaxPacketSize
  714. SEREMU_RX_INTERVAL, // bInterval
  715. #endif // SEREMU_INTERFACE
  716. #ifdef JOYSTICK_INTERFACE
  717. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  718. 9, // bLength
  719. 4, // bDescriptorType
  720. JOYSTICK_INTERFACE, // bInterfaceNumber
  721. 0, // bAlternateSetting
  722. 1, // bNumEndpoints
  723. 0x03, // bInterfaceClass (0x03 = HID)
  724. 0x00, // bInterfaceSubClass
  725. 0x00, // bInterfaceProtocol
  726. 0, // iInterface
  727. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  728. 9, // bLength
  729. 0x21, // bDescriptorType
  730. 0x11, 0x01, // bcdHID
  731. 0, // bCountryCode
  732. 1, // bNumDescriptors
  733. 0x22, // bDescriptorType
  734. LSB(sizeof(joystick_report_desc)), // wDescriptorLength
  735. MSB(sizeof(joystick_report_desc)),
  736. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  737. 7, // bLength
  738. 5, // bDescriptorType
  739. JOYSTICK_ENDPOINT | 0x80, // bEndpointAddress
  740. 0x03, // bmAttributes (0x03=intr)
  741. JOYSTICK_SIZE, 0, // wMaxPacketSize
  742. JOYSTICK_INTERVAL, // bInterval
  743. #endif // JOYSTICK_INTERFACE
  744. #ifdef MTP_INTERFACE
  745. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  746. 9, // bLength
  747. 4, // bDescriptorType
  748. MTP_INTERFACE, // bInterfaceNumber
  749. 0, // bAlternateSetting
  750. 3, // bNumEndpoints
  751. 0x06, // bInterfaceClass (0x06 = still image)
  752. 0x01, // bInterfaceSubClass
  753. 0x01, // bInterfaceProtocol
  754. 0, // iInterface
  755. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  756. 7, // bLength
  757. 5, // bDescriptorType
  758. MTP_TX_ENDPOINT | 0x80, // bEndpointAddress
  759. 0x02, // bmAttributes (0x02=bulk)
  760. MTP_TX_SIZE, 0, // wMaxPacketSize
  761. 0, // bInterval
  762. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  763. 7, // bLength
  764. 5, // bDescriptorType
  765. MTP_RX_ENDPOINT, // bEndpointAddress
  766. 0x02, // bmAttributes (0x02=bulk)
  767. MTP_RX_SIZE, 0, // wMaxPacketSize
  768. 0, // bInterval
  769. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  770. 7, // bLength
  771. 5, // bDescriptorType
  772. MTP_EVENT_ENDPOINT | 0x80, // bEndpointAddress
  773. 0x03, // bmAttributes (0x03=intr)
  774. MTP_EVENT_SIZE, 0, // wMaxPacketSize
  775. MTP_EVENT_INTERVAL, // bInterval
  776. #endif // MTP_INTERFACE
  777. #ifdef KEYMEDIA_INTERFACE
  778. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  779. 9, // bLength
  780. 4, // bDescriptorType
  781. KEYMEDIA_INTERFACE, // bInterfaceNumber
  782. 0, // bAlternateSetting
  783. 1, // bNumEndpoints
  784. 0x03, // bInterfaceClass (0x03 = HID)
  785. 0x00, // bInterfaceSubClass
  786. 0x00, // bInterfaceProtocol
  787. 0, // iInterface
  788. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  789. 9, // bLength
  790. 0x21, // bDescriptorType
  791. 0x11, 0x01, // bcdHID
  792. 0, // bCountryCode
  793. 1, // bNumDescriptors
  794. 0x22, // bDescriptorType
  795. LSB(sizeof(keymedia_report_desc)), // wDescriptorLength
  796. MSB(sizeof(keymedia_report_desc)),
  797. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  798. 7, // bLength
  799. 5, // bDescriptorType
  800. KEYMEDIA_ENDPOINT | 0x80, // bEndpointAddress
  801. 0x03, // bmAttributes (0x03=intr)
  802. KEYMEDIA_SIZE, 0, // wMaxPacketSize
  803. KEYMEDIA_INTERVAL, // bInterval
  804. #endif // KEYMEDIA_INTERFACE
  805. #ifdef AUDIO_INTERFACE
  806. // Standard AudioControl (AC) Interface Descriptor
  807. // USB DCD for Audio Devices 1.0, Table 4-1, page 36
  808. 9, // bLength
  809. 4, // bDescriptorType, 4 = INTERFACE
  810. AUDIO_INTERFACE, // bInterfaceNumber
  811. 0, // bAlternateSetting
  812. 0, // bNumEndpoints
  813. 1, // bInterfaceClass, 1 = AUDIO
  814. 1, // bInterfaceSubclass, 1 = AUDIO_CONTROL
  815. 0, // bInterfaceProtocol
  816. 0, // iInterface
  817. // Class-specific AC Interface Header Descriptor
  818. // USB DCD for Audio Devices 1.0, Table 4-2, page 37-38
  819. 10, // bLength
  820. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  821. 0x01, // bDescriptorSubtype, 1 = HEADER
  822. 0x00, 0x01, // bcdADC (version 1.0)
  823. LSB(52), MSB(52), // wTotalLength
  824. 2, // bInCollection
  825. AUDIO_INTERFACE+1, // baInterfaceNr(1) - Transmit to PC
  826. AUDIO_INTERFACE+2, // baInterfaceNr(2) - Receive from PC
  827. // Input Terminal Descriptor
  828. // USB DCD for Audio Devices 1.0, Table 4-3, page 39
  829. 12, // bLength
  830. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  831. 0x02, // bDescriptorSubType, 2 = INPUT_TERMINAL
  832. 1, // bTerminalID
  833. //0x01, 0x02, // wTerminalType, 0x0201 = MICROPHONE
  834. //0x03, 0x06, // wTerminalType, 0x0603 = Line Connector
  835. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  836. 0, // bAssocTerminal, 0 = unidirectional
  837. 2, // bNrChannels
  838. 0x00, 0x03, // wChannelConfig, 0x0003 = Left & Right Front
  839. 0, // iChannelNames
  840. 0, // iTerminal
  841. // Output Terminal Descriptor
  842. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  843. 9, // bLength
  844. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  845. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  846. 2, // bTerminalID
  847. 0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
  848. 0, // bAssocTerminal, 0 = unidirectional
  849. 1, // bCSourceID, connected to input terminal, ID=1
  850. 0, // iTerminal
  851. // Input Terminal Descriptor
  852. // USB DCD for Audio Devices 1.0, Table 4-3, page 39
  853. 12, // bLength
  854. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  855. 2, // bDescriptorSubType, 2 = INPUT_TERMINAL
  856. 3, // bTerminalID
  857. 0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
  858. 0, // bAssocTerminal, 0 = unidirectional
  859. 2, // bNrChannels
  860. 0x00, 0x03, // wChannelConfig, 0x0003 = Left & Right Front
  861. 0, // iChannelNames
  862. 0, // iTerminal
  863. // Output Terminal Descriptor
  864. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  865. 9, // bLength
  866. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  867. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  868. 4, // bTerminalID
  869. //0x02, 0x03, // wTerminalType, 0x0302 = Headphones
  870. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  871. 0, // bAssocTerminal, 0 = unidirectional
  872. 3, // bCSourceID, connected to input terminal, ID=3
  873. 0, // iTerminal
  874. // Standard AS Interface Descriptor
  875. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  876. // Alternate 0: default setting, disabled zero bandwidth
  877. 9, // bLenght
  878. 4, // bDescriptorType = INTERFACE
  879. AUDIO_INTERFACE+1, // bInterfaceNumber
  880. 0, // bAlternateSetting
  881. 0, // bNumEndpoints
  882. 1, // bInterfaceClass, 1 = AUDIO
  883. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  884. 0, // bInterfaceProtocol
  885. 0, // iInterface
  886. // Alternate 1: streaming data
  887. 9, // bLenght
  888. 4, // bDescriptorType = INTERFACE
  889. AUDIO_INTERFACE+1, // bInterfaceNumber
  890. 1, // bAlternateSetting
  891. 1, // bNumEndpoints
  892. 1, // bInterfaceClass, 1 = AUDIO
  893. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  894. 0, // bInterfaceProtocol
  895. 0, // iInterface
  896. // Class-Specific AS Interface Descriptor
  897. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  898. 7, // bLength
  899. 0x24, // bDescriptorType = CS_INTERFACE
  900. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  901. 2, // bTerminalLink: Terminal ID = 2
  902. 3, // bDelay (approx 3ms delay, audio lib updates)
  903. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  904. // Type I Format Descriptor
  905. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  906. 11, // bLength
  907. 0x24, // bDescriptorType = CS_INTERFACE
  908. 2, // bDescriptorSubtype = FORMAT_TYPE
  909. 1, // bFormatType = FORMAT_TYPE_I
  910. 2, // bNrChannels = 2
  911. 2, // bSubFrameSize = 2 byte
  912. 16, // bBitResolution = 16 bits
  913. 1, // bSamFreqType = 1 frequency
  914. LSB(44100), MSB(44100), 0, // tSamFreq
  915. // Standard AS Isochronous Audio Data Endpoint Descriptor
  916. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  917. 9, // bLength
  918. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  919. AUDIO_TX_ENDPOINT | 0x80, // bEndpointAddress
  920. 0x05, // bmAttributes = isochronous, asynchronous
  921. LSB(AUDIO_TX_SIZE), MSB(AUDIO_TX_SIZE), // wMaxPacketSize
  922. 1, // bInterval, 1 = every frame
  923. 0, // bRefresh
  924. 0, // bSynchAddress
  925. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  926. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  927. 7, // bLength
  928. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  929. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  930. 0x01, // bmAttributes = Sampling Frequency
  931. 1, // bLockDelayUnits, 1 = ms
  932. 0x30, 0x00, // wLockDelay
  933. // Standard AS Interface Descriptor
  934. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  935. // Alternate 0: default setting, disabled zero bandwidth
  936. 9, // bLenght
  937. 4, // bDescriptorType = INTERFACE
  938. AUDIO_INTERFACE+2, // bInterfaceNumber
  939. 0, // bAlternateSetting
  940. 0, // bNumEndpoints
  941. 1, // bInterfaceClass, 1 = AUDIO
  942. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  943. 0, // bInterfaceProtocol
  944. 0, // iInterface
  945. // Alternate 1: streaming data
  946. 9, // bLenght
  947. 4, // bDescriptorType = INTERFACE
  948. AUDIO_INTERFACE+2, // bInterfaceNumber
  949. 1, // bAlternateSetting
  950. 2, // bNumEndpoints
  951. 1, // bInterfaceClass, 1 = AUDIO
  952. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  953. 0, // bInterfaceProtocol
  954. 0, // iInterface
  955. // Class-Specific AS Interface Descriptor
  956. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  957. 7, // bLength
  958. 0x24, // bDescriptorType = CS_INTERFACE
  959. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  960. 3, // bTerminalLink: Terminal ID = 3
  961. 3, // bDelay (approx 3ms delay, audio lib updates)
  962. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  963. // Type I Format Descriptor
  964. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  965. 11, // bLength
  966. 0x24, // bDescriptorType = CS_INTERFACE
  967. 2, // bDescriptorSubtype = FORMAT_TYPE
  968. 1, // bFormatType = FORMAT_TYPE_I
  969. 2, // bNrChannels = 2
  970. 2, // bSubFrameSize = 2 byte
  971. 16, // bBitResolution = 16 bits
  972. 1, // bSamFreqType = 1 frequency
  973. LSB(44100), MSB(44100), 0, // tSamFreq
  974. // Standard AS Isochronous Audio Data Endpoint Descriptor
  975. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  976. 9, // bLength
  977. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  978. AUDIO_RX_ENDPOINT, // bEndpointAddress
  979. 0x05, // bmAttributes = isochronous, asynchronous
  980. LSB(AUDIO_RX_SIZE), MSB(AUDIO_RX_SIZE), // wMaxPacketSize
  981. 1, // bInterval, 1 = every frame
  982. 0, // bRefresh
  983. AUDIO_SYNC_ENDPOINT | 0x80, // bSynchAddress
  984. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  985. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  986. 7, // bLength
  987. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  988. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  989. 0x01, // bmAttributes = Sampling Frequency
  990. 1, // bLockDelayUnits, 1 = ms
  991. 0x30, 0x00, // wLockDelay
  992. // Standard AS Isochronous Audio Synch Endpoint Descriptor
  993. // USB DCD for Audio Devices 1.0, Section 4.6.2.1, Table 4-22, page 63-64
  994. 9, // bLength
  995. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  996. AUDIO_SYNC_ENDPOINT | 0x80, // bEndpointAddress
  997. 0x01, // bmAttributes = isochronous
  998. 3, 0, // wMaxPacketSize, 3 bytes
  999. 1, // bInterval, 1 = every frame
  1000. 1, // bRefresh, 1=2ms, 2=8ms
  1001. 0, // bSynchAddress
  1002. #endif
  1003. };
  1004. // **************************************************************
  1005. // String Descriptors
  1006. // **************************************************************
  1007. // The descriptors above can provide human readable strings,
  1008. // referenced by index numbers. These descriptors are the
  1009. // actual string data
  1010. /* defined in usb_names.h
  1011. struct usb_string_descriptor_struct {
  1012. uint8_t bLength;
  1013. uint8_t bDescriptorType;
  1014. uint16_t wString[];
  1015. };
  1016. */
  1017. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  1018. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  1019. extern struct usb_string_descriptor_struct usb_string_product_name
  1020. __attribute__ ((weak, alias("usb_string_product_name_default")));
  1021. extern struct usb_string_descriptor_struct usb_string_serial_number
  1022. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  1023. struct usb_string_descriptor_struct string0 = {
  1024. 4,
  1025. 3,
  1026. {0x0409}
  1027. };
  1028. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  1029. 2 + MANUFACTURER_NAME_LEN * 2,
  1030. 3,
  1031. MANUFACTURER_NAME
  1032. };
  1033. struct usb_string_descriptor_struct usb_string_product_name_default = {
  1034. 2 + PRODUCT_NAME_LEN * 2,
  1035. 3,
  1036. PRODUCT_NAME
  1037. };
  1038. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  1039. 12,
  1040. 3,
  1041. {0,0,0,0,0,0,0,0,0,0}
  1042. };
  1043. void usb_init_serialnumber(void)
  1044. {
  1045. char buf[11];
  1046. uint32_t i, num;
  1047. __disable_irq();
  1048. FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
  1049. FTFL_FCCOB0 = 0x41;
  1050. FTFL_FCCOB1 = 15;
  1051. FTFL_FSTAT = FTFL_FSTAT_CCIF;
  1052. while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
  1053. num = *(uint32_t *)&FTFL_FCCOB7;
  1054. __enable_irq();
  1055. // add extra zero to work around OS-X CDC-ACM driver bug
  1056. if (num < 10000000) num = num * 10;
  1057. ultoa(num, buf, 10);
  1058. for (i=0; i<10; i++) {
  1059. char c = buf[i];
  1060. if (!c) break;
  1061. usb_string_serial_number_default.wString[i] = c;
  1062. }
  1063. usb_string_serial_number_default.bLength = i * 2 + 2;
  1064. }
  1065. // **************************************************************
  1066. // Descriptors List
  1067. // **************************************************************
  1068. // This table provides access to all the descriptor data above.
  1069. const usb_descriptor_list_t usb_descriptor_list[] = {
  1070. //wValue, wIndex, address, length
  1071. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  1072. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  1073. #ifdef SEREMU_INTERFACE
  1074. {0x2200, SEREMU_INTERFACE, seremu_report_desc, sizeof(seremu_report_desc)},
  1075. {0x2100, SEREMU_INTERFACE, config_descriptor+SEREMU_HID_DESC_OFFSET, 9},
  1076. #endif
  1077. #ifdef KEYBOARD_INTERFACE
  1078. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  1079. {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_HID_DESC_OFFSET, 9},
  1080. #endif
  1081. #ifdef MOUSE_INTERFACE
  1082. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  1083. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_HID_DESC_OFFSET, 9},
  1084. #endif
  1085. #ifdef JOYSTICK_INTERFACE
  1086. {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
  1087. {0x2100, JOYSTICK_INTERFACE, config_descriptor+JOYSTICK_HID_DESC_OFFSET, 9},
  1088. #endif
  1089. #ifdef RAWHID_INTERFACE
  1090. {0x2200, RAWHID_INTERFACE, rawhid_report_desc, sizeof(rawhid_report_desc)},
  1091. {0x2100, RAWHID_INTERFACE, config_descriptor+RAWHID_HID_DESC_OFFSET, 9},
  1092. #endif
  1093. #ifdef FLIGHTSIM_INTERFACE
  1094. {0x2200, FLIGHTSIM_INTERFACE, flightsim_report_desc, sizeof(flightsim_report_desc)},
  1095. {0x2100, FLIGHTSIM_INTERFACE, config_descriptor+FLIGHTSIM_HID_DESC_OFFSET, 9},
  1096. #endif
  1097. #ifdef KEYMEDIA_INTERFACE
  1098. {0x2200, KEYMEDIA_INTERFACE, keymedia_report_desc, sizeof(keymedia_report_desc)},
  1099. {0x2100, KEYMEDIA_INTERFACE, config_descriptor+KEYMEDIA_HID_DESC_OFFSET, 9},
  1100. #endif
  1101. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  1102. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  1103. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  1104. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  1105. {0, 0, NULL, 0}
  1106. };
  1107. // **************************************************************
  1108. // Endpoint Configuration
  1109. // **************************************************************
  1110. #if 0
  1111. // 0x00 = not used
  1112. // 0x19 = Recieve only
  1113. // 0x15 = Transmit only
  1114. // 0x1D = Transmit & Recieve
  1115. //
  1116. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1117. {
  1118. 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
  1119. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1120. };
  1121. #endif
  1122. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1123. {
  1124. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  1125. ENDPOINT1_CONFIG,
  1126. #elif (NUM_ENDPOINTS >= 1)
  1127. ENDPOINT_UNUSED,
  1128. #endif
  1129. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  1130. ENDPOINT2_CONFIG,
  1131. #elif (NUM_ENDPOINTS >= 2)
  1132. ENDPOINT_UNUSED,
  1133. #endif
  1134. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  1135. ENDPOINT3_CONFIG,
  1136. #elif (NUM_ENDPOINTS >= 3)
  1137. ENDPOINT_UNUSED,
  1138. #endif
  1139. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  1140. ENDPOINT4_CONFIG,
  1141. #elif (NUM_ENDPOINTS >= 4)
  1142. ENDPOINT_UNUSED,
  1143. #endif
  1144. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  1145. ENDPOINT5_CONFIG,
  1146. #elif (NUM_ENDPOINTS >= 5)
  1147. ENDPOINT_UNUSED,
  1148. #endif
  1149. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  1150. ENDPOINT6_CONFIG,
  1151. #elif (NUM_ENDPOINTS >= 6)
  1152. ENDPOINT_UNUSED,
  1153. #endif
  1154. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  1155. ENDPOINT7_CONFIG,
  1156. #elif (NUM_ENDPOINTS >= 7)
  1157. ENDPOINT_UNUSED,
  1158. #endif
  1159. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  1160. ENDPOINT8_CONFIG,
  1161. #elif (NUM_ENDPOINTS >= 8)
  1162. ENDPOINT_UNUSED,
  1163. #endif
  1164. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  1165. ENDPOINT9_CONFIG,
  1166. #elif (NUM_ENDPOINTS >= 9)
  1167. ENDPOINT_UNUSED,
  1168. #endif
  1169. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  1170. ENDPOINT10_CONFIG,
  1171. #elif (NUM_ENDPOINTS >= 10)
  1172. ENDPOINT_UNUSED,
  1173. #endif
  1174. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  1175. ENDPOINT11_CONFIG,
  1176. #elif (NUM_ENDPOINTS >= 11)
  1177. ENDPOINT_UNUSED,
  1178. #endif
  1179. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  1180. ENDPOINT12_CONFIG,
  1181. #elif (NUM_ENDPOINTS >= 12)
  1182. ENDPOINT_UNUSED,
  1183. #endif
  1184. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  1185. ENDPOINT13_CONFIG,
  1186. #elif (NUM_ENDPOINTS >= 13)
  1187. ENDPOINT_UNUSED,
  1188. #endif
  1189. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  1190. ENDPOINT14_CONFIG,
  1191. #elif (NUM_ENDPOINTS >= 14)
  1192. ENDPOINT_UNUSED,
  1193. #endif
  1194. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  1195. ENDPOINT15_CONFIG,
  1196. #elif (NUM_ENDPOINTS >= 15)
  1197. ENDPOINT_UNUSED,
  1198. #endif
  1199. };
  1200. #endif // NUM_ENDPOINTS
  1201. #endif // F_CPU >= 20 MHz