Add new function ftdi_eeprom_get_strings()
authorAdam Malinowski <amalinowski75@gmail.com>
Thu, 16 Feb 2017 14:17:14 +0000 (15:17 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 22 Feb 2017 09:01:48 +0000 (10:01 +0100)
This function adds possibility of reading EEPROM strings:
manufacturer, product and serial number.

src/ftdi.c
src/ftdi.h

index b87aa1c..777733a 100644 (file)
@@ -2596,6 +2596,47 @@ int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, char * manufacturer,
     return 0;
 }
 
+int ftdi_eeprom_get_strings(struct ftdi_context *ftdi,
+                            char *manufacturer, int mnf_len,
+                            char *product, int prod_len,
+                            char *serial, int serial_len)
+{
+    struct ftdi_eeprom *eeprom;
+
+    if (ftdi == NULL)
+        ftdi_error_return(-1, "No struct ftdi_context");
+
+    if (ftdi->eeprom == NULL)
+        ftdi_error_return(-2,"No struct ftdi_eeprom");
+
+    eeprom = ftdi->eeprom;
+
+    if (ftdi->usb_dev == NULL)
+        ftdi_error_return(-3, "No connected device or device not yet opened");
+
+    if (manufacturer)
+    {
+        strncpy(manufacturer, eeprom->manufacturer, mnf_len);
+        if (mnf_len > 0)
+            manufacturer[mnf_len - 1] = '\0';
+    }
+
+    if (product)
+    {
+        strncpy(product, eeprom->product, prod_len);
+        if (prod_len > 0)
+            product[prod_len - 1] = '\0';
+    }
+
+    if (serial)
+    {
+        strncpy(serial, eeprom->serial, serial_len);
+        if (serial_len > 0)
+            serial[serial_len - 1] = '\0';
+    }
+
+    return 0;
+}
 
 /*FTD2XX doesn't check for values not fitting in the ACBUS Signal options*/
 void set_ft232h_cbus(struct ftdi_eeprom *eeprom, unsigned char * output)
index bb66c53..e307824 100644 (file)
@@ -489,6 +489,11 @@ extern "C"
                               char *manufacturer, int mnf_len,
                               char *description, int desc_len,
                               char *serial, int serial_len);
+
+    int ftdi_eeprom_get_strings(struct ftdi_context *ftdi,
+                                char *manufacturer, int mnf_len,
+                                char *product, int prod_len,
+                                char *serial, int serial_len);
     int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, char * manufacturer,
                                 char * product, char * serial);