USB各描述符的定义,在C语言中,实际上用简单的数组就可以表示,如下:
uint8_t XXX_DeviceDescriptor[JOYSTICK_SIZ_DEVICE_DESC] =
{
0x12, /* bLength: Size of this descriptor in bytes*/
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
0x00, /*bcdUSB : USB Specification Release Number*/
0x02,
0x00, /*bDeviceClass: zero, each interface within a configuration specifies its own
class information and the various interfaces operate independently*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
0x40, /*bMaxPacketSize 64:Maximum packet size for endpoint zero*/
0xXX, /* idVendor */
0xXX,
0x05, /*idProduct*/
0x00,
0x00, /*bcdDevice rel. 2.00:Device release number*/
0x02,
IndexStringDescriptor_Manufacturer, /*Index of string descriptor describing manufacturer */
IndexStringDescriptor_Product, /*Index of string descriptor describing product*/
IndexStringDescriptor_DeviceSerialNumber, /*Index of string descriptor describing the device's serial number */
0x01 /*bNumConfigurations: Number of possible configurations*/
};
uint8_t XXX_ConfigurationDescriptor[JOYSTICK_SIZ_CONFIG_DESC] =
{
0x09, /* bLength: Configuration Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: CONFIGURATION Descriptor Type */
JOYSTICK_SIZ_CONFIG_DESC, /* wTotalLength: Bytes returned. : Total length of data returned for this*/
0x00, // configuration. Includes the combined length of all descriptors (configuration, interface,
// endpoint, and class- or vendor-specific) returned for this configuration.
0x01, /*bNumInterfaces: 1 interface: Number of interfaces supported by this configuration*/
0x01, /*bConfigurationValue: Configuration value:Value to use as an argument to the
SetConfiguration() request to select this configuration*/
0x00, /*iConfiguration: Index of string descriptor describing the configuration*/
0xE0, /*bmAttributes: Self powered
D6: Self-powered.
D5: Remote Wakeup.*/
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
/************** Descriptor of Joystick Mouse interface ****************/
/* 09 */
0x09, /*bLength: Size of this descriptor in bytes*/
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
0x00, /*bInterfaceNumber: Number of this interface. Zero-based
value identifying the index in the array of concurrent interfaces supported by this configuration*/
0x00, /*bAlternateSetting: Value used to select this alternate setting
for the interface identified in the prior field*/
0x01, /*bNumEndpoints: Number of endpoints used by this interface (excluding endpoint zero). If this
value is zero, this interface only uses the Default Control Pipe*/
0x03, /*bInterfaceClass: HID. : Class code (assigned by the USB-IF).*/
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot.:Subclass code (assigned by the USB-IF).*/
0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse.: Protocol code (assigned by the USB)*/
IndexStringDescriptor_Interface, /*iInterface: Index of string descriptor describing this interface*/
/******************** Descriptor of Joystick Mouse HID ********************/
/* 18 */
0x09, /*bLength: HID Descriptor size*/
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
0x00, /*bcdHID: HID Class Spec release number*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
0x22, /*bDescriptorType: type of next descriptor, 0x22 is for report descriptor.*/
JOYSTICK_SIZ_REPORT_DESC,/*wItemLength: Total length of Report descriptor*/
0x00,
/******************** Descriptor of Joystick Mouse endpoint ********************/
/* 27 */
0x07, /*bLength: Size of this descriptor in bytes*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /* ENDPOINT Descriptor Type*/
0x81, /*bEndpointAddress: Endpoint Address (IN).
Bit 3...0: The endpoint number
Bit 6...4: Reserved, reset to zero
Bit 7: Direction, ignored for control endpoints.
0 = OUT endpoint
1 = IN endpoint*/
0x03, /*bmAttributes: Interrupt endpoint.
This field describes the endpoint’s attributes when it is configured using the bConfigurationValue.
Bits 1..0: Transfer Type
00 = Control
01 = Isochronous
10 = Bulk
11 = Interrupt ---set
If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are
defined as follows:...*/
0x04, /*wMaxPacketSize: 4 Byte max. :Maximum packet size this endpoint is capable of*/
0x00, // sending or receiving when this configuration is selected.
0x20, /*bInterval: Polling Interval (32 ms). :Interval for polling endpoint for data transfers*/
/* 34 */
};