\retval 0: all fine
\retval -1: couldn't allocate read buffer
\retval -2: couldn't allocate struct buffer
+ \retval -3: libusb_init() failed
\remark This should be called before all functions
*/
ftdi->readbuffer_remaining = 0;
ftdi->writebuffer_chunksize = 4096;
ftdi->max_packet_size = 0;
+ ftdi->error_str = NULL;
+ ftdi->module_detach_mode = AUTO_DETACH_SIO_MODULE;
+
+ if (libusb_init(&ftdi->usb_ctx) < 0)
+ ftdi_error_return(-3, "libusb_init() failed");
ftdi_set_interface(ftdi, INTERFACE_ANY);
ftdi->bitbang_mode = 1; /* when bitbang is enabled this holds the number of the mode */
- ftdi->error_str = NULL;
-
if (eeprom == 0)
ftdi_error_return(-2, "Can't malloc struct ftdi_eeprom");
memset(eeprom, 0, sizeof(struct ftdi_eeprom));
free(ftdi->eeprom);
ftdi->eeprom = NULL;
}
- libusb_exit(ftdi->usb_ctx);
+
+ if (ftdi->usb_ctx)
+ {
+ libusb_exit(ftdi->usb_ctx);
+ ftdi->usb_ctx = NULL;
+ }
}
/**
\retval >0: number of devices found
\retval -3: out of memory
- \retval -4: libusb_init() failed
\retval -5: libusb_get_device_list() failed
\retval -6: libusb_get_device_descriptor() failed
*/
int count = 0;
int i = 0;
- if (libusb_init(&ftdi->usb_ctx) < 0)
- ftdi_error_return(-4, "libusb_init() failed");
-
if (libusb_get_device_list(ftdi->usb_ctx, &devs) < 0)
ftdi_error_return(-5, "libusb_get_device_list() failed");
\retval -8: ftdi context invalid
\retval -9: libusb_get_device_descriptor() failed
\retval -10: libusb_get_config_descriptor() failed
- \retval -11: libusb_etach_kernel_driver() failed
+ \retval -11: libusb_detach_kernel_driver() failed
\retval -12: libusb_get_configuration() failed
*/
int ftdi_usb_open_dev(struct ftdi_context *ftdi, libusb_device *dev)
// 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.
- if (libusb_detach_kernel_driver(ftdi->usb_dev, ftdi->interface) !=0)
- detach_errno = errno;
+ if (ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE)
+ {
+ if (libusb_detach_kernel_driver(ftdi->usb_dev, ftdi->interface) !=0)
+ detach_errno = errno;
+ }
if (libusb_get_configuration (ftdi->usb_dev, &cfg) < 0)
ftdi_error_return(-12, "libusb_get_configuration () failed");
cbus_mux[eeprom->cbus_function[i]]);
else
{
- /* FIXME for Uwe: This results in an access above array bounds.
- Also I couldn't find documentation about this mode.
- fprintf(stdout,"C%d BB Function: %s\n", i,
- cbus_BB[i]);
- */
- fprintf(stdout, "Unknown CBUS mode. Might be special mode?\n");
- (void)cbus_BB;
+ if (i < 4)
+ /* Running MPROG show that C0..3 have fixed function Synchronous
+ Bit Bang mode */
+ fprintf(stdout,"C%d BB Function: %s\n", i,
+ cbus_BB[i]);
+ else
+ fprintf(stdout, "Unknown CBUS mode. Might be special mode?\n");
}
}
}