Intra2net AG

libftdi1  1.5
Macros | Functions
ftdi.c File Reference
#include <libusb.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "ftdi_i.h"
#include "ftdi.h"
#include "ftdi_version_i.h"

Go to the source code of this file.

Macros

#define _FTDI_DISABLE_DEPRECATED
 
#define ftdi_error_return(code, str)
 
#define ftdi_error_return_free_device_list(code, str, devs)
 
#define H_CLK   120000000
 
#define C_CLK   48000000
 
#define MAGIC   0x55aa
 

Functions

int ftdi_init (struct ftdi_context *ftdi)
 
struct ftdi_contextftdi_new (void)
 
int ftdi_set_interface (struct ftdi_context *ftdi, enum ftdi_interface interface)
 
void ftdi_deinit (struct ftdi_context *ftdi)
 
void ftdi_free (struct ftdi_context *ftdi)
 
void ftdi_set_usbdev (struct ftdi_context *ftdi, libusb_device_handle *usb)
 
struct ftdi_version_info ftdi_get_library_version (void)
 Get libftdi library version. More...
 
int ftdi_usb_find_all (struct ftdi_context *ftdi, struct ftdi_device_list **devlist, int vendor, int product)
 
void ftdi_list_free (struct ftdi_device_list **devlist)
 
void ftdi_list_free2 (struct ftdi_device_list *devlist)
 
int ftdi_usb_get_strings (struct ftdi_context *ftdi, struct libusb_device *dev, char *manufacturer, int mnf_len, char *description, int desc_len, char *serial, int serial_len)
 
int ftdi_usb_get_strings2 (struct ftdi_context *ftdi, struct libusb_device *dev, char *manufacturer, int mnf_len, char *description, int desc_len, char *serial, int serial_len)
 
int ftdi_usb_open_dev (struct ftdi_context *ftdi, libusb_device *dev)
 
int ftdi_usb_open (struct ftdi_context *ftdi, int vendor, int product)
 
int ftdi_usb_open_desc (struct ftdi_context *ftdi, int vendor, int product, const char *description, const char *serial)
 
int ftdi_usb_open_desc_index (struct ftdi_context *ftdi, int vendor, int product, const char *description, const char *serial, unsigned int index)
 
int ftdi_usb_open_bus_addr (struct ftdi_context *ftdi, uint8_t bus, uint8_t addr)
 
int ftdi_usb_open_string (struct ftdi_context *ftdi, const char *description)
 
int ftdi_usb_reset (struct ftdi_context *ftdi)
 
int ftdi_tciflush (struct ftdi_context *ftdi)
 
int ftdi_usb_purge_rx_buffer (struct ftdi_context *ftdi)
 
int ftdi_tcoflush (struct ftdi_context *ftdi)
 
int ftdi_usb_purge_tx_buffer (struct ftdi_context *ftdi)
 
int ftdi_tcioflush (struct ftdi_context *ftdi)
 
int ftdi_usb_purge_buffers (struct ftdi_context *ftdi)
 
int ftdi_usb_close (struct ftdi_context *ftdi)
 
int convert_baudrate_UT_export (int baudrate, struct ftdi_context *ftdi, unsigned short *value, unsigned short *index)
 Wrapper function to export ftdi_convert_baudrate() to the unit test Do not use, it's only for the unit test framework. More...
 
int ftdi_set_baudrate (struct ftdi_context *ftdi, int baudrate)
 
int ftdi_set_line_property (struct ftdi_context *ftdi, enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity)
 
int ftdi_set_line_property2 (struct ftdi_context *ftdi, enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity, enum ftdi_break_type break_type)
 
int ftdi_write_data (struct ftdi_context *ftdi, const unsigned char *buf, int size)
 
struct ftdi_transfer_controlftdi_write_data_submit (struct ftdi_context *ftdi, unsigned char *buf, int size)
 
struct ftdi_transfer_controlftdi_read_data_submit (struct ftdi_context *ftdi, unsigned char *buf, int size)
 
int ftdi_transfer_data_done (struct ftdi_transfer_control *tc)
 
void ftdi_transfer_data_cancel (struct ftdi_transfer_control *tc, struct timeval *to)
 
int ftdi_write_data_set_chunksize (struct ftdi_context *ftdi, unsigned int chunksize)
 
int ftdi_write_data_get_chunksize (struct ftdi_context *ftdi, unsigned int *chunksize)
 
int ftdi_read_data (struct ftdi_context *ftdi, unsigned char *buf, int size)
 
int ftdi_read_data_set_chunksize (struct ftdi_context *ftdi, unsigned int chunksize)
 
int ftdi_read_data_get_chunksize (struct ftdi_context *ftdi, unsigned int *chunksize)
 
int ftdi_set_bitmode (struct ftdi_context *ftdi, unsigned char bitmask, unsigned char mode)
 
int ftdi_disable_bitbang (struct ftdi_context *ftdi)
 
int ftdi_read_pins (struct ftdi_context *ftdi, unsigned char *pins)
 
int ftdi_set_latency_timer (struct ftdi_context *ftdi, unsigned char latency)
 
int ftdi_get_latency_timer (struct ftdi_context *ftdi, unsigned char *latency)
 
int ftdi_poll_modem_status (struct ftdi_context *ftdi, unsigned short *status)
 
int ftdi_setflowctrl (struct ftdi_context *ftdi, int flowctrl)
 
int ftdi_setflowctrl_xonxoff (struct ftdi_context *ftdi, unsigned char xon, unsigned char xoff)
 
int ftdi_setdtr (struct ftdi_context *ftdi, int state)
 
int ftdi_setrts (struct ftdi_context *ftdi, int state)
 
int ftdi_setdtr_rts (struct ftdi_context *ftdi, int dtr, int rts)
 
int ftdi_set_event_char (struct ftdi_context *ftdi, unsigned char eventch, unsigned char enable)
 
int ftdi_set_error_char (struct ftdi_context *ftdi, unsigned char errorch, unsigned char enable)
 
int ftdi_eeprom_initdefaults (struct ftdi_context *ftdi, char *manufacturer, char *product, char *serial)
 
int ftdi_eeprom_set_strings (struct ftdi_context *ftdi, const char *manufacturer, const char *product, const char *serial)
 
int ftdi_eeprom_get_strings (struct ftdi_context *ftdi, char *manufacturer, int mnf_len, char *product, int prod_len, char *serial, int serial_len)
 
void set_ft232h_cbus (struct ftdi_eeprom *eeprom, unsigned char *output)
 
int ftdi_eeprom_build (struct ftdi_context *ftdi)
 
int ftdi_eeprom_decode (struct ftdi_context *ftdi, int verbose)
 
int ftdi_get_eeprom_value (struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int *value)
 
int ftdi_set_eeprom_value (struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int value)
 
int ftdi_get_eeprom_buf (struct ftdi_context *ftdi, unsigned char *buf, int size)
 
int ftdi_set_eeprom_buf (struct ftdi_context *ftdi, const unsigned char *buf, int size)
 
int ftdi_set_eeprom_user_data (struct ftdi_context *ftdi, const char *buf, int size)
 
int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val)
 
int ftdi_read_eeprom (struct ftdi_context *ftdi)
 
int ftdi_read_chipid (struct ftdi_context *ftdi, unsigned int *chipid)
 
int ftdi_write_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short eeprom_val)
 
int ftdi_write_eeprom (struct ftdi_context *ftdi)
 
int ftdi_erase_eeprom (struct ftdi_context *ftdi)
 
const char * ftdi_get_error_string (struct ftdi_context *ftdi)
 

Macro Definition Documentation

◆ _FTDI_DISABLE_DEPRECATED

#define _FTDI_DISABLE_DEPRECATED

Definition at line 40 of file ftdi.c.

◆ ftdi_error_return

#define ftdi_error_return (   code,
  str 
)
Value:
do { \
if ( ftdi ) \
ftdi->error_str = str; \
else \
fprintf(stderr, str); \
return code; \
} while(0);

