77#include < Wire.h>
88#include < zephyr/sys/util_macro.h>
99
10+ #include < zephyr/logging/log.h>
11+ LOG_MODULE_REGISTER (arduino_wire, CONFIG_ARDUINO_API_LOG_LEVEL);
12+
1013arduino::ZephyrI2C::ZephyrI2C (const struct device *i2c) : i2c_dev(i2c)
1114{
1215}
@@ -45,12 +48,14 @@ size_t arduino::ZephyrI2C::requestFrom(uint8_t address, size_t len,
4548 /* Use stack-allocated buffer for reading */
4649 uint8_t readbuff[sizeof (rxRingBuffer.buffer )];
4750 if (len > sizeof (readbuff)) {
51+ LOG_ERR (" requested read length (%zu) exceeds buffer size (%zu)" , len, sizeof (readbuff));
4852 return 0 ;
4953 }
5054
5155 int ret = i2c_read (i2c_dev, readbuff, len, address);
5256 if (ret != 0 )
5357 {
58+ LOG_ERR (" burst read failed" );
5459 return 0 ;
5560 }
5661
@@ -59,6 +64,7 @@ size_t arduino::ZephyrI2C::requestFrom(uint8_t address, size_t len,
5964 ret = ring_buf_put (&rxRingBuffer.rb , readbuff, len);
6065 if (ret == 0 )
6166 {
67+ LOG_ERR (" failed to put data in ring buffer" );
6268 return 0 ;
6369 }
6470 return len;
@@ -70,6 +76,7 @@ size_t arduino::ZephyrI2C::requestFrom(uint8_t address, size_t len) { // TODO fo
7076
7177size_t arduino::ZephyrI2C::write (uint8_t data) { // TODO for ADS1115
7278 if (usedTxBuffer >= sizeof (txBuffer)) {
79+ LOG_ERR (" tx buffer is full" );
7380 return 0 ;
7481 }
7582 txBuffer[usedTxBuffer++] = data;
@@ -89,6 +96,7 @@ int arduino::ZephyrI2C::read() {
8996 uint8_t buf[1 ];
9097
9198 if (!ring_buf_get (&rxRingBuffer.rb , buf, 1 )) {
99+ LOG_ERR (" buffer is empty" );
92100 return -1 ; // no data available
93101 }
94102
0 commit comments