MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
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... | |
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... | |
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. | |
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. | |
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... | |
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... | |
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 |
#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,
name | The 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,
name | The name string of the I2C slave handle. |
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().
handle | i2c master handle pointer, this should be a static variable. |
completionStatus | Either kStatus_HAL_I2cSuccess or an error code describing how the transfer completed. |
callbackParam | Arbitrary 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().
handle | i2c slave master handle pointer, this should be a static variable. |
transfer | Pointer to transfer descriptor containing values passed to and/or from the callback. |
callbackParam | Arbitrary pointer-sized value passed from the application. |
enum hal_i2c_status_t |
enum hal_i2c_direction_t |
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.
hal_i2c_status_t HAL_I2cMasterInit | ( | hal_i2c_master_handle_t | handle, |
const hal_i2c_master_config_t * | config | ||
) |
Example below shows how to use this API to configure the I2C master.
handle | Pointer 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))]; |
config | A pointer to the master configuration structure |
kStatus_HAL_I2cError | An error occurred. |
kStatus_HAL_I2cSuccess | i2c master initialization succeed |
hal_i2c_status_t HAL_I2cSlaveInit | ( | hal_i2c_slave_handle_t | handle, |
const hal_i2c_slave_config_t * | config | ||
) |
Example below shows how to use this API to configure the I2C slave.
handle | Pointer 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))]; |
config | A pointer to the slave configuration structure |
kStatus_HAL_I2cError | An error occurred. |
kStatus_HAL_I2cSuccess | i2c 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.
handle | i2c master handle pointer, this should be a static variable. |
kStatus_HAL_I2cSuccess | i2c 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.
handle | i2c slave handle pointer, this should be a static variable. |
kStatus_HAL_I2cSuccess | i2c 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 | ||
) |
handle | i2c master handle pointer, this should be a static variable. |
txBuff | The pointer to the data to be transferred. |
txSize | The length in bytes of the data to be transferred. |
flags | Transfer 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. |
kStatus_HAL_I2cSuccess | Successfully complete the data transmission. |
kStatus_HAL_I2cArbitrationLost | Transfer error, arbitration lost. |
kStatus_HAL_I2cNak | Transfer 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 | ||
) |
handle | i2c master handle pointer, this should be a static variable. |
rxBuff | The pointer to the data to store the received data. |
rxSize | The length in bytes of the data to be received. |
flags | Transfer 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. |
kStatus_HAL_I2cSuccess | Successfully complete the data transmission. |
kStatus_HAL_I2cTimeout | Send stop signal failed, timeout. |
hal_i2c_status_t HAL_I2cSlaveWriteBlocking | ( | hal_i2c_slave_handle_t | handle, |
const uint8_t * | txBuff, | ||
size_t | txSize | ||
) |
handle | i2c slave handle pointer, this should be a static variable. |
txBuff | The pointer to the data to be transferred. |
txSize | The length in bytes of the data to be transferred. |
kStatus_HAL_I2cSuccess | Successfully complete the data transmission. |
kStatus_HAL_I2cArbitrationLost | Transfer error, arbitration lost. |
kStatus_HAL_I2cNak | Transfer error, receive NAK during transfer. |
hal_i2c_status_t HAL_I2cSlaveReadBlocking | ( | hal_i2c_slave_handle_t | handle, |
uint8_t * | rxBuff, | ||
size_t | rxSize | ||
) |
handle | i2c slave handle pointer, this should be a static variable. |
rxBuff | The pointer to the data to store the received data. |
rxSize | The length in bytes of the data to be received. |
kStatus_HAL_I2cSuccess | Successfully complete data receive. |
kStatus_HAL_I2cTimeout | Wait status flag timeout. |
hal_i2c_status_t HAL_I2cMasterTransferBlocking | ( | hal_i2c_master_handle_t | handle, |
hal_i2c_master_transfer_t * | xfer | ||
) |
handle | i2c master handle pointer, this should be a static variable. |
xfer | Pointer to the transfer structure. |
kStatus_HAL_I2cSuccess | Successfully complete the data transmission. |
kStatus_HAL_I2cBusy | Previous transmission still not finished. |
kStatus_HAL_I2cTimeout | Transfer error, wait signal timeout. |
kStatus_HAL_I2cArbitrationLost | Transfer error, arbitration lost. |
kStatus_HAL_I2cNak | Transfer 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.
handle | i2c master handle pointer, this should be a static variable. |
callback | pointer to user callback function. |
callbackParam | user parameter passed to the callback function. |
kStatus_HAL_I2cSuccess | i2c master handle created |
hal_i2c_status_t HAL_I2cMasterTransferNonBlocking | ( | hal_i2c_master_handle_t | handle, |
hal_i2c_master_transfer_t * | xfer | ||
) |
handle | i2c master handle pointer, this should be a static variable. |
xfer | pointer to hal_i2c_master_transfer_t structure. |
kStatus_HAL_I2cSuccess | Successfully start the data transmission. |
kStatus_HAL_I2cBusy | Previous transmission still not finished. |
kStatus_HAL_I2cTimeout | Transfer error, wait signal timeout. |
hal_i2c_status_t HAL_I2cMasterTransferGetCount | ( | hal_i2c_master_handle_t | handle, |
size_t * | count | ||
) |
handle | i2c master handle pointer, this should be a static variable. |
count | Number of bytes transferred so far by the non-blocking transaction. |
kStatus_HAL_I2cError | An error occurred. |
kStatus_HAL_I2cSuccess | Successfully return the count. |
hal_i2c_status_t HAL_I2cMasterTransferAbort | ( | hal_i2c_master_handle_t | handle | ) |
handle | i2c master handle pointer, this should be a static variable. |
kStatus_HAL_I2cTimeout | Timeout during polling flag. |
kStatus_HAL_I2cSuccess | Successfully 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.
handle | i2c slave handle pointer, this should be a static variable. |
callback | pointer to user callback function. |
callbackParam | user parameter passed to the callback function. |
kStatus_HAL_I2cSuccess | i2c 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.
handle | i2c slave handle pointer, this should be a static variable. |
eventMask | Bit 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. |
kStatus_HAL_I2cSuccess | Slave transfers were successfully started. |
kStatus_HAL_I2cBusy | Slave transfers have already been started on this handle. |
hal_i2c_status_t HAL_I2cSlaveTransferAbort | ( | hal_i2c_slave_handle_t | handle | ) |
handle | i2c slave handle pointer, this should be a static variable. |
kStatus_HAL_I2cSuccess | Successfully return the count. |
hal_i2c_status_t HAL_I2cSlaveTransferGetCount | ( | hal_i2c_slave_handle_t | handle, |
size_t * | count | ||
) |
handle | i2c slave handle pointer, this should be a static variable. |
count | Number of bytes transferred so far by the non-blocking transaction. |
kStatus_HAL_I2cError | An error occurred. |
kStatus_HAL_I2cSuccess | Successfully return the count. |