X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=ftdipp%2Fftdi.hpp;h=a438d968a87832918067f8d0cdfdeb21f63b43d6;hp=478d9a4097b9b462b15dba98da82cf68221afbb5;hb=c45d26308211c383903cb06f15ba7575d807fe06;hpb=cfceadbca71ddaf170ea3d869adb8ea4d91ea819 diff --git a/ftdipp/ftdi.hpp b/ftdipp/ftdi.hpp index 478d9a4..a438d96 100644 --- a/ftdipp/ftdi.hpp +++ b/ftdipp/ftdi.hpp @@ -2,25 +2,37 @@ ftdi.hpp - C++ wrapper for libftdi ------------------- begin : Mon Oct 13 2008 - copyright : (C) 2008 by Marek Vavruša + copyright : (C) 2008-2014 by Marek Vavruša and libftdi developers email : opensource@intra2net.com and marek@vavrusa.com ***************************************************************************/ +/* +Copyright (C) 2008-2014 by Marek Vavruša and libftdi developers -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License * - * version 2.1 as published by the Free Software Foundation; * - * * - ***************************************************************************/ +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" +#include namespace Ftdi { @@ -67,18 +79,24 @@ public: /* 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 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 usb_dev_handle *dev); + 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); @@ -108,20 +126,21 @@ public: /* BitBang mode */ int set_bitmode(unsigned char bitmask, unsigned char mode); - int bitbang_enable(unsigned char bitmask); + int set_bitmode(unsigned char bitmask, enum ftdi_mpsse_mode mode); int bitbang_disable(); int read_pins(unsigned char *pins); /* Misc */ - char* error_string(); + const 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); + void set_usb_device(struct libusb_device *dev); private: class Private; @@ -136,13 +155,14 @@ public: Eeprom(Context* parent); ~Eeprom(); - void init_defaults(); - void set_size(int size); - int size(unsigned char *eeprom, int maxsize); + 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: @@ -150,17 +170,46 @@ 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(); - static List* find_all(int vendor, int product); + static List* find_all(Context &context, int vendor, int product); + + /// List type storing "Context" objects + typedef std::list ListType; + /// Iterator type for the container + typedef ListType::iterator iterator; + /// Const iterator type for the container + typedef ListType::const_iterator const_iterator; + /// Reverse iterator type for the container + typedef ListType::reverse_iterator reverse_iterator; + /// Const reverse iterator type for the container + 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;