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 Copyright (C) 2008 by Marek Vavruša
11 The software in this package is distributed under the GNU General
12 Public License version 2 (with a special exception described below).
14 A copy of GNU General Public License (GPL) is included in this distribution,
15 in the file COPYING.GPL.
17 As a special exception, if other files instantiate templates or use macros
18 or inline functions from this file, or you compile this file and link it
19 with other works to produce a work based on this file, this file
20 does not by itself cause the resulting work to be covered
21 by the GNU General Public License.
23 However the source code for this file must still be made available
24 in accordance with section (3) of the GNU General Public License.
26 This exception does not invalidate any other reasons why a work based
27 on this file might be covered by the GNU General Public License.
29 #ifndef __libftdi_hpp__
30 #define __libftdi_hpp__
34 #include <boost/shared_ptr.hpp>
40 /* Forward declarations*/
44 /*! \brief FTDI device context.
45 * Represents single FTDI device context.
54 /*! \brief Direction flags for flush().
62 /*! \brief Modem control flags.
70 /* Constructor, Destructor */
76 const std::string& vendor();
77 const std::string& description();
78 const std::string& serial();
80 /* Device manipulators */
82 int open(struct usb_device *dev = 0);
83 int open(int vendor, int product, const std::string& description = std::string(), const std::string& serial = std::string());
86 int flush(int mask = Input|Output);
87 int set_interface(enum ftdi_interface interface);
88 void set_usb_device(struct usb_dev_handle *dev);
90 /* Line manipulators */
91 int set_baud_rate(int baudrate);
92 int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
93 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);
96 int read(unsigned char *buf, int size);
97 int write(unsigned char *buf, int size);
98 int set_read_chunk_size(unsigned int chunksize);
99 int set_write_chunk_size(unsigned int chunksize);
100 int read_chunk_size();
101 int write_chunk_size();
105 int writeAsync(unsigned char *buf, int size);
106 void asyncComplete(int wait_for_more);
110 int set_event_char(unsigned char eventch, unsigned char enable);
111 int set_error_char(unsigned char errorch, unsigned char enable);
112 int set_flow_control(int flowctrl);
113 int set_modem_control(int mask = Dtr|Rts);
114 int set_latency(unsigned char latency);
115 int set_dtr(bool state);
116 int set_rts(bool state);
118 unsigned short poll_modem_status();
122 int set_bitmode(unsigned char bitmask, unsigned char mode);
123 int bitbang_enable(unsigned char bitmask);
124 int bitbang_disable();
125 int read_pins(unsigned char *pins);
128 char* error_string();
134 struct ftdi_context* context();
135 void set_context(struct ftdi_context* context);
136 void set_usb_device(struct usb_device *dev);
140 boost::shared_ptr<Private> d;
143 /*! \brief Device EEPROM.
148 Eeprom(Context* parent);
151 void init_defaults();
152 void set_size(int size);
153 int size(unsigned char *eeprom, int maxsize);
154 int chip_id(unsigned int *chipid);
155 int build(unsigned char *output);
156 int read(unsigned char *eeprom);
157 int write(unsigned char *eeprom);
162 boost::shared_ptr<Private> d;
165 /*! \brief Device list.
170 List(struct ftdi_device_list* devlist = 0);
173 static List* find_all(int vendor, int product);
175 /// List type storing "Context" objects
176 typedef std::list<Context> ListType;
177 /// Iterator type for the container
178 typedef ListType::iterator iterator;
179 /// Const iterator type for the container
180 typedef ListType::const_iterator const_iterator;
181 /// Reverse iterator type for the container
182 typedef ListType::reverse_iterator reverse_iterator;
183 /// Const reverse iterator type for the container
184 typedef ListType::const_reverse_iterator const_reverse_iterator;
188 const_iterator begin() const;
189 const_iterator end() const;
191 reverse_iterator rbegin();
192 reverse_iterator rend();
193 const_reverse_iterator rbegin() const;
194 const_reverse_iterator rend() const;
196 ListType::size_type size() const;
200 void push_back(const Context& element);
201 void push_front(const Context& element);
203 iterator erase(iterator pos);
204 iterator erase(iterator beg, iterator end);
208 boost::shared_ptr<Private> d;