| Updated: October 28, 2024 | 
#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.
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: