The basic concept of USB device driver development

Links: https://blog.csdn.net/zqixiao_09/article/details/50984074

A, USB device consists of three functional modules, USB bus interface, USB devices and the logic function unit:

  • USB Interface: USB device serial interface engine SIE
  • USB logical device: USB system software is seen as a collection of endpoints
  • Functional units: client software is seen as a set of interfaces

Second, from an architectural standpoint the device, the USB device by a number of configuration, interface and endpoint , namely a USB device corresponds to a device descriptor, which may contain one or more configurations, each configuration may contain one or more interfaces each interface may contain a number of endpoints. And wherein the configuration of the interface is a USB abstract device functions, and actual data transfer is completed by the endpoint must specify an interface to configure and use thereof in the USB enumeration ;

Three, the USB device will be described using a variety of descriptors which device architecture, such as a device descriptor, a configuration descriptor, interface descriptor, end descriptor, string descriptor, they are usually stored in the USB device in the fixed program;

A device descriptor: represents a USB device, composed of one or more configuration, it is for explaining the overall apparatus and information indicating the number contained in the configuration, a USB device can have a device descriptor ;

. 1  struct the usb_device_descriptor
 2  {
 . 3      _ _u8 bLength; // descriptor length 
. 4      _ _u8 bDescriptorType; // descriptor type number 
. 5   
. 6      _ _le16 bcdUSB; // the USB version 
. 7      _ _u8 the bDeviceClass; // device class code USB allocated 
. 8      _ _u8 bDeviceSubClass; // subclass code USB allocated 
. 9      _ _u8 bDeviceProtocol; // protocol code USB allocated 
10      _ _u8 bMaxPacketSize0; // Endpoint0 maximum packet size 
. 11      _ _le16 the idVendor; // Manufacturer ID 
12     _Le16 idProduct _; // Number 
13 is      _ _le16 bcdDevice; // device serial number 
14      _ _u8 iManufacturer; // description index vendor string 
15      _ _u8 iProduct,; // description index product string 
16      _ _u8 iSerialNumber; / / indexing apparatus described serial number string 
. 17      _ _u8 bNumConfigurations; // number of possible configuration 
18 is } _attribute_ _ _ ((packed the));

2 configuration descriptor: high-power mode of the USB device and the low-power mode may correspond to a configuration that the USB device for explaining the characteristics of each configuration, such as the number contained in the interface;

. 1  struct usb_config_descriptor
 2  {
 . 3      _ _u8 bLength; // descriptor length 
. 4      _ _u8 bDescriptorType; // descriptor type number 
. 5      
. 6      _ _le16 wTotalLength; // size of the configuration of all data returned 
. 7      _ _u8 bNumInterfaces; // Configure the number of interfaces supported 
. 8      _ _u8 bConfigurationValue; // a Set_Configuration desired command parameter value 
. 9      _ _u8 iConfiguration; // string describing the configuration of the index value of 
10      _ _u8 the bmAttributes; // supply mode selection 
. 11      _ _u8 bMaxPower; //Device maximum current extracted from the bus 
12 is } _attribute_ _ _ ((packed The));

3 interface descriptors: for CD-ROM, a mass storage interface which is used when a file transfer, an audio interface which is used when the user plays CD. Interface is a collection of endpoints, may comprise one or more alternative settings, the user may be in a configuration state change in the number and characteristics of the USB interface contains the current time, it is characteristic of each user interface description USB device, such as device belongs class and its subclasses;

. 1  struct usb_interface_descriptor
 2  {
 . 3      _ _u8 bLength;            // descriptor length 
. 4      _ _u8 bDescriptorType; // descriptor type 
. 5      
. 6      _ _u8 bInterfaceNumber;    // number of the interface 
. 7      _ _u8 bAlternateSetting; // spare interface descriptor No. 
8      _u8 bNumEndpoints _;       // end points of the interface is not inclusive 0 
. 9      _ _u8 bInterfaceClass;     // Interface type 
10      _ _u8 bInterfaceSubClass; // interfaces subtype 
. 11      _ _u8 bInterfaceProtocol; //Followed interface protocol 
12 is      _ _u8 iInterface; // description string index value of the interface 
13 is } _attribute_ _ _ ((packed The));

4 endpoint descriptor; the endpoints are the actual physical unit in the USB device, i.e., USB data transfer is performed between the USB device and each endpoint host. Each endpoint has a unique number of endpoints, each endpoint of the data transmission direction is determined generally supported, i.e., the input IN and the output OUT, the use of the device address, and endpoint number can specify a transmission direction endpoint. 0 special endpoint, it has a data input IN and output OUT of two physical units of data, and the control can only support transmission of all USB devices must contain a number of endpoint 0, is used as the default control pipe, USB system software is the use of the piping configuration and USB logic device in communication; 0 endpoint must not only be used in the later configuration. USB device endpoints may contain a plurality of non-zero, for low-speed devices contain up to two additional end points, for full-speed / high-speed device contains up to 15 additional end points;

. 1  struct usb_endpoint_descriptor
 2  {
 . 3      _ _u8 bLength; // descriptor length 
. 4      _ _u8 bDescriptorType; // descriptor type 
. 5      _ _u8 bEndpointAddress; // Endpoint Address: 0 ~ 3 endpoint number is, bit 7 is the direction (0 -OUT, the iN-. 1) 
. 6      _ _u8 the bmAttributes; // endpoint attribute: bit [0: 1] indicates the control value of 00, 01 denotes synchronization, expressed as quantities 02, 03 as an interrupt 
. 7      _ _le16 the wMaxPacketSize; / // / endpoint according to the maximum packet size sent or received 
. 8      _ _u8 bInterval; // time interval polling data transmitting endpoint
 9                             // for bulk transfer endpoint, and the endpoint of the transmission control, this field is ignored
 10                          // for endpoint isochronous transfer, this field must be 1 
. 11     _ _u8 bRefresh;
12     _ _u8 bSynchAddress;
13 } _ _attribute_ _ ((packed));

5 String Descriptor: description of some specific information, such as the manufacturer's name, serial number, its content has been given in the form of Unicode, that can be read by the client software, string descriptor is optional;

. 1  struct usb_string_descriptor
 2  {
 . 3      _ _u8 bLength; // descriptor length 
. 4      _ _u8 bDescriptorType; // descriptor type 
. 5      
. 6      _ _le16 wData [ . 1 ];
 . 7 } _ _ _attribute_ ((packed The));

four,

Fives,

Guess you like

Origin www.cnblogs.com/bo1990/p/11424342.html