libftdi-git Archives

Subject: port libftdi to libusb-1.0 branch, eeprom-new, updated. v0.17-167-gd327f92

From: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
To: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sat, 15 Jan 2011 18:22:41 +0100 (CET)
The branch, eeprom-new has been updated
       via  d327f924c20f61561facfd9537fc495beb3fc315 (commit)
       via  545f9df90958b8cedd9945ddc267ef54a735532d (commit)
       via  de4871c4b481faf22acdb227cdd384aebe05d421 (commit)
      from  8a987aa2e1335d9ef3ebbdf496a7b071317b40a3 (commit)


- Log -----------------------------------------------------------------
commit d327f924c20f61561facfd9537fc495beb3fc315
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date:   Sat Jan 15 18:22:36 2011 +0100

    Use eeprom_set_value()/eeprom_get_value() where possible

commit 545f9df90958b8cedd9945ddc267ef54a735532d
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date:   Sat Jan 15 18:21:58 2011 +0100

    Fix typo in documentation

commit de4871c4b481faf22acdb227cdd384aebe05d421
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date:   Sat Jan 15 17:56:21 2011 +0100

    Prepare switch to opaque eeprom buffer

-----------------------------------------------------------------------

Summary of changes:
 ftdi_eeprom/main.c |  133 +++++++++++++++++++++++++++++++++++-----------------
 src/ftdi.c         |    2 +-
 2 files changed, 91 insertions(+), 44 deletions(-)

diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c
index f928e05..03b24b3 100644
--- a/ftdi_eeprom/main.c
+++ b/ftdi_eeprom/main.c
@@ -42,7 +42,7 @@
 #include <ftdi.h>
 #include <ftdi_eeprom_version.h>
 
