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>
|
2019-11-19 09:00:56 +01:00
|
|
|
#include <string>
|
2019-09-26 18:29:20 +02:00
|
|
|
|
2022-10-15 16:17:32 +02:00
|
|
|
#include "cable.hpp"
|
|
|
|
|
|
2019-09-26 18:29:20 +02:00
|
|
|
class FTDIpp_MPSSE {
|
|
|
|
|
public:
|
2022-10-15 16:17:32 +02:00
|
|
|
FTDIpp_MPSSE(const cable_t &cable, const std::string &dev,
|
2022-01-19 18:42:15 +01:00
|
|
|
const std::string &serial, uint32_t clkHZ, int8_t verbose = 0);
|
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);
|
2021-06-12 08:40:40 +02:00
|
|
|
uint32_t getClkFreq() { return _clkHZ;}
|
2019-09-26 18:29:20 +02:00
|
|
|
|
2019-09-28 15:38:57 +02:00
|
|
|
int vid() {return _vid;}
|
|
|
|
|
int pid() {return _pid;}
|
2023-02-25 17:10:40 +01:00
|
|
|
uint8_t bus_addr() {return _bus;}
|
|
|
|
|
uint8_t device_addr() {return _addr;}
|
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);
|
2020-10-30 08:18:38 +01:00
|
|
|
/* gpio direction */
|
2020-10-28 19:48:59 +01:00
|
|
|
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);
|
2020-10-28 07:58:33 +01:00
|
|
|
|
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);
|
2023-07-30 07:23:19 +02:00
|
|
|
bool _verbose;
|
2020-10-27 20:27:02 +01:00
|
|
|
mpsse_bit_config _cable;
|
2019-09-26 18:29:20 +02:00
|
|
|
int _vid;
|
|
|
|
|
int _pid;
|
2022-06-01 16:17:38 +02:00
|
|
|
int _index;
|
2020-10-29 07:40:56 +01:00
|
|
|
private:
|
2022-10-15 17:12:45 +02:00
|
|
|
uint8_t _bus;
|
|
|
|
|
uint8_t _addr;
|
2023-04-10 17:59:07 +02:00
|
|
|
uint8_t _bitmode;
|
2019-11-19 09:00:56 +01:00
|
|
|
char _product[64];
|
2019-09-26 18:29:20 +02:00
|
|
|
unsigned char _interface;
|
2020-10-29 07:39:07 +01:00
|
|
|
/* gpio */
|
|
|
|
|
bool __gpio_write(bool low_pins);
|
2020-03-06 08:24:49 +01:00
|
|
|
protected:
|
2021-02-05 06:28:19 +01:00
|
|
|
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;
|
2021-07-14 19:08:40 +02:00
|
|
|
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
|