Skip to content

Commit a2822be

Browse files
JZimnolDhruvaG2000
authored andcommitted
Wire: add logging module, add basic error logs
Signed-off-by: Jakub Zimnol <zimnol.jakub@gmail.com>
1 parent ea100a9 commit a2822be

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ config ARDUINO_MAX_TONES
4141
Specify the maximum number of tones that can be played simultaneously with tone().
4242
If set to a negative value, the maximum number will be determined from the
4343
system's digital pin configuration.
44+
45+
module = ARDUINO_API
46+
module-str = arduino_api
47+
source "subsys/logging/Kconfig.template.log_config"
48+
4449
endif

libraries/Wire/Wire.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
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+
1013
arduino::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

7177
size_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

Comments
 (0)