]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/lufa/descriptor.h
c6c94e3618404db4e4ec887ede39a1b44972f319
[qmk_firmware.git] / tmk_core / protocol / lufa / descriptor.h
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 /*
9              LUFA Library
10      Copyright (C) Dean Camera, 2012.
11
12   dean [at] fourwalledcubicle [dot] com
13            www.lufa-lib.org
14 */
15
16 /*
17   Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
18   Copyright 2010  Denver Gingerich (denver [at] ossguy [dot] com)
19
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.
28
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
36   this software.
37 */
38
39 /** \file
40  *
41  *  Header file for Descriptors.c.
42  */
43
44 #ifndef _DESCRIPTORS_H_
45 #define _DESCRIPTORS_H_
46
47 #include <LUFA/Drivers/USB/USB.h>
48 #include <avr/pgmspace.h>
49
50
51 typedef struct
52 {
53     USB_Descriptor_Configuration_Header_t Config;
54
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;
59
60 #ifdef MOUSE_ENABLE
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;
65 #endif
66
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;
72 #endif
73
74 #ifdef CONSOLE_ENABLE
75     // Console HID Interface
76     USB_Descriptor_Interface_t            Console_Interface;
77     USB_HID_Descriptor_HID_t              Console_HID;
78     USB_Descriptor_Endpoint_t             Console_INEndpoint;
79     USB_Descriptor_Endpoint_t             Console_OUTEndpoint;
80 #endif
81
82 #ifdef NKRO_ENABLE
83     // NKRO HID Interface
84     USB_Descriptor_Interface_t            NKRO_Interface;
85     USB_HID_Descriptor_HID_t              NKRO_HID;
86     USB_Descriptor_Endpoint_t             NKRO_INEndpoint;
87 #endif
88
89 #ifdef MIDI_ENABLE
90       // MIDI Audio Control Interface
91       USB_Descriptor_Interface_t                Audio_ControlInterface;
92       USB_Audio_Descriptor_Interface_AC_t       Audio_ControlInterface_SPC;
93
94       // MIDI Audio Streaming Interface
95       USB_Descriptor_Interface_t                Audio_StreamInterface;
96       USB_MIDI_Descriptor_AudioInterface_AS_t   Audio_StreamInterface_SPC;
97       USB_MIDI_Descriptor_InputJack_t           MIDI_In_Jack_Emb;
98       USB_MIDI_Descriptor_InputJack_t           MIDI_In_Jack_Ext;
99       USB_MIDI_Descriptor_OutputJack_t          MIDI_Out_Jack_Emb;
100       USB_MIDI_Descriptor_OutputJack_t          MIDI_Out_Jack_Ext;
101       USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
102       USB_MIDI_Descriptor_Jack_Endpoint_t       MIDI_In_Jack_Endpoint_SPC;
103       USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
104       USB_MIDI_Descriptor_Jack_Endpoint_t       MIDI_Out_Jack_Endpoint_SPC;
105 #endif
106
107 #ifdef VIRTSER_ENABLE
108         USB_Descriptor_Interface_Association_t   CDC_Interface_Association;
109
110         // CDC Control Interface
111         USB_Descriptor_Interface_t               CDC_CCI_Interface;
112         USB_CDC_Descriptor_FunctionalHeader_t    CDC_Functional_Header;
113         USB_CDC_Descriptor_FunctionalACM_t       CDC_Functional_ACM;
114         USB_CDC_Descriptor_FunctionalUnion_t     CDC_Functional_Union;
115         USB_Descriptor_Endpoint_t                CDC_NotificationEndpoint;
116
117         // CDC Data Interface
118         USB_Descriptor_Interface_t               CDC_DCI_Interface;
119         USB_Descriptor_Endpoint_t                CDC_DataOutEndpoint;
120         USB_Descriptor_Endpoint_t                CDC_DataInEndpoint;
121 #endif
122 } USB_Descriptor_Configuration_t;
123
124
125 /* index of interface */
126 #define KEYBOARD_INTERFACE          0
127
128 #ifdef MOUSE_ENABLE
129 #   define MOUSE_INTERFACE          (KEYBOARD_INTERFACE + 1)
130 #else
131 #   define MOUSE_INTERFACE          KEYBOARD_INTERFACE
132 #endif
133
134 #ifdef EXTRAKEY_ENABLE
135 #   define EXTRAKEY_INTERFACE       (MOUSE_INTERFACE + 1)
136 #else
137 #   define EXTRAKEY_INTERFACE       MOUSE_INTERFACE
138 #endif
139
140 #ifdef CONSOLE_ENABLE
141 #   define CONSOLE_INTERFACE        (EXTRAKEY_INTERFACE + 1)
142 #else
143 #   define CONSOLE_INTERFACE        EXTRAKEY_INTERFACE
144 #endif
145
146 #ifdef NKRO_ENABLE
147 #   define NKRO_INTERFACE           (CONSOLE_INTERFACE + 1)
148 #else
149 #   define NKRO_INTERFACE           CONSOLE_INTERFACE
150 #endif
151
152 #ifdef MIDI_ENABLE
153 #   define AC_INTERFACE           (NKRO_INTERFACE + 1)
154 #   define AS_INTERFACE           (NKRO_INTERFACE + 2)
155 #else
156 #   define AS_INTERFACE           NKRO_INTERFACE
157 #endif
158
159 #ifdef VIRTSER_ENABLE
160 #   define CCI_INTERFACE         (AS_INTERFACE + 1)
161 #   define CDI_INTERFACE         (AS_INTERFACE + 2)
162 #else
163 #   define CDI_INTERFACE         AS_INTERFACE
164 #endif
165
166 /* nubmer of interfaces */
167 #define TOTAL_INTERFACES            (CDI_INTERFACE + 1)
168
169
170 // Endopoint number and size
171 #define KEYBOARD_IN_EPNUM           1
172
173 #ifdef MOUSE_ENABLE
174 #   define MOUSE_IN_EPNUM           (KEYBOARD_IN_EPNUM + 1)
175 #else
176 #   define MOUSE_IN_EPNUM           KEYBOARD_IN_EPNUM
177 #endif
178
179 #ifdef EXTRAKEY_ENABLE
180 #   define EXTRAKEY_IN_EPNUM        (MOUSE_IN_EPNUM + 1)
181 #else
182 #   define EXTRAKEY_IN_EPNUM        MOUSE_IN_EPNUM
183 #endif
184
185 #ifdef CONSOLE_ENABLE
186 #   define CONSOLE_IN_EPNUM         (EXTRAKEY_IN_EPNUM + 1)
187 #   define CONSOLE_OUT_EPNUM        (EXTRAKEY_IN_EPNUM + 1)
188 //#   define CONSOLE_OUT_EPNUM        (EXTRAKEY_IN_EPNUM + 2)
189 #else
190 #   define CONSOLE_OUT_EPNUM        EXTRAKEY_IN_EPNUM
191 #endif
192
193 #ifdef NKRO_ENABLE
194 #   define NKRO_IN_EPNUM            (CONSOLE_OUT_EPNUM + 1)
195 #else
196 #   define NKRO_IN_EPNUM            CONSOLE_OUT_EPNUM
197 #endif
198
199 #ifdef MIDI_ENABLE
200 #   define MIDI_STREAM_IN_EPNUM     (NKRO_IN_EPNUM + 1)
201 // #   define MIDI_STREAM_OUT_EPNUM    (NKRO_IN_EPNUM + 1)
202 #   define MIDI_STREAM_OUT_EPNUM    (NKRO_IN_EPNUM + 2)
203 #   define MIDI_STREAM_IN_EPADDR    (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
204 #   define MIDI_STREAM_OUT_EPADDR   (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
205 #else
206 #   define MIDI_STREAM_OUT_EPNUM     NKRO_IN_EPNUM
207 #endif
208
209 #ifdef VIRTSER_ENABLE
210 #   define CDC_NOTIFICATION_EPNUM   (MIDI_STREAM_OUT_EPNUM + 1)
211 #   define CDC_IN_EPNUM             (MIDI_STREAM_OUT_EPNUM + 2)
212 #   define CDC_OUT_EPNUM                    (MIDI_STREAM_OUT_EPNUM + 3)
213 #   define CDC_NOTIFICATION_EPADDR        (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
214 #   define CDC_IN_EPADDR                  (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
215 #   define CDC_OUT_EPADDR                  (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
216 #else
217 #   define CDC_OUT_EPNUM        MIDI_STREAM_OUT_EPNUM
218 #endif
219
220
221 #if defined(__AVR_ATmega32U2__) && CDC_OUT_EPNUM > 4
222 # error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, SERIAL)"
223 #endif
224
225 #define KEYBOARD_EPSIZE             8
226 #define MOUSE_EPSIZE                8
227 #define EXTRAKEY_EPSIZE             8
228 #define CONSOLE_EPSIZE              32
229 #define NKRO_EPSIZE                 32
230 #define MIDI_STREAM_EPSIZE          64
231 #define CDC_NOTIFICATION_EPSIZE     8
232 #define CDC_EPSIZE                  16
233
234
235 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
236                                     const uint8_t wIndex,
237                                     const void** const DescriptorAddress)
238                                     ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
239
240
241 /* new API */
242 #if LUFA_VERSION_INTEGER < 0x140302
243     #undef VERSION_BCD
244     #define VERSION_BCD(Major, Minor, Revision) \
245                                               CPU_TO_LE16( ((Major & 0xFF) << 8) | \
246                                                            ((Minor & 0x0F) << 4) | \
247                                                            (Revision & 0x0F) )
248 #endif
249
250 #endif