Offset |
Field |
Size |
Description |
0 |
bLength |
1 |
Descriptor size in bytes |
1 |
bDescriptorType |
1 |
Device descriptor (0x02) |
2 |
wTotalLength |
2 |
Total bytes returned |
4 |
bNumInterfaces |
1 |
Number of interfaces |
5 |
bConfigurationValue |
1 |
Value used to select configuration |
6 |
iConfiguration |
1 |
Index describing configuration string |
7 |
bmAttributes |
1 |
Power supply attributes |
8 |
bMaxPower |
2 |
Max power consumption in 2mA |
Table 8.8 shows an example configuration descriptor for a mouse device. The length of the descriptor is 9 bytes ( bLength =9), and the descriptor type is 0x02 ( bDescriptorType =0x02). The total combined size of the descriptors is 34 ( wTotalLength =34). The number of interfaces for the mouse device is 1 ( bNumInterfaces =1). Host SetConfiguration command must use the value 1 as an argument in SetConfiguration() to select this configuration. There is no string to describe this configuration. bmAttributes is set to 0x40 to indicate that the device is self-powered. bMaxPower is set to 10 to specify that the maximum current drawn by the device is 20mA.
Table 8.8: Example configuration descriptor
Offset |
Field |
Value |
Description |
0 |
bLength |
9 |
Descriptor size is 9 bytes |
1 |
bDescriptorType |
0x02 |
Device descriptor is 0x02 |
2 |
wTotalLength |
34 |
Total bytes returned is 34 |
4 |
bNumInterfaces |
1 |
Number of interfaces is 1 |
5 |
bConfigurationValue |
1 |
Value used to select configuration |
6 |
iConfiguration |
0x2A |
Index describing configuration string |
7 |
bmAttributes |
0x40 |
Power supply attributes |
8 |
bMaxPower |
10 |
Max power consumption is 20mA |
8.4.3 Interface Descriptors
The interface descriptors specify the class of the interface and the number of endpoints it uses. There may be more than one interface.
Table 8.9 shows the format of the interface descriptor with the meaning of each field.
Table 8.9: Interface descriptor
Offset |
Field |
Size |
Description |
0 |
bLength |
1 |
Descriptor size in bytes |
1 |
bDescriptorType |
1 |
Device descriptor (0x04) |
2 |
bInterfaceNumber |
1 |
Number of interface |
3 |
bAlternateSetting |
1 |
Value to select alternate setting |
4 |
bNumEndpoints |
1 |
Number of endpoints |
5 |
bInterfaceClass |
1 |
Class code |
6 |
bInterfaceSubClass |
1 |
Subclass code |
7 |
bInterfaceProtocol |
1 |
Protocol code |
8 |
iInterface |
1 |
Index of string descriptor to interface |
bLength is the length of the device descriptor.
bDescriptorType is the descriptor type.
bInterfaceNumber indicates the index of the interface descriptor.
bAlternateSetting can be used to specify alternate interfaces that can be selected by the host using command Set Interface .
bNumEndpoints indicates the number of endpoints used by the interface.
bInterfaceClass specifies the device class code (assigned by the USB organization).
bInterfaceSubClass specifies the device subclass code (assigned by the USB organization).
bInterfaceProtocol specifies the device protocol code (assigned by the USB organization).
iInterface is an index to a string descriptor of the interface.
Table 8.10 shows an example interface descriptor for a mouse device. The descriptor length is 9 bytes ( bLength =9) and the descriptor type is 0x04 ( bDescriptorType =0x04). The interface number used to reference this interface is 1 ( bInterfaceNumber =1).
Table 8.10: Example interface descriptor
Offset |
Field |
Value |
Description |
0 |
bLength |
9 |
Descriptor size is 9 bytes |
1 |
bDescriptorType |
0x04 |
Device descriptor is 0x04 |
2 |
bInterfaceNumber |
0 |
Number of interface |
3 |
bAlternateSetting |
0 |
Value to select alternate setting |
4 |
bNumEndpoints |
1 |
Number of endpoints is 1 |
5 |
bInterfaceClass |
0x03 |
Class code is 0x03 |
6 |
bInterfaceSubClass |
0x02 |
Subclass code is 0x02 |
7 |
bInterfaceProtocol |
0x02 |
Protocol code is 0x02 |
8 |
iInterface |
0 |
Index of string descriptor to interface |
bAlternateSetting is set to 0 (i.e., no alternate interfaces). The number of endpoints used by this interface is 1 (excluding endpoint 0), and this is the endpoint used for the mouse to send its data. The device class code is 0x03 ( bInterfaceClass =0x03). This is an HID (human interface device) type class. The interface subclass is set to 0x02. The device protocol is 0x02 (mouse). There is no string to describe this interface ( iInterface =0).
An HID descriptor always follows an interface descriptor when the interface belongs to the HID class. Table 8.11 shows the format of the HID descriptor.
bLength is the length of the device descriptor.
bDescriptorType is the descriptor type.
bcdHID is the HID class specification.
bCountryCode specifies any special local changes.
bNumDescriptors specifies if there are any additional descriptors associated with this class.
bDescriptorType is the type of the additional descriptor specified in bNumDescriptors .
wDescriptorLength is the length of the additional descriptor in bytes.
Table 8.11: HID descriptor
Offset |
Field |
Size |
Description |
0 |
bLength |
1 |
Descriptor size in bytes |
1 |
bDescriptorType |
1 |
HID (0x21) |
2 |
bcdHID |
2 |
HID class |
4 |
bCountryCode |
1 |
Special country dependent code |
5 |
bNumDescriptors |
1 |
Number of additional descriptors |
6 |
bDescriptorType |
1 |
Type of additional descriptor |
7 |
wDescriptorLength |
2 |
Length of additional descriptor |
Table 8.12 shows an example HID descriptor for a mouse device. The length of the descriptor is 9 bytes ( bLength =9), and the descriptor type is 0x21 ( bDescriptorType =0x21). The HID class is set to 1.1 ( bcdHID =0x0110). The country code is set to zero ( bCountryCode =0), specifying that there is no special localization with this device. The number of descriptors is set to 1 bNumDescriptors =1) which specifies that there is one additional descriptor associated with this class. The type of the additional descriptor is REPORT ( bDescriptorType =REPORT), and its length is 52 bytes ( wDescriptorLength =52).
Читать дальше