You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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. #include "usb_desc.h"
  32. #ifdef NUM_ENDPOINTS
  33. #include "usb_names.h"
  34. #include "kinetis.h"
  35. #include "avr_functions.h"
  36. // USB Descriptors are binary data which the USB host reads to
  37. // automatically detect a USB device's capabilities. The format
  38. // and meaning of every field is documented in numerous USB
  39. // standards. When working with USB descriptors, despite the
  40. // complexity of the standards and poor writing quality in many
  41. // of those documents, remember descriptors are nothing more
  42. // than constant binary data that tells the USB host what the
  43. // device can do. Computers will load drivers based on this data.
  44. // Those drivers then communicate on the endpoints specified by
  45. // the descriptors.
  46. // To configure a new combination of interfaces or make minor
  47. // changes to existing configuration (eg, change the name or ID
  48. // numbers), usually you would edit "usb_desc.h". This file
  49. // is meant to be configured by the header, so generally it is
  50. // only edited to add completely new USB interfaces or features.
  51. // **************************************************************
  52. // USB Device
  53. // **************************************************************
  54. #define LSB(n) ((n) & 255)
  55. #define MSB(n) (((n) >> 8) & 255)
  56. // USB Device Descriptor. The USB host reads this first, to learn
  57. // what type of device is connected.
  58. static uint8_t device_descriptor[] = {
  59. 18, // bLength
  60. 1, // bDescriptorType
  61. 0x00, 0x02, // bcdUSB
  62. #ifdef DEVICE_CLASS
  63. DEVICE_CLASS, // bDeviceClass
  64. #else
  65. 0,
  66. #endif
  67. #ifdef DEVICE_SUBCLASS
  68. DEVICE_SUBCLASS, // bDeviceSubClass
  69. #else
  70. 0,
  71. #endif
  72. #ifdef DEVICE_PROTOCOL
  73. DEVICE_PROTOCOL, // bDeviceProtocol
  74. #else
  75. 0,
  76. #endif
  77. EP0_SIZE, // bMaxPacketSize0
  78. LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
  79. LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct
  80. 0x00, 0x01, // bcdDevice
  81. 1, // iManufacturer
  82. 2, // iProduct
  83. 3, // iSerialNumber
  84. 1 // bNumConfigurations
  85. };
  86. // These descriptors must NOT be "const", because the USB DMA
  87. // has trouble accessing flash memory with enough bandwidth
  88. // while the processor is executing from flash.
  89. // **************************************************************
  90. // HID Report Descriptors
  91. // **************************************************************
  92. // Each HID interface needs a special report descriptor that tells
  93. // the meaning and format of the data.
  94. #ifdef KEYBOARD_INTERFACE
  95. // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
  96. static uint8_t keyboard_report_desc[] = {
  97. 0x05, 0x01, // Usage Page (Generic Desktop),
  98. 0x09, 0x06, // Usage (Keyboard),
  99. 0xA1, 0x01, // Collection (Application),
  100. 0x75, 0x01, // Report Size (1),
  101. 0x95, 0x08, // Report Count (8),
  102. 0x05, 0x07, // Usage Page (Key Codes),
  103. 0x19, 0xE0, // Usage Minimum (224),
  104. 0x29, 0xE7, // Usage Maximum (231),
  105. 0x15, 0x00, // Logical Minimum (0),
  106. 0x25, 0x01, // Logical Maximum (1),
  107. 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
  108. 0x95, 0x08, // Report Count (8),
  109. 0x75, 0x01, // Report Size (1),
  110. 0x15, 0x00, // Logical Minimum (0),
  111. 0x25, 0x01, // Logical Maximum (1),
  112. 0x05, 0x0C, // Usage Page (Consumer),
  113. 0x09, 0xE9, // Usage (Volume Increment),
  114. 0x09, 0xEA, // Usage (Volume Decrement),
  115. 0x09, 0xE2, // Usage (Mute),
  116. 0x09, 0xCD, // Usage (Play/Pause),
  117. 0x09, 0xB5, // Usage (Scan Next Track),
  118. 0x09, 0xB6, // Usage (Scan Previous Track),
  119. 0x09, 0xB7, // Usage (Stop),
  120. 0x09, 0xB8, // Usage (Eject),
  121. 0x81, 0x02, // Input (Data, Variable, Absolute), ;Media keys
  122. 0x95, 0x05, // Report Count (5),
  123. 0x75, 0x01, // Report Size (1),
  124. 0x05, 0x08, // Usage Page (LEDs),
  125. 0x19, 0x01, // Usage Minimum (1),
  126. 0x29, 0x05, // Usage Maximum (5),
  127. 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
  128. 0x95, 0x01, // Report Count (1),
  129. 0x75, 0x03, // Report Size (3),
  130. 0x91, 0x03, // Output (Constant), ;LED report padding
  131. 0x95, 0x06, // Report Count (6),
  132. 0x75, 0x08, // Report Size (8),
  133. 0x15, 0x00, // Logical Minimum (0),
  134. 0x25, 0x7F, // Logical Maximum(104),
  135. 0x05, 0x07, // Usage Page (Key Codes),
  136. 0x19, 0x00, // Usage Minimum (0),
  137. 0x29, 0x7F, // Usage Maximum (104),
  138. 0x81, 0x00, // Input (Data, Array), ;Normal keys
  139. 0xc0 // End Collection
  140. };
  141. #endif
  142. #ifdef MOUSE_INTERFACE
  143. // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
  144. static uint8_t mouse_report_desc[] = {
  145. 0x05, 0x01, // Usage Page (Generic Desktop)
  146. 0x09, 0x02, // Usage (Mouse)
  147. 0xA1, 0x01, // Collection (Application)
  148. 0x85, 0x01, // REPORT_ID (1)
  149. 0x05, 0x09, // Usage Page (Button)
  150. 0x19, 0x01, // Usage Minimum (Button #1)
  151. 0x29, 0x08, // Usage Maximum (Button #8)
  152. 0x15, 0x00, // Logical Minimum (0)
  153. 0x25, 0x01, // Logical Maximum (1)
  154. 0x95, 0x08, // Report Count (8)
  155. 0x75, 0x01, // Report Size (1)
  156. 0x81, 0x02, // Input (Data, Variable, Absolute)
  157. 0x05, 0x01, // Usage Page (Generic Desktop)
  158. 0x09, 0x30, // Usage (X)
  159. 0x09, 0x31, // Usage (Y)
  160. 0x09, 0x38, // Usage (Wheel)
  161. 0x15, 0x81, // Logical Minimum (-127)
  162. 0x25, 0x7F, // Logical Maximum (127)
  163. 0x75, 0x08, // Report Size (8),
  164. 0x95, 0x03, // Report Count (3),
  165. 0x81, 0x06, // Input (Data, Variable, Relative)
  166. 0xC0, // End Collection
  167. 0x05, 0x01, // Usage Page (Generic Desktop)
  168. 0x09, 0x02, // Usage (Mouse)
  169. 0xA1, 0x01, // Collection (Application)
  170. 0x85, 0x02, // REPORT_ID (2)
  171. 0x05, 0x01, // Usage Page (Generic Desktop)
  172. 0x09, 0x30, // Usage (X)
  173. 0x09, 0x31, // Usage (Y)
  174. 0x15, 0x00, // Logical Minimum (0)
  175. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  176. 0x75, 0x10, // Report Size (16),
  177. 0x95, 0x02, // Report Count (2),
  178. 0x81, 0x02, // Input (Data, Variable, Absolute)
  179. 0xC0 // End Collection
  180. };
  181. #endif
  182. #ifdef JOYSTICK_INTERFACE
  183. static uint8_t joystick_report_desc[] = {
  184. 0x05, 0x01, // Usage Page (Generic Desktop)
  185. 0x09, 0x04, // Usage (Joystick)
  186. 0xA1, 0x01, // Collection (Application)
  187. 0x15, 0x00, // Logical Minimum (0)
  188. 0x25, 0x01, // Logical Maximum (1)
  189. 0x75, 0x01, // Report Size (1)
  190. 0x95, 0x20, // Report Count (32)
  191. 0x05, 0x09, // Usage Page (Button)
  192. 0x19, 0x01, // Usage Minimum (Button #1)
  193. 0x29, 0x20, // Usage Maximum (Button #32)
  194. 0x81, 0x02, // Input (variable,absolute)
  195. 0x15, 0x00, // Logical Minimum (0)
  196. 0x25, 0x07, // Logical Maximum (7)
  197. 0x35, 0x00, // Physical Minimum (0)
  198. 0x46, 0x3B, 0x01, // Physical Maximum (315)
  199. 0x75, 0x04, // Report Size (4)
  200. 0x95, 0x01, // Report Count (1)
  201. 0x65, 0x14, // Unit (20)
  202. 0x05, 0x01, // Usage Page (Generic Desktop)
  203. 0x09, 0x39, // Usage (Hat switch)
  204. 0x81, 0x42, // Input (variable,absolute,null_state)
  205. 0x05, 0x01, // Usage Page (Generic Desktop)
  206. 0x09, 0x01, // Usage (Pointer)
  207. 0xA1, 0x00, // Collection ()
  208. 0x15, 0x00, // Logical Minimum (0)
  209. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  210. 0x75, 0x0A, // Report Size (10)
  211. 0x95, 0x04, // Report Count (4)
  212. 0x09, 0x30, // Usage (X)
  213. 0x09, 0x31, // Usage (Y)
  214. 0x09, 0x32, // Usage (Z)
  215. 0x09, 0x35, // Usage (Rz)
  216. 0x81, 0x02, // Input (variable,absolute)
  217. 0xC0, // End Collection
  218. 0x15, 0x00, // Logical Minimum (0)
  219. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  220. 0x75, 0x0A, // Report Size (10)
  221. 0x95, 0x02, // Report Count (2)
  222. 0x09, 0x36, // Usage (Slider)
  223. 0x09, 0x36, // Usage (Slider)
  224. 0x81, 0x02, // Input (variable,absolute)
  225. 0xC0 // End Collection
  226. };
  227. #endif
  228. #ifdef SEREMU_INTERFACE
  229. static uint8_t seremu_report_desc[] = {
  230. 0x06, 0xC9, 0xFF, // Usage Page 0xFFC9 (vendor defined)
  231. 0x09, 0x04, // Usage 0x04
  232. 0xA1, 0x5C, // Collection 0x5C
  233. 0x75, 0x08, // report size = 8 bits (global)
  234. 0x15, 0x00, // logical minimum = 0 (global)
  235. 0x26, 0xFF, 0x00, // logical maximum = 255 (global)
  236. 0x95, SEREMU_TX_SIZE, // report count (global)
  237. 0x09, 0x75, // usage (local)
  238. 0x81, 0x02, // Input
  239. 0x95, SEREMU_RX_SIZE, // report count (global)
  240. 0x09, 0x76, // usage (local)
  241. 0x91, 0x02, // Output
  242. 0x95, 0x04, // report count (global)
  243. 0x09, 0x76, // usage (local)
  244. 0xB1, 0x02, // Feature
  245. 0xC0 // end collection
  246. };
  247. #endif
  248. #ifdef RAWHID_INTERFACE
  249. static uint8_t rawhid_report_desc[] = {
  250. 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),
  251. 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
  252. 0xA1, 0x01, // Collection 0x01
  253. 0x75, 0x08, // report size = 8 bits
  254. 0x15, 0x00, // logical minimum = 0
  255. 0x26, 0xFF, 0x00, // logical maximum = 255
  256. 0x95, RAWHID_TX_SIZE, // report count
  257. 0x09, 0x01, // usage
  258. 0x81, 0x02, // Input (array)
  259. 0x95, RAWHID_RX_SIZE, // report count
  260. 0x09, 0x02, // usage
  261. 0x91, 0x02, // Output (array)
  262. 0xC0 // end collection
  263. };
  264. #endif
  265. #ifdef FLIGHTSIM_INTERFACE
  266. static uint8_t flightsim_report_desc[] = {
  267. 0x06, 0x1C, 0xFF, // Usage page = 0xFF1C
  268. 0x0A, 0x39, 0xA7, // Usage = 0xA739
  269. 0xA1, 0x01, // Collection 0x01
  270. 0x75, 0x08, // report size = 8 bits
  271. 0x15, 0x00, // logical minimum = 0
  272. 0x26, 0xFF, 0x00, // logical maximum = 255
  273. 0x95, FLIGHTSIM_TX_SIZE, // report count
  274. 0x09, 0x01, // usage
  275. 0x81, 0x02, // Input (array)
  276. 0x95, FLIGHTSIM_RX_SIZE, // report count
  277. 0x09, 0x02, // usage
  278. 0x91, 0x02, // Output (array)
  279. 0xC0 // end collection
  280. };
  281. #endif
  282. // **************************************************************
  283. // USB Configuration
  284. // **************************************************************
  285. // USB Configuration Descriptor. This huge descriptor tells all
  286. // of the devices capbilities.
  287. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  288. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  289. 9, // bLength;
  290. 2, // bDescriptorType;
  291. LSB(CONFIG_DESC_SIZE), // wTotalLength
  292. MSB(CONFIG_DESC_SIZE),
  293. NUM_INTERFACE, // bNumInterfaces
  294. 1, // bConfigurationValue
  295. 0, // iConfiguration
  296. 0xC0, // bmAttributes
  297. 50, // bMaxPower
  298. #ifdef CDC_IAD_DESCRIPTOR
  299. // interface association descriptor, USB ECN, Table 9-Z
  300. 8, // bLength
  301. 11, // bDescriptorType
  302. CDC_STATUS_INTERFACE, // bFirstInterface
  303. 2, // bInterfaceCount
  304. 0x02, // bFunctionClass
  305. 0x02, // bFunctionSubClass
  306. 0x01, // bFunctionProtocol
  307. 4, // iFunction
  308. #endif
  309. #ifdef CDC_DATA_INTERFACE
  310. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  311. 9, // bLength
  312. 4, // bDescriptorType
  313. CDC_STATUS_INTERFACE, // bInterfaceNumber
  314. 0, // bAlternateSetting
  315. 1, // bNumEndpoints
  316. 0x02, // bInterfaceClass
  317. 0x02, // bInterfaceSubClass
  318. 0x01, // bInterfaceProtocol
  319. 0, // iInterface
  320. // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
  321. 5, // bFunctionLength
  322. 0x24, // bDescriptorType
  323. 0x00, // bDescriptorSubtype
  324. 0x10, 0x01, // bcdCDC
  325. // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
  326. 5, // bFunctionLength
  327. 0x24, // bDescriptorType
  328. 0x01, // bDescriptorSubtype
  329. 0x01, // bmCapabilities
  330. 1, // bDataInterface
  331. // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
  332. 4, // bFunctionLength
  333. 0x24, // bDescriptorType
  334. 0x02, // bDescriptorSubtype
  335. 0x06, // bmCapabilities
  336. // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
  337. 5, // bFunctionLength
  338. 0x24, // bDescriptorType
  339. 0x06, // bDescriptorSubtype
  340. CDC_STATUS_INTERFACE, // bMasterInterface
  341. CDC_DATA_INTERFACE, // bSlaveInterface0
  342. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  343. 7, // bLength
  344. 5, // bDescriptorType
  345. CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
  346. 0x03, // bmAttributes (0x03=intr)
  347. CDC_ACM_SIZE, 0, // wMaxPacketSize
  348. 64, // bInterval
  349. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  350. 9, // bLength
  351. 4, // bDescriptorType
  352. CDC_DATA_INTERFACE, // bInterfaceNumber
  353. 0, // bAlternateSetting
  354. 2, // bNumEndpoints
  355. 0x0A, // bInterfaceClass
  356. 0x00, // bInterfaceSubClass
  357. 0x00, // bInterfaceProtocol
  358. 0, // iInterface
  359. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  360. 7, // bLength
  361. 5, // bDescriptorType
  362. CDC_RX_ENDPOINT, // bEndpointAddress
  363. 0x02, // bmAttributes (0x02=bulk)
  364. CDC_RX_SIZE, 0, // wMaxPacketSize
  365. 0, // bInterval
  366. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  367. 7, // bLength
  368. 5, // bDescriptorType
  369. CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
  370. 0x02, // bmAttributes (0x02=bulk)
  371. CDC_TX_SIZE, 0, // wMaxPacketSize
  372. 0, // bInterval
  373. #endif // CDC_DATA_INTERFACE
  374. #ifdef MIDI_INTERFACE
  375. // Standard MS Interface Descriptor,
  376. 9, // bLength
  377. 4, // bDescriptorType
  378. MIDI_INTERFACE, // bInterfaceNumber
  379. 0, // bAlternateSetting
  380. 2, // bNumEndpoints
  381. 0x01, // bInterfaceClass (0x01 = Audio)
  382. 0x03, // bInterfaceSubClass (0x03 = MIDI)
  383. 0x00, // bInterfaceProtocol (unused for MIDI)
  384. 0, // iInterface
  385. // MIDI MS Interface Header, USB MIDI 6.1.2.1, page 21, Table 6-2
  386. 7, // bLength
  387. 0x24, // bDescriptorType = CS_INTERFACE
  388. 0x01, // bDescriptorSubtype = MS_HEADER
  389. 0x00, 0x01, // bcdMSC = revision 01.00
  390. 0x41, 0x00, // wTotalLength
  391. // MIDI IN Jack Descriptor, B.4.3, Table B-7 (embedded), page 40
  392. 6, // bLength
  393. 0x24, // bDescriptorType = CS_INTERFACE
  394. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  395. 0x01, // bJackType = EMBEDDED
  396. 1, // bJackID, ID = 1
  397. 0, // iJack
  398. // MIDI IN Jack Descriptor, B.4.3, Table B-8 (external), page 40
  399. 6, // bLength
  400. 0x24, // bDescriptorType = CS_INTERFACE
  401. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  402. 0x02, // bJackType = EXTERNAL
  403. 2, // bJackID, ID = 2
  404. 0, // iJack
  405. // MIDI OUT Jack Descriptor, B.4.4, Table B-9, page 41
  406. 9,
  407. 0x24, // bDescriptorType = CS_INTERFACE
  408. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  409. 0x01, // bJackType = EMBEDDED
  410. 3, // bJackID, ID = 3
  411. 1, // bNrInputPins = 1 pin
  412. 2, // BaSourceID(1) = 2
  413. 1, // BaSourcePin(1) = first pin
  414. 0, // iJack
  415. // MIDI OUT Jack Descriptor, B.4.4, Table B-10, page 41
  416. 9,
  417. 0x24, // bDescriptorType = CS_INTERFACE
  418. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  419. 0x02, // bJackType = EXTERNAL
  420. 4, // bJackID, ID = 4
  421. 1, // bNrInputPins = 1 pin
  422. 1, // BaSourceID(1) = 1
  423. 1, // BaSourcePin(1) = first pin
  424. 0, // iJack
  425. // Standard Bulk OUT Endpoint Descriptor, B.5.1, Table B-11, pae 42
  426. 9, // bLength
  427. 5, // bDescriptorType = ENDPOINT
  428. MIDI_RX_ENDPOINT, // bEndpointAddress
  429. 0x02, // bmAttributes (0x02=bulk)
  430. MIDI_RX_SIZE, 0, // wMaxPacketSize
  431. 0, // bInterval
  432. 0, // bRefresh
  433. 0, // bSynchAddress
  434. // Class-specific MS Bulk OUT Endpoint Descriptor, B.5.2, Table B-12, page 42
  435. 5, // bLength
  436. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  437. 0x01, // bJackType = MS_GENERAL
  438. 1, // bNumEmbMIDIJack = 1 jack
  439. 1, // BaAssocJackID(1) = jack ID #1
  440. // Standard Bulk IN Endpoint Descriptor, B.5.1, Table B-11, pae 42
  441. 9, // bLength
  442. 5, // bDescriptorType = ENDPOINT
  443. MIDI_TX_ENDPOINT | 0x80, // bEndpointAddress
  444. 0x02, // bmAttributes (0x02=bulk)
  445. MIDI_TX_SIZE, 0, // wMaxPacketSize
  446. 0, // bInterval
  447. 0, // bRefresh
  448. 0, // bSynchAddress
  449. // Class-specific MS Bulk IN Endpoint Descriptor, B.5.2, Table B-12, page 42
  450. 5, // bLength
  451. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  452. 0x01, // bJackType = MS_GENERAL
  453. 1, // bNumEmbMIDIJack = 1 jack
  454. 3, // BaAssocJackID(1) = jack ID #3
  455. #endif // MIDI_INTERFACE
  456. #ifdef KEYBOARD_INTERFACE
  457. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  458. 9, // bLength
  459. 4, // bDescriptorType
  460. KEYBOARD_INTERFACE, // bInterfaceNumber
  461. 0, // bAlternateSetting
  462. 1, // bNumEndpoints
  463. 0x03, // bInterfaceClass (0x03 = HID)
  464. 0x01, // bInterfaceSubClass (0x01 = Boot)
  465. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  466. 0, // iInterface
  467. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  468. 9, // bLength
  469. 0x21, // bDescriptorType
  470. 0x11, 0x01, // bcdHID
  471. 0, // bCountryCode
  472. 1, // bNumDescriptors
  473. 0x22, // bDescriptorType
  474. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  475. MSB(sizeof(keyboard_report_desc)),
  476. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  477. 7, // bLength
  478. 5, // bDescriptorType
  479. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  480. 0x03, // bmAttributes (0x03=intr)
  481. KEYBOARD_SIZE, 0, // wMaxPacketSize
  482. KEYBOARD_INTERVAL, // bInterval
  483. #endif // KEYBOARD_INTERFACE
  484. #ifdef MOUSE_INTERFACE
  485. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  486. 9, // bLength
  487. 4, // bDescriptorType
  488. MOUSE_INTERFACE, // bInterfaceNumber
  489. 0, // bAlternateSetting
  490. 1, // bNumEndpoints
  491. 0x03, // bInterfaceClass (0x03 = HID)
  492. 0x00, // bInterfaceSubClass (0x01 = Boot)
  493. 0x00, // bInterfaceProtocol (0x02 = Mouse)
  494. 0, // iInterface
  495. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  496. 9, // bLength
  497. 0x21, // bDescriptorType
  498. 0x11, 0x01, // bcdHID
  499. 0, // bCountryCode
  500. 1, // bNumDescriptors
  501. 0x22, // bDescriptorType
  502. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  503. MSB(sizeof(mouse_report_desc)),
  504. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  505. 7, // bLength
  506. 5, // bDescriptorType
  507. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  508. 0x03, // bmAttributes (0x03=intr)
  509. MOUSE_SIZE, 0, // wMaxPacketSize
  510. MOUSE_INTERVAL, // bInterval
  511. #endif // MOUSE_INTERFACE
  512. #ifdef RAWHID_INTERFACE
  513. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  514. 9, // bLength
  515. 4, // bDescriptorType
  516. RAWHID_INTERFACE, // bInterfaceNumber
  517. 0, // bAlternateSetting
  518. 2, // bNumEndpoints
  519. 0x03, // bInterfaceClass (0x03 = HID)
  520. 0x00, // bInterfaceSubClass
  521. 0x00, // bInterfaceProtocol
  522. 0, // iInterface
  523. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  524. 9, // bLength
  525. 0x21, // bDescriptorType
  526. 0x11, 0x01, // bcdHID
  527. 0, // bCountryCode
  528. 1, // bNumDescriptors
  529. 0x22, // bDescriptorType
  530. LSB(sizeof(rawhid_report_desc)), // wDescriptorLength
  531. MSB(sizeof(rawhid_report_desc)),
  532. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  533. 7, // bLength
  534. 5, // bDescriptorType
  535. RAWHID_TX_ENDPOINT | 0x80, // bEndpointAddress
  536. 0x03, // bmAttributes (0x03=intr)
  537. RAWHID_TX_SIZE, 0, // wMaxPacketSize
  538. RAWHID_TX_INTERVAL, // bInterval
  539. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  540. 7, // bLength
  541. 5, // bDescriptorType
  542. RAWHID_RX_ENDPOINT, // bEndpointAddress
  543. 0x03, // bmAttributes (0x03=intr)
  544. RAWHID_RX_SIZE, 0, // wMaxPacketSize
  545. RAWHID_RX_INTERVAL, // bInterval
  546. #endif // RAWHID_INTERFACE
  547. #ifdef FLIGHTSIM_INTERFACE
  548. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  549. 9, // bLength
  550. 4, // bDescriptorType
  551. FLIGHTSIM_INTERFACE, // bInterfaceNumber
  552. 0, // bAlternateSetting
  553. 2, // bNumEndpoints
  554. 0x03, // bInterfaceClass (0x03 = HID)
  555. 0x00, // bInterfaceSubClass
  556. 0x00, // bInterfaceProtocol
  557. 0, // iInterface
  558. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  559. 9, // bLength
  560. 0x21, // bDescriptorType
  561. 0x11, 0x01, // bcdHID
  562. 0, // bCountryCode
  563. 1, // bNumDescriptors
  564. 0x22, // bDescriptorType
  565. LSB(sizeof(flightsim_report_desc)), // wDescriptorLength
  566. MSB(sizeof(flightsim_report_desc)),
  567. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  568. 7, // bLength
  569. 5, // bDescriptorType
  570. FLIGHTSIM_TX_ENDPOINT | 0x80, // bEndpointAddress
  571. 0x03, // bmAttributes (0x03=intr)
  572. FLIGHTSIM_TX_SIZE, 0, // wMaxPacketSize
  573. FLIGHTSIM_TX_INTERVAL, // bInterval
  574. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  575. 7, // bLength
  576. 5, // bDescriptorType
  577. FLIGHTSIM_RX_ENDPOINT, // bEndpointAddress
  578. 0x03, // bmAttributes (0x03=intr)
  579. FLIGHTSIM_RX_SIZE, 0, // wMaxPacketSize
  580. FLIGHTSIM_RX_INTERVAL, // bInterval
  581. #endif // FLIGHTSIM_INTERFACE
  582. #ifdef SEREMU_INTERFACE
  583. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  584. 9, // bLength
  585. 4, // bDescriptorType
  586. SEREMU_INTERFACE, // bInterfaceNumber
  587. 0, // bAlternateSetting
  588. 2, // bNumEndpoints
  589. 0x03, // bInterfaceClass (0x03 = HID)
  590. 0x00, // bInterfaceSubClass
  591. 0x00, // bInterfaceProtocol
  592. 0, // iInterface
  593. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  594. 9, // bLength
  595. 0x21, // bDescriptorType
  596. 0x11, 0x01, // bcdHID
  597. 0, // bCountryCode
  598. 1, // bNumDescriptors
  599. 0x22, // bDescriptorType
  600. LSB(sizeof(seremu_report_desc)), // wDescriptorLength
  601. MSB(sizeof(seremu_report_desc)),
  602. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  603. 7, // bLength
  604. 5, // bDescriptorType
  605. SEREMU_TX_ENDPOINT | 0x80, // bEndpointAddress
  606. 0x03, // bmAttributes (0x03=intr)
  607. SEREMU_TX_SIZE, 0, // wMaxPacketSize
  608. SEREMU_TX_INTERVAL, // bInterval
  609. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  610. 7, // bLength
  611. 5, // bDescriptorType
  612. SEREMU_RX_ENDPOINT, // bEndpointAddress
  613. 0x03, // bmAttributes (0x03=intr)
  614. SEREMU_RX_SIZE, 0, // wMaxPacketSize
  615. SEREMU_RX_INTERVAL, // bInterval
  616. #endif // SEREMU_INTERFACE
  617. #ifdef JOYSTICK_INTERFACE
  618. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  619. 9, // bLength
  620. 4, // bDescriptorType
  621. JOYSTICK_INTERFACE, // bInterfaceNumber
  622. 0, // bAlternateSetting
  623. 1, // bNumEndpoints
  624. 0x03, // bInterfaceClass (0x03 = HID)
  625. 0x00, // bInterfaceSubClass
  626. 0x00, // bInterfaceProtocol
  627. 0, // iInterface
  628. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  629. 9, // bLength
  630. 0x21, // bDescriptorType
  631. 0x11, 0x01, // bcdHID
  632. 0, // bCountryCode
  633. 1, // bNumDescriptors
  634. 0x22, // bDescriptorType
  635. LSB(sizeof(joystick_report_desc)), // wDescriptorLength
  636. MSB(sizeof(joystick_report_desc)),
  637. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  638. 7, // bLength
  639. 5, // bDescriptorType
  640. JOYSTICK_ENDPOINT | 0x80, // bEndpointAddress
  641. 0x03, // bmAttributes (0x03=intr)
  642. JOYSTICK_SIZE, 0, // wMaxPacketSize
  643. JOYSTICK_INTERVAL, // bInterval
  644. #endif // JOYSTICK_INTERFACE
  645. };
  646. // **************************************************************
  647. // String Descriptors
  648. // **************************************************************
  649. // The descriptors above can provide human readable strings,
  650. // referenced by index numbers. These descriptors are the
  651. // actual string data
  652. /* defined in usb_names.h
  653. struct usb_string_descriptor_struct {
  654. uint8_t bLength;
  655. uint8_t bDescriptorType;
  656. uint16_t wString[];
  657. };
  658. */
  659. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  660. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  661. extern struct usb_string_descriptor_struct usb_string_product_name
  662. __attribute__ ((weak, alias("usb_string_product_name_default")));
  663. extern struct usb_string_descriptor_struct usb_string_serial_number
  664. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  665. struct usb_string_descriptor_struct string0 = {
  666. 4,
  667. 3,
  668. {0x0409}
  669. };
  670. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  671. 2 + MANUFACTURER_NAME_LEN * 2,
  672. 3,
  673. MANUFACTURER_NAME
  674. };
  675. struct usb_string_descriptor_struct usb_string_product_name_default = {
  676. 2 + PRODUCT_NAME_LEN * 2,
  677. 3,
  678. PRODUCT_NAME
  679. };
  680. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  681. 12,
  682. 3,
  683. {0,0,0,0,0,0,0,0,0,0}
  684. };
  685. void usb_init_serialnumber(void)
  686. {
  687. char buf[11];
  688. uint32_t i, num;
  689. __disable_irq();
  690. FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
  691. FTFL_FCCOB0 = 0x41;
  692. FTFL_FCCOB1 = 15;
  693. FTFL_FSTAT = FTFL_FSTAT_CCIF;
  694. while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
  695. num = *(uint32_t *)&FTFL_FCCOB7;
  696. __enable_irq();
  697. // add extra zero to work around OS-X CDC-ACM driver bug
  698. if (num < 10000000) num = num * 10;
  699. ultoa(num, buf, 10);
  700. for (i=0; i<10; i++) {
  701. char c = buf[i];
  702. if (!c) break;
  703. usb_string_serial_number_default.wString[i] = c;
  704. }
  705. usb_string_serial_number_default.bLength = i * 2 + 2;
  706. }
  707. // **************************************************************
  708. // Descriptors List
  709. // **************************************************************
  710. // This table provides access to all the descriptor data above.
  711. const usb_descriptor_list_t usb_descriptor_list[] = {
  712. //wValue, wIndex, address, length
  713. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  714. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  715. #ifdef SEREMU_INTERFACE
  716. {0x2200, SEREMU_INTERFACE, seremu_report_desc, sizeof(seremu_report_desc)},
  717. {0x2100, SEREMU_INTERFACE, config_descriptor+SEREMU_DESC_OFFSET, 9},
  718. #endif
  719. #ifdef KEYBOARD_INTERFACE
  720. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  721. {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_DESC_OFFSET, 9},
  722. #endif
  723. #ifdef MOUSE_INTERFACE
  724. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  725. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_DESC_OFFSET, 9},
  726. #endif
  727. #ifdef JOYSTICK_INTERFACE
  728. {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
  729. {0x2100, JOYSTICK_INTERFACE, config_descriptor+JOYSTICK_DESC_OFFSET, 9},
  730. #endif
  731. #ifdef RAWHID_INTERFACE
  732. {0x2200, RAWHID_INTERFACE, rawhid_report_desc, sizeof(rawhid_report_desc)},
  733. {0x2100, RAWHID_INTERFACE, config_descriptor+RAWHID_DESC_OFFSET, 9},
  734. #endif
  735. #ifdef FLIGHTSIM_INTERFACE
  736. {0x2200, FLIGHTSIM_INTERFACE, flightsim_report_desc, sizeof(flightsim_report_desc)},
  737. {0x2100, FLIGHTSIM_INTERFACE, config_descriptor+FLIGHTSIM_DESC_OFFSET, 9},
  738. #endif
  739. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  740. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  741. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  742. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  743. //{0x0301, 0x0409, (const uint8_t *)&string1, 0},
  744. //{0x0302, 0x0409, (const uint8_t *)&string2, 0},
  745. //{0x0303, 0x0409, (const uint8_t *)&string3, 0},
  746. {0, 0, NULL, 0}
  747. };
  748. // **************************************************************
  749. // Endpoint Configuration
  750. // **************************************************************
  751. #if 0
  752. // 0x00 = not used
  753. // 0x19 = Recieve only
  754. // 0x15 = Transmit only
  755. // 0x1D = Transmit & Recieve
  756. //
  757. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  758. {
  759. 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
  760. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  761. };
  762. #endif
  763. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  764. {
  765. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  766. ENDPOINT1_CONFIG,
  767. #elif (NUM_ENDPOINTS >= 1)
  768. ENDPOINT_UNUSED,
  769. #endif
  770. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  771. ENDPOINT2_CONFIG,
  772. #elif (NUM_ENDPOINTS >= 2)
  773. ENDPOINT_UNUSED,
  774. #endif
  775. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  776. ENDPOINT3_CONFIG,
  777. #elif (NUM_ENDPOINTS >= 3)
  778. ENDPOINT_UNUSED,
  779. #endif
  780. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  781. ENDPOINT4_CONFIG,
  782. #elif (NUM_ENDPOINTS >= 4)
  783. ENDPOINT_UNUSED,
  784. #endif
  785. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  786. ENDPOINT5_CONFIG,
  787. #elif (NUM_ENDPOINTS >= 5)
  788. ENDPOINT_UNUSED,
  789. #endif
  790. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  791. ENDPOINT6_CONFIG,
  792. #elif (NUM_ENDPOINTS >= 6)
  793. ENDPOINT_UNUSED,
  794. #endif
  795. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  796. ENDPOINT7_CONFIG,
  797. #elif (NUM_ENDPOINTS >= 7)
  798. ENDPOINT_UNUSED,
  799. #endif
  800. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  801. ENDPOINT8_CONFIG,
  802. #elif (NUM_ENDPOINTS >= 8)
  803. ENDPOINT_UNUSED,
  804. #endif
  805. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  806. ENDPOINT9_CONFIG,
  807. #elif (NUM_ENDPOINTS >= 9)
  808. ENDPOINT_UNUSED,
  809. #endif
  810. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  811. ENDPOINT10_CONFIG,
  812. #elif (NUM_ENDPOINTS >= 10)
  813. ENDPOINT_UNUSED,
  814. #endif
  815. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  816. ENDPOINT11_CONFIG,
  817. #elif (NUM_ENDPOINTS >= 11)
  818. ENDPOINT_UNUSED,
  819. #endif
  820. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  821. ENDPOINT12_CONFIG,
  822. #elif (NUM_ENDPOINTS >= 12)
  823. ENDPOINT_UNUSED,
  824. #endif
  825. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  826. ENDPOINT13_CONFIG,
  827. #elif (NUM_ENDPOINTS >= 13)
  828. ENDPOINT_UNUSED,
  829. #endif
  830. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  831. ENDPOINT14_CONFIG,
  832. #elif (NUM_ENDPOINTS >= 14)
  833. ENDPOINT_UNUSED,
  834. #endif
  835. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  836. ENDPOINT15_CONFIG,
  837. #elif (NUM_ENDPOINTS >= 15)
  838. ENDPOINT_UNUSED,
  839. #endif
  840. };
  841. #endif // NUM_ENDPOINTS
  842. #endif // F_CPU >= 20 MHz