logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

usb_descriptor.h (8836B)


  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. # if STM32_USB_USE_OTG1 == TRUE
  42. # define USB_ENDPOINTS_ARE_REORDERABLE
  43. # endif
  44. #endif
  45. /*
  46. * USB descriptor structure
  47. */
  48. typedef struct {
  49. USB_Descriptor_Configuration_Header_t Config;
  50. #ifndef KEYBOARD_SHARED_EP
  51. // Keyboard HID Interface
  52. USB_Descriptor_Interface_t Keyboard_Interface;
  53. USB_HID_Descriptor_HID_t Keyboard_HID;
  54. USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
  55. #else
  56. // Shared Interface
  57. USB_Descriptor_Interface_t Shared_Interface;
  58. USB_HID_Descriptor_HID_t Shared_HID;
  59. USB_Descriptor_Endpoint_t Shared_INEndpoint;
  60. #endif
  61. #ifdef RAW_ENABLE
  62. // Raw HID Interface
  63. USB_Descriptor_Interface_t Raw_Interface;
  64. USB_HID_Descriptor_HID_t Raw_HID;
  65. USB_Descriptor_Endpoint_t Raw_INEndpoint;
  66. USB_Descriptor_Endpoint_t Raw_OUTEndpoint;
  67. #endif
  68. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  69. // Mouse HID Interface
  70. USB_Descriptor_Interface_t Mouse_Interface;
  71. USB_HID_Descriptor_HID_t Mouse_HID;
  72. USB_Descriptor_Endpoint_t Mouse_INEndpoint;
  73. #endif
  74. #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
  75. // Shared Interface
  76. USB_Descriptor_Interface_t Shared_Interface;
  77. USB_HID_Descriptor_HID_t Shared_HID;
  78. USB_Descriptor_Endpoint_t Shared_INEndpoint;
  79. #endif
  80. #ifdef CONSOLE_ENABLE
  81. // Console HID Interface
  82. USB_Descriptor_Interface_t Console_Interface;
  83. USB_HID_Descriptor_HID_t Console_HID;
  84. USB_Descriptor_Endpoint_t Console_INEndpoint;
  85. #endif
  86. #ifdef MIDI_ENABLE
  87. USB_Descriptor_Interface_Association_t Audio_Interface_Association;
  88. // MIDI Audio Control Interface
  89. USB_Descriptor_Interface_t Audio_ControlInterface;
  90. USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
  91. // MIDI Audio Streaming Interface
  92. USB_Descriptor_Interface_t Audio_StreamInterface;
  93. USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
  94. USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
  95. USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
  96. USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
  97. USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
  98. USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
  99. USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
  100. USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
  101. USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
  102. #endif
  103. #ifdef VIRTSER_ENABLE
  104. USB_Descriptor_Interface_Association_t CDC_Interface_Association;
  105. // CDC Control Interface
  106. USB_Descriptor_Interface_t CDC_CCI_Interface;
  107. USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
  108. USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
  109. USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
  110. USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
  111. // CDC Data Interface
  112. USB_Descriptor_Interface_t CDC_DCI_Interface;
  113. USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
  114. USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
  115. #endif
  116. #if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP)
  117. // Joystick HID Interface
  118. USB_Descriptor_Interface_t Joystick_Interface;
  119. USB_HID_Descriptor_HID_t Joystick_HID;
  120. USB_Descriptor_Endpoint_t Joystick_INEndpoint;
  121. #endif
  122. #if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
  123. // Digitizer HID Interface
  124. USB_Descriptor_Interface_t Digitizer_Interface;
  125. USB_HID_Descriptor_HID_t Digitizer_HID;
  126. USB_Descriptor_Endpoint_t Digitizer_INEndpoint;
  127. #endif
  128. } USB_Descriptor_Configuration_t;
  129. /*
  130. * Interface indexes
  131. */
  132. enum usb_interfaces {
  133. #ifndef KEYBOARD_SHARED_EP
  134. KEYBOARD_INTERFACE,
  135. #else
  136. SHARED_INTERFACE,
  137. # define KEYBOARD_INTERFACE SHARED_INTERFACE
  138. #endif
  139. // It is important that the Raw HID interface is at a constant
  140. // interface number, to support Linux/OSX platforms and chrome.hid
  141. // If Raw HID is enabled, let it be always 1.
  142. #ifdef RAW_ENABLE
  143. RAW_INTERFACE,
  144. #endif
  145. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  146. MOUSE_INTERFACE,
  147. #endif
  148. #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
  149. SHARED_INTERFACE,
  150. #endif
  151. #ifdef CONSOLE_ENABLE
  152. CONSOLE_INTERFACE,
  153. #endif
  154. #ifdef MIDI_ENABLE
  155. AC_INTERFACE,
  156. AS_INTERFACE,
  157. #endif
  158. #ifdef VIRTSER_ENABLE
  159. CCI_INTERFACE,
  160. CDI_INTERFACE,
  161. #endif
  162. #if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP)
  163. JOYSTICK_INTERFACE,
  164. #endif
  165. #if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
  166. DIGITIZER_INTERFACE,
  167. #endif
  168. TOTAL_INTERFACES
  169. };
  170. #define IS_VALID_INTERFACE(i) ((i) >= 0 && (i) < TOTAL_INTERFACES)
  171. #define NEXT_EPNUM __COUNTER__
  172. /*
  173. * Endpoint numbers
  174. */
  175. enum usb_endpoints {
  176. __unused_epnum__ = NEXT_EPNUM, // Endpoint numbering starts at 1
  177. #ifndef KEYBOARD_SHARED_EP
  178. KEYBOARD_IN_EPNUM = NEXT_EPNUM,
  179. #else
  180. # define KEYBOARD_IN_EPNUM SHARED_IN_EPNUM
  181. #endif
  182. #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
  183. MOUSE_IN_EPNUM = NEXT_EPNUM,
  184. #else
  185. # define MOUSE_IN_EPNUM SHARED_IN_EPNUM
  186. #endif
  187. #ifdef RAW_ENABLE
  188. RAW_IN_EPNUM = NEXT_EPNUM,
  189. # ifdef USB_ENDPOINTS_ARE_REORDERABLE
  190. # define RAW_OUT_EPNUM RAW_IN_EPNUM
  191. # else
  192. RAW_OUT_EPNUM = NEXT_EPNUM,
  193. # endif
  194. #endif
  195. #ifdef SHARED_EP_ENABLE
  196. SHARED_IN_EPNUM = NEXT_EPNUM,
  197. #endif
  198. #ifdef CONSOLE_ENABLE
  199. CONSOLE_IN_EPNUM = NEXT_EPNUM,
  200. #endif
  201. #ifdef MIDI_ENABLE
  202. MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
  203. # ifdef USB_ENDPOINTS_ARE_REORDERABLE
  204. # define MIDI_STREAM_OUT_EPNUM MIDI_STREAM_IN_EPNUM
  205. # else
  206. MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
  207. # endif
  208. #endif
  209. #ifdef VIRTSER_ENABLE
  210. CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
  211. CDC_IN_EPNUM = NEXT_EPNUM,
  212. # ifdef USB_ENDPOINTS_ARE_REORDERABLE
  213. # define CDC_OUT_EPNUM CDC_IN_EPNUM
  214. # else
  215. CDC_OUT_EPNUM = NEXT_EPNUM,
  216. # endif
  217. #endif
  218. #ifdef JOYSTICK_ENABLE
  219. # if !defined(JOYSTICK_SHARED_EP)
  220. JOYSTICK_IN_EPNUM = NEXT_EPNUM,
  221. # else
  222. # define JOYSTICK_IN_EPNUM SHARED_IN_EPNUM
  223. # endif
  224. #endif
  225. #ifdef DIGITIZER_ENABLE
  226. # if !defined(DIGITIZER_SHARED_EP)
  227. DIGITIZER_IN_EPNUM = NEXT_EPNUM,
  228. # else
  229. # define DIGITIZER_IN_EPNUM SHARED_IN_EPNUM
  230. # endif
  231. #endif
  232. };
  233. #ifdef PROTOCOL_LUFA
  234. // LUFA tells us total endpoints including control
  235. # define MAX_ENDPOINTS (ENDPOINT_TOTAL_ENDPOINTS - 1)
  236. #elif defined(PROTOCOL_CHIBIOS)
  237. // ChibiOS gives us number of available user endpoints, not control
  238. # define MAX_ENDPOINTS USB_MAX_ENDPOINTS
  239. #endif
  240. #if (NEXT_EPNUM - 1) > MAX_ENDPOINTS
  241. # 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
  242. #endif
  243. #define KEYBOARD_EPSIZE 8
  244. #define SHARED_EPSIZE 32
  245. #define MOUSE_EPSIZE 16
  246. #define RAW_EPSIZE 32
  247. #define CONSOLE_EPSIZE 32
  248. #define MIDI_STREAM_EPSIZE 64
  249. #define CDC_NOTIFICATION_EPSIZE 8
  250. #define CDC_EPSIZE 16
  251. #define JOYSTICK_EPSIZE 8
  252. #define DIGITIZER_EPSIZE 8
  253. uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const uint16_t wLength, const void** const DescriptorAddress);