zephyr/drivers/i2c/i2c_common.c
Tom Burdick a45ece6984 i2c: Adds i2c_transfer_async API for I2C
i2c_transfer_async is the asynchronous version of i2c_transfer where
the completion of the transfer is notified to the caller using a callback.

This can be used in conjuction with the common callbacks and datatypes
in async.h for directly doing an async transfer with an IPC object
to notify a thread.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-08-11 14:12:13 -04:00

42 lines
928 B
C

/*
* Logging of I2C messages
*
* Copyright 2020 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <zephyr/drivers/i2c.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(i2c);
#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
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];
LOG_DBG(" %c len=%02x: ",
msg->flags & I2C_MSG_READ ? 'R' : 'W', msg->len);
if (!(msg->flags & I2C_MSG_READ)) {
LOG_HEXDUMP_DBG(msg->buf, msg->len, "contents:");
}
}
}