libftdi  0.20
Classes | Macros | Enumerations | Functions
ftdi.h File Reference
#include <usb.h>

Go to the source code of this file.

Classes

struct  ftdi_context
 Main context structure for all libftdi functions. More...
 
struct  ftdi_device_list
 list of usb devices created by ftdi_usb_find_all() More...
 
struct  ftdi_eeprom
 FTDI eeprom structure. More...
 

Macros

#define FTDI_DEFAULT_EEPROM_SIZE   128
 
#define MPSSE_WRITE_NEG   0x01 /* Write TDI/DO on negative TCK/SK edge*/
 
#define MPSSE_BITMODE   0x02 /* Write bits, not bytes */
 
#define MPSSE_READ_NEG   0x04 /* Sample TDO/DI on negative TCK/SK edge */
 
#define MPSSE_LSB   0x08 /* LSB first */
 
#define MPSSE_DO_WRITE   0x10 /* Write TDI/DO */
 
#define MPSSE_DO_READ   0x20 /* Read TDO/DI */
 
#define MPSSE_WRITE_TMS   0x40 /* Write TMS/CS */
 
#define SET_BITS_LOW   0x80
 
#define SET_BITS_HIGH   0x82
 
#define GET_BITS_LOW   0x81
 
#define GET_BITS_HIGH   0x83
 
#define LOOPBACK_START   0x84
 
#define LOOPBACK_END   0x85
 
#define TCK_DIVISOR   0x86
 
#define DIS_DIV_5   0x8a
 
#define EN_DIV_5   0x8b
 
#define EN_3_PHASE   0x8c
 
#define DIS_3_PHASE   0x8d
 
#define CLK_BITS   0x8e
 
#define CLK_BYTES   0x8f
 
#define CLK_WAIT_HIGH   0x94
 
#define CLK_WAIT_LOW   0x95
 
#define EN_ADAPTIVE   0x96
 
#define DIS_ADAPTIVE   0x97
 
#define CLK_BYTES_OR_HIGH   0x9c
 
#define CLK_BYTES_OR_LOW   0x0d
 
#define DRIVE_OPEN_COLLECTOR   0x9e
 
#define DIV_VALUE(rate)   (rate > 6000000)?0:((6000000/rate -1) > 0xffff)? 0xffff: (6000000/rate -1)
 
#define SEND_IMMEDIATE   0x87
 
#define WAIT_ON_HIGH   0x88
 
#define WAIT_ON_LOW   0x89
 
#define READ_SHORT   0x90
 
#define READ_EXTENDED   0x91
 
#define WRITE_SHORT   0x92
 
#define WRITE_EXTENDED   0x93
 
#define SIO_RESET   0 /* Reset the port */
 
#define SIO_MODEM_CTRL   1 /* Set the modem control register */
 
#define SIO_SET_FLOW_CTRL   2 /* Set flow control register */
 
#define SIO_SET_BAUD_RATE   3 /* Set baud rate */
 
#define SIO_SET_DATA   4 /* Set the data characteristics of the port */
 
#define FTDI_DEVICE_OUT_REQTYPE   (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT)
 
#define FTDI_DEVICE_IN_REQTYPE   (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN)
 
#define SIO_RESET_REQUEST   SIO_RESET
 
#define SIO_SET_BAUDRATE_REQUEST   SIO_SET_BAUD_RATE
 
#define SIO_SET_DATA_REQUEST   SIO_SET_DATA
 
#define SIO_SET_FLOW_CTRL_REQUEST   SIO_SET_FLOW_CTRL
 
#define SIO_SET_MODEM_CTRL_REQUEST   SIO_MODEM_CTRL
 
#define SIO_POLL_MODEM_STATUS_REQUEST   0x05
 
#define SIO_SET_EVENT_CHAR_REQUEST   0x06
 
#define SIO_SET_ERROR_CHAR_REQUEST   0x07
 
#define SIO_SET_LATENCY_TIMER_REQUEST   0x09
 
