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