usb_descriptor.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. #ifndef _DESCRIPTORS_H_
  38. #define _DESCRIPTORS_H_
  39. #include <LUFA/Drivers/USB/USB.h>
  40. #ifdef PROTOCOL_CHIBIOS
  41. #include "hal.h"
  42. #endif
  43. typedef struct
  44. {
  45. USB_Descriptor_Configuration_Header_t Config;
  46. // Keyboard HID Interface
  47. USB_Descriptor_Interface_t Keyboard_Interface;
  48. USB_HID_Descriptor_HID_t Keyboard_HID;
  49. USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
  50. #ifdef MOUSE_ENABLE
  51. // Mouse HID Interface
  52. USB_Descriptor_Interface_t Mouse_Interface;
  53. USB_HID_Descriptor_HID_t Mouse_HID;
  54. USB_Descriptor_Endpoint_t Mouse_INEndpoint;
  55. #endif
  56. #ifdef EXTRAKEY_ENABLE
  57. // Extrakey HID Interface
  58. USB_Descriptor_Interface_t Extrakey_Interface;
  59. USB_HID_Descriptor_HID_t Extrakey_HID;
  60. USB_Descriptor_Endpoint_t Extrakey_INEndpoint;
  61. #endif
  62. #ifdef RAW_ENABLE
  63. // Raw HID Interface
  64. USB_Descriptor_Interface_t Raw_Interface;
  65. USB_HID_Descriptor_HID_t Raw_HID;
  66. USB_Descriptor_Endpoint_t Raw_INEndpoint;
  67. USB_Descriptor_Endpoint_t Raw_OUTEndpoint;
  68. #endif
  69. #ifdef CONSOLE_ENABLE
  70. // Console HID Interface
  71. USB_Descriptor_Interface_t Console_Interface;
  72. USB_HID_Descriptor_HID_t Console_HID;
  73. USB_Descriptor_Endpoint_t Console_INEndpoint;
  74. USB_Descriptor_Endpoint_t Console_OUTEndpoint;
  75. #endif
  76. #ifdef NKRO_ENABLE
  77. // NKRO HID Interface
  78. USB_Descriptor_Interface_t NKRO_Interface;
  79. USB_HID_Descriptor_HID_t NKRO_HID;
  80. USB_Descriptor_Endpoint_t NKRO_INEndpoint;
  81. #endif
  82. #ifdef MIDI_ENABLE
  83. USB_Descriptor_Interface_Association_t Audio_Interface_Association;
  84. // MIDI Audio Control Interface
  85. USB_Descriptor_Interface_t Audio_ControlInterface;
  86. USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
  87. // MIDI Audio Streaming Interface
  88. USB_Descriptor_Interface_t Audio_StreamInterface;
  89. USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
  90. USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
  91. USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
  92. USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
  93. USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
  94. USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
  95. USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
  96. USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
  97. USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
  98. #endif
  99. #ifdef VIRTSER_ENABLE
  100. USB_Descriptor_Interface_Association_t CDC_Interface_Association;
  101. // CDC Control Interface
  102. USB_Descriptor_Interface_t CDC_CCI_Interface;
  103. USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
  104. USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
  105. USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
  106. USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
  107. // CDC Data Interface
  108. USB_Descriptor_Interface_t CDC_DCI_Interface;
  109. USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
  110. USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
  111. #endif
  112. } USB_Descriptor_Configuration_t;
  113. /* index of interface */
  114. #define KEYBOARD_INTERFACE 0
  115. // It is important that the Raw HID interface is at a constant
  116. // interface number, to support Linux/OSX platforms and chrome.hid
  117. // If Raw HID is enabled, let it be always 1.
  118. #ifdef RAW_ENABLE
  119. # define RAW_INTERFACE (KEYBOARD_INTERFACE + 1)
  120. #else
  121. # define RAW_INTERFACE KEYBOARD_INTERFACE
  122. #endif
  123. #ifdef MOUSE_ENABLE
  124. # define MOUSE_INTERFACE (RAW_INTERFACE + 1)
  125. #else
  126. # define MOUSE_INTERFACE RAW_INTERFACE
  127. #endif
  128. #ifdef EXTRAKEY_ENABLE
  129. # define EXTRAKEY_INTERFACE (MOUSE_INTERFACE + 1)
  130. #else
  131. # define EXTRAKEY_INTERFACE MOUSE_INTERFACE
  132. #endif
  133. #ifdef CONSOLE_ENABLE
  134. # define CONSOLE_INTERFACE (EXTRAKEY_INTERFACE + 1)
  135. #else
  136. # define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
  137. #endif
  138. #ifdef NKRO_ENABLE
  139. # define NKRO_INTERFACE (CONSOLE_INTERFACE + 1)
  140. #else
  141. # define NKRO_INTERFACE CONSOLE_INTERFACE
  142. #endif
  143. #ifdef MIDI_ENABLE
  144. # define AC_INTERFACE (NKRO_INTERFACE + 1)
  145. # define AS_INTERFACE (NKRO_INTERFACE + 2)
  146. #else
  147. # define AS_INTERFACE NKRO_INTERFACE
  148. #endif
  149. #ifdef VIRTSER_ENABLE
  150. # define CCI_INTERFACE (AS_INTERFACE + 1)
  151. # define CDI_INTERFACE (AS_INTERFACE + 2)
  152. #else
  153. # define CDI_INTERFACE AS_INTERFACE
  154. #endif
  155. /* nubmer of interfaces */
  156. #define TOTAL_INTERFACES (CDI_INTERFACE + 1)
  157. // Endopoint number and size
  158. #define KEYBOARD_IN_EPNUM 1
  159. #ifdef MOUSE_ENABLE
  160. # define MOUSE_IN_EPNUM (KEYBOARD_IN_EPNUM + 1)
  161. #else
  162. # define MOUSE_IN_EPNUM KEYBOARD_IN_EPNUM
  163. #endif
  164. #ifdef EXTRAKEY_ENABLE
  165. # define EXTRAKEY_IN_EPNUM (MOUSE_IN_EPNUM + 1)
  166. #else
  167. # define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM
  168. #endif
  169. #ifdef RAW_ENABLE
  170. # define RAW_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
  171. # define RAW_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
  172. #else
  173. # define RAW_OUT_EPNUM EXTRAKEY_IN_EPNUM
  174. #endif
  175. #ifdef CONSOLE_ENABLE
  176. # define CONSOLE_IN_EPNUM (RAW_OUT_EPNUM + 1)
  177. #ifdef PROTOCOL_CHIBIOS
  178. // ChibiOS has enough memory and descriptor to actually enable the endpoint
  179. // It could use the same endpoint numbers, as that's supported by ChibiOS
  180. // But the QMK code currently assumes that the endpoint numbers are different
  181. # define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 2)
  182. #else
  183. # define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 1)
  184. #endif
  185. #else
  186. # define CONSOLE_OUT_EPNUM RAW_OUT_EPNUM
  187. #endif
  188. #ifdef NKRO_ENABLE
  189. # define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1)
  190. #else
  191. # define NKRO_IN_EPNUM CONSOLE_OUT_EPNUM
  192. #endif
  193. #ifdef MIDI_ENABLE
  194. # define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1)
  195. // # define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1)
  196. # define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 2)
  197. # define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
  198. # define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
  199. #else
  200. # define MIDI_STREAM_OUT_EPNUM NKRO_IN_EPNUM
  201. #endif
  202. #ifdef VIRTSER_ENABLE
  203. # define CDC_NOTIFICATION_EPNUM (MIDI_STREAM_OUT_EPNUM + 1)
  204. # define CDC_IN_EPNUM (MIDI_STREAM_OUT_EPNUM + 2)
  205. # define CDC_OUT_EPNUM (MIDI_STREAM_OUT_EPNUM + 3)
  206. # define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
  207. # define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
  208. # define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
  209. #else
  210. # define CDC_OUT_EPNUM MIDI_STREAM_OUT_EPNUM
  211. #endif
  212. #if (defined(PROTOCOL_LUFA) && CDC_OUT_EPNUM > (ENDPOINT_TOTAL_ENDPOINTS - 1)) || \
  213. (defined(PROTOCOL_CHIBIOS) && CDC_OUT_EPNUM > USB_MAX_ENDPOINTS)
  214. # error "There are not enough available endpoints to support all functions. Remove some in the rules.mk file.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, SERIAL, STENO)"
  215. #endif
  216. #define KEYBOARD_EPSIZE 8
  217. #define MOUSE_EPSIZE 8
  218. #define EXTRAKEY_EPSIZE 8
  219. #define RAW_EPSIZE 32
  220. #define CONSOLE_EPSIZE 32
  221. #define NKRO_EPSIZE 32
  222. #define MIDI_STREAM_EPSIZE 64
  223. #define CDC_NOTIFICATION_EPSIZE 8
  224. #define CDC_EPSIZE 16
  225. uint16_t get_usb_descriptor(const uint16_t wValue,
  226. const uint16_t wIndex,
  227. const void** const DescriptorAddress);
  228. /* new API */
  229. #if LUFA_VERSION_INTEGER < 0x140302
  230. #undef VERSION_BCD
  231. #define VERSION_BCD(Major, Minor, Revision) \
  232. CPU_TO_LE16( ((Major & 0xFF) << 8) | \
  233. ((Minor & 0x0F) << 4) | \
  234. (Revision & 0x0F) )
  235. #endif
  236. #endif