Skip to content

Commit 147d04f

Browse files
committed
Wire: reset ring buffer during requestFrom() call
Implemented flush() function to clear the rx buffer. The buffer needs to be flushed so the next read() call returns the proper data. Signed-off-by: Jakub Zimnol <zimnol.jakub@gmail.com>
1 parent 9d9665b commit 147d04f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

libraries/Wire/Wire.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ size_t arduino::ZephyrI2C::requestFrom(uint8_t address, size_t len,
4848
printk("\n\nERR: i2c burst read fails\n\n\n");
4949
return 0;
5050
}
51+
52+
/* Flush the receive buffer so another read() call returns the correct data */
53+
flush();
5154
ret = ring_buf_put(&rxRingBuffer.rb, rxRingBuffer.buffer, len);
5255
if (ret == 0)
5356
{
@@ -101,7 +104,9 @@ int arduino::ZephyrI2C::peek() {
101104
return (int)buf[0];
102105
}
103106

104-
void arduino::ZephyrI2C::flush() {}
107+
void arduino::ZephyrI2C::flush() {
108+
ring_buf_reset(&rxRingBuffer.rb);
109+
}
105110

106111
void arduino::ZephyrI2C::onReceive(voidFuncPtrParamInt cb) {}
107112
void arduino::ZephyrI2C::onRequest(voidFuncPtr cb) {}

0 commit comments

Comments
 (0)