deprecated bitbang_enable in C++ wrapper too
[libftdi] / ftdipp / ftdi.hpp
CommitLineData
cdf448f6
TJ
1/***************************************************************************
2 ftdi.hpp - C++ wrapper for libftdi
3 -------------------
4 begin : Mon Oct 13 2008
5 copyright : (C) 2008 by Marek Vavruša
6 email : opensource@intra2net.com and marek@vavrusa.com
7 ***************************************************************************/
3ab8f642
TJ
8/*
9Copyright (C) 2008 by Marek Vavruša
cdf448f6 10
3ab8f642
TJ
11The software in this package is distributed under the GNU General
12Public License version 2 (with a special exception described below).
13
14A copy of GNU General Public License (GPL) is included in this distribution,
15in the file COPYING.GPL.
16
17As a special exception, if other files instantiate templates or use macros
18or inline functions from this file, or you compile this file and link it
19with other works to produce a work based on this file, this file
20does not by itself cause the resulting work to be covered
21by the GNU General Public License.
22
23However the source code for this file must still be made available
24in accordance with section (3) of the GNU General Public License.
cdf448f6 25
3ab8f642
TJ
26This exception does not invalidate any other reasons why a work based
27on this file might be covered by the GNU General Public License.
28*/
cdf448f6
TJ
29#ifndef __libftdi_hpp__
30#define __libftdi_hpp__
20b1459a
TJ
31
32#include <list>
33#include <string>
cfceadbc 34#include <boost/shared_ptr.hpp>
20b1459a
TJ
35#include "ftdi.h"
36
37namespace Ftdi
38{
39
40/* Forward declarations*/
41class List;
42class Eeprom;
43
44/*! \brief FTDI device context.
45 * Represents single FTDI device context.
46 */
47class Context
48{
cdf448f6
TJ
49 /* Friends */
50 friend class Eeprom;
51 friend class List;
52
53public:
54 /*! \brief Direction flags for flush().
55 */
56 enum Direction
57 {
58 Input,
59 Output
60 };
61
62 /*! \brief Modem control flags.
63 */
64 enum ModemCtl
65 {
66 Dtr,
67 Rts
68 };
69
70 /* Constructor, Destructor */
71 Context();
72 ~Context();
73
74 /* Properties */
75 Eeprom* eeprom();
76 const std::string& vendor();
77 const std::string& description();
78 const std::string& serial();
79
80 /* Device manipulators */
81 bool is_open();
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());
84 int close();
85 int reset();
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);
89
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);
94
95 /* I/O */
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();
102
103 /* Async IO
104 TODO: should wrap?
105 int writeAsync(unsigned char *buf, int size);
106 void asyncComplete(int wait_for_more);
107 */
108
109 /* Flow control */
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);
117
118 unsigned short poll_modem_status();
119 unsigned latency();
120
121 /* BitBang mode */
122 int set_bitmode(unsigned char bitmask, unsigned char mode);
50ea6904 123 int DEPRECATED(bitbang_enable(unsigned char bitmask));
cdf448f6
TJ
124 int bitbang_disable();
125 int read_pins(unsigned char *pins);
126
127 /* Misc */
128 char* error_string();
129
130protected:
131 int get_strings();
132
133 /* Properties */
134 struct ftdi_context* context();
135 void set_context(struct ftdi_context* context);
136 void set_usb_device(struct usb_device *dev);
137
138private:
139 class Private;
cfceadbc 140 boost::shared_ptr<Private> d;
20b1459a
TJ
141};
142
143/*! \brief Device EEPROM.
144 */
145class Eeprom
146{
cdf448f6
TJ
147public:
148 Eeprom(Context* parent);
149 ~Eeprom();
150
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);
449c87a9 156
cdf448f6
TJ
157 int read(unsigned char *eeprom);
158 int write(unsigned char *eeprom);
449c87a9
TJ
159 int read_location(int eeprom_addr, unsigned short *eeprom_val);
160 int write_location(int eeprom_addr, unsigned short eeprom_val);
cdf448f6
TJ
161 int erase();
162
163private:
164 class Private;
cfceadbc 165 boost::shared_ptr<Private> d;
20b1459a
TJ
166};
167
20b1459a
TJ
168/*! \brief Device list.
169 */
6b22a054 170class List
20b1459a 171{
cdf448f6
TJ
172public:
173 List(struct ftdi_device_list* devlist = 0);
174 ~List();
20b1459a 175
cdf448f6 176 static List* find_all(int vendor, int product);
20b1459a 177
a14193ac
TJ
178 /// List type storing "Context" objects
179 typedef std::list<Context> ListType;
180 /// Iterator type for the container
181 typedef ListType::iterator iterator;
182 /// Const iterator type for the container
183 typedef ListType::const_iterator const_iterator;
184 /// Reverse iterator type for the container
185 typedef ListType::reverse_iterator reverse_iterator;
186 /// Const reverse iterator type for the container
187 typedef ListType::const_reverse_iterator const_reverse_iterator;
188
189 iterator begin();
190 iterator end();
191 const_iterator begin() const;
192 const_iterator end() const;
193
194 reverse_iterator rbegin();
195 reverse_iterator rend();
196 const_reverse_iterator rbegin() const;
197 const_reverse_iterator rend() const;
198
199 ListType::size_type size() const;
200 bool empty() const;
6b22a054
MV
201 void clear();
202
a14193ac
TJ
203 void push_back(const Context& element);
204 void push_front(const Context& element);
6b22a054 205
a14193ac
TJ
206 iterator erase(iterator pos);
207 iterator erase(iterator beg, iterator end);
6b22a054 208
cdf448f6
TJ
209private:
210 class Private;
cfceadbc 211 boost::shared_ptr<Private> d;
20b1459a
TJ
212};
213
214}
215
216#endif