From 122c54b2fff72274e910f5f72a94bba97f69a0f0 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Fri, 11 Jan 2019 12:59:38 -0500 Subject: [PATCH] Reorganize libftdi for easier building under GCC --- CMakeLists.txt | 43 +-- third-party/libftdi/CMakeLists.txt | 1 - third-party/libftdi/examples/CMakeLists.txt | 55 --- third-party/libftdi/examples/baud_test.c | 224 ----------- third-party/libftdi/examples/bitbang.c | 84 ---- third-party/libftdi/examples/bitbang2.c | 89 ----- third-party/libftdi/examples/bitbang_cbus.c | 94 ----- .../bitbang_cbus_eeprom_for_windows.ept | 62 --- third-party/libftdi/examples/bitbang_ft2232.c | 106 ------ .../examples/cmake_example/CMakeLists.txt | 13 - .../libftdi/examples/cmake_example/main.c | 24 -- third-party/libftdi/examples/eeprom.c | 299 --------------- third-party/libftdi/examples/find_all.c | 54 --- third-party/libftdi/examples/find_all_pp.cpp | 72 ---- third-party/libftdi/examples/serial_test.c | 179 --------- third-party/libftdi/examples/simple.c | 53 --- third-party/libftdi/examples/stream_test.c | 358 ------------------ third-party/libftdi/ftdipp/CMakeLists.txt | 21 +- 18 files changed, 29 insertions(+), 1802 deletions(-) delete mode 100644 third-party/libftdi/examples/CMakeLists.txt delete mode 100644 third-party/libftdi/examples/baud_test.c delete mode 100644 third-party/libftdi/examples/bitbang.c delete mode 100644 third-party/libftdi/examples/bitbang2.c delete mode 100644 third-party/libftdi/examples/bitbang_cbus.c delete mode 100644 third-party/libftdi/examples/bitbang_cbus_eeprom_for_windows.ept delete mode 100644 third-party/libftdi/examples/bitbang_ft2232.c delete mode 100644 third-party/libftdi/examples/cmake_example/CMakeLists.txt delete mode 100644 third-party/libftdi/examples/cmake_example/main.c delete mode 100644 third-party/libftdi/examples/eeprom.c delete mode 100644 third-party/libftdi/examples/find_all.c delete mode 100644 third-party/libftdi/examples/find_all_pp.cpp delete mode 100644 third-party/libftdi/examples/serial_test.c delete mode 100644 third-party/libftdi/examples/simple.c delete mode 100644 third-party/libftdi/examples/stream_test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ad84296..12b650e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,18 +24,6 @@ else() #if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-switch -Wno-nested-anon-types -Wno-gnu-anonymous-struct -Wno-unknown-pragmas -Wno-zero-length-array") endif() -# libftdi -if(NOT WIN32) - include_directories(${CMAKE_CURRENT_SOURCE_DIR} third-party/libftdi/src third-party/libftdi/ftdipp) - add_subdirectory(third-party/libftdi) -endif(NOT WIN32) - -# winpcap -if(WIN32) - include_directories(AFTER third-party/winpcap/include) - add_definitions(-DWPCAP -DHAVE_REMOTE -DWIN32_LEAN_AND_MEAN) -endif(WIN32) - # doxygen find_package(Doxygen) if(DOXYGEN_FOUND) @@ -43,7 +31,7 @@ if(DOXYGEN_FOUND) set(ICSNEO_DOCS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/docs) message("Will build Doxygen based documentation") - + add_custom_target(libicsneo_doxygen ALL COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} @@ -142,6 +130,18 @@ target_include_directories(icsneocpp ) set_property(TARGET icsneocpp PROPERTY POSITION_INDEPENDENT_CODE ON) +# libftdi +if(NOT WIN32) + target_include_directories(icsneocpp PUBLIC third-party/libftdi/ftdipp) + add_subdirectory(third-party/libftdi) +endif(NOT WIN32) + +# winpcap +if(WIN32) + target_include_directories(icsneocpp PUBLIC AFTER third-party/winpcap/include) + add_definitions(-DWPCAP -DHAVE_REMOTE -DWIN32_LEAN_AND_MEAN) +endif(WIN32) + add_library(icsneoc SHARED api/icsneoc/icsneoc.cpp) target_include_directories(icsneoc PUBLIC @@ -150,7 +150,7 @@ target_include_directories(icsneoc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ) -target_link_libraries(icsneoc icsneocpp) +target_link_libraries(icsneoc PRIVATE icsneocpp) add_library(icsneolegacy SHARED api/icsneolegacy/icsneolegacy.cpp @@ -164,9 +164,9 @@ target_include_directories(icsneolegacy PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ) -target_link_libraries(icsneolegacy icsneocpp) +target_link_libraries(icsneolegacy PRIVATE icsneocpp) -target_compile_features(icsneocpp PRIVATE cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums) +target_compile_features(icsneocpp PUBLIC cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums) target_compile_features(icsneoc PRIVATE cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums) target_compile_features(icsneolegacy PRIVATE cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums) @@ -175,15 +175,8 @@ if(NOT WIN32) find_package(Threads) set_property(TARGET ftdi1-static PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET ftdipp1-static PROPERTY POSITION_INDEPENDENT_CODE ON) - target_link_libraries(icsneocpp ftdipp1-static) - target_link_libraries(icsneoc ftdipp1-static) - target_link_libraries(icsneolegacy ftdipp1-static) - target_link_libraries(icsneocpp ftdi1-static) - target_link_libraries(icsneoc ftdi1-static) - target_link_libraries(icsneolegacy ftdi1-static) - target_link_libraries(icsneocpp ${CMAKE_THREAD_LIBS_INIT}) - target_link_libraries(icsneoc ${CMAKE_THREAD_LIBS_INIT}) - target_link_libraries(icsneolegacy ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(icsneocpp PUBLIC ftdipp1-static) + target_link_libraries(icsneocpp PUBLIC ${CMAKE_THREAD_LIBS_INIT}) endif() set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/third-party/libftdi/CMakeLists.txt b/third-party/libftdi/CMakeLists.txt index b6ad430..4741d46 100644 --- a/third-party/libftdi/CMakeLists.txt +++ b/third-party/libftdi/CMakeLists.txt @@ -150,7 +150,6 @@ add_subdirectory(src) add_subdirectory(ftdipp) add_subdirectory(python) add_subdirectory(ftdi_eeprom) -add_subdirectory(examples) add_subdirectory(packages) add_subdirectory(test) diff --git a/third-party/libftdi/examples/CMakeLists.txt b/third-party/libftdi/examples/CMakeLists.txt deleted file mode 100644 index 1263c62..0000000 --- a/third-party/libftdi/examples/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -option(EXAMPLES "Build example programs" ON) - -if (EXAMPLES) - # Includes - include_directories( ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ) - - message(STATUS "Building example programs.") - - # Targets - add_executable(simple simple.c) - add_executable(bitbang bitbang.c) - add_executable(bitbang2 bitbang2.c) - add_executable(bitbang_cbus bitbang_cbus.c) - add_executable(bitbang_ft2232 bitbang_ft2232.c) - add_executable(find_all find_all.c) - add_executable(serial_test serial_test.c) - add_executable(baud_test baud_test.c) - add_executable(stream_test stream_test.c) - add_executable(eeprom eeprom.c) - - # Linkage - target_link_libraries(simple ftdi1) - target_link_libraries(bitbang ftdi1) - target_link_libraries(bitbang2 ftdi1) - target_link_libraries(bitbang_cbus ftdi1) - target_link_libraries(bitbang_ft2232 ftdi1) - target_link_libraries(find_all ftdi1) - target_link_libraries(serial_test ftdi1) - target_link_libraries(baud_test ftdi1) - target_link_libraries(stream_test ftdi1) - target_link_libraries(eeprom ftdi1) - - # libftdi++ examples - if(FTDI_BUILD_CPP) - if(Boost_FOUND) - message(STATUS "Building libftdi++ examples.") - include_directories(BEFORE ${CMAKE_SOURCE_DIR}/ftdipp - ${Boost_INCLUDE_DIRS}) - - # Target - add_executable(find_all_pp find_all_pp.cpp) - - # Linkage - target_link_libraries(find_all_pp ftdipp1) - endif(Boost_FOUND) - endif(FTDI_BUILD_CPP) - - # Source includes - include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src) - -else(EXAMPLES) - message(STATUS "Not building example programs.") -endif(EXAMPLES) diff --git a/third-party/libftdi/examples/baud_test.c b/third-party/libftdi/examples/baud_test.c deleted file mode 100644 index eb50e2f..0000000 --- a/third-party/libftdi/examples/baud_test.c +++ /dev/null @@ -1,224 +0,0 @@ -/* baud_test.c - * - * test setting the baudrate and compare it with the expected runtime - * - * options: - * -p defaults to "i:0x0403:0x6001" (this is the first FT232R with default id) - * d: path of bus and device-node (e.g. "003/001") within usb device tree (usually at /proc/bus/usb/) - * i:: first device with given vendor and product id, - * ids can be decimal, octal (preceded by "0") or hex (preceded by "0x") - * i::: as above with index being the number of the device (starting with 0) - * if there are more than one - * s::: first device with given vendor id, product id and serial string - * -d - * -b (divides by 16 if bitbang as taken from the ftdi datasheets) - * -m r: serial a: async bitbang s:sync bitbang - * -c - * - * (C) 2009 by Gerd v. Egidy - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#include -#include -#include -#include -#include - -double get_prec_time() -{ - struct timeval tv; - double res; - - gettimeofday(&tv,NULL); - - res=tv.tv_sec; - res+=((double)tv.tv_usec/1000000); - - return res; -} - -int main(int argc, char **argv) -{ - struct ftdi_context *ftdi; - int i, t; - unsigned char *txbuf; - unsigned char *rxbuf; - double start, duration, plan; - int retval= 0; - - // default values - int baud=9600; - int set_baud; - int datasize=100000; - - char default_devicedesc[] = "i:0x0403:0x6001"; - char *devicedesc=default_devicedesc; - int txchunksize=256; - enum ftdi_mpsse_mode test_mode=BITMODE_BITBANG; - - while ((t = getopt (argc, argv, "b:d:p:m:c:")) != -1) - { - switch (t) - { - case 'd': - datasize = atoi (optarg); - break; - case 'm': - switch (*optarg) - { - case 'r': - // serial - test_mode=BITMODE_RESET; - break; - case 'a': - // async - test_mode=BITMODE_BITBANG; - break; - case 's': - // sync - test_mode=BITMODE_SYNCBB; - break; - } - break; - case 'b': - baud = atoi (optarg); - break; - case 'p': - devicedesc=optarg; - break; - case 'c': - txchunksize = atoi (optarg); - break; - } - } - - txbuf=malloc(txchunksize); - rxbuf=malloc(txchunksize); - if (txbuf == NULL || rxbuf == NULL) - { - fprintf(stderr, "can't malloc\n"); - return EXIT_FAILURE; - } - - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - retval = EXIT_FAILURE; - goto done; - } - - if (ftdi_usb_open_string(ftdi, devicedesc) < 0) - { - fprintf(stderr,"Can't open ftdi device: %s\n",ftdi_get_error_string(ftdi)); - retval = EXIT_FAILURE; - goto do_deinit; - } - - set_baud=baud; - if (test_mode!=BITMODE_RESET) - { - // we do bitbang, so real baudrate / 16 - set_baud=baud/16; - } - - ftdi_set_baudrate(ftdi,set_baud); - printf("real baudrate used: %d\n",(test_mode==BITMODE_RESET) ? ftdi->baudrate : ftdi->baudrate*16); - - if (ftdi_set_bitmode(ftdi, 0xFF,test_mode) < 0) - { - fprintf(stderr,"Can't set mode: %s\n",ftdi_get_error_string(ftdi)); - retval = EXIT_FAILURE; - goto do_close; - } - - if (test_mode==BITMODE_RESET) - { - // serial 8N1: 8 data bits, 1 startbit, 1 stopbit - plan=((double)(datasize*10))/baud; - } - else - { - // bitbang means 8 bits at once - plan=((double)datasize)/baud; - } - - printf("this test should take %.2f seconds\n",plan); - - // prepare data to send: 0 and 1 bits alternating (except for serial start/stopbit): - // maybe someone wants to look at this with a scope or logic analyzer - for (i=0; i0); - } - - start=get_prec_time(); - - // don't wait for more data to arrive, take what we get and keep on sending - // yes, we really would like to have libusb 1.0+ with async read/write... - ftdi->usb_read_timeout=1; - - i=0; - while (i < datasize) - { - int sendsize=txchunksize; - if (i+sendsize > datasize) - sendsize=datasize-i; - - if ((sendsize=ftdi_write_data(ftdi, txbuf, sendsize)) < 0) - { - fprintf(stderr,"write failed at %d: %s\n", - i, ftdi_get_error_string(ftdi)); - retval = EXIT_FAILURE; - goto do_close; - } - - i+=sendsize; - - if (test_mode==BITMODE_SYNCBB) - { - // read the same amount of data as sent - ftdi_read_data(ftdi, rxbuf, sendsize); - } - } - - duration=get_prec_time()-start; - printf("and took %.4f seconds, this is %.0f baud or factor %.3f\n",duration,(plan*baud)/duration,plan/duration); -do_close: - ftdi_usb_close(ftdi); -do_deinit: - ftdi_free(ftdi); -done: - if(rxbuf) - free(rxbuf); - if(txbuf) - free(txbuf); - exit (retval); -} diff --git a/third-party/libftdi/examples/bitbang.c b/third-party/libftdi/examples/bitbang.c deleted file mode 100644 index 0a67772..0000000 --- a/third-party/libftdi/examples/bitbang.c +++ /dev/null @@ -1,84 +0,0 @@ -/* This program is distributed under the GPL, version 2 */ - -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - struct ftdi_context *ftdi; - int f,i; - unsigned char buf[1]; - int retval = 0; - - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - - f = ftdi_usb_open(ftdi, 0x0403, 0x6001); - - if (f < 0 && f != -5) - { - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi)); - retval = 1; - goto done; - } - - printf("ftdi open succeeded: %d\n",f); - - printf("enabling bitbang mode\n"); - ftdi_set_bitmode(ftdi, 0xFF, BITMODE_BITBANG); - - usleep(3 * 1000000); - - buf[0] = 0x0; - printf("turning everything on\n"); - f = ftdi_write_data(ftdi, buf, 1); - if (f < 0) - { - fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(ftdi)); - } - - usleep(3 * 1000000); - - buf[0] = 0xFF; - printf("turning everything off\n"); - f = ftdi_write_data(ftdi, buf, 1); - if (f < 0) - { - fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(ftdi)); - } - - usleep(3 * 1000000); - - for (i = 0; i < 32; i++) - { - buf[0] = 0 | (0xFF ^ 1 << (i % 8)); - if ( i > 0 && (i % 8) == 0) - { - printf("\n"); - } - printf("%02hhx ",buf[0]); - fflush(stdout); - f = ftdi_write_data(ftdi, buf, 1); - if (f < 0) - { - fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(ftdi)); - } - usleep(1 * 1000000); - } - - printf("\n"); - - printf("disabling bitbang mode\n"); - ftdi_disable_bitbang(ftdi); - - ftdi_usb_close(ftdi); -done: - ftdi_free(ftdi); - - return retval; -} diff --git a/third-party/libftdi/examples/bitbang2.c b/third-party/libftdi/examples/bitbang2.c deleted file mode 100644 index f10a496..0000000 --- a/third-party/libftdi/examples/bitbang2.c +++ /dev/null @@ -1,89 +0,0 @@ -/* ftdi_out.c - * - * Output a (stream of) byte(s) in bitbang mode to the - * ftdi245 chip that is (hopefully) attached. - * - * We have a little board that has a FT245BM chip and - * the 8 outputs are connected to several different - * things that we can turn on and off with this program. - * - * If you have an idea about hardware that can easily - * interface onto an FTDI chip, I'd like to collect - * ideas. If I find it worthwhile to make, I'll consider - * making it, I'll even send you a prototype (against - * cost-of-material) if you want. - * - * At "harddisk-recovery.nl" they have a little board that - * controls the power to two harddrives and two fans. - * - * -- REW R.E.Wolff@BitWizard.nl - * - * - * - * This program was based on libftdi_example_bitbang2232.c - * which doesn't carry an author or attribution header. - * - * - * This program is distributed under the GPL, version 2. - * Millions copies of the GPL float around the internet. - */ - - -#include -#include -#include -#include - -void ftdi_fatal (struct ftdi_context *ftdi, char *str) -{ - fprintf (stderr, "%s: %s\n", - str, ftdi_get_error_string (ftdi)); - ftdi_free(ftdi); - exit (1); -} - -int main(int argc, char **argv) -{ - struct ftdi_context *ftdi; - int i, t; - unsigned char data; - int delay = 100000; /* 100 thousand microseconds: 1 tenth of a second */ - - while ((t = getopt (argc, argv, "d:")) != -1) - { - switch (t) - { - case 'd': - delay = atoi (optarg); - break; - } - } - - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_bew failed\n"); - return EXIT_FAILURE; - } - - if (ftdi_usb_open(ftdi, 0x0403, 0x6001) < 0) - ftdi_fatal (ftdi, "Can't open ftdi device"); - - if (ftdi_set_bitmode(ftdi, 0xFF, BITMODE_BITBANG) < 0) - ftdi_fatal (ftdi, "Can't enable bitbang"); - - for (i=optind; i < argc ; i++) - { - sscanf (argv[i], "%x", &t); - data = t; - if (ftdi_write_data(ftdi, &data, 1) < 0) - { - fprintf(stderr,"write failed for 0x%x: %s\n", - data, ftdi_get_error_string(ftdi)); - } - usleep(delay); - } - - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - exit (0); -} diff --git a/third-party/libftdi/examples/bitbang_cbus.c b/third-party/libftdi/examples/bitbang_cbus.c deleted file mode 100644 index b902b50..0000000 --- a/third-party/libftdi/examples/bitbang_cbus.c +++ /dev/null @@ -1,94 +0,0 @@ -/* bitbang_cbus.c - - Example to use CBUS bitbang mode of newer chipsets. - You must enable CBUS bitbang mode in the EEPROM first. - - Thanks to Steve Brown for the - the information how to do it. - - The top nibble controls input/output and the bottom nibble - controls the state of the lines set to output. The datasheet isn't clear - what happens if you set a bit in the output register when that line is - conditioned for input. This is described in more detail - in the FT232R bitbang app note. - - BITMASK - CBUS Bits - 3210 3210 - xxxx xxxx - |    |------ Output Control 0->LO, 1->HI - |----------- Input/Output   0->Input, 1->Output - - Example: - All pins to output with 0 bit high: 0xF1 (11110001) - Bits 0 and 1 to input, 2 and 3 to output and masked high: 0xCC (11001100) - - The input is standard "0x" hex notation. - A carriage return terminates the program. - - This program is distributed under the GPL, version 2 -*/ - -#include -#include -#include -#include - -int main(void) -{ - struct ftdi_context *ftdi; - int f; - unsigned char buf[1]; - unsigned char bitmask; - char input[10]; - - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - - f = ftdi_usb_open(ftdi, 0x0403, 0x6001); - if (f < 0 && f != -5) - { - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi)); - ftdi_free(ftdi); - exit(-1); - } - printf("ftdi open succeeded: %d\n",f); - - while (1) - { - // Set bitmask from input - fgets(input, sizeof(input) - 1, stdin); - if (input[0] == '\n') break; - bitmask = strtol(input, NULL, 0); - printf("Using bitmask 0x%02x\n", bitmask); - f = ftdi_set_bitmode(ftdi, bitmask, BITMODE_CBUS); - if (f < 0) - { - fprintf(stderr, "set_bitmode failed for 0x%x, error %d (%s)\n", bitmask, f, ftdi_get_error_string(ftdi)); - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - exit(-1); - } - - // read CBUS - f = ftdi_read_pins(ftdi, &buf[0]); - if (f < 0) - { - fprintf(stderr, "read_pins failed, error %d (%s)\n", f, ftdi_get_error_string(ftdi)); - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - exit(-1); - } - printf("Read returned 0x%01x\n", buf[0] & 0x0f); - } - printf("disabling bitbang mode\n"); - ftdi_disable_bitbang(ftdi); - - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - - return 0; -} diff --git a/third-party/libftdi/examples/bitbang_cbus_eeprom_for_windows.ept b/third-party/libftdi/examples/bitbang_cbus_eeprom_for_windows.ept deleted file mode 100644 index 59716c6..0000000 --- a/third-party/libftdi/examples/bitbang_cbus_eeprom_for_windows.ept +++ /dev/null @@ -1,62 +0,0 @@ -[Basic Details] -Device Type=6 -VID PID Type=0 -USB VID=0403 -USB PID=6001 -[USB Power Options] -Bus Powered=1 -Self Powered=0 -Max Bus Power=44 -[USB Serial Number Control] -Prefix=FT -Use Fixed Serial Number=0 -Fixed Serial Number=FTDECZJT -[USB Remote WakeUp] -Enable Remote WakeUp=1 -[Windows Plug and Play] -Enable Plug and Play=0 -[USB String Descriptors] -Manufacturer=FTDI -Product=USB Serial Converter -[Programming Options] -Only Program Blank Devices=0 -[BM Device Specific Options] -USB Version Number=1 -Disable Serial Number=0 -IO Pin Pull Down in Suspend=0 -[Dual Device Specific Options A] -RS 232 mode=1 -245 FIFO mode=0 -245 CPU FIFO mode=0 -OPTO Isolate mode=1 -High Current Drive=0 -[Dual Device Specific Options B] -RS 232 mode=1 -245 FIFO mode=0 -245 CPU FIFO mode=0 -OPTO Isolate mode=0 -High Current Drive=0 -[Dual Device Driver Options A] -Virtual Com Port Driver=1 -D2XX Driver=0 -[Dual Device Driver Options B] -Virtual Com Port Driver=1 -D2XX Driver=0 -[R Device Specific Options] -Invert TXD=0 -Invert RXD=0 -Invert RTS#=0 -Invert CTS#=0 -Invert DTR#=0 -Invert DSR#=0 -Invert DCD#=0 -Invert RI#=0 -C0 Signal=10 -C1 Signal=10 -C2 Signal=10 -C3 Signal=10 -C4 Signal=5 -Enable Ext Osc=0 -High Current I/O=0 -Load D2XX Driver=0 -In EndPoint Size=0 diff --git a/third-party/libftdi/examples/bitbang_ft2232.c b/third-party/libftdi/examples/bitbang_ft2232.c deleted file mode 100644 index 8f10490..0000000 --- a/third-party/libftdi/examples/bitbang_ft2232.c +++ /dev/null @@ -1,106 +0,0 @@ -/* bitbang_ft2232.c - - Output some flickering in bitbang mode to the FT2232 - - Thanks to max@koeln.ccc.de for fixing and extending - the example for the second channel. - - This program is distributed under the GPL, version 2 -*/ - -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - struct ftdi_context *ftdi, *ftdi2; - unsigned char buf[1]; - int f,i; - - // Init 1. channel - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - - ftdi_set_interface(ftdi, INTERFACE_A); - f = ftdi_usb_open(ftdi, 0x0403, 0x6001); - if (f < 0 && f != -5) - { - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi)); - ftdi_free(ftdi); - exit(-1); - } - printf("ftdi open succeeded(channel 1): %d\n",f); - - printf("enabling bitbang mode(channel 1)\n"); - ftdi_set_bitmode(ftdi, 0xFF, BITMODE_BITBANG); - - // Init 2. channel - if ((ftdi2 = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - ftdi_set_interface(ftdi2, INTERFACE_B); - f = ftdi_usb_open(ftdi2, 0x0403, 0x6001); - if (f < 0 && f != -5) - { - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi2)); - ftdi_free(ftdi2); - exit(-1); - } - printf("ftdi open succeeded(channel 2): %d\n",f); - - printf("enabling bitbang mode (channel 2)\n"); - ftdi_set_bitmode(ftdi2, 0xFF, BITMODE_BITBANG); - - // Write data - printf("startloop\n"); - for (i = 0; i < 23; i++) - { - buf[0] = 0x1; - printf("porta: %02i: 0x%02x \n",i,buf[0]); - f = ftdi_write_data(ftdi, buf, 1); - if (f < 0) - fprintf(stderr,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(ftdi)); - usleep(1 * 1000000); - - buf[0] = 0x2; - printf("porta: %02i: 0x%02x \n",i,buf[0]); - f = ftdi_write_data(ftdi, buf, 1); - if (f < 0) - fprintf(stderr,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(ftdi)); - usleep(1 * 1000000); - - buf[0] = 0x1; - printf("portb: %02i: 0x%02x \n",i,buf[0]); - f = ftdi_write_data(ftdi2, buf, 1); - if (f < 0) - fprintf(stderr,"write failed on channel 2 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(ftdi2)); - usleep(1 * 1000000); - - buf[0] = 0x2; - printf("portb: %02i: 0x%02x \n",i,buf[0]); - f = ftdi_write_data(ftdi2, buf, 1); - if (f < 0) - fprintf(stderr,"write failed on channel 2 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(ftdi2)); - usleep(1 * 1000000); - } - printf("\n"); - - printf("disabling bitbang mode(channel 1)\n"); - ftdi_disable_bitbang(ftdi); - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - - printf("disabling bitbang mode(channel 2)\n"); - ftdi_disable_bitbang(ftdi2); - ftdi_usb_close(ftdi2); - ftdi_free(ftdi2); - - return 0; -} diff --git a/third-party/libftdi/examples/cmake_example/CMakeLists.txt b/third-party/libftdi/examples/cmake_example/CMakeLists.txt deleted file mode 100644 index fe203ed..0000000 --- a/third-party/libftdi/examples/cmake_example/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required ( VERSION 2.8 ) - -project ( example C ) - -find_package ( LibFTDI1 NO_MODULE REQUIRED ) -include ( ${LIBFTDI_USE_FILE} ) - -add_executable ( example main.c ) -target_link_libraries( example ${LIBFTDI_LIBRARIES} ) - -install ( TARGETS example - DESTINATION bin ) - diff --git a/third-party/libftdi/examples/cmake_example/main.c b/third-party/libftdi/examples/cmake_example/main.c deleted file mode 100644 index 93b3a79..0000000 --- a/third-party/libftdi/examples/cmake_example/main.c +++ /dev/null @@ -1,24 +0,0 @@ -/* main.c - - Example for ftdi_new() - - This program is distributed under the GPL, version 2 -*/ - -#include -#include -#include - -int main(void) -{ - struct ftdi_context *ftdi; - int retval = EXIT_SUCCESS; - - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - - return retval; -} diff --git a/third-party/libftdi/examples/eeprom.c b/third-party/libftdi/examples/eeprom.c deleted file mode 100644 index 247589a..0000000 --- a/third-party/libftdi/examples/eeprom.c +++ /dev/null @@ -1,299 +0,0 @@ -/* LIBFTDI EEPROM access example - - This program is distributed under the GPL, version 2 -*/ - -#include -#include -#include -#include -#include -#include -#include - -int read_decode_eeprom(struct ftdi_context *ftdi) -{ - int i, j, f; - int value; - int size; - unsigned char buf[256]; - - f = ftdi_read_eeprom(ftdi); - if (f < 0) - { - fprintf(stderr, "ftdi_read_eeprom: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - return -1; - } - - - ftdi_get_eeprom_value(ftdi, CHIP_SIZE, & value); - if (value <0) - { - fprintf(stderr, "No EEPROM found or EEPROM empty\n"); - fprintf(stderr, "On empty EEPROM, use -w option to write default values\n"); - return -1; - } - fprintf(stderr, "Chip type %d ftdi_eeprom_size: %d\n", ftdi->type, value); - if (ftdi->type == TYPE_R) - size = 0xa0; - else - size = value; - ftdi_get_eeprom_buf(ftdi, buf, size); - for (i=0; i < size; i += 16) - { - fprintf(stdout,"0x%03x:", i); - - for (j = 0; j< 8; j++) - fprintf(stdout," %02x", buf[i+j]); - fprintf(stdout," "); - for (; j< 16; j++) - fprintf(stdout," %02x", buf[i+j]); - fprintf(stdout," "); - for (j = 0; j< 8; j++) - fprintf(stdout,"%c", isprint(buf[i+j])?buf[i+j]:'.'); - fprintf(stdout," "); - for (; j< 16; j++) - fprintf(stdout,"%c", isprint(buf[i+j])?buf[i+j]:'.'); - fprintf(stdout,"\n"); - } - - f = ftdi_eeprom_decode(ftdi, 1); - if (f < 0) - { - fprintf(stderr, "ftdi_eeprom_decode: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - return -1; - } - return 0; -} - -int main(int argc, char **argv) -{ - struct ftdi_context *ftdi; - int f, i; - int vid = 0; - int pid = 0; - char const *desc = 0; - char const *serial = 0; - int erase = 0; - int use_defaults = 0; - int large_chip = 0; - int do_write = 0; - int retval = 0; - int value; - - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "Failed to allocate ftdi structure :%s \n", - ftdi_get_error_string(ftdi)); - return EXIT_FAILURE; - } - - while ((i = getopt(argc, argv, "d::ev:p:l:P:S:w")) != -1) - { - switch (i) - { - case 'd': - use_defaults = 1; - if (optarg) - large_chip = 0x66; - break; - case 'e': - erase = 1; - break; - case 'v': - vid = strtoul(optarg, NULL, 0); - break; - case 'p': - pid = strtoul(optarg, NULL, 0); - break; - case 'P': - desc = optarg; - break; - case 'S': - serial = optarg; - break; - case 'w': - do_write = 1; - break; - default: - fprintf(stderr, "usage: %s [options]\n", *argv); - fprintf(stderr, "\t-d[num] Work with default valuesfor 128 Byte " - "EEPROM or for 256 Byte EEPROM if some [num] is given\n"); - fprintf(stderr, "\t-w write\n"); - fprintf(stderr, "\t-e erase\n"); - fprintf(stderr, "\t-v verbose decoding\n"); - fprintf(stderr, "\t-p Search for device with PID == number\n"); - fprintf(stderr, "\t-v Search for device with VID == number\n"); - fprintf(stderr, "\t-P 1) - { - int i = 1; - fprintf(stderr, "%d FTDI devices found: Only Readout on EEPROM done. ",res); - fprintf(stderr, "Use VID/PID/desc/serial to select device\n"); - for (curdev = devlist; curdev != NULL; curdev= curdev->next, i++) - { - f = ftdi_usb_open_dev(ftdi, curdev->dev); - if (f<0) - { - fprintf(stderr, "Unable to open device %d: (%s)", - i, ftdi_get_error_string(ftdi)); - continue; - } - fprintf(stderr, "Decoded values of device %d:\n", i); - read_decode_eeprom(ftdi); - ftdi_usb_close(ftdi); - } - ftdi_list_free(&devlist); - retval = EXIT_SUCCESS; - goto do_deinit; - } - else if (res == 1) - { - f = ftdi_usb_open_dev(ftdi, devlist[0].dev); - if (f<0) - { - fprintf(stderr, "Unable to open device %d: (%s)", - i, ftdi_get_error_string(ftdi)); - } - } - else - { - fprintf(stderr, "No devices found\n"); - f = 0; - } - ftdi_list_free(&devlist); - } - else - { - // Open device - f = ftdi_usb_open_desc(ftdi, vid, pid, desc, serial); - if (f < 0) - { - fprintf(stderr, "Device VID 0x%04x PID 0x%04x", vid, pid); - if (desc) - fprintf(stderr, " Desc %s", desc); - if (serial) - fprintf(stderr, " Serial %s", serial); - fprintf(stderr, "\n"); - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - - retval = -1; - goto done; - } - } - if (erase) - { - f = ftdi_erase_eeprom(ftdi); /* needed to determine EEPROM chip type */ - if (f < 0) - { - fprintf(stderr, "Erase failed: %s", - ftdi_get_error_string(ftdi)); - retval = -2; - goto done; - } - if (ftdi_get_eeprom_value(ftdi, CHIP_TYPE, & value) <0) - { - fprintf(stderr, "ftdi_get_eeprom_value: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - } - if (value == -1) - fprintf(stderr, "No EEPROM\n"); - else if (value == 0) - fprintf(stderr, "Internal EEPROM\n"); - else - fprintf(stderr, "Found 93x%02x\n", value); - retval = 0; - goto done; - } - - if (use_defaults) - { - ftdi_eeprom_initdefaults(ftdi, NULL, NULL, NULL); - if (ftdi_set_eeprom_value(ftdi, MAX_POWER, 500) <0) - { - fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - } - if (large_chip) - if (ftdi_set_eeprom_value(ftdi, CHIP_TYPE, 0x66) <0) - { - fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - } - f=(ftdi_eeprom_build(ftdi)); - if (f < 0) - { - fprintf(stderr, "ftdi_eeprom_build: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - retval = -1; - goto done; - } - } - else if (do_write) - { - ftdi_eeprom_initdefaults(ftdi, NULL, NULL, NULL); - f = ftdi_erase_eeprom(ftdi); - if (ftdi_set_eeprom_value(ftdi, MAX_POWER, 500) <0) - { - fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - } - f = ftdi_erase_eeprom(ftdi);/* needed to determine EEPROM chip type */ - if (ftdi_get_eeprom_value(ftdi, CHIP_TYPE, & value) <0) - { - fprintf(stderr, "ftdi_get_eeprom_value: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - } - if (value == -1) - fprintf(stderr, "No EEPROM\n"); - else if (value == 0) - fprintf(stderr, "Internal EEPROM\n"); - else - fprintf(stderr, "Found 93x%02x\n", value); - f=(ftdi_eeprom_build(ftdi)); - if (f < 0) - { - fprintf(stderr, "Erase failed: %s", - ftdi_get_error_string(ftdi)); - retval = -2; - goto done; - } - f = ftdi_write_eeprom(ftdi); - { - fprintf(stderr, "ftdi_eeprom_decode: %d (%s)\n", - f, ftdi_get_error_string(ftdi)); - retval = 1; - goto done; - } - } - retval = read_decode_eeprom(ftdi); -done: - ftdi_usb_close(ftdi); -do_deinit: - ftdi_free(ftdi); - return retval; -} diff --git a/third-party/libftdi/examples/find_all.c b/third-party/libftdi/examples/find_all.c deleted file mode 100644 index 4a70650..0000000 --- a/third-party/libftdi/examples/find_all.c +++ /dev/null @@ -1,54 +0,0 @@ -/* find_all.c - - Example for ftdi_usb_find_all() - - This program is distributed under the GPL, version 2 -*/ - -#include -#include -#include - -int main(void) -{ - int ret, i; - struct ftdi_context *ftdi; - struct ftdi_device_list *devlist, *curdev; - char manufacturer[128], description[128]; - int retval = EXIT_SUCCESS; - - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - - if ((ret = ftdi_usb_find_all(ftdi, &devlist, 0, 0)) < 0) - { - fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); - retval = EXIT_FAILURE; - goto do_deinit; - } - - printf("Number of FTDI devices found: %d\n", ret); - - i = 0; - for (curdev = devlist; curdev != NULL; i++) - { - printf("Checking device: %d\n", i); - if ((ret = ftdi_usb_get_strings(ftdi, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0) - { - fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); - retval = EXIT_FAILURE; - goto done; - } - printf("Manufacturer: %s, Description: %s\n\n", manufacturer, description); - curdev = curdev->next; - } -done: - ftdi_list_free(&devlist); -do_deinit: - ftdi_free(ftdi); - - return retval; -} diff --git a/third-party/libftdi/examples/find_all_pp.cpp b/third-party/libftdi/examples/find_all_pp.cpp deleted file mode 100644 index 4061cd9..0000000 --- a/third-party/libftdi/examples/find_all_pp.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* final_all_pp.cpp - - Simple libftdi-cpp usage - - This program is distributed under the GPL, version 2 -*/ - -#include "ftdi.hpp" -#include -#include -#include -#include -using namespace Ftdi; - -int main(int argc, char **argv) -{ - // Show help - if (argc > 1) - { - if (strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"--help") == 0) - { - std::cout << "Usage: " << argv[0] << " [-v VENDOR_ID] [-p PRODUCT_ID]" << std::endl; - return EXIT_SUCCESS; - } - } - - // Parse args - int vid = 0x0403, pid = 0x6010, tmp = 0; - for (int i = 0; i < (argc - 1); i++) - { - if (strcmp(argv[i], "-v") == 0) - if ((tmp = strtol(argv[++i], 0, 16)) >= 0) - vid = tmp; - - if (strcmp(argv[i], "-p") == 0) - if ((tmp = strtol(argv[++i], 0, 16)) >= 0) - pid = tmp; - } - - // Print header - std::cout << std::hex << std::showbase - << "Found devices ( VID: " << vid << ", PID: " << pid << " )" - << std::endl - << "------------------------------------------------" - << std::endl << std::dec; - - // Print whole list - Context context; - List* list = List::find_all(context, vid, pid); - for (List::iterator it = list->begin(); it != list->end(); it++) - { - std::cout << "FTDI (" << &*it << "): " - << it->vendor() << ", " - << it->description() << ", " - << it->serial(); - - // Open test - if(it->open() == 0) - std::cout << " (Open OK)"; - else - std::cout << " (Open FAILED)"; - - it->close(); - - std::cout << std::endl; - - } - - delete list; - - return EXIT_SUCCESS; -} diff --git a/third-party/libftdi/examples/serial_test.c b/third-party/libftdi/examples/serial_test.c deleted file mode 100644 index 289dd97..0000000 --- a/third-party/libftdi/examples/serial_test.c +++ /dev/null @@ -1,179 +0,0 @@ -/* serial_test.c - - Read/write data via serial I/O - - This program is distributed under the GPL, version 2 -*/ - -#include -#include -#include -#include -#include -#include - -static int exitRequested = 0; -/* - * sigintHandler -- - * - * SIGINT handler, so we can gracefully exit when the user hits ctrl-C. - */ -static void -sigintHandler(int signum) -{ - exitRequested = 1; -} - -int main(int argc, char **argv) -{ - struct ftdi_context *ftdi; - unsigned char buf[1024]; - int f = 0, i; - int vid = 0x403; - int pid = 0; - int baudrate = 115200; - int interface = INTERFACE_ANY; - int do_write = 0; - unsigned int pattern = 0xffff; - int retval = EXIT_FAILURE; - - while ((i = getopt(argc, argv, "i:v:p:b:w::")) != -1) - { - switch (i) - { - case 'i': // 0=ANY, 1=A, 2=B, 3=C, 4=D - interface = strtoul(optarg, NULL, 0); - break; - case 'v': - vid = strtoul(optarg, NULL, 0); - break; - case 'p': - pid = strtoul(optarg, NULL, 0); - break; - case 'b': - baudrate = strtoul(optarg, NULL, 0); - break; - case 'w': - do_write = 1; - if (optarg) - pattern = strtoul(optarg, NULL, 0); - if (pattern > 0xff) - { - fprintf(stderr, "Please provide a 8 bit pattern\n"); - exit(-1); - } - break; - default: - fprintf(stderr, "usage: %s [-i interface] [-v vid] [-p pid] [-b baudrate] [-w [pattern]]\n", *argv); - exit(-1); - } - } - - // Init - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - - if (!vid && !pid && (interface == INTERFACE_ANY)) - { - ftdi_set_interface(ftdi, INTERFACE_ANY); - struct ftdi_device_list *devlist; - int res; - if ((res = ftdi_usb_find_all(ftdi, &devlist, 0, 0)) < 0) - { - fprintf(stderr, "No FTDI with default VID/PID found\n"); - goto do_deinit; - } - if (res == 1) - { - f = ftdi_usb_open_dev(ftdi, devlist[0].dev); - if (f<0) - { - fprintf(stderr, "Unable to open device %d: (%s)", - i, ftdi_get_error_string(ftdi)); - } - } - ftdi_list_free(&devlist); - if (res > 1) - { - fprintf(stderr, "%d Devices found, please select Device with VID/PID\n", res); - /* TODO: List Devices*/ - goto do_deinit; - } - if (res == 0) - { - fprintf(stderr, "No Devices found with default VID/PID\n"); - goto do_deinit; - } - } - else - { - // Select interface - ftdi_set_interface(ftdi, interface); - - // Open device - f = ftdi_usb_open(ftdi, vid, pid); - } - if (f < 0) - { - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi)); - exit(-1); - } - - // Set baudrate - f = ftdi_set_baudrate(ftdi, baudrate); - if (f < 0) - { - fprintf(stderr, "unable to set baudrate: %d (%s)\n", f, ftdi_get_error_string(ftdi)); - exit(-1); - } - - /* Set line parameters - * - * TODO: Make these parameters settable from the command line - * - * Parameters are choosen that sending a continous stream of 0x55 - * should give a square wave - * - */ - f = ftdi_set_line_property(ftdi, 8, STOP_BIT_1, NONE); - if (f < 0) - { - fprintf(stderr, "unable to set line parameters: %d (%s)\n", f, ftdi_get_error_string(ftdi)); - exit(-1); - } - - if (do_write) - for(i=0; i<1024; i++) - buf[i] = pattern; - - signal(SIGINT, sigintHandler); - while (!exitRequested) - { - if (do_write) - f = ftdi_write_data(ftdi, buf, - (baudrate/512 >sizeof(buf))?sizeof(buf): - (baudrate/512)?baudrate/512:1); - else - f = ftdi_read_data(ftdi, buf, sizeof(buf)); - if (f<0) - usleep(1 * 1000000); - else if(f> 0 && !do_write) - { - fprintf(stderr, "read %d bytes\n", f); - fwrite(buf, f, 1, stdout); - fflush(stderr); - fflush(stdout); - } - } - signal(SIGINT, SIG_DFL); - retval = EXIT_SUCCESS; - - ftdi_usb_close(ftdi); - do_deinit: - ftdi_free(ftdi); - - return retval; -} diff --git a/third-party/libftdi/examples/simple.c b/third-party/libftdi/examples/simple.c deleted file mode 100644 index cfd674b..0000000 --- a/third-party/libftdi/examples/simple.c +++ /dev/null @@ -1,53 +0,0 @@ -/* simple.c - - Simple libftdi usage example - - This program is distributed under the GPL, version 2 -*/ - -#include -#include -#include - -int main(void) -{ - int ret; - struct ftdi_context *ftdi; - struct ftdi_version_info version; - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - - version = ftdi_get_library_version(); - printf("Initialized libftdi %s (major: %d, minor: %d, micro: %d, snapshot ver: %s)\n", - version.version_str, version.major, version.minor, version.micro, - version.snapshot_str); - - if ((ret = ftdi_usb_open(ftdi, 0x0403, 0x6001)) < 0) - { - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); - ftdi_free(ftdi); - return EXIT_FAILURE; - } - - // Read out FTDIChip-ID of R type chips - if (ftdi->type == TYPE_R) - { - unsigned int chipid; - printf("ftdi_read_chipid: %d\n", ftdi_read_chipid(ftdi, &chipid)); - printf("FTDI chipid: %X\n", chipid); - } - - if ((ret = ftdi_usb_close(ftdi)) < 0) - { - fprintf(stderr, "unable to close ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); - ftdi_free(ftdi); - return EXIT_FAILURE; - } - - ftdi_free(ftdi); - - return EXIT_SUCCESS; -} diff --git a/third-party/libftdi/examples/stream_test.c b/third-party/libftdi/examples/stream_test.c deleted file mode 100644 index 43abea9..0000000 --- a/third-party/libftdi/examples/stream_test.c +++ /dev/null @@ -1,358 +0,0 @@ -/* stream_test.c - * - * Test reading from FT2232H in synchronous FIFO mode. - * - * The FT2232H must supply data due to an appropriate circuit - * - * To check for skipped block with appended code, - * a structure as follows is assumed - * 1* uint32_t num (incremented in 0x4000 steps) - * 3* uint32_t dont_care - * - * After start, data will be read in streaming until the program is aborted - * Progess information wil be printed out - * If a filename is given on the command line, the data read will be - * written to that file - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -void check_outfile(char *); - -static FILE *outputFile; - -static int check = 1; -static int exitRequested = 0; -/* - * sigintHandler -- - * - * SIGINT handler, so we can gracefully exit when the user hits ctrl-C. - */ - -static void -sigintHandler(int signum) -{ - exitRequested = 1; -} - -static void -usage(const char *argv0) -{ - fprintf(stderr, - "Usage: %s [options...] \n" - "Test streaming read from FT2232H\n" - "[-P string] only look for product with given string\n" - "[-n] don't check for special block structure\n" - "\n" - "If some filename is given, write data read to that file\n" - "Progess information is printed each second\n" - "Abort with ^C\n" - "\n" - "Options:\n" - "\n" - "Copyright (C) 2009 Micah Dowty \n" - "Adapted for use with libftdi (C) 2010 Uwe Bonnes \n", - argv0); - exit(1); -} - -static uint32_t start = 0; -static uint32_t offset = 0; -static uint64_t blocks = 0; -static uint32_t skips = 0; -static uint32_t n_err = 0; -static int -readCallback(uint8_t *buffer, int length, FTDIProgressInfo *progress, void *userdata) -{ - if (length) - { - if (check) - { - int i,rem; - uint32_t num; - for (i= offset; i3) - { - num = *(uint32_t*) (buffer+i); - if (start && (num != start +0x4000)) - { - uint32_t delta = ((num-start)/0x4000)-1; - fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at blocks %10llu\n", - delta, start -0x4000, num, (unsigned long long) blocks); - n_err++; - skips += delta; - } - start = num; - } - else if (rem) - start += 0x4000; - if (rem != 0) - { - blocks ++; - offset = 16-rem; - } - } - if (outputFile) - { - if (fwrite(buffer, length, 1, outputFile) != 1) - { - perror("Write error"); - return 1; - } - } - } - if (progress) - { - fprintf(stderr, "%10.02fs total time %9.3f MiB captured %7.1f kB/s curr rate %7.1f kB/s totalrate %d dropouts\n", - progress->totalTime, - progress->current.totalBytes / (1024.0 * 1024.0), - progress->currentRate / 1024.0, - progress->totalRate / 1024.0, - n_err); - } - return exitRequested ? 1 : 0; -} - -int main(int argc, char **argv) -{ - struct ftdi_context *ftdi; - int err, c; - FILE *of = NULL; - char const *outfile = 0; - outputFile =0; - exitRequested = 0; - char *descstring = NULL; - int option_index; - static struct option long_options[] = {{NULL},}; - - while ((c = getopt_long(argc, argv, "P:n", long_options, &option_index)) !=- 1) - switch (c) - { - case -1: - break; - case 'P': - descstring = optarg; - break; - case 'n': - check = 0; - break; - default: - usage(argv[0]); - } - - if (optind == argc - 1) - { - // Exactly one extra argument- a dump file - outfile = argv[optind]; - } - else if (optind < argc) - { - // Too many extra args - usage(argv[0]); - } - - if ((ftdi = ftdi_new()) == 0) - { - fprintf(stderr, "ftdi_new failed\n"); - return EXIT_FAILURE; - } - - if (ftdi_set_interface(ftdi, INTERFACE_A) < 0) - { - fprintf(stderr, "ftdi_set_interface failed\n"); - ftdi_free(ftdi); - return EXIT_FAILURE; - } - - if (ftdi_usb_open_desc(ftdi, 0x0403, 0x6010, descstring, NULL) < 0) - { - fprintf(stderr,"Can't open ftdi device: %s\n",ftdi_get_error_string(ftdi)); - ftdi_free(ftdi); - return EXIT_FAILURE; - } - - /* A timeout value of 1 results in may skipped blocks */ - if(ftdi_set_latency_timer(ftdi, 2)) - { - fprintf(stderr,"Can't set latency, Error %s\n",ftdi_get_error_string(ftdi)); - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - return EXIT_FAILURE; - } - -/* if(ftdi_usb_purge_rx_buffer(ftdi) < 0) - { - fprintf(stderr,"Can't rx purge\n",ftdi_get_error_string(ftdi)); - return EXIT_FAILURE; - }*/ - if (outfile) - if ((of = fopen(outfile,"w+")) == 0) - fprintf(stderr,"Can't open logfile %s, Error %s\n", outfile, strerror(errno)); - if (of) - if (setvbuf(of, NULL, _IOFBF , 1<<16) == 0) - outputFile = of; - signal(SIGINT, sigintHandler); - - err = ftdi_readstream(ftdi, readCallback, NULL, 8, 256); - if (err < 0 && !exitRequested) - exit(1); - - if (outputFile) { - fclose(outputFile); - outputFile = NULL; - } - fprintf(stderr, "Capture ended.\n"); - - if (ftdi_set_bitmode(ftdi, 0xff, BITMODE_RESET) < 0) - { - fprintf(stderr,"Can't set synchronous fifo mode, Error %s\n",ftdi_get_error_string(ftdi)); - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - return EXIT_FAILURE; - } - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - signal(SIGINT, SIG_DFL); - if (check && outfile) - { - if ((outputFile = fopen(outfile,"r")) == 0) - { - fprintf(stderr,"Can't open logfile %s, Error %s\n", outfile, strerror(errno)); - ftdi_usb_close(ftdi); - ftdi_free(ftdi); - return EXIT_FAILURE; - } - check_outfile(descstring); - fclose(outputFile); - } - else if (check) - fprintf(stderr,"%d errors of %llu blocks (%Le), %d (%Le) blocks skipped\n", - n_err, (unsigned long long) blocks, (long double)n_err/(long double) blocks, - skips, (long double)skips/(long double) blocks); - exit (0); -} - -void check_outfile(char *descstring) -{ - if(strcmp(descstring,"FT2232HTEST") == 0) - { - char buf0[1024]; - char buf1[1024]; - char bufr[1024]; - char *pa, *pb, *pc; - unsigned int num_lines = 0, line_num = 1; - int err_count = 0; - unsigned int num_start, num_end; - - pa = buf0; - pb = buf1; - pc = buf0; - if(fgets(pa, 1023, outputFile) == NULL) - { - fprintf(stderr,"Empty output file\n"); - return; - } - while(fgets(pb, 1023, outputFile) != NULL) - { - num_lines++; - unsigned int num_save = num_start; - if( sscanf(pa,"%6u%94s%6u",&num_start, bufr,&num_end) !=3) - { - fprintf(stdout,"Format doesn't match at line %8d \"%s", - num_lines, pa); - err_count++; - line_num = num_save +2; - } - else - { - if ((num_start+1)%100000 != num_end) - { - if (err_count < 20) - fprintf(stdout,"Malformed line %d \"%s\"\n", - num_lines, pa); - err_count++; - } - else if(num_start != line_num) - { - if (err_count < 20) - fprintf(stdout,"Skipping from %d to %d\n", - line_num, num_start); - err_count++; - - } - line_num = num_end; - } - pa = pb; - pb = pc; - pc = pa; - } - if(err_count) - fprintf(stdout,"\n%d errors of %d data sets %f\n", err_count, num_lines, (double) err_count/(double)num_lines); - else - fprintf(stdout,"No errors for %d lines\n",num_lines); - } - else if(strcmp(descstring,"LLBBC10") == 0) - { - uint32_t block0[4]; - uint32_t block1[4]; - uint32_t *pa = block0; - uint32_t *pb = block1; - uint32_t *pc = block0; - uint32_t start= 0; - uint32_t nread = 0; - int n_shown = 0; - int n_errors = 0; - if (fread(pa, sizeof(uint32_t), 4,outputFile) < 4) - { - fprintf(stderr,"Empty result file\n"); - return; - } - while(fread(pb, sizeof(uint32_t), 4,outputFile) != 0) - { - blocks++; - nread = pa[0]; - if(start>0 && (nread != start)) - { - if(n_shown < 30) - { - fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at blocks %10llu \n", - (nread-start)/0x4000, start -0x4000, nread, (unsigned long long) blocks); - n_shown ++; - } - n_errors++; - } - else if (n_shown >0) - n_shown--; - start = nread + 0x4000; - pa = pb; - pb = pc; - pc = pa; - } - if(n_errors) - fprintf(stderr, "%d blocks wrong from %llu blocks read\n", - n_errors, (unsigned long long) blocks); - else - fprintf(stderr, "%llu blocks all fine\n", (unsigned long long) blocks); - } -} diff --git a/third-party/libftdi/ftdipp/CMakeLists.txt b/third-party/libftdi/ftdipp/CMakeLists.txt index 27fbe8d..ad2db72 100644 --- a/third-party/libftdi/ftdipp/CMakeLists.txt +++ b/third-party/libftdi/ftdipp/CMakeLists.txt @@ -11,21 +11,17 @@ if (FTDIPP) if(Boost_FOUND) - # Includes - include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/src) - - include_directories(${Boost_INCLUDE_DIRS}) - - - set(FTDI_BUILD_CPP True PARENT_SCOPE) message(STATUS "Building libftdi1++") # Shared library add_library(ftdipp1 SHARED ${cpp_sources}) + target_include_directories(ftdipp1 BEFORE PUBLIC ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../src) + target_include_directories(ftdipp1 PUBLIC ${Boost_INCLUDE_DIRS}) + math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3) @@ -33,7 +29,7 @@ if (FTDIPP) set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) # Dependencies - target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES}) + target_link_libraries(ftdipp1 PUBLIC ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES}) install ( TARGETS ftdipp1 @@ -45,6 +41,11 @@ if (FTDIPP) # Static library if ( STATICLIBS ) add_library(ftdipp1-static STATIC ${cpp_sources}) + target_include_directories(ftdipp1-static BEFORE PUBLIC ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../src) + target_include_directories(ftdipp1-static PUBLIC ${Boost_INCLUDE_DIRS}) + target_link_libraries(ftdipp1-static PUBLIC ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES}) set_target_properties(ftdipp1-static PROPERTIES OUTPUT_NAME "ftdipp1") set_target_properties(ftdipp1-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)