Libftdi


Defines

#define ftdi_error_return(code, str)

Functions

int ftdi_init (struct ftdi_context *ftdi)
int ftdi_set_interface (struct ftdi_context *ftdi, enum ftdi_interface interface)
void ftdi_deinit (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)
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_reset (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_write_data (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)
void ftdi_eeprom_initdefaults (struct ftdi_eeprom *eeprom)
int ftdi_eeprom_build (struct ftdi_eeprom *eeprom, unsigned char *output)
int ftdi_read_eeprom (struct ftdi_context *ftdi, unsigned char *eeprom)
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)
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)

Detailed Description


Define Documentation

#define ftdi_error_return ( code,
str   ) 

Value:

do {  \
        ftdi->error_str = str;             \
        return code;                       \
   } while(0);


Function Documentation

int ftdi_init ( struct ftdi_context ftdi  ) 

Initializes a ftdi_context.

Parameters:
ftdi pointer to ftdi_context
Return values:
0,: all fine
-1,: couldn't allocate read buffer
Remarks:
This should be called before all functions

int ftdi_set_interface ( struct ftdi_context ftdi,
enum ftdi_interface  interface 
)

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

Parameters:
ftdi pointer to ftdi_context
interface Interface to use for FT2232C chips.
Return values:
0,: all fine
-1,: unknown interface

void ftdi_deinit ( struct ftdi_context ftdi  ) 

Deinitializes a ftdi_context.

Parameters:
ftdi pointer to ftdi_context

void ftdi_set_usbdev ( struct ftdi_context ftdi,
usb_dev_handle *  usb 
)

Use an already open libusb device.

Parameters:
ftdi pointer to ftdi_context
usb libusb usb_dev_handle to use

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:
ftdi pointer to ftdi_context
devlist Pointer where to store list of found devices
vendor Vendor ID to search for
product Product 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

void ftdi_list_free ( struct ftdi_device_list **  devlist  ) 

Frees a usb device list.

Parameters:
devlist USB device list created by ftdi_usb_find_all()

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:
ftdi pointer to ftdi_context
dev libusb usb_dev to use
manufacturer Store manufacturer string here if not NULL
mnf_len Buffer size of manufacturer string
description Store product description string here if not NULL
desc_len Buffer size of product description string
serial Store serial string here if not NULL
serial_len Buffer 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

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

Opens a ftdi device given by a usb_device.

Parameters:
ftdi pointer to ftdi_context
dev libusb usb_dev to use
Return values:
0,: all fine
-4,: unable to open device
-5,: unable to claim device
-6,: reset failed
-7,: set baudrate failed

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

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

Parameters:
ftdi pointer to ftdi_context
vendor Vendor ID
product Product ID
Return values:
same as 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:
ftdi pointer to ftdi_context
vendor Vendor ID
product Product ID
description Description to search for. Use NULL if not needed.
serial Serial 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

int ftdi_usb_reset ( struct ftdi_context ftdi  ) 

Resets the ftdi device.

Parameters:
ftdi pointer to ftdi_context
Return values:
0,: all fine
-1,: FTDI reset failed

int ftdi_usb_purge_buffers ( struct ftdi_context ftdi  ) 

Clears the buffers on the chip.

Parameters:
ftdi pointer to ftdi_context
Return values:
0,: all fine
-1,: write buffer purge failed
-2,: read buffer purge failed

int ftdi_usb_close ( struct ftdi_context ftdi  ) 

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

Parameters:
ftdi pointer to ftdi_context
Return values:
0,: all fine
-1,: usb_release failed
-2,: usb_close failed

int ftdi_set_baudrate ( struct ftdi_context ftdi,
int  baudrate 
)

Sets the chip baud rate

Parameters:
ftdi pointer to ftdi_context
baudrate baud rate to set
Return values:
0,: all fine
-1,: invalid baudrate
-2,: setting baudrate failed

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 by Alain Abbas

Parameters:
ftdi pointer to ftdi_context
bits Number of bits
sbit Number of stop bits
parity Parity mode
Return values:
0,: all fine
-1,: Setting line property failed

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:
ftdi pointer to ftdi_context
buf Buffer with the data
size Size of the buffer
Return values:
<0,: error code from usb_bulk_write()
>0,: number of bytes written

int ftdi_write_data_set_chunksize ( struct ftdi_context ftdi,
unsigned int  chunksize 
)

