\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));
ftdi->eeprom = eeprom;
- ftdi->module_detach_mode = AUTO_DETACH_SIO_MODULE;
-
/* All fine. Now allocate the readbuffer */
return ftdi_read_data_set_chunksize(ftdi, 4096);
}
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");