DCMD_I2C_SENDRECV

#include <hw/i2c.h>

#define DCMD_I2C_SENDRECV           __DIOTF(_DCMD_I2C, 7, i2c_sendrecv_t)

The arguments to devctl() are:

Argument Value
filedes A file descriptor that you obtained by opening the device.
dcmd DCMD_I2C_SENDRECV
dev_data_ptr A pointer to a i2c_sendrecv_t that's followed by a buffer
n_bytes sizeof(i2c_sendrecv_t) plus the size of the buffer
dev_info_ptr NULL

The DCMD_I2C_SENDRECV command executes a send followed by a receive. This sequence is typically used to read a slave device's register value. When multiple applications access the same slave device, it is necessary to execute this sequence atomically to prevent register reads from being interrupted.

Input
  • i2c_sendrecv_t — the message header
  • uint8_t[] — a buffer, containing the send data, that's large enough to hold the receive data
Output
  • i2c_sendrecv_t — the message header (unchanged)
  • uint8_t[] — the receive data in the buffer

The i2c_sendrecv_t structure is defined as:

typedef struct {
    i2c_addr_t slave;      /* slave address */
    uint32_t   send_len;   /* length of send data in bytes */
    uint32_t   recv_len;   /* length of receive data in bytes */
    uint32_t   stop;       /* set stop when complete? */
} i2c_sendrecv_t;

If an error occurs, the command returns:

EIO
The master send failed. Causes include: bad slave address, bad bus speed, bus is busy.
EFAULT
An error occurred while accessing the data buffer.
EINVAL
Bad message format.
ENOMEM
Insufficient memory.
EPERM
The master is locked by another connection.