#include
#include
#include "libusb.h"
int main(int argc, char *argv[])
{
// init
int nRet = libusb_init(NULL);
if (nRet < 0)
{
printf("libusb_init(NULL) failed:[%s] \n", libusb_strerror(nRet));
return -1;
}
printf("libusb_init(NULL) ok \n");
// open device
libusb_device_handle* pHandle = libusb_open_device_with_vid_pid(NULL, 0x2207, 0x0011);
if (pHandle == NULL)
{
printf("libusb_open_device_with_vid_pid(0x2207, 0x0011) failed \n");
libusb_exit(NULL);
return -1;
}
printf("libusb_open_device_with_vid_pid(0x2207, 0x0011) ok \n");
if (libusb_kernel_driver_active(pHandle, 0) == 1)
{
printf("USB Kernel Driver Active \n");
if (libusb_kernel_driver_active(pHandle, 0) == 0)
{
printf("Kernel Driver Detached \n");
}
}
libusb_detach_kernel_driver(pHandle, 0);
// declare interface
nRet = libusb_claim_interface(pHandle, 0);
if (nRet < 0)
{
printf("libusb_claim_interface(0) failed:[%s] \n", libusb_strerror(nRet));
libusb_close(pHandle);
libusb_exit(NULL);
return -1;
}
printf("libusb_claim_interface(0) ok \n");
// write data
char sBuf[] = "1234567890";
int nActualBytes = 0;
libusb_clear_halt(pHandle, 0x01);
nRet = libusb_bulk_transfer(pHandle, 0x01, (unsigned char *)sBuf, strlen(sBuf), &nActualBytes, 1000);
if (nRet < 0)
{
printf("libusb_bulk_transfer(0x01) write failed:[%s] \n", libusb_strerror(nRet));
libusb_release_interface(pHandle, 0);
libusb_close(pHandle);
libusb_exit(NULL);
return -1;
}
printf("libusb_bulk_transfer(0x01) write size:[%d] \n", nActualBytes);
// read data
char sBuf2[10] = {0};
nActualBytes = 0;
libusb_clear_halt(pHandle, 0x81);
nRet = libusb_bulk_transfer(pHandle, 0x81, (unsigned char *)sBuf2, sizeof(sBuf2), &nActualBytes, 1000);
if (nRet < 0)
{
printf("libusb_bulk_transfer(0x81) read failed:[%s] \n", libusb_strerror(nRet));
libusb_release_interface(pHandle, 0);
libusb_close(pHandle);
libusb_exit(NULL);
return -1;
}
printf("libusb_bulk_transfer(0x81) read size:[%d] \n", nActualBytes);
// release interface
libusb_release_interface(pHandle, 0);
// close device
libusb_close(pHandle);
// release
libusb_exit(NULL);
return 0;
}
Bus 001 Device 099: ID 2207:0011 Fuzhou Rockchip Electronics Company SmartTab
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x2207 Fuzhou Rockchip Electronics Company
idProduct 0x0011 SmartTab
bcdDevice 3.10
iManufacturer 1 rockchip
iProduct 2 rk3xxx
iSerial 3 eb8c2325414a96dd
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 62
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 4 adb_mtp
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 0
iInterface 5 MTP
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x001c 1x 28 bytes
bInterval 6
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 66
bInterfaceProtocol 1
iInterface 6 ADB Interface
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Binary Object Store Descriptor:
bLength 5
bDescriptorType 15
wTotalLength 22
bNumDeviceCaps 2
USB 2.0 Extension Device Capability:
bLength 7
bDescriptorType 16
bDevCapabilityType 2
bmAttributes 0x00000006
Link Power Management (LPM) Supported
SuperSpeed USB Device Capability:
bLength 10
bDescriptorType 16
bDevCapabilityType 3
bmAttributes 0x00
wSpeedsSupported 0x000f
Device can operate at Low Speed (1Mbps)
Device can operate at Full Speed (12Mbps)
Device can operate at High Speed (480Mbps)
Device can operate at SuperSpeed (5Gbps)
bFunctionalitySupport 1
Lowest fully-functional device speed is Full Speed (12Mbps)
bU1DevExitLat 1 micro seconds
bU2DevExitLat 500 micro seconds
Device Status: 0x0000
(Bus Powered)
建议题主,先用rk的板子和windows电脑连接一下,使用bus hound工具先抓一下RK那边的bluk输入输出是否正确。不行你就用中断那个口试试0x82
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x001c 1x 28 bytes
提供参考链接【libusb阻塞】,期望对你有所帮助:https://www.cnblogs.com/heyp/p/3421800.html
不如让作为从机的那个设备工作在标准设备模式,比如NDIS,CDC之类的,这样就不必用底层的USB通讯,而是直接用高层的通讯方式了。