libftdi Archives

Subject: [PATCH 05/10] remove deprecated code

From: Shawn Hoffman <business@xxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Cc: Shawn Hoffman <godisgovernment@xxxxxxxxx>
Date: Wed, 10 Apr 2024 07:15:44 -0700
From: Shawn Hoffman <godisgovernment@xxxxxxxxx>

---
 examples/purge_test.c | 175 ++++++++++++++++--------------------------
 ftdipp/ftdi.cpp       |  27 -------
 ftdipp/ftdi.hpp       |   1 -
 src/ftdi.c            |  91 ----------------------
 src/ftdi.h            |  56 +-------------
 5 files changed, 69 insertions(+), 281 deletions(-)

diff --git a/examples/purge_test.c b/examples/purge_test.c
index 2d42aa4..f705814 100644
--- a/examples/purge_test.c
+++ b/examples/purge_test.c
@@ -23,15 +23,13 @@
 #include <getopt.h>
 #include <signal.h>
 #include <errno.h>
-/* Prevent deprecated messages when building library */
-#define _FTDI_DISABLE_DEPRECATED
 #include <ftdi.h>
 
-#include <termios.h>           // For baudcodes & linux UARTs
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <fcntl.h>
-
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <termios.h>           // For baudcodes & linux UARTs
 
 static struct ftdi_context *ftdi = NULL;
 static int dev_fd = -1;
@@ -42,7 +40,6 @@ static int baud = 9600;
 static int baud_code = -1;
 static enum ftdi_interface interface = INTERFACE_A;
 static int msg_size = 80;
-static int broken_purge_test = 0;
 
 static const int latency_min = 2;
 static const int latency_max = 255;
@@ -91,34 +88,33 @@ static const char * chip_types[] = {
 static void
 usage(const char *argv0)
 {
-   fprintf(stderr,
-           "Usage: %s [options...] device-specifier\n"
-           "Flush test for UARTS.\n"
-          " with loopback connector\n"
-           "    [-b baud]        baud rate (e.g., 300, 600, 1200, ...230400)\n"
-           "    [-i {a|b|c|d}]   FTDI interface for chips which have multiple 
UARTS\n"
-          "    [-l latency]     Latency (%d..%d)\n"
-           "    [-n msg-size]    Number of bytes in test message\n"
-           "    [-N note]        Note for the output\n"
-          "    [-P]             Use broken libftdi1 purge methods (over new 
flush)\n"
-           "\n"
-           "    device-specifier String specifying the UART.  If the first 
character\n"
-          "                     is the '/' character, the program assumes a 
Linux UART\n"
-          "                     is to be tested and the string would be 
something like\n"
-          "                     '/dev/ttyS0' or '/dev/ttyUSB0'. Otherwise, the 
program\n"
-          "                     assumes an FTDI device is being tested with 
the FTDI1\n"
-          "                     library. The device-specifier must be a 
string\n"
-          "                     accepted by the ftdi_usb_open_string function. 
An\n"
-          "                     example would be 'i:0x0403:0x6011[:index]'.\n"
-          "\n"
-          "NOTE: To function correctly, this program requires a loopback 
connector\n"
-          "      attached to the UART under test.\n"
-           "\n"
-           "Adapted from stream_test.c 2018. Eric Schott <els6@xxxxxxx>\n"
-           "Copyright (C) 2009 Micah Dowty <micah@xxxxxxx>\n"
-           "Adapted for use with libftdi (C) 2010 Uwe Bonnes 
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>\n",
-           argv0, latency_min, latency_max);
-   exit(1);
+    fprintf(stderr,
+        "Usage: %s [options...] device-specifier\n"
+        "Flush test for UARTS.\n"
+        " with loopback connector\n"
+        "    [-b baud]        baud rate (e.g., 300, 600, 1200, ...230400)\n"
+        "    [-i {a|b|c|d}]   FTDI interface for chips which have multiple 
UARTS\n"
+        "    [-l latency]     Latency (%d..%d)\n"
+        "    [-n msg-size]    Number of bytes in test message\n"
+        "    [-N note]        Note for the output\n"
+        "\n"
+        "    device-specifier String specifying the UART.  If the first 
character\n"
+        "                     is the '/' character, the program assumes a 
Linux UART\n"
+        "                     is to be tested and the string would be 
something like\n"
+        "                     '/dev/ttyS0' or '/dev/ttyUSB0'. Otherwise, the 
program\n"
+        "                     assumes an FTDI device is being tested with the 
FTDI1\n"
+        "                     library. The device-specifier must be a string\n"
+        "                     accepted by the ftdi_usb_open_string function. 
An\n"
+        "                     example would be 'i:0x0403:0x6011[:index]'.\n"
+        "\n"
+        "NOTE: To function correctly, this program requires a loopback 
connector\n"
+        "      attached to the UART under test.\n"
+        "\n"
+        "Adapted from stream_test.c 2018. Eric Schott <els6@xxxxxxx>\n"
+        "Copyright (C) 2009 Micah Dowty <micah@xxxxxxx>\n"
+        "Adapted for use with libftdi (C) 2010 Uwe Bonnes 
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>\n",
+        argv0, latency_min, latency_max);
+    exit(1);
 }
 
 
@@ -137,7 +133,7 @@ int main(int argc, char **argv)
     long int msg_xmit_time_us;
     static struct option long_options[] = {{NULL},};
 
-    while ((c = getopt_long(argc, argv, "n:b:i:l:N:P", long_options, 
&option_index)) !=- 1)
+    while ((c = getopt_long(argc, argv, "n:b:i:l:N", long_options, 
&option_index)) != -1)
         switch (c)
         {
         case -1:
@@ -178,11 +174,11 @@ int main(int argc, char **argv)
             latency = ascii2int(optarg, argv[0]);
             if (latency < latency_min || latency > latency_max)
             {
-             fprintf(stderr, "latency [-l] must be an integer in the range 
%d..%d\n",
-                       latency_min, latency_max);
+                fprintf(stderr, "latency [-l] must be an integer in the range 
%d..%d\n",
+                    latency_min, latency_max);
                 usage(argv[0]);
             }
-           latency_specified = 1;
+            latency_specified = 1;
             break;
         case 'n':
             msg_size = ascii2int(optarg, argv[0]);
@@ -195,9 +191,6 @@ int main(int argc, char **argv)
         case 'N':
             note = optarg;
             break;
-       case 'P':
-           broken_purge_test = 1;
-           break;
         default:
             usage(argv[0]);
         }
@@ -227,14 +220,9 @@ int main(int argc, char **argv)
     {
         struct termios termios;
 
-       if (latency_specified) {
-         fprintf(stderr, "Latency (-l) option not support on this device; 
ignored\n");
-       }
-
-       if (broken_purge_test) {
-         fprintf(stderr, "Broken-purge (-P) option not support with Linux 
kernel driver\n");
-         return EXIT_FAILURE;
-       }
+        if (latency_specified) {
+            fprintf(stderr, "Latency (-l) option not support on this device; 
ignored\n");
+        }
 
         dev_fd = open(dev_string, O_NOCTTY | O_RDWR);
         if (dev_fd < 0)
@@ -257,7 +245,7 @@ int main(int argc, char **argv)
             return EXIT_FAILURE;
         }
 
-       note_default = "Linux kernel driver";
+        note_default = "Linux kernel driver";
 
         cfmakeraw(&termios);
 
@@ -305,18 +293,18 @@ int main(int argc, char **argv)
             return EXIT_FAILURE;
         }
 
-       if(ftdi_set_latency_timer(ftdi, (unsigned char) latency))
-       {
-           if (latency_specified &&
+        if (ftdi_set_latency_timer(ftdi, (unsigned char) latency))
+        {
+            if (latency_specified &&
                 (ftdi->type == TYPE_AM || ftdi->type == TYPE_232H)) {
-               fprintf(stderr, "Latency (-l) option not support on this 
device; ignored\n");
-           } else if (ftdi->type != TYPE_AM && ftdi->type != TYPE_232H) {
+                fprintf(stderr, "Latency (-l) option not support on this 
device; ignored\n");
+            } else if (ftdi->type != TYPE_AM && ftdi->type != TYPE_232H) {
                 fprintf(stderr,"Error setting latency for ftdi device \"%s\" 
(%d): %s\n",
                         dev_string, ftdi->type, ftdi_get_error_string(ftdi));
                 ftdi_free(ftdi);
                 return EXIT_FAILURE;
             }
-       }
+        }
 
         if (ftdi_set_line_property2(ftdi, BITS_8, STOP_BIT_1, NONE, BREAK_OFF) 
< 0)
         {
@@ -341,11 +329,6 @@ int main(int argc, char **argv)
             ftdi_free(ftdi);
             return EXIT_FAILURE;
         }
-
-       if (broken_purge_test)
-           note_default = "libftdi w/ deprecated purge";
-       else
-           note_default = "libftdi w/ new flush methods";
     }
 
     printf("Purge (tcflush) test for device %s\n", dev_string);
@@ -426,7 +409,7 @@ int main(int argc, char **argv)
         int rc;
 
         printf("\n********  Test purge %s; expect %s  ********\n"
-              "  --              Flushing UART\n",
+           "  --              Flushing UART\n",
                flushTestName[test], expected[test]);
         flush(TCIOFLUSH);
         usleep(msg_xmit_time_us);
@@ -478,7 +461,7 @@ int main(int argc, char **argv)
             usleep(usec_delay);
         }
         else
-       {
+        {
             printf("  -- %9.1f ms Drain() reports completed; timing OK; 
delaying for 4 bytes\n", 
                    (get_time_usec() - usec_test_start) * .001);
             usleep(char_cnt_2_usec(4));
@@ -539,28 +522,28 @@ static int ascii2int(const char * str, const char * 
pgm_name)
 /**********************************************************************
  */
 static struct Baud_Table {
-       int32_t baud, baud_code;
+    int32_t baud, baud_code;
 } baud_table [] =
 {
-       { 50,     B50     },
-       { 75,     B75     },
-       { 110,    B110    },
-       { 134,    B134    },
-       { 150,    B150    },
-       { 200,    B200    },
-       { 300,    B300    },
-       { 600,    B600    },
-       { 1200,   B1200   },
-       { 1800,   B1800   },
-       { 2400,   B2400   },
-       { 4800,   B4800   },
-       { 9600,   B9600   },
-       { 19200,  B19200  },
-       { 38400,  B38400  },
-       { 57600,  B57600  },
-       { 115200, B115200 },
-       { 230400, B230400 },
-       { -1,     -1,     }
+    { 50,     B50     },
+    { 75,     B75     },
+    { 110,    B110    },
+    { 134,    B134    },
+    { 150,    B150    },
+    { 200,    B200    },
+    { 300,    B300    },
+    { 600,    B600    },
+    { 1200,   B1200   },
+    { 1800,   B1800   },
+    { 2400,   B2400   },
+    { 4800,   B4800   },
+    { 9600,   B9600   },
+    { 19200,  B19200  },
+    { 38400,  B38400  },
+    { 57600,  B57600  },
+    { 115200, B115200 },
+    { 230400, B230400 },
+    { -1,     -1,     }
 };
 
 /**********************************************************************
@@ -619,7 +602,7 @@ static int flush(int queue_selector)
     int rc;
     if (dev_fd >= 0)
         rc = tcflush(dev_fd, queue_selector);
-    else if (! broken_purge_test)
+    else
     {
         switch (queue_selector) {
 
@@ -640,28 +623,6 @@ static int flush(int queue_selector)
             return -1;
         }
     }
-    else
-    {
-        switch (queue_selector) {
-
-        case TCIOFLUSH:
-            rc = ftdi_usb_purge_buffers(ftdi);
-            break;
-
-        case TCIFLUSH:
-            rc = ftdi_usb_purge_rx_buffer(ftdi);
-            break;
-
-        case TCOFLUSH:
-            rc = ftdi_usb_purge_tx_buffer(ftdi);
-            break;
-
-        default:
-            errno = EINVAL;
-            return -1;
-        }
-    }
-
     return rc;
 }
 
diff --git a/ftdipp/ftdi.cpp b/ftdipp/ftdi.cpp
index afb84fb..d81c4b3 100644
--- a/ftdipp/ftdi.cpp
+++ b/ftdipp/ftdi.cpp
@@ -27,7 +27,6 @@ This exception does not invalidate any other reasons why a 
work based
 on this file might be covered by the GNU General Public License.
 */
 #include <libusb.h>
-#define _FTDI_DISABLE_DEPRECATED
 #include "ftdi.hpp"
 #include "ftdi_i.h"
 #include "ftdi.h"
@@ -143,32 +142,6 @@ int Context::reset()
     return ftdi_usb_reset(d->ftdi);
 }
 
-int Context::flush(int mask)
-{
-    int ret;
-
-    switch (mask & (Input | Output)) {
-    case Input:
-        ret = ftdi_usb_purge_rx_buffer(d->ftdi);
-        break;
-
-    case Output:
-        ret = ftdi_usb_purge_tx_buffer(d->ftdi);
-        break;
-
-    case Input | Output:
-        ret = ftdi_usb_purge_buffers(d->ftdi);
-        break;
-
-    default:
-        // Emulate behavior of previous version.
-        ret = 1;
-        break;
-    }
-
-    return ret;
-}
-
 int Context::tcflush(int mask)
 {
     int ret;
diff --git a/ftdipp/ftdi.hpp b/ftdipp/ftdi.hpp
index f569cce..481c44c 100644
--- a/ftdipp/ftdi.hpp
+++ b/ftdipp/ftdi.hpp
@@ -85,7 +85,6 @@ public:
     int open(const std::string& description);
     int close();
     int reset();
-    int DEPRECATED(flush)(int mask = Input|Output);
     int tcflush(int mask = Input|Output);
     int set_interface(enum ftdi_interface interface);
     void set_usb_device(struct libusb_device_handle *dev);
diff --git a/src/ftdi.c b/src/ftdi.c
index 7c2e693..610fe3e 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -36,8 +36,6 @@
 #include <stdlib.h>
 
 #include "ftdi_i.h"
-/* Prevent deprecated messages when building library */
-#define _FTDI_DISABLE_DEPRECATED
 #include "ftdi.h"
 #include "ftdi_version_i.h"
 
@@ -1056,36 +1054,6 @@ int ftdi_tciflush(struct ftdi_context *ftdi)
     return 0;
 }
 
-
-/**
-    Clears the write buffer on the chip and the internal read buffer.
-    This is incorrect behavior for an RX flush.
-
-    \param ftdi pointer to ftdi_context
-
-    \retval  0: all fine
-    \retval -1: write buffer purge failed
-    \retval -2: USB device unavailable
-
-    \deprecated Use \ref ftdi_tciflush(struct ftdi_context *ftdi)
-*/
-int ftdi_usb_purge_rx_buffer(struct ftdi_context *ftdi)
-{
-    if (ftdi == NULL || ftdi->usb_dev == NULL)
-        ftdi_error_return(-2, "USB device unavailable");
-
-    if (libusb_control_transfer(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
-                                SIO_RESET_REQUEST, SIO_RESET_PURGE_RX,
-                                ftdi->index, NULL, 0, ftdi->usb_write_timeout) 
< 0)
-        ftdi_error_return(-1, "FTDI purge of RX buffer failed");
-
-    // Invalidate data in the readbuffer
-    ftdi->readbuffer_offset = 0;
-    ftdi->readbuffer_remaining = 0;
-
-    return 0;
-}
-
 /**
     Clears the write buffer on the chip.
     This is correct behavior for a TX flush.
@@ -1109,32 +1077,6 @@ int ftdi_tcoflush(struct ftdi_context *ftdi)
     return 0;
 }
 
-
-/**
-    Clears the read buffer on the chip.
-    This is incorrect behavior for a TX flush.
-
-    \param ftdi pointer to ftdi_context
-
-    \retval  0: all fine
-    \retval -1: read buffer purge failed
-    \retval -2: USB device unavailable
-
-    \deprecated Use \ref ftdi_tcoflush(struct ftdi_context *ftdi)
-*/
-int ftdi_usb_purge_tx_buffer(struct ftdi_context *ftdi)
-{
-    if (ftdi == NULL || ftdi->usb_dev == NULL)
-        ftdi_error_return(-2, "USB device unavailable");
-
-    if (libusb_control_transfer(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
-                                SIO_RESET_REQUEST, SIO_RESET_PURGE_TX,
-                                ftdi->index, NULL, 0, ftdi->usb_write_timeout) 
< 0)
-        ftdi_error_return(-1, "FTDI purge of TX buffer failed");
-
-    return 0;
-}
-
 /**
     Clears the RX and TX FIFOs on the chip and the internal read buffer.
     This is correct behavior for both RX and TX flush.
@@ -1164,39 +1106,6 @@ int ftdi_tcioflush(struct ftdi_context *ftdi)
     return 0;
 }
 
-/**
-    Clears the buffers on the chip and the internal read buffer.
-    While coded incorrectly, the result is satisfactory.
-
-    \param ftdi pointer to ftdi_context
-
-    \retval  0: all fine
-    \retval -1: read buffer purge failed
-    \retval -2: write buffer purge failed
-    \retval -3: USB device unavailable
-
-    \deprecated Use \ref ftdi_tcioflush(struct ftdi_context *ftdi)
-*/
-int ftdi_usb_purge_buffers(struct ftdi_context *ftdi)
-{
-    int result;
-
-    if (ftdi == NULL || ftdi->usb_dev == NULL)
-        ftdi_error_return(-3, "USB device unavailable");
-
-    result = ftdi_usb_purge_rx_buffer(ftdi);
-    if (result < 0)
-        return -1;
-
-    result = ftdi_usb_purge_tx_buffer(ftdi);
-    if (result < 0)
-        return -2;
-
-    return 0;
-}
-
-
-
 /**
     Closes the ftdi device. Call ftdi_deinit() if you're cleaning up.
 
diff --git a/src/ftdi.h b/src/ftdi.h
index ffeb452..186cf9e 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -180,47 +180,9 @@ enum ftdi_module_detach_mode
 #define SIO_WRITE_EEPROM_REQUEST      0x91
 #define SIO_ERASE_EEPROM_REQUEST      0x92
 
-
 #define SIO_RESET_SIO 0
-
-/* ** WARNING ** SIO_RESET_PURGE_RX or SIO_RESET_PURGE_TX are values used
- * internally by libftdi to purge the RX and/or TX FIFOs (buffers).
- * APPLICATION PROGRAMS SHOULD NOT BE USING THESE VALUES. Application
- * programs should use one of the ftdi_tciflush, ftdi_tcoflush, or
- * ftdi_tcioflush functions which emulate the Linux serial port tcflush(3)
- * function.
- *
- * History:
- *
- * The definitions for these values are with respect to the FTDI chip, not the
- * CPU. That is, when the FTDI chip receives a USB control transfer request
- * with the command SIO_RESET_PURGE_RX, the FTDI chip empties the FIFO
- * containing data received from the CPU awaiting transfer out the serial
- * port to the connected serial device (e.g., a modem). Likewise, upon
- * reception of the SIO_RESET_PURGE_TX command, the FTDI chip empties the
- * FIFO of data received from the attached serial device destined to be
- * transmitted to the CPU.
- *
- * Unfortunately the coding of the previous releases of libfti assumed these
- * commands had the opposite effect. This resulted in the function
- * ftdi_usb_purge_tx_buffer clearing data received from the attached serial
- * device.  Similarly, the function ftdi_usb_purge_rx_buffer cleared the
- * FTDI FIFO containing data to be transmitted to the attached serial
- * device.  More seriously, this latter function clear the libftid's
- * internal buffer of data received from the serial device, destined
- * to the application program.
- */
-#ifdef __GNUC__
-#define SIO_RESET_PURGE_RX _Ftdi_Pragma("GCC warning \"SIO_RESET_PURGE_RX\" 
deprecated: - use tciflush() method") 1
-#define SIO_RESET_PURGE_TX _Ftdi_Pragma("GCC warning \"SIO_RESET_PURGE_RX\" 
deprecated: - use tcoflush() method") 2
-#else
-#pragma message("WARNING: You need to implement deprecated #define for this 
compiler")
-#define SIO_RESET_PURGE_RX 1
-#define SIO_RESET_PURGE_TX 2
-#endif
-/* New names for the values used internally to flush (purge). */
-#define SIO_TCIFLUSH 2
 #define SIO_TCOFLUSH 1
+#define SIO_TCIFLUSH 2
 
 #define SIO_DISABLE_FLOW_CTRL 0x0
 #define SIO_RTS_CTS_HS (0x1 << 8)
@@ -240,19 +202,6 @@ enum ftdi_module_detach_mode
    (taken from libusb) */
 #define FTDI_URB_USERCONTEXT_COOKIE ((void *)0x1)
 
-#ifdef _FTDI_DISABLE_DEPRECATED
-#define DEPRECATED(func) func
-#else
-#ifdef __GNUC__
-#define DEPRECATED(func) __attribute__ ((deprecated)) func
-#elif defined(_MSC_VER)
-#define DEPRECATED(func) __declspec(deprecated) func
-#else
-#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
-#define DEPRECATED(func) func
-#endif
-#endif
-
 struct ftdi_transfer_control
 {
     int completed;
@@ -562,9 +511,6 @@ extern "C"
     int ftdi_tciflush(struct ftdi_context *ftdi);
     int ftdi_tcoflush(struct ftdi_context *ftdi);
     int ftdi_tcioflush(struct ftdi_context *ftdi);
-    int DEPRECATED(ftdi_usb_purge_rx_buffer(struct ftdi_context *ftdi));
-    int DEPRECATED(ftdi_usb_purge_tx_buffer(struct ftdi_context *ftdi));
-    int DEPRECATED(ftdi_usb_purge_buffers(struct ftdi_context *ftdi));
 
     int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
     int ftdi_set_line_property(struct ftdi_context *ftdi, enum ftdi_bits_type 
bits,
-- 
2.44.0.windows.1


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread