2020-06-05 05:08:13 +08:00
|
|
|
/*
|
|
|
|
* Logging of I2C messages
|
|
|
|
*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/i2c.h>
|
2020-06-05 05:08:13 +08:00
|
|
|
|
|
|
|
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/logging/log.h>
|
2020-06-05 05:08:13 +08:00
|
|
|
LOG_MODULE_REGISTER(i2c);
|
|
|
|
|
2022-05-02 22:41:38 +08:00
|
|
|
#if defined(CONFIG_I2C_CALLBACK) && defined(CONFIG_POLL)
|
|
|
|
void z_i2c_transfer_signal_cb(const struct device *dev,
|
|
|
|
int result,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct k_poll_signal *sig = (struct k_poll_signal *)data;
|
|
|
|
|
|
|
|
k_poll_signal_raise(sig, result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-05 05:08:13 +08:00
|
|
|
void i2c_dump_msgs(const char *name, const struct i2c_msg *msgs,
|
|
|
|
uint8_t num_msgs, uint16_t addr)
|
|
|
|
{
|
|
|
|
LOG_DBG("I2C msg: %s, addr=%x", name, addr);
|
|
|
|
for (unsigned int i = 0; i < num_msgs; i++) {
|
|
|
|
const struct i2c_msg *msg = &msgs[i];
|
|
|
|
|
2022-08-25 14:45:30 +08:00
|
|
|
LOG_DBG(" %c %s%s len=%02x: ",
|
|
|
|
msg->flags & I2C_MSG_READ ? 'R' : 'W',
|
|
|
|
msg->flags & I2C_MSG_RESTART ? "Sr " : "",
|
|
|
|
msg->flags & I2C_MSG_STOP ? "P" : "",
|
|
|
|
msg->len);
|
2020-06-05 05:08:13 +08:00
|
|
|
if (!(msg->flags & I2C_MSG_READ)) {
|
|
|
|
LOG_HEXDUMP_DBG(msg->buf, msg->len, "contents:");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|