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 = 0x2,
00059 Output = 0x1,
00060 };
00061
00064 enum ModemCtl
00065 {
00066 Dtr = 0x2,
00067 Rts = 0x1,
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 libusb_device *dev = 0);
00083 int open(int vendor, int product);
00084 int open(int vendor, int product, const std::string& description, const std::string& serial = std::string(), unsigned int index=0);
00085 int open(const std::string& description);
00086 int close();
00087 int reset();
00088 int flush(int mask = Input|Output);
00089 int set_interface(enum ftdi_interface interface);
00090 void set_usb_device(struct libusb_device_handle *dev);
00091
00092
00093 int set_baud_rate(int baudrate);
00094 int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
00095 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);
00096 int get_usb_read_timeout() const;
00097 void set_usb_read_timeout(int usb_read_timeout);
00098 int get_usb_write_timeout() const;
00099 void set_usb_write_timeout(int usb_write_timeout);
00100
00101
00102 int read(unsigned char *buf, int size);
00103 int write(const unsigned char *buf, int size);
00104 int set_read_chunk_size(unsigned int chunksize);
00105 int set_write_chunk_size(unsigned int chunksize);
00106 int read_chunk_size();
00107 int write_chunk_size();
00108
00109
00110
00111
00112
00113
00114
00115
00116 int set_event_char(unsigned char eventch, unsigned char enable);
00117 int set_error_char(unsigned char errorch, unsigned char enable);
00118 int set_flow_control(int flowctrl);
00119 int set_modem_control(int mask = Dtr|Rts);
00120 int set_latency(unsigned char latency);
00121 int set_dtr(bool state);
00122 int set_rts(bool state);
00123
00124 unsigned short poll_modem_status();
00125 unsigned latency();
00126
00127
00128 int set_bitmode(unsigned char bitmask, unsigned char mode);
00129 int set_bitmode(unsigned char bitmask, enum ftdi_mpsse_mode mode);
00130 int bitbang_disable();
00131 int read_pins(unsigned char *pins);
00132
00133
00134 const char* error_string();
00135
00136 protected:
00137 int get_strings(bool vendor=true, bool description=true, bool serial=true);
00138 int get_strings_and_reopen(bool vendor=true, bool description=true, bool serial=true);
00139
00140
00141 struct ftdi_context* context();
00142 void set_context(struct ftdi_context* context);
00143 void set_usb_device(struct libusb_device *dev);
00144
00145 private:
00146 class Private;
00147 boost::shared_ptr<Private> d;
00148 };
00149
00152 class Eeprom
00153 {
00154 public:
00155 Eeprom(Context* parent);
00156 ~Eeprom();
00157
00158 int init_defaults(char *manufacturer, char* product, char * serial);
00159 int chip_id(unsigned int *chipid);
00160 int build(unsigned char *output);
00161
00162 int read(unsigned char *eeprom);
00163 int write(unsigned char *eeprom);
00164 int read_location(int eeprom_addr, unsigned short *eeprom_val);
00165 int write_location(int eeprom_addr, unsigned short eeprom_val);
00166 int erase();
00167
00168 private:
00169 class Private;
00170 boost::shared_ptr<Private> d;
00171 };
00172
00175 class List
00176 {
00177 public:
00178 List(struct ftdi_device_list* devlist = 0);
00179 ~List();
00180
00181 static List* find_all(Context &context, int vendor, int product);
00182
00184 typedef std::list<Context> ListType;
00186 typedef ListType::iterator iterator;
00188 typedef ListType::const_iterator const_iterator;
00190 typedef ListType::reverse_iterator reverse_iterator;
00192 typedef ListType::const_reverse_iterator const_reverse_iterator;
00193
00194 iterator begin();
00195 iterator end();
00196 const_iterator begin() const;
00197 const_iterator end() const;
00198
00199 reverse_iterator rbegin();
00200 reverse_iterator rend();
00201 const_reverse_iterator rbegin() const;
00202 const_reverse_iterator rend() const;
00203
00204 ListType::size_type size() const;
00205 bool empty() const;
00206 void clear();
00207
00208 void push_back(const Context& element);
00209 void push_front(const Context& element);
00210
00211 iterator erase(iterator pos);
00212 iterator erase(iterator beg, iterator end);
00213
00214 private:
00215 class Private;
00216 boost::shared_ptr<Private> d;
00217 };
00218
00219 }
00220
00221 #endif