Unverified Commit 7bb30b3c authored by Alexandre-Jacques St-Jacques's avatar Alexandre-Jacques St-Jacques Committed by GitHub

Refactoring TwoWire::requestFrom() headers in Wire.cpp (#5935)

* Refactoring function headers

Changing the header so the main TwoWire::requestFrom() definition uses a `size_t` instead of a `uint8_t`, removing the 255 bytes limit on I2C requests.
Co-authored-by: default avatarFlaviu Tamas <me@flaviutamas.com>
Co-authored-by: default avatarMe No Dev <me-no-dev@users.noreply.github.com>
parent 4b638de1
......@@ -354,7 +354,7 @@ uint8_t TwoWire::endTransmission(bool sendStop)
return 4;
}
uint8_t TwoWire::requestFrom(uint16_t address, uint8_t size, bool sendStop)
size_t TwoWire::requestFrom(uint16_t address, size_t size, bool sendStop)
{
if(is_slave){
log_e("Bus is in Slave Mode");
......@@ -445,42 +445,47 @@ void TwoWire::flush(void)
//i2cFlush(num); // cleanup
}
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)
size_t TwoWire::requestFrom(uint8_t address, size_t len, bool sendStop)
{
return requestFrom(static_cast<uint16_t>(address), static_cast<uint8_t>(quantity), static_cast<bool>(sendStop));
return requestFrom(static_cast<uint16_t>(address), static_cast<size_t>(len), static_cast<bool>(sendStop));
}
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t len, uint8_t sendStop)
{
return requestFrom(static_cast<uint16_t>(address), static_cast<size_t>(len), static_cast<bool>(sendStop));
}
uint8_t TwoWire::requestFrom(uint16_t address, uint8_t quantity, uint8_t sendStop)
uint8_t TwoWire::requestFrom(uint16_t address, uint8_t len, uint8_t sendStop)
{
return requestFrom(address, static_cast<uint8_t>(quantity), static_cast<bool>(sendStop));
return requestFrom(address, static_cast<size_t>(len), static_cast<bool>(sendStop));
}
/* Added to match the Arduino function definition: https://github.com/arduino/ArduinoCore-API/blob/173e8eadced2ad32eeb93bcbd5c49f8d6a055ea6/api/HardwareI2C.h#L39
* See: https://github.com/arduino-libraries/ArduinoECCX08/issues/25
*/
size_t TwoWire::requestFrom(uint8_t address, size_t len, bool stopBit)
uint8_t TwoWire::requestFrom(uint16_t address, uint8_t len, bool stopBit)
{
return requestFrom((uint16_t)address, (uint8_t)len, stopBit);
return requestFrom((uint16_t)address, (size_t)len, stopBit);
}
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity)
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t len)
{
return requestFrom(static_cast<uint16_t>(address), static_cast<uint8_t>(quantity), true);
return requestFrom(static_cast<uint16_t>(address), static_cast<size_t>(len), true);
}
uint8_t TwoWire::requestFrom(uint16_t address, uint8_t quantity)
uint8_t TwoWire::requestFrom(uint16_t address, uint8_t len)
{
return requestFrom(address, static_cast<uint8_t>(quantity), true);
return requestFrom(address, static_cast<size_t>(len), true);
}
uint8_t TwoWire::requestFrom(int address, int quantity)
uint8_t TwoWire::requestFrom(int address, int len)
{
return requestFrom(static_cast<uint16_t>(address), static_cast<uint8_t>(quantity), true);
return requestFrom(static_cast<uint16_t>(address), static_cast<size_t>(len), true);
}
uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop)
uint8_t TwoWire::requestFrom(int address, int len, int sendStop)
{
return static_cast<uint8_t>(requestFrom(static_cast<uint16_t>(address), static_cast<uint8_t>(quantity), static_cast<bool>(sendStop)));
return static_cast<uint8_t>(requestFrom(static_cast<uint16_t>(address), static_cast<size_t>(len), static_cast<bool>(sendStop)));
}
void TwoWire::beginTransmission(int address)
......
......@@ -93,6 +93,7 @@ public:
uint8_t endTransmission(bool sendStop);
uint8_t endTransmission(void);
size_t requestFrom(uint16_t address, size_t size, bool sendStop);
uint8_t requestFrom(uint16_t address, uint8_t size, bool sendStop);
uint8_t requestFrom(uint16_t address, uint8_t size, uint8_t sendStop);
size_t requestFrom(uint8_t address, size_t len, bool stopBit);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment