Android USB configfs使用总结

1 如何使用
Linux 3.0新的USB gadget configfs.c驱动的用法如下所示:
挂载configfs文件系统。
# mount -t configfs none /sys/kernel/config
# cd /sys/kernel/config
# ls
usb_gadget
# cd usb_gadget

创建g1目录,实例化一个新的gadget模板。
# mkdir g1
# cd g1
# ls
UDC  bDeviceProtocol    bMaxPacketSize0    bcdUSB    functions    idVendor    bDeviceClass     bDeviceSubClass    bcdDevice    configs    idProduct    strings

定义USB产品的VID和PID。
# echo "0xabcd"  > idVendor
# echo "0x1234" > idProduct

实例化英语语言ID。
# mkdir strings/0x409
# ls strings/0x409
manufacturer    product    serialnumber

将开发商、产品和序列号字符串写入内核。
# echo "0123456789ABCDEF" > strings/0x409/serialnumber
# echo "Master"  > strings/0x409/manufacturer
# echo "George"  > strings/0x409/product

创建功能实例,需要注意的是,一个功能如果有多个实例的话,扩展名必须用数字编号。
# mkdir functions/acm.GS0
# mkdir functions/acm.GS1
# mkdir functions/ecm.usb0

创建一个USB配置实例:
# mkdir configs/c.1
# ls configs/c.1
MaxPower bmAttributes strings

定义配置描述符使用的字符串
# mkdir configs/c.1/string/0x409
# ls configs/c.1/strings/0x409/
configuration
# echo "2XACM+ECM" > configfs/c.1/strings/0x409/configuration

捆绑功能实例到配置c.1
# ln -s functions/acm.GS0 configs/c.1
# ln -s functions/acm.GS1 configs/c.1
# ln -s functions/ecm.usb0 configs/c.1

查找本机可获得的UDC实例
# ls /sys/class/udc/
msm_hsusb

将gadget驱动注册到UDC上,插上USB线到电脑上,电脑就会枚举USB设备。
# echo "msm_hsusb" > UDC

2 驱动调用流程
2.1 创建USB gadget
# cd /config
# ls
# cd usb_gadget
# mkdir g1
# ls
# cd g1
# ls
[...]
# cd /config/usb_gadget/g1
# echo ${sys.usb.controller} > UDC

2.2 创建一个USB配置
# mkdir configs/c.1

format: *.num
*: any string
num: usb configuration value, which should be started from 1

This string length should be less than 40

call-stack:
gadgets_make
--->
config_desc_make

2.3 创建一个USB功能
# mkdir functions/acm.GS0

format: func_name.instance_name

call-stack:
gadgets_make
--->
function_make

2.4 配置USB描述中的字符串
# echo "oem-demo" > xxx/strings/0x409/xxx

call-stack:
gadget_strings_langid_attrs

3 Linux Gadget and Host逻辑端点索引
ep_index  = (epnum * 2) + direction - 1, where direction = 0 for OUT, 1 for IN, [0,1,2...30]

4 Abbreviations
ARC:Argonant RISC Core
AT91SAM9260:SAM means Smart ARM-based Microcontroller
ATMEL SAMBA:ATMEL Smart ARM-based Microcontroller Boot Assistant
CC2530:TI ChipCon2530
DWC2:Design Ware Controller 2,Apple的嵌入式设备,包括iPad和iPhone都是使用的DWC2
ISP1161:Philips' Integrated host Solution Pairs 1161,“Firms introduce USB host controllers”,https://www.eetimes.com/document.asp?doc_id=1290054
Quirks:the attributes of a device that are considered to be noncompliant with expected operation
SL811HS:Cypress/ScanLogic 811 Host/Slave,性能上与ISP1161(Integrated host Solution Pairs 1161)相当
TDI:TransDimension Inc.,该公司首先发明了将TT集成到EHCI RootHub中的方法,这样对于嵌入式系统来说,就省去了OHCI/UHCI的硬件,同时降低了成本,作为对该公司的纪念,Linux内核定义了宏ehci_is_TDI(ehci);产品UHC124表示USB Host Controller;收购了ARC USB技术;现已被chipidea收购,chipidea又被mips收购
TLV:TI Low Value,高性价比
TPS:TI Performance Solution
TT:Transaction Translator(事务转换器,将USB2.0的包转换成USB1.1的包)

你可能感兴趣的:(USB)