This section describes the programming interface of the SPI driver.
|
| #define | SPI_DUMMYDATA (0xFFFFU) |
| | SPI dummy transfer data, the data is sent while txBuff is NULL. More...
|
| |
|
| enum | _spi_xfer_option {
kSPI_EndOfFrame = (SPI_TXDATCTL_EOF_MASK),
kSPI_EndOfTransfer = (SPI_TXDATCTL_EOT_MASK),
kSPI_ReceiveIgnore = (SPI_TXDATCTL_RXIGNORE_MASK)
} |
| | SPI transfer option. More...
|
| |
| enum | spi_shift_direction_t {
kSPI_MsbFirst = 0U,
kSPI_LsbFirst = 1U
} |
| | SPI data shifter direction options. More...
|
| |
| enum | spi_clock_polarity_t {
kSPI_ClockPolarityActiveHigh = 0x0U,
kSPI_ClockPolarityActiveLow = 0x1U
} |
| | SPI clock polarity configuration. More...
|
| |
| enum | spi_clock_phase_t {
kSPI_ClockPhaseFirstEdge = 0x0U,
kSPI_ClockPhaseSecondEdge = 0x1U
} |
| | SPI clock phase configuration. More...
|
| |
| enum | spi_ssel_t { kSPI_Ssel0Assert = (int)(~SPI_TXDATCTL_TXSSEL0_N_MASK)
} |
| | Slave select. More...
|
| |
| enum | spi_spol_t |
| | ssel polarity
|
| |
| enum | spi_data_width_t {
kSPI_Data4Bits = 3,
kSPI_Data5Bits = 4,
kSPI_Data6Bits = 5,
kSPI_Data7Bits = 6,
kSPI_Data8Bits = 7,
kSPI_Data9Bits = 8,
kSPI_Data10Bits = 9,
kSPI_Data11Bits = 10,
kSPI_Data12Bits = 11,
kSPI_Data13Bits = 12,
kSPI_Data14Bits = 13,
kSPI_Data15Bits = 14,
kSPI_Data16Bits = 15
} |
| | Transfer data width. More...
|
| |
| enum | {
kStatus_SPI_Busy = MAKE_STATUS(kStatusGroup_LPC_MINISPI, 0),
kStatus_SPI_Idle = MAKE_STATUS(kStatusGroup_LPC_MINISPI, 1),
kStatus_SPI_Error = MAKE_STATUS(kStatusGroup_LPC_MINISPI, 2),
kStatus_SPI_BaudrateNotSupport
} |
| | SPI transfer status. More...
|
| |
| enum | _spi_interrupt_enable {
kSPI_RxReadyInterruptEnable = SPI_INTENSET_RXRDYEN_MASK,
kSPI_TxReadyInterruptEnable = SPI_INTENSET_TXRDYEN_MASK,
kSPI_RxOverrunInterruptEnable = SPI_INTENSET_RXOVEN_MASK,
kSPI_TxUnderrunInterruptEnable = SPI_INTENSET_TXUREN_MASK,
kSPI_SlaveSelectAssertInterruptEnable = SPI_INTENSET_SSAEN_MASK,
kSPI_SlaveSelectDeassertInterruptEnable = SPI_INTENSET_SSDEN_MASK
} |
| | SPI interrupt sources. More...
|
| |
| enum | _spi_status_flags {
kSPI_RxReadyFlag = SPI_STAT_RXRDY_MASK,
kSPI_TxReadyFlag = SPI_STAT_TXRDY_MASK,
kSPI_RxOverrunFlag = SPI_STAT_RXOV_MASK,
kSPI_TxUnderrunFlag = SPI_STAT_TXUR_MASK,
kSPI_SlaveSelectAssertFlag = SPI_STAT_SSA_MASK,
kSPI_SlaveSelectDeassertFlag = SPI_STAT_SSD_MASK,
kSPI_StallFlag = SPI_STAT_STALLED_MASK,
kSPI_EndTransferFlag = SPI_STAT_ENDTRANSFER_MASK,
kSPI_MasterIdleFlag = SPI_STAT_MSTIDLE_MASK
} |
| | SPI status flags. More...
|
| |
|
| status_t | SPI_MasterTransferCreateHandle (SPI_Type *base, spi_master_handle_t *handle, spi_master_callback_t callback, void *userData) |
| | Initializes the SPI master handle. More...
|
| |
| status_t | SPI_MasterTransferNonBlocking (SPI_Type *base, spi_master_handle_t *handle, spi_transfer_t *xfer) |
| | Performs a non-blocking SPI interrupt transfer. More...
|
| |
| status_t | SPI_MasterTransferGetCount (SPI_Type *base, spi_master_handle_t *handle, size_t *count) |
| | Gets the master transfer count. More...
|
| |
| void | SPI_MasterTransferAbort (SPI_Type *base, spi_master_handle_t *handle) |
| | SPI master aborts a transfer using an interrupt. More...
|
| |
| void | SPI_MasterTransferHandleIRQ (SPI_Type *base, spi_master_handle_t *handle) |
| | Interrupts the handler for the SPI. More...
|
| |
| status_t | SPI_SlaveTransferCreateHandle (SPI_Type *base, spi_slave_handle_t *handle, spi_slave_callback_t callback, void *userData) |
| | Initializes the SPI slave handle. More...
|
| |
| status_t | SPI_SlaveTransferNonBlocking (SPI_Type *base, spi_slave_handle_t *handle, spi_transfer_t *xfer) |
| | Performs a non-blocking SPI slave interrupt transfer. More...
|
| |
| static status_t | SPI_SlaveTransferGetCount (SPI_Type *base, spi_slave_handle_t *handle, size_t *count) |
| | Gets the slave transfer count. More...
|
| |
| static void | SPI_SlaveTransferAbort (SPI_Type *base, spi_slave_handle_t *handle) |
| | SPI slave aborts a transfer using an interrupt. More...
|
| |
| void | SPI_SlaveTransferHandleIRQ (SPI_Type *base, spi_slave_handle_t *handle) |
| | Interrupts a handler for the SPI slave. More...
|
| |
| struct spi_delay_config_t |
| uint8_t spi_delay_config_t::preDelay |
| uint8_t spi_delay_config_t::postDelay |
| uint8_t spi_delay_config_t::frameDelay |
| uint8_t spi_delay_config_t::transferDelay |
| struct spi_master_config_t |
| struct spi_slave_config_t |
| uint32_t spi_transfer_t::configFlags |
| struct _spi_master_handle |
| uint32_t spi_master_handle_t::lastCommand |
| #define SPI_DUMMYDATA (0xFFFFU) |
| Enumerator |
|---|
| kSPI_EndOfFrame |
Data is treated as the end of a frame.
|
| kSPI_EndOfTransfer |
Data is treated as the end of a transfer.
|
| kSPI_ReceiveIgnore |
Ignore the receive data.
|
| Enumerator |
|---|
| kSPI_MsbFirst |
Data transfers start with most significant bit.
|
| kSPI_LsbFirst |
Data transfers start with least significant bit.
|
| Enumerator |
|---|
| kSPI_ClockPolarityActiveHigh |
Active-high SPI clock (idles low).
|
| kSPI_ClockPolarityActiveLow |
Active-low SPI clock (idles high).
|
| Enumerator |
|---|
| kSPI_ClockPhaseFirstEdge |
First edge on SCK occurs at the middle of the first cycle of a data transfer.
|
| kSPI_ClockPhaseSecondEdge |
First edge on SCK occurs at the start of the first cycle of a data transfer.
|
| Enumerator |
|---|
| kSPI_Ssel0Assert |
Slave select 0.
|
| Enumerator |
|---|
| kSPI_Data4Bits |
4 bits data width
|
| kSPI_Data5Bits |
5 bits data width
|
| kSPI_Data6Bits |
6 bits data width
|
| kSPI_Data7Bits |
7 bits data width
|
| kSPI_Data8Bits |
8 bits data width
|
| kSPI_Data9Bits |
9 bits data width
|
| kSPI_Data10Bits |
10 bits data width
|
| kSPI_Data11Bits |
11 bits data width
|
| kSPI_Data12Bits |
12 bits data width
|
| kSPI_Data13Bits |
13 bits data width
|
| kSPI_Data14Bits |
14 bits data width
|
| kSPI_Data15Bits |
15 bits data width
|
| kSPI_Data16Bits |
16 bits data width
|
| Enumerator |
|---|
| kStatus_SPI_Busy |
SPI bus is busy.
|
| kStatus_SPI_Idle |
SPI is idle.
|
| kStatus_SPI_Error |
SPI error.
|
| kStatus_SPI_BaudrateNotSupport |
Baudrate is not support in current clock source.
|
| Enumerator |
|---|
| kSPI_RxReadyInterruptEnable |
Rx ready interrupt.
|
| kSPI_TxReadyInterruptEnable |
Tx ready interrupt.
|
| kSPI_RxOverrunInterruptEnable |
Rx overrun interrupt.
|
| kSPI_TxUnderrunInterruptEnable |
Tx underrun interrupt.
|
| kSPI_SlaveSelectAssertInterruptEnable |
Slave select assert interrupt.
|
| kSPI_SlaveSelectDeassertInterruptEnable |
Slave select deassert interrupt.
|
| Enumerator |
|---|
| kSPI_RxReadyFlag |
Receive ready flag.
|
| kSPI_TxReadyFlag |
Transmit ready flag.
|
| kSPI_RxOverrunFlag |
Receive overrun flag.
|
| kSPI_TxUnderrunFlag |
Transmit underrun flag.
|
| kSPI_SlaveSelectAssertFlag |
Slave select assert flag.
|
| kSPI_SlaveSelectDeassertFlag |
slave select deassert flag.
|
| kSPI_StallFlag |
Stall flag.
|
| kSPI_EndTransferFlag |
End transfer bit.
|
| kSPI_MasterIdleFlag |
Master in idle status flag.
|
| uint32_t SPI_GetInstance |
( |
SPI_Type * |
base | ) |
|
The purpose of this API is to get the configuration structure initialized for use in SPI_MasterInit(). User may use the initialized structure unchanged in SPI_MasterInit(), or modify some fields of the structure before calling SPI_MasterInit(). After calling this API, the master is ready to transfer. Example:
- Parameters
-
| config | pointer to master config structure |
The configuration structure can be filled by user from scratch, or be set with default values by SPI_MasterGetDefaultConfig(). After calling this API, the slave is ready to transfer. Example
- Parameters
-
| base | SPI base pointer |
| config | pointer to master configuration structure |
| srcClock_Hz | Source clock frequency. |
The purpose of this API is to get the configuration structure initialized for use in SPI_SlaveInit(). Modify some fields of the structure before calling SPI_SlaveInit(). Example:
- Parameters
-
| config | pointer to slave configuration structure |
The configuration structure can be filled by user from scratch or be set with default values by SPI_SlaveGetDefaultConfig(). After calling this API, the slave is ready to transfer. Example
- Parameters
-
| base | SPI base pointer |
| config | pointer to slave configuration structure |
| void SPI_Deinit |
( |
SPI_Type * |
base | ) |
|
Calling this API resets the SPI module, gates the SPI clock. Disable the fifo if enabled. The SPI module can't work unless calling the SPI_MasterInit/SPI_SlaveInit to initialize module.
- Parameters
-
| static void SPI_Enable |
( |
SPI_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
| base | SPI base pointer |
| enable | or disable ( true = enable, false = disable) |
| static uint32_t SPI_GetStatusFlags |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
- Returns
- SPI Status, use status flag to AND _spi_status_flags could get the related status.
| static void SPI_ClearStatusFlags |
( |
SPI_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
| base | SPI base pointer |
| mask | SPI Status, use status flag to AND _spi_status_flags could get the related status. |
| static void SPI_EnableInterrupts |
( |
SPI_Type * |
base, |
|
|
uint32_t |
irqs |
|
) |
| |
|
inlinestatic |
- Parameters
-
| base | SPI base pointer |
| irqs | SPI interrupt source. The parameter can be any combination of the following values:
- kSPI_RxReadyInterruptEnable
- kSPI_TxReadyInterruptEnable
|
| static void SPI_DisableInterrupts |
( |
SPI_Type * |
base, |
|
|
uint32_t |
irqs |
|
) |
| |
|
inlinestatic |
- Parameters
-
| base | SPI base pointer |
| irqs | SPI interrupt source. The parameter can be any combination of the following values:
- kSPI_RxReadyInterruptEnable
- kSPI_TxReadyInterruptEnable
|
| static bool SPI_IsMaster |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
| base | SPI peripheral address. |
- Returns
- Returns true if the module is in master mode or false if the module is in slave mode.
| status_t SPI_MasterSetBaudRate |
( |
SPI_Type * |
base, |
|
|
uint32_t |
baudrate_Bps, |
|
|
uint32_t |
srcClock_Hz |
|
) |
| |
This is only used in master.
- Parameters
-
| base | SPI base pointer |
| baudrate_Bps | baud rate needed in Hz. |
| srcClock_Hz | SPI source clock frequency in Hz. |
| static void SPI_WriteData |
( |
SPI_Type * |
base, |
|
|
uint16_t |
data |
|
) |
| |
|
inlinestatic |
- Parameters
-
| base | SPI base pointer |
| data | needs to be write. |
| static void SPI_WriteConfigFlags |
( |
SPI_Type * |
base, |
|
|
uint32_t |
configFlags |
|
) |
| |
|
inlinestatic |
- Parameters
-
| base | SPI base pointer |
| configFlags | control command needs to be write. |
| void SPI_WriteDataWithConfigFlags |
( |
SPI_Type * |
base, |
|
|
uint16_t |
data, |
|
|
uint32_t |
configFlags |
|
) |
| |
- Parameters
-
| base | SPI base pointer |
| value | needs to be write. |
| static uint32_t SPI_ReadData |
( |
SPI_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
- Returns
- Data in the register.
the delay uint is SPI clock time, maximum value is 0xF.
- Parameters
-
| void SPI_SetDummyData |
( |
SPI_Type * |
base, |
|
|
uint16_t |
dummyData |
|
) |
| |
This API can change the default data to be transferred when users set the tx buffer to NULL.
- Parameters
-
| base | SPI peripheral address. |
| dummyData | Data to be transferred when tx buffer is NULL. |
- Parameters
-
| base | SPI base pointer |
| xfer | pointer to spi_xfer_config_t structure |
- Return values
-
| kStatus_Success | Successfully start a transfer. |
| kStatus_InvalidArgument | Input argument is invalid. |
This function initializes the SPI master handle which can be used for other SPI master transactional APIs. Usually, for a specified SPI instance, call this API once to get the initialized handle.
- Parameters
-
| base | SPI peripheral base address. |
| handle | SPI handle pointer. |
| callback | Callback function. |
| userData | User data. |
| status_t SPI_MasterTransferNonBlocking |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle, |
|
|
spi_transfer_t * |
xfer |
|
) |
| |
- Parameters
-
| base | SPI peripheral base address. |
| handle | pointer to spi_master_handle_t structure which stores the transfer state |
| xfer | pointer to spi_xfer_config_t structure |
- Return values
-
| kStatus_Success | Successfully start a transfer. |
| kStatus_InvalidArgument | Input argument is invalid. |
| kStatus_SPI_Busy | SPI is not idle, is running another transfer. |
| status_t SPI_MasterTransferGetCount |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle, |
|
|
size_t * |
count |
|
) |
| |
This function gets the master transfer count.
- Parameters
-
| base | SPI peripheral base address. |
| handle | Pointer to the spi_master_handle_t structure which stores the transfer state. |
| count | The number of bytes transferred by using the non-blocking transaction. |
- Returns
- status of status_t.
| void SPI_MasterTransferAbort |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle |
|
) |
| |
This function aborts a transfer using an interrupt.
- Parameters
-
| base | SPI peripheral base address. |
| handle | Pointer to the spi_master_handle_t structure which stores the transfer state. |
| void SPI_MasterTransferHandleIRQ |
( |
SPI_Type * |
base, |
|
|
spi_master_handle_t * |
handle |
|
) |
| |
- Parameters
-
| base | SPI peripheral base address. |
| handle | pointer to spi_master_handle_t structure which stores the transfer state. |
This function initializes the SPI slave handle which can be used for other SPI slave transactional APIs. Usually, for a specified SPI instance, call this API once to get the initialized handle.
- Parameters
-
| base | SPI peripheral base address. |
| handle | SPI handle pointer. |
| callback | Callback function. |
| userData | User data. |
- Note
- The API returns immediately after the transfer initialization is finished.
- Parameters
-
| base | SPI peripheral base address. |
| handle | pointer to spi_master_handle_t structure which stores the transfer state |
| xfer | pointer to spi_xfer_config_t structure |
- Return values
-
| kStatus_Success | Successfully start a transfer. |
| kStatus_InvalidArgument | Input argument is invalid. |
| kStatus_SPI_Busy | SPI is not idle, is running another transfer. |
This function gets the slave transfer count.
- Parameters
-
| base | SPI peripheral base address. |
| handle | Pointer to the spi_master_handle_t structure which stores the transfer state. |
| count | The number of bytes transferred by using the non-blocking transaction. |
- Returns
- status of status_t.
This function aborts a transfer using an interrupt.
- Parameters
-
| base | SPI peripheral base address. |
| handle | Pointer to the spi_slave_handle_t structure which stores the transfer state. |
- Parameters
-
| base | SPI peripheral base address. |
| handle | pointer to spi_slave_handle_t structure which stores the transfer state |