libftdi Archives

Subject: [PATCH] -FT230X: Readout, decode and encode the RS232 inverson configuration bits.

From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 14 Aug 2014 15:43:01 +0200
-- 
Uwe Bonnes                bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>From e56d3d7b8f25ceb903c5339c76da62807377724f Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Aug 2014 14:34:38 +0200
Subject: FT230X: Readout, decode and encode the RS232 inverson configuration
 bits.

---
 src/ftdi.c   | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ftdi.h   |  1 +
 src/ftdi_i.h |  5 +++++
 3 files changed, 68 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index c62428d..978342b 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -3065,6 +3065,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
             {
                 output[0x1a + j] = eeprom->cbus_function[j];
             }
+            output[0x0b] = eeprom->rs232_inversion;
             break;
     }
 
@@ -3389,6 +3390,8 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int 
verbose)
         eeprom->group1_drive   = (buf[0x0c] >> 4) & 0x03;
         eeprom->group1_schmitt = (buf[0x0c] >> 4) & IS_SCHMITT;
         eeprom->group1_slew    = (buf[0x0c] >> 4) & SLOW_SLEW;
+
+        eeprom->rs232_inversion = buf[0xb];
     }
 
     if (verbose)
@@ -3512,6 +3515,57 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int 
verbose)
                 if (eeprom->cbus_function[i]<= CBUSH_AWAKE)
                     fprintf(stdout,"CBUS%d Function: %s\n", i, 
cbush_mux[eeprom->cbus_function[i]]);
             }
+            if(eeprom->rs232_inversion ) {
+                int i = 0;
+                fprintf(stdout,"Inversion on ");
+                if (eeprom->rs232_inversion & INVERT_TXD) {
+                    fprintf(stdout,"TXD");
+                    i = 1;
+                }
+                if (eeprom->rs232_inversion & INVERT_RXD) {
+                    if (i)
+                        fprintf(stdout,", ");
+                    fprintf(stdout,"RXD");
+                    i = 1;
+                }
+                if (eeprom->rs232_inversion & INVERT_RTS) {
+                    if (i)
+                        fprintf(stdout,", ");
+                    fprintf(stdout,"RTS");
+                    i = 1;
+                }
+                if (eeprom->rs232_inversion & INVERT_CTS) {
+                    if (i)
+                        fprintf(stdout,", ");
+                    fprintf(stdout,"CTS");
+                    i = 1;
+                }
+                if (eeprom->rs232_inversion & INVERT_DTR) {
+                    if (i)
+                        fprintf(stdout,", ");
+                    fprintf(stdout,"DTR");
+                    i = 1;
+                }
+                if (eeprom->rs232_inversion & INVERT_DSR) {
+                    if (i)
+                        fprintf(stdout,", ");
+                    fprintf(stdout,"DSR");
+                    i = 1;
+                }
+                if (eeprom->rs232_inversion & INVERT_DCD) {
+                    if (i)
+                        fprintf(stdout,", ");
+                    fprintf(stdout,"DCD");
+                    i = 1;
+                }
+                if (eeprom->rs232_inversion & INVERT_RI) {
+                    if (i)
+                        fprintf(stdout,", ");
+                    fprintf(stdout,"RI");
+                    i = 1;
+                }
+                fprintf(stdout," Pin(s)\n");
+            }
         }
 
         if (ftdi->type == TYPE_R)
@@ -3734,6 +3788,9 @@ int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum 
ftdi_eeprom_value valu
         case CHIP_SIZE:
             *value = ftdi->eeprom->size;
             break;
+        case RS232_INVERSION:
+            *value = ftdi->eeprom->rs232_inversion;
+            break;
         default:
             ftdi_error_return(-1, "Request for unknown EEPROM value");
     }
@@ -3923,6 +3980,11 @@ int ftdi_set_eeprom_value(struct ftdi_context *ftdi, 
enum ftdi_eeprom_value valu
             break;
         case CHIP_SIZE:
             ftdi_error_return(-2, "EEPROM Value can't be changed");
+            break;
+        case RS232_INVERSION:
+            ftdi->eeprom->rs232_inversion = value;
+            break;
+
         default :
             ftdi_error_return(-1, "Request to unknown EEPROM value");
     }
diff --git a/src/ftdi.h b/src/ftdi.h
index 07fcd71..e192a66 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -332,6 +332,7 @@ enum ftdi_eeprom_value
     CHANNEL_C_RS485    = 53,
     CHANNEL_D_RS485    = 54,
     RELEASE_NUMBER     = 55,
+    RS232_INVERSION    = 56,
 };
 
 /**
diff --git a/src/ftdi_i.h b/src/ftdi_i.h
index 19d8dd5..066790b 100644
--- a/src/ftdi_i.h
+++ b/src/ftdi_i.h
@@ -123,6 +123,11 @@ struct ftdi_eeprom
     int data_order;
     int flow_control;
 
+    /* FT-X Device and Peripheral control
+     * Fixme: Decode byte[0xa]
+     */
+    int rs232_inversion;
+
     /** eeprom size in bytes. This doesn't get stored in the eeprom
         but is the only way to pass it to ftdi_eeprom_build. */
     int size;
-- 
1.8.4.5


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread