adafruit / Adafruit_Arduino_Boards

Configuration and other support files to use Adafruit's boards like Trinket, Pro Trinket, Gemma, Flora, and more with the Arduino IDE 1.6.x
51 stars 36 forks source link

TinyWireM code requestFrom() incompatible with Wire requestFrom() #13

Open bperrybap opened 7 years ago

bperrybap commented 7 years ago

The Wire library function requestFrom() function returns the number of bytes transferred. The TinyWireM library code function requestFrom() returns a status where zero means success.

The TinyWireM requestFrom() is fundamentally incompatible with the Wire library requestFrom(). Code that expects the Wire API behavior and checks and uses the return value, breaks. Given that the Adafruit tiny core provides a Wire wrapper for TinyWireM, the API functions need to behave the same as Wire.

The fix is pretty simple and isolated to the requestFrom() code in TinyWireM.cpp I'm not sure if there is any concern about breaking any existing code that is depending on the current behavior. Unfortunately, there is no magic bullet fix, either code that works with Wire breaks or code the depends on existing TinyWireM behavior of requestFrom() breaks when the code is fixed.

Note that this same issue/bug also affects the TinyWireM library: https://github.com/adafruit/TinyWireM

bperrybap commented 7 years ago

Here is the documentation for requestFrom() for further clarity on return values: https://www.arduino.cc/en/Reference/WireRequestFrom