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
10 Copyright (C) Dean Camera, 2012.
12 dean [at] fourwalledcubicle [dot] com
17 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
18 Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
20 Permission to use, copy, modify, distribute, and sell this
21 software and its documentation for any purpose is hereby granted
22 without fee, provided that the above copyright notice appear in
23 all copies and that both that the copyright notice and this
24 permission notice and warranty disclaimer appear in supporting
25 documentation, and that the name of the author not be used in
26 advertising or publicity pertaining to distribution of the
27 software without specific, written prior permission.
29 The author disclaim all warranties with regard to this
30 software, including all implied warranties of merchantability
31 and fitness. In no event shall the author be liable for any
32 special, indirect or consequential damages or any damages
33 whatsoever resulting from loss of use, data or profits, whether
34 in an action of contract, negligence or other tortious action,
35 arising out of or in connection with the use or performance of
41 * Header file for Descriptors.c.
44 #ifndef _DESCRIPTORS_H_
45 #define _DESCRIPTORS_H_
47 #include <LUFA/Drivers/USB/USB.h>
48 #include <avr/pgmspace.h>
53 USB_Descriptor_Configuration_Header_t Config;
55 // Keyboard HID Interface
56 USB_Descriptor_Interface_t Keyboard_Interface;
57 USB_HID_Descriptor_HID_t Keyboard_HID;
58 USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
61 // Mouse HID Interface
62 USB_Descriptor_Interface_t Mouse_Interface;
63 USB_HID_Descriptor_HID_t Mouse_HID;
64 USB_Descriptor_Endpoint_t Mouse_INEndpoint;
67 #ifdef EXTRAKEY_ENABLE
68 // Extrakey HID Interface
69 USB_Descriptor_Interface_t Extrakey_Interface;
70 USB_HID_Descriptor_HID_t Extrakey_HID;
71 USB_Descriptor_Endpoint_t Extrakey_INEndpoint;
76 USB_Descriptor_Interface_t Raw_Interface;
77 USB_HID_Descriptor_HID_t Raw_HID;
78 USB_Descriptor_Endpoint_t Raw_INEndpoint;
79 USB_Descriptor_Endpoint_t Raw_OUTEndpoint;
83 // Console HID Interface
84 USB_Descriptor_Interface_t Console_Interface;
85 USB_HID_Descriptor_HID_t Console_HID;
86 USB_Descriptor_Endpoint_t Console_INEndpoint;
87 USB_Descriptor_Endpoint_t Console_OUTEndpoint;
92 USB_Descriptor_Interface_t NKRO_Interface;
93 USB_HID_Descriptor_HID_t NKRO_HID;
94 USB_Descriptor_Endpoint_t NKRO_INEndpoint;
98 // MIDI Audio Control Interface
99 USB_Descriptor_Interface_t Audio_ControlInterface;
100 USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
102 // MIDI Audio Streaming Interface
103 USB_Descriptor_Interface_t Audio_StreamInterface;
104 USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
105 USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
106 USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
107 USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
108 USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
109 USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
110 USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
111 USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
112 USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
115 #ifdef VIRTSER_ENABLE
116 USB_Descriptor_Interface_Association_t CDC_Interface_Association;
118 // CDC Control Interface
119 USB_Descriptor_Interface_t CDC_CCI_Interface;
120 USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
121 USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
122 USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
123 USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
125 // CDC Data Interface
126 USB_Descriptor_Interface_t CDC_DCI_Interface;
127 USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
128 USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
130 } USB_Descriptor_Configuration_t;
133 /* index of interface */
134 #define KEYBOARD_INTERFACE 0
136 // It is important that the Raw HID interface is at a constant
137 // interface number, to support Linux/OSX platforms and chrome.hid
138 // If Raw HID is enabled, let it be always 1.
140 # define RAW_INTERFACE (KEYBOARD_INTERFACE + 1)
142 # define RAW_INTERFACE KEYBOARD_INTERFACE
146 # define MOUSE_INTERFACE (RAW_INTERFACE + 1)
148 # define MOUSE_INTERFACE RAW_INTERFACE
151 #ifdef EXTRAKEY_ENABLE
152 # define EXTRAKEY_INTERFACE (MOUSE_INTERFACE + 1)
154 # define EXTRAKEY_INTERFACE MOUSE_INTERFACE
157 #ifdef CONSOLE_ENABLE
158 # define CONSOLE_INTERFACE (EXTRAKEY_INTERFACE + 1)
160 # define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
164 # define NKRO_INTERFACE (CONSOLE_INTERFACE + 1)
166 # define NKRO_INTERFACE CONSOLE_INTERFACE
170 # define AC_INTERFACE (NKRO_INTERFACE + 1)
171 # define AS_INTERFACE (NKRO_INTERFACE + 2)
173 # define AS_INTERFACE NKRO_INTERFACE
176 #ifdef VIRTSER_ENABLE
177 # define CCI_INTERFACE (AS_INTERFACE + 1)
178 # define CDI_INTERFACE (AS_INTERFACE + 2)
180 # define CDI_INTERFACE AS_INTERFACE
183 /* nubmer of interfaces */
184 #define TOTAL_INTERFACES (CDI_INTERFACE + 1)
187 // Endopoint number and size
188 #define KEYBOARD_IN_EPNUM 1
191 # define MOUSE_IN_EPNUM (KEYBOARD_IN_EPNUM + 1)
193 # define MOUSE_IN_EPNUM KEYBOARD_IN_EPNUM
196 #ifdef EXTRAKEY_ENABLE
197 # define EXTRAKEY_IN_EPNUM (MOUSE_IN_EPNUM + 1)
199 # define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM
203 # define RAW_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
204 # define RAW_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
206 # define RAW_OUT_EPNUM EXTRAKEY_IN_EPNUM
209 #ifdef CONSOLE_ENABLE
210 # define CONSOLE_IN_EPNUM (RAW_OUT_EPNUM + 1)
211 //# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 2)
212 # define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 1)
214 # define CONSOLE_OUT_EPNUM RAW_OUT_EPNUM
218 # define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1)
220 # define NKRO_IN_EPNUM CONSOLE_OUT_EPNUM
224 # define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1)
225 // # define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1)
226 # define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 2)
227 # define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
228 # define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
230 # define MIDI_STREAM_OUT_EPNUM NKRO_IN_EPNUM
233 #ifdef VIRTSER_ENABLE
234 # define CDC_NOTIFICATION_EPNUM (MIDI_STREAM_OUT_EPNUM + 1)
235 # define CDC_IN_EPNUM (MIDI_STREAM_OUT_EPNUM + 2)
236 # define CDC_OUT_EPNUM (MIDI_STREAM_OUT_EPNUM + 3)
237 # define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
238 # define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
239 # define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
241 # define CDC_OUT_EPNUM MIDI_STREAM_OUT_EPNUM
244 #if (defined(__AVR_ATmega32U2__) && CDC_OUT_EPNUM > 4) || \
245 (defined(__AVR_ATmega32U4__) && CDC_OUT_EPNUM > 6)
246 # error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, SERIAL)"
249 #define KEYBOARD_EPSIZE 8
250 #define MOUSE_EPSIZE 8
251 #define EXTRAKEY_EPSIZE 8
252 #define RAW_EPSIZE 32
253 #define CONSOLE_EPSIZE 32
254 #define NKRO_EPSIZE 32
255 #define MIDI_STREAM_EPSIZE 64
256 #define CDC_NOTIFICATION_EPSIZE 8
257 #define CDC_EPSIZE 16
260 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
261 const uint16_t wIndex,
262 const void** const DescriptorAddress)
263 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
267 #if LUFA_VERSION_INTEGER < 0x140302
269 #define VERSION_BCD(Major, Minor, Revision) \
270 CPU_TO_LE16( ((Major & 0xFF) << 8) | \
271 ((Minor & 0x0F) << 4) | \