MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Hal_i2c_driver

Overview

Data Structures

struct  hal_i2c_master_config_t
 HAL I2C master user configuration. More...
 
struct  hal_i2c_slave_config_t
 HAL I2C slave user configuration. More...
 
struct  hal_i2c_master_transfer_t
 HAL I2C master transfer structure. More...
 
struct  hal_i2c_slave_transfer_t
 HAL I2C slave transfer structure. More...
 

Macros

#define HAL_I2C_MASTER_HANDLE_SIZE   (80U)
 HAL I2C master handle size. More...
 
#define HAL_I2C_SLAVE_HANDLE_SIZE   (80U)
 HAL I2C slave handle size. More...
 
#define HAL_I2C_MASTER_HANDLE_DEFINE(name)   uint32_t name[(HAL_I2C_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
 Defines the I2C master handle. More...
 
#define HAL_I2C_SLAVE_HANDLE_DEFINE(name)   uint32_t name[(HAL_I2C_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
 Defines the I2C slave handle. More...
 

Typedefs

typedef void * hal_i2c_master_handle_t
 HAL I2C master handle. More...
 
typedef void * hal_i2c_slave_handle_t
 HAL I2C slave handle. More...
 
typedef void(* hal_i2c_master_transfer_callback_t )(hal_i2c_master_handle_t handle, hal_i2c_status_t completionStatus, void *callbackParam)
 Master completion callback function pointer type. More...
 
typedef void(* hal_i2c_slave_transfer_callback_t )(hal_i2c_slave_handle_t handle, hal_i2c_slave_transfer_t *transfer, void *callbackParam)
 Slave event callback function pointer type. More...
 

Enumerations

enum  hal_i2c_status_t {
  kStatus_HAL_I2cSuccess = kStatus_Success,
  kStatus_HAL_I2cError = MAKE_STATUS(kStatusGroup_HAL_I2C, 1),
  kStatus_HAL_I2cBusy = MAKE_STATUS(kStatusGroup_HAL_I2C, 2),
  kStatus_HAL_I2cIdle = MAKE_STATUS(kStatusGroup_HAL_I2C, 3),
  kStatus_HAL_I2cNak = MAKE_STATUS(kStatusGroup_HAL_I2C, 4),
  kStatus_HAL_I2cArbitrationLost = MAKE_STATUS(kStatusGroup_HAL_I2C, 5),
  kStatus_HAL_I2cTimeout = MAKE_STATUS(kStatusGroup_HAL_I2C, 6),
  kStatus_HAL_I2cAddrressNak = MAKE_STATUS(kStatusGroup_HAL_I2C, 7)
}
 HAL I2C status. More...
 
enum  hal_i2c_direction_t {
  kHAL_I2cWrite = 0U,
  kHAL_I2cRead = 1U
}
 Direction of master and slave transfers. More...
 
enum  hal_i2c_master_transfer_flag_t {
  kHAL_I2cTransferDefaultFlag = 0x0U,
  kHAL_I2cTransferNoStartFlag = 0x1U,
  kHAL_I2cTransferRepeatedStartFlag = 0x2U,
  kHAL_I2cTransferNoStopFlag = 0x4U
}
 I2C transfer control flag. More...
 
enum  hal_i2c_slave_transfer_event_t {
  kHAL_I2cSlaveAddressMatchEvent = 0x01U,
  kHAL_I2cSlaveTransmitEvent = 0x02U,
  kHAL_I2cSlaveReceiveEvent = 0x04U,
  kHAL_I2cSlaveTransmitAckEvent = 0x08U,
  kHAL_I2cSlaveCompletionEvent = 0x20U,
  kHAL_I2cSlaveStartEvent = 0x10U,
  kHAL_I2cSlaveGenaralcallEvent = 0x40U,
  kHAL_I2cSlaveAllEvents
}
 Set of events sent to the callback for nonblocking slave transfers. More...
 

Initialization and de-initialization

