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的包)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章