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 години
преди 8 години
преди 11 години
преди 8 години
преди 8 години
преди 11 години
преди 8 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 9 години
преди 8 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 9 години
преди 8 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 8 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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 CONFIG_DESC_SIZE KEYMEDIA_INTERFACE_DESC_POS+KEYMEDIA_INTERFACE_DESC_SIZE
  375. // **************************************************************
  376. // USB Configuration
  377. // **************************************************************
  378. // USB Configuration Descriptor. This huge descriptor tells all
  379. // of the devices capbilities.
  380. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  381. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  382. 9, // bLength;
  383. 2, // bDescriptorType;
  384. LSB(CONFIG_DESC_SIZE), // wTotalLength
  385. MSB(CONFIG_DESC_SIZE),
  386. NUM_INTERFACE, // bNumInterfaces
  387. 1, // bConfigurationValue
  388. 0, // iConfiguration
  389. 0xC0, // bmAttributes
  390. 50, // bMaxPower
  391. #ifdef CDC_IAD_DESCRIPTOR
  392. // interface association descriptor, USB ECN, Table 9-Z
  393. 8, // bLength
  394. 11, // bDescriptorType
  395. CDC_STATUS_INTERFACE, // bFirstInterface
  396. 2, // bInterfaceCount
  397. 0x02, // bFunctionClass
  398. 0x02, // bFunctionSubClass
  399. 0x01, // bFunctionProtocol
  400. 4, // iFunction
  401. #endif
  402. #ifdef CDC_DATA_INTERFACE
  403. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  404. 9, // bLength
  405. 4, // bDescriptorType
  406. CDC_STATUS_INTERFACE, // bInterfaceNumber
  407. 0, // bAlternateSetting
  408. 1, // bNumEndpoints
  409. 0x02, // bInterfaceClass
  410. 0x02, // bInterfaceSubClass
  411. 0x01, // bInterfaceProtocol
  412. 0, // iInterface
  413. // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
  414. 5, // bFunctionLength
  415. 0x24, // bDescriptorType
  416. 0x00, // bDescriptorSubtype
  417. 0x10, 0x01, // bcdCDC
  418. // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
  419. 5, // bFunctionLength
  420. 0x24, // bDescriptorType
  421. 0x01, // bDescriptorSubtype
  422. 0x01, // bmCapabilities
  423. 1, // bDataInterface
  424. // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
  425. 4, // bFunctionLength
  426. 0x24, // bDescriptorType
  427. 0x02, // bDescriptorSubtype
  428. 0x06, // bmCapabilities
  429. // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
  430. 5, // bFunctionLength
  431. 0x24, // bDescriptorType
  432. 0x06, // bDescriptorSubtype
  433. CDC_STATUS_INTERFACE, // bMasterInterface
  434. CDC_DATA_INTERFACE, // bSlaveInterface0
  435. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  436. 7, // bLength
  437. 5, // bDescriptorType
  438. CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
  439. 0x03, // bmAttributes (0x03=intr)
  440. CDC_ACM_SIZE, 0, // wMaxPacketSize
  441. 64, // bInterval
  442. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  443. 9, // bLength
  444. 4, // bDescriptorType
  445. CDC_DATA_INTERFACE, // bInterfaceNumber
  446. 0, // bAlternateSetting
  447. 2, // bNumEndpoints
  448. 0x0A, // bInterfaceClass
  449. 0x00, // bInterfaceSubClass
  450. 0x00, // bInterfaceProtocol
  451. 0, // iInterface
  452. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  453. 7, // bLength
  454. 5, // bDescriptorType
  455. CDC_RX_ENDPOINT, // bEndpointAddress
  456. 0x02, // bmAttributes (0x02=bulk)
  457. CDC_RX_SIZE, 0, // wMaxPacketSize
  458. 0, // bInterval
  459. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  460. 7, // bLength
  461. 5, // bDescriptorType
  462. CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
  463. 0x02, // bmAttributes (0x02=bulk)
  464. CDC_TX_SIZE, 0, // wMaxPacketSize
  465. 0, // bInterval
  466. #endif // CDC_DATA_INTERFACE
  467. #ifdef MIDI_INTERFACE
  468. // Standard MS Interface Descriptor,
  469. 9, // bLength
  470. 4, // bDescriptorType
  471. MIDI_INTERFACE, // bInterfaceNumber
  472. 0, // bAlternateSetting
  473. 2, // bNumEndpoints
  474. 0x01, // bInterfaceClass (0x01 = Audio)
  475. 0x03, // bInterfaceSubClass (0x03 = MIDI)
  476. 0x00, // bInterfaceProtocol (unused for MIDI)
  477. 0, // iInterface
  478. // MIDI MS Interface Header, USB MIDI 6.1.2.1, page 21, Table 6-2
  479. 7, // bLength
  480. 0x24, // bDescriptorType = CS_INTERFACE
  481. 0x01, // bDescriptorSubtype = MS_HEADER
  482. 0x00, 0x01, // bcdMSC = revision 01.00
  483. 0x41, 0x00, // wTotalLength
  484. // MIDI IN Jack Descriptor, B.4.3, Table B-7 (embedded), page 40
  485. 6, // bLength
  486. 0x24, // bDescriptorType = CS_INTERFACE
  487. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  488. 0x01, // bJackType = EMBEDDED
  489. 1, // bJackID, ID = 1
  490. 0, // iJack
  491. // MIDI IN Jack Descriptor, B.4.3, Table B-8 (external), page 40
  492. 6, // bLength
  493. 0x24, // bDescriptorType = CS_INTERFACE
  494. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  495. 0x02, // bJackType = EXTERNAL
  496. 2, // bJackID, ID = 2
  497. 0, // iJack
  498. // MIDI OUT Jack Descriptor, B.4.4, Table B-9, page 41
  499. 9,
  500. 0x24, // bDescriptorType = CS_INTERFACE
  501. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  502. 0x01, // bJackType = EMBEDDED
  503. 3, // bJackID, ID = 3
  504. 1, // bNrInputPins = 1 pin
  505. 2, // BaSourceID(1) = 2
  506. 1, // BaSourcePin(1) = first pin
  507. 0, // iJack
  508. // MIDI OUT Jack Descriptor, B.4.4, Table B-10, page 41
  509. 9,
  510. 0x24, // bDescriptorType = CS_INTERFACE
  511. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  512. 0x02, // bJackType = EXTERNAL
  513. 4, // bJackID, ID = 4
  514. 1, // bNrInputPins = 1 pin
  515. 1, // BaSourceID(1) = 1
  516. 1, // BaSourcePin(1) = first pin
  517. 0, // iJack
  518. // Standard Bulk OUT Endpoint Descriptor, B.5.1, Table B-11, pae 42
  519. 9, // bLength
  520. 5, // bDescriptorType = ENDPOINT
  521. MIDI_RX_ENDPOINT, // bEndpointAddress
  522. 0x02, // bmAttributes (0x02=bulk)
  523. MIDI_RX_SIZE, 0, // wMaxPacketSize
  524. 0, // bInterval
  525. 0, // bRefresh
  526. 0, // bSynchAddress
  527. // Class-specific MS Bulk OUT Endpoint Descriptor, B.5.2, Table B-12, page 42
  528. 5, // bLength
  529. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  530. 0x01, // bJackType = MS_GENERAL
  531. 1, // bNumEmbMIDIJack = 1 jack
  532. 1, // BaAssocJackID(1) = jack ID #1
  533. // Standard Bulk IN Endpoint Descriptor, B.5.1, Table B-11, pae 42
  534. 9, // bLength
  535. 5, // bDescriptorType = ENDPOINT
  536. MIDI_TX_ENDPOINT | 0x80, // bEndpointAddress
  537. 0x02, // bmAttributes (0x02=bulk)
  538. MIDI_TX_SIZE, 0, // wMaxPacketSize
  539. 0, // bInterval
  540. 0, // bRefresh
  541. 0, // bSynchAddress
  542. // Class-specific MS Bulk IN Endpoint Descriptor, B.5.2, Table B-12, page 42
  543. 5, // bLength
  544. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  545. 0x01, // bJackType = MS_GENERAL
  546. 1, // bNumEmbMIDIJack = 1 jack
  547. 3, // BaAssocJackID(1) = jack ID #3
  548. #endif // MIDI_INTERFACE
  549. #ifdef KEYBOARD_INTERFACE
  550. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  551. 9, // bLength
  552. 4, // bDescriptorType
  553. KEYBOARD_INTERFACE, // bInterfaceNumber
  554. 0, // bAlternateSetting
  555. 1, // bNumEndpoints
  556. 0x03, // bInterfaceClass (0x03 = HID)
  557. 0x01, // bInterfaceSubClass (0x01 = Boot)
  558. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  559. 0, // iInterface
  560. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  561. 9, // bLength
  562. 0x21, // bDescriptorType
  563. 0x11, 0x01, // bcdHID
  564. 0, // bCountryCode
  565. 1, // bNumDescriptors
  566. 0x22, // bDescriptorType
  567. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  568. MSB(sizeof(keyboard_report_desc)),
  569. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  570. 7, // bLength
  571. 5, // bDescriptorType
  572. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  573. 0x03, // bmAttributes (0x03=intr)
  574. KEYBOARD_SIZE, 0, // wMaxPacketSize
  575. KEYBOARD_INTERVAL, // bInterval
  576. #endif // KEYBOARD_INTERFACE
  577. #ifdef MOUSE_INTERFACE
  578. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  579. 9, // bLength
  580. 4, // bDescriptorType
  581. MOUSE_INTERFACE, // bInterfaceNumber
  582. 0, // bAlternateSetting
  583. 1, // bNumEndpoints
  584. 0x03, // bInterfaceClass (0x03 = HID)
  585. 0x00, // bInterfaceSubClass (0x01 = Boot)
  586. 0x00, // bInterfaceProtocol (0x02 = Mouse)
  587. 0, // iInterface
  588. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  589. 9, // bLength
  590. 0x21, // bDescriptorType
  591. 0x11, 0x01, // bcdHID
  592. 0, // bCountryCode
  593. 1, // bNumDescriptors
  594. 0x22, // bDescriptorType
  595. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  596. MSB(sizeof(mouse_report_desc)),
  597. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  598. 7, // bLength
  599. 5, // bDescriptorType
  600. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  601. 0x03, // bmAttributes (0x03=intr)
  602. MOUSE_SIZE, 0, // wMaxPacketSize
  603. MOUSE_INTERVAL, // bInterval
  604. #endif // MOUSE_INTERFACE
  605. #ifdef RAWHID_INTERFACE
  606. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  607. 9, // bLength
  608. 4, // bDescriptorType
  609. RAWHID_INTERFACE, // bInterfaceNumber
  610. 0, // bAlternateSetting
  611. 2, // bNumEndpoints
  612. 0x03, // bInterfaceClass (0x03 = HID)
  613. 0x00, // bInterfaceSubClass
  614. 0x00, // bInterfaceProtocol
  615. 0, // iInterface
  616. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  617. 9, // bLength
  618. 0x21, // bDescriptorType
  619. 0x11, 0x01, // bcdHID
  620. 0, // bCountryCode
  621. 1, // bNumDescriptors
  622. 0x22, // bDescriptorType
  623. LSB(sizeof(rawhid_report_desc)), // wDescriptorLength
  624. MSB(sizeof(rawhid_report_desc)),
  625. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  626. 7, // bLength
  627. 5, // bDescriptorType
  628. RAWHID_TX_ENDPOINT | 0x80, // bEndpointAddress
  629. 0x03, // bmAttributes (0x03=intr)
  630. RAWHID_TX_SIZE, 0, // wMaxPacketSize
  631. RAWHID_TX_INTERVAL, // bInterval
  632. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  633. 7, // bLength
  634. 5, // bDescriptorType
  635. RAWHID_RX_ENDPOINT, // bEndpointAddress
  636. 0x03, // bmAttributes (0x03=intr)
  637. RAWHID_RX_SIZE, 0, // wMaxPacketSize
  638. RAWHID_RX_INTERVAL, // bInterval
  639. #endif // RAWHID_INTERFACE
  640. #ifdef FLIGHTSIM_INTERFACE
  641. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  642. 9, // bLength
  643. 4, // bDescriptorType
  644. FLIGHTSIM_INTERFACE, // bInterfaceNumber
  645. 0, // bAlternateSetting
  646. 2, // bNumEndpoints
  647. 0x03, // bInterfaceClass (0x03 = HID)
  648. 0x00, // bInterfaceSubClass
  649. 0x00, // bInterfaceProtocol
  650. 0, // iInterface
  651. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  652. 9, // bLength
  653. 0x21, // bDescriptorType
  654. 0x11, 0x01, // bcdHID
  655. 0, // bCountryCode
  656. 1, // bNumDescriptors
  657. 0x22, // bDescriptorType
  658. LSB(sizeof(flightsim_report_desc)), // wDescriptorLength
  659. MSB(sizeof(flightsim_report_desc)),
  660. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  661. 7, // bLength
  662. 5, // bDescriptorType
  663. FLIGHTSIM_TX_ENDPOINT | 0x80, // bEndpointAddress
  664. 0x03, // bmAttributes (0x03=intr)
  665. FLIGHTSIM_TX_SIZE, 0, // wMaxPacketSize
  666. FLIGHTSIM_TX_INTERVAL, // bInterval
  667. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  668. 7, // bLength
  669. 5, // bDescriptorType
  670. FLIGHTSIM_RX_ENDPOINT, // bEndpointAddress
  671. 0x03, // bmAttributes (0x03=intr)
  672. FLIGHTSIM_RX_SIZE, 0, // wMaxPacketSize
  673. FLIGHTSIM_RX_INTERVAL, // bInterval
  674. #endif // FLIGHTSIM_INTERFACE
  675. #ifdef SEREMU_INTERFACE
  676. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  677. 9, // bLength
  678. 4, // bDescriptorType
  679. SEREMU_INTERFACE, // bInterfaceNumber
  680. 0, // bAlternateSetting
  681. 2, // bNumEndpoints
  682. 0x03, // bInterfaceClass (0x03 = HID)
  683. 0x00, // bInterfaceSubClass
  684. 0x00, // bInterfaceProtocol
  685. 0, // iInterface
  686. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  687. 9, // bLength
  688. 0x21, // bDescriptorType
  689. 0x11, 0x01, // bcdHID
  690. 0, // bCountryCode
  691. 1, // bNumDescriptors
  692. 0x22, // bDescriptorType
  693. LSB(sizeof(seremu_report_desc)), // wDescriptorLength
  694. MSB(sizeof(seremu_report_desc)),
  695. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  696. 7, // bLength
  697. 5, // bDescriptorType
  698. SEREMU_TX_ENDPOINT | 0x80, // bEndpointAddress
  699. 0x03, // bmAttributes (0x03=intr)
  700. SEREMU_TX_SIZE, 0, // wMaxPacketSize
  701. SEREMU_TX_INTERVAL, // bInterval
  702. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  703. 7, // bLength
  704. 5, // bDescriptorType
  705. SEREMU_RX_ENDPOINT, // bEndpointAddress
  706. 0x03, // bmAttributes (0x03=intr)
  707. SEREMU_RX_SIZE, 0, // wMaxPacketSize
  708. SEREMU_RX_INTERVAL, // bInterval
  709. #endif // SEREMU_INTERFACE
  710. #ifdef JOYSTICK_INTERFACE
  711. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  712. 9, // bLength
  713. 4, // bDescriptorType
  714. JOYSTICK_INTERFACE, // bInterfaceNumber
  715. 0, // bAlternateSetting
  716. 1, // bNumEndpoints
  717. 0x03, // bInterfaceClass (0x03 = HID)
  718. 0x00, // bInterfaceSubClass
  719. 0x00, // bInterfaceProtocol
  720. 0, // iInterface
  721. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  722. 9, // bLength
  723. 0x21, // bDescriptorType
  724. 0x11, 0x01, // bcdHID
  725. 0, // bCountryCode
  726. 1, // bNumDescriptors
  727. 0x22, // bDescriptorType
  728. LSB(sizeof(joystick_report_desc)), // wDescriptorLength
  729. MSB(sizeof(joystick_report_desc)),
  730. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  731. 7, // bLength
  732. 5, // bDescriptorType
  733. JOYSTICK_ENDPOINT | 0x80, // bEndpointAddress
  734. 0x03, // bmAttributes (0x03=intr)
  735. JOYSTICK_SIZE, 0, // wMaxPacketSize
  736. JOYSTICK_INTERVAL, // bInterval
  737. #endif // JOYSTICK_INTERFACE
  738. #ifdef MTP_INTERFACE
  739. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  740. 9, // bLength
  741. 4, // bDescriptorType
  742. MTP_INTERFACE, // bInterfaceNumber
  743. 0, // bAlternateSetting
  744. 3, // bNumEndpoints
  745. 0x06, // bInterfaceClass (0x06 = still image)
  746. 0x01, // bInterfaceSubClass
  747. 0x01, // bInterfaceProtocol
  748. 0, // iInterface
  749. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  750. 7, // bLength
  751. 5, // bDescriptorType
  752. MTP_TX_ENDPOINT | 0x80, // bEndpointAddress
  753. 0x02, // bmAttributes (0x02=bulk)
  754. MTP_TX_SIZE, 0, // wMaxPacketSize
  755. 0, // bInterval
  756. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  757. 7, // bLength
  758. 5, // bDescriptorType
  759. MTP_RX_ENDPOINT, // bEndpointAddress
  760. 0x02, // bmAttributes (0x02=bulk)
  761. MTP_RX_SIZE, 0, // wMaxPacketSize
  762. 0, // bInterval
  763. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  764. 7, // bLength
  765. 5, // bDescriptorType
  766. MTP_EVENT_ENDPOINT | 0x80, // bEndpointAddress
  767. 0x03, // bmAttributes (0x03=intr)
  768. MTP_EVENT_SIZE, 0, // wMaxPacketSize
  769. MTP_EVENT_INTERVAL, // bInterval
  770. #endif // MTP_INTERFACE
  771. #ifdef KEYMEDIA_INTERFACE
  772. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  773. 9, // bLength
  774. 4, // bDescriptorType
  775. KEYMEDIA_INTERFACE, // bInterfaceNumber
  776. 0, // bAlternateSetting
  777. 1, // bNumEndpoints
  778. 0x03, // bInterfaceClass (0x03 = HID)
  779. 0x00, // bInterfaceSubClass
  780. 0x00, // bInterfaceProtocol
  781. 0, // iInterface
  782. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  783. 9, // bLength
  784. 0x21, // bDescriptorType
  785. 0x11, 0x01, // bcdHID
  786. 0, // bCountryCode
  787. 1, // bNumDescriptors
  788. 0x22, // bDescriptorType
  789. LSB(sizeof(keymedia_report_desc)), // wDescriptorLength
  790. MSB(sizeof(keymedia_report_desc)),
  791. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  792. 7, // bLength
  793. 5, // bDescriptorType
  794. KEYMEDIA_ENDPOINT | 0x80, // bEndpointAddress
  795. 0x03, // bmAttributes (0x03=intr)
  796. KEYMEDIA_SIZE, 0, // wMaxPacketSize
  797. KEYMEDIA_INTERVAL, // bInterval
  798. #endif // KEYMEDIA_INTERFACE
  799. };
  800. // **************************************************************
  801. // String Descriptors
  802. // **************************************************************
  803. // The descriptors above can provide human readable strings,
  804. // referenced by index numbers. These descriptors are the
  805. // actual string data
  806. /* defined in usb_names.h
  807. struct usb_string_descriptor_struct {
  808. uint8_t bLength;
  809. uint8_t bDescriptorType;
  810. uint16_t wString[];
  811. };
  812. */
  813. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  814. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  815. extern struct usb_string_descriptor_struct usb_string_product_name
  816. __attribute__ ((weak, alias("usb_string_product_name_default")));
  817. extern struct usb_string_descriptor_struct usb_string_serial_number
  818. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  819. struct usb_string_descriptor_struct string0 = {
  820. 4,
  821. 3,
  822. {0x0409}
  823. };
  824. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  825. 2 + MANUFACTURER_NAME_LEN * 2,
  826. 3,
  827. MANUFACTURER_NAME
  828. };
  829. struct usb_string_descriptor_struct usb_string_product_name_default = {
  830. 2 + PRODUCT_NAME_LEN * 2,
  831. 3,
  832. PRODUCT_NAME
  833. };
  834. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  835. 12,
  836. 3,
  837. {0,0,0,0,0,0,0,0,0,0}
  838. };
  839. void usb_init_serialnumber(void)
  840. {
  841. char buf[11];
  842. uint32_t i, num;
  843. __disable_irq();
  844. FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
  845. FTFL_FCCOB0 = 0x41;
  846. FTFL_FCCOB1 = 15;
  847. FTFL_FSTAT = FTFL_FSTAT_CCIF;
  848. while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
  849. num = *(uint32_t *)&FTFL_FCCOB7;
  850. __enable_irq();
  851. // add extra zero to work around OS-X CDC-ACM driver bug
  852. if (num < 10000000) num = num * 10;
  853. ultoa(num, buf, 10);
  854. for (i=0; i<10; i++) {
  855. char c = buf[i];
  856. if (!c) break;
  857. usb_string_serial_number_default.wString[i] = c;
  858. }
  859. usb_string_serial_number_default.bLength = i * 2 + 2;
  860. }
  861. // **************************************************************
  862. // Descriptors List
  863. // **************************************************************
  864. // This table provides access to all the descriptor data above.
  865. const usb_descriptor_list_t usb_descriptor_list[] = {
  866. //wValue, wIndex, address, length
  867. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  868. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  869. #ifdef SEREMU_INTERFACE
  870. {0x2200, SEREMU_INTERFACE, seremu_report_desc, sizeof(seremu_report_desc)},
  871. {0x2100, SEREMU_INTERFACE, config_descriptor+SEREMU_HID_DESC_OFFSET, 9},
  872. #endif
  873. #ifdef KEYBOARD_INTERFACE
  874. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  875. {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_HID_DESC_OFFSET, 9},
  876. #endif
  877. #ifdef MOUSE_INTERFACE
  878. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  879. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_HID_DESC_OFFSET, 9},
  880. #endif
  881. #ifdef JOYSTICK_INTERFACE
  882. {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
  883. {0x2100, JOYSTICK_INTERFACE, config_descriptor+JOYSTICK_HID_DESC_OFFSET, 9},
  884. #endif
  885. #ifdef RAWHID_INTERFACE
  886. {0x2200, RAWHID_INTERFACE, rawhid_report_desc, sizeof(rawhid_report_desc)},
  887. {0x2100, RAWHID_INTERFACE, config_descriptor+RAWHID_HID_DESC_OFFSET, 9},
  888. #endif
  889. #ifdef FLIGHTSIM_INTERFACE
  890. {0x2200, FLIGHTSIM_INTERFACE, flightsim_report_desc, sizeof(flightsim_report_desc)},
  891. {0x2100, FLIGHTSIM_INTERFACE, config_descriptor+FLIGHTSIM_HID_DESC_OFFSET, 9},
  892. #endif
  893. #ifdef KEYMEDIA_INTERFACE
  894. {0x2200, KEYMEDIA_INTERFACE, keymedia_report_desc, sizeof(keymedia_report_desc)},
  895. {0x2100, KEYMEDIA_INTERFACE, config_descriptor+KEYMEDIA_HID_DESC_OFFSET, 9},
  896. #endif
  897. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  898. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  899. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  900. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  901. {0, 0, NULL, 0}
  902. };
  903. // **************************************************************
  904. // Endpoint Configuration
  905. // **************************************************************
  906. #if 0
  907. // 0x00 = not used
  908. // 0x19 = Recieve only
  909. // 0x15 = Transmit only
  910. // 0x1D = Transmit & Recieve
  911. //
  912. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  913. {
  914. 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
  915. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  916. };
  917. #endif
  918. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  919. {
  920. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  921. ENDPOINT1_CONFIG,
  922. #elif (NUM_ENDPOINTS >= 1)
  923. ENDPOINT_UNUSED,
  924. #endif
  925. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  926. ENDPOINT2_CONFIG,
  927. #elif (NUM_ENDPOINTS >= 2)
  928. ENDPOINT_UNUSED,
  929. #endif
  930. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  931. ENDPOINT3_CONFIG,
  932. #elif (NUM_ENDPOINTS >= 3)
  933. ENDPOINT_UNUSED,
  934. #endif
  935. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  936. ENDPOINT4_CONFIG,
  937. #elif (NUM_ENDPOINTS >= 4)
  938. ENDPOINT_UNUSED,
  939. #endif
  940. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  941. ENDPOINT5_CONFIG,
  942. #elif (NUM_ENDPOINTS >= 5)
  943. ENDPOINT_UNUSED,
  944. #endif
  945. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  946. ENDPOINT6_CONFIG,
  947. #elif (NUM_ENDPOINTS >= 6)
  948. ENDPOINT_UNUSED,
  949. #endif
  950. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  951. ENDPOINT7_CONFIG,
  952. #elif (NUM_ENDPOINTS >= 7)
  953. ENDPOINT_UNUSED,
  954. #endif
  955. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  956. ENDPOINT8_CONFIG,
  957. #elif (NUM_ENDPOINTS >= 8)
  958. ENDPOINT_UNUSED,
  959. #endif
  960. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  961. ENDPOINT9_CONFIG,
  962. #elif (NUM_ENDPOINTS >= 9)
  963. ENDPOINT_UNUSED,
  964. #endif
  965. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  966. ENDPOINT10_CONFIG,
  967. #elif (NUM_ENDPOINTS >= 10)
  968. ENDPOINT_UNUSED,
  969. #endif
  970. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  971. ENDPOINT11_CONFIG,
  972. #elif (NUM_ENDPOINTS >= 11)
  973. ENDPOINT_UNUSED,
  974. #endif
  975. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  976. ENDPOINT12_CONFIG,
  977. #elif (NUM_ENDPOINTS >= 12)
  978. ENDPOINT_UNUSED,
  979. #endif
  980. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  981. ENDPOINT13_CONFIG,
  982. #elif (NUM_ENDPOINTS >= 13)
  983. ENDPOINT_UNUSED,
  984. #endif
  985. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  986. ENDPOINT14_CONFIG,
  987. #elif (NUM_ENDPOINTS >= 14)
  988. ENDPOINT_UNUSED,
  989. #endif
  990. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  991. ENDPOINT15_CONFIG,
  992. #elif (NUM_ENDPOINTS >= 15)
  993. ENDPOINT_UNUSED,
  994. #endif
  995. };
  996. #endif // NUM_ENDPOINTS
  997. #endif // F_CPU >= 20 MHz