首页 > 编程知识 正文

usb接口定义详解,usb六种接口

时间:2023-05-04 14:54:26 阅读:44362 作者:1693

目录

1.USB描述符

2 .接口描述符的配置

3.STM32配置描述符集合代码(必须按顺序) ) ) )。

4 .接口描述符配置详细信息

1.USB描述符USB描述符为设备描述符,http://www.Sina.com/http://www.Sina.com /,3http://www.Sina.com标准

3358www.Sina.com/前提到了配置描述符和http://www.Sina.com/http://www.Sina.com /,这次是3358 www.Sina 主机主要从标准配置描述符、接口描述符、端点描述符、HID描述符、报告描述符和物理描述符中获取分别返回给主机的配置描述符集。 接口描述符为9字节,配置如下:

33558 www.Sina.com/* usbconfigurationdescriptor */const uint8_ tcustomhid _ config descriptor [ custom hid _ siz _ ] USB _ configuration _ descriptor _ type,/* bdescriptortype : configuration */custom hid _ siz _ config _ desc,/* wtotallengthlow 3360 bytes returned */0x 00/* wtotallengthhhigh : bytes returned */0x 01,/* bnum接口33601接口/* bconfigurationvalue 3360 conn value/* I configuration : indexofstringdescriptordescribingtheconfiguration */0xc 0,/* BM attributes 3360 bus powered */* bus powered :7 th bit,Self Powered: 6th bit,远程唤醒up : 5th bit, 保留:4.0bits */0x 96、/* max power 300 ma : thiscurrentisusedfordetectingvbus *//接口描述符//* * * * * * *0x09,/* blength : interfacedescriptorsize */USB _ interface _ descriptor _ type,/*bdescriptortype3360iipe

/* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x02, /* bNumEndpoints 此接口有两个端点 */ 0x03, /* bInterfaceClass: HID */ 0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */ 0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */ 0, /* iInterface: Index of string descriptor */ //// HID描述符(后续讲解)///******************** Descriptor of Custom HID HID ********************/ /* 18 */ 0x09, /* bLength: HID Descriptor size */ HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */ 0x10, /* bcdHID: HID Class Spec release number */ 0x01, 0x00, /* bCountryCode: Hardware target country 国家代码 */ 0x01, /* bNumDescriptors: Number of HID class descriptors to follow 类别描述符数目(至少有一个报表描述符)*/ 0x22, /* bDescriptorType 报告描述符 */ CUSTOMHID_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor 报告描述符大小 */ 0x00,/* 标志类别描述符说明结束 */ //// 端点1描述符///******************** Descriptor of Custom HID endpoints ******************/ /* 27 */ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */ 0x82, /* bEndpointAddress: Endpoint Address (IN) */ // bit 3...0 : the endpoint number // bit 6...4 : reserved // bit 7 : 0(OUT), 1(IN) 0x03, /* bmAttributes: Interrupt endpoint */ 0x40, /* wMaxPacketSize: 64 Bytes max */ 0x00, 0x02, /* bInterval: Polling Interval (2 ms) */ /* 34 *///// 端点2描述符// 0x07,/* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE,/* bDescriptorType: *//*Endpoint descriptor type */ 0x01,/* bEndpointAddress: *//*Endpoint Address (OUT) */ 0x03,/* bmAttributes: Interrupt endpoint */ 0x40,/* wMaxPacketSize: 64 Bytes max */ 0x00, 0x02,/* bInterval: Polling Interval (2 ms) */ /* 41 */}; /* CustomHID_ConfigDescriptor */ 4.接口描述符组成详解

1.bLength

配置描述符的长度。

2.bDescriptorType

描述符类型,接口描述符为0x04。描述符的结构开头是一样的,都是先说描述符长度,然后说类型,每种描述符的类型是不一样的,如下表格,可速查。

3.bInterfaceNumber

接口编号。如果一个配置有多个接口的话,那么每个接口的编号都有一个独立的编号,编号从0开始递增。这里可以设置为0。

4.bAlternateSetting

备用接口编号,一般很少用,设置为0。

5.bNumEndpoints

该接口使用的端点个数,前面讲过一个接口就是一种功能,每个接口需要用户为其分配端点来实现对应的功能,注意一点,这个端点个数不包括端点0。

6.bInterfaceClass、bInterfaceSubClass、bInterfaceProtocol

当设备描述符设备类型bDeviceClass为0时,也就是指示用接口描述符来标识类别,此时用接口类、接口子类、接口协议来说明USB设备此功能所属的类别。如下图显示设备和接口的各种类别,这个类别给设备描述符用还是给接口描述符用要看Descriptor Usage标识(如图中所示)。我们如果单纯用作数据传输的话,直接写FFh就好,代表着用户自定义。USB类信息更详细内容可进入https://www.usb.org/defined-class-codes查看。

7.iInterface

描述此接口的字串索引值,没有的话一般都是0。

 

1.版权归本作者(一个早起的程序员)所有;

2.未经原作者允许不得转载本文内容,否则将视为侵权;

3.转载或者引用本文内容请注明来源及原作者;

4.对于不遵守此声明或者其他违法使用本文内容者,本人依法保留追究权等。

下面是我的个人微信公众号,关注【一个早起的程序员】精彩文章不断。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。