3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 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 0x05, 0x01, /* Usage Page (Generic Desktop) */
51 0x09, 0x02, /* Usage (Mouse) */
52 0xA1, 0x01, /* Collection (Application) */
53 0x09, 0x01, /* Usage (Pointer) */
54 0xA1, 0x00, /* Collection (Physical) */
55 0x95, 0x03, /* Report Count (3) */
56 0x75, 0x01, /* Report Size (1) */
57 0x05, 0x09, /* Usage Page (Button) */
58 0x19, 0x01, /* Usage Minimum (Button 1) */
59 0x29, 0x03, /* Usage Maximum (Button 3) */
60 0x15, 0x00, /* Logical Minimum (0) */
61 0x25, 0x01, /* Logical Maximum (1) */
62 0x81, 0x02, /* Input (Data, Variable, Absolute) */
63 0x95, 0x01, /* Report Count (1) */
64 0x75, 0x05, /* Report Size (5) */
65 0x81, 0x01, /* Input (Constant) */
66 0x75, 0x08, /* Report Size (8) */
67 0x95, 0x02, /* Report Count (2) */
68 0x05, 0x01, /* Usage Page (Generic Desktop Control) */
69 0x09, 0x30, /* Usage X */
70 0x09, 0x31, /* Usage Y */
71 0x15, 0x81, /* Logical Minimum (-127) */
72 0x25, 0x7F, /* Logical Maximum (127) */
73 0x81, 0x06, /* Input (Data, Variable, Relative) */
74 0xC0, /* End Collection */
75 0xC0, /* End Collection */
78 /** Same as the MouseReport structure, but defines the keyboard HID interface's report structure. */
79 USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport
[] =
81 0x05, 0x01, /* Usage Page (Generic Desktop) */
82 0x09, 0x06, /* Usage (Keyboard) */
83 0xa1, 0x01, /* Collection (Application) */
84 0x75, 0x01, /* Report Size (1) */
85 0x95, 0x08, /* Report Count (8) */
86 0x05, 0x07, /* Usage Page (Key Codes) */
87 0x19, 0xe0, /* Usage Minimum (Keyboard LeftControl) */
88 0x29, 0xe7, /* Usage Maximum (Keyboard Right GUI) */
89 0x15, 0x00, /* Logical Minimum (0) */
90 0x25, 0x01, /* Logical Maximum (1) */
91 0x81, 0x02, /* Input (Data, Variable, Absolute) */
92 0x95, 0x01, /* Report Count (1) */
93 0x75, 0x08, /* Report Size (8) */
94 0x81, 0x03, /* Input (Const, Variable, Absolute) */
95 0x95, 0x05, /* Report Count (5) */
96 0x75, 0x01, /* Report Size (1) */
97 0x05, 0x08, /* Usage Page (LEDs) */
98 0x19, 0x01, /* Usage Minimum (Num Lock) */
99 0x29, 0x05, /* Usage Maximum (Kana) */
100 0x91, 0x02, /* Output (Data, Variable, Absolute) */
101 0x95, 0x01, /* Report Count (1) */
102 0x75, 0x03, /* Report Size (3) */
103 0x91, 0x03, /* Output (Const, Variable, Absolute) */
104 0x95, 0x06, /* Report Count (6) */
105 0x75, 0x08, /* Report Size (8) */
106 0x15, 0x00, /* Logical Minimum (0) */
107 0x25, 0x65, /* Logical Maximum (101) */
108 0x05, 0x07, /* Usage Page (Keyboard) */
109 0x19, 0x00, /* Usage Minimum (Reserved (no event indicated)) */
110 0x29, 0x65, /* Usage Maximum (Keyboard Application) */
111 0x81, 0x00, /* Input (Data, Array, Absolute) */
112 0xC0 /* End Collection */
115 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
116 * device characteristics, including the supported USB version, control endpoint size and the
117 * number of device configurations. The descriptor is read out by the USB host when the enumeration
120 USB_Descriptor_Device_t PROGMEM DeviceDescriptor
=
122 .Header
= {.Size
= sizeof(USB_Descriptor_Device_t
), .Type
= DTYPE_Device
},
124 .USBSpecification
= VERSION_BCD(01.10),
129 .Endpoint0Size
= FIXED_CONTROL_ENDPOINT_SIZE
,
133 .ReleaseNumber
= 0x0000,
135 .ManufacturerStrIndex
= 0x01,
136 .ProductStrIndex
= 0x02,
137 .SerialNumStrIndex
= NO_DESCRIPTOR
,
139 .NumberOfConfigurations
= FIXED_NUM_CONFIGURATIONS
142 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
143 * of the device in one of its supported configurations, including information about any device interfaces
144 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
145 * a configuration so that the host may correctly communicate with the USB device.
147 USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor
=
151 .Header
= {.Size
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type
= DTYPE_Configuration
},
153 .TotalConfigurationSize
= sizeof(USB_Descriptor_Configuration_t
),
154 .TotalInterfaces
= 2,
156 .ConfigurationNumber
= 1,
157 .ConfigurationStrIndex
= NO_DESCRIPTOR
,
159 .ConfigAttributes
= (USB_CONFIG_ATTR_BUSPOWERED
| USB_CONFIG_ATTR_SELFPOWERED
),
161 .MaxPowerConsumption
= USB_CONFIG_POWER_MA(100)
164 .HID1_KeyboardInterface
=
166 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
168 .InterfaceNumber
= 0x00,
169 .AlternateSetting
= 0x00,
175 .Protocol
= HID_BOOT_KEYBOARD_PROTOCOL
,
177 .InterfaceStrIndex
= NO_DESCRIPTOR
182 .Header
= {.Size
= sizeof(USB_HID_Descriptor_t
), .Type
= DTYPE_HID
},
184 .HIDSpec
= VERSION_BCD(01.11),
186 .TotalReportDescriptors
= 1,
187 .HIDReportType
= DTYPE_Report
,
188 .HIDReportLength
= sizeof(KeyboardReport
)
191 .HID1_ReportINEndpoint
=
193 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
195 .EndpointAddress
= (ENDPOINT_DESCRIPTOR_DIR_IN
| KEYBOARD_IN_EPNUM
),
196 .Attributes
= (EP_TYPE_INTERRUPT
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
197 .EndpointSize
= HID_EPSIZE
,
198 .PollingIntervalMS
= 0x0A
201 .HID2_MouseInterface
=
203 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
205 .InterfaceNumber
= 0x01,
206 .AlternateSetting
= 0x00,
212 .Protocol
= HID_BOOT_MOUSE_PROTOCOL
,
214 .InterfaceStrIndex
= NO_DESCRIPTOR
219 .Header
= {.Size
= sizeof(USB_HID_Descriptor_t
), .Type
= DTYPE_HID
},
221 .HIDSpec
= VERSION_BCD(01.11),
223 .TotalReportDescriptors
= 1,
224 .HIDReportType
= DTYPE_Report
,
225 .HIDReportLength
= sizeof(MouseReport
)
228 .HID2_ReportINEndpoint
=
230 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
232 .EndpointAddress
= (ENDPOINT_DESCRIPTOR_DIR_IN
| MOUSE_IN_EPNUM
),
233 .Attributes
= (EP_TYPE_INTERRUPT
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
234 .EndpointSize
= HID_EPSIZE
,
235 .PollingIntervalMS
= 0x0A
239 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
240 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
241 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
243 USB_Descriptor_String_t PROGMEM LanguageString
=
245 .Header
= {.Size
= USB_STRING_LEN(1), .Type
= DTYPE_String
},
247 .UnicodeString
= {LANGUAGE_ID_ENG
}
250 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
251 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
254 USB_Descriptor_String_t PROGMEM ManufacturerString
=
256 .Header
= {.Size
= USB_STRING_LEN(11), .Type
= DTYPE_String
},
258 .UnicodeString
= L
"Dean Camera"
261 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
262 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
265 USB_Descriptor_String_t PROGMEM ProductString
=
267 .Header
= {.Size
= USB_STRING_LEN(28), .Type
= DTYPE_String
},
269 .UnicodeString
= L
"LUFA Mouse and Keyboard Demo"
272 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
273 * documentation) by the application code so that the address and size of a requested descriptor can be given
274 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
275 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
278 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
,
279 const uint8_t wIndex
,
280 const void** const DescriptorAddress
)
282 const uint8_t DescriptorType
= (wValue
>> 8);
283 const uint8_t DescriptorNumber
= (wValue
& 0xFF);
285 const void* Address
= NULL
;
286 uint16_t Size
= NO_DESCRIPTOR
;
288 switch (DescriptorType
)
291 Address
= &DeviceDescriptor
;
292 Size
= sizeof(USB_Descriptor_Device_t
);
294 case DTYPE_Configuration
:
295 Address
= &ConfigurationDescriptor
;
296 Size
= sizeof(USB_Descriptor_Configuration_t
);
299 switch (DescriptorNumber
)
302 Address
= &LanguageString
;
303 Size
= pgm_read_byte(&LanguageString
.Header
.Size
);
306 Address
= &ManufacturerString
;
307 Size
= pgm_read_byte(&ManufacturerString
.Header
.Size
);
310 Address
= &ProductString
;
311 Size
= pgm_read_byte(&ProductString
.Header
.Size
);
319 Address
= &ConfigurationDescriptor
.HID1_KeyboardHID
;
320 Size
= sizeof(USB_HID_Descriptor_t
);
324 Address
= &ConfigurationDescriptor
.HID2_MouseHID
;
325 Size
= sizeof(USB_HID_Descriptor_t
);
331 Address
= &KeyboardReport
;
332 Size
= sizeof(KeyboardReport
);
336 Address
= &MouseReport
;
337 Size
= sizeof(MouseReport
);
343 *DescriptorAddress
= Address
;