Configure write buffer chunk size. Default is 4096.

Parameters:
ftdi pointer to ftdi_context
chunksize Chunk size
Return values:
0,: all fine

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

Get write buffer chunk size.

Parameters:
ftdi pointer to ftdi_context
chunksize Pointer to store chunk size in
Return values:
0,: all fine

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 transfered during every read.

Parameters:
ftdi pointer to ftdi_context
buf Buffer to store data in
size Size of the buffer
Return values:
<0,: error code from usb_bulk_read()
0,: no data was available
>0,: number of bytes read
Remarks:
This function is not useful in bitbang mode. Use ftdi_read_pins() to get the current state of the pins.

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:
ftdi pointer to ftdi_context
chunksize Chunk size
Return values:
0,: all fine

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

Get read buffer chunk size.

Parameters:
ftdi pointer to ftdi_context
chunksize Pointer to store chunk size in
Return values:
0,: all fine

int ftdi_enable_bitbang ( struct ftdi_context ftdi,
unsigned char  bitmask 
)

Enable bitbang mode.

For advanced bitbang modes of the FT2232C chip use ftdi_set_bitmode().

Parameters:
ftdi pointer to ftdi_context
bitmask Bitmask to configure lines. HIGH/ON value configures a line as output.
Return values:
0,: all fine
-1,: can't enable bitbang mode

int ftdi_disable_bitbang ( struct ftdi_context ftdi  ) 

Disable bitbang mode.

Parameters:
ftdi pointer to ftdi_context
Return values:
0,: all fine
-1,: can't disable bitbang mode

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

Enable advanced bitbang mode for FT2232C chips.

Parameters:
ftdi pointer to ftdi_context
bitmask Bitmask to configure lines. HIGH/ON value configures a line as output.
mode Bitbang mode: 1 for normal mode, 2 for SPI mode
Return values:
0,: all fine
-1,: can't enable bitbang mode

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

Directly read pin state. Useful for bitbang mode.

Parameters:
ftdi pointer to ftdi_context
pins Pointer to store pins into
Return values:
0,: all fine
-1,: read pins failed

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:
ftdi pointer to ftdi_context
latency Value between 1 and 255
Return values:
0,: all fine
-1,: latency out of range
-2,: unable to set latency timer

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

Get latency timer

Parameters:
ftdi pointer to ftdi_context
latency Pointer to store latency value in
Return values:
0,: all fine
-1,: unable to get latency timer

void ftdi_eeprom_initdefaults ( struct ftdi_eeprom eeprom  ) 

Init eeprom with default values.

Parameters:
eeprom Pointer to ftdi_eeprom

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().

Parameters:
eeprom Pointer to ftdi_eeprom
output Buffer of 128 bytes to store eeprom image to
Return values:
>0,: used eeprom size
-1,: eeprom size (128 bytes) exceeded by custom strings

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

Read eeprom

Parameters:
ftdi pointer to ftdi_context
eeprom Pointer to store eeprom into
Return values:
0,: all fine
-1,: read failed

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

Write eeprom

Parameters:
ftdi pointer to ftdi_context
eeprom Pointer to read eeprom from
Return values:
0,: all fine
-1,: read failed

int ftdi_erase_eeprom ( struct ftdi_context ftdi  ) 

Erase eeprom

Parameters:
ftdi pointer to ftdi_context
Return values:
0,: all fine
-1,: erase failed

char* ftdi_get_error_string ( struct ftdi_context ftdi  ) 

Get string representation for last error code

Parameters:
ftdi pointer to ftdi_context
Return values:
Pointer to error string

int ftdi_setflowctrl ( struct ftdi_context ftdi,
int  flowctrl 
)

Set flowcontrol for ftdi chip

Parameters:
ftdi pointer to ftdi_context
flowctrl flow 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

int ftdi_setdtr ( struct ftdi_context ftdi,
int  state 
)

Set dtr line

Parameters:
ftdi pointer to ftdi_context
state state to set line to (1 or 0)
Return values:
0,: all fine
-1,: set dtr failed

int ftdi_setrts ( struct ftdi_context ftdi,
int  state 
)

Set rts line

Parameters:
ftdi pointer to ftdi_context
state state to set line to (1 or 0)
Return values:
0,: all fine
-1 set rts failed


Generated on Wed Dec 12 20:16:30 2007 for libftdi by  doxygen 1.5.4