libftdi1: ftdi.hpp Source File

libftdi1 1.5

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ftdi.hpp
Go to the documentation of this file.
1 /***************************************************************************
2 ftdi.hpp - C++ wrapper for libftdi
3 -------------------
4 begin : Mon Oct 13 2008
5 copyright : (C) 2008-2020 by Marek Vavruša and libftdi developers
6 email : opensource@intra2net.com and marek@vavrusa.com
7 ***************************************************************************/
8 /*
9 Copyright (C) 2008-2017 by Marek Vavruša and libftdi developers
10
11 The software in this package is distributed under the GNU General
12 Public License version 2 (with a special exception described below).
13
14 A copy of GNU General Public License (GPL) is included in this distribution,
15 in the file COPYING.GPL.
16
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.
22
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.
25
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.
28 */
29 #ifndef __libftdi_hpp__
30 #define __libftdi_hpp__
31
32 #include <list>
33 #include <string>
34 #include <boost/shared_ptr.hpp>
35 #include <ftdi.h>
36
37 namespace Ftdi
38 {
39
40 /* Forward declarations*/
41 class List;
42 class Eeprom;
43
47 class Context
48 {
49 /* Friends */
50 friend class Eeprom;
51 friend class List;
52
53 public:
56 enum Direction
57 {
58 Input = 0x2,
59 Output = 0x1,
60 };
61
64 enum ModemCtl
65 {
66 Dtr = 0x2,
67 Rts = 0x1,
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 libusb_device *dev = 0);
83 int open(int vendor, int product);
84 int open(int vendor, int product, const std::string& description, const std::string& serial = std::string(), unsigned int index=0);
85 int open(const std::string& description);
86 int close();
87 int reset();
88 int DEPRECATED(flush)(int mask = Input|Output);
89 int tcflush(int mask = Input|Output);
90 int set_interface(enum ftdi_interface interface);
91 void set_usb_device(struct libusb_device_handle *dev);
92
93 /* Line manipulators */
94 int set_baud_rate(int baudrate);
95 int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
96 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);
97 int get_usb_read_timeout() const;
98 void set_usb_read_timeout(int usb_read_timeout);
99 int get_usb_write_timeout() const;
100 void set_usb_write_timeout(int usb_write_timeout);
101
102 /* I/O */
103 int read(unsigned char *buf, int size);
104 int write(const unsigned char *buf, int size);
105 int set_read_chunk_size(unsigned int chunksize);
106 int set_write_chunk_size(unsigned int chunksize);
107 int read_chunk_size();
108 int write_chunk_size();
109
110 /* Async IO
111 TODO: should wrap?
112 int writeAsync(const unsigned char *buf, int size);
113 void asyncComplete(int wait_for_more);
114 */
115
116 /* Flow control */
117 int set_event_char(unsigned char eventch, unsigned char enable);
118 int set_error_char(unsigned char errorch, unsigned char enable);
119 int set_flow_control(int flowctrl);
120 int set_modem_control(int mask = Dtr|Rts);
121 int set_latency(unsigned char latency);
122 int set_dtr(bool state);
123 int set_rts(bool state);
124
125 unsigned short poll_modem_status();
126 unsigned latency();
127
128 /* BitBang mode */
129 int set_bitmode(unsigned char bitmask, unsigned char mode);
130 int set_bitmode(unsigned char bitmask, enum ftdi_mpsse_mode mode);
131 int bitbang_disable();
132 int read_pins(unsigned char *pins);
133
134 /* Misc */
135 const char* error_string();
136
137 protected:
138 int get_strings(bool vendor=true, bool description=true, bool serial=true);
139 int get_strings_and_reopen(bool vendor=true, bool description=true, bool serial=true);
140
141 /* Properties */
142 struct ftdi_context* context();
143 void set_context(struct ftdi_context* context);
144 void set_usb_device(struct libusb_device *dev);
145
146 private:
147 class Private;
148 boost::shared_ptr<Private> d;
149 };
150
153 class Eeprom
154 {
155 public:
156 Eeprom(Context* parent);
157 ~Eeprom();
158
159 int init_defaults(char *manufacturer, char* product, char * serial);
160 int chip_id(unsigned int *chipid);
161 int build(unsigned char *output);
162
163 int read(unsigned char *eeprom);
164 int write(unsigned char *eeprom);
165 int read_location(int eeprom_addr, unsigned short *eeprom_val);
166 int write_location(int eeprom_addr, unsigned short eeprom_val);
167 int erase();
168
169 private:
170 class Private;
171 boost::shared_ptr<Private> d;
172 };
173
176 class List
177 {
178 public:
179 List(struct ftdi_device_list* devlist = 0);
180 ~List();
181
182 static List* find_all(Context &context, int vendor, int product);
183
185 typedef std::list<Context> ListType;
187 typedef ListType::iterator iterator;
189 typedef ListType::const_iterator const_iterator;
191 typedef ListType::reverse_iterator reverse_iterator;
193 typedef ListType::const_reverse_iterator const_reverse_iterator;
194
195 iterator begin();
196 iterator end();
197 const_iterator begin() const;
198 const_iterator end() const;
199
200 reverse_iterator rbegin();
201 reverse_iterator rend();
202 const_reverse_iterator rbegin() const;
203 const_reverse_iterator rend() const;
204
205 ListType::size_type size() const;
206 bool empty() const;
207 void clear();
208
209 void push_back(const Context& element);
210 void push_front(const Context& element);
211
212 iterator erase(iterator pos);
213 iterator erase(iterator beg, iterator end);
214
215 private:
216 class Private;
217 boost::shared_ptr<Private> d;
218 };
219
220 }
221
222 #endif
Ftdi::List::empty
bool empty() const
Definition: ftdi.cpp:634
Ftdi::Context::set_modem_control
int set_modem_control(int mask=Dtr|Rts)
Definition: ftdi.cpp:287
Ftdi::Context::tcflush
int tcflush(int mask=Input|Output)
Definition: ftdi.cpp:172
ftdi_device_list
list of usb devices created by ftdi_usb_find_all()
Definition: ftdi.h:394
Ftdi::List::end
iterator end()
Definition: ftdi.cpp:561
Ftdi::Context::write
int write(const unsigned char *buf, int size)
Definition: ftdi.cpp:263
Ftdi::Context::Output
Definition: ftdi.hpp:59
Ftdi::Context
FTDI device context. Represents single FTDI device context.
Definition: ftdi.hpp:47
Ftdi::Context::read_chunk_size
int read_chunk_size()
Definition: ftdi.cpp:254
Ftdi::Context::description
const std::string & description()
Device strings properties.
Definition: ftdi.cpp:418
Ftdi::List::rbegin
reverse_iterator rbegin()
Definition: ftdi.cpp:588
ftdi_interface
ftdi_interface
Definition: ftdi.h:82
Ftdi::List::push_front
void push_front(const Context &element)
Definition: ftdi.cpp:669
Ftdi::Context::read
int read(unsigned char *buf, int size)
Definition: ftdi.cpp:244
Ftdi::Context::Dtr
Definition: ftdi.hpp:66
Ftdi::Context::Direction
Direction
Direction flags for flush().
Definition: ftdi.hpp:56
Ftdi::Context::error_string
const char * error_string()
Definition: ftdi.cpp:358
Ftdi::List::iterator
ListType::iterator iterator
Iterator type for the container.
Definition: ftdi.hpp:187
Ftdi::Context::reset
int reset()
Definition: ftdi.cpp:141
Ftdi::Context::vendor
const std::string & vendor()
Device strings properties.
Definition: ftdi.cpp:409
Ftdi::Eeprom::~Eeprom
~Eeprom()
Definition: ftdi.cpp:467
ftdi_context
Main context structure for all libftdi functions.
Definition: ftdi.h:271
Ftdi::Eeprom::read_location
int read_location(int eeprom_addr, unsigned short *eeprom_val)
Definition: ftdi.cpp:496
Ftdi::List::ListType
std::list< Context > ListType
List type storing "Context" objects.
Definition: ftdi.hpp:185
Ftdi::Context::get_usb_write_timeout
int get_usb_write_timeout() const
Definition: ftdi.cpp:234
Ftdi::Context::~Context
~Context()
Destructor.
Definition: ftdi.cpp:74
Ftdi::Context::bitbang_disable
int bitbang_disable()
Definition: ftdi.cpp:348
Ftdi::Context::eeprom
Eeprom * eeprom()
Ftdi::Context::get_strings
int get_strings(bool vendor=true, bool description=true, bool serial=true)
Definition: ftdi.cpp:363
Ftdi::Context::flush
int DEPRECATED() flush(int mask=Input|Output)
Definition: ftdi.cpp:146
Ftdi::List::begin
iterator begin()
Definition: ftdi.cpp:552
Ftdi::Context::write_chunk_size
int write_chunk_size()
Definition: ftdi.cpp:273
Ftdi::Context::open
int open(struct libusb_device *dev=0)
Definition: ftdi.cpp:123
Ftdi::Context::set_latency
int set_latency(unsigned char latency)
Definition: ftdi.cpp:309
Ftdi::Context::serial
const std::string & serial()
Device strings properties.
Definition: ftdi.cpp:427
Ftdi::Context::ModemCtl
ModemCtl
Modem control flags.
Definition: ftdi.hpp:64
Ftdi::Context::Input
Definition: ftdi.hpp:58
Ftdi::Eeprom::erase
int erase()
Definition: ftdi.cpp:506
Ftdi::List::Private
Definition: ftdi.cpp:511
ftdi_bits_type
ftdi_bits_type
Definition: ftdi.h:62
Ftdi::Context::get_strings_and_reopen
int get_strings_and_reopen(bool vendor=true, bool description=true, bool serial=true)
Definition: ftdi.cpp:380
Ftdi::Context::set_interface
int set_interface(enum ftdi_interface interface)
Definition: ftdi.cpp:198
Ftdi::Context::set_read_chunk_size
int set_read_chunk_size(unsigned int chunksize)
Definition: ftdi.cpp:249
Ftdi::Context::get_usb_read_timeout
int get_usb_read_timeout() const
Definition: ftdi.cpp:224
Ftdi::Eeprom
Device EEPROM.
Definition: ftdi.hpp:153
Ftdi::Context::set_rts
int set_rts(bool state)
Definition: ftdi.cpp:304
Ftdi::Context::latency
unsigned latency()
Definition: ftdi.cpp:314
Ftdi::Context::close
int close()
Definition: ftdi.cpp:134
Ftdi::Context::poll_modem_status
unsigned short poll_modem_status()
Definition: ftdi.cpp:321
Ftdi::Context::set_usb_write_timeout
void set_usb_write_timeout(int usb_write_timeout)
Definition: ftdi.cpp:239
Ftdi::Context::set_write_chunk_size
int set_write_chunk_size(unsigned int chunksize)
Definition: ftdi.cpp:268
Ftdi
Definition: ftdi.cpp:35
Ftdi::List::reverse_iterator
ListType::reverse_iterator reverse_iterator
Reverse iterator type for the container.
Definition: ftdi.hpp:191
ftdi.h
Ftdi::Context::set_usb_read_timeout
void set_usb_read_timeout(int usb_read_timeout)
Definition: ftdi.cpp:229
Ftdi::List::rend
reverse_iterator rend()
Definition: ftdi.cpp:597
Ftdi::List::push_back
void push_back(const Context &element)
Definition: ftdi.cpp:660
Ftdi::Context::set_usb_device
void set_usb_device(struct libusb_device_handle *dev)
Definition: ftdi.cpp:203
Ftdi::List::List
List(struct ftdi_device_list *devlist=0)
Definition: ftdi.cpp:528
Ftdi::Context::set_flow_control
int set_flow_control(int flowctrl)
Definition: ftdi.cpp:282
Ftdi::List::erase
iterator erase(iterator pos)
Definition: ftdi.cpp:679
Ftdi::Eeprom::build
int build(unsigned char *output)
Definition: ftdi.cpp:481
ftdi_break_type
ftdi_break_type
Definition: ftdi.h:64
Ftdi::Eeprom::chip_id
int chip_id(unsigned int *chipid)
Definition: ftdi.cpp:476
Ftdi::Context::set_bitmode
int set_bitmode(unsigned char bitmask, unsigned char mode)
Definition: ftdi.cpp:338
Ftdi::List::~List
~List()
Definition: ftdi.cpp:544
Ftdi::Context::set_error_char
int set_error_char(unsigned char errorch, unsigned char enable)
Definition: ftdi.cpp:333
ftdi_parity_type
ftdi_parity_type
Definition: ftdi.h:58
Ftdi::Eeprom::Private
Definition: ftdi.cpp:450
DEPRECATED
#define DEPRECATED(func)
Definition: ftdi.h:252
Ftdi::Context::Context
Context()
Constructor.
Definition: ftdi.cpp:67
Ftdi::List::clear
void clear()
Definition: ftdi.cpp:644
Ftdi::Eeprom::init_defaults
int init_defaults(char *manufacturer, char *product, char *serial)
Definition: ftdi.cpp:471
ftdi_stopbits_type
ftdi_stopbits_type
Definition: ftdi.h:60
Ftdi::Context::set_dtr
int set_dtr(bool state)
Definition: ftdi.cpp:299
Ftdi::List
Device list.
Definition: ftdi.hpp:176
Ftdi::Context::set_line_property
int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity)
Definition: ftdi.cpp:214
Ftdi::List::const_iterator
ListType::const_iterator const_iterator
Const iterator type for the container.
Definition: ftdi.hpp:189
Ftdi::Context::context
struct ftdi_context * context()
Definition: ftdi.cpp:445
Ftdi::Context::Rts
Definition: ftdi.hpp:67
Ftdi::Eeprom::Eeprom
Eeprom(Context *parent)
Definition: ftdi.cpp:461
Ftdi::Eeprom::read
int read(unsigned char *eeprom)
Definition: ftdi.cpp:486
Ftdi::Context::set_baud_rate
int set_baud_rate(int baudrate)
Definition: ftdi.cpp:209
Ftdi::List::size
ListType::size_type size() const
Definition: ftdi.cpp:625
Ftdi::Eeprom::write
int write(unsigned char *eeprom)
Definition: ftdi.cpp:491
ftdi_mpsse_mode
ftdi_mpsse_mode
Definition: ftdi.h:67
Ftdi::List::const_reverse_iterator
ListType::const_reverse_iterator const_reverse_iterator
Const reverse iterator type for the container.
Definition: ftdi.hpp:193
Ftdi::List::find_all
static List * find_all(Context &context, int vendor, int product)
Definition: ftdi.cpp:695
Ftdi::Context::set_event_char
int set_event_char(unsigned char eventch, unsigned char enable)
Definition: ftdi.cpp:328
Ftdi::Context::is_open
bool is_open()
Definition: ftdi.cpp:78
Ftdi::Context::read_pins
int read_pins(unsigned char *pins)
Definition: ftdi.cpp:353
Ftdi::Context::set_context
void set_context(struct ftdi_context *context)
Definition: ftdi.cpp:434
Ftdi::Eeprom::write_location
int write_location(int eeprom_addr, unsigned short eeprom_val)
Definition: ftdi.cpp:501