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:
195
CMakeLists.txt
195
CMakeLists.txt
@@ -1,53 +1,86 @@
|
|||||||
|
###
|
||||||
|
### CMake policy settings
|
||||||
|
###
|
||||||
|
# see http://www.cmake.org/Wiki/CMake_Policies
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.6)
|
||||||
|
# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015
|
||||||
|
if(POLICY CMP0015)
|
||||||
|
cmake_policy(SET CMP0015 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
project (LIBPINPROC)
|
|
||||||
|
|
||||||
# User can redefine to "SHARED" on command line with:
|
###
|
||||||
# cmake -DLIB_TYPE=SHARED ...
|
### Project settings
|
||||||
IF(NOT DEFINED LIB_TYPE)
|
###
|
||||||
set(LIB_TYPE STATIC)
|
project(PINPROC)
|
||||||
ENDIF(NOT DEFINED LIB_TYPE)
|
|
||||||
|
|
||||||
set(PINPROC_VERSION_MAJOR "0")
|
set(PINPROC_VERSION_MAJOR "0")
|
||||||
set(PINPROC_VERSION_MINOR "9")
|
set(PINPROC_VERSION_MINOR "9")
|
||||||
set(PINPROC_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}")
|
set(PINPROC_VERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}")
|
||||||
|
|
||||||
IF(APPLE)
|
|
||||||
# set( CMAKE_OSX_ARCHITECTURES ppc;i386 ) # Uncomment for universal binary
|
|
||||||
ENDIF(APPLE)
|
|
||||||
|
|
||||||
include_directories(${LIBPINPROC_SOURCE_DIR}/include /usr/local/include $ENV{EXTRA_INC})
|
###
|
||||||
link_directories(/usr/local/lib $ENV{EXTRA_LINK})
|
### Project options
|
||||||
|
###
|
||||||
|
# General stuff
|
||||||
|
option(PINPROC_BUILD_TOOLS "Enable testing and firmware tools" ON)
|
||||||
|
|
||||||
set(FILES src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp)
|
# Compilation options
|
||||||
add_library(pinproc
|
# see http://www.cmake.org/cmake/help/cmake2.6docs.html#variable:BUILD_SHARED_LIBS
|
||||||
${LIB_TYPE}
|
# http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library
|
||||||
${FILES}
|
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
|
||||||
${public_headers}
|
# see http://msdn.microsoft.com/en-us/library/aa278396(v=vs.60).aspx
|
||||||
${private_headers}
|
# http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=VS.71%29.aspx
|
||||||
${sources}
|
option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON)
|
||||||
)
|
option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF)
|
||||||
set_target_properties(pinproc PROPERTIES
|
|
||||||
VERSION "${PINPROC_VERSION}"
|
|
||||||
SOVERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}"
|
###
|
||||||
)
|
### Source
|
||||||
|
###
|
||||||
|
# !!! file(GLOB) didn't work on Ubuntu 10.04 with cmake 2.8 !!!
|
||||||
|
#file(GLOB sources src/[a-z]*.cpp)
|
||||||
|
#file(GLOB public_headers include/[a-z]*.h)
|
||||||
|
#file(GLOB private_headers src/[a-z]*.h)
|
||||||
|
set(sources "src/pinproc.cpp;src/PRDevice.cpp;src/PRHardware.cpp")
|
||||||
|
set(public_headers "include/pinproc.h")
|
||||||
|
set(private_headers "src/PRCommon.h;src/PRDevice.h;src/PRHardware.h")
|
||||||
|
message(STATUS "sources is ${sources}")
|
||||||
|
message(STATUS "public_headers is ${public_headers}")
|
||||||
|
message(STATUS "private_headers is ${private_headers}")
|
||||||
|
|
||||||
|
include_directories(${PINPROC_SOURCE_DIR}/include $ENV{EXTRA_INC} /usr/local/include)
|
||||||
|
link_directories($ENV{EXTRA_LINK} /usr/local/lib)
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
### General compilation settings
|
||||||
|
###
|
||||||
|
if(APPLE)
|
||||||
|
# set(CMAKE_OSX_ARCHITECTURES ppc;i386) # Uncomment for universal binary
|
||||||
|
endif()
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(libraries ftd2xx)
|
set(libraries ftd2xx)
|
||||||
set(_library_dir bin) # .dll are in PATH, like executables
|
if(BUILD_SHARED_LIBS)
|
||||||
else(WIN32)
|
add_definitions(-DPINPROC_DLL) # use or build Windows DLL
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
set(libraries usb ftdi)
|
set(libraries usb ftdi)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(YAML_CPP_LIB "yaml-cpp")
|
||||||
|
set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}")
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
### General install settings
|
||||||
|
###
|
||||||
|
if(WIN32)
|
||||||
|
set(_library_dir bin) # .dll are in PATH, like executables
|
||||||
|
else()
|
||||||
set(_library_dir lib)
|
set(_library_dir lib)
|
||||||
endif(WIN32)
|
endif()
|
||||||
|
|
||||||
add_executable(pinproctest examples/pinproctest/pinproctest.cpp examples/pinproctest/drivers.cpp examples/pinproctest/dmd.cpp examples/pinproctest/switches.cpp examples/pinproctest/alphanumeric.cpp)
|
|
||||||
add_executable(pinprocfw utils/pinprocfw/pinprocfw.cpp utils/pinprocfw/lenval.cpp)
|
|
||||||
target_link_libraries(pinproctest pinproc ${libraries} yaml-cpp)
|
|
||||||
target_link_libraries(pinprocfw pinproc ${libraries})
|
|
||||||
|
|
||||||
###############################################################
|
|
||||||
# The remainder of the file is used for "make install" stuff
|
|
||||||
###############################################################
|
|
||||||
|
|
||||||
set(INCLUDE_INSTALL_DIR include/p-roc)
|
set(INCLUDE_INSTALL_DIR include/p-roc)
|
||||||
set(LIB_INSTALL_DIR ${_library_dir}${LIB_SUFFIX})
|
set(LIB_INSTALL_DIR ${_library_dir}${LIB_SUFFIX})
|
||||||
@@ -58,9 +91,59 @@ set(_INSTALL_DESTINATIONS
|
|||||||
ARCHIVE DESTINATION lib${LIB_SUFFIX}
|
ARCHIVE DESTINATION lib${LIB_SUFFIX}
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB public_headers include/[a-z]*.h)
|
|
||||||
file(GLOB private src/[a-z]*.h)
|
###
|
||||||
file(GLOB sources src/[a-z]*.cpp)
|
### Library
|
||||||
|
###
|
||||||
|
add_library(pinproc
|
||||||
|
${sources}
|
||||||
|
${public_headers}
|
||||||
|
${private_headers}
|
||||||
|
)
|
||||||
|
set_target_properties(pinproc PROPERTIES
|
||||||
|
VERSION "${PINPROC_VERSION}"
|
||||||
|
SOVERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Correct MSVC for static libraries (/MD[d], /MT[d], /ML[d] (single-threaded until VS 2003))
|
||||||
|
# see http://msdn.microsoft.com/en-us/library/aa278396(v=vs.60).aspx
|
||||||
|
# http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=VS.71%29.aspx
|
||||||
|
if((MSVC) AND (NOT BUILD_SHARED_LIBS))
|
||||||
|
set(TMP_SUFFIX "md") # CMake defaults to /MD for MSVC
|
||||||
|
|
||||||
|
if (NOT MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML)
|
||||||
|
if (MSVC_STHREADED_RT) # User wants to have old single-threade runtime libraries
|
||||||
|
set(TMP_SUFFIX "ml")
|
||||||
|
set(TMP_OPTION "/ML")
|
||||||
|
if(NOT MSVC_VERSION LESS 1400)
|
||||||
|
message(FATAL_ERROR "Single-threaded runtime libraries (/ML) only availbe until VS .NET 2003 (7.1).")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(TMP_SUFFIX "mt")
|
||||||
|
set(TMP_OPTION "/MT")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# correct linker options
|
||||||
|
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
||||||
|
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
|
||||||
|
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
||||||
|
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
|
||||||
|
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||||
|
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL})
|
||||||
|
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
|
||||||
|
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# correct library names
|
||||||
|
set_target_properties(pinproc PROPERTIES PREFIX "lib")
|
||||||
|
set_target_properties(pinproc PROPERTIES DEBUG_POSTFIX "${TMP_SUFFIX}d")
|
||||||
|
set_target_properties(pinproc PROPERTIES RELEASE_POSTFIX "${TMP_SUFFIX}")
|
||||||
|
set_target_properties(pinproc PROPERTIES MINSIZEREL_POSTFIX "${TMP_SUFFIX}")
|
||||||
|
set_target_properties(pinproc PROPERTIES RELWITHDEBINFO_POSTFIX "${TMP_SUFFIX}")
|
||||||
|
# correct external library names
|
||||||
|
set(YAML_CPP_LIB "lib${YAML_CPP_LIB}${TMP_SUFFIX}")
|
||||||
|
set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}d")
|
||||||
|
endif()
|
||||||
|
|
||||||
install(TARGETS pinproc ${_INSTALL_DESTINATIONS})
|
install(TARGETS pinproc ${_INSTALL_DESTINATIONS})
|
||||||
install(
|
install(
|
||||||
@@ -72,5 +155,37 @@ if(UNIX)
|
|||||||
set(PC_FILE ${CMAKE_BINARY_DIR}/pinproc.pc)
|
set(PC_FILE ${CMAKE_BINARY_DIR}/pinproc.pc)
|
||||||
configure_file("pinproc.pc.cmake" ${PC_FILE} @ONLY)
|
configure_file("pinproc.pc.cmake" ${PC_FILE} @ONLY)
|
||||||
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
||||||
endif(UNIX)
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
### Extras
|
||||||
|
###
|
||||||
|
#TODO: use add_subdirectory() and separate CMakeLists.txt
|
||||||
|
if(PINPROC_BUILD_TOOLS)
|
||||||
|
# Create a target for the test tool (see yaml-cpp)
|
||||||
|
add_executable(pinproctest
|
||||||
|
examples/pinproctest/pinproctest.cpp
|
||||||
|
examples/pinproctest/drivers.cpp
|
||||||
|
examples/pinproctest/dmd.cpp
|
||||||
|
examples/pinproctest/switches.cpp
|
||||||
|
examples/pinproctest/alphanumeric.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(pinproctest
|
||||||
|
pinproc
|
||||||
|
${libraries}
|
||||||
|
optimized ${YAML_CPP_LIB}
|
||||||
|
debug ${YAML_CPP_LIB_DBG}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a target for the firmware tool (see yaml-cpp)
|
||||||
|
#TODO: use add_subdirectory() and separate CMakeLists.txt
|
||||||
|
add_executable(pinprocfw
|
||||||
|
utils/pinprocfw/pinprocfw.cpp
|
||||||
|
utils/pinprocfw/lenval.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(pinprocfw
|
||||||
|
pinproc
|
||||||
|
${libraries}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -348,117 +348,6 @@ int32_t CreateJTAGShiftTDODataBurst ( uint32_t * burst, uint16_t numBits, bool_t
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__WIN32__) || defined(_WIN32)
|
#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"
|
#include "ftd2xx.h"
|
||||||
|
|
||||||
#define BUF_SIZE 16
|
#define BUF_SIZE 16
|
||||||
@@ -587,4 +476,105 @@ int PRHardwareWrite(uint8_t *buffer, int bytes)
|
|||||||
else return 0;
|
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 <string.h>
|
||||||
#include "PRDevice.h"
|
#include "PRDevice.h"
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER < 1300)
|
#if defined(_MSC_VER) && (_MSC_VER < 1400)
|
||||||
#define vsnprintf _vsnprintf
|
#define vsnprintf _vsnprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user