From 2f73e59f57aed0117ef46824cbe50f08f5dff022 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sun, 24 Apr 2005 16:01:32 +0000 Subject: [PATCH] libftdi: (tomj) ported set_line_property patch to HEAD --- src/ftdi.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- src/ftdi.h | 6 ++++++ 2 files changed, 51 insertions(+), 1 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index 69ad240..e10e052 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -20,7 +20,7 @@ #include "ftdi.h" #define ftdi_error_return(code, str) do { \ - ftdi->error_str = str; \ + ftdi->error_str = str; \ return code; \ } while(0); @@ -376,6 +376,50 @@ int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate) return 0; } +/* + set (RS232) line characteristics + by Alain Abbas - +*/ +int ftdi_set_line_property(struct ftdi_context *ftdi, enum ftdi_bits_type bits, + enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity) +{ + unsigned short value = bits; + + switch(parity) { + case NONE: + value |= (0x00 << 8); + break; + case ODD: + value |= (0x01 << 8); + break; + case EVEN: + value |= (0x02 << 8); + break; + case MARK: + value |= (0x03 << 8); + break; + case SPACE: + value |= (0x04 << 8); + break; + } + + switch(sbit) { + case STOP_BIT_1: + value |= (0x00 << 11); + break; + case STOP_BIT_15: + value |= (0x01 << 11); + break; + case STOP_BIT_2: + value |= (0x02 << 11); + break; + } + + if (usb_control_msg(ftdi->usb_dev, 0x40, 0x04, value, ftdi->index, NULL, 0, ftdi->usb_write_timeout) != 0) + ftdi_error_return (-1, "Setting new line property failed"); + + return 0; +} int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size) { diff --git a/src/ftdi.h b/src/ftdi.h index 5fc20a6..46ee56c 100644 --- a/src/ftdi.h +++ b/src/ftdi.h @@ -20,6 +20,10 @@ #include enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_2232C=2 }; +enum ftdi_parity_type { NONE=0, ODD=1, EVEN=2, MARK=3, SPACE=4 }; +enum ftdi_stopbits_type { STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2 }; +enum ftdi_bits_type { BITS_7=7, BITS_8=8 }; + enum ftdi_mpsse_mode { BITMODE_RESET = 0x00, BITMODE_BITBANG= 0x01, @@ -147,6 +151,8 @@ extern "C" { int 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, + enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity); int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size); int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize); -- 1.7.1