Completed the support for the FT4232H chip
[libftdi] / ftdi_eeprom / main.c
index df7c877..ad7de93 100644 (file)
@@ -107,7 +107,6 @@ int main(int argc, char *argv[])
         CFG_INT("product_id", 0, 0),
         CFG_BOOL("self_powered", cfg_true, 0),
         CFG_BOOL("remote_wakeup", cfg_true, 0),
-        CFG_STR_LIST("chip_type", "{BM,R,other}", 0),
         CFG_BOOL("in_is_isochronous", cfg_false, 0),
         CFG_BOOL("out_is_isochronous", cfg_false, 0),
         CFG_BOOL("suspend_pull_downs", cfg_false, 0),
@@ -145,7 +144,7 @@ int main(int argc, char *argv[])
     int _read = 0, _erase = 0, _flash = 0;
 
     int my_eeprom_size = 0;
-    unsigned char eeprom_buf[FTDI_MAX_EEPROM_SIZE];
+    unsigned char *eeprom_buf = NULL;
     char *filename;
     int size_check;
     int i, argc_filename;
@@ -240,33 +239,18 @@ int main(int argc, char *argv[])
     
     if (_read > 0)
     {
+        ftdi_eeprom_decode(ftdi, 0 /* debug: 1 */);
 
-        ftdi_eeprom_decode(ftdi, 0);
-        /* Debug output */
-        /*
-        const char* chip_types[] = {"other", "BM", "R"};
-        printf("vendor_id = \"%04x\"\n", eeprom->vendor_id);
-        printf("product_id = \"%04x\"\n", eeprom->product_id);
-        printf("chip_type = \"%s\"\n",
-          (eeprom->chip_type > 0x06) || (eeprom->chip_type & 0x01) ? "unknown":
-          chip_types[eeprom->chip_type>>1]);
-        printf("self_powered = \"%s\"\n", eeprom->self_powered?"true":"false");
-        printf("remote_wakeup = \"%s\"\n", eeprom->remote_wakeup?"true":"false");
-        printf("max_power = \"%d\"\n", eeprom->max_power);
-        printf("in_is_isochronous = \"%s\"\n", eeprom->in_is_isochronous?"true":"false");
-        printf("out_is_isochronous = \"%s\"\n", eeprom->out_is_isochronous?"true":"false");
-        printf("suspend_pull_downs = \"%s\"\n", eeprom->suspend_pull_downs?"true":"false");
-        printf("use_serial = \"%s\"\n", eeprom->use_serial?"true":"false");
-        printf("change_usb_version = \"%s\"\n", eeprom->change_usb_version?"true":"false");
-        printf("usb_version = \"%d\"\n", eeprom->usb_version);
-        printf("manufacturer = \"%s\"\n", eeprom->manufacturer);
-        printf("product = \"%s\"\n", eeprom->product);
-        printf("serial = \"%s\"\n", eeprom->serial);
-        */
+        eeprom_buf = malloc(my_eeprom_size);
+        ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
 
+        if (eeprom_buf == NULL)
+        {
+            fprintf(stderr, "Malloc failed, aborting\n");
+            goto cleanup;
+        }
         if (filename != NULL && strlen(filename) > 0)
         {
-            ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
 
             FILE *fp = fopen (filename, "wb");
             fwrite (eeprom_buf, 1, my_eeprom_size, fp);
@@ -313,6 +297,15 @@ int main(int argc, char *argv[])
     if (cfg_getbool(cfg, "invert_ri")) invert |= INVERT_RI;
     eeprom_set_value(ftdi, INVERT, invert);
 
+    eeprom_set_value(ftdi, CHANNEL_A_DRIVER, DRIVER_VCP);
+    eeprom_set_value(ftdi, CHANNEL_B_DRIVER, DRIVER_VCP);
+    eeprom_set_value(ftdi, CHANNEL_C_DRIVER, DRIVER_VCP);
+    eeprom_set_value(ftdi, CHANNEL_D_DRIVER, DRIVER_VCP);
+    eeprom_set_value(ftdi, CHANNEL_A_RS485, 0);
+    eeprom_set_value(ftdi, CHANNEL_B_RS485, 0);
+    eeprom_set_value(ftdi, CHANNEL_C_RS485, 0);
+    eeprom_set_value(ftdi, CHANNEL_D_RS485, 0);
+
     if (_erase > 0)
     {
         printf("FTDI erase eeprom: %d\n", ftdi_erase_eeprom(ftdi));
@@ -339,6 +332,7 @@ int main(int argc, char *argv[])
         {
             if (filename != NULL && strlen(filename) > 0)
             {
+                eeprom_buf = malloc(my_eeprom_size);
                 FILE *fp = fopen(filename, "rb");
                 fread(eeprom_buf, 1, my_eeprom_size, fp);
                 fclose(fp);
@@ -361,6 +355,8 @@ int main(int argc, char *argv[])
         else
             printf ("Writing to file: %s\n", filename);
 
+        if (eeprom_buf == NULL)
+            eeprom_buf = malloc(my_eeprom_size);
         ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
 
         fwrite(eeprom_buf, my_eeprom_size, 1, fp);
@@ -368,12 +364,15 @@ int main(int argc, char *argv[])
     }
 
 cleanup:
+    if (eeprom_buf)
+        free(eeprom_buf);
     if (_read > 0 || _erase > 0 || _flash > 0)
     {
         printf("FTDI close: %d\n", ftdi_usb_close(ftdi));
     }
 
     ftdi_deinit (ftdi);
+    ftdi_free (ftdi);
 
     cfg_free(cfg);