From 419269a60de7cfd3915e290a1bb436c71461baf4 Mon Sep 17 00:00:00 2001 From: gstellenberg Date: Mon, 1 Jun 2009 11:07:56 -0500 Subject: [PATCH] Added D2XX support --- src/PRHardware.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/src/PRHardware.cpp b/src/PRHardware.cpp index 3460012..9d2b35f 100644 --- a/src/PRHardware.cpp +++ b/src/PRHardware.cpp @@ -240,7 +240,7 @@ int32_t CreateDMDUpdateConfigBurst ( uint32_t * burst, PRDMDConfig *dmd_config) * As we add support for other drivers (such as D2xx on Windows), we will add more implementations of the PRHardware*() functions here. */ -#if !defined(USE_LIBFTDI) +#if !defined(USE_D2XX) #define USE_LIBFTDI 1 #endif @@ -346,3 +346,134 @@ int PRHardwareWrite(uint8_t *buffer, int bytes) } #endif // USE_LIBFTDI + +#if USE_D2XX +#include "ftd2xx.h" + +#define BUF_SIZE 16 +#define MAX_DEVICES 1 + +// Globals +static FT_HANDLE ftHandles[MAX_DEVICES]; +static FT_HANDLE ftHandle; + +PRResult PRHardwareOpen() +{ + char cBufWrite[BUF_SIZE]; + char * pcBufLD[MAX_DEVICES + 1]; + char cBufLD[MAX_DEVICES][64]; + FT_STATUS ftStatus; + int iNumDevs = 0; + int i, j; + int iDevicesOpen = 0; + + for(i = 0; i < MAX_DEVICES; i++) { + pcBufLD[i] = cBufLD[i]; + ftHandles[i] = NULL; + } + pcBufLD[MAX_DEVICES] = NULL; + + ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_SERIAL_NUMBER); + + if(ftStatus != FT_OK) { + DEBUG(PRLog(kPRLogInfo,"Error: FT_ListDevices(%d)\n", ftStatus)); + return kPRFailure; + } + + for(j = 0; j < BUF_SIZE; j++) { + cBufWrite[j] = j; + } + + for(i = 0; ( (i 0) + { + FT_ResetDevice(ftHandle); + DEBUG(PRLog(kPRLogInfo,"FTDI Device Opened\n")); + return kPRSuccess; + } + else return kPRFailure; +} + +void PRHardwareClose() +{ + int i; + + for(i = 0; i < MAX_DEVICES; i++) { + if(ftHandles[i] != NULL) { + FT_Close(ftHandles[i]); + ftHandles[i] = NULL; + DEBUG(PRLog(kPRLogInfo,"Closed device\n")); + } + } +} + +int PRHardwareRead(uint8_t *buffer, int maxBytes) +{ + FT_STATUS ftStatus; + DWORD bytesToRead; + DWORD bytesRead; + int i; + + ftStatus = FT_GetQueueStatus(ftHandle,&bytesToRead); + if (ftStatus != FT_OK) return 0; + + if (maxBytes < bytesToRead) bytesToRead = maxBytes; + ftStatus = FT_Read(ftHandle, buffer, bytesToRead, &bytesRead); + if (ftStatus == FT_OK) { + DEBUG(PRLog(kPRLogVerbose,"Read %d bytes:\n",bytesRead)); + for (i=0; i