mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Driver: Switch to libredxx
- no more libFTDI - no more libusb on Linux and macOS - no more FTDI repack - no more binary libs - faster D2XX on Windows (no longer uses COM)
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#ifndef __DXX_H_
|
||||
#define __DXX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/driver.h"
|
||||
#include "icsneo/device/founddevice.h"
|
||||
|
||||
#include "libredxx/libredxx.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class DXX : public Driver {
|
||||
public:
|
||||
static void Find(std::vector<FoundDevice>& found);
|
||||
|
||||
DXX(const device_eventhandler_t& err, neodevice_t& forDevice, uint16_t pid, libredxx_device_type type);
|
||||
|
||||
bool open() override;
|
||||
|
||||
bool isOpen() override;
|
||||
|
||||
bool close() override;
|
||||
|
||||
private:
|
||||
void read();
|
||||
void write();
|
||||
neodevice_t neodevice;
|
||||
uint16_t pid;
|
||||
libredxx_device_type type;
|
||||
libredxx_opened_device* device = nullptr;
|
||||
std::thread readThread;
|
||||
std::thread writeThread;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // __DXX_H_
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef __FTD3XX_H_
|
||||
#define __FTD3XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "icsneo/communication/driver.h"
|
||||
#include "icsneo/device/founddevice.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class FTD3XX : public Driver {
|
||||
public:
|
||||
static void Find(std::vector<FoundDevice>& foundDevices);
|
||||
FTD3XX(const device_eventhandler_t& err, neodevice_t& forDevice);
|
||||
~FTD3XX() override { if(isOpen()) close(); }
|
||||
bool open() override;
|
||||
bool isOpen() override;
|
||||
bool close() override;
|
||||
bool isEthernet() const override { return false; }
|
||||
private:
|
||||
neodevice_t& device;
|
||||
std::optional<void*> handle;
|
||||
|
||||
std::thread readThread, writeThread;
|
||||
void readTask();
|
||||
void writeTask();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef __FTDI_H_
|
||||
#define __FTDI_H_
|
||||
|
||||
#define INTREPID_USB_VENDOR_ID (0x093c)
|
||||
|
||||
#if defined _WIN32
|
||||
#include "icsneo/platform/windows/ftdi.h"
|
||||
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||
#include "icsneo/platform/posix/ftdi.h"
|
||||
#else
|
||||
#warning "This platform is not supported by the FTDI driver"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,74 +0,0 @@
|
||||
#ifndef __FTDI_POSIX_H_
|
||||
#define __FTDI_POSIX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <ftdi.h>
|
||||
#include "icsneo/device/neodevice.h"
|
||||
#include "icsneo/communication/driver.h"
|
||||
#include "icsneo/third-party/concurrentqueue/blockingconcurrentqueue.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class FTDI : public Driver {
|
||||
public:
|
||||
static void Find(std::vector<FoundDevice>& found);
|
||||
|
||||
FTDI(const device_eventhandler_t& err, neodevice_t& forDevice);
|
||||
~FTDI() { if(isOpen()) close(); }
|
||||
bool open();
|
||||
bool close();
|
||||
bool isOpen() { return ftdi.isOpen(); }
|
||||
|
||||
private:
|
||||
class FTDIContext {
|
||||
public:
|
||||
FTDIContext() : context(ftdi_new()) {}
|
||||
~FTDIContext() {
|
||||
if(context)
|
||||
ftdi_free(context); // calls ftdi_deinit and ftdi_close if required
|
||||
context = nullptr;
|
||||
}
|
||||
|
||||
// A PID of 0 disables filtering by PID
|
||||
std::pair<int, std::vector< std::pair<std::string, uint16_t> > > findDevices(int pid = 0);
|
||||
|
||||
int openDevice(int pid, const char* serial);
|
||||
bool closeDevice();
|
||||
bool isOpen() const { return deviceOpen; }
|
||||
int flush() { return ftdi_usb_purge_buffers(context); }
|
||||
int reset() { return ftdi_usb_reset(context); }
|
||||
int read(uint8_t* data, size_t size) { return ftdi_read_data(context, data, (int)size); }
|
||||
int write(const uint8_t* data, size_t size) { return ftdi_write_data(context, data, (int)size); }
|
||||
int setBaudrate(int baudrate) { return ftdi_set_baudrate(context, baudrate); }
|
||||
int setLatencyTimer(uint8_t latency) { return ftdi_set_latency_timer(context, latency); }
|
||||
bool setReadTimeout(int timeout) { if(context == nullptr) return false; context->usb_read_timeout = timeout; return true; }
|
||||
bool setWriteTimeout(int timeout) { if(context == nullptr) return false; context->usb_write_timeout = timeout; return true; }
|
||||
private:
|
||||
struct ftdi_context* context;
|
||||
bool deviceOpen = false;
|
||||
};
|
||||
FTDIContext ftdi;
|
||||
|
||||
static std::vector<std::string> handles;
|
||||
|
||||
static bool ErrorIsDisconnection(int errorCode);
|
||||
std::thread readThread, writeThread;
|
||||
|
||||
void readTask();
|
||||
void writeTask();
|
||||
|
||||
bool openable; // Set to false in the constructor if the object has not been found in searchResultDevices
|
||||
|
||||
neodevice_t& device;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -4,6 +4,8 @@
|
||||
#ifdef __cplusplus
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
@@ -3,14 +3,34 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/platform/windows/vcp.h"
|
||||
#include "icsneo/communication/driver.h"
|
||||
#include "icsneo/device/founddevice.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class CDCACM : public VCP {
|
||||
class CDCACM : public Driver {
|
||||
public:
|
||||
CDCACM(const device_eventhandler_t& err, neodevice_t& forDevice) : VCP(err, forDevice) {}
|
||||
static void Find(std::vector<FoundDevice>& found) { return VCP::Find(found, { L"usbser" }); }
|
||||
CDCACM(const device_eventhandler_t& err, const std::wstring& path);
|
||||
static void Find(std::vector<FoundDevice>& found);
|
||||
bool open() override;
|
||||
bool isOpen() override;
|
||||
bool close() override;
|
||||
|
||||
private:
|
||||
void read();
|
||||
void write();
|
||||
std::wstring path;
|
||||
HANDLE handle = INVALID_HANDLE_VALUE;
|
||||
std::thread readThread;
|
||||
std::thread writeThread;
|
||||
OVERLAPPED readOverlapped = {};
|
||||
OVERLAPPED writeOverlapped = {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef __DYNAMICLIB_WINDOWS_H_
|
||||
#define __DYNAMICLIB_WINDOWS_H_
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
|
||||
#ifndef ICSNEOC_BUILD_STATIC
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef __FTDI_WINDOWS_H_
|
||||
#define __FTDI_WINDOWS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/platform/windows/vcp.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class FTDI : public VCP {
|
||||
public:
|
||||
FTDI(const device_eventhandler_t& err, neodevice_t& forDevice) : VCP(err, forDevice) {}
|
||||
static void Find(std::vector<FoundDevice>& found) { return VCP::Find(found, { L"serenum" /*, L"ftdibus" */ }); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include <pcap.h>
|
||||
#include <memory>
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#ifndef __VCP_WINDOWS_H_
|
||||
#define __VCP_WINDOWS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include "icsneo/device/neodevice.h"
|
||||
#include "icsneo/communication/driver.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
// Virtual COM Port Communication
|
||||
class VCP : public Driver {
|
||||
public:
|
||||
static void Find(std::vector<FoundDevice>& found, std::vector<std::wstring> driverName);
|
||||
static bool IsHandleValid(neodevice_handle_t handle);
|
||||
typedef void(*fn_boolCallback)(bool success);
|
||||
|
||||
VCP(const device_eventhandler_t& err, neodevice_t& forDevice);
|
||||
virtual ~VCP();
|
||||
bool open() { return open(false); }
|
||||
void openAsync(fn_boolCallback callback);
|
||||
bool close();
|
||||
bool isOpen();
|
||||
|
||||
private:
|
||||
bool open(bool fromAsync);
|
||||
bool opening = false;
|
||||
neodevice_t& device;
|
||||
|
||||
struct Detail;
|
||||
std::shared_ptr<Detail> detail;
|
||||
|
||||
std::vector<std::shared_ptr<std::thread>> threads;
|
||||
std::thread readThread, writeThread;
|
||||
void readTask();
|
||||
void writeTask();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user