#define SIO_GET_LATENCY_TIMER_REQUEST   0x0A
 
#define SIO_SET_BITMODE_REQUEST   0x0B
 
#define SIO_READ_PINS_REQUEST   0x0C
 
#define SIO_READ_EEPROM_REQUEST   0x90
 
#define SIO_WRITE_EEPROM_REQUEST   0x91
 
#define SIO_ERASE_EEPROM_REQUEST   0x92
 
#define SIO_RESET_SIO   0
 
#define SIO_RESET_PURGE_RX   1
 
#define SIO_RESET_PURGE_TX   2
 
#define SIO_DISABLE_FLOW_CTRL   0x0
 
#define SIO_RTS_CTS_HS   (0x1 << 8)
 
#define SIO_DTR_DSR_HS   (0x2 << 8)
 
#define SIO_XON_XOFF_HS   (0x4 << 8)
 
#define SIO_SET_DTR_MASK   0x1
 
#define SIO_SET_DTR_HIGH   ( 1 | ( SIO_SET_DTR_MASK << 8))
 
#define SIO_SET_DTR_LOW   ( 0 | ( SIO_SET_DTR_MASK << 8))
 
#define SIO_SET_RTS_MASK   0x2
 
#define SIO_SET_RTS_HIGH   ( 2 | ( SIO_SET_RTS_MASK << 8 ))
 
#define SIO_SET_RTS_LOW   ( 0 | ( SIO_SET_RTS_MASK << 8 ))
 
#define SIO_RTS_CTS_HS   (0x1 << 8)
 
#define FTDI_URB_USERCONTEXT_COOKIE   ((void *)0x1)
 
#define DEPRECATED(func)   func
 
#define CBUS_TXDEN   0
 
#define CBUS_PWREN   1
 
#define CBUS_RXLED   2
 
#define CBUS_TXLED   3
 
#define CBUS_TXRXLED   4
 
#define CBUS_SLEEP   5
 
#define CBUS_CLK48   6
 
#define CBUS_CLK24   7
 
#define CBUS_CLK12   8
 
#define CBUS_CLK6   9
 
#define CBUS_IOMODE   10
 
#define CBUS_BB_WR   11
 
#define CBUS_BB_RD   12
 
#define INVERT_TXD   0x01
 
#define INVERT_RXD   0x02
 
#define INVERT_RTS   0x04
 
#define INVERT_CTS   0x08
 
#define INVERT_DTR   0x10
 
#define INVERT_DSR   0x20
 
#define INVERT_DCD   0x40
 
#define INVERT_RI   0x80
 
#define HIGH_CURRENT_DRIVE   0x04
 

Enumerations

enum  ftdi_chip_type {
  TYPE_AM =0, TYPE_BM =1, TYPE_2232C =2, TYPE_R =3,
  TYPE_2232H =4, TYPE_4232H =5, TYPE_232H = 6
}
 
enum  ftdi_parity_type {
  NONE =0, ODD =1, EVEN =2, MARK =3,
  SPACE =4
}
 
enum  ftdi_stopbits_type { STOP_BIT_1 =0, STOP_BIT_15 =1, STOP_BIT_2 =2 }
 
enum  ftdi_bits_type { BITS_7 =7, BITS_8 =8 }
 
enum  ftdi_break_type { BREAK_OFF =0, BREAK_ON =1 }
 
enum  ftdi_mpsse_mode {
  BITMODE_RESET = 0x00, BITMODE_BITBANG = 0x01, BITMODE_MPSSE = 0x02, BITMODE_SYNCBB = 0x04,
  BITMODE_MCU = 0x08, BITMODE_OPTO = 0x10, BITMODE_CBUS = 0x20, BITMODE_SYNCFF = 0x40
}
 
enum  ftdi_interface {
  INTERFACE_ANY = 0, INTERFACE_A = 1, INTERFACE_B = 2, INTERFACE_C = 3,
  INTERFACE_D = 4
}
 
