upload
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

descriptor.h 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright 2012,2013 Jun Wako <[email protected]>
  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. #include <avr/pgmspace.h>
  41. typedef struct
  42. {
  43. USB_Descriptor_Configuration_Header_t Config;
  44. // Keyboard HID Interface
  45. USB_Descriptor_Interface_t Keyboard_Interface;
  46. USB_HID_Descriptor_HID_t Keyboard_HID;
  47. USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
  48. #ifdef MOUSE_ENABLE
  49. // Mouse HID Interface
  50. USB_Descriptor_Interface_t Mouse_Interface;
  51. USB_HID_Descriptor_HID_t Mouse_HID;
  52. USB_Descriptor_Endpoint_t Mouse_INEndpoint;
  53. #endif
  54. #ifdef EXTRAKEY_ENABLE
  55. // Extrakey HID Interface
  56. USB_Descriptor_Interface_t Extrakey_Interface;
  57. USB_HID_Descriptor_HID_t Extrakey_HID;
  58. USB_Descriptor_Endpoint_t Extrakey_INEndpoint;
  59. #endif
  60. #ifdef CONSOLE_ENABLE
  61. // Console HID Interface
  62. USB_Descriptor_Interface_t Console_Interface;
  63. USB_HID_Descriptor_HID_t Console_HID;
  64. USB_Descriptor_Endpoint_t Console_INEndpoint;
  65. USB_Descriptor_Endpoint_t Console_OUTEndpoint;
  66. #endif
  67. #ifdef NKRO_ENABLE
  68. // NKRO HID Interface
  69. USB_Descriptor_Interface_t NKRO_Interface;
  70. USB_HID_Descriptor_HID_t NKRO_HID;
  71. USB_Descriptor_Endpoint_t NKRO_INEndpoint;
  72. #endif
  73. #ifdef MIDI_ENABLE
  74. // MIDI Audio Control Interface
  75. USB_Descriptor_Interface_t Audio_ControlInterface;
  76. USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
  77. // MIDI Audio Streaming Interface
  78. USB_Descriptor_Interface_t Audio_StreamInterface;
  79. USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
  80. USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
  81. USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
  82. USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
  83. USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
  84. USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
  85. USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
  86. USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
  87. USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
  88. #endif
  89. } USB_Descriptor_Configuration_t;
  90. /* index of interface */
  91. #define KEYBOARD_INTERFACE 0
  92. #ifdef MOUSE_ENABLE
  93. # define MOUSE_INTERFACE (KEYBOARD_INTERFACE + 1)
  94. #else
  95. # define MOUSE_INTERFACE KEYBOARD_INTERFACE
  96. #endif
  97. #ifdef EXTRAKEY_ENABLE
  98. # define EXTRAKEY_INTERFACE (MOUSE_INTERFACE + 1)
  99. #else
  100. # define EXTRAKEY_INTERFACE MOUSE_INTERFACE
  101. #endif
  102. #ifdef CONSOLE_ENABLE
  103. # define CONSOLE_INTERFACE (EXTRAKEY_INTERFACE + 1)
  104. #else
  105. # define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
  106. #endif
  107. #ifdef NKRO_ENABLE
  108. # define NKRO_INTERFACE (CONSOLE_INTERFACE + 1)
  109. #else
  110. # define NKRO_INTERFACE CONSOLE_INTERFACE
  111. #endif
  112. #ifdef MIDI_ENABLE
  113. # define AC_INTERFACE (NKRO_INTERFACE + 1)
  114. # define AS_INTERFACE (NKRO_INTERFACE + 2)
  115. #else
  116. # define AS_INTERFACE NKRO_INTERFACE
  117. #endif
  118. /* nubmer of interfaces */
  119. #define TOTAL_INTERFACES AS_INTERFACE + 1
  120. // Endopoint number and size
  121. #define KEYBOARD_IN_EPNUM 1
  122. #ifdef MOUSE_ENABLE
  123. # define MOUSE_IN_EPNUM (KEYBOARD_IN_EPNUM + 1)
  124. #else
  125. # define MOUSE_IN_EPNUM KEYBOARD_IN_EPNUM
  126. #endif
  127. #ifdef EXTRAKEY_ENABLE
  128. # define EXTRAKEY_IN_EPNUM (MOUSE_IN_EPNUM + 1)
  129. #else
  130. # define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM
  131. #endif
  132. #ifdef CONSOLE_ENABLE
  133. # define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
  134. # define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 1)
  135. //# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
  136. #else
  137. # define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM
  138. #endif
  139. #ifdef NKRO_ENABLE
  140. # define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1)
  141. #else
  142. # define NKRO_IN_EPNUM CONSOLE_OUT_EPNUM
  143. #endif
  144. #ifdef MIDI_ENABLE
  145. # define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1)
  146. // # define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1)
  147. # define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 2)
  148. # define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
  149. # define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
  150. #endif
  151. #if defined(__AVR_ATmega32U2__) && MIDI_STREAM_OUT_EPADDR > 4
  152. # error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI)"
  153. #endif
  154. #define KEYBOARD_EPSIZE 8
  155. #define MOUSE_EPSIZE 8
  156. #define EXTRAKEY_EPSIZE 8
  157. #define CONSOLE_EPSIZE 32
  158. #define NKRO_EPSIZE 16
  159. #define MIDI_STREAM_EPSIZE 64
  160. uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
  161. const uint8_t wIndex,
  162. const void** const DescriptorAddress)
  163. ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
  164. /* new API */
  165. #if LUFA_VERSION_INTEGER < 0x140302
  166. #undef VERSION_BCD
  167. #define VERSION_BCD(Major, Minor, Revision) \
  168. CPU_TO_LE16( ((Major & 0xFF) << 8) | \
  169. ((Minor & 0x0F) << 4) | \
  170. (Revision & 0x0F) )
  171. #endif
  172. #endif