Definition at line 44 of file ftdi.c.

◆ ftdi_error_return_free_device_list

#define ftdi_error_return_free_device_list (   code,
  str,
  devs 
)
Value:
do { \
libusb_free_device_list(devs,1); \
ftdi->error_str = str; \
return code; \
} while(0);

Definition at line 52 of file ftdi.c.

◆ H_CLK

#define H_CLK   120000000

◆ C_CLK

#define C_CLK   48000000

◆ MAGIC

#define MAGIC   0x55aa

Erase eeprom

This is not supported on FT232R/FT245R according to the MProg manual from FTDI.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1erase failed
-2USB device unavailable
-3Writing magic failed
-4Read EEPROM failed
-5Unexpected EEPROM value

Definition at line 4668 of file ftdi.c.

Function Documentation

◆ ftdi_init()

int ftdi_init ( struct ftdi_context ftdi)

◆ ftdi_new()

struct ftdi_context* ftdi_new ( void  )

Allocate and initialize a new ftdi_context

Returns
a pointer to a new ftdi_context, or NULL on failure

Definition at line 132 of file ftdi.c.

References ftdi_init().

Referenced by Ftdi::Context::Private::Private().

◆ ftdi_set_interface()

int ftdi_set_interface ( struct ftdi_context ftdi,
enum ftdi_interface  interface 
)

Open selected channels on a chip, otherwise use first channel.

Parameters
ftdipointer to ftdi_context
interfaceInterface to use for FT2232C/2232H/4232H chips.
Return values
0all fine
-1unknown interface
-2USB device unavailable
-3Device already open, interface can't be set in that state

Definition at line 161 of file ftdi.c.

References ftdi_error_return, ftdi_context::in_ep, ftdi_context::index, ftdi_context::interface, INTERFACE_A, INTERFACE_ANY, INTERFACE_B, INTERFACE_C, INTERFACE_D, ftdi_context::out_ep, and ftdi_context::usb_dev.

Referenced by ftdi_init(), and Ftdi::Context::set_interface().

◆ ftdi_deinit()

void ftdi_deinit ( struct ftdi_context ftdi)

Deinitializes a ftdi_context.

Parameters
ftdipointer to ftdi_context

Definition at line 214 of file ftdi.c.

Referenced by ftdi_free().

◆ ftdi_free()

void ftdi_free ( struct ftdi_context ftdi)

Deinitialize and free an ftdi_context.

Parameters
ftdipointer to ftdi_context

Definition at line 260 of file ftdi.c.

References ftdi_deinit().

Referenced by Ftdi::Context::set_context(), and Ftdi::Context::Private::~Private().

◆ ftdi_set_usbdev()

void ftdi_set_usbdev ( struct ftdi_context ftdi,
libusb_device_handle *  usb 
)

Use an already open libusb device.

Parameters
ftdipointer to ftdi_context
usblibusb libusb_device_handle to use

Definition at line 272 of file ftdi.c.

References ftdi_context::usb_dev.

Referenced by Ftdi::Context::set_usb_device().

◆ ftdi_get_library_version()

struct ftdi_version_info ftdi_get_library_version ( void  )

Get libftdi library version.

Returns
ftdi_version_info Library version information

Definition at line 285 of file ftdi.c.

References ftdi_version_info::major, ftdi_version_info::micro, ftdi_version_info::minor, ftdi_version_info::snapshot_str, and ftdi_version_info::version_str.

◆ ftdi_usb_find_all()

int ftdi_usb_find_all ( struct ftdi_context ftdi,
struct ftdi_device_list **  devlist,
int  vendor,
int  product 
)

Finds all ftdi devices with given VID:PID on the usb bus. Creates a new ftdi_device_list which needs to be deallocated by ftdi_list_free() after use. With VID:PID 0:0, search for the default devices (0x403:0x6001, 0x403:0x6010, 0x403:0x6011, 0x403:0x6014, 0x403:0x6015)

Parameters
ftdipointer to ftdi_context
devlistPointer where to store list of found devices
vendorVendor ID to search for
productProduct ID to search for
Return values
>0number of devices found
-3out of memory
-5libusb_get_device_list() failed
-6libusb_get_device_descriptor() failed

Definition at line 314 of file ftdi.c.

References ftdi_device_list::dev, ftdi_error_return, ftdi_error_return_free_device_list, ftdi_device_list::next, and ftdi_context::usb_ctx.

Referenced by Ftdi::List::find_all().

◆ ftdi_list_free()

void ftdi_list_free ( struct ftdi_device_list **  devlist)

Frees a usb device list.

Parameters
devlistUSB device list created by ftdi_usb_find_all()

Definition at line 362 of file ftdi.c.

References ftdi_device_list::dev, and ftdi_device_list::next.

Referenced by Ftdi::List::clear(), ftdi_list_free2(), and Ftdi::List::Private::~Private().

◆ ftdi_list_free2()

void ftdi_list_free2 ( struct ftdi_device_list devlist)

Frees a usb device list.

Parameters
devlistUSB device list created by ftdi_usb_find_all()

Definition at line 382 of file ftdi.c.

References ftdi_list_free().

◆ ftdi_usb_get_strings()

int ftdi_usb_get_strings ( struct ftdi_context ftdi,
struct libusb_device *  dev,
char *  manufacturer,
int  mnf_len,
char *  description,
int  desc_len,
char *  serial,
int  serial_len 
)

Return device ID strings from the usb device.

The parameters manufacturer, description and serial may be NULL or pointer to buffers to store the fetched strings.

Note
Use this function only in combination with ftdi_usb_find_all() as it closes the internal "usb_dev" after use.
Parameters
ftdipointer to ftdi_context
devlibusb usb_dev to use
manufacturerStore manufacturer string here if not NULL
mnf_lenBuffer size of manufacturer string
descriptionStore product description string here if not NULL
desc_lenBuffer size of product description string
serialStore serial string here if not NULL
serial_lenBuffer size of serial string
Return values
0all fine
-1wrong arguments
-4unable to open device
-7get product manufacturer failed
-8get product description failed
-9get serial number failed
-11libusb_get_device_descriptor() failed

Definition at line 413 of file ftdi.c.

References ftdi_device_list::dev, ftdi_error_return, ftdi_usb_get_strings2(), and ftdi_context::usb_dev.

Referenced by Ftdi::Context::get_strings().

◆ ftdi_usb_get_strings2()

int ftdi_usb_get_strings2 ( struct ftdi_context ftdi,
struct libusb_device *  dev,
char *  manufacturer,
int  mnf_len,
char *  description,
int  desc_len,
char *  serial,
int  serial_len 
)

Return device ID strings from the usb device.

The parameters manufacturer, description and serial may be NULL or pointer to buffers to store the fetched strings.

Note
The old function ftdi_usb_get_strings() always closes the device. This version only closes the device if it was opened by it.
Parameters
ftdipointer to ftdi_context
devlibusb usb_dev to use
manufacturerStore manufacturer string here if not NULL
mnf_lenBuffer size of manufacturer string
descriptionStore product description string here if not NULL
desc_lenBuffer size of product description string
serialStore serial string here if not NULL
serial_lenBuffer size of serial string
Return values
0all fine
-1wrong arguments
-4unable to open device
-7get product manufacturer failed
-8get product description failed
-9get serial number failed
-11libusb_get_device_descriptor() failed

Definition at line 470 of file ftdi.c.

References ftdi_error_return, and ftdi_context::usb_dev.

Referenced by ftdi_usb_get_strings().

◆ ftdi_usb_open_dev()

int ftdi_usb_open_dev ( struct ftdi_context ftdi,
libusb_device *  dev 
)

Opens a ftdi device given by an usb_device.