hal_i2c_status_t HAL_I2cMasterInit (hal_i2c_master_handle_t handle, const hal_i2c_master_config_t *config)
 Initializes the HAL I2C master peripheral. More...
 
hal_i2c_status_t HAL_I2cSlaveInit (hal_i2c_slave_handle_t handle, const hal_i2c_slave_config_t *config)
 Initializes the HAL I2C peripheral. More...
 
hal_i2c_status_t HAL_I2cMasterDeinit (hal_i2c_master_handle_t handle)
 De-initializes the HAL I2C master peripheral. More...
 
hal_i2c_status_t HAL_I2cSlaveDeinit (hal_i2c_slave_handle_t handle)
 De-initializes the HAL I2C slave peripheral. More...
 

Bus Operations

hal_i2c_status_t HAL_I2cMasterWriteBlocking (hal_i2c_master_handle_t handle, const uint8_t *txBuff, size_t txSize, uint32_t flags)
 Performs a polling send transaction on the HAL I2C bus. More...
 
hal_i2c_status_t HAL_I2cMasterReadBlocking (hal_i2c_master_handle_t handle, uint8_t *rxBuff, size_t rxSize, uint32_t flags)
 Performs a polling receive transaction on the HAL I2C bus. More...
 
hal_i2c_status_t HAL_I2cSlaveWriteBlocking (hal_i2c_slave_handle_t handle, const uint8_t *txBuff, size_t txSize)
 Performs a polling send transaction on the HAL I2C bus. More...
 
hal_i2c_status_t HAL_I2cSlaveReadBlocking (hal_i2c_slave_handle_t handle, uint8_t *rxBuff, size_t rxSize)
 Performs a polling receive transaction on the HAL I2C bus. More...
 
hal_i2c_status_t HAL_I2cMasterTransferBlocking (hal_i2c_master_handle_t handle, hal_i2c_master_transfer_t *xfer)
 Performs a master polling transfer on the HAL I2C bus. More...
 

Transactional

hal_i2c_status_t HAL_I2cMasterTransferInstallCallback (hal_i2c_master_handle_t handle, hal_i2c_master_transfer_callback_t callback, void *callbackParam)
 Installs a callback and callback parameter. More...
 
hal_i2c_status_t HAL_I2cMasterTransferNonBlocking (hal_i2c_master_handle_t handle, hal_i2c_master_transfer_t *xfer)
 Performs a master interrupt non-blocking transfer on the HAL I2C bus. More...
 
hal_i2c_status_t HAL_I2cMasterTransferGetCount (hal_i2c_master_handle_t handle, size_t *count)
 Gets the master transfer status during a interrupt non-blocking transfer. More...
 
hal_i2c_status_t HAL_I2cMasterTransferAbort (hal_i2c_master_handle_t handle)
 Aborts an interrupt non-blocking transfer early. More...
 
hal_i2c_status_t HAL_I2cSlaveTransferInstallCallback (hal_i2c_slave_handle_t handle, hal_i2c_slave_transfer_callback_t callback, void *callbackParam)
 Installs a callback and callback parameter. More...
 
hal_i2c_status_t HAL_I2cSlaveTransferNonBlocking (hal_i2c_slave_handle_t handle, uint32_t eventMask)
 Starts accepting slave transfers. More...
 
hal_i2c_status_t HAL_I2cSlaveTransferAbort (hal_i2c_slave_handle_t handle)
 Aborts the slave transfer. More...
 
hal_i2c_status_t HAL_I2cSlaveTransferGetCount (hal_i2c_slave_handle_t handle, size_t *count)
 Gets the slave transfer remaining bytes during a interrupt non-blocking transfer. More...
 

Data Structure Documentation

struct hal_i2c_master_config_t

Data Fields

uint32_t srcClock_Hz
 Clock source for I2C in Hz.
 
uint32_t baudRate_Bps
 Baud rate configuration of HAL I2C peripheral. More...
 
bool enableMaster
 Enables the HAL I2C peripheral at initialization time. More...
 
