libftdi Archives

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

From: Brian <brian@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Mon, 16 May 2022 19:05:08 +0000
Hi there, this is a WIP patch for ftdi_eeprom that adds support for drive,
slew and schmitt settings for both ADBUS and ACBUS on the ft232h (currently
only group0_drive exists). I also changed the offset used for the group1
settings in ftdi.c: The eeprom (with stock configuration) of my um232h seems
to have the same memory map used in the 2232h and 4232h for these settings.

The factory defaults are:

group0_drive=8MA
group0_slew=false
group0_schmitt=false
group1_drive=8MA
group1_slew=false
group1_schmitt=false

Two things I still couldn't figure out:
- Why when I run ftdi_eeprom build-eeprom eeprom->chip is 0 instead 0x56
- In my um232h the content of 0x8A is 0x48/"H", I couldn't find what is
this for, any ideas?

Sorry for the messy e-mail, I'm tired, hope it makes sense. Cheers!

Signed-off-by: Brian Gomes Bascoy (pera) <brian@xxxxxxxxxxxxx>
---
 ftdi_eeprom/main.c | 32 ++++++++++++++++++++++++++++++++
 src/ftdi.c         | 10 +++++-----
 2 files changed, 37 insertions(+), 5 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..4875c73 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -3424,17 +3424,17 @@ 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);

-            output[0x1e] = eeprom->chip;
+            output[0x1e] = 0x56;//??? eeprom->chip;
             /* FIXME: Build FT232H specific EEPROM settings */
             break;
         case TYPE_230X:
--
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