USB复合设备
- 格式:doc
- 大小:66.50 KB
- 文档页数:6
USBCompoundDevice,USB复合设备;USBCompositeDevice,。
科普下USB复合设备和USB组合设备的区别。
关键字Communication Device Class,简称CDCUSB Compound Device,USB复合设备USB Composite Device,USB组合设备摘要Compound Device内嵌Hub和多个Function,每个Function都相当于⼀个独⽴的USB外设,有⾃⼰的PID/VID/DID。
Composite Device内只有⼀个Function,只有⼀套PID/VID/DID,通过将不同的interface定义为不同的类来实现多个功能的组合。
正⽂Compound Device内嵌Hub和多个Function,每个Function都相当于⼀个独⽴的USB外设,有⾃⼰的PID/VID/DID。
Composite Device内只有⼀个Function,只有⼀套PID/VID/DID,通过将不同的interface定义为不同的类来实现多个功能的组合。
很多⼈认为⼀个USB接⼝上实现多个设备,就是指复合设备,其实,这是不确切的,虽然USB Compound Device和USB Composite Device都会被百度翻译为USB复合设备。
在⼀个USB接⼝上实现多个设备有2中⽅法,⼀种是Compound Device,就是复合设备;另⼀种是Composite Device,就是组合设备。
在USB2.0的标准协议中,定义如下:When multiple functions are combined with a hub in a single package, they are referred to as a compound device.A device that has multiple interfaces controlled independently of each other is referred to as acomposite device.所以,复合设备其实就是⼏个设备通过⼀个USB Hub形成的单⼀设备;组合设备也就是具有多个接⼝的设备,每个接⼝代表⼀个独⽴的设备。
1SPRACB5–September 2017Submit Documentation FeedbackCopyright ©2017,Texas Instruments IncorporatedUSB Composite Gadget Using CONFIG-FS on DRA7xx DevicesApplication ReportSPRACB5–September 2017USB Composite Gadget Using CONFIG-FS on DRA7xxDevicesRavi BABSTRACTThis application note explains how to create a USB composite gadget,network control model (NCM)and abstract control model (ACM)from the user space using Linux ®CONFIG-FS on the DRA7xx platform.Contents1Introduction ...................................................................................................................22USB Composite Gadget Using CONFIG-FS .............................................................................33Creating Composite Gadget From User Space .. (44)References ...................................................................................................................8List of Figures1Block Diagram of USB Composite Gadget ...............................................................................32Selection of CONFIGFS Through menuconfig ...........................................................................43Select USB Configuration Through menuconfig .........................................................................44Composite Gadget Configuration Items as Files and Directories .....................................................55VID,PID,and Manufacturer String Configuration .......................................................................66Kernel Logs Show Enumeration of USB Composite Gadget by Host ................................................67Ping From EVM and Host PC ..............................................................................................78Enable USB0Interface (79)Running iperf From Host PC (8)List of Tables1Kernal and U-Boot Commits (2)TrademarksUbuntu is a registered trademark of Canonical Ltd.Linux is a registered trademark of Linus Torvalds.All other trademarks are the property of their respective owners.Introduction 2SPRACB5–September 2017Submit Documentation FeedbackCopyright ©2017,Texas Instruments IncorporatedUSB Composite Gadget Using CONFIG-FS on DRA7xx Devices1IntroductionThe scope of this document is to provide guidelines to configure the USB composite gadget using CONFIG-FS.1.1Software RequirementsThis application note is based on the Processor SDK Linux Automotive (PSDKLA)3.02,and uses the U-Boot version 2016.05as a reference.This application note requires that users:•Install Processor SDK Linux Automotive 3.02•Can build U-Boot and kernelTable 1lists the kernel and U-Boot commits corresponding to the 3.02SDK.Table 1.Kernal and U-Boot CommitsRepository Commit ID HeadlineKernel 89944627d53a Late attach:Fix for accessing second level page tableU-Boot850ffc07orbadefconfigs:dra7xx_hs_evm:Move OPTEE load address to avoid overlapsFor more information,see the release download links and software developer's guide .1.2Hardware RequirementsThe Dra75x/J6EVM Rev-H evaluation board is used for reference.1.3Build Instructions1.Download the PSDKLA-3.02release2.Follow the instructions in the Processor SDK Linux Automotive Software Developer's Guide to build the U-Boot,kernel,DTB,and modules.... USB Composite Gadget Using CONFIG-FS3SPRACB5–September 2017Submit Documentation FeedbackCopyright ©2017,Texas Instruments IncorporatedUSB Composite Gadget Using CONFIG-FS on DRA7xx Devices2USB Composite Gadget Using CONFIG-FSA USB composite gadget is a USB device framework which combines more than one USB-class device function.Figure 1shows the USB composite gadget,which consists of a single control pipe (endpoint-0)and a set of configurations.Each configuration contains a set of interfaces for a USB-specific class (such as serial or mass storage,or CDC and Ethernet).Each interface contains a set of endpoints (IN-receive or OUT-transmit)on which data transfers to and from,between the device function and USB host.For example,the composite gadget includes a mass storage device (for any storage media),CDC and RNDIS network interfaces,and so on.Figure 1.Block Diagram of USB Composite GadgetThe USB composite gadget framework in Linux kernel lets users combine one or more gadget functions,and exposes as a single,composite,gadget function to the USB host.The Linux kernel supports creation of the USB composite gadget in the user space through CONFIG_FS support,where the standard kernel gadget functions are exposed through CONFIGFS as config items and groups,and both are represented as directories.Both items and groups can have attributes which are represented as directories or files.The user can create and remove directories,which can be read-only or read-write depending on what they represent.For more information,visit gadget configfs and configfs .Creating Composite Gadget From User Space 4SPRACB5–September 2017Submit Documentation FeedbackCopyright ©2017,Texas Instruments IncorporatedUSB Composite Gadget Using CONFIG-FS on DRA7xx Devices3Creating Composite Gadget From User Space 3.1Building the KernelThe Linux kernel supports CONFIGFS,which lets the user create the composite gadget from the user space.1.From menuconfig of the Linux kernel,select CONFIG_CONFIGFS_FS.CONFIG_CONFIGFS_FS is selected through Menuconfig →FileSystem →Psuedo File System →{M}Userspace-driven configuration filesystem (see Figure 2).Figure 2.Selection of CONFIGFS Through menuconfig2.Select the required gadget module,in this example the NCM and serial ACM gadget modules are selected,as shown through menuconfig (see Figure 3).Figure 3.Select USB Configuration Through menuconfig3.Build the kernel,DTB,and all gadget modules.You can also use the default PSDKLA-3.02prebuilt binaries.For more information,see the PSDKLA user’s guide for building the kernel,DTB,and gadget modules . Creating Composite Gadget From User Space5SPRACB5–September 2017Submit Documentation FeedbackCopyright ©2017,Texas Instruments IncorporatedUSB Composite Gadget Using CONFIG-FS on DRA7xx Devices3.2USB Composite Gadget Through CONFIGFSThe following example shows how to create the USB composite gadget from the user space,which includes two USB device functions:•USB NCM gadget •USB ACM gadget3.2.1Creating NCM and ACM Composite GadgetsTo set up NCM and ACM composite gadgets:1.Connect the USB0(super-speed)port of the EVM to the Ubuntu ®PC through the USB device cable.2.Build the kernel,as explained in Section3.1.3.Copy the kernel,DTB,and install modules to the SD card.You can also use PSDKLA-3.02prebuilt binaries.Next,boot the kernel to root prompt,and follow these steps:1.Insert gadget modules.#modprobe libcomposite2.Mount the configfs file system,if not mounted already.#mount -t configfs none /sys/kernel/config3.Switch to device mode.By default,in the PSDKLA-3.02release the USB0port is configured in DRD mode,therefore configure the USB0port in device mode.#mount -t debugfs debugfs /mnt#echo "device">/mnt/b/mode4.Create the composite gadget.#cd /sys/kernel/config/#cd usb_gadget/#mkdir j6g #cd j6gFigure 4shows the files and directories that are automatically created.Figure posite Gadget Configuration Items as Files and Directories5.Update the VID and PID and strings (see Figure 5).#echo "0xA55A">idVendor #echo "0x0111">idProduct #mkdir strings/0x409#cd strings/#cd 0x409/Creating Composite Gadget From User Space 6SPRACB5–September 2017Submit Documentation FeedbackCopyright ©2017,Texas Instruments IncorporatedUSB Composite Gadget Using CONFIG-FS on DRA7xx DevicesFigure 5.VID,PID,and Manufacturer String Configuration#echo "0123456789">serialnumber #echo "Xyz Inc.">manufacturer #echo "NCM+ACM gadget">product #cd ../..6.Create the USB device functions (NCM and ACM).cd functions/mkdir acm.gs0mkdir b0cd ..7.Create the configuration and update the strings.cd configs/mkdir c.1cd c.1mkdir strings/0x409cd strings/0x409/echo "ACM+NCM">configuration cd ../../../..8.Create symbolic links.ln -s functions/acm.gs0configs/c.1ln -s functions/b0configs/c.19.Attach the USB0port to UDC.#echo "b">UDCIssue the previously mentioned command,and the DRA7xx EVM (USB composite gadget NCM and ACM)is connected to the Ubuntu host.The host enumerates the USB composite gadget (ACM and NCM),and the USB0interface and serial device /dev/ttyGS0are created,as shown in Figure 6.The /dev/ttyACM0interface is created on the Ubuntu host.Figure 6.Kernel Logs Show Enumeration of USB Composite Gadget by Host Creating Composite Gadget From User Space7SPRACB5–September 2017Submit Documentation FeedbackCopyright ©2017,Texas Instruments IncorporatedUSB Composite Gadget Using CONFIG-FS on DRA7xx Devices3.2.2Verifying NCM Composite GadgetVerify the NCM gadget interface through ping between the EVM and the Ubuntu host.1.From the EVM,bring up the USB0interface.#ifconfig usb0192.168.100.10up2.From the Ubuntu host,bring up the USB0interface.#ifconfig usb0192.168.100.5up3.Ping from both the EVM and the Ubuntu host.Figure 7shows the ping from the EVM.Figure 7.Ping From EVM and Host PC3.2.3Running iperf (IPV6)on NCM InterfaceReboot the EVM and follow the steps in Section 3.2.1to create the USB composite gadget.Do the following to run iperf:1.From the EVM,bring up the interface (see Figure 8).#ifconfig usb0upFigure 8.Enable USB0Interface2.From the EVM,run the iperf udp server.#iperf -s -u -V -bReferences 8SPRACB5–September 2017Submit Documentation FeedbackCopyright ©2017,Texas Instruments IncorporatedUSB Composite Gadget Using CONFIG-FS on DRA7xx Devices3.From the Ubuntu host,run the iperf udp client.1.Disconnect all interfaces in the Ubuntu host PC before running the iperf client.2.Copy the inet6address from the EVM (red box in Figure 8)and issue the iperf client from the host PC.Figure 9.Running iperf From Host PCThe iperf result shows there is 272Mbps with 0.48%data loss.3.2.4Verifying the ACM Serial Gadget InterfaceAfter the steps for creating the USB composite gadget are complete,the NCM and ACM interface is created,as shown in Section 3.2.1.1.From the EVM,do the terminal settings.#stty -F /dev/ttyGS0-icanon2.Run the linux-serial-test application from the EVM.#./linux-serial-test -w 10-a 100-s -e -p /dev/ttyGS0-b 96003.Run the linux-serial-test application from the Ubuntu host.#chmod +x /dev/ttyACM0#sudo ./linux-serial-test -w 10-a 100-s -e -p /dev/ttyGS0-b 9600NOTE:Git clone the linux-serial-test application and compile it for the DRA7xx platform and theUbuntu host.4References•Texas Instruments,DRA7xx Technical Reference Manual •Texas Instruments,PSDKLA 3.02release•Texas Instruments,Processor SDK LINUX Automotive Software Developer’s Guide •GitHub,Git Source Reference for Linux Serial Test Application •Linux,configfs -Userspace-driven kernel object configuration •Linux,Linux USB gadget configured through configfsIMPORTANT NOTICE FOR TI DESIGN INFORMATION AND RESOURCESTexas Instruments Incorporated(‘TI”)technical,application or other design advice,services or information,including,but not limited to, reference designs and materials relating to evaluation modules,(collectively,“TI Resources”)are intended to assist designers who are developing applications that incorporate TI products;by downloading,accessing or using any particular TI Resource in any way,you (individually or,if you are acting on behalf of a company,your company)agree to use it solely for this purpose and subject to the terms of this Notice.TI’s provision of TI Resources does not expand or otherwise alter TI’s applicable published warranties or warranty disclaimers for TI products,and no additional obligations or liabilities arise from TI providing such TI Resources.TI reserves the right to make corrections, enhancements,improvements and other changes to its TI Resources.You understand and agree that you remain responsible for using your independent analysis,evaluation and judgment in designing your applications and that you have full and exclusive responsibility to assure the safety of your applications and compliance of your applications (and of all TI products used in or for your applications)with all applicable regulations,laws and other applicable requirements.You represent that,with respect to your applications,you have all the necessary expertise to create and implement safeguards that(1) anticipate dangerous consequences of failures,(2)monitor failures and their consequences,and(3)lessen the likelihood of failures that might cause harm and take appropriate actions.You agree that prior to using or distributing any applications that include TI products,you will thoroughly test such applications and the functionality of such TI products as used in such applications.TI has not conducted any testing other than that specifically described in the published documentation for a particular TI Resource.You are authorized to use,copy and modify any individual TI Resource only in connection with the development of applications that include the TI product(s)identified in such TI Resource.NO OTHER LICENSE,EXPRESS OR IMPLIED,BY ESTOPPEL OR OTHERWISE TO ANY OTHER TI INTELLECTUAL PROPERTY RIGHT,AND NO LICENSE TO ANY TECHNOLOGY OR INTELLECTUAL PROPERTY RIGHT OF TI OR ANY THIRD PARTY IS GRANTED HEREIN,including but not limited to any patent right,copyright,mask work right,or other intellectual property right relating to any combination,machine,or process in which TI products or services are rmation regarding or referencing third-party products or services does not constitute a license to use such products or services,or a warranty or endorsement e of TI Resources may require a license from a third party under the patents or other intellectual property of the third party,or a license from TI under the patents or other intellectual property of TI.TI RESOURCES ARE PROVIDED“AS IS”AND WITH ALL FAULTS.TI DISCLAIMS ALL OTHER WARRANTIES OR REPRESENTATIONS,EXPRESS OR IMPLIED,REGARDING TI RESOURCES OR USE THEREOF,INCLUDING BUT NOT LIMITED TO ACCURACY OR COMPLETENESS,TITLE,ANY EPIDEMIC FAILURE WARRANTY AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE,AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHTS.TI SHALL NOT BE LIABLE FOR AND SHALL NOT DEFEND OR INDEMNIFY YOU AGAINST ANY CLAIM,INCLUDING BUT NOT LIMITED TO ANY INFRINGEMENT CLAIM THAT RELATES TO OR IS BASED ON ANY COMBINATION OF PRODUCTS EVEN IF DESCRIBED IN TI RESOURCES OR OTHERWISE.IN NO EVENT SHALL TI BE LIABLE FOR ANY ACTUAL,DIRECT,SPECIAL, COLLATERAL,INDIRECT,PUNITIVE,INCIDENTAL,CONSEQUENTIAL OR EXEMPLARY DAMAGES IN CONNECTION WITH OR ARISING OUT OF TI RESOURCES OR USE THEREOF,AND REGARDLESS OF WHETHER TI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.You agree to fully indemnify TI and its representatives against any damages,costs,losses,and/or liabilities arising out of your non-compliance with the terms and provisions of this Notice.This Notice applies to TI Resources.Additional terms apply to the use and purchase of certain types of materials,TI products and services. These include;without limitation,TI’s standard terms for semiconductor products /sc/docs/stdterms.htm),evaluation modules,and samples(/sc/docs/sampterms.htm).Mailing Address:Texas Instruments,Post Office Box655303,Dallas,Texas75265Copyright©2017,Texas Instruments Incorporated。
USB学习系列之二——USB设备的插入检测机制B的插入检测机制:USB端口的D+和D-均用一个15k的电阻接地,当无设备接入时,均处于低电平;在设备端在D+(表示高速设备或者全速设备)或者D-(表示低速设备)接了一个1.5k的上拉电阻到+3.3v,一旦将设备接入,USB端口的D+或者D-其中一个被拉高为3v,系统识别到外部设备接入。
注意:高速设备首先会被识别为全速设备,然后再通过集线器和设备二者的确认最后切换到高速模式下。
在高速模式下,采用的是电流传输模式,这个时候上拉电阻需要从D+上断开。
2.当设备没有枚举成功时(可以通过一个10K的电阻将USB的电源端和D+ 或者D-连接起来,电脑会发现一个无法识别的设备,这个设备的PID和VID都是0,根据每个特性可以简单的判定设备的枚举是否成功。
3.一个具体的USB实现什么功能,USB主机并不知道。
USB主机通过读取USB的设备描述符来获取设备的类型、厂商的ID和产品的ID(通常依靠它们来加载对应的驱动程序)、端点情况、版本号等众多信息。
B1.1协议定义的标准描述符有设备描述符(DeviceDescriptor)、配置描述符(ConfigurationDescriptor)、接口描述符(InterfaceDescriptor)、端点描述符(EndpointDescriptor)和字符串描述符(StringDescriptor)。
USB2.0相比于USB1.1新增加的两个描述符:限定符描述符(QualifierDescriptor)和其他速度配置描述符(OtherSpeedConfigurationDescriptor)。
5.一个USB设备只有一个设备描述符。
设备描述符里面决定了该设备有多少种配置,每种配置都有一个配置描述符;。
(19)中华人民共和国国家知识产权局(12)发明专利申请(10)申请公布号 (43)申请公布日 (21)申请号 201910184721.5(22)申请日 2019.03.12(71)申请人 福建升腾资讯有限公司地址 350000 福建省福州市仓山区金山工业区金山大道618号21#、22#、55#(72)发明人 庄毅民 赖文辉 (74)专利代理机构 福州市鼓楼区京华专利事务所(普通合伙) 35212代理人 宋连梅(51)Int.Cl.G06F 13/38(2006.01)G06F 13/42(2006.01)(54)发明名称一种USB复合设备及其工作方法(57)摘要本发明提供一种USB复合设备,所述USB复合设备具有CCID接口、HID接口以及USB驱动;所述CCID接口包括接触IC卡CCID接口、非接触IC卡CCID接口以及PSAM卡CCID接口;所述HID接口包括二代证HID接口以及磁条卡HID接口;所述USB 驱动包括用于与终端建立连接的USB外设单元以及用于执行数据处理的数据处理单元。
本发明通过开发USB底层驱动,实现了3CCID+2HID接口的USB驱动,其中CCID接口应用于接触式IC卡、非接触式IC卡以及PSAM卡3种外设模块,HID接口应用于磁条卡和二代证2种外设模块,因此,可很好的满足同时操作多个外设模块以及多个业务系统并行使用的需求。
权利要求书1页 说明书4页 附图2页CN 109977050 A 2019.07.05C N 109977050A权 利 要 求 书1/1页CN 109977050 A1.一种USB复合设备,其特征在于:所述USB复合设备具有CCID接口、HID接口以及USB驱动;所述CCID接口包括接触IC卡CCID接口、非接触IC卡CCID接口以及PSAM卡CCID接口;所述HID接口包括二代证HID接口以及磁条卡HID接口;所述USB驱动包括用于与终端建立连接的USB外设单元以及用于执行数据处理的数据处理单元。
UM2823用户手册STM32WB Nucleo-64开发板(MB1641)引言基于MB1641的NUCLEO-WB15CC STM32WB Nucleo-64开发板是一款低功耗蓝牙和超低功耗器件,嵌入了功能强大的超低功耗射频,符合低功耗蓝牙SIG规范5.2版本。
ARDUINO®Uno V3和ST morpho接口利用多种专用跳线,提供了一种扩展STM32WB Nucleo开放式开发平台功能的简单方法。
图1.NUCLEO-WB15CC顶视图图片不属于合同范围。
UM2823特性1 特性•STM32WB15CC(320 KB Flash存储器,48 KB SRAM,VFQFPN48封装)超低功耗无线微控制器,具有以下特点:‒双核32位(Arm® Cortex-M4®和用于实时射频的专用M0+ CPU)‒ 2.4 GHz射频收发器,支持Bluetooth®规范5.2版本•三个用户LED•一个复位按钮和三个用户按钮•板载连接器:‒ARDUINO® Uno V3扩展连接器‒意法半导体的morpho扩展引脚接口,用于完全访问所有的STM32WB I/O•集成PCB天线和SMA连接器封装•灵活的供电选择:ST-LINK、USB VBUS或外部电源•用于安装CR2032电池插座的板载封装•具有USB重新枚举功能的板载ST-LINK/V2-1调试器/编程器:大容量存储器、虚拟COM端口和调试端口•提供了全面的免费软件库和例程,可从STM32CubeWB MCU软件包获得•支持多种集成开发环境(IDE),包括IAR Embedded Workbench®、MDK-ARM、STM32CubeIDE,以及Mbed Studio注意:Arm是Arm Limited(或其子公司)在美国和/或其他地区的注册商标。
UM2823订购信息2 订购信息如要订购NUCLEO-WB15CC Nucleo-64开发板,请参阅表1。
⼀⽂搞懂USB设备端驱动框架【转】hello ⼤家好,今天带领⼤家学习⼀下USB 设备端驱动内核版本:4.4.941. Linux USB ⼦系统在介绍设备端驱动前,我们先来看看 Linux USB⼦系统。
这⾥的⼦系统是相对于整个Linux kernel 来说的,⽽⾮单⼀设备。
从整体概括了USB主机端和设备端的通信框架。
Linux kernel 中早已集成了较为完善的USB协议栈,由于其规模庞⼤,包含多个类别的设备驱动,所以Linux系统中的USB协议栈也被称为USB⼦系统。
1.1 主机端主机端,简化抽象三层:各种类设备驱动:mass sotrage, CDC, HID等USB 设备驱动:USB 核⼼处理主机控制器驱动:不同的USB主机控制器(OHCI/EHCI/UHCI),抽象为HDC。
1.2 设备端设备端,也抽象为三层:设备功能驱动:mass sotage , CDC, HID 等,对应主机端的类设备驱动Gadget 设备驱动:中间层,向下直接和UDC通信,建⽴链接;向上提供通⽤接⼝,屏蔽USB请求以及传输细节。
设备控制器驱动:UDC驱动,直接处理USB设备控制器。
2. USB 设备驱动2.1 gadget 驱动框架拆解1我们将USB 设备端驱动拆解⼀下,其驱动框架如下:上⽂提到,Gadget 设备层起着⾄关重要的作⽤。
为上层提供通⽤的驱动框架,与下层UDC通过Gadget Interface 建⽴联系。
其中Compsite Framwork 提供了⼀个通⽤的usb_gadget_driver 模板,包括各种⽅法供上层Function driver 使⽤。
(driver/usb/gadget/compsite.c)从上图我们可以看出,对于USB设备端驱动开发⽽⾔,更多的关注的是Function driver这层。
USB 控制相关过程,内核提供了⼀个中间层帮我们屏蔽掉了。
2.2 gadget 驱动框架拆解2内核版本:Linux Kernel 4.4.94,我们以这个版本进⾏拆解分析4.x 的内核相对于3.x的内核在gadget 驱动上分解的更加完善,显得⽬录结构,层次分明,分⼯合理,更便于理解。
USB USB(通用串行总线)是用于将适用USB 的外围设备连接到主机的外部总线结构,其主要是用在中速和低速的外设USB 是通过PCI 总线和PC 的内部系统数据线连接实现数据的传输USB 同时又是一种通信协议他支持主系统(host)和USB 的外围设备(device)之间的数据传输。
USB 目前有两个版本,USB1.1的最高数据传输率为12Mbps,USB2.0则提高到480Mbps。
注意:二者的物理接口完全一致,数据传输率上的差别完全由PC的USB host控制器以及USB设备决定。
USB可以通过连接线为设备提供最高5V,500mA的电力。
USB接口的类型 USB接口有3种类型:- Type A:一般用于PC- Type B:一般用于USB设备- Mini-USB:一般用于数码相机、数码摄像机、测量仪器以及移动硬盘等USB 的作用 连接PC 与电话,PC 具有很强的运算能力,而电话提供最为广泛的通信互连。
运算与通信成为计算机应用的基础,而计算机与通信是两个相对独立发展的产业,USB 旨在提供可以广泛应用于PC 到电话的互连的普遍性的连接。
Plug-and-Play ,从用户端来看PC 的串行口、并行口和键盘鼠标端口都不能Plug-and-Play,USB 则提供真正的Plug-and-Play。
端口扩展PC 的已有的串行/并行口等端口只适用于一两种的外设,并且不易扩展。
USB提供双向、低成本、低速到中速(USB 2.0 可达480Mb/s) 的通用外设总线,适用于连接各种各样的外设,并且易于扩展。
USB 的拓朴结构 在USB 的网络协议中每个USB 的系统有且只有一个主系统(host)它负责管理整个USB 系统包括USB设备的连接与删除、Host 与USB 设备的通信总路线的控制等等。
Host端有一个Root Hub 可提供一个或多个USB 下行端口每个端口可以连接一个USB Hub或一个USB DeviceUSB Hub 是用于USB 端口扩展的即USB Hub 可以将一个USB 端口扩展为多个端口。
usb真是很强很大,强是现在很多产品都用她来做,为了方便,不用开发驱动。
大是因为usb 协议太多了,就光hid都有好多种。
还是扯回正题,这次总结复合型设备,前面总结了hid和mass storage设备,如果在正常情况下两个设备都正常了的,那么现在就可以来做做复合型设备了。
百度和google都没找到她的定义,那么我来定义一下(见笑),复合型设备:具有两种usb 设备功能的一种设备,无论是相同的设备功能,还是不同的设备功能,只要同时具有两种以上的功能就是复合型设备。
其实很直白,大家都看的出来。
现在就把hid keyboard and usb mass storage复合起来,组成一个设备。
首先要说的是既然是复合型设备,那么就有多个interface,这里有两个设备,那么就需要两个interface,需要几个设备描述符呢,一个就够了,那配置描述符呢,也只需要一个就好了,那需要几个端点描述符呢,这个嘛,我就不知道了(开玩笑,你在总结你不知道),这个就得讲讲usb的几种传输模式了。
在usb里面一共有四种传输:控制传输、中断传输、批量传输、等时传输。
控制和批量端点用于异步的数据传输,驱动需要他们就立马工作。
中断和等时端点是周期性的,即在固定时间段连续的传输数据。
是不是有点熟悉,的确,前面总结过的,在这里再提提。
所以有几个端点,还是得看你在用哪种传输模式,hid keyboard和usb mass storage他们使用的传输方式是中断传输和批量传输。
中断传输:interrupt in ,在这里只需要interrupt in就ok了,既只要一个端点,至于interrupt out 就不用管了。
批量传输:bulk in和bulk out,由于u盘是双向的,当然需要有两个端点哦,毕竟他们通信要有来回才行啊。
所以要复合hid keyboard和usb mass storage就需要三个端点。
好了,前面说来复合型设备的描述符分别是:设备描述符*1+配置描述符*1+端点描述符*3,那么到这里就完了吗,如果只是usb mass storage,在加一个端点就完了,但是这里是Hid,还需要一个子类,在hid里面还有很多子类,那么就需要区分他们,不然host不知道你是哪家的,好比有很多人叫张三,但是这个世界那么多是张三,你知道他应该是哪家的呢,还是只有slave主动说自己是谁方便。
现在配置是设备描述符*1+配置描述符*1+端点描述符*3+子类描述符,但是描述符排列是有顺序的,写完一个在写另外一个。
// Descriptors for the GET_DESCRIPTOR and SET_DESCRIPTOR requests.typedef struct usb_device_descriptor {unsigned char length; // USB_DEVICE_DESCRIPTOR_LENGTH == 18unsigned char type; // USB_DEVREQ_DESCRIPTOR_TYPE unsigned char usb_spec_lo;unsigned char usb_spec_hi;unsigned char device_class;unsigned char device_subclass;unsigned char device_protocol;unsigned char max_packet_size;unsigned char vendor_lo;unsigned char vendor_hi;unsigned char product_lo;unsigned char product_hi;unsigned char device_lo;unsigned char device_hi;unsigned char manufacturer_str;unsigned char product_str;unsigned char serial_number_str;unsigned char number_configurations;} __attribute__((packed)) usb_device_descriptor;/*设备描述符*/const usb_device_descriptor device_desc = {.length = USB_DEVICE_DESC_SIZE, //0x12.type = USB_DEVICE_DESCRIPTOR_TYPE, // 1.usb_spec_lo =0x00,.usb_spec_hi =0x02,.device_class = 0x00,.device_subclass = 0x00,.device_protocol = 0x00,.max_packet_size = USB_MAX_PACKET0,.vendor_lo = 0x51,.vendor_hi = 0xC2,.product_lo = 0x03,.product_hi = 0x20,.device_lo =0x00,.device_hi = 0x01,.manufacturer_str = 0x01,.product_str= 0x02,.serial_number_str = 0x03,.number_configurations = 0x01, //};typedef struct usb_configuration_descriptor {unsigned char length;unsigned char type;unsigned char total_length_lo;unsigned char total_length_hi; //totallengthunsigned char number_interfaces;unsigned char configuration_id;unsigned char configuration_str;unsigned char attributes;unsigned char max_power;} __attribute__((packed)) usb_configuration_descriptor;typedef struct usb_interface_descriptor {unsigned char length;unsigned char type;unsigned char interface_id;unsigned char alternate_setting;unsigned char number_endpoints;unsigned char interface_class;unsigned char interface_subclass;unsigned char interface_protocol;unsigned char interface_str;} __attribute__((packed)) usb_interface_descriptor;typedef struct usb_endpoint_descriptor {unsigned char length;unsigned char type;unsigned char endpoint;unsigned char attributes;unsigned char max_packet_lo;unsigned char max_packet_hi;unsigned char interval;} __attribute__((packed)) usb_endpoint_descriptor;typedef struct usb_hid_descriptor{unsigned char length;unsigned char type;unsigned char bcdhid_lo;unsigned char bcdhid_hi;unsigned char countrycode;unsigned char numdescriptor;unsigned char descriptortype;unsigned char descriptorlength_lo;unsigned char descriptorlength_hi;}__attribute__((packed)) usb_hid_descriptor;typedef struct usb_scsi_hid_config{const usb_configuration_descriptor config;const usb_interface_descriptor scsi_inter;const usb_endpoint_descriptor scsi_endpoint_in;const usb_endpoint_descriptor scsi_endpoint_out;const usb_interface_descriptor hid_inter;const usb_hid_descriptor hid_desc;const usb_endpoint_descriptor hid_endpoint_in;}__attribute__((packed)) USB_CON_INT_ENDP_DESCRIPTOR_STRUCT;#define USB_CON_INT_ENDP_DESCRIPTOR_STRUCT_LENGTH (sizeof(USB_CON_INT_ENDP_DESCRIPTOR_STRUCT))const USB_CON_INT_ENDP_DESCRIPTOR_STRUCT usb_scsi_hid_con_int_endp = {/*config*/{.length= USB_CONFIGUARTION_DESC_SIZE,.type = USB_CONFIGURATION_DESCRIPTOR_TYPE,.total_length_lo = USB_CON_INT_ENDP_DESCRIPTOR_STRUCT_LENGTH&0xff, .total_length_hi = (USB_CON_INT_ENDP_DESCRIPTOR_STRUCT_LENGTH>>8)&0xff,.number_interfaces = 0x02, /*两个interface*/.configuration_id = 0x01, /*一个configuration*/.configuration_str = 0x00,.attributes = USB_CONFIG_BUS_POWERED,.max_power = USB_CONFIG_POWER_MA(300)},/*usb mass storage interface descriptor*/{.length = USB_INTERFACE_DESC_SIZE,.type = USB_INTERFACE_DESCRIPTOR_TYPE,.interface_id = 0x00,.alternate_setting = 0x00,.number_endpoints = 0x02,.interface_class = USB_DEVICE_CLASS_STORAGE, /*0x08表示mass storage*/ .interface_subclass = 0x06, /*表示支持SCSI Primary command-2*/.interface_protocol = 0x50, /*仅使用批量传输*/.interface_str = 0x04},/*usb mass storage Bulk in 2*/{/* Endpoint, EP2 Bulk IN */.length = USB_ENDPOINT_DESC_SIZE, /* bLength */.type = USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */.endpoint = USB_ENDPOINT_IN(2), /* bEndpointAddress */.attributes = USB_ENDPOINT_TYPE_BULK, /* bmAttributes */.max_packet_lo = 0x40, /* wMaxPacketSize */.max_packet_hi =0x00,.interval = 0x00, /* bInterval: ignore for Bulk transfer */ },/*usb mass storage Bulk out 3*/{/* Endpoint, EP3 Bulk OUT */.length = USB_ENDPOINT_DESC_SIZE, /* bLength */.type = USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */.endpoint = USB_ENDPOINT_OUT(3), /* bEndpointAddress */.attributes = USB_ENDPOINT_TYPE_BULK, /* bmAttributes */.max_packet_lo = 0x40, /* wMaxPacketSize */.max_packet_hi =0x00,.interval = 0x00, /* bInterval: ignore for Bulk transfer */},/*hid interface descriptor */{.length = USB_INTERFACE_DESC_SIZE,.type = USB_INTERFACE_DESCRIPTOR_TYPE, // 4.interface_id = 0x01,.alternate_setting = 0x00,.number_endpoints = 0x01,.interface_class = USB_DEVICE_CLASS_HUMAN_INTERFACE, //03.interface_subclass = HID_SUBCLASS_BOOT, /*0x01*/.interface_protocol = HID_PROTOCOL_NONE, /*0x00,没有协议,也可以写你需要的协议具体的看hid协议*/.interface_str = 0x00},/*hid subclass descriptor*/{.length = HID_DESC_SIZE,.type = HID_HID_DESCRIPTOR_TYPE,.bcdhid_lo = 0x00,.bcdhid_hi =0x01,.countrycode = 0x00,.numdescriptor = 0x01,.descriptortype = HID_REPORT_DESCRIPTOR_TYPE,.descriptorlength_lo = HID_REPORT_DESC_SIZE&0xff,.descriptorlength_hi = (HID_REPORT_DESC_SIZE>>8)&0xff},/*hid endpoint interrupt in 1*/{.length = USB_ENDPOINT_DESC_SIZE,.type = USB_ENDPOINT_DESCRIPTOR_TYPE,.endpoint = USB_ENDPOINT_IN(1),.attributes = USB_ENDPOINT_TYPE_INTERRUPT,.max_packet_lo =0x08,.max_packet_hi =0x00,.interval = 0x20},};到这里基本就完成了复合设备,只要你的代码两部分都整合在一起,就好了,。