3 Copyright (C) Dean Camera, 2013.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2013 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 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
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"
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.
47 const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport
[] =
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
55 * Absolute screen coordinates: false
57 HID_DESCRIPTOR_MOUSE(-1, 1, -1, 1, 3, false)
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
65 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor
=
67 .Header
= {.Size
= sizeof(USB_Descriptor_Device_t
), .Type
= DTYPE_Device
},
69 .USBSpecification
= VERSION_BCD(01.10),
70 .Class
= USB_CSCP_IADDeviceClass
,
71 .SubClass
= USB_CSCP_IADDeviceSubclass
,
72 .Protocol
= USB_CSCP_IADDeviceProtocol
,
74 .Endpoint0Size
= FIXED_CONTROL_ENDPOINT_SIZE
,
78 .ReleaseNumber
= VERSION_BCD(00.01),
80 .ManufacturerStrIndex
= 0x01,
81 .ProductStrIndex
= 0x02,
82 .SerialNumStrIndex
= USE_INTERNAL_SERIAL
,
84 .NumberOfConfigurations
= FIXED_NUM_CONFIGURATIONS
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.
92 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor
=
96 .Header
= {.Size
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type
= DTYPE_Configuration
},
98 .TotalConfigurationSize
= sizeof(USB_Descriptor_Configuration_t
),
101 .ConfigurationNumber
= 1,
102 .ConfigurationStrIndex
= NO_DESCRIPTOR
,
104 .ConfigAttributes
= (USB_CONFIG_ATTR_RESERVED
| USB_CONFIG_ATTR_SELFPOWERED
),
106 .MaxPowerConsumption
= USB_CONFIG_POWER_MA(100)
111 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_Association_t
), .Type
= DTYPE_InterfaceAssociation
},
113 .FirstInterfaceIndex
= 0,
114 .TotalInterfaces
= 2,
116 .Class
= CDC_CSCP_CDCClass
,
117 .SubClass
= CDC_CSCP_ACMSubclass
,
118 .Protocol
= CDC_CSCP_ATCommandProtocol
,
120 .IADStrIndex
= NO_DESCRIPTOR
125 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
127 .InterfaceNumber
= 0,
128 .AlternateSetting
= 0,
132 .Class
= CDC_CSCP_CDCClass
,
133 .SubClass
= CDC_CSCP_ACMSubclass
,
134 .Protocol
= CDC_CSCP_ATCommandProtocol
,
136 .InterfaceStrIndex
= NO_DESCRIPTOR
139 .CDC_Functional_Header
=
141 .Header
= {.Size
= sizeof(USB_CDC_Descriptor_FunctionalHeader_t
), .Type
= DTYPE_CSInterface
},
142 .Subtype
= CDC_DSUBTYPE_CSInterface_Header
,
144 .CDCSpecification
= VERSION_BCD(01.10),
147 .CDC_Functional_ACM
=
149 .Header
= {.Size
= sizeof(USB_CDC_Descriptor_FunctionalACM_t
), .Type
= DTYPE_CSInterface
},
150 .Subtype
= CDC_DSUBTYPE_CSInterface_ACM
,
152 .Capabilities
= 0x06,
155 .CDC_Functional_Union
=
157 .Header
= {.Size
= sizeof(USB_CDC_Descriptor_FunctionalUnion_t
), .Type
= DTYPE_CSInterface
},
158 .Subtype
= CDC_DSUBTYPE_CSInterface_Union
,
160 .MasterInterfaceNumber
= 0,
161 .SlaveInterfaceNumber
= 1,
164 .CDC_NotificationEndpoint
=
166 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
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
176 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
178 .InterfaceNumber
= 1,
179 .AlternateSetting
= 0,
183 .Class
= CDC_CSCP_CDCDataClass
,
184 .SubClass
= CDC_CSCP_NoDataSubclass
,
185 .Protocol
= CDC_CSCP_NoDataProtocol
,
187 .InterfaceStrIndex
= NO_DESCRIPTOR
190 .CDC_DataOutEndpoint
=
192 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
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
200 .CDC_DataInEndpoint
=
202 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
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
212 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
214 .InterfaceNumber
= 2,
215 .AlternateSetting
= 0,
219 .Class
= HID_CSCP_HIDClass
,
220 .SubClass
= HID_CSCP_BootSubclass
,
221 .Protocol
= HID_CSCP_MouseBootProtocol
,
223 .InterfaceStrIndex
= NO_DESCRIPTOR
228 .Header
= {.Size
= sizeof(USB_HID_Descriptor_HID_t
), .Type
= HID_DTYPE_HID
},
230 .HIDSpec
= VERSION_BCD(01.11),
232 .TotalReportDescriptors
= 1,
233 .HIDReportType
= HID_DTYPE_Report
,
234 .HIDReportLength
= sizeof(MouseReport
)
237 .HID_ReportINEndpoint
=
239 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
241 .EndpointAddress
= MOUSE_EPADDR
,
242 .Attributes
= (EP_TYPE_INTERRUPT
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
243 .EndpointSize
= MOUSE_EPSIZE
,
244 .PollingIntervalMS
= 0x05
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.
252 const USB_Descriptor_String_t PROGMEM LanguageString
=
254 .Header
= {.Size
= USB_STRING_LEN(1), .Type
= DTYPE_String
},
256 .UnicodeString
= {LANGUAGE_ID_ENG
}
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
263 const USB_Descriptor_String_t PROGMEM ManufacturerString
=
265 .Header
= {.Size
= USB_STRING_LEN(11), .Type
= DTYPE_String
},
267 .UnicodeString
= L
"Dean Camera"
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
274 const USB_Descriptor_String_t PROGMEM ProductString
=
276 .Header
= {.Size
= USB_STRING_LEN(23), .Type
= DTYPE_String
},
278 .UnicodeString
= L
"LUFA CDC and Mouse Demo"
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
287 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
,
288 const uint8_t wIndex
,
289 const void** const DescriptorAddress
)
291 const uint8_t DescriptorType
= (wValue
>> 8);
292 const uint8_t DescriptorNumber
= (wValue
& 0xFF);
294 const void* Address
= NULL
;
295 uint16_t Size
= NO_DESCRIPTOR
;
297 switch (DescriptorType
)
300 Address
= &DeviceDescriptor
;
301 Size
= sizeof(USB_Descriptor_Device_t
);
303 case DTYPE_Configuration
:
304 Address
= &ConfigurationDescriptor
;
305 Size
= sizeof(USB_Descriptor_Configuration_t
);
308 switch (DescriptorNumber
)
311 Address
= &LanguageString
;
312 Size
= pgm_read_byte(&LanguageString
.Header
.Size
);
315 Address
= &ManufacturerString
;
316 Size
= pgm_read_byte(&ManufacturerString
.Header
.Size
);
319 Address
= &ProductString
;
320 Size
= pgm_read_byte(&ProductString
.Header
.Size
);
326 Address
= &ConfigurationDescriptor
.HID_MouseHID
;
327 Size
= sizeof(USB_HID_Descriptor_HID_t
);
329 case HID_DTYPE_Report
:
330 Address
= &MouseReport
;
331 Size
= sizeof(MouseReport
);
335 *DescriptorAddress
= Address
;