Fix PrinterHost demo so that it will only enumerate printers with Bidirectional proto...
[pub/USBasp.git] / Demos / Device / ClassDriver / DualCDC / Descriptors.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 disclaim 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 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
41 * device characteristics, including the supported USB version, control endpoint size and the
42 * number of device configurations. The descriptor is read out by the USB host when the enumeration
43 * process begins.
44 */
45 USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
46 {
47 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
48
49 .USBSpecification = VERSION_BCD(01.10),
50 .Class = 0xEF,
51 .SubClass = 0x02,
52 .Protocol = 0x01,
53
54 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
55
56 .VendorID = 0x03EB,
57 .ProductID = 0x204E,
58 .ReleaseNumber = 0x0000,
59
60 .ManufacturerStrIndex = 0x01,
61 .ProductStrIndex = 0x02,
62 .SerialNumStrIndex = USE_INTERNAL_SERIAL,
63
64 .NumberOfConfigurations = 1
65 };
66
67 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
68 * of the device in one of its supported configurations, including information about any device interfaces
69 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
70 * a configuration so that the host may correctly communicate with the USB device.
71 */
72 USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
73 {
74 .Config =
75 {
76 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
77
78 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
79 .TotalInterfaces = 4,
80
81 .ConfigurationNumber = 1,
82 .ConfigurationStrIndex = NO_DESCRIPTOR,
83
84 .ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
85
86 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
87 },
88
89 .IAD1 =
90 {
91 .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
92
93 .FirstInterfaceIndex = 0,
94 .TotalInterfaces = 2,
95
96 .Class = 0x02,
97 .SubClass = 0x02,
98 .Protocol = 0x01,
99
100 .IADStrIndex = NO_DESCRIPTOR
101 },
102
103 .CDC1_CCI_Interface =
104 {
105 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
106
107 .InterfaceNumber = 0,
108 .AlternateSetting = 0,
109
110 .TotalEndpoints = 1,
111
112 .Class = 0x02,
113 .SubClass = 0x02,
114 .Protocol = 0x01,
115
116 .InterfaceStrIndex = NO_DESCRIPTOR
117 },
118
119 .CDC1_Functional_IntHeader =
120 {
121 .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
122 .SubType = 0x00,
123
124 .Data = {0x01, 0x10}
125 },
126
127 .CDC1_Functional_CallManagement =
128 {
129 .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
130 .SubType = 0x01,
131
132 .Data = {0x03, 0x01}
133 },
134
135 .CDC1_Functional_AbstractControlManagement =
136 {
137 .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(1)), .Type = 0x24},
138 .SubType = 0x02,
139
140 .Data = {0x06}
141 },
142
143 .CDC1_Functional_Union =
144 {
145 .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
146 .SubType = 0x06,
147
148 .Data = {0x00, 0x01}
149 },
150
151 .CDC1_ManagementEndpoint =
152 {
153 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
154
155 .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC1_NOTIFICATION_EPNUM),
156 .Attributes = EP_TYPE_INTERRUPT,
157 .EndpointSize = CDC_NOTIFICATION_EPSIZE,
158 .PollingIntervalMS = 0xFF
159 },
160
161 .CDC1_DCI_Interface =
162 {
163 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
164
165 .InterfaceNumber = 1,
166 .AlternateSetting = 0,
167
168 .TotalEndpoints = 2,
169
170 .Class = 0x0A,
171 .SubClass = 0x00,
172 .Protocol = 0x00,
173
174 .InterfaceStrIndex = NO_DESCRIPTOR
175 },
176
177 .CDC1_DataOutEndpoint =
178 {
179 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
180
181 .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | CDC1_RX_EPNUM),
182 .Attributes = EP_TYPE_BULK,
183 .EndpointSize = CDC_TXRX_EPSIZE,
184 .PollingIntervalMS = 0x00
185 },
186
187 .CDC1_DataInEndpoint =
188 {
189 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
190
191 .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC1_TX_EPNUM),
192 .Attributes = EP_TYPE_BULK,
193 .EndpointSize = CDC_TXRX_EPSIZE,
194 .PollingIntervalMS = 0x00
195 },
196
197 .IAD2 =
198 {
199 .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
200
201 .FirstInterfaceIndex = 2,
202 .TotalInterfaces = 2,
203
204 .Class = 0x02,
205 .SubClass = 0x02,
206 .Protocol = 0x01,
207
208 .IADStrIndex = NO_DESCRIPTOR
209 },
210
211 .CDC2_CCI_Interface =
212 {
213 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
214
215 .InterfaceNumber = 2,
216 .AlternateSetting = 0,
217
218 .TotalEndpoints = 1,
219
220 .Class = 0x02,
221 .SubClass = 0x02,
222 .Protocol = 0x01,
223
224 .InterfaceStrIndex = NO_DESCRIPTOR
225 },
226
227 .CDC2_Functional_IntHeader =
228 {
229 .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
230 .SubType = 0x00,
231
232 .Data = {0x01, 0x10}
233 },
234
235 .CDC2_Functional_CallManagement =
236 {
237 .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
238 .SubType = 0x01,
239
240 .Data = {0x03, 0x03}
241 },
242
243 .CDC2_Functional_AbstractControlManagement =
244 {
245 .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(1)), .Type = 0x24},
246 .SubType = 0x02,
247
248 .Data = {0x06}
249 },
250
251 .CDC2_Functional_Union =
252 {
253 .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
254 .SubType = 0x06,
255
256 .Data = {0x02, 0x03}
257 },
258
259 .CDC2_ManagementEndpoint =
260 {
261 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
262
263 .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC2_NOTIFICATION_EPNUM),
264 .Attributes = EP_TYPE_INTERRUPT,
265 .EndpointSize = CDC_NOTIFICATION_EPSIZE,
266 .PollingIntervalMS = 0xFF
267 },
268
269 .CDC2_DCI_Interface =
270 {
271 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
272
273 .InterfaceNumber = 3,
274 .AlternateSetting = 0,
275
276 .TotalEndpoints = 2,
277
278 .Class = 0x0A,
279 .SubClass = 0x00,
280 .Protocol = 0x00,
281
282 .InterfaceStrIndex = NO_DESCRIPTOR
283 },
284
285 .CDC2_DataOutEndpoint =
286 {
287 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
288
289 .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | CDC2_RX_EPNUM),
290 .Attributes = EP_TYPE_BULK,
291 .EndpointSize = CDC_TXRX_EPSIZE,
292 .PollingIntervalMS = 0x00
293 },
294
295 .CDC2_DataInEndpoint =
296 {
297 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
298
299 .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC2_TX_EPNUM),
300 .Attributes = EP_TYPE_BULK,
301 .EndpointSize = CDC_TXRX_EPSIZE,
302 .PollingIntervalMS = 0x00
303 }
304 };
305
306 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
307 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
308 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
309 */
310 USB_Descriptor_String_t PROGMEM LanguageString =
311 {
312 .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
313
314 .UnicodeString = {LANGUAGE_ID_ENG}
315 };
316
317 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
318 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
319 * Descriptor.
320 */
321 USB_Descriptor_String_t PROGMEM ManufacturerString =
322 {
323 .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
324
325 .UnicodeString = L"Dean Camera"
326 };
327
328 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
329 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
330 * Descriptor.
331 */
332 USB_Descriptor_String_t PROGMEM ProductString =
333 {
334 .Header = {.Size = USB_STRING_LEN(13), .Type = DTYPE_String},
335
336 .UnicodeString = L"LUFA Dual CDC Demo"
337 };
338
339 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
340 * documentation) by the application code so that the address and size of a requested descriptor can be given
341 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
342 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
343 * USB host.
344 */
345 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)
346 {
347 const uint8_t DescriptorType = (wValue >> 8);
348 const uint8_t DescriptorNumber = (wValue & 0xFF);
349
350 void* Address = NULL;
351 uint16_t Size = NO_DESCRIPTOR;
352
353 switch (DescriptorType)
354 {
355 case DTYPE_Device:
356 Address = (void*)&DeviceDescriptor;
357 Size = sizeof(USB_Descriptor_Device_t);
358 break;
359 case DTYPE_Configuration:
360 Address = (void*)&ConfigurationDescriptor;
361 Size = sizeof(USB_Descriptor_Configuration_t);
362 break;
363 case DTYPE_String:
364 switch (DescriptorNumber)
365 {
366 case 0x00:
367 Address = (void*)&LanguageString;
368 Size = pgm_read_byte(&LanguageString.Header.Size);
369 break;
370 case 0x01:
371 Address = (void*)&ManufacturerString;
372 Size = pgm_read_byte(&ManufacturerString.Header.Size);
373 break;
374 case 0x02:
375 Address = (void*)&ProductString;
376 Size = pgm_read_byte(&ProductString.Header.Size);
377 break;
378 }
379
380 break;
381 }
382
383 *DescriptorAddress = Address;
384 return Size;
385 }