2019-09-26 18:29:20 +02:00
|
|
|
#ifndef _FTDIPP_MPSSE_H
|
|
|
|
|
#define _FTDIPP_MPSSE_H
|
|
|
|
|
#include <ftdi.h>
|
2019-11-19 09:00:56 +01:00
|
|
|
#include <string>
|
2019-09-26 18:29:20 +02:00
|
|
|
|
|
|
|
|
class FTDIpp_MPSSE {
|
|
|
|
|
public:
|
|
|
|
|
typedef struct {
|
|
|
|
|
int vid;
|
|
|
|
|
int pid;
|
2020-03-07 07:19:20 +01:00
|
|
|
int interface;
|
2019-09-26 18:29:20 +02:00
|
|
|
int bit_low_val;
|
|
|
|
|
int bit_low_dir;
|
|
|
|
|
int bit_high_val;
|
|
|
|
|
int bit_high_dir;
|
|
|
|
|
} mpsse_bit_config;
|
|
|
|
|
|
2020-03-08 16:58:05 +01:00
|
|
|
FTDIpp_MPSSE(const mpsse_bit_config &cable, const std::string &dev,
|
2020-09-29 14:16:30 +02:00
|
|
|
const std::string &serial, uint32_t clkHZ, bool verbose = false);
|
2020-03-08 16:58:05 +01:00
|
|
|
~FTDIpp_MPSSE();
|
|
|
|
|
|
2020-10-27 20:27:02 +01:00
|
|
|
int init(unsigned char latency, unsigned char bitmask_mode,
|
|
|
|
|
unsigned char mode);
|
2019-09-26 18:29:20 +02:00
|
|
|
int setClkFreq(uint32_t clkHZ);
|
|
|
|
|
int setClkFreq(uint32_t clkHZ, char use_divide_by_5);
|
|
|
|
|
|
2019-09-28 15:38:57 +02:00
|
|
|
int vid() {return _vid;}
|
|
|
|
|
int pid() {return _pid;}
|
2019-09-26 18:29:20 +02:00
|
|
|
|
2020-10-28 07:58:33 +01:00
|
|
|
/* access gpio */
|
|
|
|
|
/* read gpio */
|
|
|
|
|
uint16_t gpio_get();
|
|
|
|
|
uint8_t gpio_get(bool low_pins);
|
|
|
|
|
/* update selected gpio */
|
|
|
|
|
bool gpio_set(uint16_t gpio);
|
|
|
|
|
bool gpio_set(uint8_t gpio, bool low_pins);
|
|
|
|
|
bool gpio_clear(uint16_t gpio);
|
|
|
|
|
bool gpio_clear(uint8_t gpio, bool low_pins);
|
|
|
|
|
/* full access */
|
|
|
|
|
bool gpio_write(uint16_t gpio);
|
|
|
|
|
bool gpio_write(uint8_t gpio, bool low_pins);
|
|
|
|
|
|
2019-09-26 18:29:20 +02:00
|
|
|
protected:
|
2020-09-29 14:16:30 +02:00
|
|
|
void open_device(const std::string &serial, unsigned int baudrate);
|
2019-09-26 18:29:20 +02:00
|
|
|
void ftdi_usb_close_internal();
|
|
|
|
|
int close_device();
|
|
|
|
|
int mpsse_write();
|
|
|
|
|
int mpsse_read(unsigned char *rx_buff, int len);
|
|
|
|
|
int mpsse_store(unsigned char c);
|
|
|
|
|
int mpsse_store(unsigned char *c, int len);
|
|
|
|
|
int mpsse_get_buffer_size() {return _buffer_size;}
|
2019-11-19 09:00:56 +01:00
|
|
|
unsigned int udevstufftoint(const char *udevstring, int base);
|
|
|
|
|
bool search_with_dev(const std::string &device);
|
2019-11-21 08:36:16 +01:00
|
|
|
bool _verbose;
|
2020-10-27 20:27:02 +01:00
|
|
|
mpsse_bit_config _cable;
|
2019-09-26 18:29:20 +02:00
|
|
|
private:
|
|
|
|
|
int _vid;
|
|
|
|
|
int _pid;
|
2019-11-19 09:00:56 +01:00
|
|
|
int _bus;
|
|
|
|
|
int _addr;
|
|
|
|
|
char _product[64];
|
2019-09-26 18:29:20 +02:00
|
|
|
unsigned char _interface;
|
2020-03-06 08:24:49 +01:00
|
|
|
protected:
|
2020-05-31 15:56:35 +02:00
|
|
|
int _clkHZ;
|
2020-03-06 08:24:49 +01:00
|
|
|
struct ftdi_context *_ftdi;
|
2019-09-26 18:29:20 +02:00
|
|
|
int _buffer_size;
|
|
|
|
|
int _num;
|
2020-10-09 21:30:45 +02:00
|
|
|
private:
|
2019-09-26 18:29:20 +02:00
|
|
|
unsigned char *_buffer;
|
2020-10-28 07:58:33 +01:00
|
|
|
/* gpio */
|
|
|
|
|
bool __gpio_write(bool low_pins);
|
2019-09-26 18:29:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|