]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-git/Demos/Device/ClassDriver/VirtualSerialMouse/Descriptors.c
Merge commit '20b787fc1284176834cbe7ca2134e4b36bec5828'
[tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-git / Demos / Device / ClassDriver / VirtualSerialMouse / Descriptors.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 *
33 * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
34 * computer-readable structures which the host requests upon device enumeration, to determine
35 * the device's capabilities and functions.
36 */
37
38 #include "Descriptors.h"
39
40
41 /** HID class report descriptor. This is a special descriptor constructed with values from the
42 * USBIF HID class specification to describe the reports and capabilities of the HID device. This
43 * descriptor is parsed by the host and its contents used to determine what data (and in what encoding)
44 * the device will send, and what it may be sent back from the host. Refer to the HID specification for
45 * more details on HID report descriptors.
46 */
47 const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =
48 {
49 /* Use the HID class driver's standard Mouse report.
50 * Min X/Y Axis values: -1
51 * Max X/Y Axis values: 1
52 * Min physical X/Y Axis values (used to determine resolution): -1
53 * Max physical X/Y Axis values (used to determine resolution): 1
54 * Buttons: 3
55 * Absolute screen coordinates: false
56 */
57 HID_DESCRIPTOR_MOUSE(-1, 1, -1, 1, 3, false)
58 };
59
60 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
61 * device characteristics, including the supported USB version, control endpoint size and the
62 * number of device configurations. The descriptor is read out by the USB host when the enumeration
63 * process begins.
64 */
65 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
66 {
67 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
68
69 .USBSpecification = VERSION_BCD(1,1,0),
70 .Class = USB_CSCP_IADDeviceClass,
71 .SubClass = USB_CSCP_IADDeviceSubclass,
72 .Protocol = USB_CSCP_IADDeviceProtocol,
73
74 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
75
76 .VendorID = 0x03EB,
77 .ProductID = 0x2062,
78 .ReleaseNumber = VERSION_BCD(0,0,1),
79
80 .ManufacturerStrIndex = STRING_ID_Manufacturer,
81 .ProductStrIndex = STRING_ID_Product,
82 .SerialNumStrIndex = USE_INTERNAL_SERIAL,
83
84 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
85 };
86
87 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
88 * of the device in one of its supported configurations, including information about any device interfaces
89 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
90 * a configuration so that the host may correctly communicate with the USB device.
91 */
92 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
93 {
94 .Config =
95 {
96 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
97
98 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
99 .TotalInterfaces = 3,
100
101 .ConfigurationNumber = 1,
102 .ConfigurationStrIndex = NO_DESCRIPTOR,
103
104 .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
105
106 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
107 },
108
109 .CDC_IAD =
110 {
111 .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
112
113 .FirstInterfaceIndex = INTERFACE_ID_CDC_CCI,
114 .TotalInterfaces = 2,
115
116 .Class = CDC_CSCP_CDCClass,
117 .SubClass = CDC_CSCP_ACMSubclass,
118 .Protocol = CDC_CSCP_ATCommandProtocol,
119
120 .IADStrIndex = NO_DESCRIPTOR
121 },
122
123 .CDC_CCI_Interface =
124 {
125 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
126
127 .InterfaceNumber = INTERFACE_ID_CDC_CCI,
128 .AlternateSetting = 0,
129
130 .TotalEndpoints = 1,
131
132 .Class = CDC_CSCP_CDCClass,
133 .SubClass = CDC_CSCP_ACMSubclass,
134 .Protocol = CDC_CSCP_ATCommandProtocol,
135
136 .InterfaceStrIndex = NO_DESCRIPTOR
137 },
138
139 .CDC_Functional_Header =
140 {
141 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
142 .Subtype = CDC_DSUBTYPE_CSInterface_Header,
143
144 .CDCSpecification = VERSION_BCD(1,1,0),
145 },
146
147 .CDC_Functional_ACM =
148 {
149 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
150 .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
151
152 .Capabilities = 0x06,
153 },
154
155 .CDC_Functional_Union =
156 {
157 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
158 .Subtype = CDC_DSUBTYPE_CSInterface_Union,
159
160 .MasterInterfaceNumber = INTERFACE_ID_CDC_CCI,
161 .SlaveInterfaceNumber = INTERFACE_ID_CDC_DCI,
162 },
163
164 .CDC_NotificationEndpoint =
165 {
166 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
167
168 .EndpointAddress = CDC_NOTIFICATION_EPADDR,
169 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
170 .EndpointSize = CDC_NOTIFICATION_EPSIZE,
171 .PollingIntervalMS = 0xFF
172 },
173
174 .CDC_DCI_Interface =
175 {
176 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
177
178 .InterfaceNumber = INTERFACE_ID_CDC_DCI,
179 .AlternateSetting = 0,
180
181 .TotalEndpoints = 2,
182
183 .Class = CDC_CSCP_CDCDataClass,
184 .SubClass = CDC_CSCP_NoDataSubclass,
185 .Protocol = CDC_CSCP_NoDataProtocol,
186
187 .InterfaceStrIndex = NO_DESCRIPTOR
188 },
189
190 .CDC_DataOutEndpoint =
191 {
192 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
193
194 .EndpointAddress = CDC_RX_EPADDR,
195 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
196 .EndpointSize = CDC_TXRX_EPSIZE,
197 .PollingIntervalMS = 0x05
198 },
199
200 .CDC_DataInEndpoint =
201 {
202 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
203
204 .EndpointAddress = CDC_TX_EPADDR,
205 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
206 .EndpointSize = CDC_TXRX_EPSIZE,
207 .PollingIntervalMS = 0x05
208 },
209
210 .HID_Interface =
211 {
212 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
213
214 .InterfaceNumber = INTERFACE_ID_Mouse,
215 .AlternateSetting = 0,
216
217 .TotalEndpoints = 1,
218
219 .Class = HID_CSCP_HIDClass,
220 .SubClass = HID_CSCP_BootSubclass,
221 .Protocol = HID_CSCP_MouseBootProtocol,
222
223 .InterfaceStrIndex = NO_DESCRIPTOR
224 },
225
226 .HID_MouseHID =
227 {
228 .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
229
230 .HIDSpec = VERSION_BCD(1,1,1),
231 .CountryCode = 0x00,
232 .TotalReportDescriptors = 1,
233 .HIDReportType = HID_DTYPE_Report,
234 .HIDReportLength = sizeof(MouseReport)
235 },
236
237 .HID_ReportINEndpoint =
238 {
239 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
240
241 .EndpointAddress = MOUSE_EPADDR,
242 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
243 .EndpointSize = MOUSE_EPSIZE,
244 .PollingIntervalMS = 0x05
245 }
246 };
247
248 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
249 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
250 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
251 */
252 const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
253
254 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
255 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
256 * Descriptor.
257 */
258 const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera");
259
260 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
261 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
262 * Descriptor.
263 */
264 const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA CDC and Mouse Demo");
265
266 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
267 * documentation) by the application code so that the address and size of a requested descriptor can be given
268 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
269 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
270 * USB host.
271 */
272 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
273 const uint8_t wIndex,
274 const void** const DescriptorAddress)
275 {
276 const uint8_t DescriptorType = (wValue >> 8);
277 const uint8_t DescriptorNumber = (wValue & 0xFF);
278
279 const void* Address = NULL;
280 uint16_t Size = NO_DESCRIPTOR;
281
282 switch (DescriptorType)
283 {
284 case DTYPE_Device:
285 Address = &DeviceDescriptor;
286 Size = sizeof(USB_Descriptor_Device_t);
287 break;
288 case DTYPE_Configuration:
289 Address = &ConfigurationDescriptor;
290 Size = sizeof(USB_Descriptor_Configuration_t);
291 break;
292 case DTYPE_String:
293 switch (DescriptorNumber)
294 {
295 case STRING_ID_Language:
296 Address = &LanguageString;
297 Size = pgm_read_byte(&LanguageString.Header.Size);
298 break;
299 case STRING_ID_Manufacturer:
300 Address = &ManufacturerString;
301 Size = pgm_read_byte(&ManufacturerString.Header.Size);
302 break;
303 case STRING_ID_Product:
304 Address = &ProductString;
305 Size = pgm_read_byte(&ProductString.Header.Size);
306 break;
307 }
308
309 break;
310 case HID_DTYPE_HID:
311 Address = &ConfigurationDescriptor.HID_MouseHID;
312 Size = sizeof(USB_HID_Descriptor_HID_t);
313 break;
314 case HID_DTYPE_Report:
315 Address = &MouseReport;
316 Size = sizeof(MouseReport);
317 break;
318 }
319
320 *DescriptorAddress = Address;
321 return Size;
322 }
323
Imprint / Impressum