-int str_to_cbus(char *str, int max_allowed)
+static int str_to_cbus(char *str, int max_allowed)
 {
     #define MAX_OPTION 14
     const char* options[MAX_OPTION] = {
@@ -61,6 +61,42 @@ int str_to_cbus(char *str, int max_allowed)
     return 0;
 }
 
+/**
+ * @brief Set eeprom value
+ *
+ * \param ftdi pointer to ftdi_context
+ * \param value_name Enum of the value to set
+ * \param value Value to set
+ *
+ * Function will abort the program on error
+ **/
+static void eeprom_set_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value 
value_name, int value)
+{
+    if (ftdi_set_eeprom_value(ftdi, value_name, value) < 0)
+    {
+        printf("Unable to set eeprom value %d: %s. Aborting\n", value_name, 
ftdi_get_error_string(ftdi));
+        exit (-1);
+    }
+}
+
+/**
+ * @brief Get eeprom value
+ *
+ * \param ftdi pointer to ftdi_context
+ * \param value_name Enum of the value to get
+ * \param value Value to get
+ *
+ * Function will abort the program on error
+ **/
+static void eeprom_get_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value 
value_name, int *value)
+{
+    if (ftdi_get_eeprom_value(ftdi, value_name, value) < 0)
+    {
+        printf("Unable to get eeprom value %d: %s. Aborting\n", value_name, 
ftdi_get_error_string(ftdi));
+        exit (-1);
+    }
+}
+
 int main(int argc, char *argv[])
 {
     /*
@@ -113,8 +149,7 @@ int main(int argc, char *argv[])
     int i, argc_filename;
     FILE *fp;
 
-    struct ftdi_context ftdi;
-    struct ftdi_eeprom *eeprom;
+    struct ftdi_context *ftdi = NULL;
 
     printf("\nFTDI eeprom generator v%s\n", EEPROM_VERSION_STRING);
     printf ("(c) Intra2net AG and the libftdi developers 
<opensource@xxxxxxxxxxxxx>\n");
@@ -159,43 +194,50 @@ int main(int argc, char *argv[])
     if (cfg_getbool(cfg, "self_powered") && cfg_getint(cfg, "max_power") > 0)
         printf("Hint: Self powered devices should have a max_power setting of 
0.\n");
 
-    ftdi_init(&ftdi);
-    ftdi_eeprom_initdefaults (&ftdi, "Acme Inc.", "FTDI Chip", NULL);
-    eeprom = ftdi.eeprom;
+    if ((ftdi = ftdi_new()) == 0)
+    {
+        fprintf(stderr, "Failed to allocate ftdi structure :%s \n",
+                ftdi_get_error_string(ftdi));
+        return EXIT_FAILURE;
+    }
+
+    ftdi_eeprom_initdefaults (ftdi, "Acme Inc.", "FTDI Chip", NULL);
 
-    eeprom->vendor_id = cfg_getint(cfg, "vendor_id");
-    eeprom->product_id = cfg_getint(cfg, "product_id");
+    eeprom_set_value(ftdi, VENDOR_ID, cfg_getint(cfg, "vendor_id"));
+    eeprom_set_value(ftdi, PRODUCT_ID, cfg_getint(cfg, "product_id"));
+
+    // TODO: Support all chip types
     char *type = cfg_getstr(cfg, "chip_type");
     if (!strcmp(type, "BM")) {
-        ftdi.type = TYPE_BM;
+        ftdi->type = TYPE_BM;
     } else if (!strcmp(type, "R")) {
-        ftdi.type = TYPE_R;
+        ftdi->type = TYPE_R;
     } else {
-        ftdi.type = TYPE_AM;
+        ftdi->type = TYPE_AM;
     }
 
-    eeprom->self_powered = cfg_getbool(cfg, "self_powered");
-    eeprom->remote_wakeup = cfg_getbool(cfg, "remote_wakeup");
-    eeprom->max_power = cfg_getint(cfg, "max_power");
+    eeprom_set_value(ftdi, SELF_POWERED, cfg_getbool(cfg, "self_powered"));
+    eeprom_set_value(ftdi, REMOTE_WAKEUP, cfg_getbool(cfg, "remote_wakeup"));
+    eeprom_set_value(ftdi, MAX_POWER, cfg_getint(cfg, "max_power"));
 
-    eeprom->in_is_isochronous = cfg_getbool(cfg, "in_is_isochronous");
-    eeprom->out_is_isochronous = cfg_getbool(cfg, "out_is_isochronous");
-    eeprom->suspend_pull_downs = cfg_getbool(cfg, "suspend_pull_downs");
+    eeprom_set_value(ftdi, IN_IS_ISOCHRONOUS, cfg_getbool(cfg, 
"in_is_isochronous"));
+    eeprom_set_value(ftdi, OUT_IS_ISOCHRONOUS, cfg_getbool(cfg, 
"out_is_isochronous"));
+    eeprom_set_value(ftdi, SUSPEND_PULL_DOWNS, cfg_getbool(cfg, 
"suspend_pull_downs"));
 
-    eeprom->use_serial = cfg_getbool(cfg, "use_serial");
-    eeprom->use_usb_version = cfg_getbool(cfg, "change_usb_version");
-    eeprom->usb_version = cfg_getint(cfg, "usb_version");
+    eeprom_set_value(ftdi, USE_SERIAL, cfg_getbool(cfg, "use_serial"));
+    eeprom_set_value(ftdi, USE_USB_VERSION, cfg_getbool(cfg, 
"change_usb_version"));
+    eeprom_set_value(ftdi, USB_VERSION, cfg_getint(cfg, "usb_version"));
 
 
-    eeprom->manufacturer = cfg_getstr(cfg, "manufacturer");
-    eeprom->product = cfg_getstr(cfg, "product");
-    eeprom->serial = cfg_getstr(cfg, "serial");
-    eeprom->high_current = cfg_getbool(cfg, "high_current");
-    eeprom->cbus_function[0] = str_to_cbus(cfg_getstr(cfg, "cbus0"), 13);
-    eeprom->cbus_function[1] = str_to_cbus(cfg_getstr(cfg, "cbus1"), 13);
-    eeprom->cbus_function[2] = str_to_cbus(cfg_getstr(cfg, "cbus2"), 13);
-    eeprom->cbus_function[3] = str_to_cbus(cfg_getstr(cfg, "cbus3"), 13);
-    eeprom->cbus_function[4] = str_to_cbus(cfg_getstr(cfg, "cbus4"), 9);
+    ftdi->eeprom->manufacturer = cfg_getstr(cfg, "manufacturer");
+    ftdi->eeprom->product = cfg_getstr(cfg, "product");
+    ftdi->eeprom->serial = cfg_getstr(cfg, "serial");
+    eeprom_set_value(ftdi, HIGH_CURRENT, cfg_getbool(cfg, "high_current"));
+    eeprom_set_value(ftdi, CBUS_FUNCTION_0, str_to_cbus(cfg_getstr(cfg, 
"cbus0"), 13));
+    eeprom_set_value(ftdi, CBUS_FUNCTION_1, str_to_cbus(cfg_getstr(cfg, 
"cbus1"), 13));
+    eeprom_set_value(ftdi, CBUS_FUNCTION_2, str_to_cbus(cfg_getstr(cfg, 
"cbus2"), 13));
+    eeprom_set_value(ftdi, CBUS_FUNCTION_3, str_to_cbus(cfg_getstr(cfg, 
"cbus3"), 13));
+    eeprom_set_value(ftdi, CBUS_FUNCTION_4, str_to_cbus(cfg_getstr(cfg, 
"cbus4"), 9));
     int invert = 0;
     if (cfg_getbool(cfg, "invert_rxd")) invert |= INVERT_RXD;
     if (cfg_getbool(cfg, "invert_txd")) invert |= INVERT_TXD;
@@ -205,26 +247,31 @@ int main(int argc, char *argv[])
     if (cfg_getbool(cfg, "invert_dsr")) invert |= INVERT_DSR;
     if (cfg_getbool(cfg, "invert_dcd")) invert |= INVERT_DCD;
     if (cfg_getbool(cfg, "invert_ri")) invert |= INVERT_RI;
-    eeprom->invert = invert;
+    eeprom_set_value(ftdi, INVERT, invert);
 
     if (_read > 0 || _erase > 0 || _flash > 0)
     {
-        i = ftdi_usb_open(&ftdi, eeprom->vendor_id, eeprom->product_id);
+        int vendor_id = 0, product_id = 0;
+        eeprom_get_value(ftdi, VENDOR_ID, &vendor_id);
+        eeprom_get_value(ftdi, PRODUCT_ID, &product_id);
+
+        i = ftdi_usb_open(ftdi, vendor_id, product_id);
 
         if (i == 0)
         {
-            printf("EEPROM size: %d\n", eeprom->size);
+            // TODO: Do we know the eeprom size already?
+            printf("EEPROM size: %d\n", ftdi->eeprom->size);
         }
         else
         {
-            printf("Unable to find FTDI devices under given vendor/product id: 
0x%X/0x%X\n", eeprom->vendor_id, eeprom->product_id);
-            printf("Error code: %d (%s)\n", i, ftdi_get_error_string(&ftdi));
+            printf("Unable to find FTDI devices under given vendor/product id: 
0x%X/0x%X\n", vendor_id, product_id);
+            printf("Error code: %d (%s)\n", i, ftdi_get_error_string(ftdi));
             printf("Retrying with default FTDI id.\n");
 
-            i = ftdi_usb_open(&ftdi, 0x0403, 0x6001);
+            i = ftdi_usb_open(ftdi, 0x0403, 0x6001);
             if (i != 0)
             {
-                printf("Error: %s\n", ftdi.error_str);
+                printf("Error: %s\n", ftdi->error_str);
                 exit (-1);
             }
         }
@@ -232,9 +279,9 @@ int main(int argc, char *argv[])
 
     if (_read > 0)
     {
-        printf("FTDI read eeprom: %d\n", ftdi_read_eeprom(&ftdi));
+        printf("FTDI read eeprom: %d\n", ftdi_read_eeprom(ftdi));
 
-        ftdi_eeprom_decode(&ftdi, 0);
+        ftdi_eeprom_decode(ftdi, 0);
         /* Debug output */
         /*
         const char* chip_types[] = {"other", "BM", "R"};
@@ -273,10 +320,10 @@ int main(int argc, char *argv[])
 
     if (_erase > 0)
     {
-        printf("FTDI erase eeprom: %d\n", ftdi_erase_eeprom(&ftdi));
+        printf("FTDI erase eeprom: %d\n", ftdi_erase_eeprom(ftdi));
     }
 
-    size_check = ftdi_eeprom_build(&ftdi);
+    size_check = ftdi_eeprom_build(ftdi);
 
     if (size_check == -1)
     {
@@ -302,7 +349,7 @@ int main(int argc, char *argv[])
                 fclose(fp);
             }
         }
-        printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(&ftdi));
+        printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(ftdi));
     }
 
     // Write to file?
@@ -324,10 +371,10 @@ int main(int argc, char *argv[])
 cleanup:
     if (_read > 0 || _erase > 0 || _flash > 0)
     {
-        printf("FTDI close: %d\n", ftdi_usb_close(&ftdi));
+        printf("FTDI close: %d\n", ftdi_usb_close(ftdi));
     }
 
-    ftdi_deinit (&ftdi);
+    ftdi_deinit (ftdi);
 
     cfg_free(cfg);
 
diff --git a/src/ftdi.c b/src/ftdi.c
index 782bd0f..c9e8892 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -3114,7 +3114,7 @@ int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum 
ftdi_eeprom_value valu
    No parameter checking is performed
 
    \param ftdi pointer to ftdi_context
-   \param value_name Enum of the value to query
+   \param value_name Enum of the value to set
    \param value to set
 
    \retval 0: all fine


hooks/post-receive
-- 
port libftdi to libusb-1.0

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

Current Thread
  • port libftdi to libusb-1.0 branch, eeprom-new, updated. v0.17-167-gd327f92, libftdi-git <=