libftdi  0.19
Classes | Defines | Functions
Libftdi

Classes

struct  usb_dev_handle

Defines

#define ftdi_error_return(code, str)

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, usb_dev_handle *usb)
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 usb_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, struct usb_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_string (struct ftdi_context *ftdi, const char *description)
int ftdi_usb_reset (struct ftdi_context *ftdi)
int ftdi_usb_purge_rx_buffer (struct ftdi_context *ftdi)
int ftdi_usb_purge_tx_buffer (struct ftdi_context *ftdi)
int ftdi_usb_purge_buffers (struct ftdi_context *ftdi)
int ftdi_usb_close (struct ftdi_context *ftdi)
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, unsigned char *buf, int size)
void ftdi_async_complete (struct ftdi_context *ftdi, int wait_for_more)
int ftdi_write_data_async (struct ftdi_context *ftdi, unsigned char *buf, int size)
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_enable_bitbang (struct ftdi_context *ftdi, unsigned char bitmask)
int ftdi_disable_bitbang (struct ftdi_context *ftdi)
int ftdi_set_bitmode (struct ftdi_context *ftdi, unsigned char bitmask, unsigned char mode)
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_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)
void ftdi_eeprom_setsize (struct ftdi_context *ftdi, struct ftdi_eeprom *eeprom, int size)
void ftdi_eeprom_initdefaults (struct ftdi_eeprom *eeprom)
void ftdi_eeprom_free (struct ftdi_eeprom *eeprom)
int ftdi_eeprom_build (struct ftdi_eeprom *eeprom, unsigned char *output)
int ftdi_eeprom_decode (struct ftdi_eeprom *eeprom, unsigned 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, unsigned char *eeprom)
int ftdi_read_chipid (struct ftdi_context *ftdi, unsigned int *chipid)
int ftdi_read_eeprom_getsize (struct ftdi_context *ftdi, unsigned char *eeprom, int maxsize)
int ftdi_write_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short eeprom_val)
int ftdi_write_eeprom (struct ftdi_context *ftdi, unsigned char *eeprom)
int ftdi_erase_eeprom (struct ftdi_context *ftdi)
char * ftdi_get_error_string (struct ftdi_context *ftdi)

Define Documentation

#define ftdi_error_return (   code,
  str 
)

Function Documentation

int ftdi_init ( struct ftdi_context ftdi)
struct ftdi_context* ftdi_new ( void  ) [read]

Allocate and initialize a new ftdi_context

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

Definition at line 137 of file ftdi.c.

References ftdi_init().

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

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:
0,:all fine
-1,:unknown interface
-2,:USB device unavailable

Definition at line 165 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, and ftdi_context::out_ep.

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

void ftdi_deinit ( struct ftdi_context ftdi)

Deinitializes a ftdi_context.

Parameters:
ftdipointer to ftdi_context

Definition at line 205 of file ftdi.c.

References ftdi_context::async_usb_buffer, and ftdi_context::readbuffer.

Referenced by Ftdi::List::find_all(), and ftdi_free().

void ftdi_free ( struct ftdi_context ftdi)

Deinitialize and free an ftdi_context.

Parameters:
ftdipointer to ftdi_context

Definition at line 230 of file ftdi.c.

References ftdi_deinit().

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

void ftdi_set_usbdev ( struct ftdi_context ftdi,
usb_dev_handle usb 
)

Use an already open libusb device.

Parameters:
ftdipointer to ftdi_context
usblibusb usb_dev_handle to use

Definition at line 242 of file ftdi.c.

References ftdi_context::usb_dev.

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

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

Finds all ftdi devices on the usb bus. Creates a new ftdi_device_list which needs to be deallocated by ftdi_list_free() after use.

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:
>0,:number of devices found
-1,:usb_find_busses() failed
-2,:usb_find_devices() failed
-3,:out of memory

Definition at line 265 of file ftdi.c.

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

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

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 308 of file ftdi.c.

References ftdi_device_list::next.

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

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 327 of file ftdi.c.

References ftdi_list_free().

int ftdi_usb_get_strings ( struct ftdi_context ftdi,
struct usb_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:
0,:all fine
-1,:wrong arguments
-4,:unable to open device
-7,:get product manufacturer failed
-8,:get product description failed
-9,:get serial number failed
-10,:unable to close device

Definition at line 358 of file ftdi.c.

References ftdi_error_return, and ftdi_context::usb_dev.

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

int ftdi_usb_open_dev ( struct ftdi_context ftdi,
struct usb_device *  dev 
)

Opens a ftdi device given by an usb_device.

Parameters:
ftdipointer to ftdi_context
devlibusb usb_dev to use
Return values:
0,:all fine
-3,:unable to config device
-4,:unable to open device
-5,:unable to claim device
-6,:reset failed
-7,:set baudrate failed
-8,:ftdi context invalid

Definition at line 457 of file ftdi.c.

References AUTO_DETACH_SIO_MODULE, ftdi_error_return, ftdi_set_baudrate(), ftdi_usb_reset(), ftdi_context::index, ftdi_context::interface, INTERFACE_A, ftdi_context::max_packet_size, ftdi_context::module_detach_mode, ftdi_context::type, TYPE_2232C, TYPE_2232H, TYPE_4232H, TYPE_AM, TYPE_BM, TYPE_R, and ftdi_context::usb_dev.

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

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 579 of file ftdi.c.

References ftdi_usb_open_desc().

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

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:
0,:all fine
-1,:usb_find_busses() failed
-2,:usb_find_devices() failed
-3,:usb device not found
-4,:unable to open device
-5,:unable to claim device
-6,:reset failed
-7,:set baudrate failed
-8,:get product description failed
-9,:get serial number failed
-10,:unable to close device

Definition at line 606 of file ftdi.c.

References ftdi_usb_open_desc_index().

Referenced by ftdi_usb_open().

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:
0,:all fine
-1,:usb_find_busses() failed
-2,:usb_find_devices() failed
-3,:usb device not found
-4,:unable to open device
-5,:unable to claim device
-6,:reset failed
-7,:set baudrate failed
-8,:get product description failed
-9,:get serial number failed
-10,:unable to close device
-11,:ftdi context invalid

Definition at line 636 of file ftdi.c.

References ftdi_error_return, ftdi_usb_open_dev(), and ftdi_context::usb_dev.

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

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:
0,:all fine
-1,:usb_find_busses() failed
-2,:usb_find_devices() failed
-3,:usb device not found
-4,:unable to open device
-5,:unable to claim device
-6,:reset failed
-7,:set baudrate failed
-8,:get product description failed
-9,:get serial number failed
-10,:unable to close device
-11,:illegal description format
-12,:ftdi context invalid

Definition at line 737 of file ftdi.c.

References ftdi_error_return, ftdi_usb_open_desc_index(), and ftdi_usb_open_dev().

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

int ftdi_usb_reset ( struct ftdi_context ftdi)

Resets the ftdi device.

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

Definition at line 835 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_usb_open_dev(), ftdi_write_eeprom(), and Ftdi::Context::reset().

int ftdi_usb_purge_rx_buffer ( struct ftdi_context ftdi)

Clears the read buffer on the chip and the internal read buffer.

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

Definition at line 861 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().

int ftdi_usb_purge_tx_buffer ( struct ftdi_context ftdi)

Clears the write buffer on the chip.

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

Definition at line 887 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().

int ftdi_usb_purge_buffers ( struct ftdi_context ftdi)

Clears the buffers on the chip and the internal read buffer.

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

Definition at line 910 of file ftdi.c.

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

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:
0,:all fine
-1,:usb_release failed
-2,:usb_close failed
-3,:ftdi context invalid

Definition at line 940 of file ftdi.c.

References ftdi_async_complete(), ftdi_error_return, ftdi_context::interface, and ftdi_context::usb_dev.

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

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:
0,:all fine
-1,:invalid baudrate
-2,:setting baudrate failed
-3,:USB device unavailable

Definition at line 1099 of file ftdi.c.

References ftdi_context::baudrate, ftdi_context::bitbang_enabled, FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, SIO_SET_BAUDRATE_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

Referenced by ftdi_usb_open_dev(), and Ftdi::Context::set_baud_rate().

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:
0,:all fine
-1,:Setting line property failed

Definition at line 1145 of file ftdi.c.

References BREAK_OFF, and ftdi_set_line_property2().

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

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:
0,:all fine
-1,:Setting line property failed
-2,:USB device unavailable

Definition at line 1164 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().

int ftdi_write_data ( struct ftdi_context ftdi,
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:
-666,:USB device unavailable
<0,:error code from usb_bulk_write()
>0,:number of bytes written

Definition at line 1234 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().

void ftdi_async_complete ( struct ftdi_context ftdi,
int  wait_for_more 
)

Wait until one or more async URBs are completed by the kernel and mark their positions in the async-buffer as unused.

Parameters:
ftdipointer to ftdi_context
wait_for_moreif != 0 wait for more than one write to complete (until write timeout)

Definition at line 1362 of file ftdi.c.

References ftdi_context::usb_write_timeout.

Referenced by ftdi_usb_close().

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

Writes data in chunks (see ftdi_write_data_set_chunksize()) to the chip. Does not wait for completion of the transfer nor does it make sure that the transfer was successful.

This function could be extended to use signals and callbacks to inform the caller of completion or error - but this is not done yet, volunteers welcome.

Works around libusb and directly accesses functions only available on Linux. Only available if compiled with --with-async-mode.

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

Definition at line 1454 of file ftdi.c.

References ftdi_error_return, ftdi_context::in_ep, ftdi_context::usb_dev, and ftdi_context::writebuffer_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:
0,:all fine
-1,:ftdi context invalid

Definition at line 1492 of file ftdi.c.

References ftdi_error_return, and ftdi_context::writebuffer_chunksize.

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

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:
0,:all fine
-1,:ftdi context invalid

Definition at line 1510 of file ftdi.c.

References ftdi_error_return, and ftdi_context::writebuffer_chunksize.

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

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.

Returns when at least one byte is available or when the latency timer has elapsed Automatically strips the two modem status bytes transfered during every read.

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

Definition at line 1535 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().

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:
0,:all fine
-1,:ftdi context invalid

Definition at line 1660 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().

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:
0,:all fine
-1,:FTDI context invalid

Definition at line 1689 of file ftdi.c.

References ftdi_error_return, and ftdi_context::readbuffer_chunksize.

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

int ftdi_enable_bitbang ( struct ftdi_context ftdi,
unsigned char  bitmask 
)

Enable bitbang mode.

Deprecated:
use ftdi_set_bitmode with mode BITMODE_BITBANG instead
Parameters:
ftdipointer to ftdi_context
bitmaskBitmask to configure lines. HIGH/ON value configures a line as output.
Return values:
0,:all fine
-1,:can't enable bitbang mode
-2,:USB device unavailable

Definition at line 1712 of file ftdi.c.

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

int ftdi_disable_bitbang ( struct ftdi_context ftdi)

Disable bitbang mode.

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

Definition at line 1741 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().

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:
0,:all fine
-1,:can't enable bitbang mode
-2,:USB device unavailable

Definition at line 1765 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::Context::set_bitmode().

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:
0,:all fine
-1,:read pins failed
-2,:USB device unavailable

Definition at line 1792 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().

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:
0,:all fine
-1,:latency out of range
-2,:unable to set latency timer
-3,:USB device unavailable

Definition at line 1818 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().

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:
0,:all fine
-1,:unable to get latency timer
-2,:USB device unavailable

Definition at line 1845 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().

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:
0,:all fine
-1,:unable to retrieve status information
-2,:USB device unavailable

Definition at line 1899 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().

int ftdi_setflowctrl ( struct ftdi_context ftdi,
int  flowctrl 
)

Set flowcontrol for ftdi chip

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

Definition at line 1925 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().

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:
0,:all fine
-1,:set dtr failed
-2,:USB device unavailable

Definition at line 1948 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().

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:
0,:all fine
-1,:set rts failed
-2,:USB device unavailable

Definition at line 1978 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().

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:
0,:all fine
-1,:set dtr/rts failed
-2,:USB device unavailable

Definition at line 2009 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().

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:
0,:all fine
-1,:unable to set event character
-2,:USB device unavailable

Definition at line 2045 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().

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:
0,:all fine
-1,:unable to set error character
-2,:USB device unavailable

Definition at line 2074 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().

void ftdi_eeprom_setsize ( struct ftdi_context ftdi,
struct ftdi_eeprom eeprom,
int  size 
)

Set the eeprom size

Parameters:
ftdipointer to ftdi_context
eepromPointer to ftdi_eeprom
size

Definition at line 2100 of file ftdi.c.

References ftdi_context::eeprom_size, and ftdi_eeprom::size.

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

void ftdi_eeprom_initdefaults ( struct ftdi_eeprom eeprom)
void ftdi_eeprom_free ( struct ftdi_eeprom eeprom)

Frees allocated memory in eeprom.

Parameters:
eepromPointer to ftdi_eeprom

Definition at line 2155 of file ftdi.c.

References ftdi_eeprom::manufacturer, ftdi_eeprom::product, and ftdi_eeprom::serial.

int ftdi_eeprom_build ( struct ftdi_eeprom eeprom,
unsigned char *  output 
)

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

Note:
This function doesn't handle FT2232x devices. Only FT232x.
Parameters:
eepromPointer to ftdi_eeprom
outputBuffer of 128 bytes to store eeprom image to
Return values:
>0,:free eeprom size
-1,:eeprom size (128 bytes) exceeded by custom strings
-2,:Invalid eeprom pointer
-3,:Invalid cbus function setting
-4,:Chip doesn't support invert
-5,:Chip doesn't support high current drive

Definition at line 2189 of file ftdi.c.

References ftdi_eeprom::cbus_function, ftdi_eeprom::change_usb_version, ftdi_eeprom::chip_type, ftdi_eeprom::high_current, HIGH_CURRENT_DRIVE, ftdi_eeprom::in_is_isochronous, ftdi_eeprom::invert, ftdi_eeprom::manufacturer, ftdi_eeprom::max_power, ftdi_eeprom::out_is_isochronous, ftdi_eeprom::product, ftdi_eeprom::product_id, ftdi_eeprom::remote_wakeup, ftdi_eeprom::self_powered, ftdi_eeprom::serial, ftdi_eeprom::size, ftdi_eeprom::suspend_pull_downs, TYPE_2232C, TYPE_AM, TYPE_BM, TYPE_R, ftdi_eeprom::usb_version, ftdi_eeprom::use_serial, and ftdi_eeprom::vendor_id.

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

int ftdi_eeprom_decode ( struct ftdi_eeprom eeprom,
unsigned char *  buf,
int  size 
)

Decode binary EEPROM image into an ftdi_eeprom structure.

Parameters:
eepromPointer to ftdi_eeprom which will be filled in.
bufBuffer of size bytes of raw eeprom data
sizesize size of eeprom data in bytes
Return values:
0,:all fine
-1,:something 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 2413 of file ftdi.c.

References ftdi_eeprom::cbus_function, ftdi_eeprom::change_usb_version, ftdi_eeprom::chip_type, ftdi_eeprom::high_current, HIGH_CURRENT_DRIVE, ftdi_eeprom::in_is_isochronous, ftdi_eeprom::invert, ftdi_eeprom::manufacturer, ftdi_eeprom::max_power, ftdi_eeprom::out_is_isochronous, ftdi_eeprom::product, ftdi_eeprom::product_id, ftdi_eeprom::remote_wakeup, ftdi_eeprom::self_powered, ftdi_eeprom::serial, ftdi_eeprom::size, ftdi_eeprom::suspend_pull_downs, TYPE_AM, TYPE_BM, TYPE_R, ftdi_eeprom::usb_version, ftdi_eeprom::use_serial, and ftdi_eeprom::vendor_id.

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:
0,:all fine
-1,:read failed
-2,:USB device unavailable

Definition at line 2598 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::read_location().

int ftdi_read_eeprom ( struct ftdi_context ftdi,
unsigned char *  eeprom 
)

Read eeprom

Parameters:
ftdipointer to ftdi_context
eepromPointer to store eeprom into
Return values:
0,:all fine
-1,:read failed
-2,:USB device unavailable

Definition at line 2619 of file ftdi.c.

References ftdi_context::eeprom_size, 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::read().

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:
0,:all fine
-1,:read failed
-2,:USB device unavailable

Definition at line 2662 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().

int ftdi_read_eeprom_getsize ( struct ftdi_context ftdi,
unsigned char *  eeprom,
int  maxsize 
)

Guesses size of eeprom by reading eeprom and comparing halves - will not work with blank eeprom Call this function then do a write then call again to see if size changes, if so write again.

Parameters:
ftdipointer to ftdi_context
eepromPointer to store eeprom into
maxsizethe size of the buffer to read into
Return values:
-1,:eeprom read failed
-2,:USB device unavailable
>=0,:size of eeprom

Definition at line 2698 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::size().

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:
0,:all fine
-1,:read failed
-2,:USB device unavailable

Definition at line 2734 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, SIO_WRITE_EEPROM_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

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

int ftdi_write_eeprom ( struct ftdi_context ftdi,
unsigned char *  eeprom 
)

Write eeprom

Parameters:
ftdipointer to ftdi_context
eepromPointer to read eeprom from
Return values:
0,:all fine
-1,:read failed
-2,:USB device unavailable

Definition at line 2757 of file ftdi.c.

References ftdi_context::eeprom_size, FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, ftdi_poll_modem_status(), ftdi_set_latency_timer(), ftdi_usb_reset(), SIO_WRITE_EEPROM_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

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

int ftdi_erase_eeprom ( struct ftdi_context ftdi)

Erase eeprom

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

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

Definition at line 2797 of file ftdi.c.

References FTDI_DEVICE_OUT_REQTYPE, ftdi_error_return, SIO_ERASE_EEPROM_REQUEST, ftdi_context::usb_dev, and ftdi_context::usb_write_timeout.

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

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 2815 of file ftdi.c.

References ftdi_context::error_str.

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