Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
|
I2C Interface . More...
Data Structures | |
struct | i2c_dt_spec |
Complete I2C DT information. More... | |
struct | i2c_msg |
One I2C Message. More... | |
struct | i2c_target_callbacks |
Structure providing callbacks to be implemented for devices that supports the I2C target API. More... | |
struct | i2c_target_config |
Structure describing a device that supports the I2C target API. More... | |
struct | i2c_device_state |
I2C specific device state which allows for i2c device class specific additions. More... | |
Macros | |
#define | I2C_SPEED_STANDARD (0x1U) |
I2C Standard Speed: 100 kHz. | |
#define | I2C_SPEED_FAST (0x2U) |
I2C Fast Speed: 400 kHz. | |
#define | I2C_SPEED_FAST_PLUS (0x3U) |
I2C Fast Plus Speed: 1 MHz. | |
#define | I2C_SPEED_HIGH (0x4U) |
I2C High Speed: 3.4 MHz. | |
#define | I2C_SPEED_ULTRA (0x5U) |
I2C Ultra Fast Speed: 5 MHz. | |
#define | I2C_SPEED_DT (0x7U) |
Device Tree specified speed. | |
#define | I2C_SPEED_SHIFT (1U) |
#define | I2C_SPEED_SET(speed) |
#define | I2C_SPEED_MASK (0x7U << I2C_SPEED_SHIFT) /* 3 bits */ |
#define | I2C_SPEED_GET(cfg) |
#define | I2C_ADDR_10_BITS BIT(0) |
Use 10-bit addressing. | |
#define | I2C_MODE_CONTROLLER BIT(4) |
Peripheral to act as Controller. | |
#define | I2C_DT_SPEC_GET_ON_I3C(node_id) |
Structure initializer for i2c_dt_spec from devicetree (on I3C bus) | |
#define | I2C_DT_SPEC_GET_ON_I2C(node_id) |
Structure initializer for i2c_dt_spec from devicetree (on I2C bus) | |
#define | I2C_DT_SPEC_GET(node_id) |
Structure initializer for i2c_dt_spec from devicetree. | |
#define | I2C_DT_SPEC_INST_GET(inst) |
Structure initializer for i2c_dt_spec from devicetree instance. | |
#define | I2C_MSG_WRITE (0U << 0U) |
Write message to I2C bus. | |
#define | I2C_MSG_READ BIT(0) |
Read message from I2C bus. | |
#define | I2C_MSG_STOP BIT(1) |
Send STOP after this message. | |
#define | I2C_MSG_RESTART BIT(2) |
RESTART I2C transaction for this message. | |
#define | I2C_MSG_ADDR_10_BITS BIT(3) |
Use 10-bit addressing for this message. | |
#define | I2C_TARGET_FLAGS_ADDR_10_BITS BIT(0) |
Target device responds to 10-bit addressing. | |
#define | I2C_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, api, ...) |
Like DEVICE_DT_DEFINE() with I2C specifics. | |
#define | I2C_DEVICE_DT_INST_DEFINE(inst, ...) |
Like I2C_DEVICE_DT_DEFINE() for an instance of a DT_DRV_COMPAT compatible. | |
#define | I2C_DT_IODEV_DEFINE(name, node_id) |
Define an iodev for a given dt node on the bus. | |
#define | I2C_IODEV_DEFINE(name, _bus, _addr) |
Define an iodev for a given i2c device on a bus. | |
Typedefs | |
typedef void(* | i2c_callback_t) (const struct device *dev, int result, void *data) |
I2C callback for asynchronous transfer requests. | |
typedef int(* | i2c_target_write_requested_cb_t) (struct i2c_target_config *config) |
Function called when a write to the device is initiated. | |
typedef int(* | i2c_target_write_received_cb_t) (struct i2c_target_config *config, uint8_t val) |
Function called when a write to the device is continued. | |
typedef int(* | i2c_target_read_requested_cb_t) (struct i2c_target_config *config, uint8_t *val) |
Function called when a read from the device is initiated. | |
typedef int(* | i2c_target_read_processed_cb_t) (struct i2c_target_config *config, uint8_t *val) |
Function called when a read from the device is continued. | |
typedef int(* | i2c_target_stop_cb_t) (struct i2c_target_config *config) |
Function called when a stop condition is observed after a start condition addressed to a particular device. | |
Functions | |
static bool | i2c_is_ready_dt (const struct i2c_dt_spec *spec) |
Validate that I2C bus is ready. | |
static bool | i2c_is_read_op (const struct i2c_msg *msg) |
Check if the current message is a read operation. | |
static bool | i2c_is_stop_op (const struct i2c_msg *msg) |
Check if the current message includes a stop. | |
void | i2c_dump_msgs_rw (const struct device *dev, const struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr, bool dump_read) |
Dump out an I2C message. | |
static void | i2c_dump_msgs (const struct device *dev, const struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr) |
Dump out an I2C message, before it is executed. | |
static void | i2c_xfer_stats (const struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs) |
Updates the i2c stats for i2c transfers. | |
int | i2c_configure (const struct device *dev, uint32_t dev_config) |
Configure operation of a host controller. | |
int | i2c_get_config (const struct device *dev, uint32_t *dev_config) |
Get configuration of a host controller. | |
int | i2c_transfer (const struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr) |
Perform data transfer to another I2C device in controller mode. | |
static int | i2c_transfer_cb (const struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr, i2c_callback_t cb, void *userdata) |
Perform data transfer to another I2C device in controller mode. | |
static int | i2c_transfer_cb_dt (const struct i2c_dt_spec *spec, struct i2c_msg *msgs, uint8_t num_msgs, i2c_callback_t cb, void *userdata) |
Perform data transfer to another I2C device in master mode asynchronously. | |
static int | i2c_write_read_cb (const struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr, const void *write_buf, size_t num_write, void *read_buf, size_t num_read, i2c_callback_t cb, void *userdata) |
Write then read data from an I2C device asynchronously. | |
static int | i2c_write_read_cb_dt (const struct i2c_dt_spec *spec, struct i2c_msg *msgs, uint8_t num_msgs, const void *write_buf, size_t num_write, void *read_buf, size_t num_read, i2c_callback_t cb, void *userdata) |
Write then read data from an I2C device asynchronously. | |
static int | i2c_transfer_signal (const struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr, struct k_poll_signal *sig) |
Perform data transfer to another I2C device in controller mode. | |
void | i2c_iodev_submit_fallback (const struct device *dev, struct rtio_iodev_sqe *iodev_sqe) |
Fallback submit implementation. | |
static void | i2c_iodev_submit (struct rtio_iodev_sqe *iodev_sqe) |
Submit request(s) to an I2C device with RTIO. | |
struct rtio_sqe * | i2c_rtio_copy (struct rtio *r, struct rtio_iodev *iodev, const struct i2c_msg *msgs, uint8_t num_msgs) |
Copy the i2c_msgs into a set of RTIO requests. | |
static int | i2c_transfer_dt (const struct i2c_dt_spec *spec, struct i2c_msg *msgs, uint8_t num_msgs) |
Perform data transfer to another I2C device in controller mode. | |
int | i2c_recover_bus (const struct device *dev) |
Recover the I2C bus. | |
static int | i2c_target_register (const struct device *dev, struct i2c_target_config *cfg) |
Registers the provided config as Target device of a controller. | |
static int | i2c_target_unregister (const struct device *dev, struct i2c_target_config *cfg) |
Unregisters the provided config as Target device. | |
int | i2c_target_driver_register (const struct device *dev) |
Instructs the I2C Target device to register itself to the I2C Controller. | |
int | i2c_target_driver_unregister (const struct device *dev) |
Instructs the I2C Target device to unregister itself from the I2C Controller. | |
static int | i2c_write (const struct device *dev, const uint8_t *buf, uint32_t num_bytes, uint16_t addr) |
Write a set amount of data to an I2C device. | |
static int | i2c_write_dt (const struct i2c_dt_spec *spec, const uint8_t *buf, uint32_t num_bytes) |
Write a set amount of data to an I2C device. | |
static int | i2c_read (const struct device *dev, uint8_t *buf, uint32_t num_bytes, uint16_t addr) |
Read a set amount of data from an I2C device. | |
static int | i2c_read_dt (const struct i2c_dt_spec *spec, uint8_t *buf, uint32_t num_bytes) |
Read a set amount of data from an I2C device. | |
static int | i2c_write_read (const struct device *dev, uint16_t addr, const void *write_buf, size_t num_write, void *read_buf, size_t num_read) |
Write then read data from an I2C device. | |
static int | i2c_write_read_dt (const struct i2c_dt_spec *spec, const void *write_buf, size_t num_write, void *read_buf, size_t num_read) |
Write then read data from an I2C device. | |
static int | i2c_burst_read (const struct device *dev, uint16_t dev_addr, uint8_t start_addr, uint8_t *buf, uint32_t num_bytes) |
Read multiple bytes from an internal address of an I2C device. | |
static int | i2c_burst_read_dt (const struct i2c_dt_spec *spec, uint8_t start_addr, uint8_t *buf, uint32_t num_bytes) |
Read multiple bytes from an internal address of an I2C device. | |
static int | i2c_burst_write (const struct device *dev, uint16_t dev_addr, uint8_t start_addr, const uint8_t *buf, uint32_t num_bytes) |
Write multiple bytes to an internal address of an I2C device. | |
static int | i2c_burst_write_dt (const struct i2c_dt_spec *spec, uint8_t start_addr, const uint8_t *buf, uint32_t num_bytes) |
Write multiple bytes to an internal address of an I2C device. | |
static int | i2c_reg_read_byte (const struct device *dev, uint16_t dev_addr, uint8_t reg_addr, uint8_t *value) |
Read internal register of an I2C device. | |
static int | i2c_reg_read_byte_dt (const struct i2c_dt_spec *spec, uint8_t reg_addr, uint8_t *value) |
Read internal register of an I2C device. | |
static int | i2c_reg_write_byte (const struct device *dev, uint16_t dev_addr, uint8_t reg_addr, uint8_t value) |
Write internal register of an I2C device. | |
static int | i2c_reg_write_byte_dt (const struct i2c_dt_spec *spec, uint8_t reg_addr, uint8_t value) |
Write internal register of an I2C device. | |
static int | i2c_reg_update_byte (const struct device *dev, uint8_t dev_addr, uint8_t reg_addr, uint8_t mask, uint8_t value) |
Update internal register of an I2C device. | |
static int | i2c_reg_update_byte_dt (const struct i2c_dt_spec *spec, uint8_t reg_addr, uint8_t mask, uint8_t value) |
Update internal register of an I2C device. | |
Variables | |
const struct rtio_iodev_api | i2c_iodev_api |
I2C Interface .
#define I2C_ADDR_10_BITS BIT(0) |
#include <zephyr/drivers/i2c.h>
Use 10-bit addressing.
DEPRECATED - Use I2C_MSG_ADDR_10_BITS instead.
#define I2C_DEVICE_DT_DEFINE | ( | node_id, | |
init_fn, | |||
pm, | |||
data, | |||
config, | |||
level, | |||
prio, | |||
api, | |||
... ) |
#include <zephyr/drivers/i2c.h>
Like DEVICE_DT_DEFINE() with I2C specifics.
Defines a device which implements the I2C API. May generate a custom device_state container struct and init_fn wrapper when needed depending on I2C CONFIG_I2C_STATS
.
node_id | The devicetree node identifier. |
init_fn | Name of the init function of the driver. Can be NULL . |
pm | PM device resources reference (NULL if device does not use PM). |
data | Pointer to the device's private data. |
config | The address to the structure containing the configuration information for this instance of the driver. |
level | The initialization level. See SYS_INIT() for details. |
prio | Priority within the selected initialization level. See SYS_INIT() for details. |
api | Provides an initial pointer to the API function struct used by the driver. Can be NULL. |
#define I2C_DEVICE_DT_INST_DEFINE | ( | inst, | |
... ) |
#include <zephyr/drivers/i2c.h>
Like I2C_DEVICE_DT_DEFINE() for an instance of a DT_DRV_COMPAT compatible.
inst | instance number. This is replaced by DT_DRV_COMPAT(inst) in the call to I2C_DEVICE_DT_DEFINE(). |
... | other parameters as expected by I2C_DEVICE_DT_DEFINE(). |
#define I2C_DT_IODEV_DEFINE | ( | name, | |
node_id ) |
#include <zephyr/drivers/i2c.h>
Define an iodev for a given dt node on the bus.
These do not need to be shared globally but doing so will save a small amount of memory.
name | Symbolic name of the iodev to define |
node_id | Devicetree node identifier |
#define I2C_DT_SPEC_GET | ( | node_id | ) |
#include <zephyr/drivers/i2c.h>
Structure initializer for i2c_dt_spec from devicetree.
This helper macro expands to a static initializer for a struct i2c_dt_spec
by reading the relevant bus and address data from the devicetree.
node_id | Devicetree node identifier for the I2C device whose struct i2c_dt_spec to create an initializer for |
#define I2C_DT_SPEC_GET_ON_I2C | ( | node_id | ) |
#include <zephyr/drivers/i2c.h>
Structure initializer for i2c_dt_spec from devicetree (on I2C bus)
This helper macro expands to a static initializer for a struct i2c_dt_spec
by reading the relevant bus and address data from the devicetree.
node_id | Devicetree node identifier for the I2C device whose struct i2c_dt_spec to create an initializer for |
#define I2C_DT_SPEC_GET_ON_I3C | ( | node_id | ) |
#include <zephyr/drivers/i2c.h>
Structure initializer for i2c_dt_spec from devicetree (on I3C bus)
This helper macro expands to a static initializer for a struct i2c_dt_spec
by reading the relevant bus and address data from the devicetree.
node_id | Devicetree node identifier for the I2C device whose struct i2c_dt_spec to create an initializer for |
#define I2C_DT_SPEC_INST_GET | ( | inst | ) |
#include <zephyr/drivers/i2c.h>
Structure initializer for i2c_dt_spec from devicetree instance.
This is equivalent to I2C_DT_SPEC_GET(DT_DRV_INST(inst))
.
inst | Devicetree instance number |
#define I2C_IODEV_DEFINE | ( | name, | |
_bus, | |||
_addr ) |
#include <zephyr/drivers/i2c.h>
Define an iodev for a given i2c device on a bus.
These do not need to be shared globally but doing so will save a small amount of memory.
name | Symbolic name of the iodev to define |
_bus | Node ID for I2C bus |
_addr | I2C target address |
#define I2C_MODE_CONTROLLER BIT(4) |
#include <zephyr/drivers/i2c.h>
Peripheral to act as Controller.
#define I2C_MSG_ADDR_10_BITS BIT(3) |
#include <zephyr/drivers/i2c.h>
Use 10-bit addressing for this message.
#define I2C_MSG_READ BIT(0) |
#include <zephyr/drivers/i2c.h>
Read message from I2C bus.
#define I2C_MSG_RESTART BIT(2) |
#include <zephyr/drivers/i2c.h>
RESTART I2C transaction for this message.
#define I2C_MSG_STOP BIT(1) |
#include <zephyr/drivers/i2c.h>
Send STOP after this message.
#define I2C_MSG_WRITE (0U << 0U) |
#include <zephyr/drivers/i2c.h>
Write message to I2C bus.
#define I2C_SPEED_DT (0x7U) |
#include <zephyr/drivers/i2c.h>
Device Tree specified speed.
#define I2C_SPEED_FAST (0x2U) |
#include <zephyr/drivers/i2c.h>
I2C Fast Speed: 400 kHz.
#define I2C_SPEED_FAST_PLUS (0x3U) |
#include <zephyr/drivers/i2c.h>
I2C Fast Plus Speed: 1 MHz.
#define I2C_SPEED_GET | ( | cfg | ) |
#include <zephyr/drivers/i2c.h>
#define I2C_SPEED_HIGH (0x4U) |
#include <zephyr/drivers/i2c.h>
I2C High Speed: 3.4 MHz.
#define I2C_SPEED_MASK (0x7U << I2C_SPEED_SHIFT) /* 3 bits */ |
#include <zephyr/drivers/i2c.h>
#define I2C_SPEED_SET | ( | speed | ) |
#include <zephyr/drivers/i2c.h>
#define I2C_SPEED_SHIFT (1U) |
#include <zephyr/drivers/i2c.h>
#define I2C_SPEED_STANDARD (0x1U) |
#include <zephyr/drivers/i2c.h>
I2C Standard Speed: 100 kHz.
#define I2C_SPEED_ULTRA (0x5U) |
#include <zephyr/drivers/i2c.h>
I2C Ultra Fast Speed: 5 MHz.
#define I2C_TARGET_FLAGS_ADDR_10_BITS BIT(0) |
#include <zephyr/drivers/i2c.h>
Target device responds to 10-bit addressing.
typedef void(* i2c_callback_t) (const struct device *dev, int result, void *data) |
#include <zephyr/drivers/i2c.h>
I2C callback for asynchronous transfer requests.
dev | I2C device which is notifying of transfer completion or error |
result | Result code of the transfer request. 0 is success, -errno for failure. |
data | Transfer requester supplied data which is passed along to the callback. |
typedef int(* i2c_target_read_processed_cb_t) (struct i2c_target_config *config, uint8_t *val) |
#include <zephyr/drivers/i2c.h>
Function called when a read from the device is continued.
This function is invoked by the controller when the bus is ready to provide additional data for a read operation from the address associated with the device device.
The value returned in *val
will be transmitted. A success return shall cause the controller to react to additional read operations. An error return shall cause the controller to ignore bus operations until a new start condition is received.
config | the configuration structure associated with the device to which the operation is addressed. |
val | pointer to storage for the next byte of data to return for the read request. |
typedef int(* i2c_target_read_requested_cb_t) (struct i2c_target_config *config, uint8_t *val) |
#include <zephyr/drivers/i2c.h>
Function called when a read from the device is initiated.
This function is invoked by the controller when the bus completes a start condition for a read operation from the address associated with a particular device.
The value returned in *val
will be transmitted. A success return shall cause the controller to react to additional read operations. An error return shall cause the controller to ignore bus operations until a new start condition is received.
config | the configuration structure associated with the device to which the operation is addressed. |
val | pointer to storage for the first byte of data to return for the read request. |
typedef int(* i2c_target_stop_cb_t) (struct i2c_target_config *config) |
#include <zephyr/drivers/i2c.h>
Function called when a stop condition is observed after a start condition addressed to a particular device.
This function is invoked by the controller when the bus is ready to provide additional data for a read operation from the address associated with the device device. After the function returns the controller shall enter a state where it is ready to react to new start conditions.
config | the configuration structure associated with the device to which the operation is addressed. |
typedef int(* i2c_target_write_received_cb_t) (struct i2c_target_config *config, uint8_t val) |
#include <zephyr/drivers/i2c.h>
Function called when a write to the device is continued.
This function is invoked by the controller when it completes reception of a byte of data in an ongoing write operation to the device.
A success return shall cause the controller to ACK the next byte received. An error return shall cause the controller to NACK the next byte received.
config | the configuration structure associated with the device to which the operation is addressed. |
val | the byte received by the controller. |
typedef int(* i2c_target_write_requested_cb_t) (struct i2c_target_config *config) |
#include <zephyr/drivers/i2c.h>
Function called when a write to the device is initiated.
This function is invoked by the controller when the bus completes a start condition for a write operation to the address associated with a particular device.
A success return shall cause the controller to ACK the next byte received. An error return shall cause the controller to NACK the next byte received.
config | the configuration structure associated with the device to which the operation is addressed. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Read multiple bytes from an internal address of an I2C device.
This routine reads multiple bytes from an internal address of an I2C device synchronously.
Instances of this may be replaced by i2c_write_read().
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
dev_addr | Address of the I2C device for reading. |
start_addr | Internal address from which the data is being read. |
buf | Memory pool that stores the retrieved data. |
num_bytes | Number of bytes being read. |
0 | If successful. |
-EIO | General input / output error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Read multiple bytes from an internal address of an I2C device.
This is equivalent to:
i2c_burst_read(spec->bus, spec->addr, start_addr, buf, num_bytes);
spec | I2C specification from devicetree. |
start_addr | Internal address from which the data is being read. |
buf | Memory pool that stores the retrieved data. |
num_bytes | Number of bytes to read. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write multiple bytes to an internal address of an I2C device.
This routine writes multiple bytes to an internal address of an I2C device synchronously.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
dev_addr | Address of the I2C device for writing. |
start_addr | Internal address to which the data is being written. |
buf | Memory pool from which the data is transferred. |
num_bytes | Number of bytes being written. |
0 | If successful. |
-EIO | General input / output error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write multiple bytes to an internal address of an I2C device.
This is equivalent to:
i2c_burst_write(spec->bus, spec->addr, start_addr, buf, num_bytes);
spec | I2C specification from devicetree. |
start_addr | Internal address to which the data is being written. |
buf | Memory pool from which the data is transferred. |
num_bytes | Number of bytes being written. |
#include <zephyr/drivers/i2c.h>
Configure operation of a host controller.
dev | Pointer to the device structure for the driver instance. |
dev_config | Bit-packed 32-bit value to the device runtime configuration for the I2C controller. |
0 | If successful. |
-EIO | General input / output error, failed to configure device. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Dump out an I2C message, before it is executed.
This is equivalent to:
i2c_dump_msgs_rw(dev, msgs, num_msgs, addr, false);
The read messages' data isn't dumped.
dev | Target for the messages being sent. Its name will be printed in the log. |
msgs | Array of messages to dump. |
num_msgs | Number of messages to dump. |
addr | Address of the I2C target device. |
void i2c_dump_msgs_rw | ( | const struct device * | dev, |
const struct i2c_msg * | msgs, | ||
uint8_t | num_msgs, | ||
uint16_t | addr, | ||
bool | dump_read ) |
#include <zephyr/drivers/i2c.h>
Dump out an I2C message.
Dumps out a list of I2C messages. For any that are writes (W), the data is displayed in hex. Setting dump_read will dump the data for read messages too, which only makes sense when called after the messages have been processed.
It looks something like this (with name "testing"):
dev | Target for the messages being sent. Its name will be printed in the log. |
msgs | Array of messages to dump. |
num_msgs | Number of messages to dump. |
addr | Address of the I2C target device. |
dump_read | Dump data from I2C reads, otherwise only writes have data dumped. |
#include <zephyr/drivers/i2c.h>
Get configuration of a host controller.
This routine provides a way to get current configuration. It is allowed to call the function before i2c_configure, because some I2C ports can be configured during init process. However, if the I2C port is not configured, i2c_get_config returns an error.
i2c_get_config can return cached config or probe hardware, but it has to be up to date with current configuration.
dev | Pointer to the device structure for the driver instance. |
dev_config | Pointer to return bit-packed 32-bit value of the I2C controller configuration. |
0 | If successful. |
-EIO | General input / output error. |
-ERANGE | Configured I2C frequency is invalid. |
-ENOSYS | If get config is not implemented |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Submit request(s) to an I2C device with RTIO.
iodev_sqe | Prepared submissions queue entry connected to an iodev defined by I2C_DT_IODEV_DEFINE. |
void i2c_iodev_submit_fallback | ( | const struct device * | dev, |
struct rtio_iodev_sqe * | iodev_sqe ) |
#include <zephyr/drivers/i2c.h>
Fallback submit implementation.
This implementation will schedule a blocking I2C transaction on the bus via the RTIO work queue. It is only used if the I2C driver did not implement the iodev_submit function.
dev | Pointer to the device structure for an I2C controller driver. |
iodev_sqe | Prepared submissions queue entry connected to an iodev defined by I2C_DT_IODEV_DEFINE. |
#include <zephyr/drivers/i2c.h>
Check if the current message is a read operation.
msg | The message to check |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Validate that I2C bus is ready.
spec | I2C specification from devicetree |
true | if the I2C bus is ready for use. |
false | if the I2C bus is not ready for use. |
#include <zephyr/drivers/i2c.h>
Check if the current message includes a stop.
msg | The message to check |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Read a set amount of data from an I2C device.
This routine reads a set amount of data synchronously.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
buf | Memory pool that stores the retrieved data. |
num_bytes | Number of bytes to read. |
addr | Address of the I2C device being read. |
0 | If successful. |
-EIO | General input / output error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Read a set amount of data from an I2C device.
This is equivalent to:
i2c_read(spec->bus, buf, num_bytes, spec->addr);
spec | I2C specification from devicetree. |
buf | Memory pool that stores the retrieved data. |
num_bytes | Number of bytes to read. |
int i2c_recover_bus | ( | const struct device * | dev | ) |
#include <zephyr/drivers/i2c.h>
Recover the I2C bus.
Attempt to recover the I2C bus.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
0 | If successful |
-EBUSY | If bus is not clear after recovery attempt. |
-EIO | General input / output error. |
-ENOSYS | If bus recovery is not implemented |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Read internal register of an I2C device.
This routine reads the value of an 8-bit internal register of an I2C device synchronously.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
dev_addr | Address of the I2C device for reading. |
reg_addr | Address of the internal register being read. |
value | Memory pool that stores the retrieved register value. |
0 | If successful. |
-EIO | General input / output error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Read internal register of an I2C device.
This is equivalent to:
i2c_reg_read_byte(spec->bus, spec->addr, reg_addr, value);
spec | I2C specification from devicetree. |
reg_addr | Address of the internal register being read. |
value | Memory pool that stores the retrieved register value. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Update internal register of an I2C device.
This routine updates the value of a set of bits from an 8-bit internal register of an I2C device synchronously.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
dev_addr | Address of the I2C device for updating. |
reg_addr | Address of the internal register being updated. |
mask | Bitmask for updating internal register. |
value | Value for updating internal register. |
0 | If successful. |
-EIO | General input / output error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Update internal register of an I2C device.
This is equivalent to:
i2c_reg_update_byte(spec->bus, spec->addr, reg_addr, mask, value);
spec | I2C specification from devicetree. |
reg_addr | Address of the internal register being updated. |
mask | Bitmask for updating internal register. |
value | Value for updating internal register. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write internal register of an I2C device.
This routine writes a value to an 8-bit internal register of an I2C device synchronously.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
dev_addr | Address of the I2C device for writing. |
reg_addr | Address of the internal register being written. |
value | Value to be written to internal register. |
0 | If successful. |
-EIO | General input / output error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write internal register of an I2C device.
This is equivalent to:
i2c_reg_write_byte(spec->bus, spec->addr, reg_addr, value);
spec | I2C specification from devicetree. |
reg_addr | Address of the internal register being written. |
value | Value to be written to internal register. |
struct rtio_sqe * i2c_rtio_copy | ( | struct rtio * | r, |
struct rtio_iodev * | iodev, | ||
const struct i2c_msg * | msgs, | ||
uint8_t | num_msgs ) |
#include <zephyr/drivers/i2c.h>
Copy the i2c_msgs into a set of RTIO requests.
r | RTIO context |
iodev | RTIO IODev to target for the submissions |
msgs | Array of messages |
num_msgs | Number of i2c msgs in array |
sqe | Last submission in the queue added |
NULL | Not enough memory in the context to copy the requests |
int i2c_target_driver_register | ( | const struct device * | dev | ) |
#include <zephyr/drivers/i2c.h>
Instructs the I2C Target device to register itself to the I2C Controller.
This routine instructs the I2C Target device to register itself to the I2C Controller via its parent controller's i2c_target_register() API.
dev | Pointer to the device structure for the I2C target device (not itself an I2C controller). |
0 | Is successful |
-EINVAL | If parameters are invalid |
-EIO | General input / output error. |
int i2c_target_driver_unregister | ( | const struct device * | dev | ) |
#include <zephyr/drivers/i2c.h>
Instructs the I2C Target device to unregister itself from the I2C Controller.
This routine instructs the I2C Target device to unregister itself from the I2C Controller via its parent controller's i2c_target_register() API.
dev | Pointer to the device structure for the I2C target device (not itself an I2C controller). |
0 | Is successful |
-EINVAL | If parameters are invalid |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Registers the provided config as Target device of a controller.
Enable I2C target mode for the 'dev' I2C bus driver using the provided 'config' struct containing the functions and parameters to send bus events. The I2C target will be registered at the address provided as 'address' struct member. Addressing mode - 7 or 10 bit - depends on the 'flags' struct member. Any I2C bus events related to the target mode will be passed onto I2C target device driver via a set of callback functions provided in the 'callbacks' struct member.
Most of the existing hardware allows simultaneous support for controller and target mode. This is however not guaranteed.
dev | Pointer to the device structure for an I2C controller driver configured in target mode. |
cfg | Config struct with functions and parameters used by the I2C driver to send bus events |
0 | Is successful |
-EINVAL | If parameters are invalid |
-EIO | General input / output error. |
-ENOSYS | If target mode is not implemented |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Unregisters the provided config as Target device.
This routine disables I2C target mode for the 'dev' I2C bus driver using the provided 'config' struct containing the functions and parameters to send bus events.
dev | Pointer to the device structure for an I2C controller driver configured in target mode. |
cfg | Config struct with functions and parameters used by the I2C driver to send bus events |
0 | Is successful |
-EINVAL | If parameters are invalid |
-ENOSYS | If target mode is not implemented |
int i2c_transfer | ( | const struct device * | dev, |
struct i2c_msg * | msgs, | ||
uint8_t | num_msgs, | ||
uint16_t | addr ) |
#include <zephyr/drivers/i2c.h>
Perform data transfer to another I2C device in controller mode.
This routine provides a generic interface to perform data transfer to another I2C device synchronously. Use i2c_read()/i2c_write() for simple read or write.
The array of message msgs must not be NULL. The number of message num_msgs may be zero,in which case no transfer occurs.
i2c_msg
buffers all configured for I2C_MSG_WRITE
) may be packed into a single transaction by some drivers, but others may emit each fragment as a distinct write transaction, which will not produce the same behavior. See the documentation of struct i2c_msg
for limitations on support for multi-message bus transactions.dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
msgs | Array of messages to transfer. |
num_msgs | Number of messages to transfer. |
addr | Address of the I2C target device. |
0 | If successful. |
-EIO | General input / output error. |
|
inlinestaticisr-ok |
#include <zephyr/drivers/i2c.h>
Perform data transfer to another I2C device in controller mode.
This routine provides a generic interface to perform data transfer to another I2C device asynchronously with a callback completion.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
msgs | Array of messages to transfer, must live until callback completes. |
num_msgs | Number of messages to transfer. |
addr | Address of the I2C target device. |
cb | Function pointer for completion callback. |
userdata | Userdata passed to callback. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If transfer async is not implemented |
-EWOULDBLOCK | If the device is temporarily busy doing another transfer |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Perform data transfer to another I2C device in master mode asynchronously.
This is equivalent to:
i2c_transfer_cb(spec->bus, msgs, num_msgs, spec->addr, cb, userdata);
spec | I2C specification from devicetree. |
msgs | Array of messages to transfer. |
num_msgs | Number of messages to transfer. |
cb | Function pointer for completion callback. |
userdata | Userdata passed to callback. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Perform data transfer to another I2C device in controller mode.
This is equivalent to:
i2c_transfer(spec->bus, msgs, num_msgs, spec->addr);
spec | I2C specification from devicetree. |
msgs | Array of messages to transfer. |
num_msgs | Number of messages to transfer. |
|
inlinestaticisr-ok |
#include <zephyr/drivers/i2c.h>
Perform data transfer to another I2C device in controller mode.
This routine provides a generic interface to perform data transfer to another I2C device asynchronously with a k_poll_signal completion.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
msgs | Array of messages to transfer, must live until callback completes. |
num_msgs | Number of messages to transfer. |
addr | Address of the I2C target device. |
sig | Signal to notify of transfer completion. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If transfer async is not implemented |
-EWOULDBLOCK | If the device is temporarily busy doing another transfer |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write a set amount of data to an I2C device.
This routine writes a set amount of data synchronously.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
buf | Memory pool from which the data is transferred. |
num_bytes | Number of bytes to write. |
addr | Address to the target I2C device for writing. |
0 | If successful. |
-EIO | General input / output error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write a set amount of data to an I2C device.
This is equivalent to:
i2c_write(spec->bus, buf, num_bytes, spec->addr);
spec | I2C specification from devicetree. |
buf | Memory pool from which the data is transferred. |
num_bytes | Number of bytes to write. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write then read data from an I2C device.
This supports the common operation "this is what I want", "now give it to me" transaction pair through a combined write-then-read bus transaction.
dev | Pointer to the device structure for an I2C controller driver configured in controller mode. |
addr | Address of the I2C device |
write_buf | Pointer to the data to be written |
num_write | Number of bytes to write |
read_buf | Pointer to storage for read data |
num_read | Number of bytes to read |
0 | if successful |
negative | on error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write then read data from an I2C device asynchronously.
This supports the common operation "this is what I want", "now give it to me" transaction pair through a combined write-then-read bus transaction but using i2c_transfer_cb. This helper function expects caller to pass a message pointer with 2 and only 2 size.
dev | Pointer to the device structure for an I2C controller driver configured in master mode. |
msgs | Array of messages to transfer. |
num_msgs | Number of messages to transfer. |
addr | Address of the I2C device |
write_buf | Pointer to the data to be written |
num_write | Number of bytes to write |
read_buf | Pointer to storage for read data |
num_read | Number of bytes to read |
cb | Function pointer for completion callback. |
userdata | Userdata passed to callback. |
0 | if successful |
negative | on error. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write then read data from an I2C device asynchronously.
This is equivalent to:
i2c_write_read_cb(spec->bus, msgs, num_msgs, spec->addr, write_buf, num_write, read_buf, num_read);
spec | I2C specification from devicetree. |
msgs | Array of messages to transfer. |
num_msgs | Number of messages to transfer. |
write_buf | Pointer to the data to be written |
num_write | Number of bytes to write |
read_buf | Pointer to storage for read data |
num_read | Number of bytes to read |
cb | Function pointer for completion callback. |
userdata | Userdata passed to callback. |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Write then read data from an I2C device.
This is equivalent to:
i2c_write_read(spec->bus, spec->addr, write_buf, num_write, read_buf, num_read);
spec | I2C specification from devicetree. |
write_buf | Pointer to the data to be written |
num_write | Number of bytes to write |
read_buf | Pointer to storage for read data |
num_read | Number of bytes to read |
|
inlinestatic |
#include <zephyr/drivers/i2c.h>
Updates the i2c stats for i2c transfers.
dev | I2C device to update stats for |
msgs | Array of struct i2c_msg |
num_msgs | Number of i2c_msgs |
|
extern |
#include <zephyr/drivers/i2c.h>