mirror of
https://github.com/preble/libpinproc
synced 2026-02-24 18:25:23 +01:00
Continued improvements for MSVC builds. Reworked CmakeLists.txt and simplified ifdefs in PRHardware.cpp
This commit is contained in:
@@ -348,117 +348,6 @@ int32_t CreateJTAGShiftTDODataBurst ( uint32_t * burst, uint16_t numBits, bool_t
|
||||
*/
|
||||
|
||||
#if defined(__WIN32__) || defined(_WIN32)
|
||||
#define USE_D2XX 1
|
||||
#endif
|
||||
|
||||
#if !defined(USE_D2XX)
|
||||
#define USE_LIBFTDI 1
|
||||
#endif
|
||||
|
||||
#if USE_LIBFTDI
|
||||
|
||||
#include <ftdi.h>
|
||||
|
||||
static bool ftdiInitialized;
|
||||
static ftdi_context ftdic;
|
||||
|
||||
|
||||
PRResult PRHardwareOpen()
|
||||
{
|
||||
int32_t i=0;
|
||||
PRResult rc;
|
||||
struct ftdi_device_list *devlist, *curdev;
|
||||
char manufacturer[128], description[128];
|
||||
|
||||
ftdiInitialized = false;
|
||||
|
||||
// Open the FTDI device
|
||||
if (ftdi_init(&ftdic) != 0)
|
||||
{
|
||||
PRSetLastErrorText("Failed to initialize FTDI.");
|
||||
return kPRFailure;
|
||||
}
|
||||
|
||||
// Find all FTDI devices
|
||||
// This is very basic and really only expects to see 1 device. It needs to be
|
||||
// smarter. At the very least, it should check some register on the P-ROC versus
|
||||
// an input parameter to ensure the software is set up for the same architecture as
|
||||
// the P-ROC (Stern vs WPC). Otherwise, it's possible to drive the coils the wrong
|
||||
// polarity and blow fuses or fry transistors and all other sorts of badness.
|
||||
|
||||
// We first enumerate all of the devices:
|
||||
int numDevices = ftdi_usb_find_all(&ftdic, &devlist, FTDI_VENDOR_ID, FTDI_FT245RL_PRODUCT_ID);
|
||||
if (numDevices < 0) {
|
||||
PRSetLastErrorText("ftdi_usb_find_all failed: %d: %s", numDevices, ftdi_get_error_string(&ftdic));
|
||||
ftdi_deinit(&ftdic);
|
||||
return kPRFailure;
|
||||
}
|
||||
else {
|
||||
DEBUG(PRLog(kPRLogInfo, "Number of FTDI devices found: %d\n", numDevices));
|
||||
|
||||
for (curdev = devlist; curdev != NULL; i++) {
|
||||
DEBUG(PRLog(kPRLogInfo, "Checking device %d\n", i));
|
||||
if ((rc = (int32_t)ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0) {
|
||||
DEBUG(PRLog(kPRLogInfo, " ftdi_usb_get_strings failed: %d: %s\n", rc, ftdi_get_error_string(&ftdic)));
|
||||
}
|
||||
else {
|
||||
DEBUG(PRLog(kPRLogInfo, " Device #%d:\n", i));
|
||||
DEBUG(PRLog(kPRLogInfo, " Manufacturer: %s\n", manufacturer));
|
||||
DEBUG(PRLog(kPRLogInfo, " Description: %s\n", description));
|
||||
}
|
||||
curdev = curdev->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Don't need the device list anymore
|
||||
ftdi_list_free (&devlist);
|
||||
|
||||
if ((rc = (int32_t)ftdi_usb_open(&ftdic, FTDI_VENDOR_ID, FTDI_FT245RL_PRODUCT_ID)) < 0)
|
||||
{
|
||||
PRSetLastErrorText("Unable to open ftdi device: %d: %s", rc, ftdi_get_error_string(&ftdic));
|
||||
return kPRFailure;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = kPRSuccess;
|
||||
if (ftdic.type == TYPE_R) {
|
||||
uint32_t chipid;
|
||||
ftdi_read_chipid(&ftdic,&chipid);
|
||||
DEBUG(PRLog(kPRLogInfo, "FTDI chip_id = 0x%x\n", chipid));
|
||||
// Set some defaults:
|
||||
ftdi_read_data_set_chunksize(&ftdic, 4096);
|
||||
ftdi_set_latency_timer(&ftdic, 2); // This helps make reads much faster. 16 appeared to be the default.
|
||||
ftdiInitialized = true;
|
||||
return kPRSuccess;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRSetLastErrorText("FTDI type != TYPE_R: 0x%x", ftdic.type);
|
||||
return kPRFailure;
|
||||
}
|
||||
}
|
||||
}
|
||||
void PRHardwareClose()
|
||||
{
|
||||
if (ftdiInitialized)
|
||||
{
|
||||
ftdi_usb_close(&ftdic);
|
||||
ftdi_deinit(&ftdic);
|
||||
}
|
||||
}
|
||||
int PRHardwareRead(uint8_t *buffer, int maxBytes)
|
||||
{
|
||||
return ftdi_read_data(&ftdic, buffer, maxBytes);
|
||||
}
|
||||
int PRHardwareWrite(uint8_t *buffer, int bytes)
|
||||
{
|
||||
return ftdi_write_data(&ftdic, buffer, bytes);
|
||||
}
|
||||
|
||||
#endif // USE_LIBFTDI
|
||||
|
||||
#if USE_D2XX
|
||||
#include "ftd2xx.h"
|
||||
|
||||
#define BUF_SIZE 16
|
||||
@@ -587,4 +476,105 @@ int PRHardwareWrite(uint8_t *buffer, int bytes)
|
||||
else return 0;
|
||||
}
|
||||
|
||||
#endif // D2XX
|
||||
#else // WIN32
|
||||
|
||||
#include <ftdi.h>
|
||||
|
||||
static bool ftdiInitialized;
|
||||
static ftdi_context ftdic;
|
||||
|
||||
|
||||
PRResult PRHardwareOpen()
|
||||
{
|
||||
int32_t i=0;
|
||||
PRResult rc;
|
||||
struct ftdi_device_list *devlist, *curdev;
|
||||
char manufacturer[128], description[128];
|
||||
|
||||
ftdiInitialized = false;
|
||||
|
||||
// Open the FTDI device
|
||||
if (ftdi_init(&ftdic) != 0)
|
||||
{
|
||||
PRSetLastErrorText("Failed to initialize FTDI.");
|
||||
return kPRFailure;
|
||||
}
|
||||
|
||||
// Find all FTDI devices
|
||||
// This is very basic and really only expects to see 1 device. It needs to be
|
||||
// smarter. At the very least, it should check some register on the P-ROC versus
|
||||
// an input parameter to ensure the software is set up for the same architecture as
|
||||
// the P-ROC (Stern vs WPC). Otherwise, it's possible to drive the coils the wrong
|
||||
// polarity and blow fuses or fry transistors and all other sorts of badness.
|
||||
|
||||
// We first enumerate all of the devices:
|
||||
int numDevices = ftdi_usb_find_all(&ftdic, &devlist, FTDI_VENDOR_ID, FTDI_FT245RL_PRODUCT_ID);
|
||||
if (numDevices < 0) {
|
||||
PRSetLastErrorText("ftdi_usb_find_all failed: %d: %s", numDevices, ftdi_get_error_string(&ftdic));
|
||||
ftdi_deinit(&ftdic);
|
||||
return kPRFailure;
|
||||
}
|
||||
else {
|
||||
DEBUG(PRLog(kPRLogInfo, "Number of FTDI devices found: %d\n", numDevices));
|
||||
|
||||
for (curdev = devlist; curdev != NULL; i++) {
|
||||
DEBUG(PRLog(kPRLogInfo, "Checking device %d\n", i));
|
||||
if ((rc = (int32_t)ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0) {
|
||||
DEBUG(PRLog(kPRLogInfo, " ftdi_usb_get_strings failed: %d: %s\n", rc, ftdi_get_error_string(&ftdic)));
|
||||
}
|
||||
else {
|
||||
DEBUG(PRLog(kPRLogInfo, " Device #%d:\n", i));
|
||||
DEBUG(PRLog(kPRLogInfo, " Manufacturer: %s\n", manufacturer));
|
||||
DEBUG(PRLog(kPRLogInfo, " Description: %s\n", description));
|
||||
}
|
||||
curdev = curdev->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Don't need the device list anymore
|
||||
ftdi_list_free (&devlist);
|
||||
|
||||
if ((rc = (int32_t)ftdi_usb_open(&ftdic, FTDI_VENDOR_ID, FTDI_FT245RL_PRODUCT_ID)) < 0)
|
||||
{
|
||||
PRSetLastErrorText("Unable to open ftdi device: %d: %s", rc, ftdi_get_error_string(&ftdic));
|
||||
return kPRFailure;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = kPRSuccess;
|
||||
if (ftdic.type == TYPE_R) {
|
||||
uint32_t chipid;
|
||||
ftdi_read_chipid(&ftdic,&chipid);
|
||||
DEBUG(PRLog(kPRLogInfo, "FTDI chip_id = 0x%x\n", chipid));
|
||||
// Set some defaults:
|
||||
ftdi_read_data_set_chunksize(&ftdic, 4096);
|
||||
ftdi_set_latency_timer(&ftdic, 2); // This helps make reads much faster. 16 appeared to be the default.
|
||||
ftdiInitialized = true;
|
||||
return kPRSuccess;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRSetLastErrorText("FTDI type != TYPE_R: 0x%x", ftdic.type);
|
||||
return kPRFailure;
|
||||
}
|
||||
}
|
||||
}
|
||||
void PRHardwareClose()
|
||||
{
|
||||
if (ftdiInitialized)
|
||||
{
|
||||
ftdi_usb_close(&ftdic);
|
||||
ftdi_deinit(&ftdic);
|
||||
}
|
||||
}
|
||||
int PRHardwareRead(uint8_t *buffer, int maxBytes)
|
||||
{
|
||||
return ftdi_read_data(&ftdic, buffer, maxBytes);
|
||||
}
|
||||
int PRHardwareWrite(uint8_t *buffer, int bytes)
|
||||
{
|
||||
return ftdi_write_data(&ftdic, buffer, bytes);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include <string.h>
|
||||
#include "PRDevice.h"
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1300)
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1400)
|
||||
#define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user