enum  ftdi_module_detach_mode { AUTO_DETACH_SIO_MODULE = 0, DONT_DETACH_SIO_MODULE = 1 }
 

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 *usbdev)
 
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 (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_dev (struct ftdi_context *ftdi, struct usb_device *dev)
 
int ftdi_usb_open_string (struct ftdi_context *ftdi, const char *description)
 
int ftdi_usb_close (struct ftdi_context *ftdi)
 
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_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_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_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_write_data_async (struct ftdi_context *ftdi, unsigned char *buf, int size)
 
void ftdi_async_complete (struct ftdi_context *ftdi, int wait_for_more)
 
int DEPRECATED (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_rts (struct ftdi_context *ftdi, int dtr, int rts)
 
int ftdi_setdtr (struct ftdi_context *ftdi, int state)
 
int ftdi_setrts (struct ftdi_context *ftdi, int state)
 
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 *output, int size)
 
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 (struct ftdi_context *ftdi, unsigned char *eeprom)
 
int ftdi_erase_eeprom (struct ftdi_context *ftdi)
 
int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val)
 
int ftdi_write_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short eeprom_val)
 
char * ftdi_get_error_string (struct ftdi_context *ftdi)
 

Macro Definition Documentation

◆ FTDI_DEFAULT_EEPROM_SIZE

#define FTDI_DEFAULT_EEPROM_SIZE   128

Definition at line 20 of file ftdi.h.

◆ MPSSE_WRITE_NEG

#define MPSSE_WRITE_NEG   0x01 /* Write TDI/DO on negative TCK/SK edge*/

Definition at line 65 of file ftdi.h.

◆ MPSSE_BITMODE

#define MPSSE_BITMODE   0x02 /* Write bits, not bytes */

Definition at line 66 of file ftdi.h.

◆ MPSSE_READ_NEG

#define MPSSE_READ_NEG   0x04 /* Sample TDO/DI on negative TCK/SK edge */

Definition at line 67 of file ftdi.h.

◆ MPSSE_LSB

#define MPSSE_LSB   0x08 /* LSB first */

Definition at line 68 of file ftdi.h.

◆ MPSSE_DO_WRITE

#define MPSSE_DO_WRITE   0x10 /* Write TDI/DO */

Definition at line 69 of file ftdi.h.

◆ MPSSE_DO_READ

#define MPSSE_DO_READ   0x20 /* Read TDO/DI */

Definition at line 70 of file ftdi.h.

◆ MPSSE_WRITE_TMS

#define MPSSE_WRITE_TMS   0x40 /* Write TMS/CS */

Definition at line 71 of file ftdi.h.

◆ SET_BITS_LOW

#define SET_BITS_LOW   0x80

Definition at line 74 of file ftdi.h.

◆ SET_BITS_HIGH

#define SET_BITS_HIGH   0x82

Definition at line 77 of file ftdi.h.

◆ GET_BITS_LOW

#define GET_BITS_LOW   0x81

Definition at line 80 of file ftdi.h.

◆ GET_BITS_HIGH

#define GET_BITS_HIGH   0x83

Definition at line 81 of file ftdi.h.

◆ LOOPBACK_START

#define LOOPBACK_START   0x84

Definition at line 82 of file ftdi.h.

◆ LOOPBACK_END

#define LOOPBACK_END   0x85

Definition at line 83 of file ftdi.h.

◆ TCK_DIVISOR

#define TCK_DIVISOR   0x86

Definition at line 84 of file ftdi.h.

◆ DIS_DIV_5

#define DIS_DIV_5   0x8a

Definition at line 86 of file ftdi.h.

◆ EN_DIV_5

#define EN_DIV_5   0x8b

Definition at line 87 of file ftdi.h.

◆ EN_3_PHASE

#define EN_3_PHASE   0x8c

Definition at line 88 of file ftdi.h.

◆ DIS_3_PHASE

#define DIS_3_PHASE   0x8d

Definition at line 89 of file ftdi.h.

◆ CLK_BITS

#define CLK_BITS   0x8e