Parameters
ftdipointer to ftdi_context
devlibusb usb_dev to use
Return values
0all fine
-3unable to config device
-4unable to open device
-5unable to claim device
-6reset failed
-7set baudrate failed
-8ftdi context invalid
-9libusb_get_device_descriptor() failed
-10libusb_get_config_descriptor() failed
-11libusb_detach_kernel_driver() failed
-12libusb_get_configuration() failed

Definition at line 589 of file ftdi.c.

References AUTO_DETACH_REATACH_SIO_MODULE, AUTO_DETACH_SIO_MODULE, ftdi_error_return, ftdi_context::interface, ftdi_context::module_detach_mode, and ftdi_context::usb_dev.

Referenced by ftdi_usb_open_bus_addr(), ftdi_usb_open_string(), and Ftdi::Context::get_strings_and_reopen().

◆ ftdi_usb_open()

int ftdi_usb_open ( struct ftdi_context ftdi,
int  vendor,
int  product 
)

Opens the first device with a given vendor and product ids.

Parameters
ftdipointer to ftdi_context
vendorVendor ID
productProduct ID
Return values
sameas ftdi_usb_open_desc()

Definition at line 707 of file ftdi.c.

References ftdi_usb_open_desc().

Referenced by Ftdi::Context::open().

◆ ftdi_usb_open_desc()

int ftdi_usb_open_desc ( struct ftdi_context ftdi,
int  vendor,
int  product,
const char *  description,
const char *  serial 
)

Opens the first device with a given, vendor id, product id, description and serial.

Parameters
ftdipointer to ftdi_context
vendorVendor ID
productProduct ID
descriptionDescription to search for. Use NULL if not needed.
serialSerial to search for. Use NULL if not needed.
Return values
0all fine
-3usb device not found
-4unable to open device
-5unable to claim device
-6reset failed
-7set baudrate failed
-8get product description failed
-9get serial number failed
-12libusb_get_device_list() failed
-13libusb_get_device_descriptor() failed

Definition at line 733 of file ftdi.c.

References ftdi_usb_open_desc_index().

Referenced by ftdi_usb_open().

◆ ftdi_usb_open_desc_index()

int ftdi_usb_open_desc_index ( struct ftdi_context ftdi,
int  vendor,
int  product,
const char *  description,
const char *  serial,
unsigned int  index 
)

Opens the index-th device with a given, vendor id, product id, description and serial.

Parameters
ftdipointer to ftdi_context
vendorVendor ID
productProduct ID
descriptionDescription to search for. Use NULL if not needed.
serialSerial to search for. Use NULL if not needed.
indexNumber of matching device to open if there are more than one, starts with 0.
Return values
0all fine
-1usb_find_busses() failed
-2usb_find_devices() failed
-3usb device not found
-4unable to open device
-5unable to claim device
-6reset failed
-7set baudrate failed
-8get product description failed
-9get serial number failed
-10unable to close device
-11ftdi context invalid
-12libusb_get_device_list() failed

Definition at line 764 of file ftdi.c.

References ftdi_error_return, ftdi_error_return_free_device_list, ftdi_context::usb_ctx, and ftdi_context::usb_dev.

Referenced by ftdi_usb_open_desc(), ftdi_usb_open_string(), and Ftdi::Context::open().

◆ ftdi_usb_open_bus_addr()

int ftdi_usb_open_bus_addr ( struct ftdi_context ftdi,
uint8_t  bus,
uint8_t  addr 
)

Opens the device at a given USB bus and device address.

Parameters
ftdipointer to ftdi_context
busBus number
addrDevice address
Return values
0all fine
-1usb_find_busses() failed
-2usb_find_devices() failed
-3usb device not found
-4unable to open device
-5unable to claim device
-6reset failed
-7set baudrate failed
-8get product description failed
-9get serial number failed
-10unable to close device
-11ftdi context invalid
-12libusb_get_device_list() failed

Definition at line 857 of file ftdi.c.

References ftdi_error_return, ftdi_error_return_free_device_list, ftdi_usb_open_dev(), and ftdi_context::usb_ctx.

◆ ftdi_usb_open_string()

int ftdi_usb_open_string ( struct ftdi_context ftdi,
const char *  description 
)

Opens the ftdi-device described by a description-string. Intended to be used for parsing a device-description given as commandline argument.

Parameters
ftdipointer to ftdi_context
descriptionNULL-terminated description-string, using this format:
  • d:<devicenode> path of bus and device-node (e.g. "003/001") within usb device tree (usually at /proc/bus/usb/)
  • i:<vendor>:<product> first device with given vendor and product id, ids can be decimal, octal (preceded by "0") or hex (preceded by "0x")
  • i:<vendor>:<product>:<index> as above with index being the number of the device (starting with 0) if there are more than one
  • s:<vendor>:<product>:<serial> first device with given vendor id, product id and serial string
Note
The description format may be extended in later versions.
Return values
0all fine
-2libusb_get_device_list() failed
-3usb device not found
-4unable to open device
-5unable to claim device
-6reset failed
-7set baudrate failed
-8get product description failed
-9get serial number failed
-10unable to close device
-11illegal description format
-12ftdi context invalid

Definition at line 910 of file ftdi.c.

References ftdi_error_return, ftdi_error_return_free_device_list, ftdi_usb_open_desc_index(), ftdi_usb_open_dev(), and ftdi_context::usb_ctx.

Referenced by Ftdi::Context::open().

◆ ftdi_usb_reset()

int ftdi_usb_reset ( struct ftdi_context ftdi)

Resets the ftdi device.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1FTDI reset failed
-2USB device unavailable

Definition at line 1003 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, ftdi_context::readbuffer_offset, ftdi_context::readbuffer_remaining, SIO_RESET_REQUEST, SIO_RESET_SIO, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by ftdi_write_eeprom(), and Ftdi::Context::reset().

◆ ftdi_tciflush()

int ftdi_tciflush ( struct ftdi_context ftdi)

Clears the read buffer on the chip and the internal read buffer. This is the correct behavior for an RX flush.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1read buffer purge failed
-2USB device unavailable

Definition at line 1030 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, ftdi_context::readbuffer_offset, ftdi_context::readbuffer_remaining, SIO_RESET_REQUEST, SIO_TCIFLUSH, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by ftdi_tcioflush(), and Ftdi::Context::tcflush().

◆ ftdi_usb_purge_rx_buffer()

int ftdi_usb_purge_rx_buffer ( struct ftdi_context ftdi)

Clears the write buffer on the chip and the internal read buffer. This is incorrect behavior for an RX flush.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1write buffer purge failed
-2USB device unavailable
Deprecated:
Use ftdi_tciflush(struct ftdi_context *ftdi)

Definition at line 1060 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, ftdi_context::readbuffer_offset, ftdi_context::readbuffer_remaining, SIO_RESET_PURGE_RX, SIO_RESET_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::flush(), and ftdi_usb_purge_buffers().

◆ ftdi_tcoflush()

int ftdi_tcoflush ( struct ftdi_context ftdi)

Clears the write buffer on the chip. This is correct behavior for a TX flush.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1write buffer purge failed
-2USB device unavailable

Definition at line 1087 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_RESET_REQUEST, SIO_TCOFLUSH, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by ftdi_tcioflush(), and Ftdi::Context::tcflush().

◆ ftdi_usb_purge_tx_buffer()

int ftdi_usb_purge_tx_buffer ( struct ftdi_context ftdi)

Clears the read buffer on the chip. This is incorrect behavior for a TX flush.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1read buffer purge failed
-2USB device unavailable
Deprecated:
Use ftdi_tcoflush(struct ftdi_context *ftdi)

Definition at line 1113 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_RESET_PURGE_TX, SIO_RESET_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::flush(), and ftdi_usb_purge_buffers().

◆ ftdi_tcioflush()

int ftdi_tcioflush ( struct ftdi_context ftdi)

Clears the RX and TX FIFOs on the chip and the internal read buffer. This is correct behavior for both RX and TX flush.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1read buffer purge failed
-2write buffer purge failed
-3USB device unavailable

