Skip to content

Commit e7660b0

Browse files
committed
Enable I2C_BUFFER_LENGTH definition for Wire lib
Based on paclema/arduino-esp32@375a89e 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.
1 parent 55ef3e7 commit e7660b0

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

libraries/Wire/Wire.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ extern "C" {
4040

4141
// Initialize Class Variables //////////////////////////////////////////////////
4242

43-
uint8_t TwoWire::rxBuffer[BUFFER_LENGTH];
43+
uint8_t TwoWire::rxBuffer[I2C_BUFFER_LENGTH];
4444
uint8_t TwoWire::rxBufferIndex = 0;
4545
uint8_t TwoWire::rxBufferLength = 0;
4646

4747
uint8_t TwoWire::txAddress = 0;
48-
uint8_t TwoWire::txBuffer[BUFFER_LENGTH];
48+
uint8_t TwoWire::txBuffer[I2C_BUFFER_LENGTH];
4949
uint8_t TwoWire::txBufferIndex = 0;
5050
uint8_t TwoWire::txBufferLength = 0;
5151

@@ -122,9 +122,9 @@ void TwoWire::setClockStretchLimit(uint32_t limit)
122122

123123
size_t TwoWire::requestFrom(uint8_t address, size_t size, bool sendStop)
124124
{
125-
if (size > BUFFER_LENGTH)
125+
if (size > I2C_BUFFER_LENGTH)
126126
{
127-
size = BUFFER_LENGTH;
127+
size = I2C_BUFFER_LENGTH;
128128
}
129129
size_t read = (twi_readFrom(address, rxBuffer, size, sendStop) == 0) ? size : 0;
130130
rxBufferIndex = 0;
@@ -183,7 +183,7 @@ size_t TwoWire::write(uint8_t data)
183183
{
184184
if (transmitting)
185185
{
186-
if (txBufferLength >= BUFFER_LENGTH)
186+
if (txBufferLength >= I2C_BUFFER_LENGTH)
187187
{
188188
setWriteError();
189189
return 0;

libraries/Wire/Wire.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828
#include "Stream.h"
2929

3030

31-
3231
#ifndef I2C_BUFFER_LENGTH
32+
// DEPRECATED: Do not use BUFFER_LENGTH, prefer I2C_BUFFER_LENGTH
3333
#define BUFFER_LENGTH 128
34-
#else
35-
#define BUFFER_LENGTH I2C_BUFFER_LENGTH
34+
#define I2C_BUFFER_LENGTH BUFFER_LENGTH
3635
#endif
3736

3837
class TwoWire : public Stream

0 commit comments

Comments
 (0)