Definition at line 90 of file ftdi.h.

◆ CLK_BYTES

#define CLK_BYTES   0x8f

Definition at line 91 of file ftdi.h.

◆ CLK_WAIT_HIGH

#define CLK_WAIT_HIGH   0x94

Definition at line 92 of file ftdi.h.

◆ CLK_WAIT_LOW

#define CLK_WAIT_LOW   0x95

Definition at line 93 of file ftdi.h.

◆ EN_ADAPTIVE

#define EN_ADAPTIVE   0x96

Definition at line 94 of file ftdi.h.

◆ DIS_ADAPTIVE

#define DIS_ADAPTIVE   0x97

Definition at line 95 of file ftdi.h.

◆ CLK_BYTES_OR_HIGH

#define CLK_BYTES_OR_HIGH   0x9c

Definition at line 96 of file ftdi.h.

◆ CLK_BYTES_OR_LOW

#define CLK_BYTES_OR_LOW   0x0d

Definition at line 97 of file ftdi.h.

◆ DRIVE_OPEN_COLLECTOR

#define DRIVE_OPEN_COLLECTOR   0x9e

Definition at line 99 of file ftdi.h.

◆ DIV_VALUE

#define DIV_VALUE (   rate)    (rate > 6000000)?0:((6000000/rate -1) > 0xffff)? 0xffff: (6000000/rate -1)

Definition at line 102 of file ftdi.h.

◆ SEND_IMMEDIATE

#define SEND_IMMEDIATE   0x87

Definition at line 105 of file ftdi.h.

◆ WAIT_ON_HIGH

#define WAIT_ON_HIGH   0x88

Definition at line 106 of file ftdi.h.

◆ WAIT_ON_LOW

#define WAIT_ON_LOW   0x89

Definition at line 107 of file ftdi.h.

◆ READ_SHORT

#define READ_SHORT   0x90

Definition at line 110 of file ftdi.h.

◆ READ_EXTENDED

#define READ_EXTENDED   0x91

Definition at line 112 of file ftdi.h.

◆ WRITE_SHORT

#define WRITE_SHORT   0x92

Definition at line 115 of file ftdi.h.

◆ WRITE_EXTENDED

#define WRITE_EXTENDED   0x93

Definition at line 117 of file ftdi.h.

◆ SIO_RESET

#define SIO_RESET   0 /* Reset the port */

Definition at line 122 of file ftdi.h.

◆ SIO_MODEM_CTRL

#define SIO_MODEM_CTRL   1 /* Set the modem control register */

Definition at line 123 of file ftdi.h.

◆ SIO_SET_FLOW_CTRL

#define SIO_SET_FLOW_CTRL   2 /* Set flow control register */

Definition at line 124 of file ftdi.h.

◆ SIO_SET_BAUD_RATE

#define SIO_SET_BAUD_RATE   3 /* Set baud rate */

Definition at line 125 of file ftdi.h.

◆ SIO_SET_DATA

#define SIO_SET_DATA   4 /* Set the data characteristics of the port */

Definition at line 126 of file ftdi.h.

◆ FTDI_DEVICE_OUT_REQTYPE

#define FTDI_DEVICE_OUT_REQTYPE   (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT)

Definition at line 128 of file ftdi.h.

◆ FTDI_DEVICE_IN_REQTYPE

#define FTDI_DEVICE_IN_REQTYPE   (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN)

Definition at line 129 of file ftdi.h.

◆ SIO_RESET_REQUEST

#define SIO_RESET_REQUEST   SIO_RESET

Definition at line 132 of file ftdi.h.

◆ SIO_SET_BAUDRATE_REQUEST

#define SIO_SET_BAUDRATE_REQUEST   SIO_SET_BAUD_RATE

Definition at line 133 of file ftdi.h.

◆ SIO_SET_DATA_REQUEST

#define SIO_SET_DATA_REQUEST   SIO_SET_DATA

Definition at line 134 of file ftdi.h.

◆ SIO_SET_FLOW_CTRL_REQUEST

