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 година
пре 11 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 7 година
пре 11 година
пре 11 година
пре 8 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 9 година
пре 8 година
пре 11 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 9 година
пре 9 година
пре 8 година
пре 8 година
пре 8 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 8 година
пре 11 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2017 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. 0x10, 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. #ifdef BCD_DEVICE
  82. LSB(BCD_DEVICE), MSB(BCD_DEVICE), // bcdDevice
  83. #else
  84. // For USB types that don't explicitly define BCD_DEVICE,
  85. // use the minor version number to help teensy_ports
  86. // identify which Teensy model is used.
  87. #if defined(__MKL26Z64__)
  88. 0x73, 0x02,
  89. #elif defined(__MK20DX128__)
  90. 0x74, 0x02,
  91. #elif defined(__MK20DX256__)
  92. 0x75, 0x02,
  93. #elif defined(__MK64FX512__)
  94. 0x76, 0x02,
  95. #elif defined(__MK66FX1M0__)
  96. 0x77, 0x02,
  97. #else
  98. 0x00, 0x02,
  99. #endif
  100. #endif
  101. 1, // iManufacturer
  102. 2, // iProduct
  103. 3, // iSerialNumber
  104. 1 // bNumConfigurations
  105. };
  106. // These descriptors must NOT be "const", because the USB DMA
  107. // has trouble accessing flash memory with enough bandwidth
  108. // while the processor is executing from flash.
  109. // **************************************************************
  110. // HID Report Descriptors
  111. // **************************************************************
  112. // Each HID interface needs a special report descriptor that tells
  113. // the meaning and format of the data.
  114. #ifdef KEYBOARD_INTERFACE
  115. // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
  116. static uint8_t keyboard_report_desc[] = {
  117. 0x05, 0x01, // Usage Page (Generic Desktop),
  118. 0x09, 0x06, // Usage (Keyboard),
  119. 0xA1, 0x01, // Collection (Application),
  120. 0x75, 0x01, // Report Size (1),
  121. 0x95, 0x08, // Report Count (8),
  122. 0x05, 0x07, // Usage Page (Key Codes),
  123. 0x19, 0xE0, // Usage Minimum (224),
  124. 0x29, 0xE7, // Usage Maximum (231),
  125. 0x15, 0x00, // Logical Minimum (0),
  126. 0x25, 0x01, // Logical Maximum (1),
  127. 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier keys
  128. 0x95, 0x01, // Report Count (1),
  129. 0x75, 0x08, // Report Size (8),
  130. 0x81, 0x03, // Input (Constant), ;Reserved byte
  131. 0x95, 0x05, // Report Count (5),
  132. 0x75, 0x01, // Report Size (1),
  133. 0x05, 0x08, // Usage Page (LEDs),
  134. 0x19, 0x01, // Usage Minimum (1),
  135. 0x29, 0x05, // Usage Maximum (5),
  136. 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
  137. 0x95, 0x01, // Report Count (1),
  138. 0x75, 0x03, // Report Size (3),
  139. 0x91, 0x03, // Output (Constant), ;LED report padding
  140. 0x95, 0x06, // Report Count (6),
  141. 0x75, 0x08, // Report Size (8),
  142. 0x15, 0x00, // Logical Minimum (0),
  143. 0x25, 0x7F, // Logical Maximum(104),
  144. 0x05, 0x07, // Usage Page (Key Codes),
  145. 0x19, 0x00, // Usage Minimum (0),
  146. 0x29, 0x7F, // Usage Maximum (104),
  147. 0x81, 0x00, // Input (Data, Array), ;Normal keys
  148. 0xC0 // End Collection
  149. };
  150. #endif
  151. #ifdef KEYMEDIA_INTERFACE
  152. static uint8_t keymedia_report_desc[] = {
  153. 0x05, 0x0C, // Usage Page (Consumer)
  154. 0x09, 0x01, // Usage (Consumer Controls)
  155. 0xA1, 0x01, // Collection (Application)
  156. 0x75, 0x0A, // Report Size (10)
  157. 0x95, 0x04, // Report Count (4)
  158. 0x19, 0x00, // Usage Minimum (0)
  159. 0x2A, 0x9C, 0x02, // Usage Maximum (0x29C)
  160. 0x15, 0x00, // Logical Minimum (0)
  161. 0x26, 0x9C, 0x02, // Logical Maximum (0x29C)
  162. 0x81, 0x00, // Input (Data, Array)
  163. 0x05, 0x01, // Usage Page (Generic Desktop)
  164. 0x75, 0x08, // Report Size (8)
  165. 0x95, 0x03, // Report Count (3)
  166. 0x19, 0x00, // Usage Minimum (0)
  167. 0x29, 0xB7, // Usage Maximum (0xB7)
  168. 0x15, 0x00, // Logical Minimum (0)
  169. 0x26, 0xB7, 0x00, // Logical Maximum (0xB7)
  170. 0x81, 0x00, // Input (Data, Array)
  171. 0xC0 // End Collection
  172. };
  173. #endif
  174. #ifdef MOUSE_INTERFACE
  175. // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
  176. static uint8_t mouse_report_desc[] = {
  177. 0x05, 0x01, // Usage Page (Generic Desktop)
  178. 0x09, 0x02, // Usage (Mouse)
  179. 0xA1, 0x01, // Collection (Application)
  180. 0x85, 0x01, // REPORT_ID (1)
  181. 0x05, 0x09, // Usage Page (Button)
  182. 0x19, 0x01, // Usage Minimum (Button #1)
  183. 0x29, 0x08, // Usage Maximum (Button #8)
  184. 0x15, 0x00, // Logical Minimum (0)
  185. 0x25, 0x01, // Logical Maximum (1)
  186. 0x95, 0x08, // Report Count (8)
  187. 0x75, 0x01, // Report Size (1)
  188. 0x81, 0x02, // Input (Data, Variable, Absolute)
  189. 0x05, 0x01, // Usage Page (Generic Desktop)
  190. 0x09, 0x30, // Usage (X)
  191. 0x09, 0x31, // Usage (Y)
  192. 0x09, 0x38, // Usage (Wheel)
  193. 0x15, 0x81, // Logical Minimum (-127)
  194. 0x25, 0x7F, // Logical Maximum (127)
  195. 0x75, 0x08, // Report Size (8),
  196. 0x95, 0x03, // Report Count (3),
  197. 0x81, 0x06, // Input (Data, Variable, Relative)
  198. 0x05, 0x0C, // Usage Page (Consumer)
  199. 0x0A, 0x38, 0x02, // Usage (AC Pan)
  200. 0x15, 0x81, // Logical Minimum (-127)
  201. 0x25, 0x7F, // Logical Maximum (127)
  202. 0x75, 0x08, // Report Size (8),
  203. 0x95, 0x01, // Report Count (1),
  204. 0x81, 0x06, // Input (Data, Variable, Relative)
  205. 0xC0, // End Collection
  206. 0x05, 0x01, // Usage Page (Generic Desktop)
  207. 0x09, 0x02, // Usage (Mouse)
  208. 0xA1, 0x01, // Collection (Application)
  209. 0x85, 0x02, // REPORT_ID (2)
  210. 0x05, 0x01, // Usage Page (Generic Desktop)
  211. 0x09, 0x30, // Usage (X)
  212. 0x09, 0x31, // Usage (Y)
  213. 0x15, 0x00, // Logical Minimum (0)
  214. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  215. 0x75, 0x10, // Report Size (16),
  216. 0x95, 0x02, // Report Count (2),
  217. 0x81, 0x02, // Input (Data, Variable, Absolute)
  218. 0xC0 // End Collection
  219. };
  220. #endif
  221. #ifdef JOYSTICK_INTERFACE
  222. #if JOYSTICK_SIZE == 12
  223. static uint8_t joystick_report_desc[] = {
  224. 0x05, 0x01, // Usage Page (Generic Desktop)
  225. 0x09, 0x04, // Usage (Joystick)
  226. 0xA1, 0x01, // Collection (Application)
  227. 0x15, 0x00, // Logical Minimum (0)
  228. 0x25, 0x01, // Logical Maximum (1)
  229. 0x75, 0x01, // Report Size (1)
  230. 0x95, 0x20, // Report Count (32)
  231. 0x05, 0x09, // Usage Page (Button)
  232. 0x19, 0x01, // Usage Minimum (Button #1)
  233. 0x29, 0x20, // Usage Maximum (Button #32)
  234. 0x81, 0x02, // Input (variable,absolute)
  235. 0x15, 0x00, // Logical Minimum (0)
  236. 0x25, 0x07, // Logical Maximum (7)
  237. 0x35, 0x00, // Physical Minimum (0)
  238. 0x46, 0x3B, 0x01, // Physical Maximum (315)
  239. 0x75, 0x04, // Report Size (4)
  240. 0x95, 0x01, // Report Count (1)
  241. 0x65, 0x14, // Unit (20)
  242. 0x05, 0x01, // Usage Page (Generic Desktop)
  243. 0x09, 0x39, // Usage (Hat switch)
  244. 0x81, 0x42, // Input (variable,absolute,null_state)
  245. 0x05, 0x01, // Usage Page (Generic Desktop)
  246. 0x09, 0x01, // Usage (Pointer)
  247. 0xA1, 0x00, // Collection ()
  248. 0x15, 0x00, // Logical Minimum (0)
  249. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  250. 0x75, 0x0A, // Report Size (10)
  251. 0x95, 0x04, // Report Count (4)
  252. 0x09, 0x30, // Usage (X)
  253. 0x09, 0x31, // Usage (Y)
  254. 0x09, 0x32, // Usage (Z)
  255. 0x09, 0x35, // Usage (Rz)
  256. 0x81, 0x02, // Input (variable,absolute)
  257. 0xC0, // End Collection
  258. 0x15, 0x00, // Logical Minimum (0)
  259. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  260. 0x75, 0x0A, // Report Size (10)
  261. 0x95, 0x02, // Report Count (2)
  262. 0x09, 0x36, // Usage (Slider)
  263. 0x09, 0x36, // Usage (Slider)
  264. 0x81, 0x02, // Input (variable,absolute)
  265. 0xC0 // End Collection
  266. };
  267. #elif JOYSTICK_SIZE == 64
  268. // extreme joystick (to use this, edit JOYSTICK_SIZE to 64 in usb_desc.h)
  269. // 128 buttons 16
  270. // 6 axes 12
  271. // 17 sliders 34
  272. // 4 pov 2
  273. static uint8_t joystick_report_desc[] = {
  274. 0x05, 0x01, // Usage Page (Generic Desktop)
  275. 0x09, 0x04, // Usage (Joystick)
  276. 0xA1, 0x01, // Collection (Application)
  277. 0x15, 0x00, // Logical Minimum (0)
  278. 0x25, 0x01, // Logical Maximum (1)
  279. 0x75, 0x01, // Report Size (1)
  280. 0x95, 0x80, // Report Count (128)
  281. 0x05, 0x09, // Usage Page (Button)
  282. 0x19, 0x01, // Usage Minimum (Button #1)
  283. 0x29, 0x80, // Usage Maximum (Button #128)
  284. 0x81, 0x02, // Input (variable,absolute)
  285. 0x05, 0x01, // Usage Page (Generic Desktop)
  286. 0x09, 0x01, // Usage (Pointer)
  287. 0xA1, 0x00, // Collection ()
  288. 0x15, 0x00, // Logical Minimum (0)
  289. 0x27, 0xFF, 0xFF, 0, 0, // Logical Maximum (65535)
  290. 0x75, 0x10, // Report Size (16)
  291. 0x95, 23, // Report Count (23)
  292. 0x09, 0x30, // Usage (X)
  293. 0x09, 0x31, // Usage (Y)
  294. 0x09, 0x32, // Usage (Z)
  295. 0x09, 0x33, // Usage (Rx)
  296. 0x09, 0x34, // Usage (Ry)
  297. 0x09, 0x35, // Usage (Rz)
  298. 0x09, 0x36, // Usage (Slider)
  299. 0x09, 0x36, // Usage (Slider)
  300. 0x09, 0x36, // Usage (Slider)
  301. 0x09, 0x36, // Usage (Slider)
  302. 0x09, 0x36, // Usage (Slider)
  303. 0x09, 0x36, // Usage (Slider)
  304. 0x09, 0x36, // Usage (Slider)
  305. 0x09, 0x36, // Usage (Slider)
  306. 0x09, 0x36, // Usage (Slider)
  307. 0x09, 0x36, // Usage (Slider)
  308. 0x09, 0x36, // Usage (Slider)
  309. 0x09, 0x36, // Usage (Slider)
  310. 0x09, 0x36, // Usage (Slider)
  311. 0x09, 0x36, // Usage (Slider)
  312. 0x09, 0x36, // Usage (Slider)
  313. 0x09, 0x36, // Usage (Slider)
  314. 0x09, 0x36, // Usage (Slider)
  315. 0x81, 0x02, // Input (variable,absolute)
  316. 0xC0, // End Collection
  317. 0x15, 0x00, // Logical Minimum (0)
  318. 0x25, 0x07, // Logical Maximum (7)
  319. 0x35, 0x00, // Physical Minimum (0)
  320. 0x46, 0x3B, 0x01, // Physical Maximum (315)
  321. 0x75, 0x04, // Report Size (4)
  322. 0x95, 0x04, // Report Count (4)
  323. 0x65, 0x14, // Unit (20)
  324. 0x05, 0x01, // Usage Page (Generic Desktop)
  325. 0x09, 0x39, // Usage (Hat switch)
  326. 0x09, 0x39, // Usage (Hat switch)
  327. 0x09, 0x39, // Usage (Hat switch)
  328. 0x09, 0x39, // Usage (Hat switch)
  329. 0x81, 0x42, // Input (variable,absolute,null_state)
  330. 0xC0 // End Collection
  331. };
  332. #endif // JOYSTICK_SIZE
  333. #endif // JOYSTICK_INTERFACE
  334. #ifdef MULTITOUCH_INTERFACE
  335. // https://forum.pjrc.com/threads/32331-USB-HID-Touchscreen-support-needed
  336. // https://msdn.microsoft.com/en-us/library/windows/hardware/jj151563%28v=vs.85%29.aspx
  337. // https://msdn.microsoft.com/en-us/library/windows/hardware/jj151565%28v=vs.85%29.aspx
  338. // https://msdn.microsoft.com/en-us/library/windows/hardware/ff553734%28v=vs.85%29.aspx
  339. // https://msdn.microsoft.com/en-us/library/windows/hardware/jj151564%28v=vs.85%29.aspx
  340. // download.microsoft.com/download/a/d/f/adf1347d-08dc-41a4-9084-623b1194d4b2/digitizerdrvs_touch.docx
  341. static uint8_t multitouch_report_desc[] = {
  342. 0x05, 0x0D, // Usage Page (Digitizer)
  343. 0x09, 0x04, // Usage (Touch Screen)
  344. 0xa1, 0x01, // Collection (Application)
  345. 0x09, 0x22, // Usage (Finger)
  346. 0xA1, 0x02, // Collection (Logical)
  347. 0x09, 0x42, // Usage (Tip Switch)
  348. 0x15, 0x00, // Logical Minimum (0)
  349. 0x25, 0x01, // Logical Maximum (1)
  350. 0x75, 0x01, // Report Size (1)
  351. 0x95, 0x01, // Report Count (1)
  352. 0x81, 0x02, // Input (variable,absolute)
  353. 0x09, 0x51, // Usage (Contact Identifier)
  354. 0x25, 0x7F, // Logical Maximum (127)
  355. 0x75, 0x07, // Report Size (7)
  356. 0x95, 0x01, // Report Count (1)
  357. 0x81, 0x02, // Input (variable,absolute)
  358. 0x09, 0x30, // Usage (Pressure)
  359. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  360. 0x75, 0x08, // Report Size (8)
  361. 0x95, 0x01, // Report Count (1)
  362. 0x81, 0x02, // Input (variable,absolute)
  363. 0x05, 0x01, // Usage Page (Generic Desktop)
  364. 0x09, 0x30, // Usage (X)
  365. 0x09, 0x31, // Usage (Y)
  366. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  367. 0x65, 0x00, // Unit (None) <-- probably needs real units?
  368. 0x75, 0x10, // Report Size (16)
  369. 0x95, 0x02, // Report Count (2)
  370. 0x81, 0x02, // Input (variable,absolute)
  371. 0xC0, // End Collection
  372. 0x05, 0x0D, // Usage Page (Digitizer)
  373. 0x27, 0xFF, 0xFF, 0, 0, // Logical Maximum (65535)
  374. 0x75, 0x10, // Report Size (16)
  375. 0x95, 0x01, // Report Count (1)
  376. 0x09, 0x56, // Usage (Scan Time)
  377. 0x81, 0x02, // Input (variable,absolute)
  378. 0x05, 0x0D, // Usage Page (Digitizers)
  379. 0x09, 0x55, // Usage (Contact Count Maximum)
  380. 0x25, MULTITOUCH_FINGERS, // Logical Maximum (10)
  381. 0x75, 0x08, // Report Size (8)
  382. 0x95, 0x01, // Report Count (1)
  383. 0xB1, 0x02, // Feature (variable,absolute)
  384. 0xC0 // End Collection
  385. };
  386. #endif
  387. #ifdef SEREMU_INTERFACE
  388. static uint8_t seremu_report_desc[] = {
  389. 0x06, 0xC9, 0xFF, // Usage Page 0xFFC9 (vendor defined)
  390. 0x09, 0x04, // Usage 0x04
  391. 0xA1, 0x5C, // Collection 0x5C
  392. 0x75, 0x08, // report size = 8 bits (global)
  393. 0x15, 0x00, // logical minimum = 0 (global)
  394. 0x26, 0xFF, 0x00, // logical maximum = 255 (global)
  395. 0x95, SEREMU_TX_SIZE, // report count (global)
  396. 0x09, 0x75, // usage (local)
  397. 0x81, 0x02, // Input
  398. 0x95, SEREMU_RX_SIZE, // report count (global)
  399. 0x09, 0x76, // usage (local)
  400. 0x91, 0x02, // Output
  401. 0x95, 0x04, // report count (global)
  402. 0x09, 0x76, // usage (local)
  403. 0xB1, 0x02, // Feature
  404. 0xC0 // end collection
  405. };
  406. #endif
  407. #ifdef RAWHID_INTERFACE
  408. static uint8_t rawhid_report_desc[] = {
  409. 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),
  410. 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
  411. 0xA1, 0x01, // Collection 0x01
  412. 0x75, 0x08, // report size = 8 bits
  413. 0x15, 0x00, // logical minimum = 0
  414. 0x26, 0xFF, 0x00, // logical maximum = 255
  415. 0x95, RAWHID_TX_SIZE, // report count
  416. 0x09, 0x01, // usage
  417. 0x81, 0x02, // Input (array)
  418. 0x95, RAWHID_RX_SIZE, // report count
  419. 0x09, 0x02, // usage
  420. 0x91, 0x02, // Output (array)
  421. 0xC0 // end collection
  422. };
  423. #endif
  424. #ifdef FLIGHTSIM_INTERFACE
  425. static uint8_t flightsim_report_desc[] = {
  426. 0x06, 0x1C, 0xFF, // Usage page = 0xFF1C
  427. 0x0A, 0x39, 0xA7, // Usage = 0xA739
  428. 0xA1, 0x01, // Collection 0x01
  429. 0x75, 0x08, // report size = 8 bits
  430. 0x15, 0x00, // logical minimum = 0
  431. 0x26, 0xFF, 0x00, // logical maximum = 255
  432. 0x95, FLIGHTSIM_TX_SIZE, // report count
  433. 0x09, 0x01, // usage
  434. 0x81, 0x02, // Input (array)
  435. 0x95, FLIGHTSIM_RX_SIZE, // report count
  436. 0x09, 0x02, // usage
  437. 0x91, 0x02, // Output (array)
  438. 0xC0 // end collection
  439. };
  440. #endif
  441. // **************************************************************
  442. // USB Descriptor Sizes
  443. // **************************************************************
  444. // pre-compute the size and position of everything in the config descriptor
  445. //
  446. #define CONFIG_HEADER_DESCRIPTOR_SIZE 9
  447. #define CDC_IAD_DESCRIPTOR_POS CONFIG_HEADER_DESCRIPTOR_SIZE
  448. #ifdef CDC_IAD_DESCRIPTOR
  449. #define CDC_IAD_DESCRIPTOR_SIZE 8
  450. #else
  451. #define CDC_IAD_DESCRIPTOR_SIZE 0
  452. #endif
  453. #define CDC_DATA_INTERFACE_DESC_POS CDC_IAD_DESCRIPTOR_POS+CDC_IAD_DESCRIPTOR_SIZE
  454. #ifdef CDC_DATA_INTERFACE
  455. #define CDC_DATA_INTERFACE_DESC_SIZE 9+5+5+4+5+7+9+7+7
  456. #else
  457. #define CDC_DATA_INTERFACE_DESC_SIZE 0
  458. #endif
  459. #define MIDI_INTERFACE_DESC_POS CDC_DATA_INTERFACE_DESC_POS+CDC_DATA_INTERFACE_DESC_SIZE
  460. #ifdef MIDI_INTERFACE
  461. #if !defined(MIDI_NUM_CABLES) || MIDI_NUM_CABLES < 1 || MIDI_NUM_CABLES > 16
  462. #error "MIDI_NUM_CABLES must be defined between 1 to 16"
  463. #endif
  464. #define MIDI_INTERFACE_DESC_SIZE 9+7+((6+6+9+9)*MIDI_NUM_CABLES)+(9+4+MIDI_NUM_CABLES)*2
  465. #else
  466. #define MIDI_INTERFACE_DESC_SIZE 0
  467. #endif
  468. #define KEYBOARD_INTERFACE_DESC_POS MIDI_INTERFACE_DESC_POS+MIDI_INTERFACE_DESC_SIZE
  469. #ifdef KEYBOARD_INTERFACE
  470. #define KEYBOARD_INTERFACE_DESC_SIZE 9+9+7
  471. #define KEYBOARD_HID_DESC_OFFSET KEYBOARD_INTERFACE_DESC_POS+9
  472. #else
  473. #define KEYBOARD_INTERFACE_DESC_SIZE 0
  474. #endif
  475. #define MOUSE_INTERFACE_DESC_POS KEYBOARD_INTERFACE_DESC_POS+KEYBOARD_INTERFACE_DESC_SIZE
  476. #ifdef MOUSE_INTERFACE
  477. #define MOUSE_INTERFACE_DESC_SIZE 9+9+7
  478. #define MOUSE_HID_DESC_OFFSET MOUSE_INTERFACE_DESC_POS+9
  479. #else
  480. #define MOUSE_INTERFACE_DESC_SIZE 0
  481. #endif
  482. #define RAWHID_INTERFACE_DESC_POS MOUSE_INTERFACE_DESC_POS+MOUSE_INTERFACE_DESC_SIZE
  483. #ifdef RAWHID_INTERFACE
  484. #define RAWHID_INTERFACE_DESC_SIZE 9+9+7+7
  485. #define RAWHID_HID_DESC_OFFSET RAWHID_INTERFACE_DESC_POS+9
  486. #else
  487. #define RAWHID_INTERFACE_DESC_SIZE 0
  488. #endif
  489. #define FLIGHTSIM_INTERFACE_DESC_POS RAWHID_INTERFACE_DESC_POS+RAWHID_INTERFACE_DESC_SIZE
  490. #ifdef FLIGHTSIM_INTERFACE
  491. #define FLIGHTSIM_INTERFACE_DESC_SIZE 9+9+7+7
  492. #define FLIGHTSIM_HID_DESC_OFFSET FLIGHTSIM_INTERFACE_DESC_POS+9
  493. #else
  494. #define FLIGHTSIM_INTERFACE_DESC_SIZE 0
  495. #endif
  496. #define SEREMU_INTERFACE_DESC_POS FLIGHTSIM_INTERFACE_DESC_POS+FLIGHTSIM_INTERFACE_DESC_SIZE
  497. #ifdef SEREMU_INTERFACE
  498. #define SEREMU_INTERFACE_DESC_SIZE 9+9+7+7
  499. #define SEREMU_HID_DESC_OFFSET SEREMU_INTERFACE_DESC_POS+9
  500. #else
  501. #define SEREMU_INTERFACE_DESC_SIZE 0
  502. #endif
  503. #define JOYSTICK_INTERFACE_DESC_POS SEREMU_INTERFACE_DESC_POS+SEREMU_INTERFACE_DESC_SIZE
  504. #ifdef JOYSTICK_INTERFACE
  505. #define JOYSTICK_INTERFACE_DESC_SIZE 9+9+7
  506. #define JOYSTICK_HID_DESC_OFFSET JOYSTICK_INTERFACE_DESC_POS+9
  507. #else
  508. #define JOYSTICK_INTERFACE_DESC_SIZE 0
  509. #endif
  510. #define MTP_INTERFACE_DESC_POS JOYSTICK_INTERFACE_DESC_POS+JOYSTICK_INTERFACE_DESC_SIZE
  511. #ifdef MTP_INTERFACE
  512. #define MTP_INTERFACE_DESC_SIZE 9+7+7+7
  513. #else
  514. #define MTP_INTERFACE_DESC_SIZE 0
  515. #endif
  516. #define KEYMEDIA_INTERFACE_DESC_POS MTP_INTERFACE_DESC_POS+MTP_INTERFACE_DESC_SIZE
  517. #ifdef KEYMEDIA_INTERFACE
  518. #define KEYMEDIA_INTERFACE_DESC_SIZE 9+9+7
  519. #define KEYMEDIA_HID_DESC_OFFSET KEYMEDIA_INTERFACE_DESC_POS+9
  520. #else
  521. #define KEYMEDIA_INTERFACE_DESC_SIZE 0
  522. #endif
  523. #define AUDIO_INTERFACE_DESC_POS KEYMEDIA_INTERFACE_DESC_POS+KEYMEDIA_INTERFACE_DESC_SIZE
  524. #ifdef AUDIO_INTERFACE
  525. #define AUDIO_INTERFACE_DESC_SIZE 8 + 9+10+12+9+12+10+9 + 9+9+7+11+9+7 + 9+9+7+11+9+7+9
  526. #else
  527. #define AUDIO_INTERFACE_DESC_SIZE 0
  528. #endif
  529. #define MULTITOUCH_INTERFACE_DESC_POS AUDIO_INTERFACE_DESC_POS+AUDIO_INTERFACE_DESC_SIZE
  530. #ifdef MULTITOUCH_INTERFACE
  531. #define MULTITOUCH_INTERFACE_DESC_SIZE 9+9+7
  532. #define MULTITOUCH_HID_DESC_OFFSET MULTITOUCH_INTERFACE_DESC_POS+9
  533. #else
  534. #define MULTITOUCH_INTERFACE_DESC_SIZE 0
  535. #endif
  536. #define CONFIG_DESC_SIZE MULTITOUCH_INTERFACE_DESC_POS+MULTITOUCH_INTERFACE_DESC_SIZE
  537. // **************************************************************
  538. // USB Configuration
  539. // **************************************************************
  540. // USB Configuration Descriptor. This huge descriptor tells all
  541. // of the devices capbilities.
  542. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  543. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  544. 9, // bLength;
  545. 2, // bDescriptorType;
  546. LSB(CONFIG_DESC_SIZE), // wTotalLength
  547. MSB(CONFIG_DESC_SIZE),
  548. NUM_INTERFACE, // bNumInterfaces
  549. 1, // bConfigurationValue
  550. 0, // iConfiguration
  551. 0xC0, // bmAttributes
  552. 50, // bMaxPower
  553. #ifdef CDC_IAD_DESCRIPTOR
  554. // interface association descriptor, USB ECN, Table 9-Z
  555. 8, // bLength
  556. 11, // bDescriptorType
  557. CDC_STATUS_INTERFACE, // bFirstInterface
  558. 2, // bInterfaceCount
  559. 0x02, // bFunctionClass
  560. 0x02, // bFunctionSubClass
  561. 0x01, // bFunctionProtocol
  562. 0, // iFunction
  563. #endif
  564. #ifdef CDC_DATA_INTERFACE
  565. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  566. 9, // bLength
  567. 4, // bDescriptorType
  568. CDC_STATUS_INTERFACE, // bInterfaceNumber
  569. 0, // bAlternateSetting
  570. 1, // bNumEndpoints
  571. 0x02, // bInterfaceClass
  572. 0x02, // bInterfaceSubClass
  573. 0x01, // bInterfaceProtocol
  574. 0, // iInterface
  575. // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
  576. 5, // bFunctionLength
  577. 0x24, // bDescriptorType
  578. 0x00, // bDescriptorSubtype
  579. 0x10, 0x01, // bcdCDC
  580. // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
  581. 5, // bFunctionLength
  582. 0x24, // bDescriptorType
  583. 0x01, // bDescriptorSubtype
  584. 0x01, // bmCapabilities
  585. 1, // bDataInterface
  586. // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
  587. 4, // bFunctionLength
  588. 0x24, // bDescriptorType
  589. 0x02, // bDescriptorSubtype
  590. 0x06, // bmCapabilities
  591. // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
  592. 5, // bFunctionLength
  593. 0x24, // bDescriptorType
  594. 0x06, // bDescriptorSubtype
  595. CDC_STATUS_INTERFACE, // bMasterInterface
  596. CDC_DATA_INTERFACE, // bSlaveInterface0
  597. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  598. 7, // bLength
  599. 5, // bDescriptorType
  600. CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
  601. 0x03, // bmAttributes (0x03=intr)
  602. CDC_ACM_SIZE, 0, // wMaxPacketSize
  603. 64, // bInterval
  604. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  605. 9, // bLength
  606. 4, // bDescriptorType
  607. CDC_DATA_INTERFACE, // bInterfaceNumber
  608. 0, // bAlternateSetting
  609. 2, // bNumEndpoints
  610. 0x0A, // bInterfaceClass
  611. 0x00, // bInterfaceSubClass
  612. 0x00, // bInterfaceProtocol
  613. 0, // iInterface
  614. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  615. 7, // bLength
  616. 5, // bDescriptorType
  617. CDC_RX_ENDPOINT, // bEndpointAddress
  618. 0x02, // bmAttributes (0x02=bulk)
  619. CDC_RX_SIZE, 0, // wMaxPacketSize
  620. 0, // bInterval
  621. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  622. 7, // bLength
  623. 5, // bDescriptorType
  624. CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
  625. 0x02, // bmAttributes (0x02=bulk)
  626. CDC_TX_SIZE, 0, // wMaxPacketSize
  627. 0, // bInterval
  628. #endif // CDC_DATA_INTERFACE
  629. #ifdef MIDI_INTERFACE
  630. // Standard MS Interface Descriptor,
  631. 9, // bLength
  632. 4, // bDescriptorType
  633. MIDI_INTERFACE, // bInterfaceNumber
  634. 0, // bAlternateSetting
  635. 2, // bNumEndpoints
  636. 0x01, // bInterfaceClass (0x01 = Audio)
  637. 0x03, // bInterfaceSubClass (0x03 = MIDI)
  638. 0x00, // bInterfaceProtocol (unused for MIDI)
  639. 0, // iInterface
  640. // MIDI MS Interface Header, USB MIDI 6.1.2.1, page 21, Table 6-2
  641. 7, // bLength
  642. 0x24, // bDescriptorType = CS_INTERFACE
  643. 0x01, // bDescriptorSubtype = MS_HEADER
  644. 0x00, 0x01, // bcdMSC = revision 01.00
  645. LSB(7+(6+6+9+9)*MIDI_NUM_CABLES), // wTotalLength
  646. MSB(7+(6+6+9+9)*MIDI_NUM_CABLES),
  647. // MIDI IN Jack Descriptor, B.4.3, Table B-7 (embedded), page 40
  648. 6, // bLength
  649. 0x24, // bDescriptorType = CS_INTERFACE
  650. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  651. 0x01, // bJackType = EMBEDDED
  652. 1, // bJackID, ID = 1
  653. 0, // iJack
  654. // MIDI IN Jack Descriptor, B.4.3, Table B-8 (external), page 40
  655. 6, // bLength
  656. 0x24, // bDescriptorType = CS_INTERFACE
  657. 0x02, // bDescriptorSubtype = MIDI_IN_JACK
  658. 0x02, // bJackType = EXTERNAL
  659. 2, // bJackID, ID = 2
  660. 0, // iJack
  661. // MIDI OUT Jack Descriptor, B.4.4, Table B-9, page 41
  662. 9,
  663. 0x24, // bDescriptorType = CS_INTERFACE
  664. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  665. 0x01, // bJackType = EMBEDDED
  666. 3, // bJackID, ID = 3
  667. 1, // bNrInputPins = 1 pin
  668. 2, // BaSourceID(1) = 2
  669. 1, // BaSourcePin(1) = first pin
  670. 0, // iJack
  671. // MIDI OUT Jack Descriptor, B.4.4, Table B-10, page 41
  672. 9,
  673. 0x24, // bDescriptorType = CS_INTERFACE
  674. 0x03, // bDescriptorSubtype = MIDI_OUT_JACK
  675. 0x02, // bJackType = EXTERNAL
  676. 4, // bJackID, ID = 4
  677. 1, // bNrInputPins = 1 pin
  678. 1, // BaSourceID(1) = 1
  679. 1, // BaSourcePin(1) = first pin
  680. 0, // iJack
  681. #if MIDI_NUM_CABLES >= 2
  682. #define MIDI_INTERFACE_JACK_PAIR(a, b, c, d) \
  683. 6, 0x24, 0x02, 0x01, (a), 0, \
  684. 6, 0x24, 0x02, 0x02, (b), 0, \
  685. 9, 0x24, 0x03, 0x01, (c), 1, (b), 1, 0, \
  686. 9, 0x24, 0x03, 0x02, (d), 1, (a), 1, 0,
  687. MIDI_INTERFACE_JACK_PAIR(5, 6, 7, 8)
  688. #endif
  689. #if MIDI_NUM_CABLES >= 3
  690. MIDI_INTERFACE_JACK_PAIR(9, 10, 11, 12)
  691. #endif
  692. #if MIDI_NUM_CABLES >= 4
  693. MIDI_INTERFACE_JACK_PAIR(13, 14, 15, 16)
  694. #endif
  695. #if MIDI_NUM_CABLES >= 5
  696. MIDI_INTERFACE_JACK_PAIR(17, 18, 19, 20)
  697. #endif
  698. #if MIDI_NUM_CABLES >= 6
  699. MIDI_INTERFACE_JACK_PAIR(21, 22, 23, 24)
  700. #endif
  701. #if MIDI_NUM_CABLES >= 7
  702. MIDI_INTERFACE_JACK_PAIR(25, 26, 27, 28)
  703. #endif
  704. #if MIDI_NUM_CABLES >= 8
  705. MIDI_INTERFACE_JACK_PAIR(29, 30, 31, 32)
  706. #endif
  707. #if MIDI_NUM_CABLES >= 9
  708. MIDI_INTERFACE_JACK_PAIR(33, 34, 35, 36)
  709. #endif
  710. #if MIDI_NUM_CABLES >= 10
  711. MIDI_INTERFACE_JACK_PAIR(37, 38, 39, 40)
  712. #endif
  713. #if MIDI_NUM_CABLES >= 11
  714. MIDI_INTERFACE_JACK_PAIR(41, 42, 43, 44)
  715. #endif
  716. #if MIDI_NUM_CABLES >= 12
  717. MIDI_INTERFACE_JACK_PAIR(45, 46, 47, 48)
  718. #endif
  719. #if MIDI_NUM_CABLES >= 13
  720. MIDI_INTERFACE_JACK_PAIR(49, 50, 51, 52)
  721. #endif
  722. #if MIDI_NUM_CABLES >= 14
  723. MIDI_INTERFACE_JACK_PAIR(53, 54, 55, 56)
  724. #endif
  725. #if MIDI_NUM_CABLES >= 15
  726. MIDI_INTERFACE_JACK_PAIR(57, 58, 59, 60)
  727. #endif
  728. #if MIDI_NUM_CABLES >= 16
  729. MIDI_INTERFACE_JACK_PAIR(61, 62, 63, 64)
  730. #endif
  731. // Standard Bulk OUT Endpoint Descriptor, B.5.1, Table B-11, pae 42
  732. 9, // bLength
  733. 5, // bDescriptorType = ENDPOINT
  734. MIDI_RX_ENDPOINT, // bEndpointAddress
  735. 0x02, // bmAttributes (0x02=bulk)
  736. MIDI_RX_SIZE, 0, // wMaxPacketSize
  737. 0, // bInterval
  738. 0, // bRefresh
  739. 0, // bSynchAddress
  740. // Class-specific MS Bulk OUT Endpoint Descriptor, B.5.2, Table B-12, page 42
  741. 4+MIDI_NUM_CABLES, // bLength
  742. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  743. 0x01, // bJackType = MS_GENERAL
  744. MIDI_NUM_CABLES, // bNumEmbMIDIJack = number of jacks
  745. 1, // BaAssocJackID(1) = jack ID #1
  746. #if MIDI_NUM_CABLES >= 2
  747. 5,
  748. #endif
  749. #if MIDI_NUM_CABLES >= 3
  750. 9,
  751. #endif
  752. #if MIDI_NUM_CABLES >= 4
  753. 13,
  754. #endif
  755. #if MIDI_NUM_CABLES >= 5
  756. 17,
  757. #endif
  758. #if MIDI_NUM_CABLES >= 6
  759. 21,
  760. #endif
  761. #if MIDI_NUM_CABLES >= 7
  762. 25,
  763. #endif
  764. #if MIDI_NUM_CABLES >= 8
  765. 29,
  766. #endif
  767. #if MIDI_NUM_CABLES >= 9
  768. 33,
  769. #endif
  770. #if MIDI_NUM_CABLES >= 10
  771. 37,
  772. #endif
  773. #if MIDI_NUM_CABLES >= 11
  774. 41,
  775. #endif
  776. #if MIDI_NUM_CABLES >= 12
  777. 45,
  778. #endif
  779. #if MIDI_NUM_CABLES >= 13
  780. 49,
  781. #endif
  782. #if MIDI_NUM_CABLES >= 14
  783. 53,
  784. #endif
  785. #if MIDI_NUM_CABLES >= 15
  786. 57,
  787. #endif
  788. #if MIDI_NUM_CABLES >= 16
  789. 61,
  790. #endif
  791. // Standard Bulk IN Endpoint Descriptor, B.5.1, Table B-11, pae 42
  792. 9, // bLength
  793. 5, // bDescriptorType = ENDPOINT
  794. MIDI_TX_ENDPOINT | 0x80, // bEndpointAddress
  795. 0x02, // bmAttributes (0x02=bulk)
  796. MIDI_TX_SIZE, 0, // wMaxPacketSize
  797. 0, // bInterval
  798. 0, // bRefresh
  799. 0, // bSynchAddress
  800. // Class-specific MS Bulk IN Endpoint Descriptor, B.5.2, Table B-12, page 42
  801. 4+MIDI_NUM_CABLES, // bLength
  802. 0x25, // bDescriptorSubtype = CS_ENDPOINT
  803. 0x01, // bJackType = MS_GENERAL
  804. MIDI_NUM_CABLES, // bNumEmbMIDIJack = number of jacks
  805. 3, // BaAssocJackID(1) = jack ID #3
  806. #if MIDI_NUM_CABLES >= 2
  807. 7,
  808. #endif
  809. #if MIDI_NUM_CABLES >= 3
  810. 11,
  811. #endif
  812. #if MIDI_NUM_CABLES >= 4
  813. 15,
  814. #endif
  815. #if MIDI_NUM_CABLES >= 5
  816. 19,
  817. #endif
  818. #if MIDI_NUM_CABLES >= 6
  819. 23,
  820. #endif
  821. #if MIDI_NUM_CABLES >= 7
  822. 27,
  823. #endif
  824. #if MIDI_NUM_CABLES >= 8
  825. 31,
  826. #endif
  827. #if MIDI_NUM_CABLES >= 9
  828. 35,
  829. #endif
  830. #if MIDI_NUM_CABLES >= 10
  831. 39,
  832. #endif
  833. #if MIDI_NUM_CABLES >= 11
  834. 43,
  835. #endif
  836. #if MIDI_NUM_CABLES >= 12
  837. 47,
  838. #endif
  839. #if MIDI_NUM_CABLES >= 13
  840. 51,
  841. #endif
  842. #if MIDI_NUM_CABLES >= 14
  843. 55,
  844. #endif
  845. #if MIDI_NUM_CABLES >= 15
  846. 59,
  847. #endif
  848. #if MIDI_NUM_CABLES >= 16
  849. 63,
  850. #endif
  851. #endif // MIDI_INTERFACE
  852. #ifdef KEYBOARD_INTERFACE
  853. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  854. 9, // bLength
  855. 4, // bDescriptorType
  856. KEYBOARD_INTERFACE, // bInterfaceNumber
  857. 0, // bAlternateSetting
  858. 1, // bNumEndpoints
  859. 0x03, // bInterfaceClass (0x03 = HID)
  860. 0x01, // bInterfaceSubClass (0x01 = Boot)
  861. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  862. 0, // iInterface
  863. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  864. 9, // bLength
  865. 0x21, // bDescriptorType
  866. 0x11, 0x01, // bcdHID
  867. 0, // bCountryCode
  868. 1, // bNumDescriptors
  869. 0x22, // bDescriptorType
  870. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  871. MSB(sizeof(keyboard_report_desc)),
  872. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  873. 7, // bLength
  874. 5, // bDescriptorType
  875. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  876. 0x03, // bmAttributes (0x03=intr)
  877. KEYBOARD_SIZE, 0, // wMaxPacketSize
  878. KEYBOARD_INTERVAL, // bInterval
  879. #endif // KEYBOARD_INTERFACE
  880. #ifdef MOUSE_INTERFACE
  881. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  882. 9, // bLength
  883. 4, // bDescriptorType
  884. MOUSE_INTERFACE, // bInterfaceNumber
  885. 0, // bAlternateSetting
  886. 1, // bNumEndpoints
  887. 0x03, // bInterfaceClass (0x03 = HID)
  888. 0x00, // bInterfaceSubClass (0x01 = Boot)
  889. 0x00, // bInterfaceProtocol (0x02 = Mouse)
  890. 0, // iInterface
  891. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  892. 9, // bLength
  893. 0x21, // bDescriptorType
  894. 0x11, 0x01, // bcdHID
  895. 0, // bCountryCode
  896. 1, // bNumDescriptors
  897. 0x22, // bDescriptorType
  898. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  899. MSB(sizeof(mouse_report_desc)),
  900. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  901. 7, // bLength
  902. 5, // bDescriptorType
  903. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  904. 0x03, // bmAttributes (0x03=intr)
  905. MOUSE_SIZE, 0, // wMaxPacketSize
  906. MOUSE_INTERVAL, // bInterval
  907. #endif // MOUSE_INTERFACE
  908. #ifdef RAWHID_INTERFACE
  909. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  910. 9, // bLength
  911. 4, // bDescriptorType
  912. RAWHID_INTERFACE, // bInterfaceNumber
  913. 0, // bAlternateSetting
  914. 2, // bNumEndpoints
  915. 0x03, // bInterfaceClass (0x03 = HID)
  916. 0x00, // bInterfaceSubClass
  917. 0x00, // bInterfaceProtocol
  918. 0, // iInterface
  919. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  920. 9, // bLength
  921. 0x21, // bDescriptorType
  922. 0x11, 0x01, // bcdHID
  923. 0, // bCountryCode
  924. 1, // bNumDescriptors
  925. 0x22, // bDescriptorType
  926. LSB(sizeof(rawhid_report_desc)), // wDescriptorLength
  927. MSB(sizeof(rawhid_report_desc)),
  928. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  929. 7, // bLength
  930. 5, // bDescriptorType
  931. RAWHID_TX_ENDPOINT | 0x80, // bEndpointAddress
  932. 0x03, // bmAttributes (0x03=intr)
  933. RAWHID_TX_SIZE, 0, // wMaxPacketSize
  934. RAWHID_TX_INTERVAL, // bInterval
  935. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  936. 7, // bLength
  937. 5, // bDescriptorType
  938. RAWHID_RX_ENDPOINT, // bEndpointAddress
  939. 0x03, // bmAttributes (0x03=intr)
  940. RAWHID_RX_SIZE, 0, // wMaxPacketSize
  941. RAWHID_RX_INTERVAL, // bInterval
  942. #endif // RAWHID_INTERFACE
  943. #ifdef FLIGHTSIM_INTERFACE
  944. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  945. 9, // bLength
  946. 4, // bDescriptorType
  947. FLIGHTSIM_INTERFACE, // bInterfaceNumber
  948. 0, // bAlternateSetting
  949. 2, // bNumEndpoints
  950. 0x03, // bInterfaceClass (0x03 = HID)
  951. 0x00, // bInterfaceSubClass
  952. 0x00, // bInterfaceProtocol
  953. 0, // iInterface
  954. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  955. 9, // bLength
  956. 0x21, // bDescriptorType
  957. 0x11, 0x01, // bcdHID
  958. 0, // bCountryCode
  959. 1, // bNumDescriptors
  960. 0x22, // bDescriptorType
  961. LSB(sizeof(flightsim_report_desc)), // wDescriptorLength
  962. MSB(sizeof(flightsim_report_desc)),
  963. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  964. 7, // bLength
  965. 5, // bDescriptorType
  966. FLIGHTSIM_TX_ENDPOINT | 0x80, // bEndpointAddress
  967. 0x03, // bmAttributes (0x03=intr)
  968. FLIGHTSIM_TX_SIZE, 0, // wMaxPacketSize
  969. FLIGHTSIM_TX_INTERVAL, // bInterval
  970. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  971. 7, // bLength
  972. 5, // bDescriptorType
  973. FLIGHTSIM_RX_ENDPOINT, // bEndpointAddress
  974. 0x03, // bmAttributes (0x03=intr)
  975. FLIGHTSIM_RX_SIZE, 0, // wMaxPacketSize
  976. FLIGHTSIM_RX_INTERVAL, // bInterval
  977. #endif // FLIGHTSIM_INTERFACE
  978. #ifdef SEREMU_INTERFACE
  979. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  980. 9, // bLength
  981. 4, // bDescriptorType
  982. SEREMU_INTERFACE, // bInterfaceNumber
  983. 0, // bAlternateSetting
  984. 2, // bNumEndpoints
  985. 0x03, // bInterfaceClass (0x03 = HID)
  986. 0x00, // bInterfaceSubClass
  987. 0x00, // bInterfaceProtocol
  988. 0, // iInterface
  989. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  990. 9, // bLength
  991. 0x21, // bDescriptorType
  992. 0x11, 0x01, // bcdHID
  993. 0, // bCountryCode
  994. 1, // bNumDescriptors
  995. 0x22, // bDescriptorType
  996. LSB(sizeof(seremu_report_desc)), // wDescriptorLength
  997. MSB(sizeof(seremu_report_desc)),
  998. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  999. 7, // bLength
  1000. 5, // bDescriptorType
  1001. SEREMU_TX_ENDPOINT | 0x80, // bEndpointAddress
  1002. 0x03, // bmAttributes (0x03=intr)
  1003. SEREMU_TX_SIZE, 0, // wMaxPacketSize
  1004. SEREMU_TX_INTERVAL, // bInterval
  1005. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1006. 7, // bLength
  1007. 5, // bDescriptorType
  1008. SEREMU_RX_ENDPOINT, // bEndpointAddress
  1009. 0x03, // bmAttributes (0x03=intr)
  1010. SEREMU_RX_SIZE, 0, // wMaxPacketSize
  1011. SEREMU_RX_INTERVAL, // bInterval
  1012. #endif // SEREMU_INTERFACE
  1013. #ifdef JOYSTICK_INTERFACE
  1014. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1015. 9, // bLength
  1016. 4, // bDescriptorType
  1017. JOYSTICK_INTERFACE, // bInterfaceNumber
  1018. 0, // bAlternateSetting
  1019. 1, // bNumEndpoints
  1020. 0x03, // bInterfaceClass (0x03 = HID)
  1021. 0x00, // bInterfaceSubClass
  1022. 0x00, // bInterfaceProtocol
  1023. 0, // iInterface
  1024. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1025. 9, // bLength
  1026. 0x21, // bDescriptorType
  1027. 0x11, 0x01, // bcdHID
  1028. 0, // bCountryCode
  1029. 1, // bNumDescriptors
  1030. 0x22, // bDescriptorType
  1031. LSB(sizeof(joystick_report_desc)), // wDescriptorLength
  1032. MSB(sizeof(joystick_report_desc)),
  1033. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1034. 7, // bLength
  1035. 5, // bDescriptorType
  1036. JOYSTICK_ENDPOINT | 0x80, // bEndpointAddress
  1037. 0x03, // bmAttributes (0x03=intr)
  1038. JOYSTICK_SIZE, 0, // wMaxPacketSize
  1039. JOYSTICK_INTERVAL, // bInterval
  1040. #endif // JOYSTICK_INTERFACE
  1041. #ifdef MTP_INTERFACE
  1042. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1043. 9, // bLength
  1044. 4, // bDescriptorType
  1045. MTP_INTERFACE, // bInterfaceNumber
  1046. 0, // bAlternateSetting
  1047. 3, // bNumEndpoints
  1048. 0x06, // bInterfaceClass (0x06 = still image)
  1049. 0x01, // bInterfaceSubClass
  1050. 0x01, // bInterfaceProtocol
  1051. 0, // iInterface
  1052. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1053. 7, // bLength
  1054. 5, // bDescriptorType
  1055. MTP_TX_ENDPOINT | 0x80, // bEndpointAddress
  1056. 0x02, // bmAttributes (0x02=bulk)
  1057. MTP_TX_SIZE, 0, // wMaxPacketSize
  1058. 0, // bInterval
  1059. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1060. 7, // bLength
  1061. 5, // bDescriptorType
  1062. MTP_RX_ENDPOINT, // bEndpointAddress
  1063. 0x02, // bmAttributes (0x02=bulk)
  1064. MTP_RX_SIZE, 0, // wMaxPacketSize
  1065. 0, // bInterval
  1066. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1067. 7, // bLength
  1068. 5, // bDescriptorType
  1069. MTP_EVENT_ENDPOINT | 0x80, // bEndpointAddress
  1070. 0x03, // bmAttributes (0x03=intr)
  1071. MTP_EVENT_SIZE, 0, // wMaxPacketSize
  1072. MTP_EVENT_INTERVAL, // bInterval
  1073. #endif // MTP_INTERFACE
  1074. #ifdef KEYMEDIA_INTERFACE
  1075. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1076. 9, // bLength
  1077. 4, // bDescriptorType
  1078. KEYMEDIA_INTERFACE, // bInterfaceNumber
  1079. 0, // bAlternateSetting
  1080. 1, // bNumEndpoints
  1081. 0x03, // bInterfaceClass (0x03 = HID)
  1082. 0x00, // bInterfaceSubClass
  1083. 0x00, // bInterfaceProtocol
  1084. 0, // iInterface
  1085. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1086. 9, // bLength
  1087. 0x21, // bDescriptorType
  1088. 0x11, 0x01, // bcdHID
  1089. 0, // bCountryCode
  1090. 1, // bNumDescriptors
  1091. 0x22, // bDescriptorType
  1092. LSB(sizeof(keymedia_report_desc)), // wDescriptorLength
  1093. MSB(sizeof(keymedia_report_desc)),
  1094. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1095. 7, // bLength
  1096. 5, // bDescriptorType
  1097. KEYMEDIA_ENDPOINT | 0x80, // bEndpointAddress
  1098. 0x03, // bmAttributes (0x03=intr)
  1099. KEYMEDIA_SIZE, 0, // wMaxPacketSize
  1100. KEYMEDIA_INTERVAL, // bInterval
  1101. #endif // KEYMEDIA_INTERFACE
  1102. #ifdef AUDIO_INTERFACE
  1103. // interface association descriptor, USB ECN, Table 9-Z
  1104. 8, // bLength
  1105. 11, // bDescriptorType
  1106. AUDIO_INTERFACE, // bFirstInterface
  1107. 3, // bInterfaceCount
  1108. 0x01, // bFunctionClass
  1109. 0x01, // bFunctionSubClass
  1110. 0x00, // bFunctionProtocol
  1111. 0, // iFunction
  1112. // Standard AudioControl (AC) Interface Descriptor
  1113. // USB DCD for Audio Devices 1.0, Table 4-1, page 36
  1114. 9, // bLength
  1115. 4, // bDescriptorType, 4 = INTERFACE
  1116. AUDIO_INTERFACE, // bInterfaceNumber
  1117. 0, // bAlternateSetting
  1118. 0, // bNumEndpoints
  1119. 1, // bInterfaceClass, 1 = AUDIO
  1120. 1, // bInterfaceSubclass, 1 = AUDIO_CONTROL
  1121. 0, // bInterfaceProtocol
  1122. 0, // iInterface
  1123. // Class-specific AC Interface Header Descriptor
  1124. // USB DCD for Audio Devices 1.0, Table 4-2, page 37-38
  1125. 10, // bLength
  1126. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1127. 0x01, // bDescriptorSubtype, 1 = HEADER
  1128. 0x00, 0x01, // bcdADC (version 1.0)
  1129. LSB(62), MSB(62), // wTotalLength
  1130. 2, // bInCollection
  1131. AUDIO_INTERFACE+1, // baInterfaceNr(1) - Transmit to PC
  1132. AUDIO_INTERFACE+2, // baInterfaceNr(2) - Receive from PC
  1133. // Input Terminal Descriptor
  1134. // USB DCD for Audio Devices 1.0, Table 4-3, page 39
  1135. 12, // bLength
  1136. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1137. 0x02, // bDescriptorSubType, 2 = INPUT_TERMINAL
  1138. 1, // bTerminalID
  1139. //0x01, 0x02, // wTerminalType, 0x0201 = MICROPHONE
  1140. //0x03, 0x06, // wTerminalType, 0x0603 = Line Connector
  1141. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  1142. 0, // bAssocTerminal, 0 = unidirectional
  1143. 2, // bNrChannels
  1144. 0x03, 0x00, // wChannelConfig, 0x0003 = Left & Right Front
  1145. 0, // iChannelNames
  1146. 0, // iTerminal
  1147. // Output Terminal Descriptor
  1148. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  1149. 9, // bLength
  1150. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1151. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  1152. 2, // bTerminalID
  1153. 0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
  1154. 0, // bAssocTerminal, 0 = unidirectional
  1155. 1, // bCSourceID, connected to input terminal, ID=1
  1156. 0, // iTerminal
  1157. // Input Terminal Descriptor
  1158. // USB DCD for Audio Devices 1.0, Table 4-3, page 39
  1159. 12, // bLength
  1160. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1161. 2, // bDescriptorSubType, 2 = INPUT_TERMINAL
  1162. 3, // bTerminalID
  1163. 0x01, 0x01, // wTerminalType, 0x0101 = USB_STREAMING
  1164. 0, // bAssocTerminal, 0 = unidirectional
  1165. 2, // bNrChannels
  1166. 0x03, 0x00, // wChannelConfig, 0x0003 = Left & Right Front
  1167. 0, // iChannelNames
  1168. 0, // iTerminal
  1169. // Volume feature descriptor
  1170. 10, // bLength
  1171. 0x24, // bDescriptorType = CS_INTERFACE
  1172. 0x06, // bDescriptorSubType = FEATURE_UNIT
  1173. 0x31, // bUnitID
  1174. 0x03, // bSourceID (Input Terminal)
  1175. 0x01, // bControlSize (each channel is 1 byte, 3 channels)
  1176. 0x01, // bmaControls(0) Master: Mute
  1177. 0x02, // bmaControls(1) Left: Volume
  1178. 0x02, // bmaControls(2) Right: Volume
  1179. 0x00, // iFeature
  1180. // Output Terminal Descriptor
  1181. // USB DCD for Audio Devices 1.0, Table 4-4, page 40
  1182. 9, // bLength
  1183. 0x24, // bDescriptorType, 0x24 = CS_INTERFACE
  1184. 3, // bDescriptorSubtype, 3 = OUTPUT_TERMINAL
  1185. 4, // bTerminalID
  1186. //0x02, 0x03, // wTerminalType, 0x0302 = Headphones
  1187. 0x02, 0x06, // wTerminalType, 0x0602 = Digital Audio
  1188. 0, // bAssocTerminal, 0 = unidirectional
  1189. 0x31, // bCSourceID, connected to feature, ID=31
  1190. 0, // iTerminal
  1191. // Standard AS Interface Descriptor
  1192. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  1193. // Alternate 0: default setting, disabled zero bandwidth
  1194. 9, // bLenght
  1195. 4, // bDescriptorType = INTERFACE
  1196. AUDIO_INTERFACE+1, // bInterfaceNumber
  1197. 0, // bAlternateSetting
  1198. 0, // bNumEndpoints
  1199. 1, // bInterfaceClass, 1 = AUDIO
  1200. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1201. 0, // bInterfaceProtocol
  1202. 0, // iInterface
  1203. // Alternate 1: streaming data
  1204. 9, // bLenght
  1205. 4, // bDescriptorType = INTERFACE
  1206. AUDIO_INTERFACE+1, // bInterfaceNumber
  1207. 1, // bAlternateSetting
  1208. 1, // bNumEndpoints
  1209. 1, // bInterfaceClass, 1 = AUDIO
  1210. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1211. 0, // bInterfaceProtocol
  1212. 0, // iInterface
  1213. // Class-Specific AS Interface Descriptor
  1214. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  1215. 7, // bLength
  1216. 0x24, // bDescriptorType = CS_INTERFACE
  1217. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  1218. 2, // bTerminalLink: Terminal ID = 2
  1219. 3, // bDelay (approx 3ms delay, audio lib updates)
  1220. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  1221. // Type I Format Descriptor
  1222. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  1223. 11, // bLength
  1224. 0x24, // bDescriptorType = CS_INTERFACE
  1225. 2, // bDescriptorSubtype = FORMAT_TYPE
  1226. 1, // bFormatType = FORMAT_TYPE_I
  1227. 2, // bNrChannels = 2
  1228. 2, // bSubFrameSize = 2 byte
  1229. 16, // bBitResolution = 16 bits
  1230. 1, // bSamFreqType = 1 frequency
  1231. LSB(44100), MSB(44100), 0, // tSamFreq
  1232. // Standard AS Isochronous Audio Data Endpoint Descriptor
  1233. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  1234. 9, // bLength
  1235. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1236. AUDIO_TX_ENDPOINT | 0x80, // bEndpointAddress
  1237. 0x09, // bmAttributes = isochronous, adaptive
  1238. LSB(AUDIO_TX_SIZE), MSB(AUDIO_TX_SIZE), // wMaxPacketSize
  1239. 1, // bInterval, 1 = every frame
  1240. 0, // bRefresh
  1241. 0, // bSynchAddress
  1242. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  1243. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  1244. 7, // bLength
  1245. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  1246. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  1247. 0x00, // bmAttributes
  1248. 0, // bLockDelayUnits, 1 = ms
  1249. 0x00, 0x00, // wLockDelay
  1250. // Standard AS Interface Descriptor
  1251. // USB DCD for Audio Devices 1.0, Section 4.5.1, Table 4-18, page 59
  1252. // Alternate 0: default setting, disabled zero bandwidth
  1253. 9, // bLenght
  1254. 4, // bDescriptorType = INTERFACE
  1255. AUDIO_INTERFACE+2, // bInterfaceNumber
  1256. 0, // bAlternateSetting
  1257. 0, // bNumEndpoints
  1258. 1, // bInterfaceClass, 1 = AUDIO
  1259. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1260. 0, // bInterfaceProtocol
  1261. 0, // iInterface
  1262. // Alternate 1: streaming data
  1263. 9, // bLenght
  1264. 4, // bDescriptorType = INTERFACE
  1265. AUDIO_INTERFACE+2, // bInterfaceNumber
  1266. 1, // bAlternateSetting
  1267. 2, // bNumEndpoints
  1268. 1, // bInterfaceClass, 1 = AUDIO
  1269. 2, // bInterfaceSubclass, 2 = AUDIO_STREAMING
  1270. 0, // bInterfaceProtocol
  1271. 0, // iInterface
  1272. // Class-Specific AS Interface Descriptor
  1273. // USB DCD for Audio Devices 1.0, Section 4.5.2, Table 4-19, page 60
  1274. 7, // bLength
  1275. 0x24, // bDescriptorType = CS_INTERFACE
  1276. 1, // bDescriptorSubtype, 1 = AS_GENERAL
  1277. 3, // bTerminalLink: Terminal ID = 3
  1278. 3, // bDelay (approx 3ms delay, audio lib updates)
  1279. 0x01, 0x00, // wFormatTag, 0x0001 = PCM
  1280. // Type I Format Descriptor
  1281. // USB DCD for Audio Data Formats 1.0, Section 2.2.5, Table 2-1, page 10
  1282. 11, // bLength
  1283. 0x24, // bDescriptorType = CS_INTERFACE
  1284. 2, // bDescriptorSubtype = FORMAT_TYPE
  1285. 1, // bFormatType = FORMAT_TYPE_I
  1286. 2, // bNrChannels = 2
  1287. 2, // bSubFrameSize = 2 byte
  1288. 16, // bBitResolution = 16 bits
  1289. 1, // bSamFreqType = 1 frequency
  1290. LSB(44100), MSB(44100), 0, // tSamFreq
  1291. // Standard AS Isochronous Audio Data Endpoint Descriptor
  1292. // USB DCD for Audio Devices 1.0, Section 4.6.1.1, Table 4-20, page 61-62
  1293. 9, // bLength
  1294. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1295. AUDIO_RX_ENDPOINT, // bEndpointAddress
  1296. 0x05, // bmAttributes = isochronous, asynchronous
  1297. LSB(AUDIO_RX_SIZE), MSB(AUDIO_RX_SIZE), // wMaxPacketSize
  1298. 1, // bInterval, 1 = every frame
  1299. 0, // bRefresh
  1300. AUDIO_SYNC_ENDPOINT | 0x80, // bSynchAddress
  1301. // Class-Specific AS Isochronous Audio Data Endpoint Descriptor
  1302. // USB DCD for Audio Devices 1.0, Section 4.6.1.2, Table 4-21, page 62-63
  1303. 7, // bLength
  1304. 0x25, // bDescriptorType, 0x25 = CS_ENDPOINT
  1305. 1, // bDescriptorSubtype, 1 = EP_GENERAL
  1306. 0x00, // bmAttributes
  1307. 0, // bLockDelayUnits, 1 = ms
  1308. 0x00, 0x00, // wLockDelay
  1309. // Standard AS Isochronous Audio Synch Endpoint Descriptor
  1310. // USB DCD for Audio Devices 1.0, Section 4.6.2.1, Table 4-22, page 63-64
  1311. 9, // bLength
  1312. 5, // bDescriptorType, 5 = ENDPOINT_DESCRIPTOR
  1313. AUDIO_SYNC_ENDPOINT | 0x80, // bEndpointAddress
  1314. 0x11, // bmAttributes = isochronous, feedback
  1315. 3, 0, // wMaxPacketSize, 3 bytes
  1316. 1, // bInterval, 1 = every frame
  1317. 5, // bRefresh, 5 = 32ms
  1318. 0, // bSynchAddress
  1319. #endif
  1320. #ifdef MULTITOUCH_INTERFACE
  1321. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  1322. 9, // bLength
  1323. 4, // bDescriptorType
  1324. MULTITOUCH_INTERFACE, // bInterfaceNumber
  1325. 0, // bAlternateSetting
  1326. 1, // bNumEndpoints
  1327. 0x03, // bInterfaceClass (0x03 = HID)
  1328. 0x00, // bInterfaceSubClass
  1329. 0x00, // bInterfaceProtocol
  1330. 0, // iInterface
  1331. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  1332. 9, // bLength
  1333. 0x21, // bDescriptorType
  1334. 0x11, 0x01, // bcdHID
  1335. 0, // bCountryCode
  1336. 1, // bNumDescriptors
  1337. 0x22, // bDescriptorType
  1338. LSB(sizeof(multitouch_report_desc)), // wDescriptorLength
  1339. MSB(sizeof(multitouch_report_desc)),
  1340. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  1341. 7, // bLength
  1342. 5, // bDescriptorType
  1343. MULTITOUCH_ENDPOINT | 0x80, // bEndpointAddress
  1344. 0x03, // bmAttributes (0x03=intr)
  1345. MULTITOUCH_SIZE, 0, // wMaxPacketSize
  1346. 1, // bInterval
  1347. #endif // KEYMEDIA_INTERFACE
  1348. };
  1349. // **************************************************************
  1350. // String Descriptors
  1351. // **************************************************************
  1352. // The descriptors above can provide human readable strings,
  1353. // referenced by index numbers. These descriptors are the
  1354. // actual string data
  1355. /* defined in usb_names.h
  1356. struct usb_string_descriptor_struct {
  1357. uint8_t bLength;
  1358. uint8_t bDescriptorType;
  1359. uint16_t wString[];
  1360. };
  1361. */
  1362. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  1363. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  1364. extern struct usb_string_descriptor_struct usb_string_product_name
  1365. __attribute__ ((weak, alias("usb_string_product_name_default")));
  1366. extern struct usb_string_descriptor_struct usb_string_serial_number
  1367. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  1368. struct usb_string_descriptor_struct string0 = {
  1369. 4,
  1370. 3,
  1371. {0x0409}
  1372. };
  1373. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  1374. 2 + MANUFACTURER_NAME_LEN * 2,
  1375. 3,
  1376. MANUFACTURER_NAME
  1377. };
  1378. struct usb_string_descriptor_struct usb_string_product_name_default = {
  1379. 2 + PRODUCT_NAME_LEN * 2,
  1380. 3,
  1381. PRODUCT_NAME
  1382. };
  1383. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  1384. 12,
  1385. 3,
  1386. {0,0,0,0,0,0,0,0,0,0}
  1387. };
  1388. #ifdef MTP_INTERFACE
  1389. struct usb_string_descriptor_struct usb_string_mtp = {
  1390. 2 + 3 * 2,
  1391. 3,
  1392. {'M','T','P'}
  1393. };
  1394. #endif
  1395. void usb_init_serialnumber(void)
  1396. {
  1397. char buf[11];
  1398. uint32_t i, num;
  1399. __disable_irq();
  1400. #if defined(HAS_KINETIS_FLASH_FTFA) || defined(HAS_KINETIS_FLASH_FTFL)
  1401. FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
  1402. FTFL_FCCOB0 = 0x41;
  1403. FTFL_FCCOB1 = 15;
  1404. FTFL_FSTAT = FTFL_FSTAT_CCIF;
  1405. while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
  1406. num = *(uint32_t *)&FTFL_FCCOB7;
  1407. #elif defined(HAS_KINETIS_FLASH_FTFE)
  1408. kinetis_hsrun_disable();
  1409. FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
  1410. *(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
  1411. FTFL_FSTAT = FTFL_FSTAT_CCIF;
  1412. while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
  1413. num = *(uint32_t *)&FTFL_FCCOBB;
  1414. kinetis_hsrun_enable();
  1415. #endif
  1416. __enable_irq();
  1417. // add extra zero to work around OS-X CDC-ACM driver bug
  1418. if (num < 10000000) num = num * 10;
  1419. ultoa(num, buf, 10);
  1420. for (i=0; i<10; i++) {
  1421. char c = buf[i];
  1422. if (!c) break;
  1423. usb_string_serial_number_default.wString[i] = c;
  1424. }
  1425. usb_string_serial_number_default.bLength = i * 2 + 2;
  1426. }
  1427. // **************************************************************
  1428. // Descriptors List
  1429. // **************************************************************
  1430. // This table provides access to all the descriptor data above.
  1431. const usb_descriptor_list_t usb_descriptor_list[] = {
  1432. //wValue, wIndex, address, length
  1433. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  1434. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  1435. #ifdef SEREMU_INTERFACE
  1436. {0x2200, SEREMU_INTERFACE, seremu_report_desc, sizeof(seremu_report_desc)},
  1437. {0x2100, SEREMU_INTERFACE, config_descriptor+SEREMU_HID_DESC_OFFSET, 9},
  1438. #endif
  1439. #ifdef KEYBOARD_INTERFACE
  1440. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  1441. {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_HID_DESC_OFFSET, 9},
  1442. #endif
  1443. #ifdef MOUSE_INTERFACE
  1444. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  1445. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_HID_DESC_OFFSET, 9},
  1446. #endif
  1447. #ifdef JOYSTICK_INTERFACE
  1448. {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
  1449. {0x2100, JOYSTICK_INTERFACE, config_descriptor+JOYSTICK_HID_DESC_OFFSET, 9},
  1450. #endif
  1451. #ifdef RAWHID_INTERFACE
  1452. {0x2200, RAWHID_INTERFACE, rawhid_report_desc, sizeof(rawhid_report_desc)},
  1453. {0x2100, RAWHID_INTERFACE, config_descriptor+RAWHID_HID_DESC_OFFSET, 9},
  1454. #endif
  1455. #ifdef FLIGHTSIM_INTERFACE
  1456. {0x2200, FLIGHTSIM_INTERFACE, flightsim_report_desc, sizeof(flightsim_report_desc)},
  1457. {0x2100, FLIGHTSIM_INTERFACE, config_descriptor+FLIGHTSIM_HID_DESC_OFFSET, 9},
  1458. #endif
  1459. #ifdef KEYMEDIA_INTERFACE
  1460. {0x2200, KEYMEDIA_INTERFACE, keymedia_report_desc, sizeof(keymedia_report_desc)},
  1461. {0x2100, KEYMEDIA_INTERFACE, config_descriptor+KEYMEDIA_HID_DESC_OFFSET, 9},
  1462. #endif
  1463. #ifdef MULTITOUCH_INTERFACE
  1464. {0x2200, MULTITOUCH_INTERFACE, multitouch_report_desc, sizeof(multitouch_report_desc)},
  1465. {0x2100, MULTITOUCH_INTERFACE, config_descriptor+MULTITOUCH_HID_DESC_OFFSET, 9},
  1466. #endif
  1467. #ifdef MTP_INTERFACE
  1468. {0x0304, 0x0409, (const uint8_t *)&usb_string_mtp, 0},
  1469. #endif
  1470. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  1471. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  1472. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  1473. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  1474. {0, 0, NULL, 0}
  1475. };
  1476. // **************************************************************
  1477. // Endpoint Configuration
  1478. // **************************************************************
  1479. #if 0
  1480. // 0x00 = not used
  1481. // 0x19 = Recieve only
  1482. // 0x15 = Transmit only
  1483. // 0x1D = Transmit & Recieve
  1484. //
  1485. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1486. {
  1487. 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
  1488. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1489. };
  1490. #endif
  1491. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  1492. {
  1493. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  1494. ENDPOINT1_CONFIG,
  1495. #elif (NUM_ENDPOINTS >= 1)
  1496. ENDPOINT_UNUSED,
  1497. #endif
  1498. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  1499. ENDPOINT2_CONFIG,
  1500. #elif (NUM_ENDPOINTS >= 2)
  1501. ENDPOINT_UNUSED,
  1502. #endif
  1503. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  1504. ENDPOINT3_CONFIG,
  1505. #elif (NUM_ENDPOINTS >= 3)
  1506. ENDPOINT_UNUSED,
  1507. #endif
  1508. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  1509. ENDPOINT4_CONFIG,
  1510. #elif (NUM_ENDPOINTS >= 4)
  1511. ENDPOINT_UNUSED,
  1512. #endif
  1513. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  1514. ENDPOINT5_CONFIG,
  1515. #elif (NUM_ENDPOINTS >= 5)
  1516. ENDPOINT_UNUSED,
  1517. #endif
  1518. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  1519. ENDPOINT6_CONFIG,
  1520. #elif (NUM_ENDPOINTS >= 6)
  1521. ENDPOINT_UNUSED,
  1522. #endif
  1523. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  1524. ENDPOINT7_CONFIG,
  1525. #elif (NUM_ENDPOINTS >= 7)
  1526. ENDPOINT_UNUSED,
  1527. #endif
  1528. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  1529. ENDPOINT8_CONFIG,
  1530. #elif (NUM_ENDPOINTS >= 8)
  1531. ENDPOINT_UNUSED,
  1532. #endif
  1533. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  1534. ENDPOINT9_CONFIG,
  1535. #elif (NUM_ENDPOINTS >= 9)
  1536. ENDPOINT_UNUSED,
  1537. #endif
  1538. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  1539. ENDPOINT10_CONFIG,
  1540. #elif (NUM_ENDPOINTS >= 10)
  1541. ENDPOINT_UNUSED,
  1542. #endif
  1543. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  1544. ENDPOINT11_CONFIG,
  1545. #elif (NUM_ENDPOINTS >= 11)
  1546. ENDPOINT_UNUSED,
  1547. #endif
  1548. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  1549. ENDPOINT12_CONFIG,
  1550. #elif (NUM_ENDPOINTS >= 12)
  1551. ENDPOINT_UNUSED,
  1552. #endif
  1553. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  1554. ENDPOINT13_CONFIG,
  1555. #elif (NUM_ENDPOINTS >= 13)
  1556. ENDPOINT_UNUSED,
  1557. #endif
  1558. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  1559. ENDPOINT14_CONFIG,
  1560. #elif (NUM_ENDPOINTS >= 14)
  1561. ENDPOINT_UNUSED,
  1562. #endif
  1563. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  1564. ENDPOINT15_CONFIG,
  1565. #elif (NUM_ENDPOINTS >= 15)
  1566. ENDPOINT_UNUSED,
  1567. #endif
  1568. };
  1569. #endif // NUM_ENDPOINTS
  1570. #endif // F_CPU >= 20 MHz