From: Thomas Jarosch Date: Tue, 24 Jun 2008 08:05:58 +0000 (+0000) Subject: libftdi: (tomj) grouped flow control and modem status code together X-Git-Tag: v0.14~8 X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=commitdiff_plain;h=a7fb84407f54ca992eba82201b0d5a16be7815cf libftdi: (tomj) grouped flow control and modem status code together --- diff --git a/ChangeLog b/ChangeLog index e2c691c..2c3ab97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +New in 0.14 +----------- +* Grouped flow control and modem status code together (Intra2net) + New in 0.13 ----------- * Build .spec file via configure.in (Intra2net) diff --git a/src/ftdi.c b/src/ftdi.c index 74b5631..0dbc5b6 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -1398,6 +1398,83 @@ int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status) return 0; } + +/* + Flow control code by Lorenz Moesenlechner (lorenz@hcilab.org) + and Matthias Kranz (matthias@hcilab.org) +*/ +/** + Set flowcontrol for ftdi chip + + \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 + + \retval 0: all fine + \retval -1: set flow control failed +*/ +int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl) +{ + if (usb_control_msg(ftdi->usb_dev, SIO_SET_FLOW_CTRL_REQUEST_TYPE, + SIO_SET_FLOW_CTRL_REQUEST, 0, (flowctrl | ftdi->interface), + 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 + \param state state to set line to (1 or 0) + + \retval 0: all fine + \retval -1: set dtr failed +*/ +int ftdi_setdtr(struct ftdi_context *ftdi, int state) +{ + unsigned short usb_val; + + if (state) + usb_val = SIO_SET_DTR_HIGH; + else + usb_val = SIO_SET_DTR_LOW; + + if (usb_control_msg(ftdi->usb_dev, SIO_SET_MODEM_CTRL_REQUEST_TYPE, + SIO_SET_MODEM_CTRL_REQUEST, usb_val, ftdi->interface, + NULL, 0, ftdi->usb_write_timeout) != 0) + ftdi_error_return(-1, "set dtr failed"); + + return 0; +} + +/** + Set rts line + + \param ftdi pointer to ftdi_context + \param state state to set line to (1 or 0) + + \retval 0: all fine + \retval -1 set rts failed +*/ +int ftdi_setrts(struct ftdi_context *ftdi, int state) +{ + unsigned short usb_val; + + if (state) + usb_val = SIO_SET_RTS_HIGH; + else + usb_val = SIO_SET_RTS_LOW; + + if (usb_control_msg(ftdi->usb_dev, SIO_SET_MODEM_CTRL_REQUEST_TYPE, + SIO_SET_MODEM_CTRL_REQUEST, usb_val, ftdi->interface, + NULL, 0, ftdi->usb_write_timeout) != 0) + ftdi_error_return(-1, "set of rts failed"); + + return 0; +} + /** Set the special event character @@ -1809,80 +1886,4 @@ char *ftdi_get_error_string (struct ftdi_context *ftdi) return ftdi->error_str; } -/* - Flow control code by Lorenz Moesenlechner (lorenz@hcilab.org) - and Matthias Kranz (matthias@hcilab.org) -*/ -/** - Set flowcontrol for ftdi chip - - \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 - - \retval 0: all fine - \retval -1: set flow control failed -*/ -int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl) -{ - if (usb_control_msg(ftdi->usb_dev, SIO_SET_FLOW_CTRL_REQUEST_TYPE, - SIO_SET_FLOW_CTRL_REQUEST, 0, (flowctrl | ftdi->interface), - 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 - \param state state to set line to (1 or 0) - - \retval 0: all fine - \retval -1: set dtr failed -*/ -int ftdi_setdtr(struct ftdi_context *ftdi, int state) -{ - unsigned short usb_val; - - if (state) - usb_val = SIO_SET_DTR_HIGH; - else - usb_val = SIO_SET_DTR_LOW; - - if (usb_control_msg(ftdi->usb_dev, SIO_SET_MODEM_CTRL_REQUEST_TYPE, - SIO_SET_MODEM_CTRL_REQUEST, usb_val, ftdi->interface, - NULL, 0, ftdi->usb_write_timeout) != 0) - ftdi_error_return(-1, "set dtr failed"); - - return 0; -} - -/** - Set rts line - - \param ftdi pointer to ftdi_context - \param state state to set line to (1 or 0) - - \retval 0: all fine - \retval -1 set rts failed -*/ -int ftdi_setrts(struct ftdi_context *ftdi, int state) -{ - unsigned short usb_val; - - if (state) - usb_val = SIO_SET_RTS_HIGH; - else - usb_val = SIO_SET_RTS_LOW; - - if (usb_control_msg(ftdi->usb_dev, SIO_SET_MODEM_CTRL_REQUEST_TYPE, - SIO_SET_MODEM_CTRL_REQUEST, usb_val, ftdi->interface, - NULL, 0, ftdi->usb_write_timeout) != 0) - ftdi_error_return(-1, "set of rts failed"); - - return 0; -} - /* @} end of doxygen libftdi group */ diff --git a/src/ftdi.h b/src/ftdi.h index e476044..9f3527e 100644 --- a/src/ftdi.h +++ b/src/ftdi.h @@ -287,6 +287,11 @@ extern "C" { int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status); + // flow control + int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl); + int ftdi_setdtr(struct ftdi_context *ftdi, int state); + int ftdi_setrts(struct ftdi_context *ftdi, int state); + int ftdi_set_event_char(struct ftdi_context *ftdi, unsigned char eventch, unsigned char enable); int ftdi_set_error_char(struct ftdi_context *ftdi, unsigned char errorch, unsigned char enable); @@ -307,11 +312,6 @@ extern "C" { char *ftdi_get_error_string(struct ftdi_context *ftdi); - // flow control - int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl); - int ftdi_setdtr(struct ftdi_context *ftdi, int state); - int ftdi_setrts(struct ftdi_context *ftdi, int state); - #ifdef __cplusplus } #endif