#define SIO_SET_FLOW_CTRL_REQUEST   SIO_SET_FLOW_CTRL

Definition at line 135 of file ftdi.h.

◆ SIO_SET_MODEM_CTRL_REQUEST

#define SIO_SET_MODEM_CTRL_REQUEST   SIO_MODEM_CTRL

Definition at line 136 of file ftdi.h.

◆ SIO_POLL_MODEM_STATUS_REQUEST

#define SIO_POLL_MODEM_STATUS_REQUEST   0x05

Definition at line 137 of file ftdi.h.

◆ SIO_SET_EVENT_CHAR_REQUEST

#define SIO_SET_EVENT_CHAR_REQUEST   0x06

Definition at line 138 of file ftdi.h.

◆ SIO_SET_ERROR_CHAR_REQUEST

#define SIO_SET_ERROR_CHAR_REQUEST   0x07

Definition at line 139 of file ftdi.h.

◆ SIO_SET_LATENCY_TIMER_REQUEST

#define SIO_SET_LATENCY_TIMER_REQUEST   0x09

Definition at line 140 of file ftdi.h.

◆ SIO_GET_LATENCY_TIMER_REQUEST

#define SIO_GET_LATENCY_TIMER_REQUEST   0x0A

Definition at line 141 of file ftdi.h.

◆ SIO_SET_BITMODE_REQUEST

#define SIO_SET_BITMODE_REQUEST   0x0B

Definition at line 142 of file ftdi.h.

◆ SIO_READ_PINS_REQUEST

#define SIO_READ_PINS_REQUEST   0x0C

Definition at line 143 of file ftdi.h.

◆ SIO_READ_EEPROM_REQUEST

#define SIO_READ_EEPROM_REQUEST   0x90

Definition at line 144 of file ftdi.h.

◆ SIO_WRITE_EEPROM_REQUEST

#define SIO_WRITE_EEPROM_REQUEST   0x91

Definition at line 145 of file ftdi.h.

◆ SIO_ERASE_EEPROM_REQUEST

#define SIO_ERASE_EEPROM_REQUEST   0x92

Definition at line 146 of file ftdi.h.

◆ SIO_RESET_SIO

#define SIO_RESET_SIO   0

Definition at line 149 of file ftdi.h.

◆ SIO_RESET_PURGE_RX

#define SIO_RESET_PURGE_RX   1

Definition at line 150 of file ftdi.h.

◆ SIO_RESET_PURGE_TX

#define SIO_RESET_PURGE_TX   2

Definition at line 151 of file ftdi.h.

◆ SIO_DISABLE_FLOW_CTRL

#define SIO_DISABLE_FLOW_CTRL   0x0

Definition at line 153 of file ftdi.h.

◆ SIO_RTS_CTS_HS [1/2]

#define SIO_RTS_CTS_HS   (0x1 << 8)

Definition at line 165 of file ftdi.h.

◆ SIO_DTR_DSR_HS

#define SIO_DTR_DSR_HS   (0x2 << 8)

Definition at line 155 of file ftdi.h.

◆ SIO_XON_XOFF_HS

#define SIO_XON_XOFF_HS   (0x4 << 8)

Definition at line 156 of file ftdi.h.

◆ SIO_SET_DTR_MASK

#define SIO_SET_DTR_MASK   0x1

Definition at line 158 of file ftdi.h.

◆ SIO_SET_DTR_HIGH

#define SIO_SET_DTR_HIGH   ( 1 | ( SIO_SET_DTR_MASK << 8))

Definition at line 159 of file ftdi.h.

◆ SIO_SET_DTR_LOW

#define SIO_SET_DTR_LOW   ( 0 | ( SIO_SET_DTR_MASK << 8))

Definition at line 160 of file ftdi.h.

◆ SIO_SET_RTS_MASK

#define SIO_SET_RTS_MASK   0x2

Definition at line 161 of file ftdi.h.

◆ SIO_SET_RTS_HIGH

