usb_descriptor.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /*
  2. * Copyright 2012 Jun Wako <wakojun@gmail.com>
  3. * This file is based on:
  4. * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse
  5. * LUFA-120219/Demos/Device/Lowlevel/GenericHID
  6. */
  7. /*
  8. LUFA Library
  9. Copyright (C) Dean Camera, 2012.
  10. dean [at] fourwalledcubicle [dot] com
  11. www.lufa-lib.org
  12. */
  13. /*
  14. Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  15. Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
  16. Permission to use, copy, modify, distribute, and sell this
  17. software and its documentation for any purpose is hereby granted
  18. without fee, provided that the above copyright notice appear in
  19. all copies and that both that the copyright notice and this
  20. permission notice and warranty disclaimer appear in supporting
  21. documentation, and that the name of the author not be used in
  22. advertising or publicity pertaining to distribution of the
  23. software without specific, written prior permission.
  24. The author disclaim all warranties with regard to this
  25. software, including all implied warranties of merchantability
  26. and fitness. In no event shall the author be liable for any
  27. special, indirect or consequential damages or any damages
  28. whatsoever resulting from loss of use, data or profits, whether
  29. in an action of contract, negligence or other tortious action,
  30. arising out of or in connection with the use or performance of
  31. this software.
  32. */
  33. #include "util.h"
  34. #include "report.h"
  35. #include "usb_descriptor.h"
  36. #include "usb_descriptor_common.h"
  37. // clang-format off
  38. /*
  39. * HID report descriptors
  40. */
  41. #ifdef KEYBOARD_SHARED_EP
  42. const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
  43. # define SHARED_REPORT_STARTED
  44. #else
  45. const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = {
  46. #endif
  47. HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
  48. HID_RI_USAGE(8, 0x06), // Keyboard
  49. HID_RI_COLLECTION(8, 0x01), // Application
  50. #ifdef KEYBOARD_SHARED_EP
  51. HID_RI_REPORT_ID(8, REPORT_ID_KEYBOARD),
  52. #endif
  53. // Modifiers (8 bits)
  54. HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
  55. HID_RI_USAGE_MINIMUM(8, 0xE0), // Keyboard Left Control
  56. HID_RI_USAGE_MAXIMUM(8, 0xE7), // Keyboard Right GUI
  57. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  58. HID_RI_LOGICAL_MAXIMUM(8, 0x01),
  59. HID_RI_REPORT_COUNT(8, 0x08),
  60. HID_RI_REPORT_SIZE(8, 0x01),
  61. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
  62. // Reserved (1 byte)
  63. HID_RI_REPORT_COUNT(8, 0x01),
  64. HID_RI_REPORT_SIZE(8, 0x08),
  65. HID_RI_INPUT(8, HID_IOF_CONSTANT),
  66. // Keycodes (6 bytes)
  67. HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
  68. HID_RI_USAGE_MINIMUM(8, 0x00),
  69. HID_RI_USAGE_MAXIMUM(8, 0xFF),
  70. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  71. HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
  72. HID_RI_REPORT_COUNT(8, 0x06),
  73. HID_RI_REPORT_SIZE(8, 0x08),
  74. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
  75. // Status LEDs (5 bits)
  76. HID_RI_USAGE_PAGE(8, 0x08), // LED
  77. HID_RI_USAGE_MINIMUM(8, 0x01), // Num Lock
  78. HID_RI_USAGE_MAXIMUM(8, 0x05), // Kana
  79. HID_RI_REPORT_COUNT(8, 0x05),
  80. HID_RI_REPORT_SIZE(8, 0x01),
  81. HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
  82. // LED padding (3 bits)
  83. HID_RI_REPORT_COUNT(8, 0x01),
  84. HID_RI_REPORT_SIZE(8, 0x03),
  85. HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
  86. HID_RI_END_COLLECTION(0),
  87. #ifndef KEYBOARD_SHARED_EP
  88. };
  89. #endif
  90. #ifdef MOUSE_ENABLE
  91. # ifndef MOUSE_SHARED_EP
  92. const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = {
  93. # elif !defined(SHARED_REPORT_STARTED)
  94. const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
  95. # define SHARED_REPORT_STARTED
  96. # endif
  97. HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
  98. HID_RI_USAGE(8, 0x02), // Mouse
  99. HID_RI_COLLECTION(8, 0x01), // Application
  100. # ifdef MOUSE_SHARED_EP
  101. HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
  102. # endif
  103. HID_RI_USAGE(8, 0x01), // Pointer
  104. HID_RI_COLLECTION(8, 0x00), // Physical
  105. // Buttons (5 bits)
  106. HID_RI_USAGE_PAGE(8, 0x09), // Button
  107. HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1
  108. HID_RI_USAGE_MAXIMUM(8, 0x05), // Button 5
  109. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  110. HID_RI_LOGICAL_MAXIMUM(8, 0x01),
  111. HID_RI_REPORT_COUNT(8, 0x05),
  112. HID_RI_REPORT_SIZE(8, 0x01),
  113. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
  114. // Button padding (3 bits)
  115. HID_RI_REPORT_COUNT(8, 0x01),
  116. HID_RI_REPORT_SIZE(8, 0x03),
  117. HID_RI_INPUT(8, HID_IOF_CONSTANT),
  118. // X/Y position (2 bytes)
  119. HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
  120. HID_RI_USAGE(8, 0x30), // X
  121. HID_RI_USAGE(8, 0x31), // Y
  122. HID_RI_LOGICAL_MINIMUM(8, -127),
  123. HID_RI_LOGICAL_MAXIMUM(8, 127),
  124. HID_RI_REPORT_COUNT(8, 0x02),
  125. HID_RI_REPORT_SIZE(8, 0x08),
  126. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
  127. // Vertical wheel (1 byte)
  128. HID_RI_USAGE(8, 0x38), // Wheel
  129. HID_RI_LOGICAL_MINIMUM(8, -127),
  130. HID_RI_LOGICAL_MAXIMUM(8, 127),
  131. HID_RI_REPORT_COUNT(8, 0x01),
  132. HID_RI_REPORT_SIZE(8, 0x08),
  133. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
  134. // Horizontal wheel (1 byte)
  135. HID_RI_USAGE_PAGE(8, 0x0C), // Consumer
  136. HID_RI_USAGE(16, 0x0238), // AC Pan
  137. HID_RI_LOGICAL_MINIMUM(8, -127),
  138. HID_RI_LOGICAL_MAXIMUM(8, 127),
  139. HID_RI_REPORT_COUNT(8, 0x01),
  140. HID_RI_REPORT_SIZE(8, 0x08),
  141. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
  142. HID_RI_END_COLLECTION(0),
  143. HID_RI_END_COLLECTION(0),
  144. # ifndef MOUSE_SHARED_EP
  145. };
  146. # endif
  147. #endif
  148. #if defined(SHARED_EP_ENABLE) && !defined(SHARED_REPORT_STARTED)
  149. const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
  150. #endif
  151. #ifdef EXTRAKEY_ENABLE
  152. HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
  153. HID_RI_USAGE(8, 0x80), // System Control
  154. HID_RI_COLLECTION(8, 0x01), // Application
  155. HID_RI_REPORT_ID(8, REPORT_ID_SYSTEM),
  156. HID_RI_USAGE_MINIMUM(8, 0x01), // Pointer
  157. HID_RI_USAGE_MAXIMUM(16, 0x00B7), // System Display LCD Autoscale
  158. HID_RI_LOGICAL_MINIMUM(8, 0x01),
  159. HID_RI_LOGICAL_MAXIMUM(16, 0x00B7),
  160. HID_RI_REPORT_COUNT(8, 1),
  161. HID_RI_REPORT_SIZE(8, 16),
  162. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
  163. HID_RI_END_COLLECTION(0),
  164. HID_RI_USAGE_PAGE(8, 0x0C), // Consumer
  165. HID_RI_USAGE(8, 0x01), // Consumer Control
  166. HID_RI_COLLECTION(8, 0x01), // Application
  167. HID_RI_REPORT_ID(8, REPORT_ID_CONSUMER),
  168. HID_RI_USAGE_MINIMUM(8, 0x01), // Consumer Control
  169. HID_RI_USAGE_MAXIMUM(16, 0x02A0), // AC Desktop Show All Applications
  170. HID_RI_LOGICAL_MINIMUM(8, 0x01),
  171. HID_RI_LOGICAL_MAXIMUM(16, 0x02A0),
  172. HID_RI_REPORT_COUNT(8, 1),
  173. HID_RI_REPORT_SIZE(8, 16),
  174. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
  175. HID_RI_END_COLLECTION(0),
  176. #endif
  177. #ifdef NKRO_ENABLE
  178. HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
  179. HID_RI_USAGE(8, 0x06), // Keyboard
  180. HID_RI_COLLECTION(8, 0x01), // Application
  181. HID_RI_REPORT_ID(8, REPORT_ID_NKRO),
  182. // Modifiers (8 bits)
  183. HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
  184. HID_RI_USAGE_MINIMUM(8, 0xE0), // Keyboard Left Control
  185. HID_RI_USAGE_MAXIMUM(8, 0xE7), // Keyboard Right GUI
  186. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  187. HID_RI_LOGICAL_MAXIMUM(8, 0x01),
  188. HID_RI_REPORT_COUNT(8, 0x08),
  189. HID_RI_REPORT_SIZE(8, 0x01),
  190. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
  191. // Keycodes
  192. HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
  193. HID_RI_USAGE_MINIMUM(8, 0x00),
  194. HID_RI_USAGE_MAXIMUM(8, KEYBOARD_REPORT_BITS * 8 - 1),
  195. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  196. HID_RI_LOGICAL_MAXIMUM(8, 0x01),
  197. HID_RI_REPORT_COUNT(8, KEYBOARD_REPORT_BITS * 8),
  198. HID_RI_REPORT_SIZE(8, 0x01),
  199. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
  200. // Status LEDs (5 bits)
  201. HID_RI_USAGE_PAGE(8, 0x08), // LED
  202. HID_RI_USAGE_MINIMUM(8, 0x01), // Num Lock
  203. HID_RI_USAGE_MAXIMUM(8, 0x05), // Kana
  204. HID_RI_REPORT_COUNT(8, 0x05),
  205. HID_RI_REPORT_SIZE(8, 0x01),
  206. HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
  207. // LED padding (3 bits)
  208. HID_RI_REPORT_COUNT(8, 0x01),
  209. HID_RI_REPORT_SIZE(8, 0x03),
  210. HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
  211. HID_RI_END_COLLECTION(0),
  212. #endif
  213. #ifdef SHARED_EP_ENABLE
  214. };
  215. #endif
  216. #ifdef RAW_ENABLE
  217. const USB_Descriptor_HIDReport_Datatype_t PROGMEM RawReport[] = {
  218. HID_RI_USAGE_PAGE(16, RAW_USAGE_PAGE), // Vendor Defined
  219. HID_RI_USAGE(8, RAW_USAGE_ID), // Vendor Defined
  220. HID_RI_COLLECTION(8, 0x01), // Application
  221. // Data to host
  222. HID_RI_USAGE(8, 0x62), // Vendor Defined
  223. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  224. HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
  225. HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
  226. HID_RI_REPORT_SIZE(8, 0x08),
  227. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
  228. // Data from host
  229. HID_RI_USAGE(8, 0x63), // Vendor Defined
  230. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  231. HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
  232. HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
  233. HID_RI_REPORT_SIZE(8, 0x08),
  234. HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
  235. HID_RI_END_COLLECTION(0),
  236. };
  237. #endif
  238. #ifdef CONSOLE_ENABLE
  239. const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
  240. HID_RI_USAGE_PAGE(16, 0xFF31), // Vendor Defined (PJRC Teensy compatible)
  241. HID_RI_USAGE(8, 0x74), // Vendor Defined (PJRC Teensy compatible)
  242. HID_RI_COLLECTION(8, 0x01), // Application
  243. // Data to host
  244. HID_RI_USAGE(8, 0x75), // Vendor Defined
  245. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  246. HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
  247. HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
  248. HID_RI_REPORT_SIZE(8, 0x08),
  249. HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
  250. // Data from host
  251. HID_RI_USAGE(8, 0x76), // Vendor Defined
  252. HID_RI_LOGICAL_MINIMUM(8, 0x00),
  253. HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
  254. HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
  255. HID_RI_REPORT_SIZE(8, 0x08),
  256. HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
  257. HID_RI_END_COLLECTION(0),
  258. };
  259. #endif
  260. /*
  261. * Device descriptor
  262. */
  263. const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
  264. .Header = {
  265. .Size = sizeof(USB_Descriptor_Device_t),
  266. .Type = DTYPE_Device
  267. },
  268. .USBSpecification = VERSION_BCD(1, 1, 0),
  269. #if VIRTSER_ENABLE
  270. .Class = USB_CSCP_IADDeviceClass,
  271. .SubClass = USB_CSCP_IADDeviceSubclass,
  272. .Protocol = USB_CSCP_IADDeviceProtocol,
  273. #else
  274. .Class = USB_CSCP_NoDeviceClass,
  275. .SubClass = USB_CSCP_NoDeviceSubclass,
  276. .Protocol = USB_CSCP_NoDeviceProtocol,
  277. #endif
  278. .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
  279. // Specified in config.h
  280. .VendorID = VENDOR_ID,
  281. .ProductID = PRODUCT_ID,
  282. .ReleaseNumber = DEVICE_VER,
  283. .ManufacturerStrIndex = 0x01,
  284. .ProductStrIndex = 0x02,
  285. .SerialNumStrIndex = 0x03,
  286. .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
  287. };
  288. #ifndef USB_MAX_POWER_CONSUMPTION
  289. # define USB_MAX_POWER_CONSUMPTION 500
  290. #endif
  291. #ifndef USB_POLLING_INTERVAL_MS
  292. # define USB_POLLING_INTERVAL_MS 10
  293. #endif
  294. /*
  295. * Configuration descriptors
  296. */
  297. const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
  298. .Config = {
  299. .Header = {
  300. .Size = sizeof(USB_Descriptor_Configuration_Header_t),
  301. .Type = DTYPE_Configuration
  302. },
  303. .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
  304. .TotalInterfaces = TOTAL_INTERFACES,
  305. .ConfigurationNumber = 1,
  306. .ConfigurationStrIndex = NO_DESCRIPTOR,
  307. .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP),
  308. .MaxPowerConsumption = USB_CONFIG_POWER_MA(USB_MAX_POWER_CONSUMPTION)
  309. },
  310. #ifndef KEYBOARD_SHARED_EP
  311. /*
  312. * Keyboard
  313. */
  314. .Keyboard_Interface = {
  315. .Header = {
  316. .Size = sizeof(USB_Descriptor_Interface_t),
  317. .Type = DTYPE_Interface
  318. },
  319. .InterfaceNumber = KEYBOARD_INTERFACE,
  320. .AlternateSetting = 0x00,
  321. .TotalEndpoints = 1,
  322. .Class = HID_CSCP_HIDClass,
  323. .SubClass = HID_CSCP_BootSubclass,
  324. .Protocol = HID_CSCP_KeyboardBootProtocol,
  325. .InterfaceStrIndex = NO_DESCRIPTOR
  326. },
  327. .Keyboard_HID = {
  328. .Header = {
  329. .Size = sizeof(USB_HID_Descriptor_HID_t),
  330. .Type = HID_DTYPE_HID
  331. },
  332. .HIDSpec = VERSION_BCD(1, 1, 1),
  333. .CountryCode = 0x00,
  334. .TotalReportDescriptors = 1,
  335. .HIDReportType = HID_DTYPE_Report,
  336. .HIDReportLength = sizeof(KeyboardReport)
  337. },
  338. .Keyboard_INEndpoint = {
  339. .Header = {
  340. .Size = sizeof(USB_Descriptor_Endpoint_t),
  341. .Type = DTYPE_Endpoint
  342. },
  343. .EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM),
  344. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  345. .EndpointSize = KEYBOARD_EPSIZE,
  346. .PollingIntervalMS = USB_POLLING_INTERVAL_MS
  347. },
  348. #endif
  349. #ifdef RAW_ENABLE
  350. /*
  351. * Raw HID
  352. */
  353. .Raw_Interface = {
  354. .Header = {
  355. .Size = sizeof(USB_Descriptor_Interface_t),
  356. .Type = DTYPE_Interface
  357. },
  358. .InterfaceNumber = RAW_INTERFACE,
  359. .AlternateSetting = 0x00,
  360. .TotalEndpoints = 2,
  361. .Class = HID_CSCP_HIDClass,
  362. .SubClass = HID_CSCP_NonBootSubclass,
  363. .Protocol = HID_CSCP_NonBootProtocol,
  364. .InterfaceStrIndex = NO_DESCRIPTOR
  365. },
  366. .Raw_HID = {
  367. .Header = {
  368. .Size = sizeof(USB_HID_Descriptor_HID_t),
  369. .Type = HID_DTYPE_HID
  370. },
  371. .HIDSpec = VERSION_BCD(1, 1, 1),
  372. .CountryCode = 0x00,
  373. .TotalReportDescriptors = 1,
  374. .HIDReportType = HID_DTYPE_Report,
  375. .HIDReportLength = sizeof(RawReport)
  376. },
  377. .Raw_INEndpoint = {
  378. .Header = {
  379. .Size = sizeof(USB_Descriptor_Endpoint_t),
  380. .Type = DTYPE_Endpoint
  381. },
  382. .EndpointAddress = (ENDPOINT_DIR_IN | RAW_IN_EPNUM),
  383. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  384. .EndpointSize = RAW_EPSIZE,
  385. .PollingIntervalMS = 0x01
  386. },
  387. .Raw_OUTEndpoint = {
  388. .Header = {
  389. .Size = sizeof(USB_Descriptor_Endpoint_t),
  390. .Type = DTYPE_Endpoint
  391. },
  392. .EndpointAddress = (ENDPOINT_DIR_OUT | RAW_OUT_EPNUM),
  393. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  394. .EndpointSize = RAW_EPSIZE,
  395. .PollingIntervalMS = 0x01
  396. },
  397. #endif
  398. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  399. /*
  400. * Mouse
  401. */
  402. .Mouse_Interface = {
  403. .Header = {
  404. .Size = sizeof(USB_Descriptor_Interface_t),
  405. .Type = DTYPE_Interface
  406. },
  407. .InterfaceNumber = MOUSE_INTERFACE,
  408. .AlternateSetting = 0x00,
  409. .TotalEndpoints = 1,
  410. .Class = HID_CSCP_HIDClass,
  411. .SubClass = HID_CSCP_BootSubclass,
  412. .Protocol = HID_CSCP_MouseBootProtocol,
  413. .InterfaceStrIndex = NO_DESCRIPTOR
  414. },
  415. .Mouse_HID = {
  416. .Header = {
  417. .Size = sizeof(USB_HID_Descriptor_HID_t),
  418. .Type = HID_DTYPE_HID
  419. },
  420. .HIDSpec = VERSION_BCD(1, 1, 1),
  421. .CountryCode = 0x00,
  422. .TotalReportDescriptors = 1,
  423. .HIDReportType = HID_DTYPE_Report,
  424. .HIDReportLength = sizeof(MouseReport)
  425. },
  426. .Mouse_INEndpoint = {
  427. .Header = {
  428. .Size = sizeof(USB_Descriptor_Endpoint_t),
  429. .Type = DTYPE_Endpoint
  430. },
  431. .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM),
  432. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  433. .EndpointSize = MOUSE_EPSIZE,
  434. .PollingIntervalMS = USB_POLLING_INTERVAL_MS
  435. },
  436. #endif
  437. #ifdef SHARED_EP_ENABLE
  438. /*
  439. * Shared
  440. */
  441. .Shared_Interface = {
  442. .Header = {
  443. .Size = sizeof(USB_Descriptor_Interface_t),
  444. .Type = DTYPE_Interface
  445. },
  446. .InterfaceNumber = SHARED_INTERFACE,
  447. .AlternateSetting = 0x00,
  448. .TotalEndpoints = 1,
  449. .Class = HID_CSCP_HIDClass,
  450. # ifdef KEYBOARD_SHARED_EP
  451. .SubClass = HID_CSCP_BootSubclass,
  452. .Protocol = HID_CSCP_KeyboardBootProtocol,
  453. # else
  454. .SubClass = HID_CSCP_NonBootSubclass,
  455. .Protocol = HID_CSCP_NonBootProtocol,
  456. # endif
  457. .InterfaceStrIndex = NO_DESCRIPTOR
  458. },
  459. .Shared_HID = {
  460. .Header = {
  461. .Size = sizeof(USB_HID_Descriptor_HID_t),
  462. .Type = HID_DTYPE_HID
  463. },
  464. .HIDSpec = VERSION_BCD(1, 1, 1),
  465. .CountryCode = 0x00,
  466. .TotalReportDescriptors = 1,
  467. .HIDReportType = HID_DTYPE_Report,
  468. .HIDReportLength = sizeof(SharedReport)
  469. },
  470. .Shared_INEndpoint = {
  471. .Header = {
  472. .Size = sizeof(USB_Descriptor_Endpoint_t),
  473. .Type = DTYPE_Endpoint
  474. },
  475. .EndpointAddress = (ENDPOINT_DIR_IN | SHARED_IN_EPNUM),
  476. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  477. .EndpointSize = SHARED_EPSIZE,
  478. .PollingIntervalMS = USB_POLLING_INTERVAL_MS
  479. },
  480. #endif
  481. #ifdef CONSOLE_ENABLE
  482. /*
  483. * Console
  484. */
  485. .Console_Interface = {
  486. .Header = {
  487. .Size = sizeof(USB_Descriptor_Interface_t),
  488. .Type = DTYPE_Interface
  489. },
  490. .InterfaceNumber = CONSOLE_INTERFACE,
  491. .AlternateSetting = 0x00,
  492. .TotalEndpoints = 2,
  493. .Class = HID_CSCP_HIDClass,
  494. .SubClass = HID_CSCP_NonBootSubclass,
  495. .Protocol = HID_CSCP_NonBootProtocol,
  496. .InterfaceStrIndex = NO_DESCRIPTOR
  497. },
  498. .Console_HID = {
  499. .Header = {
  500. .Size = sizeof(USB_HID_Descriptor_HID_t),
  501. .Type = HID_DTYPE_HID
  502. },
  503. .HIDSpec = VERSION_BCD(1, 1, 1),
  504. .CountryCode = 0x00,
  505. .TotalReportDescriptors = 1,
  506. .HIDReportType = HID_DTYPE_Report,
  507. .HIDReportLength = sizeof(ConsoleReport)
  508. },
  509. .Console_INEndpoint = {
  510. .Header = {
  511. .Size = sizeof(USB_Descriptor_Endpoint_t),
  512. .Type = DTYPE_Endpoint
  513. },
  514. .EndpointAddress = (ENDPOINT_DIR_IN | CONSOLE_IN_EPNUM),
  515. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  516. .EndpointSize = CONSOLE_EPSIZE,
  517. .PollingIntervalMS = 0x01
  518. },
  519. .Console_OUTEndpoint = {
  520. .Header = {
  521. .Size = sizeof(USB_Descriptor_Endpoint_t),
  522. .Type = DTYPE_Endpoint
  523. },
  524. .EndpointAddress = (ENDPOINT_DIR_OUT | CONSOLE_OUT_EPNUM),
  525. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  526. .EndpointSize = CONSOLE_EPSIZE,
  527. .PollingIntervalMS = 0x01
  528. },
  529. #endif
  530. #ifdef MIDI_ENABLE
  531. /*
  532. * MIDI
  533. */
  534. .Audio_Interface_Association = {
  535. .Header = {
  536. .Size = sizeof(USB_Descriptor_Interface_Association_t),
  537. .Type = DTYPE_InterfaceAssociation
  538. },
  539. .FirstInterfaceIndex = AC_INTERFACE,
  540. .TotalInterfaces = 2,
  541. .Class = AUDIO_CSCP_AudioClass,
  542. .SubClass = AUDIO_CSCP_ControlSubclass,
  543. .Protocol = AUDIO_CSCP_ControlProtocol,
  544. .IADStrIndex = NO_DESCRIPTOR,
  545. },
  546. .Audio_ControlInterface = {
  547. .Header = {
  548. .Size = sizeof(USB_Descriptor_Interface_t),
  549. .Type = DTYPE_Interface
  550. },
  551. .InterfaceNumber = AC_INTERFACE,
  552. .AlternateSetting = 0,
  553. .TotalEndpoints = 0,
  554. .Class = AUDIO_CSCP_AudioClass,
  555. .SubClass = AUDIO_CSCP_ControlSubclass,
  556. .Protocol = AUDIO_CSCP_ControlProtocol,
  557. .InterfaceStrIndex = NO_DESCRIPTOR
  558. },
  559. .Audio_ControlInterface_SPC = {
  560. .Header = {
  561. .Size = sizeof(USB_Audio_Descriptor_Interface_AC_t),
  562. .Type = AUDIO_DTYPE_CSInterface
  563. },
  564. .Subtype = AUDIO_DSUBTYPE_CSInterface_Header,
  565. .ACSpecification = VERSION_BCD(1, 0, 0),
  566. .TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t),
  567. .InCollection = 1,
  568. .InterfaceNumber = AS_INTERFACE,
  569. },
  570. .Audio_StreamInterface = {
  571. .Header = {
  572. .Size = sizeof(USB_Descriptor_Interface_t),
  573. .Type = DTYPE_Interface
  574. },
  575. .InterfaceNumber = AS_INTERFACE,
  576. .AlternateSetting = 0,
  577. .TotalEndpoints = 2,
  578. .Class = AUDIO_CSCP_AudioClass,
  579. .SubClass = AUDIO_CSCP_MIDIStreamingSubclass,
  580. .Protocol = AUDIO_CSCP_StreamingProtocol,
  581. .InterfaceStrIndex = NO_DESCRIPTOR
  582. },
  583. .Audio_StreamInterface_SPC = {
  584. .Header = {
  585. .Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t),
  586. .Type = AUDIO_DTYPE_CSInterface
  587. },
  588. .Subtype = AUDIO_DSUBTYPE_CSInterface_General,
  589. .AudioSpecification = VERSION_BCD(1, 0, 0),
  590. .TotalLength = offsetof(USB_Descriptor_Configuration_t, MIDI_Out_Jack_Endpoint_SPC) + sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t) - offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC)
  591. },
  592. .MIDI_In_Jack_Emb = {
  593. .Header = {
  594. .Size = sizeof(USB_MIDI_Descriptor_InputJack_t),
  595. .Type = AUDIO_DTYPE_CSInterface
  596. },
  597. .Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
  598. .JackType = MIDI_JACKTYPE_Embedded,
  599. .JackID = 0x01,
  600. .JackStrIndex = NO_DESCRIPTOR
  601. },
  602. .MIDI_In_Jack_Ext = {
  603. .Header = {
  604. .Size = sizeof(USB_MIDI_Descriptor_InputJack_t),
  605. .Type = AUDIO_DTYPE_CSInterface
  606. },
  607. .Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
  608. .JackType = MIDI_JACKTYPE_External,
  609. .JackID = 0x02,
  610. .JackStrIndex = NO_DESCRIPTOR
  611. },
  612. .MIDI_Out_Jack_Emb = {
  613. .Header = {
  614. .Size = sizeof(USB_MIDI_Descriptor_OutputJack_t),
  615. .Type = AUDIO_DTYPE_CSInterface
  616. },
  617. .Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
  618. .JackType = MIDI_JACKTYPE_Embedded,
  619. .JackID = 0x03,
  620. .NumberOfPins = 1,
  621. .SourceJackID = {0x02},
  622. .SourcePinID = {0x01},
  623. .JackStrIndex = NO_DESCRIPTOR
  624. },
  625. .MIDI_Out_Jack_Ext = {
  626. .Header = {
  627. .Size = sizeof(USB_MIDI_Descriptor_OutputJack_t),
  628. .Type = AUDIO_DTYPE_CSInterface
  629. },
  630. .Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
  631. .JackType = MIDI_JACKTYPE_External,
  632. .JackID = 0x04,
  633. .NumberOfPins = 1,
  634. .SourceJackID = {0x01},
  635. .SourcePinID = {0x01},
  636. .JackStrIndex = NO_DESCRIPTOR
  637. },
  638. .MIDI_In_Jack_Endpoint = {
  639. .Endpoint = {
  640. .Header = {
  641. .Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
  642. .Type = DTYPE_Endpoint
  643. },
  644. .EndpointAddress = MIDI_STREAM_OUT_EPADDR,
  645. .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  646. .EndpointSize = MIDI_STREAM_EPSIZE,
  647. .PollingIntervalMS = 0x05
  648. },
  649. .Refresh = 0,
  650. .SyncEndpointNumber = 0
  651. },
  652. .MIDI_In_Jack_Endpoint_SPC = {
  653. .Header = {
  654. .Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t),
  655. .Type = AUDIO_DTYPE_CSEndpoint
  656. },
  657. .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
  658. .TotalEmbeddedJacks = 0x01,
  659. .AssociatedJackID = {0x01}
  660. },
  661. .MIDI_Out_Jack_Endpoint = {
  662. .Endpoint = {
  663. .Header = {
  664. .Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
  665. .Type = DTYPE_Endpoint
  666. },
  667. .EndpointAddress = MIDI_STREAM_IN_EPADDR,
  668. .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  669. .EndpointSize = MIDI_STREAM_EPSIZE,
  670. .PollingIntervalMS = 0x05
  671. },
  672. .Refresh = 0,
  673. .SyncEndpointNumber = 0
  674. },
  675. .MIDI_Out_Jack_Endpoint_SPC = {
  676. .Header = {
  677. .Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t),
  678. .Type = AUDIO_DTYPE_CSEndpoint
  679. },
  680. .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
  681. .TotalEmbeddedJacks = 0x01,
  682. .AssociatedJackID = {0x03}
  683. },
  684. #endif
  685. #ifdef VIRTSER_ENABLE
  686. /*
  687. * Virtual Serial
  688. */
  689. .CDC_Interface_Association = {
  690. .Header = {
  691. .Size = sizeof(USB_Descriptor_Interface_Association_t),
  692. .Type = DTYPE_InterfaceAssociation
  693. },
  694. .FirstInterfaceIndex = CCI_INTERFACE,
  695. .TotalInterfaces = 2,
  696. .Class = CDC_CSCP_CDCClass,
  697. .SubClass = CDC_CSCP_ACMSubclass,
  698. .Protocol = CDC_CSCP_ATCommandProtocol,
  699. .IADStrIndex = NO_DESCRIPTOR,
  700. },
  701. .CDC_CCI_Interface = {
  702. .Header = {
  703. .Size = sizeof(USB_Descriptor_Interface_t),
  704. .Type = DTYPE_Interface
  705. },
  706. .InterfaceNumber = CCI_INTERFACE,
  707. .AlternateSetting = 0,
  708. .TotalEndpoints = 1,
  709. .Class = CDC_CSCP_CDCClass,
  710. .SubClass = CDC_CSCP_ACMSubclass,
  711. .Protocol = CDC_CSCP_ATCommandProtocol,
  712. .InterfaceStrIndex = NO_DESCRIPTOR
  713. },
  714. .CDC_Functional_Header = {
  715. .Header = {
  716. .Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t),
  717. .Type = CDC_DTYPE_CSInterface
  718. },
  719. .Subtype = 0x00,
  720. .CDCSpecification = VERSION_BCD(1, 1, 0),
  721. },
  722. .CDC_Functional_ACM = {
  723. .Header = {
  724. .Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t),
  725. .Type = CDC_DTYPE_CSInterface
  726. },
  727. .Subtype = 0x02,
  728. .Capabilities = 0x02,
  729. },
  730. .CDC_Functional_Union = {
  731. .Header = {
  732. .Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t),
  733. .Type = CDC_DTYPE_CSInterface
  734. },
  735. .Subtype = 0x06,
  736. .MasterInterfaceNumber = CCI_INTERFACE,
  737. .SlaveInterfaceNumber = CDI_INTERFACE,
  738. },
  739. .CDC_NotificationEndpoint = {
  740. .Header = {
  741. .Size = sizeof(USB_Descriptor_Endpoint_t),
  742. .Type = DTYPE_Endpoint
  743. },
  744. .EndpointAddress = CDC_NOTIFICATION_EPADDR,
  745. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  746. .EndpointSize = CDC_NOTIFICATION_EPSIZE,
  747. .PollingIntervalMS = 0xFF
  748. },
  749. .CDC_DCI_Interface = {
  750. .Header = {
  751. .Size = sizeof(USB_Descriptor_Interface_t),
  752. .Type = DTYPE_Interface
  753. },
  754. .InterfaceNumber = CDI_INTERFACE,
  755. .AlternateSetting = 0,
  756. .TotalEndpoints = 2,
  757. .Class = CDC_CSCP_CDCDataClass,
  758. .SubClass = CDC_CSCP_NoDataSubclass,
  759. .Protocol = CDC_CSCP_NoDataProtocol,
  760. .InterfaceStrIndex = NO_DESCRIPTOR
  761. },
  762. .CDC_DataOutEndpoint = {
  763. .Header = {
  764. .Size = sizeof(USB_Descriptor_Endpoint_t),
  765. .Type = DTYPE_Endpoint
  766. },
  767. .EndpointAddress = CDC_OUT_EPADDR,
  768. .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  769. .EndpointSize = CDC_EPSIZE,
  770. .PollingIntervalMS = 0x05
  771. },
  772. .CDC_DataInEndpoint = {
  773. .Header = {
  774. .Size = sizeof(USB_Descriptor_Endpoint_t),
  775. .Type = DTYPE_Endpoint
  776. },
  777. .EndpointAddress = CDC_IN_EPADDR,
  778. .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  779. .EndpointSize = CDC_EPSIZE,
  780. .PollingIntervalMS = 0x05
  781. },
  782. #endif
  783. };
  784. /*
  785. * String descriptors
  786. */
  787. const USB_Descriptor_String_t PROGMEM LanguageString = {
  788. .Header = {
  789. .Size = USB_STRING_LEN(1),
  790. .Type = DTYPE_String
  791. },
  792. .UnicodeString = {LANGUAGE_ID_ENG}
  793. };
  794. const USB_Descriptor_String_t PROGMEM ManufacturerString = {
  795. .Header = {
  796. .Size = USB_STRING_LEN(sizeof(STR(MANUFACTURER)) - 1), // Subtract 1 for null terminator
  797. .Type = DTYPE_String
  798. },
  799. .UnicodeString = LSTR(MANUFACTURER)
  800. };
  801. const USB_Descriptor_String_t PROGMEM ProductString = {
  802. .Header = {
  803. .Size = USB_STRING_LEN(sizeof(STR(PRODUCT)) - 1), // Subtract 1 for null terminator
  804. .Type = DTYPE_String
  805. },
  806. .UnicodeString = LSTR(PRODUCT)
  807. };
  808. #ifndef SERIAL_NUMBER
  809. # define SERIAL_NUMBER 0
  810. #endif
  811. const USB_Descriptor_String_t PROGMEM SerialNumberString = {
  812. .Header = {
  813. .Size = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), // Subtract 1 for null terminator
  814. .Type = DTYPE_String
  815. },
  816. .UnicodeString = LSTR(SERIAL_NUMBER)
  817. };
  818. // clang-format on
  819. /**
  820. * This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
  821. * documentation) by the application code so that the address and size of a requested descriptor can be given
  822. * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
  823. * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
  824. * USB host.
  825. */
  826. uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress) {
  827. const uint8_t DescriptorType = (wValue >> 8);
  828. const uint8_t DescriptorIndex = (wValue & 0xFF);
  829. const void* Address = NULL;
  830. uint16_t Size = NO_DESCRIPTOR;
  831. switch (DescriptorType) {
  832. case DTYPE_Device:
  833. Address = &DeviceDescriptor;
  834. Size = sizeof(USB_Descriptor_Device_t);
  835. break;
  836. case DTYPE_Configuration:
  837. Address = &ConfigurationDescriptor;
  838. Size = sizeof(USB_Descriptor_Configuration_t);
  839. break;
  840. case DTYPE_String:
  841. switch (DescriptorIndex) {
  842. case 0x00:
  843. Address = &LanguageString;
  844. Size = pgm_read_byte(&LanguageString.Header.Size);
  845. break;
  846. case 0x01:
  847. Address = &ManufacturerString;
  848. Size = pgm_read_byte(&ManufacturerString.Header.Size);
  849. break;
  850. case 0x02:
  851. Address = &ProductString;
  852. Size = pgm_read_byte(&ProductString.Header.Size);
  853. break;
  854. case 0x03:
  855. Address = &SerialNumberString;
  856. Size = pgm_read_byte(&SerialNumberString.Header.Size);
  857. break;
  858. }
  859. break;
  860. case HID_DTYPE_HID:
  861. switch (wIndex) {
  862. #ifndef KEYBOARD_SHARED_EP
  863. case KEYBOARD_INTERFACE:
  864. Address = &ConfigurationDescriptor.Keyboard_HID;
  865. Size = sizeof(USB_HID_Descriptor_HID_t);
  866. break;
  867. #endif
  868. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  869. case MOUSE_INTERFACE:
  870. Address = &ConfigurationDescriptor.Mouse_HID;
  871. Size = sizeof(USB_HID_Descriptor_HID_t);
  872. break;
  873. #endif
  874. #ifdef SHARED_EP_ENABLE
  875. case SHARED_INTERFACE:
  876. Address = &ConfigurationDescriptor.Shared_HID;
  877. Size = sizeof(USB_HID_Descriptor_HID_t);
  878. break;
  879. #endif
  880. #ifdef RAW_ENABLE
  881. case RAW_INTERFACE:
  882. Address = &ConfigurationDescriptor.Raw_HID;
  883. Size = sizeof(USB_HID_Descriptor_HID_t);
  884. break;
  885. #endif
  886. #ifdef CONSOLE_ENABLE
  887. case CONSOLE_INTERFACE:
  888. Address = &ConfigurationDescriptor.Console_HID;
  889. Size = sizeof(USB_HID_Descriptor_HID_t);
  890. break;
  891. #endif
  892. }
  893. break;
  894. case HID_DTYPE_Report:
  895. switch (wIndex) {
  896. #ifndef KEYBOARD_SHARED_EP
  897. case KEYBOARD_INTERFACE:
  898. Address = &KeyboardReport;
  899. Size = sizeof(KeyboardReport);
  900. break;
  901. #endif
  902. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  903. case MOUSE_INTERFACE:
  904. Address = &MouseReport;
  905. Size = sizeof(MouseReport);
  906. break;
  907. #endif
  908. #ifdef SHARED_EP_ENABLE
  909. case SHARED_INTERFACE:
  910. Address = &SharedReport;
  911. Size = sizeof(SharedReport);
  912. break;
  913. #endif
  914. #ifdef RAW_ENABLE
  915. case RAW_INTERFACE:
  916. Address = &RawReport;
  917. Size = sizeof(RawReport);
  918. break;
  919. #endif
  920. #ifdef CONSOLE_ENABLE
  921. case CONSOLE_INTERFACE:
  922. Address = &ConsoleReport;
  923. Size = sizeof(ConsoleReport);
  924. break;
  925. #endif
  926. }
  927. break;
  928. }
  929. *DescriptorAddress = Address;
  930. return Size;
  931. }