usb_descriptor.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * Copyright 2012,2013 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. /** \file
  34. *
  35. * Header file for Descriptors.c.
  36. */
  37. #pragma once
  38. #include <LUFA/Drivers/USB/USB.h>
  39. #ifdef PROTOCOL_CHIBIOS
  40. # include <hal.h>
  41. #endif
  42. /*
  43. * USB descriptor structure
  44. */
  45. typedef struct {
  46. USB_Descriptor_Configuration_Header_t Config;
  47. #ifndef KEYBOARD_SHARED_EP
  48. // Keyboard HID Interface
  49. USB_Descriptor_Interface_t Keyboard_Interface;
  50. USB_HID_Descriptor_HID_t Keyboard_HID;
  51. USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
  52. #else
  53. // Shared Interface
  54. USB_Descriptor_Interface_t Shared_Interface;
  55. USB_HID_Descriptor_HID_t Shared_HID;
  56. USB_Descriptor_Endpoint_t Shared_INEndpoint;
  57. #endif
  58. #ifdef RAW_ENABLE
  59. // Raw HID Interface
  60. USB_Descriptor_Interface_t Raw_Interface;
  61. USB_HID_Descriptor_HID_t Raw_HID;
  62. USB_Descriptor_Endpoint_t Raw_INEndpoint;
  63. USB_Descriptor_Endpoint_t Raw_OUTEndpoint;
  64. #endif
  65. #ifdef XAP_ENABLE
  66. // Mouse HID Interface
  67. USB_Descriptor_Interface_t Xap_Interface;
  68. USB_HID_Descriptor_HID_t Xap_HID;
  69. USB_Descriptor_Endpoint_t Xap_INEndpoint;
  70. USB_Descriptor_Endpoint_t Xap_OUTEndpoint;
  71. #endif
  72. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  73. // Mouse HID Interface
  74. USB_Descriptor_Interface_t Mouse_Interface;
  75. USB_HID_Descriptor_HID_t Mouse_HID;
  76. USB_Descriptor_Endpoint_t Mouse_INEndpoint;
  77. #endif
  78. #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
  79. // Shared Interface
  80. USB_Descriptor_Interface_t Shared_Interface;
  81. USB_HID_Descriptor_HID_t Shared_HID;
  82. USB_Descriptor_Endpoint_t Shared_INEndpoint;
  83. #endif
  84. #ifdef CONSOLE_ENABLE
  85. // Console HID Interface
  86. USB_Descriptor_Interface_t Console_Interface;
  87. USB_HID_Descriptor_HID_t Console_HID;
  88. USB_Descriptor_Endpoint_t Console_INEndpoint;
  89. USB_Descriptor_Endpoint_t Console_OUTEndpoint;
  90. #endif
  91. #ifdef MIDI_ENABLE
  92. USB_Descriptor_Interface_Association_t Audio_Interface_Association;
  93. // MIDI Audio Control Interface
  94. USB_Descriptor_Interface_t Audio_ControlInterface;
  95. USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
  96. // MIDI Audio Streaming Interface
  97. USB_Descriptor_Interface_t Audio_StreamInterface;
  98. USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
  99. USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
  100. USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
  101. USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
  102. USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
  103. USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
  104. USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
  105. USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
  106. USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
  107. #endif
  108. #ifdef VIRTSER_ENABLE
  109. USB_Descriptor_Interface_Association_t CDC_Interface_Association;
  110. // CDC Control Interface
  111. USB_Descriptor_Interface_t CDC_CCI_Interface;
  112. USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
  113. USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
  114. USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
  115. USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
  116. // CDC Data Interface
  117. USB_Descriptor_Interface_t CDC_DCI_Interface;
  118. USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
  119. USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
  120. #endif
  121. #ifdef JOYSTICK_ENABLE
  122. // Joystick HID Interface
  123. USB_Descriptor_Interface_t Joystick_Interface;
  124. USB_HID_Descriptor_HID_t Joystick_HID;
  125. USB_Descriptor_Endpoint_t Joystick_INEndpoint;
  126. #endif
  127. #if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
  128. // Digitizer HID Interface
  129. USB_Descriptor_Interface_t Digitizer_Interface;
  130. USB_HID_Descriptor_HID_t Digitizer_HID;
  131. USB_Descriptor_Endpoint_t Digitizer_INEndpoint;
  132. #endif
  133. } USB_Descriptor_Configuration_t;
  134. /*
  135. * Interface indexes
  136. */
  137. enum usb_interfaces {
  138. #ifndef KEYBOARD_SHARED_EP
  139. KEYBOARD_INTERFACE,
  140. #else
  141. SHARED_INTERFACE,
  142. # define KEYBOARD_INTERFACE SHARED_INTERFACE
  143. #endif
  144. // It is important that the Raw HID interface is at a constant
  145. // interface number, to support Linux/OSX platforms and chrome.hid
  146. // If Raw HID is enabled, let it be always 1.
  147. #ifdef RAW_ENABLE
  148. RAW_INTERFACE,
  149. #endif
  150. #ifdef XAP_ENABLE
  151. XAP_INTERFACE,
  152. #endif
  153. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  154. MOUSE_INTERFACE,
  155. #endif
  156. #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
  157. SHARED_INTERFACE,
  158. #endif
  159. #ifdef CONSOLE_ENABLE
  160. CONSOLE_INTERFACE,
  161. #endif
  162. #ifdef MIDI_ENABLE
  163. AC_INTERFACE,
  164. AS_INTERFACE,
  165. #endif
  166. #ifdef VIRTSER_ENABLE
  167. CCI_INTERFACE,
  168. CDI_INTERFACE,
  169. #endif
  170. #if defined(JOYSTICK_ENABLE)
  171. JOYSTICK_INTERFACE,
  172. #endif
  173. #if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
  174. DIGITIZER_INTERFACE,
  175. #endif
  176. TOTAL_INTERFACES
  177. };
  178. #define NEXT_EPNUM __COUNTER__
  179. /*
  180. * Endpoint numbers
  181. */
  182. enum usb_endpoints {
  183. __unused_epnum__ = NEXT_EPNUM, // Endpoint numbering starts at 1
  184. #ifndef KEYBOARD_SHARED_EP
  185. KEYBOARD_IN_EPNUM = NEXT_EPNUM,
  186. #else
  187. # define KEYBOARD_IN_EPNUM SHARED_IN_EPNUM
  188. #endif
  189. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  190. MOUSE_IN_EPNUM = NEXT_EPNUM,
  191. #else
  192. # define MOUSE_IN_EPNUM SHARED_IN_EPNUM
  193. #endif
  194. #ifdef RAW_ENABLE
  195. RAW_IN_EPNUM = NEXT_EPNUM,
  196. # if STM32_USB_USE_OTG1
  197. # define RAW_OUT_EPNUM RAW_IN_EPNUM
  198. # else
  199. RAW_OUT_EPNUM = NEXT_EPNUM,
  200. # endif
  201. #endif
  202. #ifdef XAP_ENABLE
  203. XAP_IN_EPNUM = NEXT_EPNUM,
  204. # if STM32_USB_USE_OTG1
  205. # define XAP_OUT_EPNUM XAP_IN_EPNUM
  206. # else
  207. XAP_OUT_EPNUM = NEXT_EPNUM,
  208. # endif
  209. #endif
  210. #ifdef SHARED_EP_ENABLE
  211. SHARED_IN_EPNUM = NEXT_EPNUM,
  212. #endif
  213. #ifdef CONSOLE_ENABLE
  214. CONSOLE_IN_EPNUM = NEXT_EPNUM,
  215. # ifdef PROTOCOL_CHIBIOS
  216. // ChibiOS has enough memory and descriptor to actually enable the endpoint
  217. // It could use the same endpoint numbers, as that's supported by ChibiOS
  218. // But the QMK code currently assumes that the endpoint numbers are different
  219. # if STM32_USB_USE_OTG1
  220. # define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
  221. # else
  222. CONSOLE_OUT_EPNUM = NEXT_EPNUM,
  223. # endif
  224. # else
  225. # define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
  226. # endif
  227. #endif
  228. #ifdef MIDI_ENABLE
  229. MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
  230. # if STM32_USB_USE_OTG1
  231. # define MIDI_STREAM_OUT_EPNUM MIDI_STREAM_IN_EPNUM
  232. # else
  233. MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
  234. # endif
  235. #endif
  236. #ifdef VIRTSER_ENABLE
  237. CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
  238. CDC_IN_EPNUM = NEXT_EPNUM,
  239. # if STM32_USB_USE_OTG1
  240. # define CDC_OUT_EPNUM CDC_IN_EPNUM
  241. # else
  242. CDC_OUT_EPNUM = NEXT_EPNUM,
  243. # endif
  244. #endif
  245. #ifdef JOYSTICK_ENABLE
  246. JOYSTICK_IN_EPNUM = NEXT_EPNUM,
  247. # if STM32_USB_USE_OTG1
  248. JOYSTICK_OUT_EPNUM = JOYSTICK_IN_EPNUM,
  249. # else
  250. JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
  251. # endif
  252. #endif
  253. #ifdef DIGITIZER_ENABLE
  254. # if !defined(DIGITIZER_SHARED_EP)
  255. DIGITIZER_IN_EPNUM = NEXT_EPNUM,
  256. # if STM32_USB_USE_OTG1
  257. DIGITIZER_OUT_EPNUM = DIGITIZER_IN_EPNUM,
  258. # else
  259. DIGITIZER_OUT_EPNUM = NEXT_EPNUM,
  260. # endif
  261. # else
  262. # define DIGITIZER_IN_EPNUM SHARED_IN_EPNUM
  263. # endif
  264. #endif
  265. };
  266. #ifdef PROTOCOL_LUFA
  267. // LUFA tells us total endpoints including control
  268. # define MAX_ENDPOINTS (ENDPOINT_TOTAL_ENDPOINTS - 1)
  269. #elif defined(PROTOCOL_CHIBIOS)
  270. // ChibiOS gives us number of available user endpoints, not control
  271. # define MAX_ENDPOINTS USB_MAX_ENDPOINTS
  272. #endif
  273. // TODO - ARM_ATSAM
  274. #if (NEXT_EPNUM - 1) > MAX_ENDPOINTS
  275. # error There are not enough available endpoints to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Console, NKRO, MIDI, Serial, Steno, XAP
  276. #endif
  277. #define KEYBOARD_EPSIZE 8
  278. #define SHARED_EPSIZE 32
  279. #define MOUSE_EPSIZE 8
  280. #define RAW_EPSIZE 32
  281. #define CONSOLE_EPSIZE 32
  282. #define MIDI_STREAM_EPSIZE 64
  283. #define CDC_NOTIFICATION_EPSIZE 8
  284. #define CDC_EPSIZE 16
  285. #define JOYSTICK_EPSIZE 8
  286. #define DIGITIZER_EPSIZE 8
  287. #define XAP_EPSIZE 64
  288. uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress);