00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __libftdi_hpp__
00018 #define __libftdi_hpp__
00019
00020 #include <list>
00021 #include <string>
00022 #include <boost/shared_ptr.hpp>
00023 #include "ftdi.h"
00024
00025 namespace Ftdi
00026 {
00027
00028
00029 class List;
00030 class Eeprom;
00031
00035 class Context
00036 {
00037
00038 friend class Eeprom;
00039 friend class List;
00040
00041 public:
00044 enum Direction
00045 {
00046 Input,
00047 Output
00048 };
00049
00052 enum ModemCtl
00053 {
00054 Dtr,
00055 Rts
00056 };
00057
00058
00059 Context();
00060 ~Context();
00061
00062
00063 Eeprom* eeprom();
00064 const std::string& vendor();
00065 const std::string& description();
00066 const std::string& serial();
00067
00068
00069 bool is_open();
00070 int open(struct usb_device *dev = 0);
00071 int open(int vendor, int product, const std::string& description = std::string(), const std::string& serial = std::string());
00072 int close();
00073 int reset();
00074 int flush(int mask = Input|Output);
00075 int set_interface(enum ftdi_interface interface);
00076 void set_usb_device(struct usb_dev_handle *dev);
00077
00078
00079 int set_baud_rate(int baudrate);
00080 int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
00081 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);
00082
00083
00084 int read(unsigned char *buf, int size);
00085 int write(unsigned char *buf, int size);
00086 int set_read_chunk_size(unsigned int chunksize);
00087 int set_write_chunk_size(unsigned int chunksize);
00088 int read_chunk_size();
00089 int write_chunk_size();
00090
00091
00092
00093
00094
00095
00096
00097
00098 int set_event_char(unsigned char eventch, unsigned char enable);
00099 int set_error_char(unsigned char errorch, unsigned char enable);
00100 int set_flow_control(int flowctrl);
00101 int set_modem_control(int mask = Dtr|Rts);
00102 int set_latency(unsigned char latency);
00103 int set_dtr(bool state);
00104 int set_rts(bool state);
00105
00106 unsigned short poll_modem_status();
00107 unsigned latency();
00108
00109
00110 int set_bitmode(unsigned char bitmask, unsigned char mode);
00111 int bitbang_enable(unsigned char bitmask);
00112 int bitbang_disable();
00113 int read_pins(unsigned char *pins);
00114
00115
00116 char* error_string();
00117
00118 protected:
00119 int get_strings();
00120
00121
00122 struct ftdi_context* context();
00123 void set_context(struct ftdi_context* context);
00124 void set_usb_device(struct usb_device *dev);
00125
00126 private:
00127 class Private;
00128 boost::shared_ptr<Private> d;
00129 };
00130
00133 class Eeprom
00134 {
00135 public:
00136 Eeprom(Context* parent);
00137 ~Eeprom();
00138
00139 void init_defaults();
00140 void set_size(int size);
00141 int size(unsigned char *eeprom, int maxsize);
00142 int chip_id(unsigned int *chipid);
00143 int build(unsigned char *output);
00144 int read(unsigned char *eeprom);
00145 int write(unsigned char *eeprom);
00146 int erase();
00147
00148 private:
00149 class Private;
00150 boost::shared_ptr<Private> d;
00151 };
00152
00153 typedef std::list<Context> ListBase;
00154
00157 class List : public ListBase
00158 {
00159 public:
00160 List(struct ftdi_device_list* devlist = 0);
00161 ~List();
00162
00163 static List* find_all(int vendor, int product);
00164
00165 private:
00166 class Private;
00167 boost::shared_ptr<Private> d;
00168 };
00169
00170 }
00171
00172 #endif