Definition at line 1137 of file ftdi.c.

References ftdi_error_return, ftdi_tciflush(), ftdi_tcoflush(), and ftdi_context::usb_dev.

Referenced by ftdi_readstream(), and Ftdi::Context::tcflush().

◆ ftdi_usb_purge_buffers()

int ftdi_usb_purge_buffers ( struct ftdi_context ftdi)

Clears the buffers on the chip and the internal read buffer. While coded incorrectly, the result is satisfactory.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1read buffer purge failed
-2write buffer purge failed
-3USB device unavailable
Deprecated:
Use ftdi_tcioflush(struct ftdi_context *ftdi)

Definition at line 1168 of file ftdi.c.

References ftdi_error_return, ftdi_usb_purge_rx_buffer(), ftdi_usb_purge_tx_buffer(), and ftdi_context::usb_dev.

Referenced by Ftdi::Context::flush().

◆ ftdi_usb_close()

int ftdi_usb_close ( struct ftdi_context ftdi)

Closes the ftdi device. Call ftdi_deinit() if you're cleaning up.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1usb_release failed
-3ftdi context invalid

Definition at line 1197 of file ftdi.c.

References ftdi_error_return, ftdi_context::interface, and ftdi_context::usb_dev.

Referenced by Ftdi::Context::close(), and Ftdi::Context::Private::~Private().

◆ convert_baudrate_UT_export()

int convert_baudrate_UT_export ( int  baudrate,
struct ftdi_context ftdi,
unsigned short *  value,
unsigned short *  index 
)

Wrapper function to export ftdi_convert_baudrate() to the unit test Do not use, it's only for the unit test framework.

Definition at line 1431 of file ftdi.c.

◆ ftdi_set_baudrate()

int ftdi_set_baudrate ( struct ftdi_context ftdi,
int  baudrate 
)

Sets the chip baud rate

Parameters
ftdipointer to ftdi_context
baudratebaud rate to set
Return values
0all fine
-1invalid baudrate
-2setting baudrate failed
-3USB device unavailable

Definition at line 1448 of file ftdi.c.

References ftdi_context::bitbang_enabled, ftdi_error_return, and ftdi_context::usb_dev.

Referenced by Ftdi::Context::set_baud_rate().

◆ ftdi_set_line_property()

int ftdi_set_line_property ( struct ftdi_context ftdi,
enum ftdi_bits_type  bits,
enum ftdi_stopbits_type  sbit,
enum ftdi_parity_type  parity 
)

Set (RS232) line characteristics. The break type can only be set via ftdi_set_line_property2() and defaults to "off".

Parameters
ftdipointer to ftdi_context
bitsNumber of bits
sbitNumber of stop bits
parityParity mode
Return values
0all fine
-1Setting line property failed

Definition at line 1494 of file ftdi.c.

References BREAK_OFF, and ftdi_set_line_property2().

Referenced by Ftdi::Context::set_line_property().

◆ ftdi_set_line_property2()

int ftdi_set_line_property2 ( struct ftdi_context ftdi,
enum ftdi_bits_type  bits,
enum ftdi_stopbits_type  sbit,
enum ftdi_parity_type  parity,
enum ftdi_break_type  break_type 
)

Set (RS232) line characteristics

Parameters
ftdipointer to ftdi_context
bitsNumber of bits
sbitNumber of stop bits
parityParity mode
break_typeBreak type
Return values
0all fine
-1Setting line property failed
-2USB device unavailable

Definition at line 1513 of file ftdi.c.

References BREAK_OFF, BREAK_ON, EVEN, FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, MARK, NONE, ODD, SIO_SET_DATA_REQUEST, SPACE, STOP_BIT_1, STOP_BIT_15, STOP_BIT_2, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by ftdi_set_line_property(), and Ftdi::Context::set_line_property().

◆ ftdi_write_data()

int ftdi_write_data ( struct ftdi_context ftdi,
const unsigned char *  buf,
int  size 
)

Writes data in chunks (see ftdi_write_data_set_chunksize()) to the chip

Parameters
ftdipointer to ftdi_context
bufBuffer with the data
sizeSize of the buffer
Return values
-666USB device unavailable
<0error code from usb_bulk_write()
>0number of bytes written

Definition at line 1583 of file ftdi.c.

References ftdi_error_return, ftdi_context::in_ep, ftdi_context::usb_dev, ftdi_context::usb_write_timeout, and ftdi_context::writebuffer_chunksize.

Referenced by Ftdi::Context::write().

◆ ftdi_write_data_submit()

struct ftdi_transfer_control* ftdi_write_data_submit ( struct ftdi_context ftdi,
unsigned char *  buf,
int  size 
)

Writes data to the chip. Does not wait for completion of the transfer nor does it make sure that the transfer was successful.

Use libusb 1.0 asynchronous API.

Parameters
ftdipointer to ftdi_context
bufBuffer with the data
sizeSize of the buffer
Return values
NULLSome error happens when submit transfer
!NULLPointer to a ftdi_transfer_control

Definition at line 1743 of file ftdi.c.

References ftdi_transfer_control::buf, ftdi_transfer_control::completed, ftdi_transfer_control::ftdi, ftdi_context::in_ep, ftdi_transfer_control::offset, ftdi_transfer_control::size, ftdi_transfer_control::transfer, ftdi_context::usb_dev, and ftdi_context::writebuffer_chunksize.

◆ ftdi_read_data_submit()

struct ftdi_transfer_control* ftdi_read_data_submit ( struct ftdi_context ftdi,
unsigned char *  buf,
int  size 
)

Reads data from the chip. Does not wait for completion of the transfer nor does it make sure that the transfer was successful.

Use libusb 1.0 asynchronous API.

Parameters
ftdipointer to ftdi_context
bufBuffer with the data
sizeSize of the buffer
Return values
NULLSome error happens when submit transfer
!NULLPointer to a ftdi_transfer_control

Definition at line 1805 of file ftdi.c.

References ftdi_transfer_control::buf, ftdi_transfer_control::completed, ftdi_transfer_control::ftdi, ftdi_transfer_control::offset, ftdi_context::out_ep, ftdi_context::readbuffer, ftdi_context::readbuffer_chunksize, ftdi_context::readbuffer_offset, ftdi_context::readbuffer_remaining, ftdi_transfer_control::size, ftdi_transfer_control::transfer, and ftdi_context::usb_dev.

◆ ftdi_transfer_data_done()

int ftdi_transfer_data_done ( struct ftdi_transfer_control tc)

Wait for completion of the transfer.

Use libusb 1.0 asynchronous API.

Parameters
tcpointer to ftdi_transfer_control
Return values
<0: Some error happens
>=0: Data size transferred

tc->transfer could be NULL if "(size <= ftdi->readbuffer_remaining)" at ftdi_read_data_submit(). Therefore, we need to check it here.

Definition at line 1884 of file ftdi.c.

References ftdi_transfer_control::completed, ftdi_transfer_control::ftdi, ftdi_transfer_control::offset, ftdi_transfer_control::transfer, and ftdi_context::usb_ctx.

◆ ftdi_transfer_data_cancel()

void ftdi_transfer_data_cancel ( struct ftdi_transfer_control tc,
struct timeval *  to 
)

Cancel transfer and wait for completion.

Use libusb 1.0 asynchronous API.

Parameters
tcpointer to ftdi_transfer_control
topointer to timeout value or NULL for infinite

Definition at line 1931 of file ftdi.c.

References ftdi_transfer_control::completed, ftdi_transfer_control::ftdi, ftdi_transfer_control::transfer, and ftdi_context::usb_ctx.

◆ ftdi_write_data_set_chunksize()

int ftdi_write_data_set_chunksize ( struct ftdi_context ftdi,
unsigned int  chunksize 
)

Configure write buffer chunk size. Default is 4096.

Parameters
ftdipointer to ftdi_context
chunksizeChunk size
Return values
0all fine
-1ftdi context invalid

