LPSPI Peripheral driver
Power Serial Peripheral Interface (LPSPI)
Collaboration diagram for LPSPI Peripheral driver:

## Data Structures

struct | lpspi_master_config_t
| LPSPI master config structure. More...
struct | lpspi_slave_config_t
| LPSPI slave config structure. More...
struct | lpspi_transfer_t
| LPSPI master/slave transfer structure. More...
struct | lpspi_master_handle_t
| LPSPI master transfer handle structure used for transactional API. More...
struct | lpspi_slave_handle_t
| LPSPI slave transfer handle structure used for transactional API. More...

## Typedefs

typedef void(* | lpspi_master_transfer_callback_t) (LPSPI_Type *base, lpspi_master_handle_t *handle, status_t status, void *userData)
| Master completion callback function pointer type. More...
typedef void(* | lpspi_slave_transfer_callback_t) (LPSPI_Type *base, lpspi_slave_handle_t *handle, status_t status, void *userData)
| Slave completion callback function pointer type. More...

## Enumerations

enum | _lpspi_status { kStatus_LPSPI_Busy = MAKE_STATUS(kStatusGroup_LPSPI, 0), kStatus_LPSPI_Error = MAKE_STATUS(kStatusGroup_LPSPI, 1), kStatus_LPSPI_Idle = MAKE_STATUS(kStatusGroup_LPSPI, 2), kStatus_LPSPI_OutOfRange = MAKE_STATUS(kStatusGroup_LPSPI, 3) }
| Status for the LPSPI driver. More...

enum

_lpspi_flags {
kLPSPI_TxDataRequestFlag = LPSPI_SR_TDF_MASK,
kLPSPI_RxDataReadyFlag = LPSPI_SR_RDF_MASK,
kLPSPI_WordCompleteFlag = LPSPI_SR_WCF_MASK,
kLPSPI_FrameCompleteFlag = LPSPI_SR_FCF_MASK,
kLPSPI_TransferCompleteFlag = LPSPI_SR_TCF_MASK,
kLPSPI_TransmitErrorFlag = LPSPI_SR_TEF_MASK,
kLPSPI_ReceiveErrorFlag = LPSPI_SR_REF_MASK,
kLPSPI_DataMatchFlag = LPSPI_SR_DMF_MASK,
kLPSPI_ModuleBusyFlag = LPSPI_SR_MBF_MASK,
kLPSPI_AllStatusFlag
}

| LPSPI status flags in SPIx_SR register. More...

enum

_lpspi_interrupt_enable {
kLPSPI_TxInterruptEnable = LPSPI_IER_TDIE_MASK,
kLPSPI_RxInterruptEnable = LPSPI_IER_RDIE_MASK,
kLPSPI_WordCompleteInterruptEnable = LPSPI_IER_WCIE_MASK,
kLPSPI_FrameCompleteInterruptEnable = LPSPI_IER_FCIE_MASK,
kLPSPI_TransferCompleteInterruptEnable = LPSPI_IER_TCIE_MASK,
kLPSPI_TransmitErrorInterruptEnable = LPSPI_IER_TEIE_MASK,
kLPSPI_ReceiveErrorInterruptEnable = LPSPI_IER_REIE_MASK,
kLPSPI_DataMatchInterruptEnable = LPSPI_IER_DMIE_MASK,
kLPSPI_AllInterruptEnable
}

| LPSPI interrupt source. More...
enum | _lpspi_dma_enable { kLPSPI_TxDmaEnable = LPSPI_DER_TDDE_MASK, kLPSPI_RxDmaEnable = LPSPI_DER_RDDE_MASK }
| LPSPI DMA source. More...
enum | lpspi_master_slave_mode_t { kLPSPI_Master = 1U, kLPSPI_Slave = 0U }
| LPSPI master or slave mode configuration. More...
enum | lpspi_which_pcs_t { kLPSPI_Pcs0 = 0U, kLPSPI_Pcs1 = 1U, kLPSPI_Pcs2 = 2U, kLPSPI_Pcs3 = 3U }
| LPSPI Peripheral Chip Select (Pcs) configuration (which Pcs to configure). More...
enum | lpspi_pcs_polarity_config_t { kLPSPI_PcsActiveHigh = 1U, kLPSPI_PcsActiveLow = 0U }
| LPSPI Peripheral Chip Select (Pcs) Polarity configuration. More...
enum | _lpspi_pcs_polarity { kLPSPI_Pcs0ActiveLow = 1U << 0, kLPSPI_Pcs1ActiveLow = 1U << 1, kLPSPI_Pcs2ActiveLow = 1U << 2, kLPSPI_Pcs3ActiveLow = 1U << 3, kLPSPI_PcsAllActiveLow = 0xFU }
| LPSPI Peripheral Chip Select (Pcs) Polarity. More...
enum | lpspi_clock_polarity_t { kLPSPI_ClockPolarityActiveHigh = 0U, kLPSPI_ClockPolarityActiveLow = 1U }
| LPSPI clock polarity configuration. More...
enum | lpspi_clock_phase_t { kLPSPI_ClockPhaseFirstEdge = 0U, kLPSPI_ClockPhaseSecondEdge = 1U }
| LPSPI clock phase configuration. More...
enum | lpspi_shift_direction_t { kLPSPI_MsbFirst = 0U, kLPSPI_LsbFirst = 1U }
| LPSPI data shifter direction options. More...
enum | lpspi_host_request_select_t { kLPSPI_HostReqExtPin = 0U, kLPSPI_HostReqInternalTrigger = 1U }
| LPSPI Host Request select configuration. More...
enum | lpspi_match_config_t { kLPSI_MatchDisabled = 0x0U, kLPSI_1stWordEqualsM0orM1 = 0x2U, kLPSI_AnyWordEqualsM0orM1 = 0x3U, kLPSI_1stWordEqualsM0and2ndWordEqualsM1 = 0x4U, kLPSI_AnyWordEqualsM0andNxtWordEqualsM1 = 0x5U, kLPSI_1stWordAndM1EqualsM0andM1 = 0x6U, kLPSI_AnyWordAndM1EqualsM0andM1 = 0x7U }
| LPSPI Match configuration options. More...
enum | lpspi_pin_config_t { kLPSPI_SdiInSdoOut = 0U, kLPSPI_SdoInSdoOut = 1U, kLPSPI_SdiInSdiOut = 2U, kLPSPI_SdoInSdiOut = 3U }
| LPSPI pin (SDO and SDI) configuration. More...
enum | lpspi_data_out_config_t { kLpspiDataOutRetained = 0U, kLpspiDataOutTristate = 1U }
| LPSPI data output configuration. More...
enum | lpspi_transfer_width_t { kLPSPI_SingleBitXfer = 0U, kLPSPI_TwoBitXfer = 1U, kLPSPI_FourBitXfer = 2U }
| LPSPI transfer width configuration. More...
enum | lpspi_delay_type_t { kLPSPI_PcsToSck = 1U, kLPSPI_LastSckToPcs, kLPSPI_BetweenTransfer }
| LPSPI delay type selection. More...
enum | _lpspi_transfer_config_flag_for_master { kLPSPI_MasterPcs0 = 0U << LPSPI_MASTER_PCS_SHIFT, kLPSPI_MasterPcs1 = 1U << LPSPI_MASTER_PCS_SHIFT, kLPSPI_MasterPcs2 = 2U << LPSPI_MASTER_PCS_SHIFT, kLPSPI_MasterPcs3 = 3U << LPSPI_MASTER_PCS_SHIFT, kLPSPI_MasterPcsContinuous = 1U << 20, kLPSPI_MasterByteSwap = 1U << 22 }
| Can use this enum for LPSPI master transfer configFlags. More...
enum | _lpspi_transfer_config_flag_for_slave { kLPSPI_SlavePcs0 = 0U << LPSPI_SLAVE_PCS_SHIFT, kLPSPI_SlavePcs1 = 1U << LPSPI_SLAVE_PCS_SHIFT, kLPSPI_SlavePcs2 = 2U << LPSPI_SLAVE_PCS_SHIFT, kLPSPI_SlavePcs3 = 3U << LPSPI_SLAVE_PCS_SHIFT, kLPSPI_SlaveByteSwap = 1U << 22 }
| Can use this enum for LPSPI slave transfer configFlags. More...
enum | _lpspi_transfer_state { kLPSPI_Idle = 0x0U, kLPSPI_Busy, kLPSPI_Error }
| LPSPI transfer state, which is used for LPSPI transactiaonl APIs' state machine. More...

