3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
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.
38 #include "Descriptors.h"
40 /* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
41 * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
42 * This allows the host to track a device across insertions on different ports, allowing them to retain allocated
43 * resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
44 * so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
45 * from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
48 #if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)
49 #warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.
52 /** HID class report descriptor. This is a special descriptor constructed with values from the
53 * USBIF HID class specification to describe the reports and capabilities of the HID device. This
54 * descriptor is parsed by the host and its contents used to determine what data (and in what encoding)
55 * the device will send, and what it may be sent back from the host. Refer to the HID specification for
56 * more details on HID report descriptors.
58 const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport
[] =
60 /* Use the HID class driver's standard Mouse report.
61 * Min X/Y Axis values: -1
62 * Max X/Y Axis values: 1
63 * Min physical X/Y Axis values (used to determine resolution): -1
64 * Max physical X/Y Axis values (used to determine resolution): 1
66 * Absolute screen coordinates: false
68 HID_DESCRIPTOR_MOUSE(-1, 1, -1, 1, 3, false)
71 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
72 * device characteristics, including the supported USB version, control endpoint size and the
73 * number of device configurations. The descriptor is read out by the USB host when the enumeration
76 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor
=
78 .Header
= {.Size
= sizeof(USB_Descriptor_Device_t
), .Type
= DTYPE_Device
},
80 .USBSpecification
= VERSION_BCD(01.10),
81 .Class
= USB_CSCP_IADDeviceClass
,
82 .SubClass
= USB_CSCP_IADDeviceSubclass
,
83 .Protocol
= USB_CSCP_IADDeviceProtocol
,
85 .Endpoint0Size
= FIXED_CONTROL_ENDPOINT_SIZE
,
89 .ReleaseNumber
= VERSION_BCD(00.01),
91 .ManufacturerStrIndex
= 0x01,
92 .ProductStrIndex
= 0x02,
93 .SerialNumStrIndex
= USE_INTERNAL_SERIAL
,
95 .NumberOfConfigurations
= FIXED_NUM_CONFIGURATIONS
98 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
99 * of the device in one of its supported configurations, including information about any device interfaces
100 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
101 * a configuration so that the host may correctly communicate with the USB device.
103 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor
=
107 .Header
= {.Size
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type
= DTYPE_Configuration
},
109 .TotalConfigurationSize
= sizeof(USB_Descriptor_Configuration_t
),
110 .TotalInterfaces
= 3,
112 .ConfigurationNumber
= 1,
113 .ConfigurationStrIndex
= NO_DESCRIPTOR
,
115 .ConfigAttributes
= (USB_CONFIG_ATTR_RESERVED
| USB_CONFIG_ATTR_SELFPOWERED
),
117 .MaxPowerConsumption
= USB_CONFIG_POWER_MA(100)
122 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_Association_t
), .Type
= DTYPE_InterfaceAssociation
},
124 .FirstInterfaceIndex
= 0,
125 .TotalInterfaces
= 2,
127 .Class
= CDC_CSCP_CDCClass
,
128 .SubClass
= CDC_CSCP_ACMSubclass
,
129 .Protocol
= CDC_CSCP_ATCommandProtocol
,
131 .IADStrIndex
= NO_DESCRIPTOR
136 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
138 .InterfaceNumber
= 0,
139 .AlternateSetting
= 0,
143 .Class
= CDC_CSCP_CDCClass
,
144 .SubClass
= CDC_CSCP_ACMSubclass
,
145 .Protocol
= CDC_CSCP_ATCommandProtocol
,
147 .InterfaceStrIndex
= NO_DESCRIPTOR
150 .CDC_Functional_Header
=
152 .Header
= {.Size
= sizeof(USB_CDC_Descriptor_FunctionalHeader_t
), .Type
= DTYPE_CSInterface
},
153 .Subtype
= CDC_DSUBTYPE_CSInterface_Header
,
155 .CDCSpecification
= VERSION_BCD(01.10),
158 .CDC_Functional_ACM
=
160 .Header
= {.Size
= sizeof(USB_CDC_Descriptor_FunctionalACM_t
), .Type
= DTYPE_CSInterface
},
161 .Subtype
= CDC_DSUBTYPE_CSInterface_ACM
,
163 .Capabilities
= 0x06,
166 .CDC_Functional_Union
=
168 .Header
= {.Size
= sizeof(USB_CDC_Descriptor_FunctionalUnion_t
), .Type
= DTYPE_CSInterface
},
169 .Subtype
= CDC_DSUBTYPE_CSInterface_Union
,
171 .MasterInterfaceNumber
= 0,
172 .SlaveInterfaceNumber
= 1,
175 .CDC_NotificationEndpoint
=
177 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
179 .EndpointAddress
= (ENDPOINT_DIR_IN
| CDC_NOTIFICATION_EPNUM
),
180 .Attributes
= (EP_TYPE_INTERRUPT
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
181 .EndpointSize
= CDC_NOTIFICATION_EPSIZE
,
182 .PollingIntervalMS
= 0xFF
187 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
189 .InterfaceNumber
= 1,
190 .AlternateSetting
= 0,
194 .Class
= CDC_CSCP_CDCDataClass
,
195 .SubClass
= CDC_CSCP_NoDataSubclass
,
196 .Protocol
= CDC_CSCP_NoDataProtocol
,
198 .InterfaceStrIndex
= NO_DESCRIPTOR
201 .CDC_DataOutEndpoint
=
203 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
205 .EndpointAddress
= (ENDPOINT_DIR_OUT
| CDC_RX_EPNUM
),
206 .Attributes
= (EP_TYPE_BULK
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
207 .EndpointSize
= CDC_TXRX_EPSIZE
,
208 .PollingIntervalMS
= 0x01
211 .CDC_DataInEndpoint
=
213 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
215 .EndpointAddress
= (ENDPOINT_DIR_IN
| CDC_TX_EPNUM
),
216 .Attributes
= (EP_TYPE_BULK
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
217 .EndpointSize
= CDC_TXRX_EPSIZE
,
218 .PollingIntervalMS
= 0x01
223 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
225 .InterfaceNumber
= 2,
226 .AlternateSetting
= 0,
230 .Class
= HID_CSCP_HIDClass
,
231 .SubClass
= HID_CSCP_BootSubclass
,
232 .Protocol
= HID_CSCP_MouseBootProtocol
,
234 .InterfaceStrIndex
= NO_DESCRIPTOR
239 .Header
= {.Size
= sizeof(USB_HID_Descriptor_HID_t
), .Type
= HID_DTYPE_HID
},
241 .HIDSpec
= VERSION_BCD(01.11),
243 .TotalReportDescriptors
= 1,
244 .HIDReportType
= HID_DTYPE_Report
,
245 .HIDReportLength
= sizeof(MouseReport
)
248 .HID_ReportINEndpoint
=
250 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
252 .EndpointAddress
= (ENDPOINT_DIR_IN
| MOUSE_EPNUM
),
253 .Attributes
= (EP_TYPE_INTERRUPT
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
254 .EndpointSize
= MOUSE_EPSIZE
,
255 .PollingIntervalMS
= 0x01
259 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
260 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
261 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
263 const USB_Descriptor_String_t PROGMEM LanguageString
=
265 .Header
= {.Size
= USB_STRING_LEN(1), .Type
= DTYPE_String
},
267 .UnicodeString
= {LANGUAGE_ID_ENG
}
270 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
271 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
274 const USB_Descriptor_String_t PROGMEM ManufacturerString
=
276 .Header
= {.Size
= USB_STRING_LEN(11), .Type
= DTYPE_String
},
278 .UnicodeString
= L
"Dean Camera"
281 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
282 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
285 const USB_Descriptor_String_t PROGMEM ProductString
=
287 .Header
= {.Size
= USB_STRING_LEN(23), .Type
= DTYPE_String
},
289 .UnicodeString
= L
"LUFA CDC and Mouse Demo"
292 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
293 * documentation) by the application code so that the address and size of a requested descriptor can be given
294 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
295 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
298 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
,
299 const uint8_t wIndex
,
300 const void** const DescriptorAddress
)
302 const uint8_t DescriptorType
= (wValue
>> 8);
303 const uint8_t DescriptorNumber
= (wValue
& 0xFF);
305 const void* Address
= NULL
;
306 uint16_t Size
= NO_DESCRIPTOR
;
308 switch (DescriptorType
)
311 Address
= &DeviceDescriptor
;
312 Size
= sizeof(USB_Descriptor_Device_t
);
314 case DTYPE_Configuration
:
315 Address
= &ConfigurationDescriptor
;
316 Size
= sizeof(USB_Descriptor_Configuration_t
);
319 switch (DescriptorNumber
)
322 Address
= &LanguageString
;
323 Size
= pgm_read_byte(&LanguageString
.Header
.Size
);
326 Address
= &ManufacturerString
;
327 Size
= pgm_read_byte(&ManufacturerString
.Header
.Size
);
330 Address
= &ProductString
;
331 Size
= pgm_read_byte(&ProductString
.Header
.Size
);
337 Address
= &ConfigurationDescriptor
.HID_MouseHID
;
338 Size
= sizeof(USB_HID_Descriptor_HID_t
);
340 case HID_DTYPE_Report
:
341 Address
= &MouseReport
;
342 Size
= sizeof(MouseReport
);
346 *DescriptorAddress
= Address
;