Definition at line 1965 of file ftdi.c.

References ftdi_error_return, and ftdi_context::writebuffer_chunksize.

Referenced by Ftdi::Context::set_write_chunk_size().

◆ ftdi_write_data_get_chunksize()

int ftdi_write_data_get_chunksize ( struct ftdi_context ftdi,
unsigned int *  chunksize 
)

Get write buffer chunk size.

Parameters
ftdipointer to ftdi_context
chunksizePointer to store chunk size in
Return values
0all fine
-1ftdi context invalid

Definition at line 1983 of file ftdi.c.

References ftdi_error_return, and ftdi_context::writebuffer_chunksize.

Referenced by Ftdi::Context::write_chunk_size().

◆ ftdi_read_data()

int ftdi_read_data ( struct ftdi_context ftdi,
unsigned char *  buf,
int  size 
)

Reads data in chunks (see ftdi_read_data_set_chunksize()) from the chip.

Automatically strips the two modem status bytes transferred during every read.

Parameters
ftdipointer to ftdi_context
bufBuffer to store data in
sizeSize of the buffer
Return values
-666USB device unavailable
<0error code from libusb_bulk_transfer()
0no data was available
>0number of bytes read

Definition at line 2007 of file ftdi.c.

References ftdi_error_return, ftdi_context::max_packet_size, ftdi_context::out_ep, ftdi_context::readbuffer, ftdi_context::readbuffer_chunksize, ftdi_context::readbuffer_offset, ftdi_context::readbuffer_remaining, ftdi_context::usb_dev, and ftdi_context::usb_read_timeout.

Referenced by Ftdi::Context::read().

◆ ftdi_read_data_set_chunksize()

int ftdi_read_data_set_chunksize ( struct ftdi_context ftdi,
unsigned int  chunksize 
)

Configure read buffer chunk size. Default is 4096.

Automatically reallocates the buffer.

Parameters
ftdipointer to ftdi_context
chunksizeChunk size
Return values
0all fine
-1ftdi context invalid

Definition at line 2133 of file ftdi.c.

References ftdi_error_return, ftdi_context::readbuffer, ftdi_context::readbuffer_chunksize, ftdi_context::readbuffer_offset, and ftdi_context::readbuffer_remaining.

Referenced by ftdi_init(), and Ftdi::Context::set_read_chunk_size().

◆ ftdi_read_data_get_chunksize()

int ftdi_read_data_get_chunksize ( struct ftdi_context ftdi,
unsigned int *  chunksize 
)

Get read buffer chunk size.

Parameters
ftdipointer to ftdi_context
chunksizePointer to store chunk size in
Return values
0all fine
-1FTDI context invalid

Definition at line 2170 of file ftdi.c.

References ftdi_error_return, and ftdi_context::readbuffer_chunksize.

Referenced by Ftdi::Context::read_chunk_size().

◆ ftdi_set_bitmode()

int ftdi_set_bitmode ( struct ftdi_context ftdi,
unsigned char  bitmask,
unsigned char  mode 
)

Enable/disable bitbang modes.

Parameters
ftdipointer to ftdi_context
bitmaskBitmask to configure lines. HIGH/ON value configures a line as output.
modeBitbang mode: use the values defined in ftdi_mpsse_mode
Return values
0all fine
-1can't enable bitbang mode
-2USB device unavailable

Definition at line 2191 of file ftdi.c.

References ftdi_context::bitbang_enabled, ftdi_context::bitbang_mode, BITMODE_RESET, FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_BITMODE_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by ftdi_readstream(), and Ftdi::Context::set_bitmode().

◆ ftdi_disable_bitbang()

int ftdi_disable_bitbang ( struct ftdi_context ftdi)

Disable bitbang mode.

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1can't disable bitbang mode
-2USB device unavailable

Definition at line 2217 of file ftdi.c.

References ftdi_context::bitbang_enabled, FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_BITMODE_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::bitbang_disable().

◆ ftdi_read_pins()

int ftdi_read_pins ( struct ftdi_context ftdi,
unsigned char *  pins 
)

Directly read pin state, circumventing the read buffer. Useful for bitbang mode.

Parameters
ftdipointer to ftdi_context
pinsPointer to store pins into
Return values
0all fine
-1read pins failed
-2USB device unavailable

Definition at line 2240 of file ftdi.c.

References FTDI_DEVICE_IN_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_READ_PINS_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_read_timeout.

Referenced by Ftdi::Context::read_pins().

◆ ftdi_set_latency_timer()

int ftdi_set_latency_timer ( struct ftdi_context ftdi,
unsigned char  latency 
)

Set latency timer

The FTDI chip keeps data in the internal buffer for a specific amount of time if the buffer is not full yet to decrease load on the usb bus.

Parameters
ftdipointer to ftdi_context
latencyValue between 1 and 255
Return values
0all fine
-1latency out of range
-2unable to set latency timer
-3USB device unavailable

Definition at line 2266 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_LATENCY_TIMER_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by ftdi_write_eeprom(), and Ftdi::Context::set_latency().

◆ ftdi_get_latency_timer()

int ftdi_get_latency_timer ( struct ftdi_context ftdi,
unsigned char *  latency 
)

Get latency timer

Parameters
ftdipointer to ftdi_context
latencyPointer to store latency value in
Return values
0all fine
-1unable to get latency timer
-2USB device unavailable

Definition at line 2293 of file ftdi.c.

References FTDI_DEVICE_IN_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_GET_LATENCY_TIMER_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_read_timeout.

Referenced by Ftdi::Context::latency().

◆ ftdi_poll_modem_status()

int ftdi_poll_modem_status ( struct ftdi_context ftdi,
unsigned short *  status 
)

Poll modem status information

This function allows the retrieve the two status bytes of the device. The device sends these bytes also as a header for each read access where they are discarded by ftdi_read_data(). The chip generates the two stripped status bytes in the absence of data every 40 ms.

Layout of the first byte:

  • B0..B3 - must be 0
  • B4 Clear to send (CTS) 0 = inactive 1 = active
  • B5 Data set ready (DTS) 0 = inactive 1 = active
  • B6 Ring indicator (RI) 0 = inactive 1 = active
  • B7 Receive line signal detect (RLSD) 0 = inactive 1 = active

Layout of the second byte:

  • B0 Data ready (DR)
  • B1 Overrun error (OE)
  • B2 Parity error (PE)
  • B3 Framing error (FE)
  • B4 Break interrupt (BI)
  • B5 Transmitter holding register (THRE)
  • B6 Transmitter empty (TEMT)
  • B7 Error in RCVR FIFO
Parameters
ftdipointer to ftdi_context
statusPointer to store status information in. Must be two bytes.
Return values
0all fine
-1unable to retrieve status information
-2USB device unavailable

Definition at line 2347 of file ftdi.c.

References FTDI_DEVICE_IN_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_POLL_MODEM_STATUS_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_read_timeout.

Referenced by ftdi_write_eeprom(), and Ftdi::Context::poll_modem_status().

◆ ftdi_setflowctrl()

int ftdi_setflowctrl ( struct ftdi_context ftdi,
int  flowctrl 
)

Set flowcontrol for ftdi chip

Note: Do not use this function to enable XON/XOFF mode, use ftdi_setflowctrl_xonxoff() instead.

Parameters
ftdipointer to ftdi_context
flowctrlflow control to use. should be SIO_DISABLE_FLOW_CTRL, SIO_RTS_CTS_HS, SIO_DTR_DSR_HS
Return values
0all fine
-1set flow control failed
-2USB device unavailable

Definition at line 2375 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_FLOW_CTRL_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::set_flow_control().

◆ ftdi_setflowctrl_xonxoff()

int ftdi_setflowctrl_xonxoff ( struct ftdi_context ftdi,
unsigned char  xon,
unsigned char  xoff 
)

Set XON/XOFF flowcontrol for ftdi chip

