Skip to content

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Jul 20, 2022

Description of Change

Adds a new Wire (I2C) functionality to set the RX/TX buffer size and change it any time in the sketch.
Some I2C devices and sensors may require a bigger buffer for its transactions.

Tests scenarios

#include "Wire.h"

void setup() {
  Wire::setBufferSize(512);
  Wire::begin();  // as I2C Master
}

void loop() {
}

Related links

Fixes #6967
Fixes #7042

@SuGlider SuGlider added Type: Feature request Feature request for Arduino ESP32 Area: Peripherals API Relates to peripheral's APIs. labels Jul 20, 2022
@SuGlider SuGlider added this to the 2.0.5 milestone Jul 20, 2022
@SuGlider SuGlider self-assigned this Jul 20, 2022
@SuGlider SuGlider marked this pull request as draft July 20, 2022 15:16
@SuGlider SuGlider marked this pull request as ready for review July 22, 2022 14:17
@r-downing
Copy link
Contributor

r-downing commented Jul 23, 2022

If the size doesn't need to be changed at runtime, perhaps this could be done with a template size, so you don't have to use up more heap memory?

template <size_t desiredCapacity = DEFAULT_SIZE>
class TwoWire: public Stream
...
    uint8_t txBuffer[desiredCapacity];

edit - nevermind, this would be breaking before c++ '17, as you would be required to put the <>

@SuGlider
Copy link
Collaborator Author

Arduino APIs use to be "user proof" also... So creating an API with all necessary checks is safer.

Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, will test tomorrow :) take a look on my comments @SuGlider

SuGlider added 3 commits July 26, 2022 22:10
fixes begin() in case of error
Adds some `defines` that let the application know what fucntionalitites are avilable in Wire and make it more portable among different platforms
Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :) Good job @SuGlider

@SuGlider SuGlider merged commit 9bceb28 into espressif:master Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Type: Feature request Feature request for Arduino ESP32
Projects
3 participants