openFPGALoader/src/ftdipp_mpsse.hpp

89 lines
2.4 KiB
C++
Raw Permalink Normal View History

2021-06-26 15:24:07 +02:00
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/
2019-09-26 18:29:20 +02:00
#ifndef _FTDIPP_MPSSE_H
#define _FTDIPP_MPSSE_H
#include <ftdi.h>
#include <string>
2019-09-26 18:29:20 +02:00
#include "cable.hpp"
2019-09-26 18:29:20 +02:00
class FTDIpp_MPSSE {
public:
FTDIpp_MPSSE(const cable_t &cable, const std::string &dev,
const std::string &serial, uint32_t clkHZ, int8_t verbose = 0);
~FTDIpp_MPSSE();
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);
2021-06-12 08:40:40 +02:00
uint32_t getClkFreq() { return _clkHZ;}
2019-09-26 18:29:20 +02:00
int vid() {return _vid;}
int pid() {return _pid;}
uint8_t bus_addr() {return _bus;}
uint8_t device_addr() {return _addr;}
2019-09-26 18:29:20 +02: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);
/* gpio direction */
void gpio_set_dir(uint8_t dir, bool low_pins);
void gpio_set_dir(uint16_t dir);
2020-10-31 07:38:06 +01:00
/* configure as input low/high pins */
void gpio_set_input(uint8_t gpio, bool low_pins);
/* configure as input pins */
void gpio_set_input(uint16_t gpio);
/* configure as output low/high pins */
void gpio_set_output(uint8_t gpio, bool low_pins);
/* configure as output pins */
void gpio_set_output(uint16_t gpio);
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;}
unsigned int udevstufftoint(const char *udevstring, int base);
bool search_with_dev(const std::string &device);
2023-07-30 07:23:19 +02:00
bool _verbose;
mpsse_bit_config _cable;
2019-09-26 18:29:20 +02:00
int _vid;
int _pid;
int _index;
private:
uint8_t _bus;
uint8_t _addr;
uint8_t _bitmode;
char _product[64];
2019-09-26 18:29:20 +02:00
unsigned char _interface;
/* gpio */
bool __gpio_write(bool low_pins);
2020-03-06 08:24:49 +01:00
protected:
uint32_t _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;
unsigned char *_buffer;
uint8_t _iproduct[200];
2024-01-27 13:02:46 +01:00
uint8_t _imanufacturer[200];
uint8_t _iserialnumber[200];
2019-09-26 18:29:20 +02:00
};
#endif