问题
I'd like to know in which mode a USB-OTG-supporting Android device is by default, - in the USB host mode or USB slave mode ?
I guess, if the device is in slave mode, then there's no point of using API described on link below ? https://developer.android.com/guide/topics/connectivity/usb/host.html
Is there a way to programmatically switch from host to slave mode and vice versa ?
As you know, a USB OTG (On the go) device automatically switches to host or slave mode, depending on which end of an OTG-specific cable has been inserted into device
And the second question is, in case if a device has necessary OTG ports, but the kernel does not support OTG yet, which parts of the kernel should be modified in order to be able to set host-slave mode, based on cable end detection ? (no need to implement HNP)
回答1:
There is no "default" mode in USB OTG. OTG controller detects the state the USB's fifth pin(ID pin). If the ID-pin is grounded or floating, the connected device is a Host or device.
USB 2.0 spec introduced 3 new protocols, ADP, SRP, HNP. Pls reference HNP for "a way to programmatically switch from host to slave mode and vice versa".
As your second question, I think detect the ID-pin is a function of OTG controller.
来源:https://stackoverflow.com/questions/12887672/usb-host-mode-in-android-device-supporting-otg