PMSIS API
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Data Structures

struct  pi_i2c_conf_t
 I2C master configuration structure. More...
 

Enumerations

enum  pi_i2c_xfer_flags_e
 Properties for I2C transfers. More...
 
enum  pi_i2c_ioctl_e
 Commands for pi_i2c_control. More...
 

Functions

void pi_i2c_conf_init (pi_i2c_conf_t *conf)
 Initialize an I2C configuration with default values. More...
 
void pi_i2c_conf_set_slave_addr (struct pi_i2c_conf *conf, uint16_t slave_addr, int8_t is_10_bits)
 set slave addr in conf. More...
 
void pi_i2c_conf_set_wait_cycles (struct pi_i2c_conf *conf, uint16_t wait_cycles)
 set wait_cycles in conf. More...
 
int pi_i2c_open (struct pi_device *device)
 Open an I2C device. More...
 
void pi_i2c_close (struct pi_device *device)
 Close an opened I2C device. More...
 
void pi_i2c_ioctl (struct pi_device *device, uint32_t cmd, void *arg)
 Dynamically change the device configuration. More...
 
int pi_i2c_read (struct pi_device *device, uint8_t *rx_buff, int length, pi_i2c_xfer_flags_e flags)
 Enqueue a burst read copy from the I2C (from I2C device to chip). More...
 
int pi_i2c_write (struct pi_device *device, uint8_t *tx_data, int length, pi_i2c_xfer_flags_e flags)
 Enqueue a burst write copy to the I2C (from chip to I2C device). More...
 
void pi_i2c_write_read (struct pi_device *device, void *tx_buffer, void *rx_buffer, uint32_t tx_size, uint32_t rx_size)
 
void pi_i2c_write_dual (struct pi_device *device, void *tx_buffer0, void *tx_buffer1, uint32_t tx_size0, uint32_t tx_size1)
 
void pi_i2c_read_async (struct pi_device *device, uint8_t *rx_buff, int length, pi_i2c_xfer_flags_e flags, pi_task_t *task)
 Enqueue an asynchronous burst read copy from the I2C (from I2C device to chip). More...
 
void pi_i2c_write_async (struct pi_device *device, uint8_t *tx_data, int length, pi_i2c_xfer_flags_e flags, pi_task_t *task)
 Enqueue a burst write copy to the I2C (from chip to I2C device). More...
 
void pi_i2c_write_read_async (struct pi_device *device, void *tx_buffer, void *rx_buffer, uint32_t tx_size, uint32_t rx_size, pi_task_t *callback)
 
void pi_i2c_write_dual_async (struct pi_device *device, void *tx_buffer0, void *tx_buffer1, uint32_t tx_size0, uint32_t tx_size1, pi_task_t *callback)
 
int pi_i2c_read_timeout (struct pi_device *device, uint8_t *rx_buff, int length, pi_i2c_xfer_flags_e flags, uint32_t timeout_us)
 Enqueue an asynchronous burst read copy from the I2C (from I2C device to chip), with timeout. More...
 
int pi_i2c_write_timeout (struct pi_device *device, uint8_t *tx_data, int length, pi_i2c_xfer_flags_e flags, uint32_t timeout_us)
 Enqueue a burst write copy to the I2C (from chip to I2C device), with timeout. More...
 
int pi_i2c_get_request_status (pi_task_t *task)
 get the request status from a task More...
 
int pi_i2c_detect (struct pi_device *device, struct pi_i2c_conf *conf, uint8_t *rx_data)
 Scan i2c bus to detect a dev. More...
 

Description

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

Enumeration Type Documentation

This is used to tell which command to execute through pi_i2c_control.

Enumerator
PI_I2C_CTRL_SET_MAX_BAUDRATE 

Change maximum baudrate.

Parameters
baudrateMax baudrate.
PI_I2C_IOCTL_ABORT_RX 

Abort RX transfer.

Abort current RX transfert.

PI_I2C_IOCTL_ABORT_TX 

Abort TX transfer.

Abort current TX transfert.

PI_I2C_IOCTL_ATTACH_TIMEOUT_RX 

Attach UDMA timer.

This command attaches a UDMA timer channel to UDMA reception channel.

Parameters
timeout_idUDMA timeout channel ID.
PI_I2C_IOCTL_DETACH_TIMEOUT_RX 

Detach UDMA timer.

This command removes a UDMA timer channel attached to UDMA reception channel.

Parameters
timeout_idUDMA timeout channel ID.
PI_I2C_IOCTL_ATTACH_TIMEOUT_TX 