#define SIO_SET_RTS_HIGH   ( 2 | ( SIO_SET_RTS_MASK << 8 ))

Definition at line 162 of file ftdi.h.

◆ SIO_SET_RTS_LOW

#define SIO_SET_RTS_LOW   ( 0 | ( SIO_SET_RTS_MASK << 8 ))

Definition at line 163 of file ftdi.h.

◆ SIO_RTS_CTS_HS [2/2]

#define SIO_RTS_CTS_HS   (0x1 << 8)

Definition at line 165 of file ftdi.h.

◆ FTDI_URB_USERCONTEXT_COOKIE

#define FTDI_URB_USERCONTEXT_COOKIE   ((void *)0x1)

Definition at line 169 of file ftdi.h.

◆ DEPRECATED

#define DEPRECATED (   func)    func

Definition at line 177 of file ftdi.h.

◆ CBUS_TXDEN

#define CBUS_TXDEN   0

TXDEN

Definition at line 257 of file ftdi.h.

◆ CBUS_PWREN

#define CBUS_PWREN   1

PWREN#

Definition at line 259 of file ftdi.h.

◆ CBUS_RXLED

#define CBUS_RXLED   2

RXLED#

Definition at line 261 of file ftdi.h.

◆ CBUS_TXLED

#define CBUS_TXLED   3

TXLED#

Definition at line 263 of file ftdi.h.

◆ CBUS_TXRXLED

#define CBUS_TXRXLED   4

RXLED# & TXLED#

Definition at line 265 of file ftdi.h.

◆ CBUS_SLEEP

#define CBUS_SLEEP   5

SLEEP#

Definition at line 267 of file ftdi.h.

◆ CBUS_CLK48

#define CBUS_CLK48   6

48 MHz clock

Definition at line 269 of file ftdi.h.

◆ CBUS_CLK24

#define CBUS_CLK24   7

24 MHz clock

Definition at line 271 of file ftdi.h.

◆ CBUS_CLK12

#define CBUS_CLK12   8

12 MHz clock

Definition at line 273 of file ftdi.h.

◆ CBUS_CLK6

#define CBUS_CLK6   9

6 MHz clock

Definition at line 275 of file ftdi.h.

◆ CBUS_IOMODE

#define CBUS_IOMODE   10

Bitbang IO Mode

Definition at line 277 of file ftdi.h.

◆ CBUS_BB_WR

#define CBUS_BB_WR   11

Bitbang IO WR#

Definition at line 279 of file ftdi.h.

◆ CBUS_BB_RD

#define CBUS_BB_RD   12

Bitbang IO RD#

Definition at line 281 of file ftdi.h.

◆ INVERT_TXD

#define INVERT_TXD   0x01

Invert TXD#

Definition at line 285 of file ftdi.h.

◆ INVERT_RXD

#define INVERT_RXD   0x02

Invert RXD#

Definition at line 287 of file ftdi.h.

◆ INVERT_RTS

#define INVERT_RTS   0x04

Invert RTS#

Definition at line 289 of file ftdi.h.

◆ INVERT_CTS

#define INVERT_CTS   0x08

Invert CTS#

Definition at line 291 of file ftdi.h.

◆ INVERT_DTR

#define INVERT_DTR   0x10

Invert DTR#

Definition at line 293 of file ftdi.h.

◆ INVERT_DSR

#define INVERT_DSR   0x20

Invert DSR#

Definition at line 295 of file ftdi.h.

◆ INVERT_DCD

#define INVERT_DCD   0x40

Invert DCD#

Definition at line 297 of file ftdi.h.

◆ INVERT_RI

#define INVERT_RI   0x80

Invert RI#

Definition at line 299 of file ftdi.h.

◆ HIGH_CURRENT_DRIVE

#define HIGH_CURRENT_DRIVE   0x04

High current drive.

Definition at line 302 of file ftdi.h.

Enumeration Type Documentation

◆ ftdi_chip_type

FTDI chip type

