High level interface for interacting with the Infineon I3C.
The I3C is a MIPI standardized protocol designed to overcome I2C limitations (limited speed, external signals needed for interrupts, no automatic detection of the devices connected to the bus, ...) while remaining power-efficient.
Initialize an I3C instance using the cyhal_i3c_init and provide sda (I3C data) and scl (I3C clock) pins.
By default, this initializes the resource as an I3C controller.
Configure the behavior (controller/secondary controller/target) and the interface (bus frequency, target address) using the cyhal_i3c_configure function.
Attach I2C or I3C targets to the bus using the cyhal_i3c_controller_attach_targets function.
This snippet initializes an I3C resource as controller and read or write data from or to I2C target using static address (7-bit).
Initializing as I3C controller
This snippet initializes an I3C resource as controller and read or write data from or to I3C target using dynamic address.
Initializing as I3C controller
This snippet initializes an I3C resource and describe how to use callbacks.
Initializing as I3C controller
API Reference | |
Result Codes | |
HAL specific return codes definitions for all drivers. | |
Data Structures | |
struct | cyhal_i3c_cfg_t |
I3C bus configuration structure. More... | |
struct | cyhal_i3c_device_info_t |
I3C/I2C device configuration structure. More... | |
Macros | |
#define | CYHAL_I3C_MAX_ATTACHED_DEVICES (CY_I3C_MAX_DEVS) |
Named define for maximum number of the devices attached to the I3C bus. | |
Typedefs | |
typedef void(* | cyhal_i3c_event_callback_t) (void *callback_arg, cyhal_i3c_event_t event) |
Handler for I3C Device interrupts. | |
typedef void(* | cyhal_i3c_ibi_callback_t) (void *callback_arg, cyhal_i3c_ibi_event_t event, uint16_t address) |
Handler for I3C IBI events. | |
Functions | |
cy_rslt_t | cyhal_i3c_init (cyhal_i3c_t *obj, cyhal_gpio_t sda, cyhal_gpio_t scl, const cyhal_clock_t *clk) |
Initialize the I3C peripheral, and configures its specifieds pins. More... | |
void | cyhal_i3c_free (cyhal_i3c_t *obj) |
Deinitialize the i3c object. More... | |
cy_rslt_t | cyhal_i3c_configure (cyhal_i3c_t *obj, const cyhal_i3c_cfg_t *cfg) |
Configure the I3C block. More... | |
cy_rslt_t | cyhal_i3c_controller_attach_targets (cyhal_i3c_t *obj, cyhal_i3c_device_info_t *dev_list, uint32_t dev_list_size) |
Attach I2C and I3C targets to the bus and assign dynamic addresses for the I3C targets. More... | |
cy_rslt_t | cyhal_i3c_controller_transfer_async (cyhal_i3c_t *obj, uint16_t address, const void *tx, size_t tx_size, void *rx, size_t rx_size) |
I3C controller asynchronous transfer This function is non blocking. More... | |
bool | cyhal_i3c_is_busy (cyhal_i3c_t *obj) |
Checks if the specified I3C peripheral is use In use - I3C pheripheral 'actively sending/receiving data'. More... | |
cy_rslt_t | cyhal_i3c_controller_abort_async (cyhal_i3c_t *obj) |
Abort asynchronous transfer. More... | |
cy_rslt_t | cyhal_i3c_controller_write (cyhal_i3c_t *obj, uint16_t address, const uint8_t *data, uint16_t size, uint32_t timeout) |
I3C controller blocking write. More... | |
cy_rslt_t | cyhal_i3c_controller_read (cyhal_i3c_t *obj, uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout) |
I3C controller blocking read. More... | |
cy_rslt_t | cyhal_i3c_controller_mem_write (cyhal_i3c_t *obj, uint16_t address, uint16_t mem_addr, uint16_t mem_addr_size, const uint8_t *data, uint16_t size, uint32_t timeout) |
Perform an i3c write using a block of data stored at the specified memory location This function is blocking. More... | |
cy_rslt_t | cyhal_i3c_controller_mem_read (cyhal_i3c_t *obj, uint16_t address, uint16_t mem_addr, uint16_t mem_addr_size, uint8_t *data, uint16_t size, uint32_t timeout) |
Perform an i3c read using a block of data stored at the specified memory location This function is blocking. More... | |
cy_rslt_t | cyhal_i3c_target_config_write_buffer (cyhal_i3c_t *obj, const uint8_t *data, uint16_t size) |
I3C target config write buffer The user needs to setup a new buffer every time (i.e. More... | |
cy_rslt_t | cyhal_i3c_target_config_read_buffer (cyhal_i3c_t *obj, uint8_t *data, uint16_t size) |
I3C target config read buffer The user needs to setup a new buffer every time (i.e. More... | |
void | cyhal_i3c_register_callback (cyhal_i3c_t *obj, cyhal_i3c_event_callback_t callback, void *callback_arg) |
The I3C event callback handler registration. More... | |
void | cyhal_i3c_register_ibi_callback (cyhal_i3c_t *obj, cyhal_i3c_ibi_callback_t callback, void *callback_arg) |
The I3C IBI callback handler registration. More... | |
void | cyhal_i3c_enable_event (cyhal_i3c_t *obj, cyhal_i3c_event_t event, uint8_t intr_priority, bool enable) |
Configure and Enable or Disable I3C Interrupt. More... | |
void | cyhal_i3c_enable_ibi_event (cyhal_i3c_t *obj, cyhal_i3c_ibi_event_t event, uint8_t intr_priority, bool enable) |
Configure and Enable or Disable I3C Interrupt. More... | |
cy_rslt_t | cyhal_i3c_set_fifo_level (cyhal_i3c_t *obj, cyhal_i3c_fifo_type_t type, uint16_t level) |
Sets a threshold level for a FIFO that will generate an interrupt and a trigger output. More... | |
cy_rslt_t | cyhal_i3c_enable_output (cyhal_i3c_t *obj, cyhal_i3c_output_t output, cyhal_source_t *source) |
Enables the specified output signal from an I3C. More... | |
cy_rslt_t | cyhal_i3c_disable_output (cyhal_i3c_t *obj, cyhal_i3c_output_t output) |
Disables the specified output signal from an I3C. More... | |
cy_rslt_t | cyhal_i3c_init_cfg (cyhal_i3c_t *obj, const cyhal_i3c_configurator_t *cfg) |
Initialize the I3C peripheral using a configurator generated configuration struct. More... | |
uint32_t | cyhal_i3c_target_readable (cyhal_i3c_t *obj) |
Returns the number of bytes written by the I3C controller. More... | |
uint32_t | cyhal_i3c_target_writable (cyhal_i3c_t *obj) |
Returns the number of bytes can be read by the I3C controller. More... | |
struct cyhal_i3c_cfg_t |
Data Fields | ||
---|---|---|
cyhal_i3c_mode_t | i3c_mode | Specifies the mode of I3C controller operation: Controller, Target or Secondary Controller. |
cyhal_i3c_bus_mode_t | i3c_bus_mode | Specifies the mode of I3C bus: Pure or Combined. |
uint8_t | target_address | Desired static address for I3C target device. |
uint32_t | i2c_data_rate | The desired I2C data Rate in Hz. |
uint32_t | i3c_data_rate | The desired I3C data Rate in Hz. |
struct cyhal_i3c_device_info_t |
Data Fields | ||
---|---|---|
uint8_t | static_address | The device 7-bit static address. |
uint8_t | dynamic_address | The desired device 7-bit dynamic address. |
cyhal_i3c_target_type_t | device_type | Device type: I3C or I2C. |
enum cyhal_i3c_mode_t |
enum cyhal_i3c_bus_mode_t |
enum cyhal_i3c_output_t |
Enum of possible output signals from an I3C.
enum cyhal_i3c_event_t |
Enum to enable/disable/report interrupt cause flags.
cy_rslt_t cyhal_i3c_init | ( | cyhal_i3c_t * | obj, |
cyhal_gpio_t | sda, | ||
cyhal_gpio_t | scl, | ||
const cyhal_clock_t * | clk | ||
) |
Initialize the I3C peripheral, and configures its specifieds pins.
NOTE: Controller/Target specific functions only work when the block is configured to be in that mode. Use cyhal_i3c_configure() function to change settings after initialized.
[out] | obj | The I3C object |
[in] | sda | The sda pin |
[in] | scl | The scl pin |
[in] | clk | The clock to use can be shared, if not provided a new clock will be allocated |
void cyhal_i3c_free | ( | cyhal_i3c_t * | obj | ) |
Deinitialize the i3c object.
[in,out] | obj | The i3c object |
cy_rslt_t cyhal_i3c_configure | ( | cyhal_i3c_t * | obj, |
const cyhal_i3c_cfg_t * | cfg | ||
) |
Configure the I3C block.
Apply user defined configuration. Refer to cyhal_i3c_cfg_t for details. Call only after succesfull cyhal_i3c_init()
[in] | obj | The I3C object |
[in] | cfg | Configuration settings to apply |
cy_rslt_t cyhal_i3c_controller_attach_targets | ( | cyhal_i3c_t * | obj, |
cyhal_i3c_device_info_t * | dev_list, | ||
uint32_t | dev_list_size | ||
) |
Attach I2C and I3C targets to the bus and assign dynamic addresses for the I3C targets.
[in] | obj | The I3C object |
[in] | dev_list | The array with I2C and I3C targets configurations |
[in] | dev_list_size | The size of dev_list array |
cy_rslt_t cyhal_i3c_controller_transfer_async | ( | cyhal_i3c_t * | obj, |
uint16_t | address, | ||
const void * | tx, | ||
size_t | tx_size, | ||
void * | rx, | ||
size_t | rx_size | ||
) |
I3C controller asynchronous transfer This function is non blocking.
Use cyhal_i3c_is_busy() API to check status. Execution flow is:
When a read transaction is completed (requested number of bytes are read or error occurred) the busy status is cleared and the CYHAL_I3C_CONTROLLER_RD_CMPLT_EVENT event is generated.
[in] | obj | The I3C object |
[in] | address | device address (7-bit) |
[in] | tx | Pointer to the byte-array of the transmit buffer |
[in] | tx_size | The number of bytes to transmit |
[out] | rx | Pointer to the byte-array of the receive buffer |
[in] | rx_size | The number of bytes to receive |
bool cyhal_i3c_is_busy | ( | cyhal_i3c_t * | obj | ) |
Checks if the specified I3C peripheral is use In use - I3C pheripheral 'actively sending/receiving data'.
[in] | obj | The I3C peripheral to check |
cy_rslt_t cyhal_i3c_controller_abort_async | ( | cyhal_i3c_t * | obj | ) |
Abort asynchronous transfer.
This function does not perform any check - that should happen in upper layers.
[in] | obj | The I3C object |
cy_rslt_t cyhal_i3c_controller_write | ( | cyhal_i3c_t * | obj, |
uint16_t | address, | ||
const uint8_t * | data, | ||
uint16_t | size, | ||
uint32_t | timeout | ||
) |
I3C controller blocking write.
This will write size
bytes of data from the buffer pointed to by data
. It will not return until either all of the data has been written, or the timeout has elapsed.
[in] | obj | The I3C object |
[in] | address | device address (7-bit) |
[in] | data | Pointer to the byte-array of data send to the target device |
[in] | size | i3c send data size |
[in] | timeout | timeout in milisecond, set this value to 0 if you want to wait forever |
cy_rslt_t cyhal_i3c_controller_read | ( | cyhal_i3c_t * | obj, |
uint16_t | address, | ||
uint8_t * | data, | ||
uint16_t | size, | ||
uint32_t | timeout | ||
) |
I3C controller blocking read.
This will read size
bytes of data into the buffer pointed to by data
. It will not return until either all of the data has been read, or the timeout has elapsed.
[in] | obj | The I3C object |
[in] | address | device address (7-bit) |
[out] | data | Pointer to the byte-array of data receive from the target device |
[in] | size | i3c receive data size |
[in] | timeout | timeout in milisecond, set this value to 0 if you want to wait forever |
cy_rslt_t cyhal_i3c_controller_mem_write | ( | cyhal_i3c_t * | obj, |
uint16_t | address, | ||
uint16_t | mem_addr, | ||
uint16_t | mem_addr_size, | ||
const uint8_t * | data, | ||
uint16_t | size, | ||
uint32_t | timeout | ||
) |
Perform an i3c write using a block of data stored at the specified memory location This function is blocking.
[in] | obj | The I3C object |
[in] | address | device address (7-bit) |
[in] | mem_addr | mem address to store the written data |
[in] | mem_addr_size | number of bytes in the mem address |
[in] | data | Pointer to the byte-array of data send to the target device |
[in] | size | i3c controller send data size |
[in] | timeout | timeout in milisecond, set this value to 0 if you want to wait forever |
cy_rslt_t cyhal_i3c_controller_mem_read | ( | cyhal_i3c_t * | obj, |
uint16_t | address, | ||
uint16_t | mem_addr, | ||
uint16_t | mem_addr_size, | ||
uint8_t * | data, | ||
uint16_t | size, | ||
uint32_t | timeout | ||
) |
Perform an i3c read using a block of data stored at the specified memory location This function is blocking.
[in] | obj | The I3C object |
[in] | address | device address (7-bit) |
[in] | mem_addr | mem address to store the written data |
[in] | mem_addr_size | number of bytes in the mem address |
[out] | data | Pointer to the byte-array of data receive from the target device |
[in] | size | i3c controller send data size |
[in] | timeout | timeout in milisecond, set this value to 0 if you want to wait forever |
cy_rslt_t cyhal_i3c_target_config_write_buffer | ( | cyhal_i3c_t * | obj, |
const uint8_t * | data, | ||
uint16_t | size | ||
) |
I3C target config write buffer The user needs to setup a new buffer every time (i.e.
call cyhal_i3c_target_config_write_buffer and cyhal_i3c_target_config_read_buffer every time the buffer has been used up) Note that after transaction completion the buffer must be configured again. Otherwise, the same buffer is used starting from the point where the controller stopped a previous transaction. For example: The read buffer is configured to be 10 bytes and the controller reads 8 bytes. If the read buffer is not configured again, the next controller read will start from the 9th byte.
[in] | obj | The I3C object |
[in] | data | Pointer to the byte-array of data send to the controller device |
[in] | size | i3c target send data size |
cy_rslt_t cyhal_i3c_target_config_read_buffer | ( | cyhal_i3c_t * | obj, |
uint8_t * | data, | ||
uint16_t | size | ||
) |
I3C target config read buffer The user needs to setup a new buffer every time (i.e.
call cyhal_i3c_target_config_write_buffer and cyhal_i3c_target_config_read_buffer every time the buffer has been used up) Note that after transaction completion the buffer must be configured again. Otherwise, the same buffer is used starting from the point where the controller stopped a previous transaction. For example: The read buffer is configured to be 10 bytes and the controller reads 8 bytes. If the read buffer is not configured again, the next controller read will start from the 9th byte.
[in] | obj | The I3C object |
[out] | data | Pointer to the byte-array of data receive from controller device |
[in] | size | i3c target receive data size |
void cyhal_i3c_register_callback | ( | cyhal_i3c_t * | obj, |
cyhal_i3c_event_callback_t | callback, | ||
void * | callback_arg | ||
) |
The I3C event callback handler registration.
[in] | obj | The I3C object |
[in] | callback | The callback handler which will be invoked when an event triggers |
[in] | callback_arg | Generic argument that will be provided to the callback when called |
void cyhal_i3c_register_ibi_callback | ( | cyhal_i3c_t * | obj, |
cyhal_i3c_ibi_callback_t | callback, | ||
void * | callback_arg | ||
) |
The I3C IBI callback handler registration.
[in] | obj | The I3C object |
[in] | callback | The callback handler which will be invoked when IBI event triggers |
[in] | callback_arg | Generic argument that will be provided to the callback when called |
void cyhal_i3c_enable_event | ( | cyhal_i3c_t * | obj, |
cyhal_i3c_event_t | event, | ||
uint8_t | intr_priority, | ||
bool | enable | ||
) |
Configure and Enable or Disable I3C Interrupt.
[in] | obj | The I3C object |
[in] | event | The I3C event type |
[in] | intr_priority | The priority for NVIC interrupt events |
[in] | enable | True to turn on interrupts, False to turn off |
void cyhal_i3c_enable_ibi_event | ( | cyhal_i3c_t * | obj, |
cyhal_i3c_ibi_event_t | event, | ||
uint8_t | intr_priority, | ||
bool | enable | ||
) |
Configure and Enable or Disable I3C Interrupt.
[in] | obj | The I3C object |
[in] | event | The I3C IBI type |
[in] | intr_priority | The priority for NVIC interrupt events |
[in] | enable | True to turn on interrupts, False to turn off |
cy_rslt_t cyhal_i3c_set_fifo_level | ( | cyhal_i3c_t * | obj, |
cyhal_i3c_fifo_type_t | type, | ||
uint16_t | level | ||
) |
Sets a threshold level for a FIFO that will generate an interrupt and a trigger output.
The RX FIFO interrupt and trigger will be activated when the receive FIFO has more entries than the threshold. The TX FIFO interrupt and trigger will be activated when the transmit FIFO has less entries than the threshold.
[in] | obj | The I3C object |
[in] | type | FIFO type to set level for |
[in] | level | Level threshold to set |
cy_rslt_t cyhal_i3c_enable_output | ( | cyhal_i3c_t * | obj, |
cyhal_i3c_output_t | output, | ||
cyhal_source_t * | source | ||
) |
Enables the specified output signal from an I3C.
[in] | obj | The I3C object |
[in] | output | Which output signal to enable |
[out] | source | Pointer to user-allocated source signal object which will be initialized by enable_output. source should be passed to (dis)connect_digital functions to (dis)connect the associated endpoints. |
cy_rslt_t cyhal_i3c_disable_output | ( | cyhal_i3c_t * | obj, |
cyhal_i3c_output_t | output | ||
) |
Disables the specified output signal from an I3C.
[in] | obj | The I3C object |
[in] | output | Which output signal to disable |
cy_rslt_t cyhal_i3c_init_cfg | ( | cyhal_i3c_t * | obj, |
const cyhal_i3c_configurator_t * | cfg | ||
) |
Initialize the I3C peripheral using a configurator generated configuration struct.
[in] | obj | The I3C peripheral to configure |
[in] | cfg | Configuration structure generated by a configurator. |
uint32_t cyhal_i3c_target_readable | ( | cyhal_i3c_t * | obj | ) |
Returns the number of bytes written by the I3C controller.
Calling the cyhal_i3c_target_config_write_buffer API will clear the counter of bytes sent by controller
[in] | obj | The I3C object |
uint32_t cyhal_i3c_target_writable | ( | cyhal_i3c_t * | obj | ) |
Returns the number of bytes can be read by the I3C controller.
Calling the cyhal_i3c_target_config_read_buffer API will clear the counter of bytes read by controller
[in] | obj | The I3C object |