Teensy 4.1 core updated for C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 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 години
преди 8 години
преди 8 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 8 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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+10+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. // Volume feature descriptor
  871. 10, // bLength
  872. 0x24, // bDescriptorType = CS_INTERFACE
  873. 0x06, // bDescriptorSubType = FEATURE_UNIT
  874. 0x31, // bUnitID
  875. 0x03, // bSourceID (Input Terminal)
  876. 0x01, // bControlSize (each channel is 1 byte, 3 channels)
  877. 0x03, // bmaControls(0) Master: Volume & Mute
  878. 0x00, // bmaControls(1) Left: None
  879. 0x00, // bmaControls(2) Right: None
  880. 0x00, // iFeature
  881. // Output Terminal Descriptor
  882. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  883. 9, // bLength
  884. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  885. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  886. 4, // bTerminalID
  887. //0x02, 0x03, // wTerminalType, 0x0302 = Headphones
  888. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  889. 0, // bAssocTerminal, 0 = unidirectional
  890. 0x31, // bCSourceID, connected to feature, ID=31
  891. 0, // iTerminal
  892. // Standard AS Interface Descriptor
  893. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  894. // Alternate 0: default setting, disabled zero bandwidth
  895. 9, // bLenght
  896. 4, // bDescriptorType = INTERFACE
  897. AUDIO_INTERFACE+1, // bInterfaceNumber
  898. 0, // bAlternateSetting
  899. 0, // bNumEndpoints
  900. 1, // bInterfaceClass, 1 = AUDIO
  901. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  902. 0, // bInterfaceProtocol
  903. 0, // iInterface
  904. // Alternate 1: streaming data
  905. 9, // bLenght
  906. 4, // bDescriptorType = INTERFACE
  907. AUDIO_INTERFACE+1, // bInterfaceNumber
  908. 1, // bAlternateSetting
  909. 1, // bNumEndpoints
  910. 1, // bInterfaceClass, 1 = AUDIO
  911. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  912. 0, // bInterfaceProtocol
  913. 0, // iInterface
  914. // Class-Specific AS Interface Descriptor
  915. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  916. 7, // bLength
  917. 0x24, // bDescriptorType = CS_INTERFACE
  918. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  919. 2, // bTerminalLink: Terminal ID = 2
  920. 3, // bDelay (approx 3ms delay, audio lib updates)
  921. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  922. // Type I Format Descriptor
  923. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  924. 11, // bLength
  925. 0x24, // bDescriptorType = CS_INTERFACE
  926. 2, // bDescriptorSubtype = FORMAT_TYPE
  927. 1, // bFormatType = FORMAT_TYPE_I
  928. 2, // bNrChannels = 2
  929. 2, // bSubFrameSize = 2 byte
  930. 16, // bBitResolution = 16 bits
  931. 1, // bSamFreqType = 1 frequency
  932. LSB(44100), MSB(44100), 0, // tSamFreq
  933. // Standard AS Isochronous Audio Data Endpoint Descriptor
  934. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  935. 9, // bLength
  936. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  937. AUDIO_TX_ENDPOINT | 0x80, // bEndpointAddress
  938. 0x05, // bmAttributes = isochronous, asynchronous
  939. LSB(AUDIO_TX_SIZE), MSB(AUDIO_TX_SIZE), // wMaxPacketSize
  940. 1, // bInterval, 1 = every frame
  941. 0, // bRefresh
  942. 0, // bSynchAddress
  943. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  944. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  945. 7, // bLength
  946. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  947. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  948. 0x00, // bmAttributes
  949. 0, // bLockDelayUnits, 1 = ms
  950. 0x00, 0x00, // wLockDelay
  951. // Standard AS Interface Descriptor
  952. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  953. // Alternate 0: default setting, disabled zero bandwidth
  954. 9, // bLenght
  955. 4, // bDescriptorType = INTERFACE
  956. AUDIO_INTERFACE+2, // bInterfaceNumber
  957. 0, // bAlternateSetting
  958. 0, // bNumEndpoints
  959. 1, // bInterfaceClass, 1 = AUDIO
  960. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  961. 0, // bInterfaceProtocol
  962. 0, // iInterface
  963. // Alternate 1: streaming data
  964. 9, // bLenght
  965. 4, // bDescriptorType = INTERFACE
  966. AUDIO_INTERFACE+2, // bInterfaceNumber
  967. 1, // bAlternateSetting
  968. 2, // bNumEndpoints
  969. 1, // bInterfaceClass, 1 = AUDIO
  970. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  971. 0, // bInterfaceProtocol
  972. 0, // iInterface
  973. // Class-Specific AS Interface Descriptor
  974. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  975. 7, // bLength
  976. 0x24, // bDescriptorType = CS_INTERFACE
  977. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  978. 3, // bTerminalLink: Terminal ID = 3
  979. 3, // bDelay (approx 3ms delay, audio lib updates)
  980. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  981. // Type I Format Descriptor
  982. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  983. 11, // bLength
  984. 0x24, // bDescriptorType = CS_INTERFACE
  985. 2, // bDescriptorSubtype = FORMAT_TYPE
  986. 1, // bFormatType = FORMAT_TYPE_I
  987. 2, // bNrChannels = 2
  988. 2, // bSubFrameSize = 2 byte
  989. 16, // bBitResolution = 16 bits
  990. 1, // bSamFreqType = 1 frequency
  991. LSB(44100), MSB(44100), 0, // tSamFreq
  992. // Standard AS Isochronous Audio Data Endpoint Descriptor
  993. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  994. 9, // bLength
  995. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  996. AUDIO_RX_ENDPOINT, // bEndpointAddress
  997. 0x05, // bmAttributes = isochronous, asynchronous
  998. LSB(AUDIO_RX_SIZE), MSB(AUDIO_RX_SIZE), // wMaxPacketSize
  999. 1, // bInterval, 1 = every frame
  1000. 0, // bRefresh
  1001. AUDIO_SYNC_ENDPOINT | 0x80, // bSynchAddress
  1002. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  1003. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  1004. 7, // bLength
  1005. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  1006. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  1007. 0x00, // bmAttributes
  1008. 0, // bLockDelayUnits, 1 = ms
  1009. 0x00, 0x00, // wLockDelay
  1010. // Standard AS Isochronous Audio Synch Endpoint Descriptor
  1011. // USB DCD for Audio Devices 1.0, Section 4.6.2.1, Table 4-22, page 63-64
  1012. 9, // bLength
  1013. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1014. AUDIO_SYNC_ENDPOINT | 0x80, // bEndpointAddress
  1015. 0x01, // bmAttributes = isochronous
  1016. 3, 0, // wMaxPacketSize, 3 bytes
  1017. 1, // bInterval, 1 = every frame
  1018. 5, // bRefresh, 5 = 32ms
  1019. 0, // bSynchAddress
  1020. #endif
  1021. };
  1022. // **************************************************************
  1023. // String Descriptors
  1024. // **************************************************************
  1025. // The descriptors above can provide human readable strings,
  1026. // referenced by index numbers. These descriptors are the
  1027. // actual string data
  1028. /* defined in usb_names.h
  1029. struct usb_string_descriptor_struct {
  1030. uint8_t bLength;
  1031. uint8_t bDescriptorType;
  1032. uint16_t wString[];
  1033. };
  1034. */
  1035. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  1036. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  1037. extern struct usb_string_descriptor_struct usb_string_product_name
  1038. __attribute__ ((weak, alias("usb_string_product_name_default")));
  1039. extern struct usb_string_descriptor_struct usb_string_serial_number
  1040. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  1041. struct usb_string_descriptor_struct string0 = {
  1042. 4,
  1043. 3,
  1044. {0x0409}
  1045. };
  1046. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  1047. 2 + MANUFACTURER_NAME_LEN * 2,
  1048. 3,
  1049. MANUFACTURER_NAME
  1050. };
  1051. struct usb_string_descriptor_struct usb_string_product_name_default = {
  1052. 2 + PRODUCT_NAME_LEN * 2,
  1053. 3,
  1054. PRODUCT_NAME
  1055. };
  1056. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  1057. 12,
  1058. 3,
  1059. {0,0,0,0,0,0,0,0,0,0}
  1060. };
  1061. void usb_init_serialnumber(void)
  1062. {
  1063. char buf[11];
  1064. uint32_t i, num;
  1065. __disable_irq();
  1066. FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
  1067. FTFL_FCCOB0 = 0x41;
  1068. FTFL_FCCOB1 = 15;
  1069. FTFL_FSTAT = FTFL_FSTAT_CCIF;
  1070. while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
  1071. num = *(uint32_t *)&FTFL_FCCOB7;
  1072. __enable_irq();
  1073. // add extra zero to work around OS-X CDC-ACM driver bug
  1074. if (num < 10000000) num = num * 10;
  1075. ultoa(num, buf, 10);
  1076. for (i=0; i<10; i++) {
  1077. char c = buf[i];
  1078. if (!c) break;
  1079. usb_string_serial_number_default.wString[i] = c;
  1080. }
  1081. usb_string_serial_number_default.bLength = i * 2 + 2;
  1082. }
  1083. // **************************************************************
  1084. // Descriptors List
  1085. // **************************************************************
  1086. // This table provides access to all the descriptor data above.
  1087. const usb_descriptor_list_t usb_descriptor_list[] = {
  1088. //wValue, wIndex, address, length
  1089. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  1090. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  1091. #ifdef SEREMU_INTERFACE
  1092. {0x2200, SEREMU_INTERFACE, seremu_report_desc, sizeof(seremu_report_desc)},
  1093. {0x2100, SEREMU_INTERFACE, config_descriptor+SEREMU_HID_DESC_OFFSET, 9},
  1094. #endif
  1095. #ifdef KEYBOARD_INTERFACE
  1096. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  1097. {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_HID_DESC_OFFSET, 9},
  1098. #endif
  1099. #ifdef MOUSE_INTERFACE
  1100. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  1101. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_HID_DESC_OFFSET, 9},
  1102. #endif
  1103. #ifdef JOYSTICK_INTERFACE
  1104. {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
  1105. {0x2100, JOYSTICK_INTERFACE, config_descriptor+JOYSTICK_HID_DESC_OFFSET, 9},
  1106. #endif
  1107. #ifdef RAWHID_INTERFACE
  1108. {0x2200, RAWHID_INTERFACE, rawhid_report_desc, sizeof(rawhid_report_desc)},
  1109. {0x2100, RAWHID_INTERFACE, config_descriptor+RAWHID_HID_DESC_OFFSET, 9},
  1110. #endif
  1111. #ifdef FLIGHTSIM_INTERFACE
  1112. {0x2200, FLIGHTSIM_INTERFACE, flightsim_report_desc, sizeof(flightsim_report_desc)},
  1113. {0x2100, FLIGHTSIM_INTERFACE, config_descriptor+FLIGHTSIM_HID_DESC_OFFSET, 9},
  1114. #endif
  1115. #ifdef KEYMEDIA_INTERFACE
  1116. {0x2200, KEYMEDIA_INTERFACE, keymedia_report_desc, sizeof(keymedia_report_desc)},
  1117. {0x2100, KEYMEDIA_INTERFACE, config_descriptor+KEYMEDIA_HID_DESC_OFFSET, 9},
  1118. #endif
  1119. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  1120. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  1121. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  1122. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  1123. {0, 0, NULL, 0}
  1124. };
  1125. // **************************************************************
  1126. // Endpoint Configuration
  1127. // **************************************************************
  1128. #if 0
  1129. // 0x00 = not used
  1130. // 0x19 = Recieve only
  1131. // 0x15 = Transmit only
  1132. // 0x1D = Transmit & Recieve
  1133. //
  1134. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1135. {
  1136. 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
  1137. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1138. };
  1139. #endif
  1140. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1141. {
  1142. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  1143. ENDPOINT1_CONFIG,
  1144. #elif (NUM_ENDPOINTS >= 1)
  1145. ENDPOINT_UNUSED,
  1146. #endif
  1147. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  1148. ENDPOINT2_CONFIG,
  1149. #elif (NUM_ENDPOINTS >= 2)
  1150. ENDPOINT_UNUSED,
  1151. #endif
  1152. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  1153. ENDPOINT3_CONFIG,
  1154. #elif (NUM_ENDPOINTS >= 3)
  1155. ENDPOINT_UNUSED,
  1156. #endif
  1157. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  1158. ENDPOINT4_CONFIG,
  1159. #elif (NUM_ENDPOINTS >= 4)
  1160. ENDPOINT_UNUSED,
  1161. #endif
  1162. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  1163. ENDPOINT5_CONFIG,
  1164. #elif (NUM_ENDPOINTS >= 5)
  1165. ENDPOINT_UNUSED,
  1166. #endif
  1167. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  1168. ENDPOINT6_CONFIG,
  1169. #elif (NUM_ENDPOINTS >= 6)
  1170. ENDPOINT_UNUSED,
  1171. #endif
  1172. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  1173. ENDPOINT7_CONFIG,
  1174. #elif (NUM_ENDPOINTS >= 7)
  1175. ENDPOINT_UNUSED,
  1176. #endif
  1177. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  1178. ENDPOINT8_CONFIG,
  1179. #elif (NUM_ENDPOINTS >= 8)
  1180. ENDPOINT_UNUSED,
  1181. #endif
  1182. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  1183. ENDPOINT9_CONFIG,
  1184. #elif (NUM_ENDPOINTS >= 9)
  1185. ENDPOINT_UNUSED,
  1186. #endif
  1187. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  1188. ENDPOINT10_CONFIG,
  1189. #elif (NUM_ENDPOINTS >= 10)
  1190. ENDPOINT_UNUSED,
  1191. #endif
  1192. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  1193. ENDPOINT11_CONFIG,
  1194. #elif (NUM_ENDPOINTS >= 11)
  1195. ENDPOINT_UNUSED,
  1196. #endif
  1197. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  1198. ENDPOINT12_CONFIG,
  1199. #elif (NUM_ENDPOINTS >= 12)
  1200. ENDPOINT_UNUSED,
  1201. #endif
  1202. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  1203. ENDPOINT13_CONFIG,
  1204. #elif (NUM_ENDPOINTS >= 13)
  1205. ENDPOINT_UNUSED,
  1206. #endif
  1207. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  1208. ENDPOINT14_CONFIG,
  1209. #elif (NUM_ENDPOINTS >= 14)
  1210. ENDPOINT_UNUSED,
  1211. #endif
  1212. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  1213. ENDPOINT15_CONFIG,
  1214. #elif (NUM_ENDPOINTS >= 15)
  1215. ENDPOINT_UNUSED,
  1216. #endif
  1217. };
  1218. #endif // NUM_ENDPOINTS
  1219. #endif // F_CPU >= 20 MHz