## Initialization and deinitialization

void | LPSPI_MasterInit (LPSPI_Type *base, const lpspi_master_config_t *masterConfig, uint32_t srcClock_Hz)
| LPSPI master Init. More...
void | LPSPI_MasterGetDefaultConfig (lpspi_master_config_t *masterConfig)
| Set the lpspi_master_config_t structure to default values. More...
void | LPSPI_SlaveInit (LPSPI_Type *base, const lpspi_slave_config_t *slaveConfig)
| LPSPI slave configuration. More...
void | LPSPI_SlaveGetDefaultConfig (lpspi_slave_config_t *slaveConfig)
| Set the lpspi_slave_config_t structure to default values. More...
void | LPSPI_Deinit (LPSPI_Type *base)
| De-initialize the LPSPI peripheral, call this API to disbale the lpspi clock. More...
void | LPSPI_Reset (LPSPI_Type *base)
| Restores the LPSPI peripheral to reset state, notice that this function will set all the registers to reset state so the LPSPI module can not work after calling this API. More...
static void | LPSPI_Enable (LPSPI_Type *base, bool enable)
| Enables the LPSPI peripheral and sets the MCR MDIS to 0. More...

## Status

static uint32_t | LPSPI_GetStatusFlags (LPSPI_Type *base)
| Gets the LPSPI status flag state. More...
static uint32_t | LPSPI_GetTxFifoSize (LPSPI_Type *base)
| Gets the LPSPI Tx FIFO size. More...
static uint32_t | LPSPI_GetRxFifoSize (LPSPI_Type *base)
| Gets the LPSPI Rx FIFO size. More...
static uint32_t | LPSPI_GetTxFifoCount (LPSPI_Type *base)
| Gets the LPSPI Tx FIFO count. More...
static uint32_t | LPSPI_GetRxFifoCount (LPSPI_Type *base)
| Gets the LPSPI Rx FIFO count. More...
static void | LPSPI_ClearStatusFlags (LPSPI_Type *base, uint32_t statusFlags)
| Clears the LPSPI status flag. More...

## Interrupts

static void | LPSPI_EnableInterrupts (LPSPI_Type *base, uint32_t mask)
| Enable the LPSPI interrupts. More...
static void | LPSPI_DisableInterrupts (LPSPI_Type *base, uint32_t mask)
| Disable the LPSPI interrupts. More...

## DMA Control

static void | LPSPI_EnableDMA (LPSPI_Type *base, uint32_t mask)
| Enable the LPSPI DMA request. More...
static void | LPSPI_DisableDMA (LPSPI_Type *base, uint32_t mask)
| Disable the LPSPI DMA request. More...
static uint32_t | LPSPI_GetTxRegisterAddress (LPSPI_Type *base)
| Gets the LPSPI Transmit Data Register address for DMA operation. More...
static uint32_t | LPSPI_GetRxRegisterAddress (LPSPI_Type *base)
| Gets the LPSPI Receive Data Register address for DMA operation. More...

## Bus Operations

static void | LPSPI_SetMasterSlaveMode (LPSPI_Type *base, lpspi_master_slave_mode_t mode)
| Configures the LPSPI for master or slave. More...
static bool | LPSPI_IsMaster (LPSPI_Type *base)
| Returns whether the LPSPI module is in master mode. More...
static void | LPSPI_FlushFifo (LPSPI_Type *base, bool flushTxFifo, bool flushRxFifo)
| Flushes the LPSPI FIFOs. More...
static void | LPSPI_SetFifoWatermarks (LPSPI_Type *base, uint32_t txWater, uint32_t rxWater)
| Sets the transmit and receive FIFO watermark values. More...
static void | LPSPI_SetAllPcsPolarity (LPSPI_Type *base, uint32_t mask)
| Configures all the LPSPI peripheral chip select polarity simultaneously. More...
static void | LPSPI_SetFrameSize (LPSPI_Type *base, uint32_t frameSize)
| Configures the frame size . More...
uint32_t | LPSPI_MasterSetBaudRate (LPSPI_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz, uint32_t *tcrPrescaleValue)
| Sets the LPSPI baud rate in bits per second. More...
void | LPSPI_MasterSetDelayScaler (LPSPI_Type *base, uint32_t scaler, lpspi_delay_type_t whichDelay)
| Manually configures a specific LPSPI delay parameter (module must be disabled to change the delay values). More...
uint32_t | LPSPI_MasterSetDelayTimes (LPSPI_Type *base, uint32_t delayTimeInNanoSec, lpspi_delay_type_t whichDelay, uint32_t srcClock_Hz)
| Calculates the delay based on the desired delay input in nanoseconds (module must be disabled to change the delay values). More...
static void | LPSPI_WriteDataNonBlocking (LPSPI_Type *base, uint32_t data)
| Writes data into the transmit data buffer. More...
static uint32_t | LPSPI_ReadDataNonBlocking (LPSPI_Type *base)
| Reads data from the data buffer. More...
status_t | LPSPI_MasterTransferBlocking (LPSPI_Type *base, lpspi_transfer_t *transfer)
| LPSPI master transfer data using polling. More...

## Transactional

