This is an automated email from Gerrit.

Antonio Borneo ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/5891

-- gerrit

commit 0d9ba548a417acb8bb90ed5771ecec436e8b5d4b
Author: Antonio Borneo <[email protected]>
Date:   Wed Oct 28 00:51:30 2020 +0100

    openocd: add support for libftdi 1.5
    
    The new libftdi 1.5 (2020-07-07) changes some API, deprecating the
    old ones. This cause a warning at compile time.
    
    Detect in configure the version of libftdi.
    Use the new API in the driver's code and create a wrapper around
    the old API for backward compatibility with old libftdi.
    
    A cleaner implementation would have require adding the wrapper in
    an include file libftdi_helper.h, but that's probably excessive.
    
    Change-Id: I7800fbebe17dd0ce62e55b3598d8c08be8875bb7
    Signed-off-by: Antonio Borneo <[email protected]>
    Fixes: https://sourceforge.net/p/openocd/tickets/286/

diff --git a/configure.ac b/configure.ac
index 47a167e..055833a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -669,7 +669,11 @@ for hidapi_lib in hidapi hidapi-hidraw hidapi-libusb; do
        ])
 done
 
-PKG_CHECK_MODULES([LIBFTDI], [libftdi1], [use_libftdi=yes], [
+PKG_CHECK_MODULES([LIBFTDI], [libftdi1], [
+       use_libftdi=yes
+       PKG_CHECK_EXISTS([libftdi1 >= 1.5],
+               [AC_DEFINE([HAVE_LIBFTDI_TCIOFLUSH], [1], [Define if your 
libftdi has ftdi_tcioflush()])])
+  ], [
        PKG_CHECK_MODULES([LIBFTDI], [libftdi], [use_libftdi=yes], 
[use_libftdi=no])
 ])
 
diff --git a/src/jtag/drivers/openjtag.c b/src/jtag/drivers/openjtag.c
index 2cf5751..2ca0a36 100644
--- a/src/jtag/drivers/openjtag.c
+++ b/src/jtag/drivers/openjtag.c
@@ -84,6 +84,14 @@ typedef enum openjtag_tap_state {
 /* OPENJTAG access library includes */
 #include <ftdi.h>
 
+#ifndef HAVE_LIBFTDI_TCIOFLUSH
+/* Backward compatibility with libftdi pre 1.5 */
+static inline int ftdi_tcioflush(struct ftdi_context *ftdi)
+{
+       return ftdi_usb_purge_buffers(ftdi);
+}
+#endif
+
 /* OpenJTAG vid/pid */
 static uint16_t openjtag_vid = 0x0403;
 static uint16_t openjtag_pid = 0x6001;
@@ -436,8 +444,8 @@ static int openjtag_init_standard(void)
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
-       if (ftdi_usb_purge_buffers(&ftdic) < 0) {
-               LOG_ERROR("ftdi_purge_buffers: %s", ftdic.error_str);
+       if (ftdi_tcioflush(&ftdic) < 0) {
+               LOG_ERROR("ftdi flush: %s", ftdic.error_str);
                return ERROR_JTAG_INIT_FAILED;
        }
 
diff --git a/src/jtag/drivers/presto.c b/src/jtag/drivers/presto.c
index 6c3a187..ef0b856 100644
--- a/src/jtag/drivers/presto.c
+++ b/src/jtag/drivers/presto.c
@@ -36,6 +36,14 @@
 /* PRESTO access library includes */
 #include <ftdi.h>
 
+#ifndef HAVE_LIBFTDI_TCIOFLUSH
+/* Backward compatibility with libftdi pre 1.5 */
+static inline int ftdi_tcioflush(struct ftdi_context *ftdi)
+{
+       return ftdi_usb_purge_buffers(ftdi);
+}
+#endif
+
 /* -------------------------------------------------------------------------- 
*/
 
 #define FT_DEVICE_NAME_LEN 64
@@ -160,8 +168,8 @@ static int presto_open_libftdi(char *req_serial)
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
-       if (ftdi_usb_purge_buffers(&presto->ftdic) < 0) {
-               LOG_ERROR("unable to purge PRESTO buffers");
+       if (ftdi_tcioflush(&presto->ftdic) < 0) {
+               LOG_ERROR("unable to flush PRESTO buffers");
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -174,7 +182,7 @@ static int presto_open_libftdi(char *req_serial)
        if (presto_read(&presto_data, 1) != ERROR_OK) {
                LOG_DEBUG("no response from PRESTO, retrying");
 
-               if (ftdi_usb_purge_buffers(&presto->ftdic) < 0)
+               if (ftdi_tcioflush(&presto->ftdic) < 0)
                        return ERROR_JTAG_DEVICE_ERROR;
 
                presto_data = 0xD0;

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to