From: Henry Bruce Date: Fri, 26 Jun 2015 20:48:23 +0000 (-0700) Subject: cmake: add FTDI FT4222 support X-Git-Tag: v0.8.0~62 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1c9b87bfd357ec7413c66024121a7bb47d3fbda5;p=contrib%2Fmraa.git cmake: add FTDI FT4222 support Existing FTDI D2xx support is just for serial comms library but FT4222 needs a different library for i2c operation. Signed-off-by: Henry Bruce Signed-off-by: Brendan Le Foll --- diff --git a/CMakeLists.txt b/CMakeLists.txt index eb4ce97..1d2e5c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ option (BUILDSWIGNODE "Build swig node modules." ON) option (BUILDSWIGJAVA "Build Java API." OFF) option (USBPLAT "Detection USB platform." ON) option (FTDID2XX "Build with FTDI D2xx subplatform support." OFF) +option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF) option (IPK "Generate IPK using CPack" OFF) option (RPM "Generate RPM using CPack" OFF) option (BUILDPYTHON3 "Use python3 for building/installing" OFF) diff --git a/cmake/modules/FindFtd4222.cmake b/cmake/modules/FindFtd4222.cmake new file mode 100644 index 0000000..ea49aac --- /dev/null +++ b/cmake/modules/FindFtd4222.cmake @@ -0,0 +1,75 @@ +# - Try to find LIBFT4222 +# Once done this will define +# +# LIBFT4222_FOUND - system has LIBFT4222 +# LIBFT4222_INCLUDE_DIRS - the LIBFT4222 include directory +# LIBFT4222_LIBRARIES - Link these to use LIBFT4222 +# LIBFT4222_DEFINITIONS - Compiler switches required for using LIBFT4222 +# +# Adapted from cmake-modules Google Code project +# +# Copyright (c) 2006 Andreas Schneider +# +# (Changes for LIBFTD2XX) Copyright (c) 2008 Kyle Machulis +# (Changes for LIBFT4222) Henry Bruce Copyright (c) 2015 Intel Corporation. +# +# Redistribution and use is allowed according to the terms of the New BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +if (LIBFT4222_LIBRARIES AND LIBFT4222_INCLUDE_DIRS) + # in cache already + set(LIBFT4222_FOUND TRUE) +else (LIBFT4222_LIBRARIES AND LIBFT4222_INCLUDE_DIRS) + find_path(LIBFT4222_INCLUDE_DIR + NAMES + libft4222.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + ) + + SET(FTD4222_LIBNAME ft4222) + IF(WIN32) + SET(FTD4222_LIBNAME LibFT4222.lib) + ENDIF(WIN32) + + find_library(LIBFT4222_LIBRARY + NAMES + ${FTD4222_LIBNAME} + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + if(LIBFT4222_INCLUDE_DIR) + set(LIBFT4222_INCLUDE_DIRS + ${LIBFT4222_INCLUDE_DIR} + ) + endif(LIBFT4222_INCLUDE_DIR) + set(LIBFT4222_LIBRARIES + ${LIBFT4222_LIBRARY} + ) + + if (LIBFT4222_INCLUDE_DIRS AND LIBFT4222_LIBRARIES) + set(LIBFT4222_FOUND TRUE) + endif (LIBFT4222_INCLUDE_DIRS AND LIBFT4222_LIBRARIES) + + if (LIBFT4222_FOUND) + if (NOT LIBFT4222_FIND_QUIETLY) + message(STATUS "Found LIBFT4222: ${LIBFT4222_LIBRARIES}") + endif (NOT LIBFT4222_FIND_QUIETLY) + else (LIBFT4222_FOUND) + if (LIBFT4222_FIND_REQUIRED) + message(FATAL_ERROR "Could not find LIBFT4222") + endif (LIBFT4222_FIND_REQUIRED) + endif (LIBFT4222_FOUND) + + # show the LIBFT4222_INCLUDE_DIRS and LIBFT4222_LIBRARIES variables only in the advanced view + mark_as_advanced(LIBFT4222_INCLUDE_DIRS LIBFT4222_LIBRARIES) + +endif (LIBFT4222_LIBRARIES AND LIBFT4222_INCLUDE_DIRS) + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 03e8e06..de29ff3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,7 +14,7 @@ add_executable (mraa-i2c mraa-i2c.c) add_executable (spi_max7219 spi_max7219.c) include_directories(${PROJECT_SOURCE_DIR}/api) -# FIXME Hack to access internal types used by mraa-i2c +# FIXME Hack to access mraa internal types used by mraa-i2c include_directories(${PROJECT_SOURCE_DIR}/include) include_directories(${PROJECT_SOURCE_DIR}/api/mraa) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a411332..8faa785 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,7 +48,7 @@ if (ARMPLAT) endif() if (USBPLAT) - add_subdirectory(usb) + message (INFO " - Adding USB platforms") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSBPLAT=1") find_package (Ftd2xx) if (FTDID2xx) @@ -59,9 +59,18 @@ if (USBPLAT) message (WARNING " - Enabled FTDID2xx support but library not found") endif () endif () + find_package (Ftd4222) + if (FTDI4222) + if (${LIBFT4222_FOUND}) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFTDI4222=1") + set (mraa_LIBS ${mraa_LIBS} ${LIBFT4222_LIBRARIES}) + else () + message (WARNING " - Enabled FTDI4222 support but library not found") + endif () + endif () + add_subdirectory(usb) endif () - set (mraa_LIB_SRCS ${mraa_LIB_PLAT_SRCS_NOAUTO} # autogenerated version file diff --git a/src/usb/CMakeLists.txt b/src/usb/CMakeLists.txt index a0c5c87..786c49b 100644 --- a/src/usb/CMakeLists.txt +++ b/src/usb/CMakeLists.txt @@ -1,12 +1,14 @@ -message (INFO " - Adding USB platforms") set (mraa_LIB_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} ${PROJECT_SOURCE_DIR}/src/usb/usb.c - PARENT_SCOPE ) -if (FTDID2XX) - set (mraa_LIB_SRCS_NOAUTO + +if (FTDI4222) + message (INFO " - FTDI4222") + set (mraa_LIB_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} ${PROJECT_SOURCE_DIR}/src/usb/ftdi_ft4222.c PARENT_SCOPE ) endif () + + diff --git a/src/usb/usb.c b/src/usb/usb.c index 1e2d688..46832f5 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -26,7 +26,7 @@ #include #include "mraa_internal.h" -#ifdef FTDID2XX +#ifdef FTDI4222 #include "usb/ftdi_ft4222.h" #endif @@ -35,7 +35,7 @@ mraa_platform_t mraa_usb_platform_extender(mraa_board_t* board) { mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM; -#ifdef FTDID2XX +#ifdef FTDI4222 if (mraa_ftdi_ft4222_init() == MRAA_SUCCESS) { unsigned int versionChip, versionLib; if (mraa_ftdi_ft4222_get_version(&versionChip, &versionLib) == MRAA_SUCCESS) { @@ -43,13 +43,17 @@ mraa_usb_platform_extender(mraa_board_t* board) platform_type = MRAA_FTDI_FT4222; } } +#endif switch (platform_type) { +#ifdef FTDI4222 case MRAA_FTDI_FT4222: mraa_ftdi_ft4222(board); break; +#endif default: syslog(LOG_ERR, "Unknown USB Platform Extender, currently not supported by MRAA"); } -#endif + return platform_type; } +