00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __libftdi_h__
00018 #define __libftdi_h__
00019
00020 #include <usb.h>
00021
00023 enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_2232C=2 };
00025 enum ftdi_parity_type { NONE=0, ODD=1, EVEN=2, MARK=3, SPACE=4 };
00027 enum ftdi_stopbits_type { STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2 };
00029 enum ftdi_bits_type { BITS_7=7, BITS_8=8 };
00030
00032 enum ftdi_mpsse_mode {
00033 BITMODE_RESET = 0x00,
00034 BITMODE_BITBANG= 0x01,
00035 BITMODE_MPSSE = 0x02,
00036 BITMODE_SYNCBB = 0x04,
00037 BITMODE_MCU = 0x08,
00038
00039 BITMODE_OPTO = 0x10,
00040 BITMODE_CBUS = 0x20
00041 };
00042
00044 enum ftdi_interface {
00045 INTERFACE_ANY = 0,
00046 INTERFACE_A = 1,
00047 INTERFACE_B = 2
00048 };
00049
00050
00051 #define MPSSE_WRITE_NEG 0x01
00052 #define MPSSE_BITMODE 0x02
00053 #define MPSSE_READ_NEG 0x04
00054 #define MPSSE_LSB 0x08
00055 #define MPSSE_DO_WRITE 0x10
00056 #define MPSSE_DO_READ 0x20
00057 #define MPSSE_WRITE_TMS 0x40
00058
00059
00060 #define SET_BITS_LOW 0x80
00061
00062
00063 #define SET_BITS_HIGH 0x82
00064
00065
00066 #define GET_BITS_LOW 0x81
00067 #define GET_BITS_HIGH 0x83
00068 #define LOOPBACK_START 0x84
00069 #define LOOPBACK_END 0x85
00070 #define TCK_DIVISOR 0x86
00071
00072
00073 #define DIV_VALUE(rate) (rate > 6000000)?0:((6000000/rate -1) > 0xffff)? 0xffff: (6000000/rate -1)
00074
00075
00076 #define SEND_IMMEDIATE 0x87
00077 #define WAIT_ON_HIGH 0x88
00078 #define WAIT_ON_LOW 0x89
00079
00080
00081 #define READ_SHORT 0x90
00082
00083 #define READ_EXTENDED 0x91
00084
00085
00086 #define WRITE_SHORT 0x92
00087
00088 #define WRITE_EXTENDED 0x93
00089
00090
00091
00092
00093 #define SIO_MODEM_CTRL 1
00094 #define SIO_SET_FLOW_CTRL 2
00095
00096 #define SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40
00097 #define SIO_SET_FLOW_CTRL_REQUEST SIO_SET_FLOW_CTRL
00098
00099 #define SIO_DISABLE_FLOW_CTRL 0x0
00100 #define SIO_RTS_CTS_HS (0x1 << 8)
00101 #define SIO_DTR_DSR_HS (0x2 << 8)
00102 #define SIO_XON_XOFF_HS (0x4 << 8)
00103
00104 #define SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40
00105 #define SIO_SET_MODEM_CTRL_REQUEST SIO_MODEM_CTRL
00106
00107 #define SIO_SET_DTR_MASK 0x1
00108 #define SIO_SET_DTR_HIGH ( 1 | ( SIO_SET_DTR_MASK << 8))
00109 #define SIO_SET_DTR_LOW ( 0 | ( SIO_SET_DTR_MASK << 8))
00110 #define SIO_SET_RTS_MASK 0x2
00111 #define SIO_SET_RTS_HIGH ( 2 | ( SIO_SET_RTS_MASK << 8 ))
00112 #define SIO_SET_RTS_LOW ( 0 | ( SIO_SET_RTS_MASK << 8 ))
00113
00114 #define SIO_RTS_CTS_HS (0x1 << 8)
00115
00121 struct ftdi_context {
00122
00124 struct usb_dev_handle *usb_dev;
00126 int usb_read_timeout;
00128 int usb_write_timeout;
00129
00130
00132 enum ftdi_chip_type type;
00134 int baudrate;
00136 unsigned char bitbang_enabled;
00138 unsigned char *readbuffer;
00140 unsigned int readbuffer_offset;
00142 unsigned int readbuffer_remaining;
00144 unsigned int readbuffer_chunksize;
00146 unsigned int writebuffer_chunksize;
00147
00148
00150 int interface;
00152 int index;
00153
00155 int in_ep;
00156 int out_ep;
00157
00159 unsigned char bitbang_mode;
00160
00162 char *error_str;
00163 };
00164
00168 struct ftdi_device_list {
00170 struct ftdi_device_list *next;
00172 struct usb_device *dev;
00173 };
00174
00178 struct ftdi_eeprom {
00180 int vendor_id;
00182 int product_id;
00183
00185 int self_powered;
00187 int remote_wakeup;
00189 int BM_type_chip;
00190
00192 int in_is_isochronous;
00194 int out_is_isochronous;
00196 int suspend_pull_downs;
00197
00199 int use_serial;
00201 int change_usb_version;
00203 int usb_version;
00205 int max_power;
00206
00208 char *manufacturer;
00210 char *product;
00212 char *serial;
00213 };
00214
00215 #ifdef __cplusplus
00216 extern "C" {
00217 #endif
00218
00219 int ftdi_init(struct ftdi_context *ftdi);
00220 int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface);
00221
00222 void ftdi_deinit(struct ftdi_context *ftdi);
00223 void ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle *usbdev);
00224
00225 int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devlist,
00226 int vendor, int product);
00227 void ftdi_list_free(struct ftdi_device_list **devlist);
00228 int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct usb_device *dev,
00229 char * manufacturer, int mnf_len,
00230 char * description, int desc_len,
00231 char * serial, int serial_len);
00232
00233 int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
00234 int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
00235 const char* description, const char* serial);
00236 int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct usb_device *dev);
00237
00238 int ftdi_usb_close(struct ftdi_context *ftdi);
00239 int ftdi_usb_reset(struct ftdi_context *ftdi);
00240 int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
00241
00242 int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
00243 int ftdi_set_line_property(struct ftdi_context *ftdi, enum ftdi_bits_type bits,
00244 enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
00245
00246 int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
00247 int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
00248 int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
00249
00250 int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
00251 int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
00252 int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
00253
00254 int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask);
00255 int ftdi_disable_bitbang(struct ftdi_context *ftdi);
00256 int ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char bitmask, unsigned char mode);
00257 int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
00258
00259 int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency);
00260 int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
00261
00262
00263 void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
00264 int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output);
00265
00266
00267
00268 int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
00269 int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
00270 int ftdi_erase_eeprom(struct ftdi_context *ftdi);
00271
00272 char *ftdi_get_error_string(struct ftdi_context *ftdi);
00273
00274
00275 int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
00276 int ftdi_setdtr(struct ftdi_context *ftdi, int state);
00277 int ftdi_setrts(struct ftdi_context *ftdi, int state);
00278
00279 #ifdef __cplusplus
00280 }
00281 #endif
00282
00283 #endif