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 /** HID class report descriptor. This is a special descriptor constructed with values from the
41 * USBIF HID class specification to describe the reports and capabilities of the HID device. This
42 * descriptor is parsed by the host and its contents used to determine what data (and in what encoding)
43 * the device will send, and what it may be sent back from the host. Refer to the HID specification for
44 * more details on HID report descriptors.
46 * This descriptor describes the mouse HID interface's report structure.
48 USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport
[] =
50 HID_RI_USAGE_PAGE(8), 0x01, /* Generic Desktop */
51 HID_RI_USAGE(8), 0x02, /* Mouse */
52 HID_RI_COLLECTION(8), 0x01, /* Application */
53 HID_RI_USAGE(8), 0x01, /* Pointer */
54 HID_RI_COLLECTION(8), 0x00, /* Physical */
55 HID_RI_USAGE_PAGE(8), 0x09, /* Button */
56 HID_RI_USAGE_MINIMUM(8), 0x01,
57 HID_RI_USAGE_MAXIMUM(8), 0x03,
58 HID_RI_LOGICAL_MINIMUM(8), 0,
59 HID_RI_LOGICAL_MAXIMUM(8), 1,
60 HID_RI_REPORT_COUNT(8), 3,
61 HID_RI_REPORT_SIZE(8), 1,
62 HID_RI_INPUT(8), (HID_IOF_DATA
| HID_IOF_VARIABLE
| HID_IOF_ABSOLUTE
| HID_IOF_VOLATILE
),
64 HID_RI_REPORT_COUNT(8), 1,
65 HID_RI_REPORT_SIZE(8), 5,
66 HID_RI_INPUT(8), HID_IOF_CONSTANT
,
68 HID_RI_USAGE_PAGE(8), 0x01, /* Generic Desktop */
69 HID_RI_USAGE(8), 0x30, /* Usage X */
70 HID_RI_USAGE(8), 0x31, /* Usage Y */
71 HID_RI_LOGICAL_MINIMUM(8), -1,
72 HID_RI_LOGICAL_MAXIMUM(8), 1,
73 HID_RI_PHYSICAL_MINIMUM(8), -1,
74 HID_RI_PHYSICAL_MAXIMUM(8), 1,
75 HID_RI_REPORT_COUNT(8), 2,
76 HID_RI_REPORT_SIZE(8), 8,
77 HID_RI_INPUT(8), (HID_IOF_DATA
| HID_IOF_VARIABLE
| HID_IOF_RELATIVE
| HID_IOF_NON_VOLATILE
),
78 HID_RI_END_COLLECTION(0),
79 HID_RI_END_COLLECTION(0),
82 /** Same as the MouseReport structure, but defines the keyboard HID interface's report structure. */
83 USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport
[] =
85 HID_RI_USAGE_PAGE(8), 0x01, /* Generic Desktop */
86 HID_RI_USAGE(8), 0x06, /* Keyboard */
87 HID_RI_COLLECTION(8), 0x01, /* Application */
88 HID_RI_USAGE_PAGE(8), 0x07, /* Key Codes */
89 HID_RI_USAGE_MINIMUM(8), 0xE0, /* Keyboard Left Control */
90 HID_RI_USAGE_MAXIMUM(8), 0xE7, /* Keyboard Right GUI */
91 HID_RI_LOGICAL_MINIMUM(8), 0,
92 HID_RI_LOGICAL_MAXIMUM(8), 1,
93 HID_RI_REPORT_SIZE(8), 1,
94 HID_RI_REPORT_COUNT(8), 8,
95 HID_RI_INPUT(8), (HID_IOF_DATA
| HID_IOF_VARIABLE
| HID_IOF_ABSOLUTE
| HID_IOF_NON_VOLATILE
),
97 HID_RI_REPORT_COUNT(8), 1,
98 HID_RI_REPORT_SIZE(8), 8,
99 HID_RI_INPUT(8), HID_IOF_CONSTANT
,
101 HID_RI_USAGE_PAGE(8), 0x08, /* LEDs */
102 HID_RI_USAGE_MINIMUM(8), 0x01, /* Num Lock */
103 HID_RI_USAGE_MAXIMUM(8), 0x05, /* Kana */
104 HID_RI_REPORT_COUNT(8), 5,
105 HID_RI_REPORT_SIZE(8), 1,
106 HID_RI_OUTPUT(8), (HID_IOF_DATA
| HID_IOF_VARIABLE
| HID_IOF_ABSOLUTE
| HID_IOF_NON_VOLATILE
),
107 HID_RI_REPORT_COUNT(8), 1,
108 HID_RI_REPORT_SIZE(8), 3,
109 HID_RI_OUTPUT(8), HID_IOF_CONSTANT
,
111 HID_RI_LOGICAL_MINIMUM(8), 0x00,
112 HID_RI_LOGICAL_MAXIMUM(8), 0x65,
113 HID_RI_USAGE_PAGE(8), 0x07, /* Keyboard */
114 HID_RI_USAGE_MINIMUM(8), 0x00, /* Reserved (no event indicated) */
115 HID_RI_USAGE_MAXIMUM(8), 0x65, /* Keyboard Application */
116 HID_RI_REPORT_COUNT(8), 6,
117 HID_RI_REPORT_SIZE(8), 8,
118 HID_RI_INPUT(8), (HID_IOF_DATA
| HID_IOF_ARRAY
| HID_IOF_ABSOLUTE
| HID_IOF_NON_VOLATILE
),
119 HID_RI_END_COLLECTION(0),
122 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
123 * device characteristics, including the supported USB version, control endpoint size and the
124 * number of device configurations. The descriptor is read out by the USB host when the enumeration
127 USB_Descriptor_Device_t PROGMEM DeviceDescriptor
=
129 .Header
= {.Size
= sizeof(USB_Descriptor_Device_t
), .Type
= DTYPE_Device
},
131 .USBSpecification
= VERSION_BCD(01.10),
132 .Class
= USB_CSCP_NoDeviceClass
,
133 .SubClass
= USB_CSCP_NoDeviceSubclass
,
134 .Protocol
= USB_CSCP_NoDeviceProtocol
,
136 .Endpoint0Size
= FIXED_CONTROL_ENDPOINT_SIZE
,
140 .ReleaseNumber
= VERSION_BCD(00.01),
142 .ManufacturerStrIndex
= 0x01,
143 .ProductStrIndex
= 0x02,
144 .SerialNumStrIndex
= NO_DESCRIPTOR
,
146 .NumberOfConfigurations
= FIXED_NUM_CONFIGURATIONS
149 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
150 * of the device in one of its supported configurations, including information about any device interfaces
151 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
152 * a configuration so that the host may correctly communicate with the USB device.
154 USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor
=
158 .Header
= {.Size
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type
= DTYPE_Configuration
},
160 .TotalConfigurationSize
= sizeof(USB_Descriptor_Configuration_t
),
161 .TotalInterfaces
= 2,
163 .ConfigurationNumber
= 1,
164 .ConfigurationStrIndex
= NO_DESCRIPTOR
,
166 .ConfigAttributes
= (USB_CONFIG_ATTR_BUSPOWERED
| USB_CONFIG_ATTR_SELFPOWERED
),
168 .MaxPowerConsumption
= USB_CONFIG_POWER_MA(100)
171 .HID1_KeyboardInterface
=
173 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
175 .InterfaceNumber
= 0x00,
176 .AlternateSetting
= 0x00,
180 .Class
= HID_CSCP_HIDClass
,
181 .SubClass
= HID_CSCP_BootSubclass
,
182 .Protocol
= HID_CSCP_KeyboardBootProtocol
,
184 .InterfaceStrIndex
= NO_DESCRIPTOR
189 .Header
= {.Size
= sizeof(USB_HID_Descriptor_HID_t
), .Type
= HID_DTYPE_HID
},
191 .HIDSpec
= VERSION_BCD(01.11),
193 .TotalReportDescriptors
= 1,
194 .HIDReportType
= HID_DTYPE_Report
,
195 .HIDReportLength
= sizeof(KeyboardReport
)
198 .HID1_ReportINEndpoint
=
200 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
202 .EndpointAddress
= (ENDPOINT_DESCRIPTOR_DIR_IN
| KEYBOARD_IN_EPNUM
),
203 .Attributes
= (EP_TYPE_INTERRUPT
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
204 .EndpointSize
= HID_EPSIZE
,
205 .PollingIntervalMS
= 0x01
208 .HID2_MouseInterface
=
210 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
212 .InterfaceNumber
= 0x01,
213 .AlternateSetting
= 0x00,
217 .Class
= HID_CSCP_HIDClass
,
218 .SubClass
= HID_CSCP_BootSubclass
,
219 .Protocol
= HID_CSCP_MouseBootProtocol
,
221 .InterfaceStrIndex
= NO_DESCRIPTOR
226 .Header
= {.Size
= sizeof(USB_HID_Descriptor_HID_t
), .Type
= HID_DTYPE_HID
},
228 .HIDSpec
= VERSION_BCD(01.11),
230 .TotalReportDescriptors
= 1,
231 .HIDReportType
= HID_DTYPE_Report
,
232 .HIDReportLength
= sizeof(MouseReport
)
235 .HID2_ReportINEndpoint
=
237 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
239 .EndpointAddress
= (ENDPOINT_DESCRIPTOR_DIR_IN
| MOUSE_IN_EPNUM
),
240 .Attributes
= (EP_TYPE_INTERRUPT
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
241 .EndpointSize
= HID_EPSIZE
,
242 .PollingIntervalMS
= 0x01
246 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
247 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
248 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
250 USB_Descriptor_String_t PROGMEM LanguageString
=
252 .Header
= {.Size
= USB_STRING_LEN(1), .Type
= DTYPE_String
},
254 .UnicodeString
= {LANGUAGE_ID_ENG
}
257 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
258 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
261 USB_Descriptor_String_t PROGMEM ManufacturerString
=
263 .Header
= {.Size
= USB_STRING_LEN(11), .Type
= DTYPE_String
},
265 .UnicodeString
= L
"Dean Camera"
268 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
269 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
272 USB_Descriptor_String_t PROGMEM ProductString
=
274 .Header
= {.Size
= USB_STRING_LEN(28), .Type
= DTYPE_String
},
276 .UnicodeString
= L
"LUFA Mouse and Keyboard Demo"
279 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
280 * documentation) by the application code so that the address and size of a requested descriptor can be given
281 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
282 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
285 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
,
286 const uint8_t wIndex
,
287 const void** const DescriptorAddress
)
289 const uint8_t DescriptorType
= (wValue
>> 8);
290 const uint8_t DescriptorNumber
= (wValue
& 0xFF);
292 const void* Address
= NULL
;
293 uint16_t Size
= NO_DESCRIPTOR
;
295 switch (DescriptorType
)
298 Address
= &DeviceDescriptor
;
299 Size
= sizeof(USB_Descriptor_Device_t
);
301 case DTYPE_Configuration
:
302 Address
= &ConfigurationDescriptor
;
303 Size
= sizeof(USB_Descriptor_Configuration_t
);
306 switch (DescriptorNumber
)
309 Address
= &LanguageString
;
310 Size
= pgm_read_byte(&LanguageString
.Header
.Size
);
313 Address
= &ManufacturerString
;
314 Size
= pgm_read_byte(&ManufacturerString
.Header
.Size
);
317 Address
= &ProductString
;
318 Size
= pgm_read_byte(&ProductString
.Header
.Size
);
326 Address
= &ConfigurationDescriptor
.HID1_KeyboardHID
;
327 Size
= sizeof(USB_HID_Descriptor_HID_t
);
331 Address
= &ConfigurationDescriptor
.HID2_MouseHID
;
332 Size
= sizeof(USB_HID_Descriptor_HID_t
);
335 case HID_DTYPE_Report
:
338 Address
= &KeyboardReport
;
339 Size
= sizeof(KeyboardReport
);
343 Address
= &MouseReport
;
344 Size
= sizeof(MouseReport
);
350 *DescriptorAddress
= Address
;