uint8_t instance
 Instance of the i2c.
 

Field Documentation

uint32_t hal_i2c_master_config_t::baudRate_Bps
bool hal_i2c_master_config_t::enableMaster
struct hal_i2c_slave_config_t

Data Fields

uint32_t srcClock_Hz
 Clock source for I2C in Hz.
 
uint16_t slaveAddress
 A slave address configuration. More...
 
bool enableSlave
 Enables the HAL I2C peripheral at initialization time. More...
 
uint8_t instance
 Instance of the i2c.
 

Field Documentation

uint16_t hal_i2c_slave_config_t::slaveAddress
bool hal_i2c_slave_config_t::enableSlave
struct hal_i2c_master_transfer_t

Data Fields

uint8_t *volatile data
 A transfer buffer. More...
 
volatile size_t dataSize
 A transfer size. More...
 
uint32_t flags
 A transfer flag which controls the transfer. More...
 
uint32_t subaddress
 A sub address. More...
 
uint8_t subaddressSize
 A size of the command buffer. More...
 
uint8_t slaveAddress
 7-bit slave address. More...
 
hal_i2c_direction_t direction
 A transfer direction, read or write. More...
 

Field Documentation

uint8_t* volatile hal_i2c_master_transfer_t::data
volatile size_t hal_i2c_master_transfer_t::dataSize
uint32_t hal_i2c_master_transfer_t::flags
uint32_t hal_i2c_master_transfer_t::subaddress

Transferred MSB first.

uint8_t hal_i2c_master_transfer_t::subaddressSize
uint8_t hal_i2c_master_transfer_t::slaveAddress
hal_i2c_direction_t hal_i2c_master_transfer_t::direction
struct hal_i2c_slave_transfer_t

Data Fields

hal_i2c_slave_transfer_event_t event
 A reason that the callback is invoked. More...
 
uint8_t *volatile data
 A transfer buffer. More...
 
volatile size_t dataSize
 A transfer size. More...
 
hal_i2c_status_t completionStatus
 Success or error code describing how the transfer completed. More...
 
size_t transferredCount
 A number of bytes actually transferred since the start or since the last repeated start. More...
 

Field Documentation

hal_i2c_slave_transfer_event_t hal_i2c_slave_transfer_t::event
uint8_t* volatile hal_i2c_slave_transfer_t::data
volatile size_t hal_i2c_slave_transfer_t::dataSize
hal_i2c_status_t hal_i2c_slave_transfer_t::completionStatus

Only applies for kHAL_I2cSlaveCompletionEvent.

size_t hal_i2c_slave_transfer_t::transferredCount

Macro Definition Documentation

#define HAL_I2C_MASTER_HANDLE_SIZE   (80U)
#define HAL_I2C_SLAVE_HANDLE_SIZE   (80U)
#define HAL_I2C_MASTER_HANDLE_DEFINE (   name)    uint32_t name[(HAL_I2C_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]

This macro is used to define a 4 byte aligned I2C master handle. Then use "(hal_i2c_master_handle_t)name" to get the I2C master handle.

The macro should be global and could be optional. You could also define I2C master handle by yourself.

This is an example,

* HAL_I2C_MASTER_HANDLE_DEFINE(i2cMasterHandle);
*
Parameters
nameThe name string of the I2C master handle.
#define HAL_I2C_SLAVE_HANDLE_DEFINE (   name)    uint32_t name[(HAL_I2C_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]

This macro is used to define a 4 byte aligned I2C slave handle. Then use "(hal_i2c_slave_handle_t)name" to get the I2C slave handle.

The macro should be global and could be optional. You could also define I2C slave handle by yourself.

This is an example,

* HAL_I2C_SLAVE_HANDLE_DEFINE(i2cSlaveHandle);
*
Parameters
nameThe name string of the I2C slave handle.

Typedef Documentation

