Update copyright year to 2013.
[pub/lufa.git] / Demos / Device / ClassDriver / VirtualSerialMouse / Descriptors.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2013.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2013 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(01.10),
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(00.01),
79
80 .ManufacturerStrIndex = 0x01,
81 .ProductStrIndex = 0x02,
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 = 0,
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 = 0,
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(01.10),
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 = 0,
161 .SlaveInterfaceNumber = 1,
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 = 1,
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 = 2,
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(01.11),
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 =
253 {
254 .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
255
256 .UnicodeString = {LANGUAGE_ID_ENG}
257 };
258
259 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
260 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
261 * Descriptor.
262 */
263 const USB_Descriptor_String_t PROGMEM ManufacturerString =
264 {
265 .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
266
267 .UnicodeString = L"Dean Camera"
268 };
269
270 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
271 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
272 * Descriptor.
273 */
274 const USB_Descriptor_String_t PROGMEM ProductString =
275 {
276 .Header = {.Size = USB_STRING_LEN(23), .Type = DTYPE_String},
277
278 .UnicodeString = L"LUFA CDC and Mouse Demo"
279 };
280
281 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
282 * documentation) by the application code so that the address and size of a requested descriptor can be given
283 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
284 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
285 * USB host.
286 */
287 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
288 const uint8_t wIndex,
289 const void** const DescriptorAddress)
290 {
291 const uint8_t DescriptorType = (wValue >> 8);
292 const uint8_t DescriptorNumber = (wValue & 0xFF);
293
294 const void* Address = NULL;
295 uint16_t Size = NO_DESCRIPTOR;
296
297 switch (DescriptorType)
298 {
299 case DTYPE_Device:
300 Address = &DeviceDescriptor;
301 Size = sizeof(USB_Descriptor_Device_t);
302 break;
303 case DTYPE_Configuration:
304 Address = &ConfigurationDescriptor;
305 Size = sizeof(USB_Descriptor_Configuration_t);
306 break;
307 case DTYPE_String:
308 switch (DescriptorNumber)
309 {
310 case 0x00:
311 Address = &LanguageString;
312 Size = pgm_read_byte(&LanguageString.Header.Size);
313 break;
314 case 0x01:
315 Address = &ManufacturerString;
316 Size = pgm_read_byte(&ManufacturerString.Header.Size);
317 break;
318 case 0x02:
319 Address = &ProductString;
320 Size = pgm_read_byte(&ProductString.Header.Size);
321 break;
322 }
323
324 break;
325 case HID_DTYPE_HID:
326 Address = &ConfigurationDescriptor.HID_MouseHID;
327 Size = sizeof(USB_HID_Descriptor_HID_t);
328 break;
329 case HID_DTYPE_Report:
330 Address = &MouseReport;
331 Size = sizeof(MouseReport);
332 break;
333 }
334
335 *DescriptorAddress = Address;
336 return Size;
337 }
338