Attach UDMA timer.

This command attaches a UDMA timer channel to UDMA transmission channel.

Parameters
timeout_idUDMA timeout channel ID.
PI_I2C_IOCTL_DETACH_TIMEOUT_TX 

Detach UDMA timer.

This command removes a UDMA timer channel attached to UDMA transmission channel.

Parameters
timeout_idUDMA timeout channel ID.

This is used to specify additional behaviors when transfering data through I2C.

Enumerator
PI_I2C_XFER_STOP 

Generate a STOP bit at the end of the transfer.

PI_I2C_XFER_NO_STOP 

Don't generate a STOP bit at the end of the transfer.

PI_I2C_XFER_START 

Generate a START bit at the beginning of the transfer.

PI_I2C_XFER_NO_START 

Don't generate a START bit at the beginning of the transfer.

PI_I2C_XFER_RESTART 

Generate a RESTART bit at the beginning of the transfer.

PI_I2C_XFER_NO_RESTART 

Don't generate a RESTART bit at the beginning of the transfer.

Function Documentation

void pi_i2c_close ( struct pi_device *  device)

This function can be called to close an opened I2C 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
deviceThe device structure of the device to close.
void pi_i2c_conf_init ( pi_i2c_conf_t conf)

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 device is opened.

Parameters
confA pointer to the I2C configuration.
void pi_i2c_conf_set_slave_addr ( struct pi_i2c_conf *  conf,
uint16_t  slave_addr,
int8_t  is_10_bits 
)
Parameters
confA pointer to the I2C configuration.
slave_addrAddress of the slave device.
is_10_bitsIndicate if slave address is 7 bits or 10 bits.
void pi_i2c_conf_set_wait_cycles ( struct pi_i2c_conf *  conf,
uint16_t  wait_cycles 
)
Parameters
confA pointer to the I2C configuration.
wait_cyclesNumber of wait cycles applied at the end of transfer
int pi_i2c_detect ( struct pi_device *  device,
struct pi_i2c_conf *  conf,
uint8_t *  rx_data 
)

This function can be used to detect if a device is connected to the i2c bus. The pi_i2c_conf_t structure is used to pass the address of the device to look for, with different baudrate if needed.

Parameters
devicePointer to device structure.
confConf struct holding address and baudrate.
rx_dataPointer to 1 Byte buffer to store data.
Return values
0x00If a device has been detected at given address.
0xFFOtherwise.
int pi_i2c_get_request_status ( pi_task_t *  task)

This function can be used to retrieve the request status from a task.

Parameters
taskthe task to retrieve the status from
Warning
in order to be able to retrieve the request status you need to pass a pointer to the task as the first callback argument. You can use next arguments as you please.
Returns
PI_OK if the request was successful PI_ERR_I2C_NACK if a NACK was received during the request
void pi_i2c_ioctl ( struct pi_device *  device,
uint32_t  cmd,
void *  arg 
)

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

Parameters
deviceA pointer to the structure describing the device.
cmdThe 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.
argAn additional value which is required for some parameters when they are set.
int pi_i2c_open ( struct pi_device *  device)

This function must be called before the Hyperbus 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
deviceA 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.
int pi_i2c_read ( struct pi_device *  device,
uint8_t *  rx_buff,
int  length,
pi_i2c_xfer_flags_e  flags 
)

This function can be used to read at least 1 byte of data from the I2C device. The copy will make a synchronous transfer between the I2C and one of the chip memory. The caller is blocked until the transfer is finished. Depending on the chip, there may be some restrictions on the memory which can be used. Check the chip-specific documentation for more details.

Parameters
deviceA pointer to the structure describing the device.
rx_buffThe address in the chip where the received data must be written.
lengthThe size in bytes of the copy.
flagsSpecify additional transfer behaviors like start and stop bits management.
Returns
PI_OK if request is successful PI_ERR_I2C_NACK if a NACK was received during the request
void pi_i2c_read_async ( struct pi_device *  device,
uint8_t *  rx_buff,
int  length,
pi_i2c_xfer_flags_e  flags,
pi_task_t *  task 
)

This function can be used to read at least 1 byte of data from the I2C device. The copy will make an asynchronous transfer between the I2C and one of the chip memory. A task must be specified in order to specify how the caller should be notified when the transfer is finished. The task will contain the request status (success or error). It should be retrieved using the pi_i2c_get_request_status function. Depending on the chip, there may be some restrictions on the memory which can be used. Check the chip-specific documentation for more details.

