General functions for I2C driver. More...
General functions for I2C driver.
| INIT_CODE i2c_status_en i2c_init | ( | i2c_instance_en | id | ) |
Initialize the I²C peripheral for the given instance. Must be called before any other I²C driver functions. Reset block to default state and enables clock to I²C peripheral registers interface.
| id | I²C Instance ID. |
| INIT_CODE i2c_status_en i2c_deinit | ( | i2c_instance_en | id | ) |
Reset context structure and hardware registers to default state, disable interrupts, disable the I²C peripheral, and disable clock to I²C peripheral registers interface.
| id | I²C Instance ID. |
| i2c_status_en i2c_controller_set_config | ( | i2c_instance_en | id, |
| i2c_controller_config_t * | cfg ) |
Configure the I²C peripheral for controller mode, formerly known as "master" mode. This includes configuring the following parameters:
| id | I²C instance identifier. |
| cfg | Pointer to configuration struct. |
| i2c_status_en i2c_controller_get_config | ( | i2c_instance_en | id, |
| i2c_controller_config_t * | cfg ) |
Retrieve the current configuration of the I²C peripheral configured in controller mode.
| id | I²C instance identifier. |
| cfg | Pointer to structure to receive current configuration. |
| i2c_status_en i2c_controller_set_target_address | ( | i2c_instance_en | id, |
| uint32_t | address ) |
In Controller mode set the 7 or 10-bit address of the Target device. Must be called while the block is disabled.
| id | I²C Instance ID. |
| address | 7- or 10-bit target address. |
| i2c_status_en i2c_controller_get_target_address | ( | i2c_instance_en | id, |
| uint32_t * | tar_addr ) |
Get the 7- or 10-bit Target address currently configured in Controller mode. Must be called while the block is disabled.
| id | I²C Instance ID. |
| tar_addr | Pointer to a variable that receives the current Target address. |
| i2c_status_en i2c_enable | ( | i2c_instance_en | id | ) |
Enable the I²C peripheral. After enabling, configuration cannot be changed, nor can the target address be changed until the block is disabled again.
| id | I²C Instance ID. |
| i2c_status_en i2c_disable | ( | i2c_instance_en | id | ) |
Disable the I²C peripheral. Masks and clears all interrupts.
| id | I²C Instance ID. |
| i2c_status_en i2c_register_callback | ( | i2c_instance_en | id, |
| i2c_event_cb_t | cb, | ||
| void * | user_data ) |
Register a callback. A majority of I²C block logic is handled in the driver ISR. This callback will be called on various events such as:
| id | I²C Instance ID. |
| cb | User callback function. |
| i2c_status_en i2c_controller_write_blocking | ( | i2c_instance_en | id, |
| i2c_blocking_config_t * | xfer ) |
Perform a blocking write as controller to the target with the address set in Setting Target Address. This function blocks until:
If this transfer should not end with a STOP condition, set xfer.send_stop to false. This will force the next transfer to use a RESTART condition instead of a Start.
| id | I²C Instance ID. |
| xfer | Blocking transfer configuration. |
| i2c_status_en i2c_controller_read_blocking | ( | i2c_instance_en | id, |
| i2c_blocking_config_t * | xfer ) |
Perform a blocking read as controller to the target with the address set in Setting Target Address.
This function blocks until:
If this transfer should not end with a STOP condition, set xfer.send_stop to false. This will force the next transfer to use a RESTART condition instead of a Start.
| id | I²C Instance ID. |
| xfer | Blocking transfer configuration. |
| i2c_status_en i2c_controller_write_non_blocking | ( | i2c_instance_en | id, |
| i2c_nonblocking_config_t * | xfer ) |
Start a non-blocking write as controller to the target with the address set in Setting Target Address. This function loads the TX FIFO with data and configures the the I²C interrupts to handle the rest of the transfer in the driver ISR.
The callback set in i2c_register_callback will be called when:
| id | I²C Instance ID. |
| xfer | Non-blocking transfer configuration. |
| i2c_status_en i2c_controller_read_non_blocking | ( | i2c_instance_en | id, |
| i2c_nonblocking_config_t * | xfer ) |
Start a non-blocking read as controller to the target with the address set in Setting Target Address. This function configures the I²C interrupts to handle the transfer in the driver ISR.
The callback set in i2c_register_callback will be called when:
| id | I²C Instance ID. |
| xfer | Non-blocking transfer configuration. |
| i2c_status_en i2c_controller_abort | ( | i2c_instance_en | id | ) |
Abort an ongoing controller transfer. Issues STOP and clears FIFOs.
| id | I²C Instance ID. |
| i2c_status_en i2c_controller_get_transfer_count | ( | i2c_instance_en | id, |
| uint32_t * | count ) |
Returns the number of bytes transferred since last call to a non-blocking read or write function.
| id | I²C Instance ID. |
| count | Pointer to a variable where the function will store the number of bytes transferred since the last non-blocking operation |
| i2c_transfer_status_en i2c_controller_get_transfer_status | ( | i2c_instance_en | id | ) |
Returns the status of the ongoing non-blocking read or write transfer.
| id | I²C Instance ID. |
| i2c_status_en i2c_target_set_config | ( | i2c_instance_en | id, |
| i2c_target_config_t * | cfg ) |
Configure the I²C peripheral for target mode, formerly known as "slave" mode. This includes configuring the following parameters:
| id | I²C instance identifier. |
| cfg | Pointer to configuration struct. |
| i2c_status_en i2c_target_get_config | ( | i2c_instance_en | id, |
| i2c_target_config_t * | cfg ) |
Retrieve the current configuration of the I²C peripheral configured in target mode.
| id | I²C Instance ID. |
| cfg | Pointer to structure to receive current configuration. |
| i2c_status_en i2c_target_get_transfer_count | ( | i2c_instance_en | id, |
| uint32_t * | count ) |
Returns the number of bytes transferred since last call to a non-blocking read or write funciton.
| id | I²C Instance ID. |
| count | Pointer to a variable where the function will store the number of bytes transferred since the last non-blocking operation. |
| i2c_status_en i2c_target_abort | ( | i2c_instance_en | id | ) |
Abort an ongoing target transfer. Issues STOP and clears FIFOs.
| id | I²C Instance ID. |
| i2c_transfer_status_en i2c_target_get_transfer_status | ( | i2c_instance_en | id | ) |
Get the status of an ongoing non-blocking I2C transfer.
| id | I2C instance identifier (e.g., I2CS) |
| i2c_status_en i2c_target_prep_controller_write | ( | i2c_instance_en | id, |
| uint8_t * | buf, | ||
| uint32_t | size ) |
Prepare target to receive a write from controller. If there is already data in the RX FIFO, it will first load that data into the provided buffer. The rest of the data will be received in the driver ISR.
| id | I²C Instance ID. |
| buf | Buffer for incoming data. |
| size | Number of bytes expected. |
| i2c_status_en i2c_target_prep_controller_read | ( | i2c_instance_en | id, |
| uint8_t * | buf, | ||
| uint32_t | size ) |
Prepare target to send data to the controller, by writing data to the TX FIFO, and configuring interrupts to load more data if required. This could be called after a read request from the controller.
| id | I²C Instance ID. |
| buf | Data to send. |
| size | Number of bytes to send. |
| i2c_status_en i2c_s_get_standard_speed_high_low_count | ( | i2c_instance_en | id, |
| uint32_t * | ss_low_count, | ||
| uint32_t * | ss_high_count ) |
Retrieves the Standard-mode SCL low and high counts from the I²C registers.
| id | I²C Instance ID. |
| ss_low_count | Pointer to a variable that will receive the Standard-mode SCL low count value. |
| ss_high_count | Pointer to a variable that will receive the Standard-mode SCL high count value. |
| i2c_status_en i2c_s_get_fast_speed_high_low_count | ( | i2c_instance_en | id, |
| uint32_t * | fs_low_count, | ||
| uint32_t * | fs_high_count ) |
Retrieves the Fast-mode SCL low and high counts from the I²C registers.
| id | I²C Instance ID. |
| fs_low_count | Pointer to a variable that will receive the Fast-mode SCL low count value. |
| fs_high_count | Pointer to a variable that will receive the Fast-mode SCL high count value. |
| i2c_status_en i2c_s_get_sda_hold_config | ( | i2c_instance_en | id, |
| uint32_t * | sda_hold_time_rx, | ||
| uint32_t * | sda_hold_time_tx ) |
Retrieves the SDA RX and TX hold times from the I²C registers.
| id | I²C Instance ID. |
| sda_hold_time_rx | Pointer to a variable that will receive the SDA RX hold time value. |
| sda_hold_time_tx | Pointer to a variable that will receive the SDA TX hold time value. |
| i2c_status_en i2c_s_set_standard_speed_high_low_count | ( | i2c_instance_en | id, |
| uint32_t | ss_low_count, | ||
| uint32_t | ss_high_count ) |
Sets the I²C Standard-mode SCL low and high counts to the specified values.
| id | I²C Instance ID. |
| ss_low_count | Standard-mode SCL low count value to program. |
| ss_high_count | Standard-mode SCL high count value to program. |
| i2c_status_en i2c_s_set_fast_speed_high_low_count | ( | i2c_instance_en | id, |
| uint32_t | fs_low_count, | ||
| uint32_t | fs_high_count ) |
Sets the I²C Fast-mode SCL low and high counts to the specified values.
| id | I²C Instance ID. |
| fs_low_count | Fast-mode SCL low count value to program. |
| fs_high_count | Fast-mode SCL high count value to program. |
| i2c_status_en i2c_s_set_sda_hold_config | ( | i2c_instance_en | id, |
| uint32_t | sda_hold_time_rx, | ||
| uint32_t | sda_hold_time_tx ) |
Sets the I²C SDA RX and TX hold times to the specified values.
| id | I²C Instance ID. |
| sda_hold_time_rx | SDA RX hold time value to program. |
| sda_hold_time_tx | SDA TX hold time value to program. |