ftdi.hpp
Go to the documentation of this file.
/***************************************************************************
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 <list>
#include <string>
#include <boost/shared_ptr.hpp>
#include <ftdi.h>
namespace Ftdi
{
/* Forward declarations*/
class List;
class Eeprom;
class Context
{
/* Friends */
friend class Eeprom;
friend class List;
public:
enum Direction
{
Input,
Output
};
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);
int open(int vendor, int product, const std::string& description, const std::string& serial = std::string(), unsigned int index=0);
int open(const std::string& description);
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 set_bitmode(unsigned char bitmask, enum ftdi_mpsse_mode mode);
int DEPRECATED(bitbang_enable(unsigned char bitmask));
int bitbang_disable();
int read_pins(unsigned char *pins);
/* Misc */
char* error_string();
protected:
int get_strings();
int get_strings_and_reopen();
/* 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<Private> d;
};
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 read_location(int eeprom_addr, unsigned short *eeprom_val);
int write_location(int eeprom_addr, unsigned short eeprom_val);
int erase();
private:
class Private;
boost::shared_ptr<Private> d;
};
class List
{
public:
List(struct ftdi_device_list* devlist = 0);
~List();
static List* find_all(int vendor, int product);
typedef std::list<Context> ListType;
typedef ListType::iterator iterator;
typedef ListType::const_iterator const_iterator;
typedef ListType::reverse_iterator reverse_iterator;
typedef ListType::const_reverse_iterator const_reverse_iterator;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
ListType::size_type size() const;
bool empty() const;
void clear();
void push_back(const Context& element);
void push_front(const Context& element);
iterator erase(iterator pos);
iterator erase(iterator beg, iterator end);
private:
class Private;
boost::shared_ptr<Private> d;
};
}
#endif
ftdi_mpsse_mode
ftdi_mpsse_mode
Definition: ftdi.h:34
Ftdi::List::iterator
ListType::iterator iterator
Iterator type for the container.
Definition: ftdi.hpp:189
Ftdi::Eeprom
Device EEPROM.
Definition: ftdi.hpp:153
Ftdi::List::push_front
void push_front(const Context &element)
Definition: ftdi.cpp:609
Ftdi::Eeprom::init_defaults
void init_defaults()
Definition: ftdi.cpp:401
Ftdi::Eeprom::read_location
int read_location(int eeprom_addr, unsigned short *eeprom_val)
Definition: ftdi.cpp:436
Ftdi::Context::Input
Definition: ftdi.hpp:62
Ftdi::Eeprom::read
int read(unsigned char *eeprom)
Definition: ftdi.cpp:426
Ftdi::Context::set_error_char
int set_error_char(unsigned char errorch, unsigned char enable)
Definition: ftdi.cpp:274
ftdi_stopbits_type
ftdi_stopbits_type
Definition: ftdi.h:27
Ftdi::Context::set_usb_device
void set_usb_device(struct usb_dev_handle *dev)
Definition: ftdi.cpp:164
Ftdi::List::push_back
void push_back(const Context &element)
Definition: ftdi.cpp:600
Ftdi::Eeprom::size
int size(unsigned char *eeprom, int maxsize)
Definition: ftdi.cpp:411
ftdi.h
Ftdi::Context::Rts
Definition: ftdi.hpp:71
Ftdi::Context::Direction
Direction
Direction flags for flush().
Definition: ftdi.hpp:60
Ftdi::Context::write
int write(unsigned char *buf, int size)
Definition: ftdi.cpp:204
Ftdi::Context::read_chunk_size
int read_chunk_size()
Definition: ftdi.cpp:195
Ftdi::Context::set_read_chunk_size
int set_read_chunk_size(unsigned int chunksize)
Definition: ftdi.cpp:190
Ftdi::Context::write_chunk_size
int write_chunk_size()
Definition: ftdi.cpp:214
Ftdi::Context::set_context
void set_context(struct ftdi_context *context)
Definition: ftdi.cpp:364
Ftdi::List::rend
reverse_iterator rend()
Definition: ftdi.cpp:537
Ftdi::Context::get_strings_and_reopen
int get_strings_and_reopen()
Definition: ftdi.cpp:326
Ftdi::Context::description
const std::string & description()
Device strings properties.
Definition: ftdi.cpp:352
Ftdi::Context::bitbang_disable
int bitbang_disable()
Definition: ftdi.cpp:284
Ftdi::Context::set_event_char
int set_event_char(unsigned char eventch, unsigned char enable)
Definition: ftdi.cpp:269
Ftdi::List::clear
void clear()
Definition: ftdi.cpp:584
Ftdi::Context
FTDI device context. Represents single FTDI device context.
Definition: ftdi.hpp:51
Ftdi::Context::vendor
const std::string & vendor()
Device strings properties.
Definition: ftdi.cpp:345
Ftdi::Eeprom::write_location
int write_location(int eeprom_addr, unsigned short eeprom_val)
Definition: ftdi.cpp:441
Ftdi::Context::set_line_property
int set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity)
Definition: ftdi.cpp:175
Ftdi::Context::DEPRECATED
int DEPRECATED(bitbang_enable(unsigned char bitmask))
Ftdi::Eeprom::erase
int erase()
Definition: ftdi.cpp:446
ftdi_break_type
ftdi_break_type
Definition: ftdi.h:31
Ftdi::Context::latency
unsigned latency()
Definition: ftdi.cpp:255
Ftdi::Context::serial
const std::string & serial()
Device strings properties.
Definition: ftdi.cpp:359
Ftdi::List::List
List(struct ftdi_device_list *devlist=0)
Definition: ftdi.cpp:468
Ftdi::List::begin
iterator begin()
Definition: ftdi.cpp:492
Ftdi::Context::read_pins
int read_pins(unsigned char *pins)
Definition: ftdi.cpp:299
Ftdi::Context::set_baud_rate
int set_baud_rate(int baudrate)
Definition: ftdi.cpp:170
ftdi_parity_type
ftdi_parity_type
Definition: ftdi.h:25
Ftdi::Eeprom::Private
Definition: ftdi.cpp:380
Ftdi::List::ListType
std::list< Context > ListType
List type storing "Context" objects.
Definition: ftdi.hpp:187
Ftdi::Context::flush
int flush(int mask=Input|Output)
Definition: ftdi.cpp:147
Ftdi::Context::close
int close()
Definition: ftdi.cpp:136
Ftdi::List::const_iterator
ListType::const_iterator const_iterator
Const iterator type for the container.
Definition: ftdi.hpp:191
Ftdi::List::~List
~List()
Definition: ftdi.cpp:484
Ftdi::Context::set_write_chunk_size
int set_write_chunk_size(unsigned int chunksize)
Definition: ftdi.cpp:209
Ftdi::Context::read
int read(unsigned char *buf, int size)
Definition: ftdi.cpp:185
Ftdi::Context::eeprom
Eeprom * eeprom()
Ftdi::List::const_reverse_iterator
ListType::const_reverse_iterator const_reverse_iterator
Const reverse iterator type for the container.
Definition: ftdi.hpp:195
Ftdi::Context::set_flow_control
int set_flow_control(int flowctrl)
Definition: ftdi.cpp:223
Ftdi::Context::Output
Definition: ftdi.hpp:63
Ftdi::List::Private
Definition: ftdi.cpp:451
Ftdi::List::size
ListType::size_type size() const
Definition: ftdi.cpp:565
Ftdi::List::rbegin
reverse_iterator rbegin()
Definition: ftdi.cpp:528
Ftdi::List
Device list.
Definition: ftdi.hpp:178
Ftdi::Context::set_modem_control
int set_modem_control(int mask=Dtr|Rts)
Definition: ftdi.cpp:228
Ftdi::Eeprom::chip_id
int chip_id(unsigned int *chipid)
Definition: ftdi.cpp:416
Ftdi::List::end
iterator end()
Definition: ftdi.cpp:501
Ftdi::Context::set_dtr
int set_dtr(bool state)
Definition: ftdi.cpp:240
Ftdi::Eeprom::Eeprom
Eeprom(Context *parent)
Definition: ftdi.cpp:391
ftdi_device_list
list of usb devices created by ftdi_usb_find_all()
Definition: ftdi.h:247
usb_dev_handle
Definition: ftdi.c:1270
Ftdi::Context::open
int open(struct usb_device *dev=0)
Definition: ftdi.cpp:125
Ftdi::Eeprom::set_size
void set_size(int size)
Definition: ftdi.cpp:406
Ftdi::Context::get_strings
int get_strings()
Definition: ftdi.cpp:309
Ftdi::Context::set_interface
int set_interface(enum ftdi_interface interface)
Definition: ftdi.cpp:159
Ftdi::Context::Private
Definition: ftdi.cpp:40
Ftdi::Context::Context
Context()
Constructor.
Definition: ftdi.cpp:69
Ftdi::List::empty
bool empty() const
Definition: ftdi.cpp:574
Ftdi::Context::Eeprom
friend class Eeprom
Definition: ftdi.hpp:54
Ftdi::Context::Dtr
Definition: ftdi.hpp:70
Ftdi
Definition: ftdi.cpp:32
Ftdi::Context::error_string
char * error_string()
Definition: ftdi.cpp:304
ftdi_context
Main context structure for all libftdi functions.
Definition: ftdi.h:186
Ftdi::List::find_all
static List * find_all(int vendor, int product)
Definition: ftdi.cpp:635
Ftdi::Context::set_rts
int set_rts(bool state)
Definition: ftdi.cpp:245
Ftdi::Context::context
struct ftdi_context * context()
Definition: ftdi.cpp:375
Ftdi::Eeprom::~Eeprom
~Eeprom()
Definition: ftdi.cpp:397
Ftdi::Context::set_bitmode
int set_bitmode(unsigned char bitmask, unsigned char mode)
Definition: ftdi.cpp:289
ftdi_bits_type
ftdi_bits_type
Definition: ftdi.h:29
Ftdi::Context::reset
int reset()
Definition: ftdi.cpp:142
Ftdi::Eeprom::write
int write(unsigned char *eeprom)
Definition: ftdi.cpp:431
Ftdi::List::reverse_iterator
ListType::reverse_iterator reverse_iterator
Reverse iterator type for the container.
Definition: ftdi.hpp:193
Ftdi::Context::ModemCtl
ModemCtl
Modem control flags.
Definition: ftdi.hpp:68
Ftdi::List::erase
iterator erase(iterator pos)
Definition: ftdi.cpp:619
ftdi_interface
ftdi_interface
Definition: ftdi.h:48
Ftdi::Context::is_open
bool is_open()
Definition: ftdi.cpp:80
Ftdi::Context::~Context
~Context()
Destructor.
Definition: ftdi.cpp:76
Ftdi::Context::set_latency
int set_latency(unsigned char latency)
Definition: ftdi.cpp:250
Ftdi::Context::poll_modem_status
unsigned short poll_modem_status()
Definition: ftdi.cpp:262
Ftdi::Eeprom::build
int build(unsigned char *output)
Definition: ftdi.cpp:421