Classes | |
struct | _hal_i2c_master_config |
HAL I2C master user configuration. More... | |
struct | _hal_i2c_master_transfer |
HAL I2C master transfer structure. More... | |
struct | _hal_i2c_slave_config |
HAL I2C slave user configuration. More... | |
struct | _hal_i2c_slave_transfer |
HAL I2C slave transfer structure. More... | |
Macros | |
#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_MASTER_HANDLE_SIZE (80U) |
HAL I2C master handle size. 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... | |
#define | HAL_I2C_SLAVE_HANDLE_SIZE (88U) |
HAL I2C slave handle size. More... | |
Typedefs | |
typedef enum _hal_i2c_direction | hal_i2c_direction_t |
Direction of master and slave transfers. More... | |
typedef struct _hal_i2c_master_config | hal_i2c_master_config_t |
HAL I2C master user configuration. More... | |
typedef void * | hal_i2c_master_handle_t |
HAL I2C master 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 enum _hal_i2c_master_transfer_flag | hal_i2c_master_transfer_flag_t |
I2C transfer control flag. More... | |
typedef struct _hal_i2c_master_transfer | hal_i2c_master_transfer_t |
HAL I2C master transfer structure. More... | |
typedef struct _hal_i2c_slave_config | hal_i2c_slave_config_t |
HAL I2C slave user configuration. More... | |
typedef void * | hal_i2c_slave_handle_t |
HAL I2C slave handle. 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... | |
typedef enum _hal_i2c_slave_transfer_event | hal_i2c_slave_transfer_event_t |
Set of events sent to the callback for nonblocking slave transfers. More... | |
typedef struct _hal_i2c_slave_transfer | hal_i2c_slave_transfer_t |
HAL I2C slave transfer structure. More... | |
typedef enum _hal_i2c_status | hal_i2c_status_t |
HAL I2C status. 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. Call this API to gate the HAL I2C clock. The HAL I2C master module can't work unless the HAL_I2cMasterInit is called. More... | |
hal_i2c_status_t | HAL_I2cSlaveDeinit (hal_i2c_slave_handle_t handle) |
De-initializes the HAL I2C slave peripheral. 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. 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... | |
#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.
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_MASTER_HANDLE_SIZE (80U) |
#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.
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. |
#define HAL_I2C_SLAVE_HANDLE_SIZE (88U) |
typedef enum _hal_i2c_direction hal_i2c_direction_t |
Direction of master and slave transfers.
typedef struct _hal_i2c_master_config hal_i2c_master_config_t |
HAL I2C master user configuration.
typedef void* hal_i2c_master_handle_t |
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.
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. |
I2C transfer control flag.
typedef struct _hal_i2c_master_transfer hal_i2c_master_transfer_t |
HAL I2C master transfer structure.
typedef struct _hal_i2c_slave_config hal_i2c_slave_config_t |
HAL I2C slave user configuration.
typedef void* hal_i2c_slave_handle_t |
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.
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. |
Set of events sent to the callback for nonblocking slave transfers.
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.
typedef struct _hal_i2c_slave_transfer hal_i2c_slave_transfer_t |
HAL I2C slave transfer structure.
typedef enum _hal_i2c_status hal_i2c_status_t |
HAL I2C status.
enum _hal_i2c_direction |
I2C transfer control flag.
Set of events sent to the callback for nonblocking slave transfers.
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.
enum _hal_i2c_status |
HAL I2C status.
hal_i2c_status_t HAL_I2cMasterDeinit | ( | hal_i2c_master_handle_t | handle | ) |
De-initializes the HAL I2C master peripheral. 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 |
Definition at line 171 of file lpi2c_adapter.c.
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.
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 |
Definition at line 129 of file lpi2c_adapter.c.
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.
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. |
Definition at line 205 of file lpi2c_adapter.c.
hal_i2c_status_t HAL_I2cMasterTransferAbort | ( | hal_i2c_master_handle_t | handle | ) |
Aborts an interrupt non-blocking transfer early.
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. |
Definition at line 295 of file lpi2c_adapter.c.
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.
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. |
Definition at line 223 of file lpi2c_adapter.c.
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.
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. |
Definition at line 283 of file lpi2c_adapter.c.
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.
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 |
Definition at line 244 of file lpi2c_adapter.c.
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.
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. |
Definition at line 262 of file lpi2c_adapter.c.
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.
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. |
Definition at line 197 of file lpi2c_adapter.c.
hal_i2c_status_t HAL_I2cSlaveDeinit | ( | hal_i2c_slave_handle_t | handle | ) |
De-initializes the HAL I2C slave peripheral. 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 |
Definition at line 184 of file lpi2c_adapter.c.
hal_i2c_status_t HAL_I2cSlaveInit | ( | hal_i2c_slave_handle_t | handle, |
const hal_i2c_slave_config_t * | config | ||
) |
Initializes the HAL I2C peripheral.
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 |
Definition at line 150 of file lpi2c_adapter.c.
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.
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. |
Definition at line 218 of file lpi2c_adapter.c.
hal_i2c_status_t HAL_I2cSlaveTransferAbort | ( | hal_i2c_slave_handle_t | handle | ) |
Aborts the slave transfer.
handle | i2c slave handle pointer, this should be a static variable. |
kStatus_HAL_I2cSuccess | Successfully return the count. |
Definition at line 337 of file lpi2c_adapter.c.
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.
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. |
Definition at line 350 of file lpi2c_adapter.c.
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.
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 |
Definition at line 307 of file lpi2c_adapter.c.
hal_i2c_status_t HAL_I2cSlaveTransferNonBlocking | ( | hal_i2c_slave_handle_t | handle, |
uint32_t | eventMask | ||
) |
Starts accepting slave transfers.
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 kHAL_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. |
Definition at line 325 of file lpi2c_adapter.c.
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.
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. |
Definition at line 213 of file lpi2c_adapter.c.