Parameters
ftdipointer to ftdi_context
xoncharacter code used to resume transmission
xoffcharacter code used to pause transmission
Return values
0all fine
-1set flow control failed
-2USB device unavailable

Definition at line 2399 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_FLOW_CTRL_REQUEST, SIO_XON_XOFF_HS, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

◆ ftdi_setdtr()

int ftdi_setdtr ( struct ftdi_context ftdi,
int  state 
)

Set dtr line

Parameters
ftdipointer to ftdi_context
statestate to set line to (1 or 0)
Return values
0all fine
-1set dtr failed
-2USB device unavailable

Definition at line 2423 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_DTR_HIGH, SIO_SET_DTR_LOW, SIO_SET_MODEM_CTRL_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::set_dtr().

◆ ftdi_setrts()

int ftdi_setrts ( struct ftdi_context ftdi,
int  state 
)

Set rts line

Parameters
ftdipointer to ftdi_context
statestate to set line to (1 or 0)
Return values
0all fine
-1set rts failed
-2USB device unavailable

Definition at line 2453 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_MODEM_CTRL_REQUEST, SIO_SET_RTS_HIGH, SIO_SET_RTS_LOW, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::set_rts().

◆ ftdi_setdtr_rts()

int ftdi_setdtr_rts ( struct ftdi_context ftdi,
int  dtr,
int  rts 
)

Set dtr and rts line in one pass

Parameters
ftdipointer to ftdi_context
dtrDTR state to set line to (1 or 0)
rtsRTS state to set line to (1 or 0)
Return values
0all fine
-1set dtr/rts failed
-2USB device unavailable

Definition at line 2484 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_DTR_HIGH, SIO_SET_DTR_LOW, SIO_SET_MODEM_CTRL_REQUEST, SIO_SET_RTS_HIGH, SIO_SET_RTS_LOW, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::set_modem_control().

◆ ftdi_set_event_char()

int ftdi_set_event_char ( struct ftdi_context ftdi,
unsigned char  eventch,
unsigned char  enable 
)

Set the special event character

Parameters
ftdipointer to ftdi_context
eventchEvent character
enable0 to disable the event character, non-zero otherwise
Return values
0all fine
-1unable to set event character
-2USB device unavailable

Definition at line 2520 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_EVENT_CHAR_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::set_event_char().

◆ ftdi_set_error_char()

int ftdi_set_error_char ( struct ftdi_context ftdi,
unsigned char  errorch,
unsigned char  enable 
)

Set error character

Parameters
ftdipointer to ftdi_context
errorchError character
enable0 to disable the error character, non-zero otherwise
Return values
0all fine
-1unable to set error character
-2USB device unavailable

Definition at line 2549 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_context::index, SIO_SET_ERROR_CHAR_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Context::set_error_char().

◆ ftdi_eeprom_initdefaults()

int ftdi_eeprom_initdefaults ( struct ftdi_context ftdi,
char *  manufacturer,
char *  product,
char *  serial 
)

Init eeprom with default values for the connected device

Parameters
ftdipointer to ftdi_context
manufacturerString to use as Manufacturer
productString to use as Product description
serialString to use as Serial number description
Return values
0all fine
-1No struct ftdi_context
-2No struct ftdi_eeprom
-3No connected device or device not yet opened

Definition at line 2579 of file ftdi.c.

References ftdi_eeprom::cbus_function, CBUS_PWREN, CBUS_RXLED, CBUS_SLEEP, CBUS_TXDEN, CBUS_TXLED, CBUSH_TRISTATE, CBUSX_RXLED, CBUSX_SLEEP, CBUSX_TXDEN, CBUSX_TXLED, ftdi_context::eeprom, ftdi_error_return, ftdi_eeprom::manufacturer, ftdi_eeprom::max_power, ftdi_eeprom::product, ftdi_eeprom::product_id, ftdi_eeprom::release_number, ftdi_eeprom::serial, ftdi_eeprom::size, ftdi_context::type, TYPE_2232C, TYPE_2232H, TYPE_230X, TYPE_232H, TYPE_4232H, TYPE_AM, TYPE_BM, TYPE_R, ftdi_context::usb_dev, ftdi_eeprom::usb_version, ftdi_eeprom::use_serial, and ftdi_eeprom::vendor_id.

Referenced by Ftdi::Eeprom::init_defaults().

◆ ftdi_eeprom_set_strings()

int ftdi_eeprom_set_strings ( struct ftdi_context ftdi,
const char *  manufacturer,
const char *  product,
const char *  serial 
)

◆ ftdi_eeprom_get_strings()

int ftdi_eeprom_get_strings ( struct ftdi_context ftdi,
char *  manufacturer,
int  mnf_len,
char *  product,
int  prod_len,
char *  serial,
int  serial_len 
)

Return device ID strings from the eeprom. Device needs to be connected.

The parameters manufacturer, description and serial may be NULL or pointer to buffers to store the fetched strings.

Parameters
ftdipointer to ftdi_context
manufacturerStore manufacturer string here if not NULL
mnf_lenBuffer size of manufacturer string
productStore product description string here if not NULL
prod_lenBuffer size of product description string
serialStore serial string here if not NULL
serial_lenBuffer size of serial string
Return values
0all fine
-1ftdi context invalid
-2ftdi eeprom buffer invalid

Definition at line 2793 of file ftdi.c.

References ftdi_context::eeprom, ftdi_error_return, ftdi_eeprom::manufacturer, ftdi_eeprom::product, and ftdi_eeprom::serial.

◆ set_ft232h_cbus()

void set_ft232h_cbus ( struct ftdi_eeprom eeprom,
unsigned char *  output 
)

Definition at line 2832 of file ftdi.c.

References ftdi_eeprom::cbus_function, CBUSH_CLK7_5, and CBUSH_TRISTATE.

◆ ftdi_eeprom_build()

int ftdi_eeprom_build ( struct ftdi_context ftdi)

Build binary buffer from ftdi_eeprom structure. Output is suitable for ftdi_write_eeprom().

Parameters
ftdipointer to ftdi_context
Return values
>=0size of eeprom user area in bytes
-1eeprom size (128 bytes) exceeded by custom strings
-2Invalid eeprom or ftdi pointer
-3Invalid cbus function setting (FIXME: Not in the code?)
-4Chip doesn't support invert (FIXME: Not in the code?)
-5Chip doesn't support high current drive (FIXME: Not in the code?)
-6No connected EEPROM or EEPROM Type unknown

Definition at line 2910 of file ftdi.c.

References ftdi_eeprom::buf, ftdi_eeprom::chip, ftdi_context::eeprom, ftdi_error_return, FTDI_MAX_EEPROM_SIZE, ftdi_eeprom::in_is_isochronous, ftdi_eeprom::is_not_pnp, ftdi_eeprom::manufacturer, ftdi_eeprom::max_power, MAX_POWER_MILLIAMP_PER_UNIT, ftdi_eeprom::out_is_isochronous, ftdi_eeprom::product, ftdi_eeprom::product_id, ftdi_eeprom::release_number, ftdi_eeprom::remote_wakeup, ftdi_eeprom::self_powered, ftdi_eeprom::serial, ftdi_eeprom::size, ftdi_context::type, TYPE_2232C, TYPE_2232H, TYPE_230X, TYPE_232H, TYPE_4232H, TYPE_AM, TYPE_BM, TYPE_R, ftdi_eeprom::usb_version, ftdi_eeprom::use_serial, USE_SERIAL_NUM, ftdi_eeprom::use_usb_version, USE_USB_VERSION_BIT, and ftdi_eeprom::vendor_id.

Referenced by Ftdi::Eeprom::build().

◆ ftdi_eeprom_decode()

int ftdi_eeprom_decode ( struct ftdi_context ftdi,
int  verbose 
)

Decode binary EEPROM image into an ftdi_eeprom structure.

For FT-X devices use AN_201 FT-X MTP memory Configuration to decode.

Parameters
ftdipointer to ftdi_context
verboseDecode EEPROM on stdout
Return values
0all fine
-1something went wrong

