Hi Thomas,

> Do I understand the existing code correctly: It allows you do
> enable XON/XOFF mode like it is documented, but misconfigures
> the actual XON/XOFF characters?

Yes
XON/XOFF mode is enabled, but both XOFF (pause) and XON (resume)
character codes are set to zero.
So: '\x00' is sent by FTDI chip (when the internal buffer is close to
becoming full) to pause transmission, and '\x00' is sent by FTDI chip
(when the internal buffer level drops) to resume transmission.

After the change XON and XOFF character values can be freely
configured (this is similar to "official" FTDI driver API)

> Please send a proper git patch and I'll include it.

Please find patch attached.


Thanks,
Pawel



On 15/09/2017, Thomas Jarosch <[email protected]> wrote:
> Hi Pawel,
>
> On Sunday, 10 September 2017 17:02:54 CEST Pawel Jewstafjew wrote:
>> Or, to preserve backward compatibility of the libftdi ABI, this can be
>> also done by adding a new function, for example:
>>
>> int ftdi_setflowctrl_xonxoff(struct ftdi_context *ftdi, uint8_t xon,
>> uint8_t xoff)
>> {
>> […]
>> uint16_t value = (xoff_char << 8) | xon_char;
>> if (usb_control_msg(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
>>                         SIO_SET_FLOW_CTRL_REQUEST, value,
>> (SIO_XON_XOFF_HS | ftdi->index),
>>                         NULL, 0, ftdi->usb_write_timeout) != 0)
>> […]
>
> I would prefer the second approach since it will be API compatible, the ABI
> is not so important as we can just increase the .so number. Breaking
> existing
> source code would be more of a pain for distributions and users.
>
> Do I understand the existing code correctly: It allows you do
> enable XON/XOFF mode like it is documented, but misconfigures
> the actual XON/XOFF characters?
>
> Please send a proper git patch and I'll include it.
>
> Thank you,
> Thomas
>
>


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]   

From b339e2b800160a84e8f295a1ffd1f19c348d8f5c Mon Sep 17 00:00:00 2001
From: Pawel Jewstafjew <[email protected]>
Date: Wed, 20 Sep 2017 19:38:54 +0100
Subject: [PATCH] fix support for XON/XOFF flow control

---
 src/ftdi.c | 29 ++++++++++++++++++++++++++++-
 src/ftdi.h |  1 +
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index b336c80..675f8ca 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -2263,9 +2263,11 @@ int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status)
 /**
     Set flowcontrol for ftdi chip
 
+    Note: Do not use this function to enable XON/XOFF mode, use ftdi_setflowctrl_xonxoff() instead.
+
     \param ftdi pointer to ftdi_context
     \param flowctrl flow control to use. should be
-           SIO_DISABLE_FLOW_CTRL, SIO_RTS_CTS_HS, SIO_DTR_DSR_HS or SIO_XON_XOFF_HS
+           SIO_DISABLE_FLOW_CTRL, SIO_RTS_CTS_HS, SIO_DTR_DSR_HS
 
     \retval  0: all fine
     \retval -1: set flow control failed
@@ -2285,6 +2287,31 @@ int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl)
 }
 
 /**
+    Set XON/XOFF flowcontrol for ftdi chip
+
+    \param ftdi pointer to ftdi_context
+    \param xon character code used to resume transmission
+    \param xoff character code used to pause transmission
+
+    \retval  0: all fine
+    \retval -1: set flow control failed
+    \retval -2: USB device unavailable
+*/
+int ftdi_setflowctrl_xonxoff(struct ftdi_context *ftdi, unsigned char xon, unsigned char xoff)
+{
+    if (ftdi == NULL || ftdi->usb_dev == NULL)
+        ftdi_error_return(-2, "USB device unavailable");
+
+    uint16_t xonxoff = xon | (xoff << 8);
+    if (libusb_control_transfer(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
+                                SIO_SET_FLOW_CTRL_REQUEST, xonxoff, (SIO_XON_XOFF_HS | ftdi->index),
+                                NULL, 0, ftdi->usb_write_timeout) < 0)
+        ftdi_error_return(-1, "set flow control failed");
+
+    return 0;
+}
+
+/**
     Set dtr line
 
     \param ftdi pointer to ftdi_context
diff --git a/src/ftdi.h b/src/ftdi.h
index de02adf..b3e596e 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -546,6 +546,7 @@ extern "C"
 
     /* flow control */
     int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
+    int ftdi_setflowctrl_xonxoff(struct ftdi_context *ftdi, unsigned char xon, unsigned char xoff);
     int ftdi_setdtr_rts(struct ftdi_context *ftdi, int dtr, int rts);
     int ftdi_setdtr(struct ftdi_context *ftdi, int state);
     int ftdi_setrts(struct ftdi_context *ftdi, int state);
-- 
2.1.4

Reply via email to