1 /***************************************************************************
2 ftdi.hpp - C++ wrapper for libftdi
4 begin : Mon Oct 13 2008
5 copyright : (C) 2008 by Marek VavruĊĦa
6 email : opensource@intra2net.com and marek@vavrusa.com
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU Lesser General Public License *
13 * version 2.1 as published by the Free Software Foundation; *
15 ***************************************************************************/
17 #ifndef __libftdi_hpp__
18 #define __libftdi_hpp__
27 /* Forward declarations*/
31 /*! \brief FTDI device context.
32 * Represents single FTDI device context.
41 /*! \brief Direction flags for flush().
49 /*! \brief Modem control flags.
57 /* Constructor, Destructor */
63 const std::string& vendor();
64 const std::string& description();
65 const std::string& serial();
67 /* Device manipulators */
69 int open(struct usb_device *dev = 0);
70 int open(int vendor, int product, const std::string& description = std::string(), const std::string& serial = std::string());
73 int flush(int mask = Input|Output);
74 int set_interface(enum ftdi_interface interface);
75 void set_usb_device(struct usb_dev_handle *dev);
77 /* Line manipulators */
78 int set_baud_rate(int baudrate);
79 int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
80 int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity, enum ftdi_break_type break_type);
83 int read(unsigned char *buf, int size);
84 int write(unsigned char *buf, int size);
85 int set_read_chunk_size(unsigned int chunksize);
86 int set_write_chunk_size(unsigned int chunksize);
87 int read_chunk_size();
88 int write_chunk_size();
92 int writeAsync(unsigned char *buf, int size);
93 void asyncComplete(int wait_for_more);
97 int set_event_char(unsigned char eventch, unsigned char enable);
98 int set_error_char(unsigned char errorch, unsigned char enable);
99 int set_flow_control(int flowctrl);
100 int set_modem_control(int mask = Dtr|Rts);
101 int set_latency(unsigned char latency);
102 int set_dtr(bool state);
103 int set_rts(bool state);
105 unsigned short poll_modem_status();
109 int set_bitmode(unsigned char bitmask, unsigned char mode);
110 int bitbang_enable(unsigned char bitmask);
111 int bitbang_disable();
112 int read_pins(unsigned char *pins);
115 char* error_string();
121 struct ftdi_context* context();
122 void set_context(struct ftdi_context* context);
123 void set_usb_device(struct usb_device *dev);
129 /* Disable copy constructor */
130 Context(const Context &) {}
131 Context& operator=(const Context &) {}
134 /*! \brief Device EEPROM.
139 Eeprom(Context* parent);
142 void init_defaults();
143 void set_size(int size);
144 int size(unsigned char *eeprom, int maxsize);
145 int chip_id(unsigned int *chipid);
146 int build(unsigned char *output);
147 int read(unsigned char *eeprom);
148 int write(unsigned char *eeprom);
156 typedef std::list<Context*> ListBase;
158 /*! \brief Device list.
160 class List : public ListBase
163 List(struct ftdi_device_list* devlist = 0);
166 static List* find_all(int vendor, int product);