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 #ifdef PROTOCOL_CHIBIOS
54 USB_Descriptor_Configuration_Header_t Config;
56 #ifndef KEYBOARD_SHARED_EP
57 // Keyboard HID Interface
58 USB_Descriptor_Interface_t Keyboard_Interface;
59 USB_HID_Descriptor_HID_t Keyboard_HID;
60 USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
63 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
64 // Mouse HID Interface
65 USB_Descriptor_Interface_t Mouse_Interface;
66 USB_HID_Descriptor_HID_t Mouse_HID;
67 USB_Descriptor_Endpoint_t Mouse_INEndpoint;
70 #if defined(SHARED_EP_ENABLE)
71 USB_Descriptor_Interface_t Shared_Interface;
72 USB_HID_Descriptor_HID_t Shared_HID;
73 USB_Descriptor_Endpoint_t Shared_INEndpoint;
76 #if defined(RAW_ENABLE)
78 USB_Descriptor_Interface_t Raw_Interface;
79 USB_HID_Descriptor_HID_t Raw_HID;
80 USB_Descriptor_Endpoint_t Raw_INEndpoint;
81 USB_Descriptor_Endpoint_t Raw_OUTEndpoint;
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;
93 USB_Descriptor_Interface_Association_t Audio_Interface_Association;
94 // MIDI Audio Control Interface
95 USB_Descriptor_Interface_t Audio_ControlInterface;
96 USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
98 // MIDI Audio Streaming Interface
99 USB_Descriptor_Interface_t Audio_StreamInterface;
100 USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
101 USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
102 USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
103 USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
104 USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
105 USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
106 USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
107 USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
108 USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
111 #ifdef VIRTSER_ENABLE
112 USB_Descriptor_Interface_Association_t CDC_Interface_Association;
114 // CDC Control Interface
115 USB_Descriptor_Interface_t CDC_CCI_Interface;
116 USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
117 USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
118 USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
119 USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
121 // CDC Data Interface
122 USB_Descriptor_Interface_t CDC_DCI_Interface;
123 USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
124 USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
126 } USB_Descriptor_Configuration_t;
129 /* index of interface */
130 enum usb_interfaces {
131 #if !defined(KEYBOARD_SHARED_EP)
134 # define KEYBOARD_INTERFACE SHARED_INTERFACE
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.
139 #if defined(RAW_ENABLE)
142 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
145 #if defined(SHARED_EP_ENABLE)
148 #if defined(CONSOLE_ENABLE)
151 #if defined(MIDI_ENABLE)
155 #if defined(VIRTSER_ENABLE)
162 #define NEXT_EPNUM __COUNTER__
165 __unused_epnum__ = NEXT_EPNUM, /* EP numbering starts at 1 */
166 #if !defined(KEYBOARD_SHARED_EP)
167 KEYBOARD_IN_EPNUM = NEXT_EPNUM,
169 # define KEYBOARD_IN_EPNUM SHARED_IN_EPNUM
171 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
172 MOUSE_IN_EPNUM = NEXT_EPNUM,
174 # define MOUSE_IN_EPNUM SHARED_IN_EPNUM
176 #if defined(RAW_ENABLE)
177 RAW_IN_EPNUM = NEXT_EPNUM,
178 RAW_OUT_EPNUM = NEXT_EPNUM,
180 #if defined(SHARED_EP_ENABLE)
181 SHARED_IN_EPNUM = NEXT_EPNUM,
183 #if defined(CONSOLE_ENABLE)
184 CONSOLE_IN_EPNUM = NEXT_EPNUM,
185 #ifdef PROTOCOL_CHIBIOS
186 // ChibiOS has enough memory and descriptor to actually enable the endpoint
187 // It could use the same endpoint numbers, as that's supported by ChibiOS
188 // But the QMK code currently assumes that the endpoint numbers are different
189 CONSOLE_OUT_EPNUM = NEXT_EPNUM,
191 #define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
195 MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
196 MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
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)
200 #ifdef VIRTSER_ENABLE
201 CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
202 CDC_IN_EPNUM = NEXT_EPNUM,
203 CDC_OUT_EPNUM = NEXT_EPNUM,
204 # define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
205 # define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
206 # define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
210 #if defined(PROTOCOL_LUFA)
211 /* LUFA tells us total endpoints including control */
212 #define MAX_ENDPOINTS (ENDPOINT_TOTAL_ENDPOINTS - 1)
213 #elif defined(PROTOCOL_CHIBIOS)
214 /* ChibiOS gives us number of available user endpoints, not control */
215 #define MAX_ENDPOINTS USB_MAX_ENDPOINTS
217 /* TODO - ARM_ATSAM */
220 #if (NEXT_EPNUM - 1) > MAX_ENDPOINTS
221 # 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)
224 #define KEYBOARD_EPSIZE 8
225 #define SHARED_EPSIZE 32
226 #define MOUSE_EPSIZE 8
227 #define RAW_EPSIZE 32
228 #define CONSOLE_EPSIZE 32
229 #define MIDI_STREAM_EPSIZE 64
230 #define CDC_NOTIFICATION_EPSIZE 8
231 #define CDC_EPSIZE 16
233 uint16_t get_usb_descriptor(const uint16_t wValue,
234 const uint16_t wIndex,
235 const void** const DescriptorAddress);
238 #if LUFA_VERSION_INTEGER < 0x140302
240 #define VERSION_BCD(Major, Minor, Revision) \
241 CPU_TO_LE16( ((Major & 0xFF) << 8) | \
242 ((Minor & 0x0F) << 4) | \