Parameters
deviceA pointer to the structure describing the device.
rx_buffThe address in the chip where the received data must be written.
lengthThe size in bytes of the copy.
flagsSpecify additional transfer behaviors like start and stop bits management.
taskThe task used to notify the end of transfer. See the documentation of pi_task_t for more details.
int pi_i2c_read_timeout ( struct pi_device *  device,
uint8_t *  rx_buff,
int  length,
pi_i2c_xfer_flags_e  flags,
uint32_t  timeout_us 
)

This function has the same behaviour as pi_i2c_read(), with timeout. This timeout value is used to abort/cancel a transfer when timeout is reached.

Parameters
devicePointer to the structure describing the device.
rx_buffAddress in the chip where the received data must be written.
lengthSize in bytes of the copy.
flagsSpecify additional transfer behaviors like start and stop bits management.
timeout_usTimeout value in us.
Note
To use this feature, a UDMA timeout channel must be allocated before a call to this functions :
  • pi_udma_timeout_alloc()
  • pi_i2c_ioctl() //PI_I2C_IOCTL_ATTACH_TIMEOUT_RX
To use this feature asynchronously, proceed as follows :
int pi_i2c_write ( struct pi_device *  device,
uint8_t *  tx_data,
int  length,
pi_i2c_xfer_flags_e  flags 
)

This function can be used to write at least 1 byte of data to the I2C device. The copy will make a synchronous transfer between the I2C and one of the chip memory. The caller is blocked until the transfer is finished. Depending on the chip, there may be some restrictions on the memory which can be used. Check the chip-specific documentation for more details.

Parameters
deviceA pointer to the structure describing the device.
tx_dataThe address in the chip where the data to be sent is read.
lengthThe size in bytes of the copy.
flagsSpecify additional transfer behaviors like start and stop bits management.
Returns
PI_OK if request is successful PI_ERR_I2C_NACK if a NACK was received during the request
void pi_i2c_write_async ( struct pi_device *  device,
uint8_t *  tx_data,
int  length,
pi_i2c_xfer_flags_e  flags,
pi_task_t *  task 
)

This function can be used to write at least 1 byte of data to the I2C device. The copy will make an asynchronous transfer between the I2C and one of the chip memory. A task must be specified in order to specify how the caller should be notified when the transfer is finished. The task will contain the request status (success or error). It should be retrieved using the pi_i2c_get_request_status function. Depending on the chip, there may be some restrictions on the memory which can be used. Check the chip-specific documentation for more details.

Parameters
deviceA pointer to the structure describing the device.
tx_dataThe address in the chip where the data to be sent is read.
lengthThe size in bytes of the copy
flagsSpecify additional transfer behaviors like start and stop bits management.
taskThe task used to notify the end of transfer. See the documentation of pi_task_t for more details.
void pi_i2c_write_dual ( struct pi_device *  device,
void *  tx_buffer0,
void *  tx_buffer1,
uint32_t  tx_size0,
uint32_t  tx_size1 
)
void pi_i2c_write_dual_async ( struct pi_device *  device,
void *  tx_buffer0,
void *  tx_buffer1,
uint32_t  tx_size0,
uint32_t  tx_size1,
pi_task_t *  callback 
)
void pi_i2c_write_read ( struct pi_device *  device,
void *  tx_buffer,
void *  rx_buffer,
uint32_t  tx_size,
uint32_t  rx_size 
)
void pi_i2c_write_read_async ( struct pi_device *  device,
void *  tx_buffer,
void *  rx_buffer,
uint32_t  tx_size,
uint32_t  rx_size,
pi_task_t *  callback 
)
int pi_i2c_write_timeout ( struct pi_device *  device,
uint8_t *  tx_data,
int  length,
pi_i2c_xfer_flags_e  flags,
uint32_t  timeout_us 
)

This function has the same behaviour as pi_i2c_write(), with timeout. This timeout value is used to abort/cancel a transfer when timeout is reached.

Parameters
devicePointer to the structure describing the device.
tx_dataAddress in the chip where the data to be sent is read.
lengthSize in bytes of the copy
flagsSpecify additional transfer behaviors like start and stop bits management.
timeout_usTimeout value in us.
Note
To use this feature, a UDMA timeout channel must be allocated before a call to this functions :
  • pi_udma_timeout_alloc()
  • pi_i2c_ioctl() //PI_I2C_IOCTL_ATTACH_TIMEOUT_TX
To use this feature asynchronously, proceed as follows :