FIXME: How to pass size? How to handle size field in ftdi_eeprom? FIXME: Strings are malloc'ed here and should be freed somewhere

Definition at line 3548 of file ftdi.c.

References ftdi_eeprom::buf, ftdi_eeprom::channel_a_type, ftdi_eeprom::chip, ftdi_context::eeprom, ftdi_error_return, ftdi_eeprom::in_is_isochronous, ftdi_eeprom::manufacturer, ftdi_eeprom::max_power, MAX_POWER_MILLIAMP_PER_UNIT, ftdi_eeprom::out_is_isochronous, ftdi_eeprom::product, ftdi_eeprom::product_id, ftdi_eeprom::release_number, ftdi_eeprom::remote_wakeup, ftdi_eeprom::self_powered, ftdi_eeprom::serial, ftdi_eeprom::size, ftdi_eeprom::suspend_pull_downs, ftdi_context::type, TYPE_2232C, TYPE_230X, TYPE_AM, TYPE_BM, ftdi_eeprom::usb_version, ftdi_eeprom::use_serial, USE_SERIAL_NUM, ftdi_eeprom::use_usb_version, USE_USB_VERSION_BIT, and ftdi_eeprom::vendor_id.

◆ ftdi_get_eeprom_value()

int ftdi_get_eeprom_value ( struct ftdi_context ftdi,
enum ftdi_eeprom_value  value_name,
int *  value 
)

Get a value from the decoded EEPROM structure

Parameters
ftdipointer to ftdi_context
value_nameEnum of the value to query
valuePointer to store read value
Return values
0all fine
-1Value doesn't exist

Definition at line 3978 of file ftdi.c.

References ftdi_eeprom::cbus_function, CBUS_FUNCTION_0, CBUS_FUNCTION_1, CBUS_FUNCTION_2, CBUS_FUNCTION_3, CBUS_FUNCTION_4, CBUS_FUNCTION_5, CBUS_FUNCTION_6, CBUS_FUNCTION_7, CBUS_FUNCTION_8, CBUS_FUNCTION_9, ftdi_eeprom::channel_a_driver, CHANNEL_A_DRIVER, CHANNEL_A_RS485, ftdi_eeprom::channel_a_rs485enable, ftdi_eeprom::channel_a_type, CHANNEL_A_TYPE, ftdi_eeprom::channel_b_driver, CHANNEL_B_DRIVER, CHANNEL_B_RS485, ftdi_eeprom::channel_b_rs485enable, ftdi_eeprom::channel_b_type, CHANNEL_B_TYPE, ftdi_eeprom::channel_c_driver, CHANNEL_C_DRIVER, CHANNEL_C_RS485, ftdi_eeprom::channel_c_rs485enable, ftdi_eeprom::channel_d_driver, CHANNEL_D_DRIVER, CHANNEL_D_RS485, ftdi_eeprom::channel_d_rs485enable, ftdi_eeprom::chip, CHIP_SIZE, CHIP_TYPE, ftdi_eeprom::clock_polarity, CLOCK_POLARITY, ftdi_eeprom::data_order, DATA_ORDER, ftdi_context::eeprom, ftdi_eeprom::external_oscillator, EXTERNAL_OSCILLATOR, ftdi_eeprom::flow_control, FLOW_CONTROL, ftdi_error_return, ftdi_eeprom::group0_drive, GROUP0_DRIVE, ftdi_eeprom::group0_schmitt, GROUP0_SCHMITT, ftdi_eeprom::group0_slew, GROUP0_SLEW, ftdi_eeprom::group1_drive, GROUP1_DRIVE, ftdi_eeprom::group1_schmitt, GROUP1_SCHMITT, ftdi_eeprom::group1_slew, GROUP1_SLEW, ftdi_eeprom::group2_drive, GROUP2_DRIVE, ftdi_eeprom::group2_schmitt, GROUP2_SCHMITT, ftdi_eeprom::group2_slew, GROUP2_SLEW, ftdi_eeprom::group3_drive, GROUP3_DRIVE, ftdi_eeprom::group3_schmitt, GROUP3_SCHMITT, ftdi_eeprom::group3_slew, GROUP3_SLEW, ftdi_eeprom::high_current, HIGH_CURRENT, ftdi_eeprom::high_current_a, HIGH_CURRENT_A, ftdi_eeprom::high_current_b, HIGH_CURRENT_B, ftdi_eeprom::in_is_isochronous, IN_IS_ISOCHRONOUS, ftdi_eeprom::invert, INVERT, ftdi_eeprom::is_not_pnp, IS_NOT_PNP, ftdi_eeprom::max_power, MAX_POWER, ftdi_eeprom::out_is_isochronous, OUT_IS_ISOCHRONOUS, POWER_SAVE, ftdi_eeprom::powersave, ftdi_eeprom::product_id, PRODUCT_ID, ftdi_eeprom::release_number, RELEASE_NUMBER, ftdi_eeprom::remote_wakeup, REMOTE_WAKEUP, ftdi_eeprom::self_powered, SELF_POWERED, ftdi_eeprom::size, ftdi_eeprom::suspend_dbus7, SUSPEND_DBUS7, ftdi_eeprom::suspend_pull_downs, SUSPEND_PULL_DOWNS, ftdi_eeprom::usb_version, USB_VERSION, ftdi_eeprom::use_serial, USE_SERIAL, ftdi_eeprom::use_usb_version, USE_USB_VERSION, ftdi_eeprom::vendor_id, and VENDOR_ID.

◆ ftdi_set_eeprom_value()

int ftdi_set_eeprom_value ( struct ftdi_context ftdi,
enum ftdi_eeprom_value  value_name,
int  value 
)

Set a value in the decoded EEPROM Structure No parameter checking is performed

Parameters
ftdipointer to ftdi_context
value_nameEnum of the value to set
valueto set
Return values
0all fine
-1Value doesn't exist
-2Value not user settable

Definition at line 4171 of file ftdi.c.