typedef void* hal_i2c_master_handle_t
typedef void* hal_i2c_slave_handle_t
typedef void(* hal_i2c_master_transfer_callback_t)(hal_i2c_master_handle_t handle, hal_i2c_status_t completionStatus, void *callbackParam)

This callback is used only for the non-blocking master transfer API. Specify the callback you wish to use in the call to HAL_I2cMasterTransferInstallCallback().

Parameters
handlei2c master handle pointer, this should be a static variable.
completionStatusEither kStatus_HAL_I2cSuccess or an error code describing how the transfer completed.
callbackParamArbitrary pointer-sized value passed from the application.
typedef void(* hal_i2c_slave_transfer_callback_t)(hal_i2c_slave_handle_t handle, hal_i2c_slave_transfer_t *transfer, void *callbackParam)

This callback is used only for the slave non-blocking transfer API. Specify the callback you wish to use in the call to HAL_I2cSlaveTransferInstallCallback().

Parameters
handlei2c slave master handle pointer, this should be a static variable.
transferPointer to transfer descriptor containing values passed to and/or from the callback.
callbackParamArbitrary pointer-sized value passed from the application.

Enumeration Type Documentation

Enumerator
kStatus_HAL_I2cSuccess 

Successfully.

kStatus_HAL_I2cError 

Error occurs on HAL I2C.

kStatus_HAL_I2cBusy 

HAL I2C is busy with current transfer.

kStatus_HAL_I2cIdle 

HAL I2C transmitter is idle.

kStatus_HAL_I2cNak 

NAK received during transfer.

kStatus_HAL_I2cArbitrationLost 

Arbitration lost during transfer.

kStatus_HAL_I2cTimeout 

Timeout.

kStatus_HAL_I2cAddrressNak 

NAK received during the address probe.

Enumerator
kHAL_I2cWrite 

Master transmit.

kHAL_I2cRead 

Master receive.

Enumerator
kHAL_I2cTransferDefaultFlag 

A transfer starts with a start signal, stops with a stop signal.

kHAL_I2cTransferNoStartFlag 

A transfer starts without a start signal, only support write only or write+read with no start flag, do not support read only with no start flag.

kHAL_I2cTransferRepeatedStartFlag 

A transfer starts with a repeated start signal.

kHAL_I2cTransferNoStopFlag 

A transfer ends without a stop signal.

These event enumerations are used for two related purposes. First, a bit mask created by OR'ing together events is passed to I2C_SlaveTransferNonBlocking() to specify which events to enable. Then, when the slave callback is invoked, it is passed the current event through its transfer parameter.

Note
These enumerations are meant to be OR'd together to form a bit mask of events.
Enumerator
kHAL_I2cSlaveAddressMatchEvent 

Received the slave address after a start or repeated start.

kHAL_I2cSlaveTransmitEvent 

A callback is requested to provide data to transmit (slave-transmitter role).

kHAL_I2cSlaveReceiveEvent 

A callback is requested to provide a buffer in which to place received data (slave-receiver role).

kHAL_I2cSlaveTransmitAckEvent 

A callback needs to either transmit an ACK or NACK.

kHAL_I2cSlaveCompletionEvent 

A stop was detected or finished transfer, completing the transfer.

kHAL_I2cSlaveStartEvent 

A start/repeated start was detected.

kHAL_I2cSlaveGenaralcallEvent 

Received the general call address after a start or repeated start.

kHAL_I2cSlaveAllEvents 

A bit mask of all available events.

Function Documentation

hal_i2c_status_t HAL_I2cMasterInit ( hal_i2c_master_handle_t  handle,
const hal_i2c_master_config_t config 
)
Note
This API should be called at the beginning of the application. Otherwise, any operation to the HAL I2C module can cause a hard fault because the clock is not enabled. This function configures the i2c master with user-defined settings. The user can configure the configuration structure. The parameter handle is a pointer to point to a memory space of size HAL_I2C_MASTER_HANDLE_SIZE allocated by the caller.

Example below shows how to use this API to configure the I2C master.

