I2C HAL API
Module: HAL (AM13E230X) API
Structures
Name |
|
|---|---|
struct |
I2c_Hal_ControllerInitParamsType |
struct |
I2c_Hal_ControllerInstanceType |
struct |
I2c_Hal_ControllerTransactionType |
struct |
I2c_Hal_TargetTransactionType |
struct |
I2c_Hal_TargetInitParamsType |
struct |
I2c_Hal_TargetInstanceType |
struct |
I2c_Hal_TransactionStatusType |
Types
Name |
|
|---|---|
enum |
I2c_Hal_StateType { I2C_HAL_STATE_UNCONFIGURED = 0U, I2C_HAL_STATE_READY = 1U, I2C_HAL_STATE_RX = 2U, I2C_HAL_STATE_TX = 3U, I2C_HAL_STATE_TRANSFER = 4U} |
enum |
I2c_Hal_SpeedType { I2C_HAL_SPEED_STANDARD = 0U, I2C_HAL_SPEED_FAST = 1U, I2C_HAL_SPEED_FAST_PLUS = 2U} |
enum |
I2c_Hal_AddressingModeType { I2C_HAL_ADDRESSING_MODE_7BIT, I2C_HAL_ADDRESSING_MODE_10BIT} |
enum |
I2c_Hal_OperatingModeType { I2C_HAL_OPERATING_MODE_NONE, I2C_HAL_OPERATING_MODE_TRANSMIT, I2C_HAL_OPERATING_MODE_RECEIVE} |
enum |
I2c_Hal_TargetCompleteEventType { I2C_HAL_TARGET_COMPLETE_EVENT_STOP = 0U, I2C_HAL_TARGET_COMPLETE_EVENT_RX_OVERFLOW, I2C_HAL_TARGET_COMPLETE_EVENT_TX_UNDERFLOW} |
Functions
Name |
|
|---|---|
I2c_Hal_ControllerInitParamsSetDefault(I2c_Hal_ControllerInitParamsType * paramsPtr) |
|
I2c_Hal_TargetInitParamsSetDefault(I2c_Hal_TargetInitParamsType * paramsPtr) |
|
I2c_Hal_ControllerInit(I2c_Hal_ControllerInstanceType * controllerInstancePtr, const I2c_Hal_ControllerInitParamsType * paramsPtr) |
|
I2c_Hal_ControllerTransferPolling(I2c_Hal_ControllerInstanceType * controllerInstancePtr, const I2c_Hal_ControllerTransactionType * controllerTransactionPtr) |
|
I2c_Hal_ControllerTransferInterrupt(I2c_Hal_ControllerInstanceType * controllerInstancePtr, const I2c_Hal_ControllerTransactionType * controllerTransactionPtr) |
|
I2c_Hal_ControllerTransferContinuePolling(I2c_Hal_ControllerInstanceType * controllerInstancePtr, I2c_Hal_TransactionStatusType * transferStatusPtr) |
|
I2c_Hal_GetControllerCurrentState(const I2c_Hal_ControllerInstanceType * controllerInstancePtr, I2c_Hal_StateType * statePtr) |
|
void |
I2c_Hal_ControllerTransferCompleteCallback(I2c_Hal_ControllerInstanceType * controllerInstancePtr, I2c_Hal_TransactionStatusType * transferStatusPtr, void * userArgsPtr) |
void |
I2c_Hal_ControllerErrorCallback(I2c_Hal_ControllerInstanceType * controllerInstancePtr, I2c_Hal_TransactionStatusType * transferStatusPtr, void * userArgsPtr) |
void |
I2c_Hal_ControllerInterruptHandler(I2c_Hal_ControllerInstanceType * controllerInstancePtr) |
I2c_Hal_ControllerDeInit(I2c_Hal_ControllerInstanceType * controllerInstancePtr) |
|
I2c_Hal_ControllerTransferAbort(I2c_Hal_ControllerInstanceType * targetInstancePtr, uint32 timeoutCount, I2c_Hal_TransactionStatusType * transferStatusPtr) |
|
I2c_Hal_TargetInit(I2c_Hal_TargetInstanceType * targetInstancePtr, const I2c_Hal_TargetInitParamsType * paramsPtr) |
|
I2c_Hal_GetTargetCurrentState(const I2c_Hal_TargetInstanceType * targetInstancePtr, I2c_Hal_StateType * statePtr) |
|
I2c_Hal_TargetSubmitTxBuffer(I2c_Hal_TargetInstanceType * targetInstancePtr, const uint8 * bufferPtr, uint32 sizeInBytes) |
|
I2c_Hal_TargetSubmitRxBuffer(I2c_Hal_TargetInstanceType * targetInstancePtr, uint8 * bufferPtr, uint32 sizeInBytes) |
|
I2c_Hal_TargetTransferStart(I2c_Hal_TargetInstanceType * targetInstancePtr, I2c_Hal_TargetTransactionType * targetTransactionPtr) |
|
I2c_Hal_TargetTransferStop(I2c_Hal_TargetInstanceType * targetInstancePtr) |
|
void |
I2c_Hal_TargetInterruptHandler(I2c_Hal_TargetInstanceType * targetInstancePtr) |
I2c_Hal_TargetDeInit(I2c_Hal_TargetInstanceType * targetInstancePtr) |
|
I2c_Hal_TargetTransferAbort(I2c_Hal_TargetInstanceType * targetInstancePtr, I2c_Hal_TransactionStatusType * transferStatusPtr) |
|
void |
I2c_Hal_TargetRxStartCallback(I2c_Hal_TargetInstanceType * targetInstancePtr, void * userArgsPtr) |
void |
I2c_Hal_TargetRxCompleteCallback(I2c_Hal_TargetInstanceType * targetInstancePtr, uint8 * rxBufferPtr, uint32 rxSizeBytes, I2c_Hal_TargetCompleteEventType event, void * userArgsPtr) |
void |
I2c_Hal_TargetTxStartCallback(I2c_Hal_TargetInstanceType * targetInstancePtr, void * userArgsPtr) |
void |
I2c_Hal_TargetTxCompleteCallback(I2c_Hal_TargetInstanceType * targetInstancePtr, const uint8 * txBufferPtr, uint32 txSizeBytes, I2c_Hal_TargetCompleteEventType event, void * userArgsPtr) |
void |
I2c_Hal_TargetErrorCallback(I2c_Hal_TargetInstanceType * targetInstancePtr, uint32 errorCodeMask, void * userArgsPtr) |
Defines
Detailed Description
Note: All transfer APIs are non-blocking unless specified otherwise, i.e they dont wait for the RX/TX operation to complete.
For a given I2C instance, the APIs to use depends on the operation mode - controller or target that is needed. Only APIs valid in a operation mode should be used by the application, else behavior is undefined.
I2C transfer APIs can be used in below operation modes
Polling mode
APIs to use for controller data transfer I2c_Hal_ControllerTransferPolling.
Polling mode is not supported, when I2C is operating as a Target
APIs to use to check for transfer completion,
I2c_Hal_ControllerTransferContinuePolling is called to wait for the transaction to complete
I2c_Hal_ControllerInterruptHandler must not be registered to CPU interrupt line
I2c_Hal_ControllerTransferCompleteCallback and, I2c_Hal_ControllerErrorCallback are not called in this mode
Interrupt mode
APIs to use for data transfer I2c_Hal_ControllerTransferInterrupt, I2c_Hal_TargetTransferStart
I2c_Hal_ControllerTransferCompleteCallback, I2c_Hal_TargetTxCompleteCallback or I2c_Hal_TargetRxCompleteCallback is called when the transfer completes
I2c_Hal_ControllerErrorCallback, I2c_Hal_TargetErrorCallback are called in case of any error during transfer
I2c_Hal_ControllerInterruptHandler or I2c_Hal_TargetInterruptHandler must be called as part of the ISR registered to CPU interrupt line
I2c_Hal_ControllerTransferContinuePolling should NOT be used
Types Documentation
enum I2c_Hal_StateType
Enumerator |
Value |
Description |
|---|---|---|
I2C_HAL_STATE_UNCONFIGURED |
0U |
Instance not initialized or disabled |
I2C_HAL_STATE_READY |
1U |
Instance initialized and ready for use |
I2C_HAL_STATE_RX |
2U |
I2C instance is receiving data |
I2C_HAL_STATE_TX |
3U |
I2C instance is transmitting data |
I2C_HAL_STATE_TRANSFER |
4U |
I2C instance is performing some transfer |
I2C instance states.
enum I2c_Hal_SpeedType
Enumerator |
Value |
Description |
|---|---|---|
I2C_HAL_SPEED_STANDARD |
0U |
Standard mode (100 kHz) |
I2C_HAL_SPEED_FAST |
1U |
Fast mode (400 kHz) |
I2C_HAL_SPEED_FAST_PLUS |
2U |
Fast mode plus (1 MHz) |
I2C speed modes.
enum I2c_Hal_AddressingModeType
Enumerator |
Value |
Description |
|---|---|---|
I2C_HAL_ADDRESSING_MODE_7BIT |
7-bit addressing mode |
|
I2C_HAL_ADDRESSING_MODE_10BIT |
10-bit addressing mode |
I2C addressing modes.
enum I2c_Hal_OperatingModeType
Enumerator |
Value |
Description |
|---|---|---|
I2C_HAL_OPERATING_MODE_NONE |
I2C Operating Mode is not set yet |
|
I2C_HAL_OPERATING_MODE_TRANSMIT |
I2C Transmit Mode |
|
I2C_HAL_OPERATING_MODE_RECEIVE |
I2C Receive Mode |
I2C Operational Modes.
enum I2c_Hal_TargetCompleteEventType
Enumerator |
Value |
Description |
|---|---|---|
I2C_HAL_TARGET_COMPLETE_EVENT_STOP |
0U |
Completion due to STOP condition detected |
I2C_HAL_TARGET_COMPLETE_EVENT_RX_OVERFLOW |
Completion due to RX overflow (buffer full) |
|
I2C_HAL_TARGET_COMPLETE_EVENT_TX_UNDERFLOW |
Completion due to TX underflow (buffer empty) |
I2C Target completion event types.
Functions Documentation
function I2c_Hal_ControllerInitParamsSetDefault
sint32 I2c_Hal_ControllerInitParamsSetDefault(
I2c_Hal_ControllerInitParamsType * paramsPtr
)
Initializes the I2C Controller Parameters with default values.
Parameters:
paramsPtr Pointer to controller initialization parameters
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
function I2c_Hal_TargetInitParamsSetDefault
sint32 I2c_Hal_TargetInitParamsSetDefault(
I2c_Hal_TargetInitParamsType * paramsPtr
)
Initializes the I2C Target Parameters with default values.
Parameters:
paramsPtr Pointer to target initialization parameters
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
function I2c_Hal_ControllerInit
sint32 I2c_Hal_ControllerInit(
I2c_Hal_ControllerInstanceType * controllerInstancePtr,
const I2c_Hal_ControllerInitParamsType * paramsPtr
)
Initializes the I2C controller hardware.
Parameters:
controllerInstancePtr Pointer to the controller instance
paramsPtr Pointer to controller initialization parameters
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
This function initializes the I2C controller mode hardware instance with the provided configuration parameters. The function configures clock settings, operating parameters, and prepares the hardware for data transfer operations.
function I2c_Hal_ControllerTransferPolling
sint32 I2c_Hal_ControllerTransferPolling(
I2c_Hal_ControllerInstanceType * controllerInstancePtr,
const I2c_Hal_ControllerTransactionType * controllerTransactionPtr
)
Performs a transfer operation in controller mode using polling.
Parameters:
controllerInstancePtr Pointer to the controller instance (must be initialized)
controllerTransactionPtr Pointer to transaction parameters (address, buffer, size, options)
Return: I2C_HAL_ERROR_NONE if operation completed successfully, otherwise an appropriate error code
This function executes a transfer operation to an I2C target device in controller mode using polling. Depending on the transfer options, it can perform:
Writing data to the target
Reading data from the target
Combining write and read operations
The function:
Generates START condition
Transmits target address
Performs data transfer (TX and/or RX)
Optionally generates STOP condition
For multi-byte transfers, call I2c_Hal_ControllerTransferContinuePolling repeatedly until transfer is complete.
function I2c_Hal_ControllerTransferInterrupt
sint32 I2c_Hal_ControllerTransferInterrupt(
I2c_Hal_ControllerInstanceType * controllerInstancePtr,
const I2c_Hal_ControllerTransactionType * controllerTransactionPtr
)
Initiates a transfer operation in controller mode using interrupts.
Parameters:
controllerInstancePtr Pointer to the controller instance
controllerTransactionPtr Pointer to transaction parameters
Return: I2C_HAL_ERROR_NONE if operation initiated successfully, otherwise an appropriate error code
This function initiates an asynchronous transfer operation to an I2C target device in controller mode. Depending on the transfer options, it can perform:
Writing data to the target
Reading data from the target
Combining write and read operations
The function configures the controller to:
Generate START condition
Transmit target address
Perform data transfer (TX and/or RX)
Optionally generate STOP condition
The function returns immediately, and the transfer is handled asynchronously through interrupts. When the transfer is complete, the configured callback function will be invoked.
See also I2c_Hal_ControllerTransferCompleteCallback, I2c_Hal_ControllerErrorCallback
function I2c_Hal_ControllerTransferContinuePolling
sint32 I2c_Hal_ControllerTransferContinuePolling(
I2c_Hal_ControllerInstanceType * controllerInstancePtr,
I2c_Hal_TransactionStatusType * transferStatusPtr
)
Continue I2C Controller transfer in polling mode.
Parameters:
controllerInstancePtr Pointer to the controller instance
transferStatusPtr Pointer to transfer status structure
Return: I2C_HAL_ERROR_NONE if operation completed successfully, otherwise an appropriate error code
This function continues an ongoing controller transfer operation by checking hardware interrupt status flags and performing the appropriate actions. Call this function repeatedly in a loop after I2c_Hal_ControllerTransferPolling until the transfer is complete.
function I2c_Hal_GetControllerCurrentState
sint32 I2c_Hal_GetControllerCurrentState(
const I2c_Hal_ControllerInstanceType * controllerInstancePtr,
I2c_Hal_StateType * statePtr
)
Get I2C Controller Current State.
Parameters:
controllerInstancePtr Pointer to the controller instance
statePtr Pointer to store the current state
Return: I2C_HAL_ERROR_NONE if successful, otherwise an appropriate error code
This function returns the current state of the controller state machine.
function I2c_Hal_ControllerTransferCompleteCallback
void I2c_Hal_ControllerTransferCompleteCallback(
I2c_Hal_ControllerInstanceType * controllerInstancePtr,
I2c_Hal_TransactionStatusType * transferStatusPtr,
void * userArgsPtr
)
I2C Controller transfer complete callback (interrupt mode only)
Parameters:
controllerInstancePtr Pointer to the controller instance
transferStatusPtr Transfer status with completion details
userArgsPtr User-defined argument pointer
Note: This callback must be implemented by the application, otherwise a linker error will occur.
This callback is invoked by I2c_Hal_ControllerInterruptHandler when a transfer completes successfully in interrupt mode. The callback is called when:
All data has been transmitted/received
STOP condition has been detected
function I2c_Hal_ControllerErrorCallback
void I2c_Hal_ControllerErrorCallback(
I2c_Hal_ControllerInstanceType * controllerInstancePtr,
I2c_Hal_TransactionStatusType * transferStatusPtr,
void * userArgsPtr
)
I2C Controller error callback (interrupt mode only)
Parameters:
controllerInstancePtr Pointer to the controller instance
transferStatusPtr Transfer status with error details
userArgsPtr User-defined argument pointer (from init params)
Note: This callback must be implemented by the application, otherwise a linker error will occur.
This callback is invoked by I2c_Hal_ControllerInterruptHandler when an error occurs during a transfer in interrupt mode. Error code bits can be checked using [I2c_Hal_TransferErrorType] masks. Multiple error bits may be set simultaneously.
function I2c_Hal_ControllerInterruptHandler
void I2c_Hal_ControllerInterruptHandler(
I2c_Hal_ControllerInstanceType * controllerInstancePtr
)
I2C Controller interrupt handler.
Parameters:
controllerInstancePtr Pointer to the controller instance
Interrupt handler. Needs to be called from the ISR registered in the device’s interrupt controller Application must register an ISR against the appropriate CPU interrupt number after I2c_Hal_ControllerInit
In controller mode, if controller is initialized in polling mode, then interrupt handler should not be registered.
The interrupt handler will call one of below callbacks, depending on the conditions detected within the interrupt handler. The interrupt handler will also clear status and interrupt bits as needed for correct operation.
In each of the callbacks, user arguments passed during initialization are passed back to the user. The callbacks need to be implemented by the application else there will be a linker error.
The supported callbacks are,
function I2c_Hal_ControllerDeInit
sint32 I2c_Hal_ControllerDeInit(
I2c_Hal_ControllerInstanceType * controllerInstancePtr
)
De-initializes an I2C controller instance.
Parameters:
controllerInstancePtr Pointer to the I2C HAL Controller instance
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
This function disables the I2C controller hardware and releases any resources associated with it. After this call, the I2C controller hardware will be in a reset state and must be re-initialized before being used again.
function I2c_Hal_ControllerTransferAbort
sint32 I2c_Hal_ControllerTransferAbort(
I2c_Hal_ControllerInstanceType * targetInstancePtr,
uint32 timeoutCount,
I2c_Hal_TransactionStatusType * transferStatusPtr
)
Aborts an ongoing Controller transaction.
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
function I2c_Hal_TargetInit
sint32 I2c_Hal_TargetInit(
I2c_Hal_TargetInstanceType * targetInstancePtr,
const I2c_Hal_TargetInitParamsType * paramsPtr
)
Initializes the I2C target hardware.
Parameters:
targetInstancePtr Pointer to the target instance
paramsPtr Pointer to target initialization parameters
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
This function initializes the I2C target mode hardware instance with the provided configuration parameters. The function sets up the target address, clock settings, and prepares the hardware to respond to controller requests.
function I2c_Hal_GetTargetCurrentState
sint32 I2c_Hal_GetTargetCurrentState(
const I2c_Hal_TargetInstanceType * targetInstancePtr,
I2c_Hal_StateType * statePtr
)
Get I2C Target Current State.
Parameters:
targetInstancePtr Pointer to the target instance
statePtr Pointer to store the current state
Return: I2C_HAL_ERROR_NONE if operation completed successfully, otherwise an appropriate error code
function I2c_Hal_TargetSubmitTxBuffer
sint32 I2c_Hal_TargetSubmitTxBuffer(
I2c_Hal_TargetInstanceType * targetInstancePtr,
const uint8 * bufferPtr,
uint32 sizeInBytes
)
Setup the Target transmit buffer.
Parameters:
targetInstancePtr Pointer to the I2C target instance
bufferPtr Pointer to the transmit data buffer
sizeInBytes Size of the transmit buffer in bytes
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
Note: If controller requests more bytes than available in buffer and no new buffer is provided, dummy 0x00 bytes will be transmitted and I2c_Hal_TargetErrorCallback() will be called
This function configures the transmit buffer for the I2C target. The target will use this buffer to send data when the controller performs a read operation. This function should be called:
Within I2c_Hal_TargetTxCompleteCallback() to provide additional data when buffer is exhausted
To update TX buffer between transactions
function I2c_Hal_TargetSubmitRxBuffer
sint32 I2c_Hal_TargetSubmitRxBuffer(
I2c_Hal_TargetInstanceType * targetInstancePtr,
uint8 * bufferPtr,
uint32 sizeInBytes
)
Setup the Target receive buffer.
Parameters:
targetInstancePtr Pointer to the I2C target instance
bufferPtr Pointer to the receive data buffer
sizeInBytes Size of the receive buffer in bytes
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
Note: If controller sends more bytes than buffer can hold and no additional buffer is provided, excess data will be discarded and I2c_Hal_TargetErrorCallback() will be called with RX_OVERFLOW error.
This function configures the receive buffer for the I2C target. The target will use this buffer to store data when the controller performs a write operation. This function should be called:
Before calling I2c_Hal_TargetTransferStart() to prepare initial RX buffer
Within I2c_Hal_TargetRxCompleteCallback() to provide additional buffer when previous buffer is full
function I2c_Hal_TargetTransferStart
sint32 I2c_Hal_TargetTransferStart(
I2c_Hal_TargetInstanceType * targetInstancePtr,
I2c_Hal_TargetTransactionType * targetTransactionPtr
)
Setup the Target.
Parameters:
targetInstancePtr Pointer to the target instance
targetTransactionPtr Pointer to the target transaction parameters
Returns:
I2C_HAL_ERROR_HW_BUSY if the target instance is not in READY state
Return: I2C_HAL_ERROR_NONE if operation completed successfully, otherwise an appropriate error code
This function enables interrupts making the Target ready to respond to any Controller request. The application must select the transfer direction by setting either:
I2C_HAL_TARGET_TRANSFER_OPTION_TX for transmit (target sends data to controller)
I2C_HAL_TARGET_TRANSFER_OPTION_RX for receive (target receives data from controller) The default behavior (if neither option is specified) is to not participate in data transfer.
function I2c_Hal_TargetTransferStop
sint32 I2c_Hal_TargetTransferStop(
I2c_Hal_TargetInstanceType * targetInstancePtr
)
Stop the Target transfer.
Parameters:
targetInstancePtr Pointer to the I2C target instance
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
This function disables all the enabled interrupts and puts the state to ready.
function I2c_Hal_TargetInterruptHandler
void I2c_Hal_TargetInterruptHandler(
I2c_Hal_TargetInstanceType * targetInstancePtr
)
I2C Target interrupt handler.
Parameters:
targetInstancePtr Pointer to the target instance
Note: The target hardware disables the interrupt lines internally when the ISR is invoked. The interrupt handler must clear the interrupt status before returning.
Interrupt handler. Needs to be called from the ISR registered in the device’s interrupt controller Application must register an ISR against the appropriate CPU interrupt number after I2c_Hal_TargetInit This function must be called as part of the ISR with the right params
In target mode, interrupt handler must always be registered.
The interrupt handler will call one of below callbacks, depending on the conditions detected within the interrupt handler. The interrupt handler will also clear status and interrupt bits as needed for correct operation.
In each of the callbacks, user arguments passed during initialization are passed back to the user.
The Supported callbacks are,
function I2c_Hal_TargetDeInit
sint32 I2c_Hal_TargetDeInit(
I2c_Hal_TargetInstanceType * targetInstancePtr
)
De-initializes an I2C target instance.
Parameters:
targetInstancePtr Pointer to the target instance
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
This function disables the I2C target hardware and releases any resources associated with it. After this call, the I2C target hardware will be in a reset state and must be re-initialized before being used again.
function I2c_Hal_TargetTransferAbort
sint32 I2c_Hal_TargetTransferAbort(
I2c_Hal_TargetInstanceType * targetInstancePtr,
I2c_Hal_TransactionStatusType * transferStatusPtr
)
Aborts an ongoing Target transaction.
Parameters:
targetInstancePtr Pointer to the target instance
transferStatusPtr Pointer to transfer status structure
Return: I2C_HAL_ERROR_NONE if successful, otherwise an error code
This API aborts an ongoing transaction by disabling all the enabled interrupts, flushing TX and RX FIFO, reseting the fields in the handle and setting the state to ready state.
The status of the current transfer is populated in transferStatusPtr.
NOTE: no completion callbacks are called and remaining bytes is sum of TX and RX remaining bytes.
function I2c_Hal_TargetRxStartCallback
void I2c_Hal_TargetRxStartCallback(
I2c_Hal_TargetInstanceType * targetInstancePtr,
void * userArgsPtr
)
I2C Target RX start callback.
Parameters:
targetInstancePtr Pointer to the I2C target instance
userArgsPtr User-provided argument pointer
Note: These callbacks must be implemented by the application. Weak implementations are provided to avoid linker errors.
This function is called when target RX operation starts (controller writing to target). Called on first RX_FULL interrupt after STOP condition. Application can prepare for incoming data if needed.
function I2c_Hal_TargetRxCompleteCallback
void I2c_Hal_TargetRxCompleteCallback(
I2c_Hal_TargetInstanceType * targetInstancePtr,
uint8 * rxBufferPtr,
uint32 rxSizeBytes,
I2c_Hal_TargetCompleteEventType event,
void * userArgsPtr
)
I2C Target RX complete callback.
Parameters:
targetInstancePtr Pointer to the I2C target instance
rxBufferPtr Pointer to RX data buffer containing received data
rxSizeBytes Number of bytes actually received
event Completion event type (see I2c_Hal_TargetCompleteEventType)
userArgsPtr User-provided argument pointer
This function is called when target RX operation completes. Called in two scenarios:
On STOP condition - RX transfer completed normally (event = I2C_HAL_TARGET_COMPLETE_EVENT_STOP) This event can also occur as a consequence of a Repeat Start condition when the direction changes.
On RX buffer overflow - all bytes received, buffer full (event = I2C_HAL_TARGET_COMPLETE_EVENT_RX_OVERFLOW)
Application should process received data and optionally call I2c_Hal_TargetSubmitRxBuffer() to provide new buffer for continued reception.
function I2c_Hal_TargetTxStartCallback
void I2c_Hal_TargetTxStartCallback(
I2c_Hal_TargetInstanceType * targetInstancePtr,
void * userArgsPtr
)
I2C Target TX start callback.
Parameters:
targetInstancePtr Pointer to the I2C target instance
userArgsPtr User-provided argument pointer
This function is called when target TX operation is about to start. Application can use this callback to prepare for transmitting data.
function I2c_Hal_TargetTxCompleteCallback
void I2c_Hal_TargetTxCompleteCallback(
I2c_Hal_TargetInstanceType * targetInstancePtr,
const uint8 * txBufferPtr,
uint32 txSizeBytes,
I2c_Hal_TargetCompleteEventType event,
void * userArgsPtr
)
I2C Target TX complete callback.
Parameters:
targetInstancePtr Pointer to the I2C target instance
txBufferPtr Pointer to TX data buffer that was transmitted
txSizeBytes Number of bytes actually transmitted
event Completion event type (see I2c_Hal_TargetCompleteEventType)
userArgsPtr User-provided argument pointer
This function is called when target TX operation completes. Called in two scenarios:
On STOP condition - TX transfer completed normally (event = I2C_HAL_TARGET_COMPLETE_EVENT_STOP)
On TX buffer underflow - controller requests more data but TX FIFO is empty and no new buffer has been provided (event = I2C_HAL_TARGET_COMPLETE_EVENT_TX_UNDERFLOW) In this case, 0x00 bytes are transmitted until a new buffer is submitted or STOP is received.
Application can process completion, reuse TX buffer, and optionally call I2c_Hal_TargetSubmitTxBuffer() to provide new buffer for continued transmission.
function I2c_Hal_TargetErrorCallback
void I2c_Hal_TargetErrorCallback(
I2c_Hal_TargetInstanceType * targetInstancePtr,
uint32 errorCodeMask,
void * userArgsPtr
)
I2C Target error callback.
Parameters:
targetInstancePtr Pointer to the I2C target instance
errorCodeMask Error code bitmask (see [I2c_Hal_TransferErrorType])
userArgsPtr User-provided argument pointer
This function is called when an error occurs during target operation. When this callback is invoked:
No completion callbacks (TX or RX) are issued for the aborted transfer
Both TX and RX FIFOs are flushed
The remainingSizeBytes parameter in the transfer status gives the combined TX + RX count of bytes that were not transferred
Macros Documentation
define I2C_HAL_ERROR_NONE
#define I2C_HAL_ERROR_NONE (0)
No error.
define I2C_HAL_ERROR_INVALID_INSTANCE
#define I2C_HAL_ERROR_INVALID_INSTANCE (1)
Invalid instance pointer.
define I2C_HAL_ERROR_INVALID_PARAMS
#define I2C_HAL_ERROR_INVALID_PARAMS (2)
Invalid parameters.
define I2C_HAL_ERROR_UNSUPPORTED_FEATURE
#define I2C_HAL_ERROR_UNSUPPORTED_FEATURE (3)
Unsupported Feature (e.g., target API in controller mode)
define I2C_HAL_ERROR_HW_BUSY
#define I2C_HAL_ERROR_HW_BUSY (4)
HW Busy Error.
define I2C_HAL_ERROR_TRANSFER
#define I2C_HAL_ERROR_TRANSFER (5)
API Transfer Error.
define I2C_HAL_TRANSFER_ERROR_NONE
#define I2C_HAL_TRANSFER_ERROR_NONE (0x00000000U)
No error during transfer.
define I2C_HAL_TRANSFER_ERROR_CONTROLLER_TIMEOUT
#define I2C_HAL_TRANSFER_ERROR_CONTROLLER_TIMEOUT (0x00000001U)
Controller operation timed out.
define I2C_HAL_TRANSFER_ERROR_CLOCK_LOW_TIMEOUT
#define I2C_HAL_TRANSFER_ERROR_CLOCK_LOW_TIMEOUT (0x00000002U)
Serial Clock Low Timeout Error.
define I2C_HAL_TRANSFER_ERROR_ABORT
#define I2C_HAL_TRANSFER_ERROR_ABORT (0x00000004U)
Transfer Abort/ Terminate Error.
define I2C_HAL_TRANSFER_ERROR_TARGET_RXFIFO_OVERFLOW
#define I2C_HAL_TRANSFER_ERROR_TARGET_RXFIFO_OVERFLOW (0x00000008U)
Target Receive FIFO Overflow Error.
define I2C_HAL_TRANSFER_ERROR_CONTROLLER_NACK_DATA
#define I2C_HAL_TRANSFER_ERROR_CONTROLLER_NACK_DATA (0x00000010U)
Target NACKed the data from controller.
define I2C_HAL_TRANSFER_ERROR_CONTROLLER_NACK_ADDR
#define I2C_HAL_TRANSFER_ERROR_CONTROLLER_NACK_ADDR (0x00000020U)
Target NACKed the address from controller.
define I2C_HAL_TRANSFER_ERROR_CONTROLLER_ARB_LOST
#define I2C_HAL_TRANSFER_ERROR_CONTROLLER_ARB_LOST (0x00000040U)
Controller lost arbitration in multi-master mode.
define I2C_HAL_TRANSFER_ERROR_BUS_BUSY
#define I2C_HAL_TRANSFER_ERROR_BUS_BUSY (0x00000080U)
Bus is busy, cannot initiate transfer.
define I2C_HAL_TRANSFER_ERROR_TARGET_NACK
#define I2C_HAL_TRANSFER_ERROR_TARGET_NACK (0x00000100U)
Target NACK Error.
define I2C_HAL_TRANSFER_ERROR_BUS_ERROR
#define I2C_HAL_TRANSFER_ERROR_BUS_ERROR (0x00000200U)
Bus Error.
define I2C_HAL_TRANSFER_ERROR_TARGET_TXFIFO_UNDERFLOW
#define I2C_HAL_TRANSFER_ERROR_TARGET_TXFIFO_UNDERFLOW (0x00000400U)
Target Transmit FIFO Underflow Error.
define I2C_HAL_TRANSFER_ERROR_TARGET_NO_RX_BUFFER
#define I2C_HAL_TRANSFER_ERROR_TARGET_NO_RX_BUFFER (0x00000800U)
Target has no RX buffer to store received data.
define I2C_HAL_TRANSFER_ERROR_TARGET_NO_TX_BUFFER
#define I2C_HAL_TRANSFER_ERROR_TARGET_NO_TX_BUFFER (0x00001000U)
Target has no TX buffer to transmit data.
define I2C_HAL_TRANSFER_ERROR_UNSPECIFIED
#define I2C_HAL_TRANSFER_ERROR_UNSPECIFIED (0x08000000U)
Unspecified error.
define I2C_HAL_TRANSFER_OPTION_NONE
#define I2C_HAL_TRANSFER_OPTION_NONE (0x00000000U)
None specified.
define I2C_HAL_TRANSFER_OPTION_START_ENABLE
#define I2C_HAL_TRANSFER_OPTION_START_ENABLE (0x00000001U)
Enable START condition.
define I2C_HAL_TRANSFER_OPTION_STOP_ENABLE
#define I2C_HAL_TRANSFER_OPTION_STOP_ENABLE (0x00000002U)
Enable STOP condition.
define I2C_HAL_TRANSFER_OPTION_WRITE
#define I2C_HAL_TRANSFER_OPTION_WRITE (0x00000004U)
Write operation.
define I2C_HAL_TRANSFER_OPTION_READ
#define I2C_HAL_TRANSFER_OPTION_READ (0x00000008U)
Read operation.
define I2C_HAL_TRANSFER_OPTION_CLOCK_STRETCH_ENABLE
#define I2C_HAL_TRANSFER_OPTION_CLOCK_STRETCH_ENABLE (0x00000010U)
Enable clock stretching.
define I2C_HAL_TRANSFER_OPTION_PEC_ENABLE
#define I2C_HAL_TRANSFER_OPTION_PEC_ENABLE (0x00000020U)
Enable Packet Error Checking (PEC)
define I2C_HAL_TARGET_TRANSFER_OPTION_TX
#define I2C_HAL_TARGET_TRANSFER_OPTION_TX (0x00000040U)
Transmit operation.
define I2C_HAL_TARGET_TRANSFER_OPTION_RX
#define I2C_HAL_TARGET_TRANSFER_OPTION_RX (0x00000080U)
Receive operation.
define I2C_HAL_SCL_LOW_PERIOD
#define I2C_HAL_SCL_LOW_PERIOD (6U)
SCL low period in I2C clock cycles.
define I2C_HAL_SCL_HIGH_PERIOD
#define I2C_HAL_SCL_HIGH_PERIOD (4U)
SCL high period in I2C clock cycles.
define I2C_HAL_TRANSFER_OPTION_CONTROLLER_TX_DEFAULT
#define I2C_HAL_TRANSFER_OPTION_CONTROLLER_TX_DEFAULT (I2C_HAL_TRANSFER_OPTION_START_ENABLE | I2C_HAL_TRANSFER_OPTION_STOP_ENABLE | I2C_HAL_TRANSFER_OPTION_WRITE)
Controller transmit transfer options.
define I2C_HAL_TRANSFER_OPTION_CONTROLLER_RX_DEFAULT
#define I2C_HAL_TRANSFER_OPTION_CONTROLLER_RX_DEFAULT (I2C_HAL_TRANSFER_OPTION_START_ENABLE | I2C_HAL_TRANSFER_OPTION_STOP_ENABLE | I2C_HAL_TRANSFER_OPTION_READ)
Controller receive transfer options.
define I2C_HAL_TRANSFER_OPTION_TARGET_TX_DEFAULT
#define I2C_HAL_TRANSFER_OPTION_TARGET_TX_DEFAULT (I2C_HAL_TARGET_TRANSFER_OPTION_TX)
Target transmit transfer options.
define I2C_HAL_TRANSFER_OPTION_TARGET_RX_DEFAULT
#define I2C_HAL_TRANSFER_OPTION_TARGET_RX_DEFAULT (I2C_HAL_TARGET_TRANSFER_OPTION_RX)
Target receive transfer options.