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__
22 #include <boost/shared_ptr.hpp>
28 /* Forward declarations*/
32 /*! \brief FTDI device context.
33 * Represents single FTDI device context.
42 /*! \brief Direction flags for flush().
50 /*! \brief Modem control flags.
58 /* Constructor, Destructor */
64 const std::string& vendor();
65 const std::string& description();
66 const std::string& serial();
68 /* Device manipulators */
70 int open(struct usb_device *dev = 0);
71 int open(int vendor, int product, const std::string& description = std::string(), const std::string& serial = std::string());
74 int flush(int mask = Input|Output);
75 int set_interface(enum ftdi_interface interface);
76 void set_usb_device(struct usb_dev_handle *dev);
78 /* Line manipulators */
79 int set_baud_rate(int baudrate);
80 int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
81 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);
84 int read(unsigned char *buf, int size);
85 int write(unsigned char *buf, int size);
86 int set_read_chunk_size(unsigned int chunksize);
87 int set_write_chunk_size(unsigned int chunksize);
88 int read_chunk_size();
89 int write_chunk_size();
93 int writeAsync(unsigned char *buf, int size);
94 void asyncComplete(int wait_for_more);
98 int set_event_char(unsigned char eventch, unsigned char enable);
99 int set_error_char(unsigned char errorch, unsigned char enable);
100 int set_flow_control(int flowctrl);
101 int set_modem_control(int mask = Dtr|Rts);
102 int set_latency(unsigned char latency);
103 int set_dtr(bool state);
104 int set_rts(bool state);
106 unsigned short poll_modem_status();
110 int set_bitmode(unsigned char bitmask, unsigned char mode);
111 int bitbang_enable(unsigned char bitmask);
112 int bitbang_disable();
113 int read_pins(unsigned char *pins);
116 char* error_string();
122 struct ftdi_context* context();
123 void set_context(struct ftdi_context* context);
124 void set_usb_device(struct usb_device *dev);
128 boost::shared_ptr<Private> d;
131 /*! \brief Device EEPROM.
136 Eeprom(Context* parent);
139 void init_defaults();
140 void set_size(int size);
141 int size(unsigned char *eeprom, int maxsize);
142 int chip_id(unsigned int *chipid);
143 int build(unsigned char *output);
144 int read(unsigned char *eeprom);
145 int write(unsigned char *eeprom);
150 boost::shared_ptr<Private> d;
153 typedef std::list<Context> ListBase;
155 /*! \brief Device list.
157 class List : public ListBase
160 List(struct ftdi_device_list* devlist = 0);
163 static List* find_all(int vendor, int product);
167 boost::shared_ptr<Private> d;