Skip to content

Commit 6cf79a4

Browse files
committed
Wire: fix the behavior of the arduino::ZephyrI2C::read()
Removed unecessary ring buffer peek. Additionally added negative value as a return value in case of an error. Signed-off-by: Jakub Zimnol <zimnol.jakub@gmail.com>
1 parent 147d04f commit 6cf79a4

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

libraries/Wire/Wire.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,12 @@ size_t arduino::ZephyrI2C::write(const uint8_t *buffer, size_t size) {
8080

8181
int arduino::ZephyrI2C::read() {
8282
uint8_t buf[1];
83-
if (ring_buf_peek(&rxRingBuffer.rb, buf, 1) > 0) {
84-
int ret = ring_buf_get(&rxRingBuffer.rb, buf, 1);
85-
if (ret == 0) {
86-
printk("\n\nERR: buff empty\n\n\n");
87-
return 0;
88-
}
89-
return (int)buf[0];
83+
84+
if(!ring_buf_get(&rxRingBuffer.rb, buf, 1)) {
85+
return -1; // no data available
9086
}
91-
return EXIT_FAILURE;
87+
88+
return (int)buf[0];
9289
}
9390

9491
int arduino::ZephyrI2C::available() { // TODO for ADS1115

0 commit comments

Comments
 (0)