libftdi Archives

Subject: Re: [PATCH] Add group 0 & 1 options to ftdi_eeprom, and fix group1 eeprom offset for ft232h

From: Brian <brian@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Wed, 18 May 2022 14:50:08 +0000
Hi again, I now understand how to set the eeprom chip in the config
("eeprom_type=0x56"), so I removed that hacky line from the patch.  I still
don't know what 0x8A is used for but I learnt you can use user_data_addr
and user_data_file to manually set this byte in the config.

Thanks


Signed-off-by: Brian Gomes Bascoy (pera) <brian@xxxxxxxxxxxxx>
---
 ftdi_eeprom/main.c | 32 ++++++++++++++++++++++++++++++++
 src/ftdi.c         |  8 ++++----
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c
index e3a09ba..fc427db 100644
--- a/ftdi_eeprom/main.c
+++ b/ftdi_eeprom/main.c
@@ -87,6 +87,27 @@ static int parse_group0_drive(cfg_t *cfg, cfg_opt_t *opt, 
const char *value, voi
     return -1;
 }

+static int parse_group1_drive(cfg_t *cfg, cfg_opt_t *opt, const char *value, 
void *result)
+{
+    static const char* options[] =
+    {
+        "4MA", "8MA", "12MA", "16MA"
+    };
+
+    int i;
+    for (i=0; i<sizeof(options)/sizeof(*options); i++)
+    {
+        if (!(strcasecmp(options[i], value)))
+        {
+            *(int *)result = i;
+            return 0;
+        }
+    }
+
+    cfg_error(cfg, "Invalid %s option '%s'", cfg_opt_name(opt), value);
+    return -1;
+}
+
 static int parse_cbush(cfg_t *cfg, cfg_opt_t *opt, const char *value, void 
*result)
 {
     static const char* options[] =
@@ -261,6 +282,11 @@ int main(int argc, char *argv[])
         CFG_INT_CB("cbusx2", -1, 0, parse_cbusx),
         CFG_INT_CB("cbusx3", -1, 0, parse_cbusx),
         CFG_INT_CB("group0_drive", -1, 0, parse_group0_drive),
+        CFG_BOOL("group0_slew", cfg_false, 0),
+        CFG_BOOL("group0_schmitt", cfg_false, 0),
+        CFG_INT_CB("group1_drive", -1, 0, parse_group1_drive),
+        CFG_BOOL("group1_slew", cfg_false, 0),
+        CFG_BOOL("group1_schmitt", cfg_false, 0),
         CFG_BOOL("invert_txd", cfg_false, 0),
         CFG_BOOL("invert_rxd", cfg_false, 0),
         CFG_BOOL("invert_rts", cfg_false, 0),
@@ -516,6 +542,12 @@ int main(int argc, char *argv[])
             eeprom_set_value(ftdi, CBUS_FUNCTION_9, cfg_getint(cfg, "cbush9"));
         if (cfg_getint(cfg, "group0_drive") != -1)
             eeprom_set_value(ftdi, GROUP0_DRIVE, cfg_getint(cfg, 
"group0_drive"));
+        eeprom_set_value(ftdi, GROUP0_SLEW, cfg_getbool(cfg, "group0_slew"));
+        eeprom_set_value(ftdi, GROUP0_SCHMITT, cfg_getbool(cfg, 
"group0_schmitt"));
+        if (cfg_getint(cfg, "group1_drive") != -1)
+            eeprom_set_value(ftdi, GROUP1_DRIVE, cfg_getint(cfg, 
"group1_drive"));
+        eeprom_set_value(ftdi, GROUP1_SLEW, cfg_getbool(cfg, "group1_slew"));
+        eeprom_set_value(ftdi, GROUP1_SCHMITT, cfg_getbool(cfg, 
"group1_schmitt"));
     }
     else if (ftdi->type == TYPE_230X)
     {
diff --git a/src/ftdi.c b/src/ftdi.c
index 0a7fb27..8100dff 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -3424,13 +3424,13 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
                 output[0x0c] |= SLOW_SLEW;

             if (eeprom->group1_drive > DRIVE_16MA)
-                output[0x0d] |= DRIVE_16MA;
+                output[0x0c] |= DRIVE_16MA<<4;
             else
-                output[0x0d] |= eeprom->group1_drive;
+                output[0x0c] |= eeprom->group1_drive<<4;
             if (eeprom->group1_schmitt)
-                output[0x0d] |= IS_SCHMITT;
+                output[0x0c] |= IS_SCHMITT<<4;
             if (eeprom->group1_slew)
-                output[0x0d] |= SLOW_SLEW;
+                output[0x0c] |= SLOW_SLEW<<4;

             set_ft232h_cbus(eeprom, output);

--
2.35.1



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

Current Thread