00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __libftdi_hpp__
00030 #define __libftdi_hpp__
00031
00032 #include <list>
00033 #include <string>
00034 #include <boost/shared_ptr.hpp>
00035 #include <ftdi.h>
00036
00037 namespace Ftdi
00038 {
00039
00040
00041 class List;
00042 class Eeprom;
00043
00047 class Context
00048 {
00049
00050 friend class Eeprom;
00051 friend class List;
00052
00053 public:
00056 enum Direction
00057 {
00058 Input,
00059 Output
00060 };
00061
00064 enum ModemCtl
00065 {
00066 Dtr,
00067 Rts
00068 };
00069
00070
00071 Context();
00072 ~Context();
00073
00074
00075 Eeprom* eeprom();
00076 const std::string& vendor();
00077 const std::string& description();
00078 const std::string& serial();
00079
00080
00081 bool is_open();
00082 int open(struct usb_device *dev = 0);
00083 int open(int vendor, int product, const std::string& description = std::string(), const std::string& serial = std::string());
00084 int close();
00085 int reset();
00086 int flush(int mask = Input|Output);
00087 int set_interface(enum ftdi_interface interface);
00088 void set_usb_device(struct usb_dev_handle *dev);
00089
00090
00091 int set_baud_rate(int baudrate);
00092 int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
00093 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);
00094
00095
00096 int read(unsigned char *buf, int size);
00097 int write(unsigned char *buf, int size);
00098 int set_read_chunk_size(unsigned int chunksize);
00099 int set_write_chunk_size(unsigned int chunksize);
00100 int read_chunk_size();
00101 int write_chunk_size();
00102
00103
00104
00105
00106
00107
00108
00109
00110 int set_event_char(unsigned char eventch, unsigned char enable);
00111 int set_error_char(unsigned char errorch, unsigned char enable);
00112 int set_flow_control(int flowctrl);
00113 int set_modem_control(int mask = Dtr|Rts);
00114 int set_latency(unsigned char latency);
00115 int set_dtr(bool state);
00116 int set_rts(bool state);
00117
00118 unsigned short poll_modem_status();
00119 unsigned latency();
00120
00121
00122 int set_bitmode(unsigned char bitmask, unsigned char mode);
00123 int bitbang_enable(unsigned char bitmask);
00124 int bitbang_disable();
00125 int read_pins(unsigned char *pins);
00126
00127
00128 char* error_string();
00129
00130 protected:
00131 int get_strings();
00132
00133
00134 struct ftdi_context* context();
00135 void set_context(struct ftdi_context* context);
00136 void set_usb_device(struct usb_device *dev);
00137
00138 private:
00139 class Private;
00140 boost::shared_ptr<Private> d;
00141 };
00142
00145 class Eeprom
00146 {
00147 public:
00148 Eeprom(Context* parent);
00149 ~Eeprom();
00150
00151 void init_defaults();
00152 void set_size(int size);
00153 int size(unsigned char *eeprom, int maxsize);
00154 int chip_id(unsigned int *chipid);
00155 int build(unsigned char *output);
00156 int read(unsigned char *eeprom);
00157 int write(unsigned char *eeprom);
00158 int erase();
00159
00160 private:
00161 class Private;
00162 boost::shared_ptr<Private> d;
00163 };
00164
00167 class List
00168 {
00169 public:
00170 List(struct ftdi_device_list* devlist = 0);
00171 ~List();
00172
00173 static List* find_all(int vendor, int product);
00174
00176 typedef std::list<Context> ListType;
00178 typedef ListType::iterator iterator;
00180 typedef ListType::const_iterator const_iterator;
00182 typedef ListType::reverse_iterator reverse_iterator;
00184 typedef ListType::const_reverse_iterator const_reverse_iterator;
00185
00186 iterator begin();
00187 iterator end();
00188 const_iterator begin() const;
00189 const_iterator end() const;
00190
00191 reverse_iterator rbegin();
00192 reverse_iterator rend();
00193 const_reverse_iterator rbegin() const;
00194 const_reverse_iterator rend() const;
00195
00196 ListType::size_type size() const;
00197 bool empty() const;
00198 void clear();
00199
00200 void push_back(const Context& element);
00201 void push_front(const Context& element);
00202
00203 iterator erase(iterator pos);
00204 iterator erase(iterator beg, iterator end);
00205
00206 private:
00207 class Private;
00208 boost::shared_ptr<Private> d;
00209 };
00210
00211 }
00212
00213 #endif