libftdi Archives

Subject: Add ftdi_set_eeprom_buf() as proposed in ftdi_eeprom

From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Mon, 11 Jul 2011 15:02:23 +0200
---
 src/ftdi.c |   23 +++++++++++++++++++++++
 src/ftdi.h |    1 +
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index 4606bd3..2c61f82 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -3515,6 +3515,29 @@ int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, 
unsigned char * buf, int size
     return 0;
 }
 
+/** Set the EEPROM content from the user-supplied prefilled buffer
+
+    \param ftdi pointer to ftdi_context
+    \param buf buffer to read EEPROM content
+    \param size Size of buffer
+
+    \retval 0: All fine
+    \retval -1: struct ftdi_contxt or ftdi_eeprom of buf missing
+*/
+int ftdi_set_eeprom_buf(struct ftdi_context *ftdi, const unsigned char * buf, 
int size)
+{
+    if (!ftdi || !(ftdi->eeprom) || !buf)
+        ftdi_error_return(-1, "No appropriate structure");
+
+    // Only copy up to FTDI_MAX_EEPROM_SIZE bytes
+    if (size > FTDI_MAX_EEPROM_SIZE)
+        size = FTDI_MAX_EEPROM_SIZE;
+
+    memcpy(ftdi->eeprom->buf, buf, size);
+
+    return 0;
+}
+
 /**
     Read eeprom location
 
diff --git a/src/ftdi.h b/src/ftdi.h
index cf6b312..6e65868 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -588,6 +588,7 @@ extern "C"
     int ftdi_set_eeprom_value(struct ftdi_context *ftdi, enum 
ftdi_eeprom_value value_name, int  value);
 
     int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, 
int size);
+    int ftdi_set_eeprom_buf(struct ftdi_context *ftdi, const unsigned char * 
buf, int size);
 
     int ftdi_read_eeprom(struct ftdi_context *ftdi);
     int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
-- 
1.7.3.4


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

Current Thread
  • Add ftdi_set_eeprom_buf() as proposed in ftdi_eeprom, Uwe Bonnes <=