libi2cd  1.0.3
Linux kernel I2C character device library
Functions
Register Access

Register access functions. More...

Functions

static int i2cd_register_read (struct i2cd *dev, uint16_t addr, uint8_t reg, void *buf, size_t len)
 Read bytes from an 8-bit slave register. More...
 
static int i2cd_register_read16 (struct i2cd *dev, uint16_t addr, uint16_t reg, void *buf, size_t len)
 Read bytes from a 16-bit slave register. More...
 

Detailed Description

Register access functions.

These functions simplify interacting with slave devices that require a repeated START condition to separate writing a register address and reading back content. Register addresses are transmitted in host byte order; if a slave device requires different byte ordering, reg should be converted before being passed as an argument. See endian(3) for more details.

Function Documentation

◆ i2cd_register_read()

static int i2cd_register_read ( struct i2cd dev,
uint16_t  addr,
uint8_t  reg,
void *  buf,
size_t  len 
)
inlinestatic

Read bytes from an 8-bit slave register.

Parameters
devPointer to an I2C character device handle.
addrI2C slave address.
regI2C slave register.
bufPointer to a buffer to receive bytes.
lenNumber of bytes to read.
Returns
Number of messages transferred on success, or -1 on error with errno set appropriately.

This function is equivalent to calling:

i2cd_write_read(dev, addr, &reg, sizeof(reg), buf, len);

◆ i2cd_register_read16()

static int i2cd_register_read16 ( struct i2cd dev,
uint16_t  addr,
uint16_t  reg,
void *  buf,
size_t  len 
)
inlinestatic

Read bytes from a 16-bit slave register.

Parameters
devPointer to an I2C character device handle.
addrI2C slave address.
regI2C slave register.
bufPointer to a buffer to receive bytes.
lenNumber of bytes to read.
Returns
Number of messages transferred on success, or -1 on error with errno set appropriately.

This function is equivalent to calling:

i2cd_write_read(dev, addr, &reg, sizeof(reg), buf, len);
i2cd_write_read
int i2cd_write_read(struct i2cd *dev, uint16_t addr, const void *write_buf, size_t write_len, void *read_buf, size_t read_len)
Write and read bytes from a slave device using a repeated START condition.