void | LPSPI_MasterCreateHandle (LPSPI_Type *base, lpspi_master_handle_t *handle, lpspi_master_transfer_callback_t callback, void *userData)
| Initialize the lpspi master handle. More...
status_t | LPSPI_MasterTransferNonBlocking (LPSPI_Type *base, lpspi_master_handle_t *handle, lpspi_transfer_t *transfer)
| LPSPI master transfer data using interrupt. More...
status_t | LPSPI_MasterGetTransferCount (LPSPI_Type *base, lpspi_master_handle_t *handle, size_t *count)
| Get the master transfer remaining bytes. More...
void | LPSPI_MasterAbortTransfer (LPSPI_Type *base, lpspi_master_handle_t *handle)
| LPSPI master abort transfer which using interrupt. More...
void | LPSPI_MasterHandleInterrupt (LPSPI_Type *base, lpspi_master_handle_t *handle)
| LPSPI Master IRQ handler function. More...
void | LPSPI_SlaveCreateHandle (LPSPI_Type *base, lpspi_slave_handle_t *handle, lpspi_slave_transfer_callback_t callback, void *userData)
| Initialize the lpspi slave handle. More...
status_t | LPSPI_SlaveTransferNonBlocking (LPSPI_Type *base, lpspi_slave_handle_t *handle, lpspi_transfer_t *transfer)
| LPSPI slave transfer data using interrupt. More...
status_t | LPSPI_SlaveGetTransferCount (LPSPI_Type *base, lpspi_slave_handle_t *handle, size_t *count)
| Get the slave transfer remaining bytes. More...
void | LPSPI_SlaveAbortTransfer (LPSPI_Type *base, lpspi_slave_handle_t *handle)
| LPSPI slave abort transfer which using interrupt. More...
void | LPSPI_SlaveHandleInterrupt (LPSPI_Type *base, lpspi_slave_handle_t *handle)
| LPSPI Slave IRQ handler function. More...

## Usage Information

This section describes the programming interface of the LPSPI Peripheral driver. The LPSPI driver configures LPSPI module, provides the functional and transactional interfaces to build the LPSPI application.

# Function groups

## LPSPI Initialization and De-initialization

This function group initializes the default configuration structure for master and slave, initializes the LPSPI master with a master configuration, initializes the LPSPI slave with a slave configuration, and de-initializes the LPSPI module.

## LPSPI Basic Operation

This function group enables/disables the LPSPI module both interrupt and DMA, gets the data register address for the DMA transfer, sets master and slave, starts and stops the transfer, and so on.

## LPSPI Transfer Operation

This function group controls the transfer, master send/receive data, and slave send/receive data.

## LPSPI Status Operation

This function group gets/clears the LPSPI status.

## LPSPI Block Transfer Operation

This function group transfers a block of data, gets the transfer status, and aborts the transfer.

# Typical use case

## Master Operation

lpspi_master_handle_t g_m_handle; //global variable
lpspi_master_config_t masterConfig;
masterConfig.baudRate = 50000;
masterConfig.bitsPerFrame = 8 ;
masterConfig.cpol = kLPSPI_ClockPolarityActiveHigh;
masterConfig.cpha = kLPSPI_ClockPhaseFirstEdge;
masterConfig.direction = kLPSPI_MsbFirst;
masterConfig.pcsToSckDelayInNanoSec = 1000000000 / masterConfig.baudRate * 2;
masterConfig.lastSckToPcsDelayInNanoSec = 1000000000 / masterConfig.baudRate * 2;
masterConfig.betweenTransferDelayInNanoSec = 1000000000 / masterConfig.baudRate * 2;
masterConfig.whichPcs = kLPSPI_Pcs0;
masterConfig.pcsActiveHighOrLow = kLPSPI_PcsActiveLow;
masterConfig.pinCfg = kLPSPI_SdiInSdoOut;
masterConfig.dataOutConfig = kLpspiDataOutRetained;
//srcClock_Hz = CLOCK_GetFreq(xxx);
LPSPI_MasterInit(EXAMPLE_LPSPI_MASTER_BASEADDR, &masterConfig, srcClock_Hz);
LPSPI_MasterCreateHandle(base, &g_m_handle, NULL, NULL);
masterXfer.txData = masterTxData;
masterXfer.rxData = masterRxData;
masterXfer.dataSize = TRANSFER_SIZE;
masterXfer.configFlags = kLPSPI_MasterPcs0 | kLPSPI_MasterPcsContinuous | kLPSPI_SlaveByteSwap;
LPSPI_MasterTransferNonBlocking(base, &g_m_handle, &masterXfer);

## Slave Operation

lpspi_slave_handle_t g_s_handle;//global variable
/*Slave config*/
slaveConfig.bitsPerFrame = 8;
slaveConfig.cpol = kLPSPI_ClockPolarityActiveHigh;
slaveConfig.cpha = kLPSPI_ClockPhaseFirstEdge；
slaveConfig.direction = kLPSPI_MsbFirst;
slaveConfig.whichPcs = kLPSPI_Pcs0;
slaveConfig.pcsActiveHighOrLow = kLPSPI_PcsActiveLow;
slaveConfig.pinCfg = kLPSPI_SdiInSdoOut;
slaveConfig.dataOutConfig = kLpspiDataOutRetained;
LPSPI_SlaveInit(base, &slaveConfig);
/*Set up slave first */
isSlaveTransferCompleted = false;
LPSPI_SlaveCreateHandle(base, &g_s_handle, LPSPI_SlaveUserCallback, NULL);
slaveXfer.txData = slaveTxData;
slaveXfer.rxData = slaveRxData;
slaveXfer.dataSize = TRANSFER_SIZE;
slaveXfer.configFlags = kLPSPI_SlavePcs0 | kLPSPI_SlaveByteSwap;
LPSPI_SlaveTransferNonBlocking(EXAMPLE_LPSPI_SLAVE_BASEADDR, &g_s_handle, &slaveXfer);
//void LPSPI_SlaveUserCallback(LPSPI_Type *base, lpspi_slave_handle_t *handle, status_t status, void *userData)
//{
// if (status == kStatus_Success)
// {
// PRINTF("This is LPSPI slave transfer completed callback. \r\n");
// PRINTF("It's a successful transfer. \r\n\r\n");
// }
// else if (status == kStatus_LPSPI_Error)
// {
// PRINTF("This is LPSPI slave transfer completed callback. \r\n");
// PRINTF("Error occured in this transfer. \r\n\r\n");
// }
// else
// {
// __NOP();
// }
//
// isSlaveTransferCompleted = true;
//}

## Data Structure Documentation

struct lpspi_master_config_t

LPSPI master config structure.

Data Fields
uint32_t | baudRate | Baud Rate for lpspi.
uint32_t | betweenTransferDelayInNanoSec | After SCK delay time with nanosecond , set to 0 will set the minimum delay.It woulde set the boundary value if out of range that can be set.
uint32_t | bitsPerFrame | Bits per frame, minimum 8, maximum 4096.
lpspi_clock_phase_t | cpha | Clock phase.
lpspi_clock_polarity_t | cpol | Clock polarity.
lpspi_data_out_config_t | dataOutConfig | Configures if the output data is tristated between accesses (LPSPI_PCS is negated).
lpspi_shift_direction_t | direction | MSB or LSB data shift direction.
uint32_t | lastSckToPcsDelayInNanoSec | Last SCK to PCS delay time with nanosecond , set to 0 will set the minimum delay.It woulde set the boundary value if out of range that can be set.
lpspi_pcs_polarity_config_t | pcsActiveHighOrLow | Desired PCS active high or low
uint32_t | pcsToSckDelayInNanoSec | PCS to SCK delay time with nanosecond , set to 0 will set the minimum delay. It woulde set the boundary value if out of range that can be set.
lpspi_pin_config_t | pinCfg | Configures which pins are used for input and output data during single bit transfers.
lpspi_which_pcs_t | whichPcs | Desired Peripheral Chip Select (pcs)

