From: Gerhard Sittig Date: Wed, 22 Dec 2021 11:22:48 +0000 (+0100) Subject: ftdi: address ftdi_usb_purge_buffers() deprecation in libftdi 1.5 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e1a712ca268df9c179377cf5c48ece8b87ed0ed7;p=libsigrok.git ftdi: address ftdi_usb_purge_buffers() deprecation in libftdi 1.5 The ftdi_usb_purge_buffers() implementation suffered from an incorrect implementation (inverse semantics). Library version 1.5 introduced a set of substitute routines, and deprecated the existing purge API. Parameters are identical, so we get away with a mere replacement of the routine name which gets invoked. Which simplifies call sites, and concentrates all the version dependency cruft in a central spot. The fact that all drivers always flushed RX and TX and never individually also helped. --- diff --git a/configure.ac b/configure.ac index 90291772..424b0002 100644 --- a/configure.ac +++ b/configure.ac @@ -616,6 +616,7 @@ AM_COND_IF([BINDINGS_CXX], [ ]) # Check for specific libusb features, now that we know the CFLAGS. +# Also check for version dependent libftdi features. AC_LANG([C]) sr_save_cflags=$CFLAGS sr_save_libs=$LIBS @@ -625,6 +626,7 @@ AC_CHECK_TYPES([libusb_os_handle], [sr_have_libusb_os_handle=yes], [sr_have_libusb_os_handle=no], [[#include ]]) AC_CHECK_FUNCS([zip_discard]) +AC_CHECK_FUNCS([ftdi_tciflush ftdi_tcoflush ftdi_tcioflush]) LIBS=$sr_save_libs CFLAGS=$sr_save_cflags diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index df59693d..14231651 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -625,7 +625,7 @@ static int sigma_fpga_init_bitbang_once(struct dev_context *devc) if (ret != SR_OK) return ret; g_usleep(10 * 1000); - ftdi_usb_purge_buffers(&devc->ftdi.ctx); + PURGE_FTDI_BOTH(&devc->ftdi.ctx); /* * Wait until the FPGA asserts INIT_B. Check in a maximum number @@ -889,7 +889,7 @@ static int upload_firmware(struct sr_context *ctx, struct dev_context *devc, ftdi_get_error_string(&devc->ftdi.ctx)); return SR_ERR; } - ftdi_usb_purge_buffers(&devc->ftdi.ctx); + PURGE_FTDI_BOTH(&devc->ftdi.ctx); while (sigma_read_raw(devc, &pins, sizeof(pins)) > 0) ; diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 694bd54a..d35a4f53 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -243,7 +243,7 @@ static int dev_open(struct sr_dev_inst *sdi) goto err_ftdi_free; } - if ((ret = ftdi_usb_purge_buffers(devc->ftdic)) < 0) { + if ((ret = PURGE_FTDI_BOTH(devc->ftdic)) < 0) { sr_err("Failed to purge FTDI buffers (%d): %s.", ret, ftdi_get_error_string(devc->ftdic)); goto err_ftdi_free; diff --git a/src/hardware/chronovu-la/protocol.c b/src/hardware/chronovu-la/protocol.c index da772f5b..ae8f427a 100644 --- a/src/hardware/chronovu-la/protocol.c +++ b/src/hardware/chronovu-la/protocol.c @@ -202,7 +202,7 @@ static int close_usb_reset_sequencer(struct dev_context *devc) sr_dbg("Purging buffers, resetting+closing FTDI device."); /* Log errors, but ignore them (i.e., don't abort). */ - if ((ret = ftdi_usb_purge_buffers(devc->ftdic)) < 0) + if ((ret = PURGE_FTDI_BOTH(devc->ftdic)) < 0) sr_err("Failed to purge FTDI buffers (%d): %s.", ret, ftdi_get_error_string(devc->ftdic)); if ((ret = ftdi_usb_reset(devc->ftdic)) < 0) diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 8bb67121..2e7e59f4 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -325,7 +325,7 @@ static int dev_open(struct sr_dev_inst *sdi) goto err_ftdi_free; } - ret = ftdi_usb_purge_buffers(devc->ftdic); + ret = PURGE_FTDI_BOTH(devc->ftdic); if (ret < 0) { sr_err("Failed to purge FTDI RX/TX buffers (%d): %s.", ret, ftdi_get_error_string(devc->ftdic)); diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index f29e5c39..fb3b137f 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -141,7 +141,7 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_ERR; } - if ((ret = ftdi_usb_purge_buffers(devc->ftdic)) < 0) { + if ((ret = PURGE_FTDI_BOTH(devc->ftdic)) < 0) { sr_err("Failed to purge FTDI RX/TX buffers (%d): %s.", ret, ftdi_get_error_string(devc->ftdic)); goto err_dev_open_close_ftdic; diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c index f0ef6805..1b54dd16 100644 --- a/src/hardware/pipistrello-ols/protocol.c +++ b/src/hardware/pipistrello-ols/protocol.c @@ -90,7 +90,7 @@ SR_PRIV int p_ols_open(struct dev_context *devc) return SR_ERR; } - if ((ret = ftdi_usb_purge_buffers(devc->ftdic)) < 0) { + if ((ret = PURGE_FTDI_BOTH(devc->ftdic)) < 0) { sr_err("Failed to purge FTDI RX/TX buffers (%d): %s.", ret, ftdi_get_error_string(devc->ftdic)); goto err_open_close_ftdic; diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 25297f4c..a2350e02 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -32,6 +32,9 @@ #ifdef HAVE_LIBUSB_1_0 #include #endif +#ifdef HAVE_LIBFTDI +#include +#endif #include #include #include @@ -981,6 +984,21 @@ static inline void write_dblle_inc(uint8_t **p, double x) libusb_handle_events_timeout(ctx, tv) #endif +/* + * Convenience for FTDI library version dependency. + * - Version 1.5 introduced ftdi_tciflush(), ftdi_tcoflush(), and + * ftdi_tcioflush() all within the same commit, and deprecated + * ftdi_usb_purge_buffers() which suffered from inverse semantics. + * The API is drop-in compatible (arguments count and data types are + * identical). The libsigrok source code always flushes RX and TX at + * the same time, never individually. + */ +#if defined HAVE_FTDI_TCIOFLUSH && HAVE_FTDI_TCIOFLUSH +# define PURGE_FTDI_BOTH ftdi_tcioflush +#else +# define PURGE_FTDI_BOTH ftdi_usb_purge_buffers +#endif + /* Static definitions of structs ending with an all-zero entry are a * problem when compiling with -Wmissing-field-initializers: GCC * suppresses the warning only with { 0 }, clang wants { } */