i2c: use device instead of name for i2c dump messages
This commit changes the parameter of i2c_dump_msgs function from string name to pointer to the device structure. It allows for comparison of device pointers and allow to use the printed device name in i2c shell commands. Signed-off-by: Michał Barnaś <mb@semihalf.com>
This commit is contained in:
parent
7188f925f9
commit
4aac1756a9
|
@ -81,7 +81,7 @@ static int at24_emul_transfer(const struct emul *target, struct i2c_msg *msgs,
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false);
|
||||
i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false);
|
||||
switch (num_msgs) {
|
||||
case 1:
|
||||
if (msgs->flags & I2C_MSG_READ) {
|
||||
|
|
|
@ -75,7 +75,7 @@ static int max17048_emul_transfer_i2c(const struct emul *target, struct i2c_msg
|
|||
|
||||
__ASSERT_NO_MSG(msgs && num_msgs);
|
||||
|
||||
i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false);
|
||||
i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false);
|
||||
switch (num_msgs) {
|
||||
case 2:
|
||||
if (msgs->flags & I2C_MSG_READ) {
|
||||
|
|
|
@ -233,7 +233,7 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg
|
|||
|
||||
__ASSERT_NO_MSG(msgs && num_msgs);
|
||||
|
||||
i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false);
|
||||
i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false);
|
||||
switch (num_msgs) {
|
||||
case 2:
|
||||
if (msgs->flags & I2C_MSG_READ) {
|
||||
|
|
|
@ -32,6 +32,7 @@ config I2C_STATS
|
|||
config I2C_DUMP_MESSAGES
|
||||
bool "Log all I2C transactions"
|
||||
depends on LOG
|
||||
depends on I2C_LOG_LEVEL_DBG
|
||||
help
|
||||
Dump every I2C transaction to the system log as debug level log messages.
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@ void z_i2c_transfer_signal_cb(const struct device *dev,
|
|||
}
|
||||
#endif
|
||||
|
||||
void i2c_dump_msgs_rw(const char *name, const struct i2c_msg *msgs,
|
||||
uint8_t num_msgs, uint16_t addr, bool dump_read)
|
||||
void i2c_dump_msgs_rw(const struct device *dev, const struct i2c_msg *msgs, uint8_t num_msgs,
|
||||
uint16_t addr, bool dump_read)
|
||||
{
|
||||
LOG_DBG("I2C msg: %s, addr=%x", name, addr);
|
||||
LOG_DBG("I2C msg: %s, addr=%x", dev->name, addr);
|
||||
for (unsigned int i = 0; i < num_msgs; i++) {
|
||||
const struct i2c_msg *msg = &msgs[i];
|
||||
const bool is_read = msg->flags & I2C_MSG_READ;
|
||||
|
|
|
@ -76,7 +76,7 @@ static int akm09918c_emul_transfer_i2c(const struct emul *target, struct i2c_msg
|
|||
{
|
||||
struct akm09918c_emul_data *data = target->data;
|
||||
|
||||
i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false);
|
||||
i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false);
|
||||
|
||||
if (num_msgs < 1) {
|
||||
LOG_ERR("Invalid number of messages: %d", num_msgs);
|
||||
|
|
|
@ -241,7 +241,7 @@ static int bmi160_emul_transfer_i2c(const struct emul *target, struct i2c_msg *m
|
|||
|
||||
__ASSERT_NO_MSG(msgs && num_msgs);
|
||||
|
||||
i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false);
|
||||
i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false);
|
||||
switch (num_msgs) {
|
||||
case 2:
|
||||
if (msgs->flags & I2C_MSG_READ) {
|
||||
|
|
|
@ -192,7 +192,7 @@ static int pi3usb9201_emul_transfer(const struct emul *target, struct i2c_msg *m
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
i2c_dump_msgs("emul", msgs, num_msgs, addr);
|
||||
i2c_dump_msgs(target->dev, msgs, num_msgs, addr);
|
||||
|
||||
/* Only single byte register access permitted. Write operations must
|
||||
* consist of 2 write bytes: register offset, register data. Read
|
||||
|
|
|
@ -488,33 +488,33 @@ static inline bool i2c_is_ready_dt(const struct i2c_dt_spec *spec)
|
|||
* D: R len=01: 6c
|
||||
* @endcode
|
||||
*
|
||||
* @param name Name of this dump, displayed at the top.
|
||||
* @param dev Target for the messages being sent. Its name will be printed in the log.
|
||||
* @param msgs Array of messages to dump.
|
||||
* @param num_msgs Number of messages to dump.
|
||||
* @param addr Address of the I2C target device.
|
||||
* @param dump_read Dump data from I2C reads, otherwise only writes have data dumped.
|
||||
*/
|
||||
void i2c_dump_msgs_rw(const char *name, const struct i2c_msg *msgs,
|
||||
uint8_t num_msgs, uint16_t addr, bool dump_read);
|
||||
void i2c_dump_msgs_rw(const struct device *dev, const struct i2c_msg *msgs, uint8_t num_msgs,
|
||||
uint16_t addr, bool dump_read);
|
||||
|
||||
/**
|
||||
* @brief Dump out an I2C message, before it is executed.
|
||||
*
|
||||
* This is equivalent to:
|
||||
*
|
||||
* i2c_dump_msgs_rw(name, msgs, num_msgs, addr, false);
|
||||
* i2c_dump_msgs_rw(dev, msgs, num_msgs, addr, false);
|
||||
*
|
||||
* The read messages' data isn't dumped.
|
||||
*
|
||||
* @param name Name of this dump, displayed at the top.
|
||||
* @param dev Target for the messages being sent. Its name will be printed in the log.
|
||||
* @param msgs Array of messages to dump.
|
||||
* @param num_msgs Number of messages to dump.
|
||||
* @param addr Address of the I2C target device.
|
||||
*/
|
||||
static inline void i2c_dump_msgs(const char *name, const struct i2c_msg *msgs,
|
||||
static inline void i2c_dump_msgs(const struct device *dev, const struct i2c_msg *msgs,
|
||||
uint8_t num_msgs, uint16_t addr)
|
||||
{
|
||||
i2c_dump_msgs_rw(name, msgs, num_msgs, addr, false);
|
||||
i2c_dump_msgs_rw(dev, msgs, num_msgs, addr, false);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_I2C_STATS) || defined(__DOXYGEN__)
|
||||
|
@ -772,7 +772,7 @@ static inline int z_impl_i2c_transfer(const struct device *dev,
|
|||
i2c_xfer_stats(dev, msgs, num_msgs);
|
||||
|
||||
if (IS_ENABLED(CONFIG_I2C_DUMP_MESSAGES)) {
|
||||
i2c_dump_msgs_rw(dev->name, msgs, num_msgs, addr, true);
|
||||
i2c_dump_msgs_rw(dev, msgs, num_msgs, addr, true);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
Loading…
Reference in a new issue