Skip to content

Commit 73880fb

Browse files
committed
Wire: add logging module, replace printk() calls with logs
Signed-off-by: Jakub Zimnol <zimnol.jakub@gmail.com>
1 parent 6d04ab8 commit 73880fb

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

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 & 6 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,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\nERR: 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\nERR: 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\nERR: 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

7577
size_t arduino::ZephyrI2C::write(uint8_t data) { // TODO for ADS1115
7678
if (usedTxBuffer >= sizeof(txBuffer)) {
77-
printk("\n\nERR: 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\nERR: buff empty\n\n\n");
99+
LOG_ERR("buffer is empty");
98100
return -1; // no data available
99101
}
100102

0 commit comments

Comments
 (0)