MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
Data Structures | |
struct | hal_spi_master_config_t |
spi master user configure structure. More... | |
struct | hal_spi_slave_config_t |
spi slave user configure structure. More... | |
struct | hal_spi_transfer_t |
spi transfer structure More... | |
Macros | |
#define | HAL_SPI_MASTER_HANDLE_SIZE (68U) |
spi master handle size. More... | |
#define | HAL_SPI_SLAVE_HANDLE_SIZE (68U) |
spi slave handle size. More... | |
#define | HAL_SPI_MASTER_HANDLE_DEFINE(name) uint32_t name[(HAL_SPI_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] |
Defines the SPI master handle. More... | |
#define | HAL_SPI_SLAVE_HANDLE_DEFINE(name) uint32_t name[(HAL_SPI_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] |
Defines the SPI slave handle. More... | |
Typedefs | |
typedef void * | hal_spi_master_handle_t |
spi master handle. More... | |
typedef void * | hal_spi_slave_handle_t |
spi slave handle. More... | |
typedef void(* | hal_spi_master_transfer_callback_t )(hal_spi_master_handle_t handle, hal_spi_status_t status, void *callbackParam) |
spi master callback for finished transmit | |
typedef void(* | hal_spi_slave_transfer_callback_t )(hal_spi_slave_handle_t handle, hal_spi_status_t status, void *callbackParam) |
spi slave callback for finished transmit | |
Enumerations | |
enum | hal_spi_status_t { kStatus_HAL_SpiSuccess = kStatus_Success, kStatus_HAL_SpiError = MAKE_STATUS(kStatusGroup_HAL_SPI, 1), kStatus_HAL_SpiBusy = MAKE_STATUS(kStatusGroup_HAL_SPI, 2), kStatus_HAL_SpiIdle = MAKE_STATUS(kStatusGroup_HAL_SPI, 3) } |
Return status for the spi driver. More... | |
enum | hal_spi_clock_polarity_t { kHAL_SpiClockPolarityActiveHigh = 0x0U, kHAL_SpiClockPolarityActiveLow } |
spi clock polarity configuration. More... | |
enum | hal_spi_clock_phase_t { kHAL_SpiClockPhaseFirstEdge = 0x0U, kHAL_SpiClockPhaseSecondEdge } |
spi clock phase configuration. More... | |
enum | hal_spi_shift_direction_t { kHAL_SpiMsbFirst = 0x0U, kHAL_SpiLsbFirst } |
spi data shifter direction options. More... | |
Initialization and de-initialization | |
hal_spi_status_t | HAL_SpiMasterInit (hal_spi_master_handle_t handle, const hal_spi_master_config_t *config) |
Initializes the spi with master configuration. More... | |
hal_spi_status_t | HAL_SpiSlaveInit (hal_spi_slave_handle_t handle, const hal_spi_slave_config_t *config) |
Initializes the spi with slave configuration. More... | |
hal_spi_status_t | HAL_SpiMasterDeinit (hal_spi_master_handle_t handle) |
De-initializes the spi master. More... | |
hal_spi_status_t | HAL_SpiSlaveDeinit (hal_spi_slave_handle_t handle) |
De-initializes the spi slave. More... | |
struct hal_spi_master_config_t |
Data Fields | |
uint32_t | srcClock_Hz |
Clock source for spi in Hz. | |
uint32_t | baudRate_Bps |
Baud Rate for spi in Hz. | |
hal_spi_clock_polarity_t | polarity |
Clock polarity. | |
hal_spi_clock_phase_t | phase |
Clock phase. | |
hal_spi_shift_direction_t | direction |
MSB or LSB. | |
uint8_t | instance |
Instance of the spi. | |
bool | enableMaster |
Enable spi at initialization time. | |
struct hal_spi_slave_config_t |
Data Fields | |
hal_spi_clock_polarity_t | polarity |
Clock polarity. | |
hal_spi_clock_phase_t | phase |
Clock phase. | |
hal_spi_shift_direction_t | direction |
MSB or LSB. | |
uint8_t | instance |
Instance of the spi. | |
bool | enableSlave |
Enable spi at initialization time. | |
struct hal_spi_transfer_t |
#define HAL_SPI_MASTER_HANDLE_SIZE (68U) |
#define HAL_SPI_SLAVE_HANDLE_SIZE (68U) |
#define HAL_SPI_MASTER_HANDLE_DEFINE | ( | name | ) | uint32_t name[(HAL_SPI_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] |
This macro is used to define the SPI master handle. Then use "(hal_spi_master_handle_t)name" to get the SPI master handle.
The macro should be global and could be optional. You could also define SPI master handle by yourself.
This is an example,
name | The name string of the SPI master handle. |
#define HAL_SPI_SLAVE_HANDLE_DEFINE | ( | name | ) | uint32_t name[(HAL_SPI_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] |
This macro is used to define the SPI slave handle. Then use "(hal_spi_slave_handle_t)name" to get the SPI slave handle.
The macro should be global and could be optional. You could also define SPI slave handle by yourself.
This is an example,
name | The name string of the SPI slave handle. |
typedef void* hal_spi_master_handle_t |
typedef void* hal_spi_slave_handle_t |
enum hal_spi_status_t |
hal_spi_status_t HAL_SpiMasterInit | ( | hal_spi_master_handle_t | handle, |
const hal_spi_master_config_t * | config | ||
) |
This function configures the spi 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_SPI_MASTER_HANDLE_SIZE allocated by the caller.
Example below shows how to use this API to configure the SPI master.
handle | Pointer to point to a memory space of size HAL_SPI_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_SPI_MASTER_HANDLE_DEFINE(handle); or uint32_t handle[((HAL_SPI_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; |
config | pointer to master configuration structure |
kStatus_HAL_SpiError | An error occurred. |
kStatus_HAL_SpiSuccess | spi master initialization succeed |
hal_spi_status_t HAL_SpiSlaveInit | ( | hal_spi_slave_handle_t | handle, |
const hal_spi_slave_config_t * | config | ||
) |
This function configures the spi 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_SPI_SLAVE_HANDLE_SIZE allocated by the caller. After calling this API, the slave is ready to transfer.
Example below shows how to use this API to configure the SPI slave.
handle | Pointer to point to a memory space of size HAL_SPI_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_SPI_MASTER_HANDLE_DEFINE(handle); or uint32_t handle[((HAL_SPI_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; |
config | pointer to slave configuration structure |
kStatus_HAL_SpiError | An error occurred. |
kStatus_HAL_SpiSuccess | spi slave initialization succeed |
hal_spi_status_t HAL_SpiMasterDeinit | ( | hal_spi_master_handle_t | handle | ) |
De-initializes the spi master. The spi master can't work unless calling the HAL_SpiMasterInit to initialize module.
handle | spi master handle pointer, this should be a static variable. |
kStatus_HAL_SpiSuccess | spi master de-initialization succeed |
hal_spi_status_t HAL_SpiSlaveDeinit | ( | hal_spi_slave_handle_t | handle | ) |
De-initializes the spi slave. The spi slave can't work unless calling the HAL_SpiSlaveInit to initialize module.
handle | spi slave handle pointer, this should be a static variable. |
kStatus_HAL_SpiSuccess | spi slave de-initialization succeed |
hal_spi_status_t HAL_SpiMasterTransferInstallCallback | ( | hal_spi_master_handle_t | handle, |
hal_spi_master_transfer_callback_t | callback, | ||
void * | callbackParam | ||
) |
This function is used to install the callback and callback parameter for spi master module. When any status of the spi 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 | spi master handle pointer, this should be a static variable. |
callback | Callback function. |
callbackParam | The parameter of the callback function. |
kStatus_HAL_SpiSuccess | spi master handle created |
hal_spi_status_t HAL_SpiMasterTransferBlocking | ( | hal_spi_master_handle_t | handle, |
hal_spi_transfer_t * | xfer | ||
) |
handle | spi master handle pointer, this should be a static variable. |
xfer | pointer to hal_spi_transfer_t structure |
kStatus_HAL_SpiError | An error occurred. |
kStatus_HAL_SpiSuccess | Successfully sent all data. |
hal_spi_status_t HAL_SpiMasterTransferNonBlocking | ( | hal_spi_master_handle_t | handle, |
hal_spi_transfer_t * | xfer | ||
) |
handle | spi master handle pointer, this should be a static variable. |
xfer | pointer to hal_spi_transfer_t structure |
kStatus_HAL_SpiError | An error occurred. |
kStatus_HAL_SpiBusy | spi is not idle, is running another transfer. |
kStatus_HAL_SpiSuccess | Successfully start the data transmission. |
hal_spi_status_t HAL_SpiMasterTransferGetCount | ( | hal_spi_master_handle_t | handle, |
size_t * | spiCount | ||
) |
handle | spi master handle pointer, this should be a static variable. |
count | Transferred bytes of spi master. |
kStatus_HAL_SpiError | An error occurred. |
kStatus_HAL_SpiSuccess | Succeed get the transfer count. |
hal_spi_status_t HAL_SpiMasterTransferAbort | ( | hal_spi_master_handle_t | handle | ) |
handle | spi master handle pointer, this should be a static variable. |
kStatus_HAL_SpiSuccess | Succeed abort the transfer. |
hal_spi_status_t HAL_SpiSlaveTransferInstallCallback | ( | hal_spi_slave_handle_t | handle, |
hal_spi_slave_transfer_callback_t | callback, | ||
void * | callbackParam | ||
) |
This function is used to install the callback and callback parameter for spi slave module. When any status of the spi 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 | spi slave handle pointer, this should be a static variable. |
callback | Callback function. |
callbackParam | The parameter of the callback function. |
kStatus_HAL_SpiSuccess | spi slave handle created |
hal_spi_status_t HAL_SpiSlaveTransferNonBlocking | ( | hal_spi_slave_handle_t | handle, |
hal_spi_transfer_t * | xfer | ||
) |
handle | spi slave handle pointer, this should be a static variable. |
xfer | pointer to hal_spi_xfer_config_t structure |
kStatus_HAL_SpiSuccess | Successfully start a transfer. |
kStatus_HAL_SpiError | An error occurred. |
kStatus_HAL_SpiBusy | spi is not idle, is running another transfer. |
hal_spi_status_t HAL_SpiSlaveTransferGetCount | ( | hal_spi_slave_handle_t | handle, |
size_t * | spiCount | ||
) |
handle | spi slave handle pointer, this should be a static variable. |
count | Transferred bytes of spi slave. |
kStatus_HAL_SpiSuccess | Succeed get the transfer count. |
kStatus_HAL_SpiError | An error occurred. |
hal_spi_status_t HAL_SpiSlaveTransferAbort | ( | hal_spi_slave_handle_t | handle | ) |
handle | spi slave handle pointer, this should be a static variable. |
kStatus_HAL_SpiSuccess | Succeed abort the transfer. |