USB設備描述符


 

/* USB Standard Device Descriptor */
const u8 Virtual_Com_Port_DeviceDescriptor[] =
  {
    0x12,   /* bLength */  //USB設備描述符的總長度固定為18個字節,因此為12H
    USB_DEVICE_DESCRIPTOR_TYPE,     /* bDescriptorType */  //USB設備描述符的類型值,固定為01H
    0x00,                               //USB遵循的規范版本號,USB2.0; 0xXXYZ,XX為主版本號,Y為次版本號,Z為子次版本號
    0x02,   /* bcdUSB = 2.00 */
    0x02,   /* bDeviceClass: CDC */       //USB所遵循的標准設備類。0表示設備的接口相互獨立,分別屬於不同的設備類;
                                       //1~FEH之間表示USB協議中定義的某個類。03H表示HID類,02H表示CDC類。
                                       //FFH表示供應商自定義的設備類
    0x00,   /* bDeviceSubClass */       //USB設備所屬的標准設備子類。對於顯示設備類(04H),包含3個子類,
                                       //子類代碼01H表示CRT顯示器,02H表示平面顯示器,03H表示3D顯示器。
                                       //bDeviceClass為0時,該值為0;該值為FFH時,表示供應商自定義的設備子類
    0x00,   /* bDeviceProtocol */       //采用的設備類協議。該值為FFH時表示設備類協議由供應商自定義
    0x40,   /* bMaxPacketSize0 */       //端點0所支持最大數據包長度(字節),低速為8,全速為8,16,32或64,高速為64
    0x83,                               //設備供應商id,使主機為其加載合適驅動
    0x04,   /* idVendor = 0x0483 */
    0x40,                               //產品id,用於區分不同的usb設備
    0x57,   /* idProduct = 0x7540 */
    0x00,                               //設備版本號,幫助主機加載合適驅動
    0x01,   /* bcdDevice = 1.00 */
    1,              /* Index of string descriptor describing manufacturer */  //若沒有,可為0
    2,              /* Index of string descriptor describing product */          //若沒有,可為0
    3,              /* Index of string descriptor describing the device's serial number */       //若沒有,可為0
    0x01    /* bNumConfigurations */    //USB設備所支持的配置數
  };

 

 

 

 

const u8 Virtual_Com_Port_ConfigDescriptor[] =
  {
    /*Configuation Descriptor*/
    0x09,   /* bLength: Configuation Descriptor size */           //配置描述符的長度,固定為9字節,09H
    USB_CONFIGURATION_DESCRIPTOR_TYPE,      /* bDescriptorType: Configuration */        //配置描述符類型,固定位02H
    VIRTUAL_COM_PORT_SIZ_CONFIG_DESC,       /* wTotalLength:no of returned bytes */        //配置信息總長度,配置描述符、接口描述符、端點描述符長度總和
    0x00,
    0x02,   /* bNumInterfaces: 2 interface */            //所支持的接口數, 最小值為1
    0x01,   /* bConfigurationValue: Configuration value */     //USB設備的配置值
    0x00,   /* iConfiguration: Index of string descriptor describing the configuration */ //字符串描述符索引,若沒有,可為0
    0xC0,   /* bmAttributes: self powered */   //配置特性,可按位尋址,第六位置1表示用總線電源,第五位置1表示支持遠程喚醒,其他字段保留
                                               //一般0~4位置0,第7位置1
    0x00,   /* MaxPower 0 mA */                   //USB設備運行時所支持的最大電流,2mA為單位
    /*Interface Descriptor*/
    0x09,   /* bLength: Interface Descriptor size */         //接口描述符長度,固定為9字節,09H
    USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: Interface */  //接口描述符的類型值,固定位04H
    /* Interface descriptor type */
    0x00,   /* bInterfaceNumber: Number of Interface */          //USB接口的接口號
    0x00,   /* bAlternateSetting: Alternate setting */          //USB接口的可替換設置值
    0x01,   /* bNumEndpoints: One endpoints used */              //USB接口所使用的接口總數
    0x02,   /* bInterfaceClass: Communication Interface Class */    //USB接口所屬的設備類,1~FEH表示某個設備類;FFH表示供應商自定義
    0x02,   /* bInterfaceSubClass: Abstract Control Model */
    0x01,   /* bInterfaceProtocol: Common AT commands */       //接口所采用的設備類協議
    0x00,   /* iInterface: */                                   //USB接口字符串描述符的索引值
    /*Header Functional Descriptor*/
    0x05,   /* bLength: Endpoint Descriptor size */
    0x24,   /* bDescriptorType: CS_INTERFACE */
    0x00,   /* bDescriptorSubtype: Header Func Desc */
    0x10,   /* bcdCDC: spec release number */
    0x01,
    /*Call Managment Functional Descriptor*/
    0x05,   /* bFunctionLength */
    0x24,   /* bDescriptorType: CS_INTERFACE */
    0x01,   /* bDescriptorSubtype: Call Management Func Desc */
    0x00,   /* bmCapabilities: D0+D1 */
    0x01,   /* bDataInterface: 1 */
    /*ACM Functional Descriptor*/
    0x04,   /* bFunctionLength */
    0x24,   /* bDescriptorType: CS_INTERFACE */
    0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
    0x02,   /* bmCapabilities */
    /*Union Functional Descriptor*/
    0x05,   /* bFunctionLength */
    0x24,   /* bDescriptorType: CS_INTERFACE */
    0x06,   /* bDescriptorSubtype: Union func desc */
    0x00,   /* bMasterInterface: Communication class interface */
    0x01,   /* bSlaveInterface0: Data Class Interface */
    /*Endpoint 2 Descriptor*/                               //端點描述符長度固定為7字節,07H
    0x07,   /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
    0x82,   /* bEndpointAddress: (IN2) */
    0x03,   /* bmAttributes: Interrupt */
    VIRTUAL_COM_PORT_INT_SIZE,      /* wMaxPacketSize: */
    0x00,
    0xFF,   /* bInterval: */
    /*Data class interface descriptor*/
    0x09,   /* bLength: Endpoint Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: */
    0x01,   /* bInterfaceNumber: Number of Interface */
    0x00,   /* bAlternateSetting: Alternate setting */
    0x02,   /* bNumEndpoints: Two endpoints used */
    0x0A,   /* bInterfaceClass: CDC */
    0x00,   /* bInterfaceSubClass: */
    0x00,   /* bInterfaceProtocol: */
    0x00,   /* iInterface: */
    /*Endpoint 3 Descriptor*/
    0x07,   /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
    0x03,   /* bEndpointAddress: (OUT3) */
    0x02,   /* bmAttributes: Bulk */
    VIRTUAL_COM_PORT_DATA_SIZE,             /* wMaxPacketSize: */
    0x00,
    0x00,   /* bInterval: ignore for Bulk transfer */
    /*Endpoint 1 Descriptor*/
    0x07,   /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
    0x81,   /* bEndpointAddress: (IN1) */
    0x02,   /* bmAttributes: Bulk */
    VIRTUAL_COM_PORT_DATA_SIZE,             /* wMaxPacketSize: */
    0x00,
    0x00    /* bInterval */
  };

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM