Add ftdi_set_eeprom_buf() as proposed in ftdi_eeprom
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Mon, 11 Jul 2011 13:02:23 +0000 (15:02 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 19 Jul 2011 16:45:12 +0000 (18:45 +0200)
src/ftdi.c
src/ftdi.h

index 79e24ab..2a97942 100644 (file)
@@ -3508,6 +3508,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
 
index c0a3d3d..1b1d8df 100644 (file)
@@ -584,6 +584,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);