adafruit/Adafruit_Arduino_Boards

TinyWireM code requestFrom() incompatible with Wire requestFrom()

bperrybap opened this issue · 1 comments

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

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