Enumerator
TYPE_AM 
TYPE_BM 
TYPE_2232C 
TYPE_R 
TYPE_2232H 
TYPE_4232H 
TYPE_232H 

Definition at line 23 of file ftdi.h.

◆ ftdi_parity_type

Parity mode for ftdi_set_line_property()

Enumerator
NONE 
ODD 
EVEN 
MARK 
SPACE 

Definition at line 25 of file ftdi.h.

◆ ftdi_stopbits_type

Number of stop bits for ftdi_set_line_property()

Enumerator
STOP_BIT_1 
STOP_BIT_15 
STOP_BIT_2 

Definition at line 27 of file ftdi.h.

◆ ftdi_bits_type

Number of bits for ftdi_set_line_property()

Enumerator
BITS_7 
BITS_8 

Definition at line 29 of file ftdi.h.

◆ ftdi_break_type

Break type for ftdi_set_line_property2()

Enumerator
BREAK_OFF 
BREAK_ON 

Definition at line 31 of file ftdi.h.

◆ ftdi_mpsse_mode

MPSSE bitbang modes

Enumerator
BITMODE_RESET 

switch off bitbang mode, back to regular serial/FIFO

BITMODE_BITBANG 

classical asynchronous bitbang mode, introduced with B-type chips

BITMODE_MPSSE 

MPSSE mode, available on 2232x chips

BITMODE_SYNCBB 

synchronous bitbang mode, available on 2232x and R-type chips

BITMODE_MCU 

MCU Host Bus Emulation mode, available on 2232x chips

BITMODE_OPTO 

Fast Opto-Isolated Serial Interface Mode, available on 2232x chips

BITMODE_CBUS 

Bitbang on CBUS pins of R-type chips, configure in EEPROM before

BITMODE_SYNCFF 

Single Channel Synchronous FIFO mode, available on 2232H chips

Definition at line 34 of file ftdi.h.

◆ ftdi_interface

Port interface for chips with multiple interfaces

Enumerator
INTERFACE_ANY 
INTERFACE_A 
INTERFACE_B 
INTERFACE_C 
INTERFACE_D 

Definition at line 48 of file ftdi.h.

◆ ftdi_module_detach_mode

Automatic loading / unloading of kernel modules

Enumerator
AUTO_DETACH_SIO_MODULE 
DONT_DETACH_SIO_MODULE 

Definition at line 58 of file ftdi.h.

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

References ftdi_init().

◆ 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

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.

◆ ftdi_deinit()

void ftdi_deinit ( struct ftdi_context ftdi)

Deinitializes a ftdi_context.

Parameters
ftdipointer to ftdi_context

Definition at line 205 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 230 of file ftdi.c.

References ftdi_deinit().

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

◆ ftdi_set_usbdev()

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

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

Definition at line 265 of file ftdi.c.

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

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

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

References ftdi_list_free().

◆ ftdi_usb_get_strings()

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
0all fine
-1wrong arguments
-4unable to open device
-7get product manufacturer failed
-8get product description failed
-9get serial number failed
-10unable to close device

Definition at line 358 of file ftdi.c.

References ftdi_device_list::dev, ftdi_error_return, and ftdi_context::usb_dev.

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

References ftdi_usb_open_desc().

Referenced by Ftdi::Context::is_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
-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

Definition at line 608 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

Definition at line 638 of file ftdi.c.

References ftdi_error_return, and ftdi_context::usb_dev.

Referenced by ftdi_usb_open_desc(), and ftdi_usb_open_string().

◆ ftdi_usb_open_dev()

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
0all fine
-3unable to config device
-4unable to open device
-5unable to claim device
-6reset failed
-7set baudrate failed
-8ftdi context invalid

Definition at line 457 of file ftdi.c.

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

◆ 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
-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
-11illegal description format
-12ftdi context invalid

Definition at line 739 of file ftdi.c.

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

◆ 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
-2usb_close failed
-3ftdi context invalid

Definition at line 942 of file ftdi.c.

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

◆ 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 837 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::Context::close(), and ftdi_write_eeprom().

