ftdi.hpp
Go to the documentation of this file.
/***************************************************************************
ftdi.hpp - C++ wrapper for libftdi
-------------------
begin : Mon Oct 13 2008
copyright : (C) 2008-2017 by Marek Vavruša and libftdi developers
email : opensource@intra2net.com and marek@vavrusa.com
***************************************************************************/
/*
Copyright (C) 2008-2017 by Marek Vavruša and libftdi developers
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 = 0x2,
Output = 0x1,
};
enum ModemCtl
{
Dtr = 0x2,
Rts = 0x1,
};
/* 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 libusb_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 libusb_device_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);
int get_usb_read_timeout() const;
void set_usb_read_timeout(int usb_read_timeout);
int get_usb_write_timeout() const;
void set_usb_write_timeout(int usb_write_timeout);
/* I/O */
int read(unsigned char *buf, int size);
int write(const 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(const 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 bitbang_disable();
int read_pins(unsigned char *pins);
/* Misc */
const char* error_string();
protected:
int get_strings(bool vendor=true, bool description=true, bool serial=true);
int get_strings_and_reopen(bool vendor=true, bool description=true, bool serial=true);
/* Properties */
struct ftdi_context* context();
void set_context(struct ftdi_context* context);
void set_usb_device(struct libusb_device *dev);
private:
class Private;
boost::shared_ptr<Private> d;
};
class Eeprom
{
public:
Eeprom(Context* parent);
~Eeprom();
int init_defaults(char *manufacturer, char* product, char * serial);
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(Context &context, 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:57
Ftdi::List::iterator
ListType::iterator iterator
Iterator type for the container.
Definition: ftdi.hpp:190
Ftdi::Eeprom
Device EEPROM.
Definition: ftdi.hpp:156
Ftdi::List::push_front
void push_front(const Context &element)
Definition: ftdi.cpp:647
Ftdi::Eeprom::read_location
int read_location(int eeprom_addr, unsigned short *eeprom_val)
Definition: ftdi.cpp:474
Ftdi::Context::Input
Definition: ftdi.hpp:62
Ftdi::Eeprom::read
int read(unsigned char *eeprom)
Definition: ftdi.cpp:464
Ftdi::Context::set_usb_read_timeout
void set_usb_read_timeout(int usb_read_timeout)
Definition: ftdi.cpp:207
Ftdi::Context::set_error_char
int set_error_char(unsigned char errorch, unsigned char enable)
Definition: ftdi.cpp:311
ftdi_stopbits_type
ftdi_stopbits_type
Definition: ftdi.h:50
Ftdi::List::push_back
void push_back(const Context &element)
Definition: ftdi.cpp:638
ftdi.h
Ftdi::Context::Rts
Definition: ftdi.hpp:71
Ftdi::Context::Direction
Direction
Direction flags for flush().
Definition: ftdi.hpp:60
Ftdi::Context::read_chunk_size
int read_chunk_size()
Definition: ftdi.cpp:232
Ftdi::Context::set_read_chunk_size
int set_read_chunk_size(unsigned int chunksize)
Definition: ftdi.cpp:227
Ftdi::Context::get_strings
int get_strings(bool vendor=true, bool description=true, bool serial=true)
Definition: ftdi.cpp:341
Ftdi::Context::write_chunk_size
int write_chunk_size()
Definition: ftdi.cpp:251
Ftdi::Context::set_context
void set_context(struct ftdi_context *context)
Definition: ftdi.cpp:412
Ftdi::List::rend
reverse_iterator rend()
Definition: ftdi.cpp:575
Ftdi::Context::description
const std::string & description()
Device strings properties.
Definition: ftdi.cpp:396
Ftdi::Context::error_string
const char * error_string()
Definition: ftdi.cpp:336
Ftdi::Context::bitbang_disable
int bitbang_disable()
Definition: ftdi.cpp:326
Ftdi::Context::set_event_char
int set_event_char(unsigned char eventch, unsigned char enable)
Definition: ftdi.cpp:306
Ftdi::List::clear
void clear()
Definition: ftdi.cpp:622
Ftdi::Context::set_usb_device
void set_usb_device(struct libusb_device_handle *dev)
Definition: ftdi.cpp:181
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:387
Ftdi::Eeprom::write_location
int write_location(int eeprom_addr, unsigned short eeprom_val)
Definition: ftdi.cpp:479
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:192
Ftdi::Eeprom::erase
int erase()
Definition: ftdi.cpp:484
ftdi_break_type
ftdi_break_type
Definition: ftdi.h:54
Ftdi::Context::latency
unsigned latency()
Definition: ftdi.cpp:292
Ftdi::Context::serial
const std::string & serial()
Device strings properties.
Definition: ftdi.cpp:405
Ftdi::List::List
List(struct ftdi_device_list *devlist=0)
Definition: ftdi.cpp:506
Ftdi::List::begin
iterator begin()
Definition: ftdi.cpp:530
Ftdi::Context::read_pins
int read_pins(unsigned char *pins)
Definition: ftdi.cpp:331
Ftdi::Context::set_baud_rate
int set_baud_rate(int baudrate)
Definition: ftdi.cpp:187
ftdi_parity_type
ftdi_parity_type
Definition: ftdi.h:48
Ftdi::Eeprom::Private
Definition: ftdi.cpp:428
Ftdi::List::ListType
std::list< Context > ListType
List type storing "Context" objects.
Definition: ftdi.hpp:188
Ftdi::Context::flush
int flush(int mask=Input|Output)
Definition: ftdi.cpp:150
Ftdi::Context::close
int close()
Definition: ftdi.cpp:138
Ftdi::List::const_iterator
ListType::const_iterator const_iterator
Const iterator type for the container.
Definition: ftdi.hpp:192
Ftdi::List::~List
~List()
Definition: ftdi.cpp:522
Ftdi::Context::set_write_chunk_size
int set_write_chunk_size(unsigned int chunksize)
Definition: ftdi.cpp:246
Ftdi::Context::read
int read(unsigned char *buf, int size)
Definition: ftdi.cpp:222
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:196
Ftdi::Context::set_flow_control
int set_flow_control(int flowctrl)
Definition: ftdi.cpp:260
Ftdi::Context::Output
Definition: ftdi.hpp:63
Ftdi::List::Private
Definition: ftdi.cpp:489
Ftdi::List::size
ListType::size_type size() const
Definition: ftdi.cpp:603
Ftdi::List::rbegin
reverse_iterator rbegin()
Definition: ftdi.cpp:566
Ftdi::List
Device list.
Definition: ftdi.hpp:179
Ftdi::Context::set_modem_control
int set_modem_control(int mask=Dtr|Rts)
Definition: ftdi.cpp:265
Ftdi::Eeprom::chip_id
int chip_id(unsigned int *chipid)
Definition: ftdi.cpp:454
Ftdi::List::end
iterator end()
Definition: ftdi.cpp:539
Ftdi::Context::write
int write(const unsigned char *buf, int size)
Definition: ftdi.cpp:241
Ftdi::Context::set_dtr
int set_dtr(bool state)
Definition: ftdi.cpp:277
Ftdi::Eeprom::Eeprom
Eeprom(Context *parent)
Definition: ftdi.cpp:439
ftdi_device_list
list of usb devices created by ftdi_usb_find_all()
Definition: ftdi.h:342
Ftdi::Context::open
int open(struct libusb_device *dev=0)
Definition: ftdi.cpp:127
Ftdi::Eeprom::init_defaults
int init_defaults(char *manufacturer, char *product, char *serial)
Definition: ftdi.cpp:449
Ftdi::List::find_all
static List * find_all(Context &context, int vendor, int product)
Definition: ftdi.cpp:673
Ftdi::Context::set_interface
int set_interface(enum ftdi_interface interface)
Definition: ftdi.cpp:176
Ftdi::Context::Private
Definition: ftdi.cpp:42
Ftdi::Context::Context
Context()
Constructor.
Definition: ftdi.cpp:71
Ftdi::List::empty
bool empty() const
Definition: ftdi.cpp:612
Ftdi::Context::Eeprom
friend class Eeprom
Definition: ftdi.hpp:54
Ftdi::Context::Dtr
Definition: ftdi.hpp:70
Ftdi
Definition: ftdi.cpp:34
ftdi_context
Main context structure for all libftdi functions.
Definition: ftdi.h:219
Ftdi::Context::set_rts
int set_rts(bool state)
Definition: ftdi.cpp:282
Ftdi::Context::context
struct ftdi_context * context()
Definition: ftdi.cpp:423
Ftdi::Eeprom::~Eeprom
~Eeprom()
Definition: ftdi.cpp:445
Ftdi::Context::set_bitmode
int set_bitmode(unsigned char bitmask, unsigned char mode)
Definition: ftdi.cpp:316
ftdi_bits_type
ftdi_bits_type
Definition: ftdi.h:52
Ftdi::Context::get_usb_read_timeout
int get_usb_read_timeout() const
Definition: ftdi.cpp:202
Ftdi::Context::reset
int reset()
Definition: ftdi.cpp:145
Ftdi::Eeprom::write
int write(unsigned char *eeprom)
Definition: ftdi.cpp:469
Ftdi::Context::get_usb_write_timeout
int get_usb_write_timeout() const
Definition: ftdi.cpp:212
Ftdi::Context::set_usb_write_timeout
void set_usb_write_timeout(int usb_write_timeout)
Definition: ftdi.cpp:217
Ftdi::List::reverse_iterator
ListType::reverse_iterator reverse_iterator
Reverse iterator type for the container.
Definition: ftdi.hpp:194
Ftdi::Context::ModemCtl
ModemCtl
Modem control flags.
Definition: ftdi.hpp:68
Ftdi::List::erase
iterator erase(iterator pos)
Definition: ftdi.cpp:657
ftdi_interface
ftdi_interface
Definition: ftdi.h:72
Ftdi::Context::is_open
bool is_open()
Definition: ftdi.cpp:82
Ftdi::Context::get_strings_and_reopen
int get_strings_and_reopen(bool vendor=true, bool description=true, bool serial=true)
Definition: ftdi.cpp:358
Ftdi::Context::~Context
~Context()
Destructor.
Definition: ftdi.cpp:78
Ftdi::Context::set_latency
int set_latency(unsigned char latency)
Definition: ftdi.cpp:287
Ftdi::Context::poll_modem_status
unsigned short poll_modem_status()
Definition: ftdi.cpp:299
Ftdi::Eeprom::build
int build(unsigned char *output)
Definition: ftdi.cpp:459