USB interface通道
每个usb pidvid提供好几个interface通道 ,每个interface提供最多俩endpoint
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbConfiguration[mId=1,mName=USB-3.0,mAttributes=224,mMaxPower=112,mInterfaces=[
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbInterface[mId=0,mAlternateSetting=0,mName=null,mClass=14,mSubclass=1,mProtocol=0,mEndpoints=[
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbEndpoint[mAddress=130,mAttributes=3,mMaxPacketSize=64,mInterval=4]]
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbInterface[mId=1,mAlternateSetting=0,mName=null,mClass=14,mSubclass=2,mProtocol=0,mEndpoints=[]
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbInterface[mId=1,mAlternateSetting=1,mName=null,mClass=14,mSubclass=2,mProtocol=0,mEndpoints=[
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbEndpoint[mAddress=131,mAttributes=5,mMaxPacketSize=1024,mInterval=1]]
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbInterface[mId=2,mAlternateSetting=0,mName=null,mClass=3,mSubclass=0,mProtocol=0,mEndpoints=[
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbEndpoint[mAddress=129,mAttributes=3,mMaxPacketSize=128,mInterval=3]
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbEndpoint[mAddress=1,mAttributes=3,mMaxPacketSize=128,mInterval=1]]
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbInterface[mId=3,mAlternateSetting=0,mName=null,mClass=255,mSubclass=0,mProtocol=0,mEndpoints=[]
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbInterface[mId=4,mAlternateSetting=0,mName=null,mClass=254,mSubclass=0,mProtocol=0,mEndpoints=[
06-28 12:55:36.964 D/UsbHostManager( 1580): UsbEndpoint[mAddress=132,mAttributes=3,mMaxPacketSize=256,mInterval=1]]]]
public static final int USB_DIR_OUT = ServiceProtoEnums.USB_ENDPOINT_DIR_OUT; // 0
public static final int USB_DIR_IN = ServiceProtoEnums.USB_ENDPOINT_DIR_IN; // 0x80
>128 是 1 in
<128 是 0 out
如下操作都是针对interface的,所以可以多个interface同时操作读写
static jboolean
android_hardware_UsbDeviceConnection_claim_interface(JNIEnv *env, jobject thiz,
jint interfaceID, jboolean force)
{
struct usb_device* device = get_device_from_object(env, thiz);
if (!device) {
ALOGE("device is closed in native_claim_interface");
return JNI_FALSE;
}
int ret = usb_device_claim_interface(device, interfaceID);
if (ret && force && errno == EBUSY) {
// disconnect kernel driver and try again
usb_device_connect_kernel_driver(device, interfaceID, false);
ret = usb_device_claim_interface(device, interfaceID);
}
return (ret == 0) ? JNI_TRUE : JNI_FALSE;
}
static jboolean
android_hardware_UsbDeviceConnection_release_interface(JNIEnv *env, jobject thiz, jint interfaceID)
{
struct usb_device* device = get_device_from_object(env, thiz);
if (!device) {
ALOGE("device is closed in native_release_interface");
return JNI_FALSE;
}
int ret = usb_device_release_interface(device, interfaceID);
if (ret == 0) {
// allow kernel to reconnect its driver
usb_device_connect_kernel_driver(device, interfaceID, true);
}
return (ret == 0) ? JNI_TRUE : JNI_FALSE;
}
posted on 2021-06-29 11:33 framework开发 阅读(550) 评论(0) 编辑 收藏 举报