[PATCH] Make ftdi_read_eeprom_location endianess independent

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH] Make ftdi_read_eeprom_location endianess independent

Yegor Yefremov
From: Yegor Yefremov <[hidden email]>

Read 16-bit integer as two byte array and combine these two bytes
to unsigned short.
---
 src/ftdi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index f5d263c..fdf93fe 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -4195,12 +4195,16 @@ int ftdi_set_eeprom_user_data(struct ftdi_context *ftdi, const char * buf, int s
 */
 int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val)
 {
+    unsigned char buf[2];
+
     if (ftdi == NULL || ftdi->usb_dev == NULL)
         ftdi_error_return(-2, "USB device unavailable");
 
-    if (libusb_control_transfer(ftdi->usb_dev, FTDI_DEVICE_IN_REQTYPE, SIO_READ_EEPROM_REQUEST, 0, eeprom_addr, (unsigned char *)eeprom_val, 2, ftdi->usb_read_timeout) != 2)
+    if (libusb_control_transfer(ftdi->usb_dev, FTDI_DEVICE_IN_REQTYPE, SIO_READ_EEPROM_REQUEST, 0, eeprom_addr, buf, 2, ftdi->usb_read_timeout) != 2)
         ftdi_error_return(-1, "reading eeprom failed");
 
+    *eeprom_val = (0xff & buf[0]) | (buf[1] << 8);
+
     return 0;
 }
 
--
2.1.4


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Make ftdi_read_eeprom_location endianess independent

Thomas Jarosch
Hi Yegor,

On Friday, 10. June 2016 13:58:32 [hidden email] wrote:
> From: Yegor Yefremov <[hidden email]>
>
> Read 16-bit integer as two byte array and combine these two bytes
> to unsigned short.

both patches applied, thanks!

Cheers,
Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Loading...