◆ ftdi_usb_purge_rx_buffer()

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

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

◆ ftdi_usb_purge_tx_buffer()

int ftdi_usb_purge_tx_buffer ( struct ftdi_context ftdi)

Clears the write buffer on the chip.

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

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

◆ 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
0all fine
-1read buffer purge failed
-2write buffer purge failed
-3USB device unavailable

Definition at line 912 of file ftdi.c.

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

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

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

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

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

References BREAK_OFF, and ftdi_set_line_property2().

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

◆ 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 1167 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_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.

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
-666USB device unavailable
<0error code from usb_bulk_read()
0no data was available
>0number of bytes read

Definition at line 1538 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::set_line_property().

◆ 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 1663 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::read().

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

References ftdi_error_return, and ftdi_context::readbuffer_chunksize.

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

◆ ftdi_write_data()

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
-666USB device unavailable
<0error code from usb_bulk_write()
>0number of bytes written

Definition at line 1237 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.

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

References ftdi_error_return, and ftdi_context::writebuffer_chunksize.

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

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

References ftdi_error_return, and ftdi_context::writebuffer_chunksize.

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

◆ ftdi_write_data_async()

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
-666USB device unavailable
<0error code from usb_bulk_write()
>0number of bytes written

Definition at line 1457 of file ftdi.c.

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

◆ ftdi_async_complete()

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

Referenced by ftdi_usb_close().

◆ DEPRECATED()

int DEPRECATED ( ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask)  )

◆ 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 1744 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.

◆ 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 1768 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::bitbang_disable(), Ftdi::Context::set_bitmode(), and Ftdi::Context::set_error_char().

◆ 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 1795 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::set_bitmode().

◆ 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 1821 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_rts().

◆ 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 1848 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::set_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 1902 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().

◆ ftdi_setflowctrl()

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
0all fine
-1set flow control failed
-2USB device unavailable

Definition at line 1928 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.

◆ 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 2012 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.

◆ 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 1951 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.

◆ 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 1981 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_dtr().

◆ 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 2048 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.

◆ 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 2077 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_event_char().

◆ ftdi_eeprom_setsize()

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

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

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

◆ ftdi_eeprom_initdefaults()

void ftdi_eeprom_initdefaults ( struct ftdi_eeprom eeprom)

◆ ftdi_eeprom_free()

void ftdi_eeprom_free ( struct ftdi_eeprom eeprom)

Frees allocated memory in eeprom.

Parameters
eepromPointer to ftdi_eeprom

Definition at line 2158 of file ftdi.c.

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

◆ ftdi_eeprom_build()

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
>0free eeprom size
-1eeprom size (128 bytes) exceeded by custom strings
-2Invalid eeprom pointer
-3Invalid cbus function setting
-4Chip doesn't support invert
-5Chip doesn't support high current drive

Definition at line 2192 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_2232H, TYPE_232H, TYPE_4232H, TYPE_AM, TYPE_BM, TYPE_R, ftdi_eeprom::usb_version, ftdi_eeprom::use_serial, and ftdi_eeprom::vendor_id.

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

◆ ftdi_eeprom_decode()

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
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 2425 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_2232H, TYPE_232H, TYPE_4232H, TYPE_AM, TYPE_BM, TYPE_R, ftdi_eeprom::usb_version, ftdi_eeprom::use_serial, and ftdi_eeprom::vendor_id.

◆ ftdi_read_eeprom()

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

Definition at line 2640 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::build().

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

◆ ftdi_read_eeprom_getsize()

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
-1eeprom read failed
-2USB device unavailable
>=0size of eeprom

Definition at line 2719 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::set_size().

◆ ftdi_write_eeprom()

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

Definition at line 2778 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::read().

◆ ftdi_erase_eeprom()

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

Definition at line 2818 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::write_location().

◆ 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 2619 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::write().

◆ 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
-1read failed
-2USB device unavailable

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

◆ ftdi_get_error_string()

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

References ftdi_context::error_str.

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