3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11 Copyright 2010 Matthias Hullin (lufa [at] matthias [dot] hullin [dot] net)
13 Permission to use, copy, modify, distribute, and sell this
14 software and its documentation for any purpose is hereby granted
15 without fee, provided that the above copyright notice appear in
16 all copies and that both that the copyright notice and this
17 permission notice and warranty disclaimer appear in supporting
18 documentation, and that the name of the author not be used in
19 advertising or publicity pertaining to distribution of the
20 software without specific, written prior permission.
22 The author disclaim all warranties with regard to this
23 software, including all implied warranties of merchantability
24 and fitness. In no event shall the author be liable for any
25 special, indirect or consequential damages or any damages
26 whatsoever resulting from loss of use, data or profits, whether
27 in an action of contract, negligence or other tortious action,
28 arising out of or in connection with the use or performance of
34 * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
35 * computer-readable structures which the host requests upon device enumeration, to determine
36 * the device's capabilities and functions.
39 #include "Descriptors.h"
41 /* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
42 * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
43 * This allows the host to track a device across insertions on different ports, allowing them to retain allocated
44 * resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
45 * so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
46 * from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
49 #if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)
50 #warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.
53 /** HID class report descriptor. This is a special descriptor constructed with values from the
54 * USBIF HID class specification to describe the reports and capabilities of the HID device. This
55 * descriptor is parsed by the host and its contents used to determine what data (and in what encoding)
56 * the device will send, and what it may be sent back from the host. Refer to the HID specification for
57 * more details on HID report descriptors.
59 USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport
[] =
61 HID_RI_USAGE_PAGE(8), 0x01, /* Generic Desktop */
62 HID_RI_USAGE(8), 0x06, /* Keyboard */
63 HID_RI_COLLECTION(8), 0x01, /* Application */
64 HID_RI_USAGE_PAGE(8), 0x07, /* Key Codes */
65 HID_RI_USAGE_MINIMUM(8), 0xE0, /* Keyboard Left Control */
66 HID_RI_USAGE_MAXIMUM(8), 0xE7, /* Keyboard Right GUI */
67 HID_RI_LOGICAL_MINIMUM(8), 0,
68 HID_RI_LOGICAL_MAXIMUM(8), 1,
69 HID_RI_REPORT_SIZE(8), 1,
70 HID_RI_REPORT_COUNT(8), 8,
71 HID_RI_INPUT(8), (HID_IOF_DATA
| HID_IOF_VARIABLE
| HID_IOF_ABSOLUTE
| HID_IOF_NON_VOLATILE
),
73 HID_RI_REPORT_COUNT(8), 1,
74 HID_RI_REPORT_SIZE(8), 8,
75 HID_RI_INPUT(8), HID_IOF_CONSTANT
,
77 HID_RI_USAGE_PAGE(8), 0x08, /* LEDs */
78 HID_RI_USAGE_MINIMUM(8), 0x01, /* Num Lock */
79 HID_RI_USAGE_MAXIMUM(8), 0x05, /* Kana */
80 HID_RI_REPORT_COUNT(8), 5,
81 HID_RI_REPORT_SIZE(8), 1,
82 HID_RI_OUTPUT(8), (HID_IOF_DATA
| HID_IOF_VARIABLE
| HID_IOF_ABSOLUTE
| HID_IOF_NON_VOLATILE
),
83 HID_RI_REPORT_COUNT(8), 1,
84 HID_RI_REPORT_SIZE(8), 3,
85 HID_RI_OUTPUT(8), HID_IOF_CONSTANT
,
87 HID_RI_LOGICAL_MINIMUM(8), 0x00,
88 HID_RI_LOGICAL_MAXIMUM(8), 0x65,
89 HID_RI_USAGE_PAGE(8), 0x07, /* Keyboard */
90 HID_RI_USAGE_MINIMUM(8), 0x00, /* Reserved (no event indicated) */
91 HID_RI_USAGE_MAXIMUM(8), 0x65, /* Keyboard Application */
92 HID_RI_REPORT_COUNT(8), 6,
93 HID_RI_REPORT_SIZE(8), 8,
94 HID_RI_INPUT(8), (HID_IOF_DATA
| HID_IOF_ARRAY
| HID_IOF_ABSOLUTE
| HID_IOF_NON_VOLATILE
),
95 HID_RI_END_COLLECTION(0),
98 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
99 * device characteristics, including the supported USB version, control endpoint size and the
100 * number of device configurations. The descriptor is read out by the USB host when the enumeration
103 USB_Descriptor_Device_t PROGMEM DeviceDescriptor
=
105 .Header
= {.Size
= sizeof(USB_Descriptor_Device_t
), .Type
= DTYPE_Device
},
107 .USBSpecification
= VERSION_BCD(01.10),
108 .Class
= USB_CSCP_NoDeviceClass
,
109 .SubClass
= USB_CSCP_NoDeviceSubclass
,
110 .Protocol
= USB_CSCP_NoDeviceProtocol
,
112 .Endpoint0Size
= FIXED_CONTROL_ENDPOINT_SIZE
,
116 .ReleaseNumber
= VERSION_BCD(00.01),
118 .ManufacturerStrIndex
= 0x01,
119 .ProductStrIndex
= 0x02,
120 .SerialNumStrIndex
= USE_INTERNAL_SERIAL
,
122 .NumberOfConfigurations
= FIXED_NUM_CONFIGURATIONS
125 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
126 * of the device in one of its supported configurations, including information about any device interfaces
127 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
128 * a configuration so that the host may correctly communicate with the USB device.
130 USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor
=
134 .Header
= {.Size
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type
= DTYPE_Configuration
},
136 .TotalConfigurationSize
= sizeof(USB_Descriptor_Configuration_t
),
137 .TotalInterfaces
= 2,
139 .ConfigurationNumber
= 1,
140 .ConfigurationStrIndex
= NO_DESCRIPTOR
,
142 .ConfigAttributes
= USB_CONFIG_ATTR_BUSPOWERED
,
144 .MaxPowerConsumption
= USB_CONFIG_POWER_MA(100)
149 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
151 .InterfaceNumber
= 0,
152 .AlternateSetting
= 0,
156 .Class
= MS_CSCP_MassStorageClass
,
157 .SubClass
= MS_CSCP_SCSITransparentSubclass
,
158 .Protocol
= MS_CSCP_BulkOnlyTransportProtocol
,
160 .InterfaceStrIndex
= NO_DESCRIPTOR
165 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
167 .EndpointAddress
= (ENDPOINT_DESCRIPTOR_DIR_IN
| MASS_STORAGE_IN_EPNUM
),
168 .Attributes
= (EP_TYPE_BULK
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
169 .EndpointSize
= MASS_STORAGE_IO_EPSIZE
,
170 .PollingIntervalMS
= 0x01
173 .MS_DataOutEndpoint
=
175 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
177 .EndpointAddress
= (ENDPOINT_DESCRIPTOR_DIR_OUT
| MASS_STORAGE_OUT_EPNUM
),
178 .Attributes
= (EP_TYPE_BULK
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
179 .EndpointSize
= MASS_STORAGE_IO_EPSIZE
,
180 .PollingIntervalMS
= 0x01
183 .HID_KeyboardInterface
=
185 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
187 .InterfaceNumber
= 1,
188 .AlternateSetting
= 0,
192 .Class
= HID_CSCP_HIDClass
,
193 .SubClass
= HID_CSCP_BootSubclass
,
194 .Protocol
= HID_CSCP_KeyboardBootProtocol
,
196 .InterfaceStrIndex
= NO_DESCRIPTOR
201 .Header
= {.Size
= sizeof(USB_HID_Descriptor_HID_t
), .Type
= HID_DTYPE_HID
},
203 .HIDSpec
= VERSION_BCD(01.11),
205 .TotalReportDescriptors
= 1,
206 .HIDReportType
= HID_DTYPE_Report
,
207 .HIDReportLength
= sizeof(KeyboardReport
)
210 .HID_ReportINEndpoint
=
212 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
214 .EndpointAddress
= (ENDPOINT_DESCRIPTOR_DIR_IN
| KEYBOARD_EPNUM
),
215 .Attributes
= (EP_TYPE_INTERRUPT
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
216 .EndpointSize
= KEYBOARD_EPSIZE
,
217 .PollingIntervalMS
= 0x01
221 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
222 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
223 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
225 USB_Descriptor_String_t PROGMEM LanguageString
=
227 .Header
= {.Size
= USB_STRING_LEN(1), .Type
= DTYPE_String
},
229 .UnicodeString
= {LANGUAGE_ID_ENG
}
232 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
233 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
236 USB_Descriptor_String_t PROGMEM ManufacturerString
=
238 .Header
= {.Size
= USB_STRING_LEN(11), .Type
= DTYPE_String
},
240 .UnicodeString
= L
"Dean Camera"
243 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
244 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
247 USB_Descriptor_String_t PROGMEM ProductString
=
249 .Header
= {.Size
= USB_STRING_LEN(35), .Type
= DTYPE_String
},
251 .UnicodeString
= L
"LUFA Mass Storage and Keyboard Demo"
254 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
255 * documentation) by the application code so that the address and size of a requested descriptor can be given
256 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
257 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
260 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
,
261 const uint8_t wIndex
,
262 const void** const DescriptorAddress
)
264 const uint8_t DescriptorType
= (wValue
>> 8);
265 const uint8_t DescriptorNumber
= (wValue
& 0xFF);
267 const void* Address
= NULL
;
268 uint16_t Size
= NO_DESCRIPTOR
;
270 switch (DescriptorType
)
273 Address
= &DeviceDescriptor
;
274 Size
= sizeof(USB_Descriptor_Device_t
);
276 case DTYPE_Configuration
:
277 Address
= &ConfigurationDescriptor
;
278 Size
= sizeof(USB_Descriptor_Configuration_t
);
281 switch (DescriptorNumber
)
284 Address
= &LanguageString
;
285 Size
= pgm_read_byte(&LanguageString
.Header
.Size
);
288 Address
= &ManufacturerString
;
289 Size
= pgm_read_byte(&ManufacturerString
.Header
.Size
);
292 Address
= &ProductString
;
293 Size
= pgm_read_byte(&ProductString
.Header
.Size
);
299 Address
= &ConfigurationDescriptor
.HID_KeyboardHID
;
300 Size
= sizeof(USB_HID_Descriptor_HID_t
);
302 case HID_DTYPE_Report
:
303 Address
= &KeyboardReport
;
304 Size
= sizeof(KeyboardReport
);
308 *DescriptorAddress
= Address
;