libftdi: (tomj) ability to set RS232 break type
authorThomas Jarosch <opensource@intra2net.com>
Tue, 12 Aug 2008 08:41:43 +0000 (08:41 +0000)
committerThomas Jarosch <opensource@intra2net.com>
Tue, 12 Aug 2008 08:41:43 +0000 (08:41 +0000)
ChangeLog
src/ftdi.c
src/ftdi.h

index 235b004..abccc27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 New in 0.14
 -----------
+* Ability to set RS232 break type (Intra2net)
 * 64 bit build support in the RPM spec file (Uwe Bonnes)
 * Small fix to the RPM spec file (Uwe Bonnes)
 * Grouped flow control and modem status code together (Intra2net)
index 0dbc5b6..22d29bf 100644 (file)
@@ -755,7 +755,9 @@ int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate)
 }
 
 /**
-    Set (RS232) line characteristics by Alain Abbas
+    Set (RS232) line characteristics.
+    The break type can only be set via ftdi_set_line_property2()
+    and defaults to "off".
 
     \param ftdi pointer to ftdi_context
     \param bits Number of bits
@@ -768,6 +770,25 @@ 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)
 {
+    return ftdi_set_line_property2(ftdi, bits, sbit, parity, BREAK_OFF);
+}
+
+/**
+    Set (RS232) line characteristics
+
+    \param ftdi pointer to ftdi_context
+    \param bits Number of bits
+    \param sbit Number of stop bits
+    \param parity Parity mode
+    \param break_type Break type
+
+    \retval  0: all fine
+    \retval -1: Setting line property failed
+*/
+int ftdi_set_line_property2(struct ftdi_context *ftdi, enum ftdi_bits_type bits,
+                           enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity,
+                           enum ftdi_break_type break_type)
+{
     unsigned short value = bits;
 
     switch(parity) {
@@ -800,6 +821,15 @@ int ftdi_set_line_property(struct ftdi_context *ftdi, enum ftdi_bits_type bits,
         break;
     }
 
+    switch(break_type) {
+    case BREAK_OFF:
+        value |= (0x00 << 14);
+        break;
+    case BREAK_ON:
+        value |= (0x01 << 14);
+        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");
 
index 9f3527e..1dc4ea3 100644 (file)
@@ -27,8 +27,10 @@ enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_2232C=2, TYPE_R=3 };
 enum ftdi_parity_type { NONE=0, ODD=1, EVEN=2, MARK=3, SPACE=4 };
 /// Number of stop bits for ftdi_set_line_property()
 enum ftdi_stopbits_type { STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2 };
-/// Number of bits ftdi_set_line_property()
+/// Number of bits for ftdi_set_line_property()
 enum ftdi_bits_type { BITS_7=7, BITS_8=8 };
+/// Break type for ftdi_set_line_property2()
+enum ftdi_break_type { BREAK_OFF=0, BREAK_ON=1 };
 
 /// MPSSE bitbang modes
 enum ftdi_mpsse_mode {
@@ -265,6 +267,9 @@ extern "C" {
     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_set_line_property2(struct ftdi_context *ftdi, enum ftdi_bits_type bits,
+                               enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity,
+                               enum ftdi_break_type break_type);
 
     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);