]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/usb_descriptor.h
[Keyboard] fixed pins for numpad_5x4 layout (#6311)
[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 #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;
61 #endif
62
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;
68 #endif
69
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;
74 #endif
75
76 #if defined(RAW_ENABLE)
77     // Raw HID Interface
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;
82 #endif
83
84 #ifdef CONSOLE_ENABLE
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;
90 #endif
91
92 #ifdef MIDI_ENABLE
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;
97
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;
109 #endif
110
111 #ifdef VIRTSER_ENABLE
112   USB_Descriptor_Interface_Association_t   CDC_Interface_Association;
113
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;
120
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;
125 #endif
126 } USB_Descriptor_Configuration_t;
127
128
129 /* index of interface */
130 enum usb_interfaces {
131 #if !defined(KEYBOARD_SHARED_EP)
132     KEYBOARD_INTERFACE,
133 #else
134 #   define KEYBOARD_INTERFACE SHARED_INTERFACE
135 #endif
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)
140     RAW_INTERFACE,
141 #endif
142 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
143     MOUSE_INTERFACE,
144 #endif
145 #if defined(SHARED_EP_ENABLE)
146     SHARED_INTERFACE,
147 #endif
148 #if defined(CONSOLE_ENABLE)
149     CONSOLE_INTERFACE,
150 #endif
151 #if defined(MIDI_ENABLE)
152     AC_INTERFACE,
153     AS_INTERFACE,
154 #endif
155 #if defined(VIRTSER_ENABLE)
156     CCI_INTERFACE,
157     CDI_INTERFACE,
158 #endif
159     TOTAL_INTERFACES
160 };
161
162 #define NEXT_EPNUM __COUNTER__
163
164 enum usb_endpoints {
165     __unused_epnum__ = NEXT_EPNUM,   /* EP numbering starts at 1 */
166 #if !defined(KEYBOARD_SHARED_EP)
167     KEYBOARD_IN_EPNUM = NEXT_EPNUM,
168 #else
169 #   define KEYBOARD_IN_EPNUM    SHARED_IN_EPNUM
170 #endif
171 #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
172     MOUSE_IN_EPNUM = NEXT_EPNUM,
173 #else
174 #   define MOUSE_IN_EPNUM   SHARED_IN_EPNUM
175 #endif
176 #if defined(RAW_ENABLE)
177     RAW_IN_EPNUM = NEXT_EPNUM,
178     RAW_OUT_EPNUM = NEXT_EPNUM,
179 #endif
180 #if defined(SHARED_EP_ENABLE)
181     SHARED_IN_EPNUM = NEXT_EPNUM,
182 #endif
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,
190 #else
191 #define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
192 #endif
193 #endif
194 #ifdef MIDI_ENABLE
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)
199 #endif
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)
207 #endif
208 };
209
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
216 #endif
217 /* TODO - ARM_ATSAM */
218
219
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)
222 #endif
223
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
232
233 uint16_t get_usb_descriptor(const uint16_t wValue,
234                             const uint16_t wIndex,
235                             const void** const DescriptorAddress);
236
237 /* new API */
238 #if LUFA_VERSION_INTEGER < 0x140302
239     #undef VERSION_BCD
240     #define VERSION_BCD(Major, Minor, Revision) \
241                                               CPU_TO_LE16( ((Major & 0xFF) << 8) | \
242                                                            ((Minor & 0x0F) << 4) | \
243                                                            (Revision & 0x0F) )
244 #endif
245
246 #endif