Hi all,
I would like to submit a patch to ftdilib and add following functions
to allow individual EEPROM locations reads and writes (similar to
FTDI's FT_ReadEE() and FT_WriteEE():
int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int
eeprom_addr, unsigned short *eeprom_val);
int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int
eeprom_addr, unsigned short eeprom_val);
The Signalyzer H2 and Signalyzer H4 products I'm working on relies on
the EEPROM interface for the additional features and capabilities that
were added to the product ( additional GPIO, ADC, PWM, LED control,
aux I2C interface), in order to be able to utilize them when libftdi
is used individual EEPROM locations needs to be read/written, the
functions I'm proposing to add to the libftdi will serve this purpose.
Many thanks,
Oleg Seiljus
http://www.signalyzer.com
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]
diff --git a/src/ftdi.c b/src/ftdi.c
index 8b589eb..288ffc0 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -2130,6 +2130,24 @@ int ftdi_eeprom_decode(struct ftdi_eeprom *eeprom,
unsigned char *buf, int size)
}
/**
+ Read eeprom location
+
+ \param ftdi pointer to ftdi_context
+ \param address of eeprom location to be read
+ \param eeprom Pointer to store read eeprom location
+
+ \retval 0: all fine
+ \retval -1: read failed
+*/
+int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr,
unsigned short *eeprom_val)
+{
+ if (usb_control_msg(ftdi->usb_dev, FTDI_DEVICE_IN_REQTYPE,
SIO_READ_EEPROM_REQUEST, 0, eeprom_addr, (char *)eeprom_val, 2,
ftdi->usb_read_timeout) != 2)
+ ftdi_error_return(-1, "reading eeprom failed");
+
+ return 0;
+}
+
+/**
Read eeprom
\param ftdi pointer to ftdi_context
@@ -2231,6 +2249,25 @@ int ftdi_read_eeprom_getsize(struct ftdi_context *ftdi,
unsigned char *eeprom, i
}
/**
+ Write eeprom location
+
+ \param ftdi pointer to ftdi_context
+ \param address of eeprom location to be written
+ \param value to be written
+
+ \retval 0: all fine
+ \retval -1: read failed
+*/
+int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int eeprom_addr,
unsigned short eeprom_val)
+{
+ if (usb_control_msg(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
+ SIO_WRITE_EEPROM_REQUEST,
eeprom_val, eeprom_addr,
+ NULL, 0,
ftdi->usb_write_timeout) != 0)
+ ftdi_error_return(-1, "unable to write eeprom");
+ return 0;
+}
+
+/**
Write eeprom
\param ftdi pointer to ftdi_context
diff --git a/src/ftdi.h b/src/ftdi.h
index f629821..2f60595 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -347,6 +347,9 @@ extern "C"
int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
int ftdi_erase_eeprom(struct ftdi_context *ftdi);
+ int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int
eeprom_addr, unsigned short *eeprom_val);
+ int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int
eeprom_addr, unsigned short eeprom_val);
+
char *ftdi_get_error_string(struct ftdi_context *ftdi);
#ifdef __cplusplus