mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Wire buffer length improvments. (#8398)
* Enable I2C_BUFFER_LENGTH definition for Wire lib
Based on
375a89ed58
We should have been very careful when #defining things to not use a name
that could conflict with the user's own code, so this marks that old
define as deprecated.
If you opt-into the new behavior, you do not get the old BUFFER_LENGTH
constant.
As a bonus, changing these uint8_ts to size_t both reduces the code
size & improves performance.
* Increase buffer indexing variable size
I looked over the users of these variables and they should be fine with
no additional changes. The existing methods already have an option to
use size_t rather than uint8_t.
There's a few methods which return int instead of size_t, which isn't
great from a portability perspective but will be fine since this only is
designed to run on the ESP8266.
This commit is contained in:
@ -40,14 +40,14 @@ extern "C" {
|
||||
|
||||
// Initialize Class Variables //////////////////////////////////////////////////
|
||||
|
||||
uint8_t TwoWire::rxBuffer[BUFFER_LENGTH];
|
||||
uint8_t TwoWire::rxBufferIndex = 0;
|
||||
uint8_t TwoWire::rxBufferLength = 0;
|
||||
uint8_t TwoWire::rxBuffer[I2C_BUFFER_LENGTH];
|
||||
size_t TwoWire::rxBufferIndex = 0;
|
||||
size_t TwoWire::rxBufferLength = 0;
|
||||
|
||||
uint8_t TwoWire::txAddress = 0;
|
||||
uint8_t TwoWire::txBuffer[BUFFER_LENGTH];
|
||||
uint8_t TwoWire::txBufferIndex = 0;
|
||||
uint8_t TwoWire::txBufferLength = 0;
|
||||
uint8_t TwoWire::txBuffer[I2C_BUFFER_LENGTH];
|
||||
size_t TwoWire::txBufferIndex = 0;
|
||||
size_t TwoWire::txBufferLength = 0;
|
||||
|
||||
uint8_t TwoWire::transmitting = 0;
|
||||
void (*TwoWire::user_onRequest)(void);
|
||||
@ -122,9 +122,9 @@ void TwoWire::setClockStretchLimit(uint32_t limit)
|
||||
|
||||
size_t TwoWire::requestFrom(uint8_t address, size_t size, bool sendStop)
|
||||
{
|
||||
if (size > BUFFER_LENGTH)
|
||||
if (size > I2C_BUFFER_LENGTH)
|
||||
{
|
||||
size = BUFFER_LENGTH;
|
||||
size = I2C_BUFFER_LENGTH;
|
||||
}
|
||||
size_t read = (twi_readFrom(address, rxBuffer, size, sendStop) == 0) ? size : 0;
|
||||
rxBufferIndex = 0;
|
||||
@ -183,7 +183,7 @@ size_t TwoWire::write(uint8_t data)
|
||||
{
|
||||
if (transmitting)
|
||||
{
|
||||
if (txBufferLength >= BUFFER_LENGTH)
|
||||
if (txBufferLength >= I2C_BUFFER_LENGTH)
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user