From fdb93a5e53a9fb8e7789be800d05b588e4c4ff79 Mon Sep 17 00:00:00 2001 From: Pawel Jewstafjew 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 deletions(-) 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); -- 1.7.1