From: Yegor Yefremov Date: Fri, 10 Jun 2016 11:58:32 +0000 (+0200) Subject: Make ftdi_read_eeprom_location() endianess independent X-Git-Tag: v1.4rc1~19 X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=commitdiff_plain;h=1a3cb7f83149a08e3d463d7d24d50499b035a149 Make ftdi_read_eeprom_location() endianess independent Read 16-bit integer as two byte array and combine these two bytes to unsigned short. --- 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; }