ftdi_eeprom: Minor cosmetic fix on usage screen
[libftdi] / ftdi_eeprom / main.c
index 7c6920b..d72f61c 100644 (file)
@@ -4,6 +4,7 @@
     begin                : Mon Apr  7 12:05:22 CEST 2003
     copyright            : (C) 2003-2014 by Intra2net AG and the libftdi developers
     email                : opensource@intra2net.com
+    SPDX-License-Identifier: GPL-2.0-only
  ***************************************************************************/
 
 /***************************************************************************
@@ -65,6 +66,27 @@ static int parse_cbus(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *resul
     return -1;
 }
 
+static int parse_group0_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[] =
@@ -181,7 +203,7 @@ static void usage(const char *program)
     fprintf(stderr, "Syntax: %s [...options...] <config-file>\n", program);
     fprintf(stderr, "Valid Options:\n");
     fprintf(stderr, "--device <description>  Specify device to open by description string. One of:\n");
-    fprintf(stderr, "         d:<devicenode>\n");
+    fprintf(stderr, "         d:<device node>\n");
     fprintf(stderr, "         i:<vendor>:<product>\n");
     fprintf(stderr, "         i:<vendor>:<product>:<index>\n");
     fprintf(stderr, "         s:<vendor>:<product>:<serial>\n");
@@ -189,6 +211,7 @@ static void usage(const char *program)
     fprintf(stderr, "--build-eeprom          Build eeprom image\n");
     fprintf(stderr, "--erase-eeprom          Erase eeprom\n");
     fprintf(stderr, "--flash-eeprom          Flash eeprom\n");
+    fprintf(stderr, "--verbose               Print more information\n");
 }
 
 int main(int argc, char *argv[])
@@ -236,6 +259,7 @@ int main(int argc, char *argv[])
         CFG_INT_CB("cbusx1", -1, 0, parse_cbusx),
         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("invert_txd", cfg_false, 0),
         CFG_BOOL("invert_rxd", cfg_false, 0),
         CFG_BOOL("invert_rts", cfg_false, 0),
@@ -283,6 +307,8 @@ int main(int argc, char *argv[])
     int i;
     FILE *fp;
 
+    int verbose=0;
+
     struct ftdi_context *ftdi = NULL;
 
     printf("\nFTDI eeprom generator v%s\n", EEPROM_VERSION_STRING);
@@ -318,6 +344,10 @@ int main(int argc, char *argv[])
         {
             command = COMMAND_BUILD;
         }
+        else if (!strcmp(argv[i], "--verbose"))
+        {
+            verbose = 1;
+        }
         else
         {
             usage(argv[0]);
@@ -396,7 +426,7 @@ int main(int argc, char *argv[])
 
     if (command == COMMAND_READ)
     {
-        ftdi_eeprom_decode(ftdi, 0 /* debug: 1 */);
+        ftdi_eeprom_decode(ftdi, verbose);
 
         eeprom_buf = malloc(my_eeprom_size);
         ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
@@ -479,6 +509,8 @@ int main(int argc, char *argv[])
             eeprom_set_value(ftdi, CBUS_FUNCTION_8, cfg_getint(cfg, "cbush8"));
         if (cfg_getint(cfg, "cbush9") != -1)
             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"));
     }
     else if (ftdi->type == TYPE_230X)
     {
@@ -611,7 +643,15 @@ int main(int argc, char *argv[])
                     exit (-1);
                 }
 
+                printf("Flashing raw eeprom from file %s (%d bytes)\n",
+                       filename, my_eeprom_size);
+
                 ftdi_set_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
+            } else
+            {
+                printf ("ERROR: flash_raw mode enabled, but no eeprom filename "
+                        "given in config file.\n");
+                exit (-1);
             }
         }
         printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(ftdi));