Add internal I2C argument to send stop while reading (#22127)

This commit is contained in:
s-hadinger 2024-09-11 16:41:35 +02:00 committed by GitHub
parent 1edc4b57b7
commit 9d012f64c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -62,7 +62,7 @@ TwoWire& I2cGetWire(uint8_t bus = 0) {
* Return code: 0 = Error, 1 = OK
\*-------------------------------------------------------------------------------------------*/
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size, uint8_t bus = 0) {
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size, uint8_t bus = 0, bool sendStop = false) {
i2c_buffer = 0;
TwoWire& myWire = I2cGetWire(bus);
@ -73,7 +73,7 @@ bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size, uint8_t bus = 0) {
while (!status && retry) {
myWire.beginTransmission(addr); // start transmission to device
myWire.write(reg); // sends register address to read from
if (0 == myWire.endTransmission(false)) { // Try to become I2C Master, send data and collect bytes, keep master status for next request...
if (0 == myWire.endTransmission(sendStop)) { // Try to become I2C Master, send data and collect bytes, keep master status for next request...
myWire.requestFrom((int)addr, (int)size); // send data n-bytes read
if (myWire.available() == size) {
for (uint32_t i = 0; i < size; i++) {