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,15 +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)) {
48- printk (" \n\n ERR: requested length (%zu) exceeds buffer size (%zu) \n\n\n " ,
49- len, sizeof (readbuff));
51+ LOG_ERR (" requested read length (%zu) exceeds buffer size (%zu)" , len, sizeof (readbuff));
5052 return 0 ;
5153 }
5254
5355 int ret = i2c_read (i2c_dev, readbuff, len, address);
5456 if (ret != 0 )
5557 {
56- printk ( " \n\n ERR: i2c burst read fails \n\n\n " );
58+ LOG_ERR ( " burst read failed " );
5759 return 0 ;
5860 }
5961
@@ -62,7 +64,7 @@ size_t arduino::ZephyrI2C::requestFrom(uint8_t address, size_t len,
6264 ret = ring_buf_put (&rxRingBuffer.rb , readbuff, len);
6365 if (ret == 0 )
6466 {
65- printk ( " \n\n ERR: buff put fails \n\n\n " );
67+ LOG_ERR ( " failed to put data in ring buffer " );
6668 return 0 ;
6769 }
6870 return len;
@@ -74,7 +76,7 @@ size_t arduino::ZephyrI2C::requestFrom(uint8_t address, size_t len) { // TODO fo
7476
7577size_t arduino::ZephyrI2C::write (uint8_t data) { // TODO for ADS1115
7678 if (usedTxBuffer >= sizeof (txBuffer)) {
77- printk ( " \n\n ERR: tx buffer is full\n\n\n " );
79+ LOG_ERR ( " tx buffer is full" );
7880 return 0 ;
7981 }
8082 txBuffer[usedTxBuffer++] = data;
@@ -94,7 +96,7 @@ int arduino::ZephyrI2C::read() {
9496 uint8_t buf[1 ];
9597
9698 if (!ring_buf_get (&rxRingBuffer.rb , buf, 1 )) {
97- printk ( " \n\n ERR: buff empty\n\n\n " );
99+ LOG_ERR ( " buffer is empty" );
98100 return -1 ; // no data available
99101 }
100102
0 commit comments