1 /*
2  * Logging of I2C messages
3  *
4  * Copyright 2020 Google LLC
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <stdio.h>
10 
11 #include <drivers/i2c.h>
12 
13 #define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
14 #include <logging/log.h>
15 LOG_MODULE_REGISTER(i2c);
16 
i2c_dump_msgs(const char * name,const struct i2c_msg * msgs,uint8_t num_msgs,uint16_t addr)17 void i2c_dump_msgs(const char *name, const struct i2c_msg *msgs,
18 		   uint8_t num_msgs, uint16_t addr)
19 {
20 	LOG_DBG("I2C msg: %s, addr=%x", name, addr);
21 	for (unsigned int i = 0; i < num_msgs; i++) {
22 		const struct i2c_msg *msg = &msgs[i];
23 
24 		LOG_DBG("   %c len=%02x: ",
25 			msg->flags & I2C_MSG_READ ? 'R' : 'W', msg->len);
26 		if (!(msg->flags & I2C_MSG_READ)) {
27 			LOG_HEXDUMP_DBG(msg->buf, msg->len, "contents:");
28 		}
29 	}
30 }
31