3 Copyright (C) Dean Camera, 2011.
\r
5 dean [at] fourwalledcubicle [dot] com
\r
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
\r
12 Permission to use, copy, modify, distribute, and sell this
\r
13 software and its documentation for any purpose is hereby granted
\r
14 without fee, provided that the above copyright notice appear in
\r
15 all copies and that both that the copyright notice and this
\r
16 permission notice and warranty disclaimer appear in supporting
\r
17 documentation, and that the name of the author not be used in
\r
18 advertising or publicity pertaining to distribution of the
\r
19 software without specific, written prior permission.
\r
21 The author disclaim all warranties with regard to this
\r
22 software, including all implied warranties of merchantability
\r
23 and fitness. In no event shall the author be liable for any
\r
24 special, indirect or consequential damages or any damages
\r
25 whatsoever resulting from loss of use, data or profits, whether
\r
26 in an action of contract, negligence or other tortious action,
\r
27 arising out of or in connection with the use or performance of
\r
33 * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
\r
34 * computer-readable structures which the host requests upon device enumeration, to determine
\r
35 * the device's capabilities and functions.
\r
38 #include "Descriptors.h"
\r
40 /* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
\r
41 * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
\r
42 * This allows the host to track a device across insertions on different ports, allowing them to retain allocated
\r
43 * resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
\r
44 * so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
\r
45 * from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
\r
48 #if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)
\r
49 #warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.
\r
52 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
\r
53 * device characteristics, including the supported USB version, control endpoint size and the
\r
54 * number of device configurations. The descriptor is read out by the USB host when the enumeration
\r
57 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
\r
59 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
\r
61 .USBSpecification = VERSION_BCD(01.10),
\r
62 .Class = USB_CSCP_IADDeviceClass,
\r
63 .SubClass = USB_CSCP_IADDeviceSubclass,
\r
64 .Protocol = USB_CSCP_IADDeviceProtocol,
\r
66 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
\r
69 .ProductID = 0x204E,
\r
70 .ReleaseNumber = VERSION_BCD(00.01),
\r
72 .ManufacturerStrIndex = 0x01,
\r
73 .ProductStrIndex = 0x02,
\r
74 .SerialNumStrIndex = USE_INTERNAL_SERIAL,
\r
76 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
\r
79 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
\r
80 * of the device in one of its supported configurations, including information about any device interfaces
\r
81 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
\r
82 * a configuration so that the host may correctly communicate with the USB device.
\r
84 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
\r
88 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
\r
90 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
\r
91 .TotalInterfaces = 4,
\r
93 .ConfigurationNumber = 1,
\r
94 .ConfigurationStrIndex = NO_DESCRIPTOR,
\r
96 .ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
\r
98 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
\r
103 .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
\r
105 .FirstInterfaceIndex = 0,
\r
106 .TotalInterfaces = 2,
\r
108 .Class = CDC_CSCP_CDCClass,
\r
109 .SubClass = CDC_CSCP_ACMSubclass,
\r
110 .Protocol = CDC_CSCP_ATCommandProtocol,
\r
112 .IADStrIndex = NO_DESCRIPTOR
\r
115 .CDC1_CCI_Interface =
\r
117 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
\r
119 .InterfaceNumber = 0,
\r
120 .AlternateSetting = 0,
\r
122 .TotalEndpoints = 1,
\r
124 .Class = CDC_CSCP_CDCClass,
\r
125 .SubClass = CDC_CSCP_ACMSubclass,
\r
126 .Protocol = CDC_CSCP_ATCommandProtocol,
\r
128 .InterfaceStrIndex = NO_DESCRIPTOR
\r
131 .CDC1_Functional_Header =
\r
133 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
\r
134 .Subtype = CDC_DSUBTYPE_CSInterface_Header,
\r
136 .CDCSpecification = VERSION_BCD(01.10),
\r
139 .CDC1_Functional_ACM =
\r
141 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
\r
142 .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
\r
144 .Capabilities = 0x06,
\r
147 .CDC1_Functional_Union =
\r
149 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
\r
150 .Subtype = CDC_DSUBTYPE_CSInterface_Union,
\r
152 .MasterInterfaceNumber = 0,
\r
153 .SlaveInterfaceNumber = 1,
\r
156 .CDC1_ManagementEndpoint =
\r
158 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
\r
160 .EndpointAddress = (ENDPOINT_DIR_IN | CDC1_NOTIFICATION_EPNUM),
\r
161 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
\r
162 .EndpointSize = CDC_NOTIFICATION_EPSIZE,
\r
163 .PollingIntervalMS = 0xFF
\r
166 .CDC1_DCI_Interface =
\r
168 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
\r
170 .InterfaceNumber = 1,
\r
171 .AlternateSetting = 0,
\r
173 .TotalEndpoints = 2,
\r
175 .Class = CDC_CSCP_CDCDataClass,
\r
176 .SubClass = CDC_CSCP_NoDataSubclass,
\r
177 .Protocol = CDC_CSCP_NoDataProtocol,
\r
179 .InterfaceStrIndex = NO_DESCRIPTOR
\r
182 .CDC1_DataOutEndpoint =
\r
184 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
\r
186 .EndpointAddress = (ENDPOINT_DIR_OUT | CDC1_RX_EPNUM),
\r
187 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
\r
188 .EndpointSize = CDC_TXRX_EPSIZE,
\r
189 .PollingIntervalMS = 0x01
\r
192 .CDC1_DataInEndpoint =
\r
194 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
\r
196 .EndpointAddress = (ENDPOINT_DIR_IN | CDC1_TX_EPNUM),
\r
197 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
\r
198 .EndpointSize = CDC_TXRX_EPSIZE,
\r
199 .PollingIntervalMS = 0x01
\r
204 .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
\r
206 .FirstInterfaceIndex = 2,
\r
207 .TotalInterfaces = 2,
\r
209 .Class = CDC_CSCP_CDCClass,
\r
210 .SubClass = CDC_CSCP_ACMSubclass,
\r
211 .Protocol = CDC_CSCP_ATCommandProtocol,
\r
213 .IADStrIndex = NO_DESCRIPTOR
\r
216 .CDC2_CCI_Interface =
\r
218 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
\r
220 .InterfaceNumber = 2,
\r
221 .AlternateSetting = 0,
\r
223 .TotalEndpoints = 1,
\r
225 .Class = CDC_CSCP_CDCClass,
\r
226 .SubClass = CDC_CSCP_ACMSubclass,
\r
227 .Protocol = CDC_CSCP_ATCommandProtocol,
\r
229 .InterfaceStrIndex = NO_DESCRIPTOR
\r
232 .CDC2_Functional_Header =
\r
234 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
\r
235 .Subtype = CDC_DSUBTYPE_CSInterface_Header,
\r
237 .CDCSpecification = VERSION_BCD(01.10),
\r
240 .CDC2_Functional_ACM =
\r
242 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
\r
243 .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
\r
245 .Capabilities = 0x06,
\r
248 .CDC2_Functional_Union =
\r
250 .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
\r
251 .Subtype = CDC_DSUBTYPE_CSInterface_Union,
\r
253 .MasterInterfaceNumber = 2,
\r
254 .SlaveInterfaceNumber = 3,
\r
257 .CDC2_ManagementEndpoint =
\r
259 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
\r
261 .EndpointAddress = (ENDPOINT_DIR_IN | CDC2_NOTIFICATION_EPNUM),
\r
262 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
\r
263 .EndpointSize = CDC_NOTIFICATION_EPSIZE,
\r
264 .PollingIntervalMS = 0xFF
\r
267 .CDC2_DCI_Interface =
\r
269 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
\r
271 .InterfaceNumber = 3,
\r
272 .AlternateSetting = 0,
\r
274 .TotalEndpoints = 2,
\r
276 .Class = CDC_CSCP_CDCDataClass,
\r
277 .SubClass = CDC_CSCP_NoDataSubclass,
\r
278 .Protocol = CDC_CSCP_NoDataProtocol,
\r
280 .InterfaceStrIndex = NO_DESCRIPTOR
\r
283 .CDC2_DataOutEndpoint =
\r
285 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
\r
287 .EndpointAddress = (ENDPOINT_DIR_OUT | CDC2_RX_EPNUM),
\r
288 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
\r
289 .EndpointSize = CDC_TXRX_EPSIZE,
\r
290 .PollingIntervalMS = 0x01
\r
293 .CDC2_DataInEndpoint =
\r
295 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
\r
297 .EndpointAddress = (ENDPOINT_DIR_IN | CDC2_TX_EPNUM),
\r
298 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
\r
299 .EndpointSize = CDC_TXRX_EPSIZE,
\r
300 .PollingIntervalMS = 0x01
\r
304 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
\r
305 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
\r
306 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
\r
308 const USB_Descriptor_String_t PROGMEM LanguageString =
\r
310 .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
\r
312 .UnicodeString = {LANGUAGE_ID_ENG}
\r
315 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
\r
316 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
\r
319 const USB_Descriptor_String_t PROGMEM ManufacturerString =
\r
321 .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
\r
323 .UnicodeString = L"Dean Camera"
\r
326 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
\r
327 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
\r
330 const USB_Descriptor_String_t PROGMEM ProductString =
\r
332 .Header = {.Size = USB_STRING_LEN(13), .Type = DTYPE_String},
\r
334 .UnicodeString = L"LUFA Dual CDC Demo"
\r
337 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
\r
338 * documentation) by the application code so that the address and size of a requested descriptor can be given
\r
339 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
\r
340 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
\r
343 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
\r
344 const uint8_t wIndex,
\r
345 const void** const DescriptorAddress)
\r
347 const uint8_t DescriptorType = (wValue >> 8);
\r
348 const uint8_t DescriptorNumber = (wValue & 0xFF);
\r
350 const void* Address = NULL;
\r
351 uint16_t Size = NO_DESCRIPTOR;
\r
353 switch (DescriptorType)
\r
356 Address = &DeviceDescriptor;
\r
357 Size = sizeof(USB_Descriptor_Device_t);
\r
359 case DTYPE_Configuration:
\r
360 Address = &ConfigurationDescriptor;
\r
361 Size = sizeof(USB_Descriptor_Configuration_t);
\r
364 switch (DescriptorNumber)
\r
367 Address = &LanguageString;
\r
368 Size = pgm_read_byte(&LanguageString.Header.Size);
\r
371 Address = &ManufacturerString;
\r
372 Size = pgm_read_byte(&ManufacturerString.Header.Size);
\r
375 Address = &ProductString;
\r
376 Size = pgm_read_byte(&ProductString.Header.Size);
\r
383 *DescriptorAddress = Address;
\r