References ftdi_eeprom::cbus_function, CBUS_FUNCTION_0, CBUS_FUNCTION_1, CBUS_FUNCTION_2, CBUS_FUNCTION_3, CBUS_FUNCTION_4, CBUS_FUNCTION_5, CBUS_FUNCTION_6, CBUS_FUNCTION_7, CBUS_FUNCTION_8, CBUS_FUNCTION_9, ftdi_eeprom::channel_a_driver, CHANNEL_A_DRIVER, CHANNEL_A_RS485, ftdi_eeprom::channel_a_rs485enable, ftdi_eeprom::channel_a_type, CHANNEL_A_TYPE, ftdi_eeprom::channel_b_driver, CHANNEL_B_DRIVER, CHANNEL_B_RS485, ftdi_eeprom::channel_b_rs485enable, ftdi_eeprom::channel_b_type, CHANNEL_B_TYPE, ftdi_eeprom::channel_c_driver, CHANNEL_C_DRIVER, CHANNEL_C_RS485, ftdi_eeprom::channel_c_rs485enable, ftdi_eeprom::channel_d_driver, CHANNEL_D_DRIVER, CHANNEL_D_RS485, ftdi_eeprom::channel_d_rs485enable, ftdi_eeprom::chip, CHIP_SIZE, CHIP_TYPE, ftdi_eeprom::clock_polarity, CLOCK_POLARITY, ftdi_eeprom::data_order, DATA_ORDER, ftdi_context::eeprom, ftdi_eeprom::external_oscillator, EXTERNAL_OSCILLATOR, ftdi_eeprom::flow_control, FLOW_CONTROL, ftdi_error_return, ftdi_eeprom::group0_drive, GROUP0_DRIVE, ftdi_eeprom::group0_schmitt, GROUP0_SCHMITT, ftdi_eeprom::group0_slew, GROUP0_SLEW, ftdi_eeprom::group1_drive, GROUP1_DRIVE, ftdi_eeprom::group1_schmitt, GROUP1_SCHMITT, ftdi_eeprom::group1_slew, GROUP1_SLEW, ftdi_eeprom::group2_drive, GROUP2_DRIVE, ftdi_eeprom::group2_schmitt, GROUP2_SCHMITT, ftdi_eeprom::group2_slew, GROUP2_SLEW, ftdi_eeprom::group3_drive, GROUP3_DRIVE, ftdi_eeprom::group3_schmitt, GROUP3_SCHMITT, ftdi_eeprom::group3_slew, GROUP3_SLEW, ftdi_eeprom::high_current, HIGH_CURRENT, ftdi_eeprom::high_current_a, HIGH_CURRENT_A, ftdi_eeprom::high_current_b, HIGH_CURRENT_B, ftdi_eeprom::in_is_isochronous, IN_IS_ISOCHRONOUS, ftdi_eeprom::initialized_for_connected_device, ftdi_eeprom::invert, INVERT, ftdi_eeprom::is_not_pnp, IS_NOT_PNP, ftdi_eeprom::max_power, MAX_POWER, ftdi_eeprom::out_is_isochronous, OUT_IS_ISOCHRONOUS, POWER_SAVE, ftdi_eeprom::powersave, ftdi_eeprom::product_id, PRODUCT_ID, ftdi_eeprom::release_number, RELEASE_NUMBER, ftdi_eeprom::remote_wakeup, REMOTE_WAKEUP, ftdi_eeprom::self_powered, SELF_POWERED, ftdi_eeprom::suspend_dbus7, SUSPEND_DBUS7, ftdi_eeprom::suspend_pull_downs, SUSPEND_PULL_DOWNS, ftdi_eeprom::usb_version, USB_VERSION, ftdi_eeprom::use_serial, USE_SERIAL, ftdi_eeprom::use_usb_version, USE_USB_VERSION, ftdi_eeprom::user_data_addr, USER_DATA_ADDR, ftdi_eeprom::vendor_id, and VENDOR_ID.

◆ ftdi_get_eeprom_buf()

int ftdi_get_eeprom_buf ( struct ftdi_context ftdi,
unsigned char *  buf,
int  size 
)

Get the read-only buffer to the binary EEPROM content

Parameters
ftdipointer to ftdi_context
bufbuffer to receive EEPROM content
sizeSize of receiving buffer
Return values
0All fine
-1struct ftdi_contxt or ftdi_eeprom missing
-2Not enough room to store eeprom

Definition at line 4367 of file ftdi.c.

References ftdi_eeprom::buf, ftdi_context::eeprom, ftdi_error_return, FTDI_MAX_EEPROM_SIZE, and ftdi_eeprom::size.

◆ ftdi_set_eeprom_buf()

int ftdi_set_eeprom_buf ( struct ftdi_context ftdi,
const unsigned char *  buf,
int  size 
)

Set the EEPROM content from the user-supplied prefilled buffer

Parameters
ftdipointer to ftdi_context
bufbuffer to read EEPROM content
sizeSize of buffer
Return values
0All fine
-1struct ftdi_context or ftdi_eeprom or buf missing

Definition at line 4393 of file ftdi.c.

References ftdi_eeprom::buf, ftdi_context::eeprom, ftdi_error_return, FTDI_MAX_EEPROM_SIZE, and ftdi_eeprom::size.

◆ ftdi_set_eeprom_user_data()

int ftdi_set_eeprom_user_data ( struct ftdi_context ftdi,
const char *  buf,
int  size 
)

Set the EEPROM user data content from the user-supplied prefilled buffer

Parameters
ftdipointer to ftdi_context
bufbuffer to read EEPROM user data content
sizeSize of buffer
Return values
0All fine
-1struct ftdi_context or ftdi_eeprom or buf missing

Definition at line 4416 of file ftdi.c.

References ftdi_eeprom::buf, ftdi_context::eeprom, ftdi_error_return, ftdi_eeprom::size, ftdi_eeprom::user_data, and ftdi_eeprom::user_data_size.

◆ ftdi_read_eeprom_location()

int ftdi_read_eeprom_location ( struct ftdi_context ftdi,
int  eeprom_addr,
unsigned short *  eeprom_val 
)

Read eeprom location

Parameters
ftdipointer to ftdi_context
eeprom_addrAddress of eeprom location to be read
eeprom_valPointer to store read eeprom location
Return values
0all fine
-1read failed
-2USB device unavailable

Definition at line 4437 of file ftdi.c.

References ftdi_eeprom::buf, FTDI_DEVICE_IN_REQTYPE, ftdi_error_return, SIO_READ_EEPROM_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_read_timeout.

Referenced by ftdi_erase_eeprom(), ftdi_write_eeprom_location(), and Ftdi::Eeprom::read_location().

◆ ftdi_read_eeprom()

int ftdi_read_eeprom ( struct ftdi_context ftdi)

Read eeprom

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1read failed
-2USB device unavailable

Definition at line 4461 of file ftdi.c.

References ftdi_eeprom::buf, ftdi_context::eeprom, FTDI_DEVICE_IN_REQTYPE, ftdi_error_return, FTDI_MAX_EEPROM_SIZE, SIO_READ_EEPROM_REQUEST, ftdi_eeprom::size, ftdi_context::type, TYPE_R, ftdi_context::usb_dev, and ftdi_context::usb_read_timeout.

Referenced by Ftdi::Eeprom::read().

◆ ftdi_read_chipid()

int ftdi_read_chipid ( struct ftdi_context ftdi,
unsigned int *  chipid 
)

Read the FTDIChip-ID from R-type devices

Parameters
ftdipointer to ftdi_context
chipidPointer to store FTDIChip-ID
Return values
0all fine
-1read failed
-2USB device unavailable

Definition at line 4520 of file ftdi.c.

References FTDI_DEVICE_IN_REQTYPE, ftdi_error_return, SIO_READ_EEPROM_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_read_timeout.

Referenced by Ftdi::Eeprom::chip_id().

◆ ftdi_write_eeprom_location()

int ftdi_write_eeprom_location ( struct ftdi_context ftdi,
int  eeprom_addr,
unsigned short  eeprom_val 
)

Write eeprom location

Parameters
ftdipointer to ftdi_context
eeprom_addrAddress of eeprom location to be written
eeprom_valValue to be written
Return values
0all fine
-1write failed
-2USB device unavailable
-3Invalid access to checksum protected area below 0x80
-4Device can't access unprotected area
-5Reading chip type failed

Definition at line 4558 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_read_eeprom_location(), SIO_WRITE_EEPROM_REQUEST, ftdi_context::type, TYPE_2232C, TYPE_2232H, TYPE_232H, TYPE_4232H, TYPE_BM, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Eeprom::write_location().

◆ ftdi_write_eeprom()

int ftdi_write_eeprom ( struct ftdi_context ftdi)

Write eeprom

Parameters
ftdipointer to ftdi_context
Return values
0all fine
-1read failed
-2USB device unavailable
-3EEPROM not initialized for the connected device;

Definition at line 4614 of file ftdi.c.

References ftdi_eeprom::buf, ftdi_context::eeprom, FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_poll_modem_status(), ftdi_set_latency_timer(), ftdi_usb_reset(), ftdi_eeprom::initialized_for_connected_device, SIO_WRITE_EEPROM_REQUEST, ftdi_eeprom::size, ftdi_context::type, TYPE_230X, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by Ftdi::Eeprom::write().

◆ ftdi_erase_eeprom()

int ftdi_erase_eeprom ( struct ftdi_context ftdi)

◆ ftdi_get_error_string()

const char* ftdi_get_error_string ( struct ftdi_context ftdi)

Get string representation for last error code

Parameters
ftdipointer to ftdi_context
Return values
Pointerto error string

Definition at line 4731 of file ftdi.c.

References ftdi_context::error_str.

Referenced by Ftdi::Context::error_string().

© Intra2net AG 2024 | Legal | Contact