X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=ftdipp%2Fftdi.hpp;h=d56660d6acd2417109d9c08f89a16f042aad5d86;hp=7b6a9a06c47bb7672394447a9fcc8c5351996ddf;hb=6b22a0549318d1e7fba0c1d9e28c1acf7b94f8b0;hpb=20b1459a95e9a287e7e552ba0211095a92d1a59a diff --git a/ftdipp/ftdi.hpp b/ftdipp/ftdi.hpp index 7b6a9a0..d56660d 100644 --- a/ftdipp/ftdi.hpp +++ b/ftdipp/ftdi.hpp @@ -1,8 +1,37 @@ -#ifndef FTDICPP_H -#define FTDICPP_H +/*************************************************************************** + ftdi.hpp - C++ wrapper for libftdi + ------------------- + begin : Mon Oct 13 2008 + copyright : (C) 2008 by Marek Vavruša + email : opensource@intra2net.com and marek@vavrusa.com + ***************************************************************************/ +/* +Copyright (C) 2008 by Marek Vavruša + +The software in this package is distributed under the GNU General +Public License version 2 (with a special exception described below). + +A copy of GNU General Public License (GPL) is included in this distribution, +in the file COPYING.GPL. + +As a special exception, if other files instantiate templates or use macros +or inline functions from this file, or you compile this file and link it +with other works to produce a work based on this file, this file +does not by itself cause the resulting work to be covered +by the GNU General Public License. + +However the source code for this file must still be made available +in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based +on this file might be covered by the GNU General Public License. +*/ +#ifndef __libftdi_hpp__ +#define __libftdi_hpp__ #include #include +#include #include "ftdi.h" namespace Ftdi @@ -17,142 +46,157 @@ class Eeprom; */ class Context { - /* Friends */ - friend class Eeprom; - friend class List; - - public: - - /*! \brief Direction flags for flush(). - */ - enum Direction - { - Input, - Output - }; - - /*! \brief Modem control flags. - */ - enum ModemCtl - { - Dtr, - Rts - }; - - /* Constructor, Destructor */ - Context(); - ~Context(); - - /* Properties */ - Eeprom* eeprom(); - const std::string& vendor(); - const std::string& description(); - const std::string& serial(); - - /* Device manipulators */ - bool is_open(); - int open(struct usb_device *dev = 0); - int open(int vendor, int product, const std::string& description = std::string(), const std::string& serial = std::string()); - int close(); - int reset(); - int flush(int mask = Input|Output); - int set_interface(enum ftdi_interface interface); - void set_usb_device(struct usb_dev_handle *dev); - - /* Line manipulators */ - int set_baud_rate(int baudrate); - int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity); - 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); - - /* I/O */ - int read(unsigned char *buf, int size); - int write(unsigned char *buf, int size); - int set_read_chunk_size(unsigned int chunksize); - int set_write_chunk_size(unsigned int chunksize); - int read_chunk_size(); - int write_chunk_size(); - - /* Async IO - TODO: should wrap? - int writeAsync(unsigned char *buf, int size); - void asyncComplete(int wait_for_more); - */ - - /* Flow control */ - int set_event_char(unsigned char eventch, unsigned char enable); - int set_error_char(unsigned char errorch, unsigned char enable); - int set_flow_control(int flowctrl); - int set_modem_control(int mask = Dtr|Rts); - int set_latency(unsigned char latency); - int set_dtr(bool state); - int set_rts(bool state); - - unsigned short poll_modem_status(); - unsigned latency(); - - /* BitBang mode */ - int set_bitmode(unsigned char bitmask, unsigned char mode); - int bitbang_enable(unsigned char bitmask); - int bitbang_disable(); - int read_pins(unsigned char *pins); - - /* Misc */ - char* error_string(); - - protected: - int get_strings(); - - /* Properties */ - struct ftdi_context* context(); - void set_context(struct ftdi_context* context); - void set_usb_device(struct usb_device *dev); - - private: - class Private; - Private *d; - - /* Disable copy constructor */ - Context(const Context &) {} - Context& operator=(const Context &) {} + /* Friends */ + friend class Eeprom; + friend class List; + +public: + /*! \brief Direction flags for flush(). + */ + enum Direction + { + Input, + Output + }; + + /*! \brief Modem control flags. + */ + enum ModemCtl + { + Dtr, + Rts + }; + + /* Constructor, Destructor */ + Context(); + ~Context(); + + /* Properties */ + Eeprom* eeprom(); + const std::string& vendor(); + const std::string& description(); + const std::string& serial(); + + /* Device manipulators */ + bool is_open(); + int open(struct usb_device *dev = 0); + int open(int vendor, int product, const std::string& description = std::string(), const std::string& serial = std::string()); + int close(); + int reset(); + int flush(int mask = Input|Output); + int set_interface(enum ftdi_interface interface); + void set_usb_device(struct usb_dev_handle *dev); + + /* Line manipulators */ + int set_baud_rate(int baudrate); + int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity); + 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); + + /* I/O */ + int read(unsigned char *buf, int size); + int write(unsigned char *buf, int size); + int set_read_chunk_size(unsigned int chunksize); + int set_write_chunk_size(unsigned int chunksize); + int read_chunk_size(); + int write_chunk_size(); + + /* Async IO + TODO: should wrap? + int writeAsync(unsigned char *buf, int size); + void asyncComplete(int wait_for_more); + */ + + /* Flow control */ + int set_event_char(unsigned char eventch, unsigned char enable); + int set_error_char(unsigned char errorch, unsigned char enable); + int set_flow_control(int flowctrl); + int set_modem_control(int mask = Dtr|Rts); + int set_latency(unsigned char latency); + int set_dtr(bool state); + int set_rts(bool state); + + unsigned short poll_modem_status(); + unsigned latency(); + + /* BitBang mode */ + int set_bitmode(unsigned char bitmask, unsigned char mode); + int bitbang_enable(unsigned char bitmask); + int bitbang_disable(); + int read_pins(unsigned char *pins); + + /* Misc */ + char* error_string(); + +protected: + int get_strings(); + + /* Properties */ + struct ftdi_context* context(); + void set_context(struct ftdi_context* context); + void set_usb_device(struct usb_device *dev); + +private: + class Private; + boost::shared_ptr d; }; /*! \brief Device EEPROM. */ class Eeprom { - public: - Eeprom(Context* parent); - ~Eeprom(); - - void init_defaults(); - void set_size(int size); - int size(unsigned char *eeprom, int maxsize); - int chip_id(unsigned int *chipid); - int build(unsigned char *output); - int read(unsigned char *eeprom); - int write(unsigned char *eeprom); - int erase(); - - private: - class Private; - Private *d; +public: + Eeprom(Context* parent); + ~Eeprom(); + + void init_defaults(); + void set_size(int size); + int size(unsigned char *eeprom, int maxsize); + int chip_id(unsigned int *chipid); + int build(unsigned char *output); + int read(unsigned char *eeprom); + int write(unsigned char *eeprom); + int erase(); + +private: + class Private; + boost::shared_ptr d; }; -typedef std::list ListBase; - /*! \brief Device list. */ -class List : public ListBase +class List { - public: - List(struct ftdi_device_list* devlist = 0); - ~List(); +public: + List(struct ftdi_device_list* devlist = 0); + ~List(); + + static List* find_all(int vendor, int product); + + /*! List size */ + int size(); + + /*! Append element */ + void push_back(const Context& element); + void append(const Context& element) + { push_back(element); } + + /*! Prepend element */ + void push_front(const Context& element); + void prepend(const Context& element) + { push_front(element); } + + /*! Clear list */ + void clear(); + + /* Iterators */ + typedef std::list::iterator iterator; + std::list::iterator begin(); + std::list::iterator end(); - static List* find_all(int vendor, int product); - private: - class Private; - Private *d; +private: + class Private; + boost::shared_ptr d; }; }