I2C Slave

group I2C_SLAVE

The I2C driver provides support for transferring data between an external I2C device and the chip running this driver.

Unnamed Group

enum pi_i2c_slave_ioctl_e

Values:

enumerator PI_I2C_SLAVE_CTRL_SET_MAX_BAUDRATE = 1 << __PI_I2C_SLAVE_CTRL_SET_MAX_BAUDRATE_BIT

Change maximum baudrate.

typedef struct pi_i2c_slave_args pi_i2c_slave_args_t
typedef void (*pi_i2c_callback_t)(pi_i2c_slave_args_t*)
typedef struct pi_i2c_slave_conf pi_i2c_slave_conf_t

I2C master configuration structure.

This structure is used to pass the desired I2C Slave configuration to the runtime when opening a device.

void pi_i2c_slave_conf_init(pi_i2c_slave_conf_t *conf)

Initialize an I2C Slave configuration with default values.

This function can be called to get default values for all parameters before setting some of them. The structure containing the configuration must be kept alive until the I2C Slave device is opened.

Parameters:
  • conf – A pointer to the I2C Slave configuration.

void pi_i2c_slave_conf_set_addr0(struct pi_i2c_slave_conf *conf, uint16_t addr, uint8_t mask, uint8_t is_10_bit, uint8_t eof, uint8_t sof)

set gap9 slave addr0 in conf.

Parameters:
  • conf – A pointer to the I2C slave configuration.

  • addr – Addr0 for gap slave mode

  • mask – Choose a match mask

  • is_10_bit – If 1, addr is 10 bit

  • eof – EOF

  • sof – SOF

void pi_i2c_slave_conf_set_addr1(struct pi_i2c_slave_conf *conf, uint16_t addr, uint8_t mask, uint8_t is_10_bit, uint8_t eof, uint8_t sof)

set gap9 slave addr1 in conf.

Parameters:
  • conf – A pointer to the I2C slave configuration.

  • addr – Addr1 for gap slave mode

  • mask – Choose a match mask

  • is_10_bit – If 1, addr is 10 bit

  • eof – EOF

  • sof – SOF

int32_t pi_i2c_slave_open(struct pi_device *device)

Open an I2C slave device.

This function must be called before the I2C slave device can be used. It will do all the needed configuration to make it usable and initialize the handle used to refer to this opened device when calling other functions.

Parameters:
  • device – A pointer to the device structure of the device to open. This structure is allocated by the called and must be kept alive until the device is closed.

Returns:

0 if the operation is successfull, -1 if there was an error.

void pi_i2c_slave_close(struct pi_device *device)

Close an opened I2C slave device.

This function can be called to close an opened I2C slave device once it is not needed anymore, in order to free all allocated resources. Once this function is called, the device is not accessible anymore and must be opened again before being used.

Parameters:
  • device – The device structure of the device to close.

void pi_i2c_slave_set_rx(void *handle, void *l2_addr, uint32_t size)

set rx channel registers for I2C slave

Parameters:
  • handle – A pointer to the low level handle passed by driver in slave irq context.

  • l2_addr – L2 address for the rx buffer

  • size – size of the rx buffer

void pi_i2c_slave_set_tx(void *handle, void *l2_addr, uint32_t size)

set tx channel registers for I2C slave

Parameters:
  • handle – A pointer to the low level handle passed by driver in slave irq context.

  • l2_addr – L2 address for the tx buffer

  • size – Size of the tx buffer

void pi_i2c_slave_unlock(void *handle, int32_t is_rd)

Flush & unlock I2C slave bus (need to stop transfers before)

Parameters:
  • handle – A pointer to the low level handle passed by driver in slave irq context.

  • is_rd – If 1 flush for rx transfer, else for tx

void pi_i2c_slave_ioctl(struct pi_device *device, uint32_t cmd, void *arg)

I2C slave IOCTL function.

This function can be called to change part of the device configuration after it has been opened.

Parameters:
  • device – A pi device structure pointing to I2C slave device

  • cmd – The command which specifies which parameters of the driver to modify and for some of them also their values. The command must be one of those defined in pi_i2c_ioctl_e.

  • arg – An additional value which is required for some parameters when they are set.

void pi_i2c_slave_stop_rx(void *handle)

Stop transfer on I2C slave rx channel.

Parameters:
  • handle – A pointer to the low level handle passed by driver in slave irq context.

void pi_i2c_slave_stop_tx(void *handle)

Stop transfer on I2C slave tx channel.

Parameters:
  • handle – A pointer to the low level handle passed by driver in slave irq context.

struct pi_i2c_slave_args
struct pi_i2c_slave_conf
#include <i2c_slave.h>

I2C master configuration structure.

This structure is used to pass the desired I2C Slave configuration to the runtime when opening a device.

Public Members

uint8_t itf

Specifies on which I2C interface the device is connected.

uint8_t sof0

Specifies whether addr0 triggers irq on START

uint8_t eof0

Specifies whether addr1 triggers irq on STOP

uint8_t sof1

Specifies whether addr1 triggers irq on START

uint8_t eof1

Specifies whether addr1 triggers irq on STOP

uint8_t addr0_10_bit

Specifies whether addr0 is 10 bits

uint8_t addr1_10_bit

Specifies whether addr1 is 10 bits

uint8_t mask0

Specifies addr matching mask for addr0

uint8_t mask1

Specifies addr matching mask for addr1

uint16_t addr0

Addr0 to which itf match

uint16_t addr1

Addr1 to which itf match

uint32_t max_baudrate

Maximum baudrate for the I2C bitstream which can be used with the opened device .

pi_i2c_callback_t rx_callback

callback for rx transfers

pi_i2c_callback_t tx_callback

callback for tx transfers