USB descriptor example

Source: Internet
Author: User
Device descriptor

The device descriptor provides general information about the USB device. This includes information about the full function of the device and device settings. a USB device can have only one device descriptor. All USB devices have default control channels. The maximum package length of the default control channel is specified in the device descriptor.

Rom usb_device_descriptor device_dsc = {  0x12 , //  Byte blength descriptor length   0x01 , //  Byte bdescriptortype descriptor type is fixed to 0x01 A byte   Zero X 0200 , //  Word bcdusb Specification Version (using BCD code)   0x00 ,//  Byte bdeviceclass, ClassCodeIndicates the standard equipment Class 0x01 ~ 0xfe is the standard  //  Slave class, 0xff is the vendor-defined type  //  0x00 is not defined in the device descriptor, for example, when hid is 0  //  Each interface of the device is independent of each other and will be further defined in the interface Descriptor   0x00 , //  Byte bdevicesubclass defines the device category in more detail   0x00 , //  Byte bdeviceprotocl protocol code. The value 0 indicates no device protocol is used.  8 , //  The maximum packet length supported by byte bmaxpacketsize0 endpoint 0,  0x04d8 , //  Supplier ID of word idvendor USB device  0x003f , //  Word idproduct USB product ID  Zero X 0002 , //  BCD code indicates the version number of the USB device, which is specified by the supplier.  0x01 , // Word bcddevice supplier string descriptor index value  0x02 , //  Byte imanufacturer product string descriptor index value  0x00 , //  Byte iproduct USB set serial number string descriptor index value, 0 indicates no  0x01       //  Byte iserialnumber number of configurations supported by the USB device  }; 
Configuration Descriptor

The configuration descriptor provides the device configuration information. The description table contains a bconfigurationvalue field, which is used as a parameter to set the required configuration backup during the setconfiguration () request. This descriptor provides the number of interfaces in this configuration. Each interface may be operated independently.

Rom byte configdescriptor1 [] ={  0x09 , //  Byte blength configuration descriptor length, fixed to 0x09 bytes  0x02 , //  Byte bdescriptortype the USB descriptor type is fixed to 02 h. The above 0x01 is 0x12.  0x29 , 0x00 , //  Total length of word wtotallength configuration information, including configuration, interface, and Endpoint Descriptor   1 , //  Byte bnuminterface the number of interfaces supported by this configuration  1 , //  Byte bconfigurationvale configuration value the parameter value required by the set_configuration command   0 , //  Byte iconfiguration string descriptor index value, 0 indicates no string is configured   0xe0 , //  Byte bmattribute Configuration Attribute, power supply mode selection, see usb_device.h sixth position 1  //                //  Indicates that the bus power is used, and the fifth position 1 indicates that the Remote Wake-up function is supported. The others are reserved.  // 0 ~ 4 position 0, 7 position 1, set to 11100000b  50 , //  The maximum bus current required by byte maxpower is the maximum current Unit that the device extracts from the bus.  //  2mA, up to 500mA, set to 250  
Interface Descriptor

The interface descriptor provides an interface information in a configuration. If a configuration supports multiple interfaces, the endpoint descriptor will be returned after the interface descriptor. The interface descriptor is always returned as part of the configuration descriptor. Setinterface () and getinterface () are used to select and return the selected interface settings. The number of endpoints of an interface descriptor does not include the number of endpoints 0.

  0x09 , //  Byte blength device descriptor byte size   0x04 , // Byte bdescriptortype descriptor type number    0 , //  Byte binterfacenunber interface number  0 , //  Byte balternatesetting backup interface descriptor number  2 , //  Byte bnumendpoints the total number of endpoints used by this interface, excluding endpoint 0  0x03 , //  Byte binterfaceclass interface type, which belongs to the device class. Here it is the hid class   0 , //  Byte binterfacesubclass interface sub-type if the device class is 1-Feh  //  Step to represent the device subclass  0 , //  Protocol used by the byte binterfaceprotocol Interface  0 , //  Byte iinterface describes the string index value of this interface 
Hid Descriptor

Apart from the standard USB descriptor, The HID device must also support the hid descriptor, report descriptor, and physical Descriptor (optional ). Hid descriptors are used to identify additional descriptors contained in USB devices, such as report descriptors.

  0x09 ,//  Blength descriptor length sizeof (usb_hid_dsc) + 3,   0x21 , //  Bdescriptortype descriptor type: HID = 0x21   0x11 , 0x01 , //  Bcdhid standard version number (BCD code), which is 1.11   0x00 , //  Bcountrycode country code 00 indicates that the device is not localized   1 , // Number of other class descriptors supported by bnumdescriptor see usbcfg. h   0x22 , //  Bdescriptortype report descriptor type   28 , 0x00 , //  Wdescriptorlength the total length of the report descriptor sizeof (hid_rpt01 ), 
Endpoint Descriptor

Each endpoint used by each interface has its own descriptor, which is used by the host to determine the bandwidth requirements of each endpoint. The descriptor of each endpoint is always returned as part of the device setting description, and the control endpoint 0 has no descriptor.

 /*  ********************  */  0x07 ,//  Byte blength device descriptor length byte size * sizeof (usb_ep_dsc)  0x05 , //  Byte bdescriptortype descriptor type number  0x81 , //  Byte bendpointaddress: the endpoint number and transmission direction. The value 7th indicates the data transmission of the endpoint.  //  Direction, 0 indicates out data transmission, 1 indicates in data transmission, 0th ~ 3 indicates the port number 001b.  //  Indicates endpoint 1 ,.  0x03 , // The endpoint feature. B Indicates control transmission 01 synchronous transmission, 10B transmission, and 11B interruption.  0x40 , 0x00 , //  Word wmaxpacketsize the maximum size of the Package received and sent by the endpoint  0x01 , //  Byte binterval host queries the interval MS of the endpoint         /*  ********************  */  0x07 , //  Byte blength  0x05 , //  Endpoint Descriptor   0x01 , //  Endpointaddress 0 indicates out Input  0x03 , //  Attributes  0x40 , 0x00     //  Size   0x01          //  Interval }; 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.