* HAL_I2C_MASTER_HANDLE_DEFINE(i2cMasterHandle);
* hal_i2c_master_config_t masterConfig;
* masterConfig.enableMaster = true;
* masterConfig.baudRate_Bps = 100000U;
* masterConfig.srcClock_Hz = 12000000U;
* masterConfig.instance = 0;
* HAL_I2cMasterInit((hal_i2c_master_handle_t)i2cMasterHandle, &masterConfig);
*
Parameters
handlePointer to point to a memory space of size HAL_I2C_MASTER_HANDLE_SIZE allocated by the caller. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. You can define the handle in the following two ways: HAL_I2C_MASTER_HANDLE_DEFINE(handle); or uint32_t handle[((HAL_I2C_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
configA pointer to the master configuration structure
Return values
kStatus_HAL_I2cErrorAn error occurred.
kStatus_HAL_I2cSuccessi2c master initialization succeed
hal_i2c_status_t HAL_I2cSlaveInit ( hal_i2c_slave_handle_t  handle,
const hal_i2c_slave_config_t config 
)
Note
This API should be called at the beginning of the application. Otherwise, any operation to the HAL I2C module can cause a hard fault because the clock is not enabled. This function configures the i2c slave with user-defined settings. The user can configure the configuration structure. The parameter handle is a pointer to point to a memory space of size HAL_I2C_SLAVE_HANDLE_SIZE allocated by the caller.

Example below shows how to use this API to configure the I2C slave.

* HAL_I2C_SLAVE_HANDLE_DEFINE(i2cSlaveHandle);
* hal_i2c_slave_config_t slaveConfig;
* slaveConfig.enableSlave = true;
* slaveConfig.slaveAddress = 0x01U;
* slaveConfig.srcClock_Hz = 12000000U;
* slaveConfig.instance = 0;
* HAL_I2cSlaveInit((hal_i2c_slave_handle_t)i2cSlaveHandle, &slaveConfig);
*
Parameters
handlePointer to point to a memory space of size HAL_I2C_SLAVE_HANDLE_SIZE allocated by the caller. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. You can define the handle in the following two ways: HAL_I2C_SLAVE_HANDLE_DEFINE(handle); or uint32_t handle[((HAL_I2C_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
configA pointer to the slave configuration structure
Return values
kStatus_HAL_I2cErrorAn error occurred.
kStatus_HAL_I2cSuccessi2c slave initialization succeed
hal_i2c_status_t HAL_I2cMasterDeinit ( hal_i2c_master_handle_t  handle)

Call this API to gate the HAL I2C clock. The HAL I2C master module can't work unless the HAL_I2cMasterInit is called.

Parameters
handlei2c master handle pointer, this should be a static variable.
Return values
kStatus_HAL_I2cSuccessi2c master de-initialization succeed
hal_i2c_status_t HAL_I2cSlaveDeinit ( hal_i2c_slave_handle_t  handle)

Calling this API gates the HAL I2C clock. The HAL I2C slave module can't work unless the HAL_I2cSlaveInit is called to enable the clock.

Parameters
handlei2c slave handle pointer, this should be a static variable.
Return values
kStatus_HAL_I2cSuccessi2c slave de-initialization succeed
hal_i2c_status_t HAL_I2cMasterWriteBlocking ( hal_i2c_master_handle_t  handle,
const uint8_t *  txBuff,
size_t  txSize,
uint32_t  flags 
)
Parameters
handlei2c master handle pointer, this should be a static variable.
txBuffThe pointer to the data to be transferred.
txSizeThe length in bytes of the data to be transferred.
flagsTransfer control flag to decide whether need to send a stop, use kHAL_I2cTransferDefaultFlag to issue a stop and kHAL_I2cTransferNoStopFlag to not send a stop.
Return values
kStatus_HAL_I2cSuccessSuccessfully complete the data transmission.
kStatus_HAL_I2cArbitrationLostTransfer error, arbitration lost.
kStatus_HAL_I2cNakTransfer error, receive NAK during transfer.
hal_i2c_status_t HAL_I2cMasterReadBlocking ( hal_i2c_master_handle_t  handle,
uint8_t *  rxBuff,
size_t  rxSize,
uint32_t  flags 
)
Note
The HAL_I2cMasterReadBlocking function stops the bus before reading the final byte. Without stopping the bus prior for the final read, the bus issues another read, resulting in garbage data being read into the data register.
Parameters
handlei2c master handle pointer, this should be a static variable.
rxBuffThe pointer to the data to store the received data.
rxSizeThe length in bytes of the data to be received.
flagsTransfer control flag to decide whether need to send a stop, use kHAL_I2cTransferDefaultFlag to issue a stop and kHAL_I2cTransferNoStopFlag to not send a stop.
Return values
kStatus_HAL_I2cSuccessSuccessfully complete the data transmission.
kStatus_HAL_I2cTimeoutSend stop signal failed, timeout.
hal_i2c_status_t HAL_I2cSlaveWriteBlocking ( hal_i2c_slave_handle_t  handle,
const uint8_t *  txBuff,
size_t  txSize 
)
Parameters
handlei2c slave handle pointer, this should be a static variable.
txBuffThe pointer to the data to be transferred.
txSizeThe length in bytes of the data to be transferred.
Return values
kStatus_HAL_I2cSuccessSuccessfully complete the data transmission.
kStatus_HAL_I2cArbitrationLostTransfer error, arbitration lost.
kStatus_HAL_I2cNakTransfer error, receive NAK during transfer.
hal_i2c_status_t HAL_I2cSlaveReadBlocking ( hal_i2c_slave_handle_t  handle,
uint8_t *  rxBuff,
size_t  rxSize 
)
Parameters
handlei2c slave handle pointer, this should be a static variable.
rxBuffThe pointer to the data to store the received data.
rxSizeThe length in bytes of the data to be received.
Return values
kStatus_HAL_I2cSuccessSuccessfully complete data receive.
kStatus_HAL_I2cTimeoutWait status flag timeout.
hal_i2c_status_t HAL_I2cMasterTransferBlocking ( hal_i2c_master_handle_t  handle,
hal_i2c_master_transfer_t xfer 
)
Note
The API does not return until the transfer succeeds or fails due to arbitration lost or receiving a NAK.
Parameters
handlei2c master handle pointer, this should be a static variable.
xferPointer to the transfer structure.
Return values
kStatus_HAL_I2cSuccessSuccessfully complete the data transmission.
kStatus_HAL_I2cBusyPrevious transmission still not finished.
kStatus_HAL_I2cTimeoutTransfer error, wait signal timeout.
kStatus_HAL_I2cArbitrationLostTransfer error, arbitration lost.
kStatus_HAL_I2cNakTransfer error, receive NAK during transfer.
hal_i2c_status_t HAL_I2cMasterTransferInstallCallback ( hal_i2c_master_handle_t  handle,
hal_i2c_master_transfer_callback_t  callback,
void *  callbackParam 
)

This function is used to install the callback and callback parameter for i2c master module. When any status of the i2c master changed, the driver will notify the upper layer by the installed callback function. And the status is also passed as status parameter when the callback is called.

Parameters
handlei2c master handle pointer, this should be a static variable.
callbackpointer to user callback function.
callbackParamuser parameter passed to the callback function.
Return values
kStatus_HAL_I2cSuccessi2c master handle created
hal_i2c_status_t HAL_I2cMasterTransferNonBlocking ( hal_i2c_master_handle_t  handle,
hal_i2c_master_transfer_t xfer 
)
Note
Calling the API returns immediately after transfer initiates. The user needs to call HAL_I2cMasterGetTransferCount to poll the transfer status to check whether the transfer is finished. If the return status is not kStatus_HAL_I2cBusy, the transfer is finished.
Parameters
handlei2c master handle pointer, this should be a static variable.
xferpointer to hal_i2c_master_transfer_t structure.
Return values
kStatus_HAL_I2cSuccessSuccessfully start the data transmission.
kStatus_HAL_I2cBusyPrevious transmission still not finished.
kStatus_HAL_I2cTimeoutTransfer error, wait signal timeout.
hal_i2c_status_t HAL_I2cMasterTransferGetCount ( hal_i2c_master_handle_t  handle,
size_t *  count 
)
Parameters
handlei2c master handle pointer, this should be a static variable.
countNumber of bytes transferred so far by the non-blocking transaction.
Return values
kStatus_HAL_I2cErrorAn error occurred.
kStatus_HAL_I2cSuccessSuccessfully return the count.
hal_i2c_status_t HAL_I2cMasterTransferAbort ( hal_i2c_master_handle_t  handle)
Note
This API can be called at any time when an interrupt non-blocking transfer initiates to abort the transfer early.
Parameters
handlei2c master handle pointer, this should be a static variable.
Return values
kStatus_HAL_I2cTimeoutTimeout during polling flag.
kStatus_HAL_I2cSuccessSuccessfully abort the transfer.
hal_i2c_status_t HAL_I2cSlaveTransferInstallCallback ( hal_i2c_slave_handle_t  handle,
hal_i2c_slave_transfer_callback_t  callback,
void *  callbackParam 
)

This function is used to install the callback and callback parameter for i2c slave module. When any status of the i2c slave changed, the driver will notify the upper layer by the installed callback function. And the status is also passed as status parameter when the callback is called.

Parameters
handlei2c slave handle pointer, this should be a static variable.
callbackpointer to user callback function.
callbackParamuser parameter passed to the callback function.
Return values
kStatus_HAL_I2cSuccessi2c slave handle created
hal_i2c_status_t HAL_I2cSlaveTransferNonBlocking ( hal_i2c_slave_handle_t  handle,
uint32_t  eventMask 
)

Call this API after calling the HAL_I2cSlaveInit() and HAL_I2cSlaveTransferInstallCallback() to start processing transactions driven by an HAL I2C slave. The slave monitors the HAL I2C bus and passes events to the callback that was passed into the call to HAL_I2cSlaveTransferInstallCallback(). The callback is always invoked from the interrupt context.

The set of events received by the callback is customizable. To do so, set the eventMask parameter to the OR'd combination of hal_i2c_slave_transfer_event_t enumerators for the events you wish to receive. The kHAL_I2cSlaveTransmitEvent and #kLPHAL_I2cSlaveReceiveEvent events are always enabled and do not need to be included in the mask. Alternatively, pass 0 to get a default set of only the transmit and receive events that are always enabled. In addition, the kHAL_I2cSlaveAllEvents constant is provided as a convenient way to enable all events.

Parameters
handlei2c slave handle pointer, this should be a static variable.
eventMaskBit mask formed by OR'ing together hal_i2c_slave_transfer_event_t enumerators to specify which events to send to the callback. Other accepted values are 0 to get a default set of only the transmit and receive events, and kHAL_I2cSlaveAllEvents to enable all events.
Return values
kStatus_HAL_I2cSuccessSlave transfers were successfully started.
kStatus_HAL_I2cBusySlave transfers have already been started on this handle.
hal_i2c_status_t HAL_I2cSlaveTransferAbort ( hal_i2c_slave_handle_t  handle)
Note
This API can be called at any time to stop slave for handling the bus events.
Parameters
handlei2c slave handle pointer, this should be a static variable.
Return values
kStatus_HAL_I2cSuccessSuccessfully return the count.
hal_i2c_status_t HAL_I2cSlaveTransferGetCount ( hal_i2c_slave_handle_t  handle,
size_t *  count 
)
Parameters
handlei2c slave handle pointer, this should be a static variable.
countNumber of bytes transferred so far by the non-blocking transaction.
Return values
kStatus_HAL_I2cErrorAn error occurred.
kStatus_HAL_I2cSuccessSuccessfully return the count.