struct lpspi_slave_config_t

LPSPI slave config structure.

Data Fields
uint32_t | bitsPerFrame | Bits per frame, minimum 8, maximum 4096.
lpspi_clock_phase_t | cpha | Clock phase.
lpspi_clock_polarity_t | cpol | Clock polarity.
lpspi_data_out_config_t | dataOutConfig | Configures if the output data is tristated between accesses (LPSPI_PCS is negated).
lpspi_shift_direction_t | direction | MSB or LSB data shift direction.
lpspi_pcs_polarity_config_t | pcsActiveHighOrLow | Desired PCS active high or low
lpspi_pin_config_t | pinCfg | Configures which pins are used for input and output data during single bit transfers.
lpspi_which_pcs_t | whichPcs | Desired Peripheral Chip Select (pcs)

struct lpspi_transfer_t

LPSPI master/slave transfer structure.

Data Fields
uint32_t | configFlags | Transfer transfer config flags , set from _lpspi_transfer_config_flag_for_master if the transfer is used for master or _lpspi_transfer_config_flag_for_slave enum if the transfer is used for slave.
volatile size_t | dataSize | Transfer bytes.
uint8_t * | rxData | Receive buffer.
uint8_t * | txData | Send buffer.

struct _lpspi_master_handle

LPSPI master transfer handle structure used for transactional API.

Forward declaration of the _lpspi_master_handle typedefs.

Data Fields
LPSPI_Type * | base | LPSPI base address.
volatile uint8_t | bytesEachRead | Bytes for each read RDR .
volatile uint8_t | bytesEachWrite | Bytes for each write TDR .
lpspi_master_transfer_callback_t | callback | Completion callback.
volatile uint8_t | fifoSize | Fifo dataSize.
volatile bool | isByteSwap | A flag that whether should byte swap.
volatile bool | isPcsContinuous | Is PCS continuous in transfer.
volatile uint32_t | readRegRemainingTimes | read RDR register remaining times .
uint8_t *volatile | rxData | Receive buffer.
volatile size_t | rxRemainingByteCount | Number of bytes remaining to receive.
volatile uint8_t | rxWatermark | Rx watermark.
volatile uint8_t | state | LPSPI transfer state , _lpspi_transfer_state.
uint32_t | totalByteCount | Number of transfer bytes
uint32_t | txBuffIfNull | Used if there is not txData for DMA purpose.
uint8_t *volatile | txData | Send buffer.
volatile size_t | txRemainingByteCount | Number of bytes remaining to send.
void * | userData | Callback user data.
volatile uint32_t | writeRegRemainingTimes | write TDR register remaining times .
volatile bool | writeTcrInIsr | A flag that whether should write TCR in ISR.

struct _lpspi_slave_handle

LPSPI slave transfer handle structure used for transactional API.

Forward declaration of the _lpspi_slave_handle typedefs.

Data Fields
LPSPI_Type * | base | LPSPI base address.
volatile uint8_t | bytesEachRead | Bytes for each read RDR .
volatile uint8_t | bytesEachWrite | Bytes for each write TDR .
lpspi_slave_transfer_callback_t | callback | Completion callback.
volatile uint32_t | errorCount | Error count for slave transfer.
volatile uint8_t | fifoSize | Fifo dataSize.
volatile bool | isByteSwap | A flag that whether should byte swap.
volatile uint32_t | readRegRemainingTimes | read RDR register remaining times .
uint8_t *volatile | rxData | Receive buffer.
volatile size_t | rxRemainingByteCount | Number of bytes remaining to receive.
volatile uint8_t | rxWatermark | Rx watermark.
volatile uint8_t | state | LPSPI transfer state , _lpspi_transfer_state.
uint32_t | totalByteCount | Number of transfer bytes
uint8_t *volatile | txData | Send buffer.
volatile size_t | txRemainingByteCount | Number of bytes remaining to send.
void * | userData | Callback user data.
volatile uint32_t | writeRegRemainingTimes | write TDR register remaining times .

## Typedef Documentation

typedef void(* lpspi_master_transfer_callback_t) (LPSPI_Type *base, lpspi_master_handle_t *handle, status_t status, void *userData)

Master completion callback function pointer type.

Parameters

  base | LPSPI peripheral address.
  handle | Pointer to the handle for the LPSPI master.
  status | Success or error code describing whether the transfer completed.
  userData | Arbitrary pointer-dataSized value passed from the application.

typedef void(* lpspi_slave_transfer_callback_t) (LPSPI_Type *base, lpspi_slave_handle_t *handle, status_t status, void *userData)

Slave completion callback function pointer type.

Parameters

  base | LPSPI peripheral address.
  handle | Pointer to the handle for the LPSPI slave.
  status | Success or error code describing whether the transfer completed.
  userData | Arbitrary pointer-dataSized value passed from the application.

## Enumeration Type Documentation

enum _lpspi_dma_enable

LPSPI DMA source.

Enumerator
kLPSPI_TxDmaEnable | Transmit data dma enable
kLPSPI_RxDmaEnable | Receive data dma enable

enum _lpspi_flags

LPSPI status flags in SPIx_SR register.

Enumerator
kLPSPI_TxDataRequestFlag | Transmit data flag
kLPSPI_RxDataReadyFlag | Receive data flag
kLPSPI_WordCompleteFlag | Word Complete flag
kLPSPI_FrameCompleteFlag | Frame Complete flag
kLPSPI_TransferCompleteFlag | Transfer Complete flag
kLPSPI_TransmitErrorFlag | Transmit Error flag (FIFO underrun)
kLPSPI_ReceiveErrorFlag | Receive Error flag (FIFO overrun)
kLPSPI_DataMatchFlag | Data Match flag
kLPSPI_ModuleBusyFlag | Module Busy flag
kLPSPI_AllStatusFlag | Used for clearing all w1c status flags

enum _lpspi_interrupt_enable

LPSPI interrupt source.

Enumerator
kLPSPI_TxInterruptEnable | Transmit data interrupt enable
kLPSPI_RxInterruptEnable | Receive data interrupt enable
kLPSPI_WordCompleteInterruptEnable | Word complete interrupt enable
kLPSPI_FrameCompleteInterruptEnable | Frame complete interrupt enable
kLPSPI_TransferCompleteInterruptEnable | Transfer complete interrupt enable
kLPSPI_TransmitErrorInterruptEnable | Transmit error interrupt enable(FIFO underrun)
kLPSPI_ReceiveErrorInterruptEnable | Receive Error interrupt enable (FIFO overrun)
kLPSPI_DataMatchInterruptEnable | Data Match interrupt enable
kLPSPI_AllInterruptEnable | All above interrupts enable.

enum _lpspi_pcs_polarity

LPSPI Peripheral Chip Select (Pcs) Polarity.

