我试图像这样在android中分离ftdi内核驱动程序(libftdi-0.x代码):
#ifdef LIBUSB_HAS_GET_DRIVER_NP
// Try to detach ftdi_sio kernel module.
// Returns ENODATA if driver is not loaded.
//
// The return code is kept in a separate variable and only parsed
// if usb_set_configuration() or usb_claim_interface() fails as the
// detach operation might be denied and everything still works fine.
// Likely scenario is a static ftdi_sio kernel module.
fprintf(stderr, "detaching kernel driver... \n");
if (ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE)
{
fprintf(stderr, "usb_detach_kernel_driver_np() ...\n");
if (usb_detach_kernel_driver_np(ftdi->usb_dev, ftdi->interface) != 0 && errno != ENODATA) {
fprintf(stderr, "failed to detach\n");
detach_errno = errno;
}
}
#endif
由于该设备的所有下一次调用都因error=32 (EPIPE)而失败,我相信它实际上并没有分离:
fprintf(stderr, "ftdi set configuration\n");
if (dev->descriptor.bNumConfigurations > 0)
{
// libusb-win32 on Windows 64 can return a null pointer for a valid device
if (dev->config) {
config_val = dev->config[0].bConfigurationValue;
fprintf(stderr, "trying to set configuration %i\n", config_val);
}
if (usb_set_configuration(ftdi->usb_dev, config_val) && errno != EBUSY)
{
ftdi_usb_close_internal (ftdi);
if (detach_errno == EPERM)
{
ftdi_error_return(-8, "inappropriate permissions on device!");
}
else
{
ftdi_error_return(-3, "unable to set usb configuration. Make sure the default FTDI driver is not in use");
}
}
}
日志:
08-08 11:40:54.197: WARN/System.err(31772): trying to set configuration 1
08-08 11:40:54.197: WARN/System.err(31772): libusb-compat debug: usb_set_configuration: configuration 1
08-08 11:40:54.197: WARN/System.err(31772): libusb: 0.005311 debug [libusb_set_configuration] configuration 1
08-08 11:40:54.197: WARN/System.err(31772): libusb: 0.007173 error [op_set_configuration] failed, error -1 errno 32
根据上面的评论,它似乎实际上并没有分离,但结果还可以。
关于如何分离它或至少获得实际结果的任何想法?有逛街吗?
更新:我已经在 2 个 android 设备上进行了尝试,这两个设备都支持 android 4.0.x 和 android 4.1 上的 usb-host,有 2 个不同的 FTDI 设备。
更新:我创建了android 问题