This minimal example demonstrates the issue.
#include
void setup() {
}
void loop() {
unsigned int rx_cnt=10;
Wire.requestFrom(0x20, rx_cnt);
}
Further investigation has revealed the cause of the issue - from Wire.h
Classic AVR:
uint8_t requestFrom(uint8_t, uint8_t);
uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
uint8_t requestFrom(int, int);
uint8_t requestFrom(int, int, int);
megaavr:
uint8_t requestFrom(uint8_t, size_t);
uint8_t requestFrom(uint8_t, size_t, bool);
uint8_t requestFrom(int, int);
uint8_t requestFrom(int, int, int);
In both cases, these are all aliases of of the second one.
The problem arises when requestFrom() is called with an int as the first argument, and an unsigned int as the second one. This is done in the BMI160 library from EmotiBit
What happens?
size_t is an unsigned int.
So the compiler is looking for the best match for requestFrom(int, unsigned int) - but it can't choose between requestFrom(uint8_t,size_t) (which is the same as requestFrom(uint8_t,unsigned int) )
and
requestFrom(int,int)
In both cases one variable would need it's type converted - so it doesn't know which to choose.
In the case of classic avr, this is not ambiguous, because the choices are requestFrom(uint8_t,uint8_t), and requestFrom(int,int) - so the second one gets chosen, as it requires changing the type of only one of the arguments.
The newly standardized arduino API (used for megaavr, but not for classic avr) specifies for hardwareI2C the signature shall have size_t for the second argument (annoying, as it wastes memory, and the buffer length on existing arduino boards is short enough that a uint8_t would work)
I adjusted the signatures for all the variants of requestFrom to specify size_t as the type for the second argument. Fix is in github now, and will be in 1.0.6
Thanks for reporting this issue.