Enumerator
kLPSPI_Pcs0ActiveLow | Pcs0 Active Low (idles high).
kLPSPI_Pcs1ActiveLow | Pcs1 Active Low (idles high).
kLPSPI_Pcs2ActiveLow | Pcs2 Active Low (idles high).
kLPSPI_Pcs3ActiveLow | Pcs3 Active Low (idles high).
kLPSPI_PcsAllActiveLow | Pcs0 to Pcs5 Active Low (idles high).

enum _lpspi_status

Status for the LPSPI driver.

Enumerator
kStatus_LPSPI_Busy | LPSPI transfer is busy.
kStatus_LPSPI_Error | LPSPI driver error.
kStatus_LPSPI_Idle | LPSPI is idle.
kStatus_LPSPI_OutOfRange | LPSPI transfer out Of range.

enum _lpspi_transfer_config_flag_for_master

Can use this enum for LPSPI master transfer configFlags.

Enumerator
kLPSPI_MasterPcs0 | LPSPI master xfer use PCS0 signal
kLPSPI_MasterPcs1 | LPSPI master xfer use PCS1 signal
kLPSPI_MasterPcs2 | LPSPI master xfer use PCS2 signal
kLPSPI_MasterPcs3 | LPSPI master xfer use PCS3 signal
kLPSPI_MasterPcsContinuous | Is PCS signal continuous

kLPSPI_MasterByteSwap

LPSPI master transfer byte order would be the same with the bitPerFrame which is set to 8 if use this flag. For instance , you want to send data is : 1 2 3 4 5 6 7 8 (set lpspi_shift_direction_t to MSB) if set bitPerFrame = 8 , the waveform is 1 2 3 4 5 6 7 8 ; if set bitPerFrame = 64 , the waveform would be 4 3 2 1 8 7 6 5 ( do not use the kLPSPI_MasterByteSwap flag); or the waveform would be 1 2 3 4 5 6 7 8 (use the kLPSPI_MasterByteSwap flag in transfer structure)

enum _lpspi_transfer_config_flag_for_slave

Can use this enum for LPSPI slave transfer configFlags.

Enumerator
kLPSPI_SlavePcs0 | LPSPI slave xfer use PCS0 signal
kLPSPI_SlavePcs1 | LPSPI slave xfer use PCS1 signal
kLPSPI_SlavePcs2 | LPSPI slave xfer use PCS2 signal
kLPSPI_SlavePcs3 | LPSPI slave xfer use PCS3 signal

kLPSPI_SlaveByteSwap

LPSPI slave transfer byte order would be the same with the bitPerFrame which is set to 8 if use this flag. For instance , you want to send data is : 1 2 3 4 5 6 7 8 (set lpspi_shift_direction_t to MSB) if set bitPerFrame = 8 , the waveform is 1 2 3 4 5 6 7 8 ; if set bitPerFrame = 64 , the waveform would be 4 3 2 1 8 7 6 5 ( do not use the kLPSPI_MasterByteSwap flag); or the waveform would be 1 2 3 4 5 6 7 8 (use the kLPSPI_MasterByteSwap flag in transfer structure)

enum _lpspi_transfer_state

LPSPI transfer state, which is used for LPSPI transactiaonl APIs' state machine.

Enumerator
kLPSPI_Idle | Nothing in the transmitter/receiver.
kLPSPI_Busy | Transfer queue is not finished.
kLPSPI_Error | Transfer error.

enum lpspi_clock_phase_t

LPSPI clock phase configuration.

Enumerator
kLPSPI_ClockPhaseFirstEdge | CPHA=0. Data is captured on the leading edge of the SCK and changed on the following edge.
kLPSPI_ClockPhaseSecondEdge | CPHA=1. Data is changed on the leading edge of the SCK and captured on the following edge.

enum lpspi_clock_polarity_t

LPSPI clock polarity configuration.

Enumerator
kLPSPI_ClockPolarityActiveHigh | CPOL=0. Active-high LPSPI clock (idles low)
kLPSPI_ClockPolarityActiveLow | CPOL=1. Active-low LPSPI clock (idles high)

enum lpspi_data_out_config_t

LPSPI data output configuration.

Enumerator
kLpspiDataOutRetained | Data out retains last value when chip select de-asserted
kLpspiDataOutTristate | Data out is tristated when chip select de-asserted

enum lpspi_delay_type_t

LPSPI delay type selection.

Enumerator
kLPSPI_PcsToSck | Pcs-to-SCK delay.
kLPSPI_LastSckToPcs | Last SCK edge to Pcs delay.
kLPSPI_BetweenTransfer | Delay between transfers.

enum lpspi_host_request_select_t

LPSPI Host Request select configuration.

Enumerator
kLPSPI_HostReqExtPin | Host Request is an ext pin.
kLPSPI_HostReqInternalTrigger | Host Request is an internal trigger.

enum lpspi_master_slave_mode_t

LPSPI master or slave mode configuration.

Enumerator
kLPSPI_Master | LPSPI peripheral operates in master mode.
kLPSPI_Slave | LPSPI peripheral operates in slave mode.

enum lpspi_match_config_t

LPSPI Match configuration options.

Enumerator
kLPSI_MatchDisabled | LPSPI Match Disabled.
kLPSI_1stWordEqualsM0orM1 | LPSPI Match Enabled.
kLPSI_AnyWordEqualsM0orM1 | LPSPI Match Enabled.
kLPSI_1stWordEqualsM0and2ndWordEqualsM1 | LPSPI Match Enabled.
kLPSI_AnyWordEqualsM0andNxtWordEqualsM1 | LPSPI Match Enabled.
kLPSI_1stWordAndM1EqualsM0andM1 | LPSPI Match Enabled.
kLPSI_AnyWordAndM1EqualsM0andM1 | LPSPI Match Enabled.

enum lpspi_pcs_polarity_config_t

LPSPI Peripheral Chip Select (Pcs) Polarity configuration.

Enumerator
kLPSPI_PcsActiveHigh | Pcs Active High (idles low)
kLPSPI_PcsActiveLow | Pcs Active Low (idles high)

enum lpspi_pin_config_t

LPSPI pin (SDO and SDI) configuration.

Enumerator
kLPSPI_SdiInSdoOut | LPSPI SDI input, SDO output.
kLPSPI_SdoInSdoOut | LPSPI SDO input, SDO output.
kLPSPI_SdiInSdiOut | LPSPI SDI input, SDI output.
kLPSPI_SdoInSdiOut | LPSPI SDO input, SDI output.

enum lpspi_shift_direction_t

LPSPI data shifter direction options.

Enumerator
kLPSPI_MsbFirst | Data transfers start with most significant bit.
kLPSPI_LsbFirst | Data transfers start with least significant bit.

enum lpspi_transfer_width_t

LPSPI transfer width configuration.

Enumerator
kLPSPI_SingleBitXfer | 1-bit shift at a time, data out on SDO, in on SDI (normal mode)
kLPSPI_TwoBitXfer | 2-bits shift out on SDO/SDI and in on SDO/SDI
kLPSPI_FourBitXfer | 4-bits shift out on SDO/SDI/PCS[3:2] and in on SDO/SDI/PCS[3:2]

enum lpspi_which_pcs_t

