From c9eeb2f12fe5632bab5b35766c1b6261e591872a Mon Sep 17 00:00:00 2001 From: Adam Malinowski Date: Thu, 16 Feb 2017 15:17:14 +0100 Subject: [PATCH 1/1] Add new function ftdi_eeprom_get_strings() This function adds possibility of reading EEPROM strings: manufacturer, product and serial number. --- src/ftdi.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/ftdi.h | 5 +++++ 2 files changed, 46 insertions(+), 0 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index b87aa1c..777733a 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -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) diff --git a/src/ftdi.h b/src/ftdi.h index bb66c53..e307824 100644 --- a/src/ftdi.h +++ b/src/ftdi.h @@ -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); -- 1.7.1