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

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