LPSPI Peripheral Chip Select (Pcs) configuration (which Pcs to configure).

Enumerator
kLPSPI_Pcs0 | Pcs[0]
kLPSPI_Pcs1 | Pcs[1]
kLPSPI_Pcs2 | Pcs[2]
kLPSPI_Pcs3 | Pcs[3]

## Function Documentation

static void LPSPI_ClearStatusFlags | ( | LPSPI_Type * | base,
|  | uint32_t | statusFlags
| ) |  |

inlinestatic

Clears the LPSPI status flag.

This function clears the desired status bit by using a write-1-to-clear. The user passes in the base and the desired status flag bit to clear. The list of status flags is defined in the _lpspi_flags. Example usage:

LPSPI_ClearStatusFlags(base, kLPSPI_TxDataRequestFlag|kLPSPI_RxDataReadyFlag);

Parameters

  base | LPSPI peripheral address.
  statusFlags | The status flag , used from type _lpspi_flags.

< The status flags are cleared by writing 1 (w1c).

void LPSPI_Deinit | ( | LPSPI_Type * | base | ) |

De-initialize the LPSPI peripheral, call this API to disbale the lpspi clock.

Parameters

  base | LPSPI peripheral address.

static void LPSPI_DisableDMA | ( | LPSPI_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Disable the LPSPI DMA request.

This function configures the Rx and Tx DMA mask of the LPSPI. The parameters are base, DMA mask.

SPI_DisableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);

Parameters

  base | LPSPI peripheral address.
  mask | The interrupt mask, can use the enum _lpspi_dma_enable.

