libftdi Archives

Subject: EEPROM max_power build/decode inconsistency

From: Daniel Kirkham <dk2@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sun, 29 Apr 2012 00:16:34 +1000
Hi all,

I just noticed an inconsistency in the handling of the max_power EEPROM value 
while writing a short program to reprogram my FT2232.

In ftdi_eeprom_build (line 2580 of ftdi.c):

        output[0x09] = eeprom->max_power>>1;

Whereas: in ftdi_eeprom_decode (line 3051 of ftdi.c):

    eeprom->max_power = buf[0x09];

and further down in ftdi_eeprom_decode (line 3267):

            fprintf(stdout, "Bus Powered: %3d mA%s", eeprom->max_power * 2,

and ftdi_get_eeprom_value (line 3448)

            *value = ftdi->eeprom->max_power;

and ftdi_set_eeprom_value (line 3635)

            ftdi->eeprom->max_power = value;

So, with the exception of line 2580, the value being passed around is the power 
requirement expressed as half the number of milliamperes (mA) required by the 
device, and that line 3267 correctly translates this for presentation purposes. 
This is consistent with the way power units are specified within the USB 
protocols (ie. each unit is 2mA).

On this basis, the bit-shift division in line 2580 should be removed:
2580:   output[0x09] = eeprom->max_power;

Alternatively, if the API defines that max_power should be expressed directly 
in mA, then lines 3051 and 3267 need to be adjusted to:
3051:     eeprom->max_power = buf[0x09] * 2;
3267:   fprintf(stdout, "Bus Powered: %3d mA%s", eeprom->max_power,

Given these changes may break some usage, perhaps this needs to be discussed 
before patching the library one way or the other.

Regards,

Daniel



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

Current Thread