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. Add an helper include file 'libftdi_helper.h' that wraps the old API for backward compatibility with old libftdi. Change-Id: I7800fbebe17dd0ce62e55b3598d8c08be8875bb7 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Fixes: https://sourceforge.net/p/openocd/tickets/286/ Reviewed-on: http://openocd.zylin.com/5891 Tested-by: jenkins
This commit is contained in:
parent
1718e733d6
commit
5bb0f6befb
|
@ -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])
|
||||
])
|
||||
|
||||
|
|
|
@ -187,6 +187,7 @@ DRIVERHEADERS = \
|
|||
%D%/bitbang.h \
|
||||
%D%/bitq.h \
|
||||
%D%/jtag_usb_common.h \
|
||||
%D%/libftdi_helper.h \
|
||||
%D%/libusb_helper.h \
|
||||
%D%/minidriver_imp.h \
|
||||
%D%/mpsse.h \
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef OPENOCD_JTAG_DRIVERS_LIBFTDI_HELPER_H
|
||||
#define OPENOCD_JTAG_DRIVERS_LIBFTDI_HELPER_H
|
||||
|
||||
#include <ftdi.h>
|
||||
|
||||
#ifndef HAVE_LIBFTDI_TCIOFLUSH
|
||||
/* Backward compatibility with libftdi pre 1.5 */
|
||||
|
||||
static inline int ftdi_tciflush(struct ftdi_context *ftdi)
|
||||
{
|
||||
return ftdi_usb_purge_rx_buffer(ftdi);
|
||||
}
|
||||
|
||||
static inline int ftdi_tcoflush(struct ftdi_context *ftdi)
|
||||
{
|
||||
return ftdi_usb_purge_tx_buffer(ftdi);
|
||||
}
|
||||
|
||||
static inline int ftdi_tcioflush(struct ftdi_context *ftdi)
|
||||
{
|
||||
return ftdi_usb_purge_buffers(ftdi);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENOCD_JTAG_DRIVERS_LIBFTDI_HELPER_H */
|
|
@ -82,7 +82,7 @@ typedef enum openjtag_tap_state {
|
|||
} openjtag_tap_state_t;
|
||||
|
||||
/* OPENJTAG access library includes */
|
||||
#include <ftdi.h>
|
||||
#include "libftdi_helper.h"
|
||||
|
||||
/* OpenJTAG vid/pid */
|
||||
static uint16_t openjtag_vid = 0x0403;
|
||||
|
@ -436,8 +436,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "bitq.h"
|
||||
|
||||
/* PRESTO access library includes */
|
||||
#include <ftdi.h>
|
||||
#include "libftdi_helper.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -160,8 +160,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 +174,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;
|
||||
|
|
Loading…
Reference in New Issue