static void LPSPI_DisableInterrupts | ( | LPSPI_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Disable the LPSPI interrupts.

LPSPI_DisableInterrupts(base, kLPSPI_TxInterruptEnable | kLPSPI_RxInterruptEnable );

Parameters

  base | LPSPI peripheral address.
  mask | The interrupt mask, can use the enum _lpspi_interrupt_enable.

static void LPSPI_Enable | ( | LPSPI_Type * | base,
|  | bool | enable
| ) |  |

inlinestatic

Enables the LPSPI peripheral and sets the MCR MDIS to 0.

Parameters

  base | LPSPI peripheral address.
  enable | pass true to enable module, false to disable module.

static void LPSPI_EnableDMA | ( | LPSPI_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Enable the LPSPI DMA request.

This function configures the Rx and Tx DMA mask of the LPSPI. The parameters are base, DMA mask.

LPSPI_EnableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);

Parameters

  base | LPSPI peripheral address.
  mask | The interrupt mask, can use the enum _lpspi_dma_enable.

static void LPSPI_EnableInterrupts | ( | LPSPI_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Enable the LPSPI interrupts.

This function configures the various interrupt masks of the LPSPI. The parameters are base, interrupt mask. Note, for Tx Fill and Rx FIFO Drain requests, enable the interrupt request will disable the DMA request in the meanwhile.

LPSPI_EnableInterrupts(base, kLPSPI_TxInterruptEnable | kLPSPI_RxInterruptEnable );

Parameters

  base | LPSPI peripheral address.
  mask | The interrupt mask, can use the enum _lpspi_interrupt_enable.

static void LPSPI_FlushFifo | ( | LPSPI_Type * | base,
|  | bool | flushTxFifo,
|  | bool | flushRxFifo
| ) |  |

inlinestatic

Flushes the LPSPI FIFOs.

Parameters

  base | LPSPI peripheral address.
  flushTxFifo | Flushes (true) the Tx FIFO, else do not flush (false) the Tx FIFO
  flushRxFifo | Flushes (true) the Rx FIFO, else do not flush (false) the Rx FIFO

static uint32_t LPSPI_GetRxFifoCount | ( | LPSPI_Type * | base | ) |

inlinestatic

Gets the LPSPI Rx FIFO count.

Parameters

  base | LPSPI peripheral address.

Returns
  The number of words in the receive FIFO.

static uint32_t LPSPI_GetRxFifoSize | ( | LPSPI_Type * | base | ) |

inlinestatic

Gets the LPSPI Rx FIFO size.

Parameters

  base | LPSPI peripheral address.

Returns
  The LPSPI Rx FIFO size.

static uint32_t LPSPI_GetRxRegisterAddress | ( | LPSPI_Type * | base | ) |

inlinestatic

Gets the LPSPI Receive Data Register address for DMA operation.

This function gets the LPSPI Receive Data Register address as this value is needed for the DMA operation. This function can be used for either master or slave mode.

Parameters

  base | LPSPI peripheral address.

Returns
  The LPSPI Receive Data Register address

static uint32_t LPSPI_GetStatusFlags | ( | LPSPI_Type * | base | ) |

inlinestatic

Gets the LPSPI status flag state.

Parameters

  base | LPSPI peripheral address.

Returns
  The LPSPI status(in SR register).

static uint32_t LPSPI_GetTxFifoCount | ( | LPSPI_Type * | base | ) |

inlinestatic

Gets the LPSPI Tx FIFO count.

Parameters

  base | LPSPI peripheral address.

Returns
  The number of words in the transmit FIFO.

static uint32_t LPSPI_GetTxFifoSize | ( | LPSPI_Type * | base | ) |

inlinestatic

Gets the LPSPI Tx FIFO size.

Parameters

  base | LPSPI peripheral address.

Returns
  The LPSPI Tx FIFO size.

static uint32_t LPSPI_GetTxRegisterAddress | ( | LPSPI_Type * | base | ) |

inlinestatic

Gets the LPSPI Transmit Data Register address for DMA operation.

This function gets the LPSPI Transmit Data Register address as this value is needed for the DMA operation. This function can be used for either master or slave mode.

Parameters

  base | LPSPI peripheral address.

Returns
  The LPSPI Transmit Data Register address

static bool LPSPI_IsMaster | ( | LPSPI_Type * | base | ) |

inlinestatic

Returns whether the LPSPI module is in master mode.

Parameters

  base | LPSPI peripheral address.

Returns
  Returns true if the module is in master mode or false if the module is in slave mode.

void LPSPI_MasterAbortTransfer | ( | LPSPI_Type * | base,
|  | lpspi_master_handle_t * | handle
| ) |  |

LPSPI master abort transfer which using interrupt.

This function abort transfer which using interrupt.

Parameters

  base | LPSPI peripheral address.
  handle | pointer to lpspi_master_handle_t structure which stores the transfer state.

void LPSPI_MasterCreateHandle | ( | LPSPI_Type * | base,
|  | lpspi_master_handle_t * | handle,
|  | lpspi_master_transfer_callback_t | callback,
|  | void * | userData
| ) |  |

Initialize the lpspi master handle.

This function initializes the LPSPI handle which can be used for other LPSPI transactional APIs. Usually, for a specified LPSPI instance, user need only call this API once to get the initialized handle.

Parameters

  base | LPSPI peripheral address.
  handle | LPSPI handle pointer to lpspi_master_handle_t.
  callback | dspi callback.
  userData | callback function parameter.

void LPSPI_MasterGetDefaultConfig | ( | lpspi_master_config_t * | masterConfig | ) |

Set the lpspi_master_config_t structure to default values.

The purpose of this API is to get the config structure initialized for LPSPI_MasterInit(). User may use the initialized structure unchanged in LPSPI_MasterInit(), or modify some fields of the structure before calling LPSPI_MasterInit(). Example:

lpspi_master_config_t masterConfig;
LPSPI_MasterGetDefaultConfig(&masterConfig);

Parameters

  masterConfig | pointer to lpspi_master_config_t structure

status_t LPSPI_MasterGetTransferCount | ( | LPSPI_Type * | base,
|  | lpspi_master_handle_t * | handle,
|  | size_t * | count
| ) |  |

Get the master transfer remaining bytes.

This function get the master transfer remaining bytes.

Parameters

  base | LPSPI peripheral address.
  handle | pointer to lpspi_master_handle_t structure which stores the transfer state.
  count | Number of bytes transferred so far by the non-blocking transaction.

Returns
  status of status_t.

void LPSPI_MasterHandleInterrupt | ( | LPSPI_Type * | base,
|  | lpspi_master_handle_t * | handle
| ) |  |

LPSPI Master IRQ handler function.

This function process the LPSPI transmit and receive IRQ.

Parameters

  base | LPSPI peripheral address.
  handle | pointer to lpspi_master_handle_t structure which stores the transfer state.

void LPSPI_MasterInit | ( | LPSPI_Type * | base,
|  | const lpspi_master_config_t * | masterConfig,
|  | uint32_t | srcClock_Hz
| ) |  |

LPSPI master Init.

Parameters

  base | LPSPI peripheral address.
  masterConfig | Pointer to structure lpspi_master_config_t.
  srcClock_Hz | Module source input clock in Hertz

uint32_t LPSPI_MasterSetBaudRate | ( | LPSPI_Type * | base,
|  | uint32_t | baudRate_Bps,
|  | uint32_t | srcClock_Hz,
|  | uint32_t * | tcrPrescaleValue
| ) |  |

Sets the LPSPI baud rate in bits per second.

This function takes in the desired bitsPerSec (baud rate) and calculates the nearest possible baud rate without exceeding the desired baud rate, and returns the calculated baud rate in bits-per-second. It requires that the caller also provide the frequency of the module source clock (in Hertz). Also note that the baud rate does not go into effect until the Transmit Control Register (TCR) is programmed with the prescale value. Hence, this function returns the prescale tcrPrescaleValue parameter for later programming in the TCR. The higher level peripheral driver should alert the user of an out of range baud rate input.

Note that the LPSPI module must first be disabled before configuring this. Note that the LPSPI module must be configured for master mode before configuring this.

Parameters

  base | LPSPI peripheral address.
  baudRate_Bps | The desired baud rate in bits per second
  srcClock_Hz | Module source input clock in Hertz
  tcrPrescaleValue | The TCR prescale value, needed by user to program the TCR

Returns
  The actual calculated baud rate. This function may also return a "0" if the LPSPI is not configured for master mode or if the LPSPI module is not disabled.

void LPSPI_MasterSetDelayScaler | ( | LPSPI_Type * | base,
|  | uint32_t | scaler,
|  | lpspi_delay_type_t | whichDelay
| ) |  |

Manually configures a specific LPSPI delay parameter (module must be disabled to change the delay values).

This function configures the following: SCK to PCS delay, or PCS to SCK delay, or The configurations must occur between the transfer delay.

The delay names are available in type lpspi_delay_type_t.

The user passes the desired delay along with the delay value. This allows the user to directly set the delay values if they have pre-calculated them or if they simply wish to manually increment the value.

Note that the LPSPI module must first be disabled before configuring this. Note that the LPSPI module must be configured for master mode before configuring this.

Parameters

  base | LPSPI peripheral address.
  scaler | The 8-bit delay value 0x00 to 0xFF (255)
  whichDelay | The desired delay to configure, must be of type lpspi_delay_type_t

uint32_t LPSPI_MasterSetDelayTimes | ( | LPSPI_Type * | base,
|  | uint32_t | delayTimeInNanoSec,
|  | lpspi_delay_type_t | whichDelay,
|  | uint32_t | srcClock_Hz
| ) |  |

Calculates the delay based on the desired delay input in nanoseconds (module must be disabled to change the delay values).

This function calculates the values for the following: SCK to PCS delay, or PCS to SCK delay, or The configurations must occur between the transfer delay.

The delay names are available in type lpspi_delay_type_t.

The user passes the desired delay and the desired delay value in nano-seconds. The function calculates the value needed for the desired delay parameter and returns the actual calculated delay because an exact delay match may not be possible. In this case, the closest match is calculated without going below the desired delay value input. It is possible to input a very large delay value that exceeds the capability of the part, in which case the maximum supported delay is returned. It is up to the higher level peripheral driver to alert the user of an out of range delay input.

Note that the LPSPI module must first be disabled before configuring this. Note that the LPSPI module must be configured for master mode before configuring this.

Parameters

  base | LPSPI peripheral address.
  delayTimeInNanoSec | The desired delay value in nano-seconds.
  whichDelay | The desired delay to configure, must be of type lpspi_delay_type_t
  srcClock_Hz | Module source input clock in Hertz

Returns
  actual calculated delay value in nano-seconds

status_t LPSPI_MasterTransferBlocking | ( | LPSPI_Type * | base,
|  | lpspi_transfer_t * | transfer
| ) |  |

LPSPI master transfer data using polling.

This function transfer data with polling, this is blocking function, will not return until all transfer have been completed.

Note: The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4 . For bytesPerFrame greater than 4 situation: the transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not integer multiples of 4 , otherwise , the transfer data size can be integer multiples of bytesPerFrame.

Parameters

  base | LPSPI peripheral address.
  transfer | pointer to lpspi_transfer_t structure.

Returns
  status of status_t.

status_t LPSPI_MasterTransferNonBlocking | ( | LPSPI_Type * | base,
|  | lpspi_master_handle_t * | handle,
|  | lpspi_transfer_t * | transfer
| ) |  |

LPSPI master transfer data using interrupt.

This function transfer data using interrupt , this is non-blocking function, will return right away, when all data have been transfer, the callback function will be called.

Note: The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4 . For bytesPerFrame greater than 4 situation: the transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not integer multiples of 4 , otherwise , the transfer data size can be integer multiples of bytesPerFrame.

Parameters

  base | LPSPI peripheral address.
  handle | pointer to lpspi_master_handle_t structure which stores the transfer state.
  transfer | pointer to lpspi_transfer_t structure.

Returns
  status of status_t.

static uint32_t LPSPI_ReadDataNonBlocking | ( | LPSPI_Type * | base | ) |

inlinestatic

Reads data from the data buffer.

This function reads the data from the Receive Data Register (RDR). This function can be used for either master or slave mode.

Parameters

  base | LPSPI peripheral address.

Returns
  The data read from the data buffer

void LPSPI_Reset | ( | LPSPI_Type * | base | ) |

Restores the LPSPI peripheral to reset state, notice that this function will set all the registers to reset state so the LPSPI module can not work after calling this API.

Parameters

  base | LPSPI peripheral address.

static void LPSPI_SetAllPcsPolarity | ( | LPSPI_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

Configures all the LPSPI peripheral chip select polarity simultaneously.

Note that the CFGR1 should only be written when the LPSPI is disabled (LPSPIx_CR_MEN = 0).

This is an example: PCS0,PCS1 set to active low and other PCS set to active high. Please note that the number of PCS is specific to the device.

LPSPI_SetAllPcsPolarity(base, kLPSPI_Pcs0ActiveLow | kLPSPI_Pcs1ActiveLow);

Parameters

  base | LPSPI peripheral address.
  mask | The PCS polarity mask , can use the enum _lpspi_pcs_polarity.

static void LPSPI_SetFifoWatermarks | ( | LPSPI_Type * | base,
|  | uint32_t | txWater,
|  | uint32_t | rxWater
| ) |  |

inlinestatic

Sets the transmit and receive FIFO watermark values.

This function allows the user to set the receive and transmit FIFO watermarks. The function does not compare the watermark setting to the FIFO size. The FIFO watermark should not be equal to or greater than the FIFO size. It is up to the higher level driver to make this check.

Parameters

  base | LPSPI peripheral address.
  txWater | The TX FIFO watermark value . Writing a value equal or greater than the FIFO size will be truncated.
  rxWater | The RX FIFO watermark value . Writing a value equal or greater than the FIFO size will be truncated.

static void LPSPI_SetFrameSize | ( | LPSPI_Type * | base,
|  | uint32_t | frameSize
| ) |  |

inlinestatic

Configures the frame size .

The minimum frame size is 8-bits and the maximum frame size is 4096-bits. If the frame size is less than or equal to 32-bits, the word size and frame size are identical. If the frame size is greater than 32-bits, then the word size is 32-bits for each word except the last (the last word contains the remainder bits if the frame size is not divisible by 32). The minimum word size is 2-bits, a frame size of 33-bits (or similar) is not supported.

Note 1 : the transmit command register should be initialized before enabling the LPSPI in slave mode, although the command register will not update until after the LPSPI is enabled. Once enabled, the transmit command register should only be changed if the LPSPI is idle.

Note 2 : The transmit and command FIFO is a combined FIFO that includes both transmit data and command words. That means the TCR register shoule be write when the Tx Fifo is not full.

Parameters

  base | LPSPI peripheral address.
  frameSize | The frame size in number of bits.

static void LPSPI_SetMasterSlaveMode | ( | LPSPI_Type * | base,
|  | lpspi_master_slave_mode_t | mode
| ) |  |

inlinestatic

Configures the LPSPI for master or slave.

Note that the CFGR1 should only be written when the LPSPI is disabled (LPSPIx_CR_MEN = 0).

Parameters

  base | LPSPI peripheral address.
  mode | Mode setting (master or slave) of type lpspi_master_slave_mode_t.

void LPSPI_SlaveAbortTransfer | ( | LPSPI_Type * | base,
|  | lpspi_slave_handle_t * | handle
| ) |  |

LPSPI slave abort transfer which using interrupt.

This function abort transfer which using interrupt.

Parameters

  base | LPSPI peripheral address.
  handle | pointer to lpspi_slave_handle_t structure which stores the transfer state.

void LPSPI_SlaveCreateHandle | ( | LPSPI_Type * | base,
|  | lpspi_slave_handle_t * | handle,
|  | lpspi_slave_transfer_callback_t | callback,
|  | void * | userData
| ) |  |

Initialize the lpspi slave handle.

This function initializes the LPSPI handle which can be used for other LPSPI transactional APIs. Usually, for a specified LPSPI instance, user need only call this API once to get the initialized handle.

Parameters

  base | LPSPI peripheral address.
  handle | LPSPI handle pointer to lpspi_slave_handle_t.
  callback | dspi callback.
  userData | callback function parameter.

void LPSPI_SlaveGetDefaultConfig | ( | lpspi_slave_config_t * | slaveConfig | ) |

Set the lpspi_slave_config_t structure to default values.

The purpose of this API is to get the config structure initialized for LPSPI_SlaveInit(). User may use the initialized structure unchanged in LPSPI_SlaveInit(), or modify some fields of the structure before calling LPSPI_SlaveInit(). Example:

lpspi_slave_config_t slaveConfig;
LPSPI_SlaveGetDefaultConfig(&slaveConfig);

Parameters

  slaveConfig | pointer to lpspi_slave_config_t structure.

< Bits per frame, minimum 4, maximum 16.

< Clock polarity.

< Clock phase.

< MSB or LSB data shift direction.

< Desired Peripheral Chip Select (pcs)

< Desired PCS active high or low

status_t LPSPI_SlaveGetTransferCount | ( | LPSPI_Type * | base,
|  | lpspi_slave_handle_t * | handle,
|  | size_t * | count
| ) |  |

Get the slave transfer remaining bytes.

This function get the slave transfer remaining bytes.

Parameters

  base | LPSPI peripheral address.
  handle | pointer to lpspi_slave_handle_t structure which stores the transfer state.
  count | Number of bytes transferred so far by the non-blocking transaction.

Returns
  status of status_t.

void LPSPI_SlaveHandleInterrupt | ( | LPSPI_Type * | base,
|  | lpspi_slave_handle_t * | handle
| ) |  |

LPSPI Slave IRQ handler function.

This function process the LPSPI transmit and receive IRQ.

Parameters

  base | LPSPI peripheral address.
  handle | pointer to lpspi_slave_handle_t structure which stores the transfer state.

void LPSPI_SlaveInit | ( | LPSPI_Type * | base,
|  | const lpspi_slave_config_t * | slaveConfig
| ) |  |

LPSPI slave configuration.

Parameters

  base | LPSPI peripheral address.
  slaveConfig | Pointer to structure lpspi_slave_config_t.

status_t LPSPI_SlaveTransferNonBlocking | ( | LPSPI_Type * | base,
|  | lpspi_slave_handle_t * | handle,
|  | lpspi_transfer_t * | transfer
| ) |  |

LPSPI slave transfer data using interrupt.

This function transfer data using interrupt , this is non-blocking function, will return right away, when all data have been transfer, the callback function will be called.

Note: The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4 . For bytesPerFrame greater than 4 situation: the transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not integer multiples of 4 , otherwise , the transfer data size can be integer multiples of bytesPerFrame.

Parameters

  base | LPSPI peripheral address.
  handle | pointer to lpspi_slave_handle_t structure which stores the transfer state.
  transfer | pointer to lpspi_transfer_t structure.

Returns
  status of status_t.

static void LPSPI_WriteDataNonBlocking | ( | LPSPI_Type * | base,
|  | uint32_t | data
| ) |  |

inlinestatic

Writes data into the transmit data buffer.

This function writes data passed in by the user to the Transmit Data Register (TDR). The user can pass up to 32-bits of data to load into the TDR. If the frame size exceeds 32-bits, the user has to manage sending the data one 32-bit word at a time. Any writes to the TDR result in an immediate push to the transmit FIFO. This function can be used for either master or slave modes.

Parameters

  base | LPSPI peripheral address.
  data | The data word to be sent