InPlay API
SPI device driver

HAL_SPI. More...

Enumerations

enum  spi_id { MSPI_ID, SSPI0_ID, SSPI1_ID }
 SPI ID. More...
 
enum  spi_fmt { SPI_STD_FMT, SPI_DUAL_FMT, SPI_QUAD_FMT }
 SPI format. More...
 
enum  spi_tmod { SPI_TMOD_TX_AND_RX, SPI_TMOD_TX_ONLY, SPI_TMOD_RX_ONLY, SPI_TMOD_EEPROM_READ }
 SPI transfer mode. More...
 
enum  spi_dfs_bit
 SPI data frame size.
 
enum  spi_err
 SPI error code.
 
enum  spi_dir
 SPI DMA direction.
 
enum  spi_mstr_cs
 SPI CS (master only)
 
enum  qspi_cmd_width
 Dual or Quad SPI command width.
 
enum  qspi_addr_width
 Dual or Quad SPI address width.
 
enum  qspi_ttype
 Quad SPI command and address transfer type.
 

Functions

void * hal_spi_open (int id, int speed, int phase, int polarity, int prio)
 Open the SPI driver. More...
 
int hal_spi_close (void *hdl)
 Close the SPI driver. More...
 
int hal_spi_int_prio (void *hdl, int prio)
 Set SPI interrupt priority. More...
 
int hal_spi_tx_non_block (void *hdl, int cs, int dfs, void *buffer, uint16_t buffer_len, void *arg, void(*callback)(void *arg, int status, uint16_t size))
 Master or Slave SPI transmit function. More...
 
int hal_spi_rx_non_block (void *hdl, int cs, int dfs, void *buffer, uint16_t buffer_len, void *arg, void(*callback)(void *arg, int status, uint16_t size))
 Master or Slave SPI Receive function. More...
 
int hal_spi_trx_non_block (void *hdl, int cs, int dfs, void *wbuf, void *rbuf, uint16_t buf_len, void *arg, void(*callback)(void *arg, int status, uint16_t actual_size))
 Master or Slave SPI Transmit and Receive function (bi-direction) More...
 
int hal_spi_tx_dma (void *hdl, int cs, void *buffer, uint16_t buffer_len, uint16_t *actual_size)
 Master or Slave SPI transmit DMA function. More...
 
int hal_spi_rx_dma (void *hdl, int cs, void *buffer, uint16_t buffer_len, uint16_t *actual_size)
 Master or Slave SPI Receive DMA function. More...
 
int hal_spi_trx_dma (void *hdl, int cs, void *wbuf, void *rbuf, uint16_t buffer_len, uint16_t *actual_size)
 Master or Slave SPI Transmit and Receive DMA function (bi-direction) More...
 
int hal_slv_spi_tx (void *hdl, int phase, int polarity, int dfs, void *buf, uint16_t buf_len, uint16_t *wlen)
 Slave SPI transmit function. More...
 
int hal_slv_spi_rx (void *hdl, int phase, int polarity, int dfs, void *buf, uint16_t buf_len, uint16_t *rlen)
 Slave SPI Receive function. More...
 
int hal_slv_spi_trx (void *hdl, int phase, int polarity, int dfs, void *wbuf, void *rbuf, uint16_t buf_len, uint16_t *wlen, uint16_t *rlen)
 Slave SPI Transmit and Receive function (bi-direction) More...
 
void hal_slv_spi_stop (void *hdl)
 Slave SPI stop function. More...
 
int hal_spi_busy (void *hdl)
 Get SPI busy status. More...
 
int hal_spi_trx_dma_chain_start (void *hdl, int cs, int speed, int phase, int polarity, int dfs, void *wbuf[2], void *rbuf[2], uint16_t buffer_len, void *arg, void(*callback)(void *arg, int dir, int id, int status))
 Master SPI Transmit and Receive DMA block chain function (bi-direction) More...
 
int hal_spi_trx_dma_chain_stop (void *hdl)
 Master or Slave SPI Transmit and Receive DMA block chain function (bi-direction) More...
 

Detailed Description

HAL_SPI.

Enumeration Type Documentation

◆ spi_fmt

enum spi_fmt

SPI format.

Enumerator
SPI_STD_FMT 

Standard.

SPI_DUAL_FMT 

Dual format with 2 data wire.

SPI_QUAD_FMT 

Quad format with 4 data wire.

◆ spi_id

enum spi_id

SPI ID.

Enumerator
MSPI_ID 

Master SPI Id.

SSPI0_ID 

Slave SPI Id.

SSPI1_ID 

Slave SPI Id.

◆ spi_tmod

enum spi_tmod

SPI transfer mode.

Enumerator
SPI_TMOD_TX_AND_RX 

Transfer in bi-direction mode.

SPI_TMOD_TX_ONLY 

Tranfer in TX mode only.

SPI_TMOD_RX_ONLY 

Transfer in RX mode only.

SPI_TMOD_EEPROM_READ 

Transfer in EEPROM.

Function Documentation

◆ hal_slv_spi_rx()

int hal_slv_spi_rx ( void *  hdl,
int  phase,
int  polarity,
int  dfs,
void *  buf,
uint16_t  buf_len,
uint16_t *  rlen 
)

Slave SPI Receive function.

Note
  1. SPI slave can receive multiple uint within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]bufferThe void pointer point to the RX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buffer_lenThe RX buffer length.
[out]rlenActual RX length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_slv_spi_stop()

void hal_slv_spi_stop ( void *  hdl)

Slave SPI stop function.

Parameters
[in]hdlThe handle from the "open" function call.
Returns
None.

◆ hal_slv_spi_trx()

int hal_slv_spi_trx ( void *  hdl,
int  phase,
int  polarity,
int  dfs,
void *  wbuf,
void *  rbuf,
uint16_t  buf_len,
uint16_t *  wlen,
uint16_t *  rlen 
)

Slave SPI Transmit and Receive function (bi-direction)

Note
  1. For SPI slave transmit, the master needs to provide the "Slave Select" signal. The SPI slave will transmit one unit (could be byte, short, or long depends on the data frame size) out per "Slave Select" signal. SPI slave can't do multiple transfer within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]wbufThe void pointer point to the TX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]rbufThe void pointer point to the RX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buf_lenThe TX and RX buffer length.
[out]wlenActual TX length.
[out]rlenActual RX length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_slv_spi_tx()

int hal_slv_spi_tx ( void *  hdl,
int  phase,
int  polarity,
int  dfs,
void *  buf,
uint16_t  buf_len,
uint16_t *  wlen 
)

Slave SPI transmit function.

Experimental slave SPI API

Note
  1. For SPI slave transmit, the master needs to provide the "Slave Select" signal. The SPI slave will transmit one unit (could be byte, short, or long depends on the data frame size) out per "Slave Select" signal. SPI slave can't do multiple transfer within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]bufferThe void pointer point to the TX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buffer_lenThe TX buffer length.
[out]wlenActual TX length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_busy()

int hal_spi_busy ( void *  hdl)

Get SPI busy status.

Parameters
[in]hdlThe handle from the "open" function call.
Returns
1 if busy, otherwise 0

◆ hal_spi_close()

int hal_spi_close ( void *  hdl)

Close the SPI driver.

Parameters
[in]hdlThe handle from the "open" function call.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_int_prio()

int hal_spi_int_prio ( void *  hdl,
int  prio 
)

Set SPI interrupt priority.

Parameters
[in]hdlThe handle from the "open" function call.
[in]prioInterrupt priority.
See also
in_irq.h.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_open()

void* hal_spi_open ( int  id,
int  speed,
int  phase,
int  polarity,
int  prio 
)

Open the SPI driver.

Parameters
[in]idThe SPI ID,
See also
enum spi_id.
Returns
Handle to the SPI driver, NULL means open failed.

◆ hal_spi_rx_dma()

int hal_spi_rx_dma ( void *  hdl,
int  cs,
void *  buffer,
uint16_t  buffer_len,
uint16_t *  actual_size 
)

Master or Slave SPI Receive DMA function.

Note
  1. SPI slave can receive multiple uint within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]csThe SPI slave select. This is only valid for master SPI and the possible value are 0 or 1.
[in]speedThe SPI serial clock rate. They can be 16, 8, 4, 2, or 1 Mhz. Only for master.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]bufferThe void pointer point to the RX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buffer_lenThe RX buffer length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_rx_non_block()

int hal_spi_rx_non_block ( void *  hdl,
int  cs,
int  dfs,
void *  buffer,
uint16_t  buffer_len,
void *  arg,
void(*)(void *arg, int status, uint16_t size)  callback 
)

Master or Slave SPI Receive function.

Note
  1. SPI slave can receive multiple uint within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]csThe SPI slave select. This is only valid for master SPI and the possible value are 0 or 1.
[in]speedThe SPI serial clock rate. They can be 16, 8, 4, 2, or 1 Mhz. Only for master.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]bufferThe void pointer point to the RX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buffer_lenThe RX buffer length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_trx_dma()

int hal_spi_trx_dma ( void *  hdl,
int  cs,
void *  wbuf,
void *  rbuf,
uint16_t  buffer_len,
uint16_t *  actual_size 
)

Master or Slave SPI Transmit and Receive DMA function (bi-direction)

Note
  1. For SPI slave transmit, the master needs to provide the "Slave Select" signal. The SPI slave will transmit one unit (could be byte, short, or long depends on the data frame size) out per "Slave Select" signal. SPI slave can't do multiple transfer within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]csThe SPI slave select. This is only valid for master SPI and the possible value are 0 or 1.
[in]speedThe SPI serial clock rate. They can be 16, 8, 4, 2, or 1 Mhz. Only for master.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]wbufThe void pointer point to the TX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]rbufThe void pointer point to the RX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buffer_lenThe TX and RX buffer length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_trx_dma_chain_start()

int hal_spi_trx_dma_chain_start ( void *  hdl,
int  cs,
int  speed,
int  phase,
int  polarity,
int  dfs,
void *  wbuf[2],
void *  rbuf[2],
uint16_t  buffer_len,
void *  arg,
void(*)(void *arg, int dir, int id, int status)  callback 
)

Master SPI Transmit and Receive DMA block chain function (bi-direction)

Note
  1. This is to start the DMA block chaining. The SPI's TX/RX FIFO will be automatically filled/emptied by the DMA.
  2. While user handles the ping buffer, the DMA will handle the pong buffer
  1. The ping/pong scheme will continuously transfer data to/from slave which means the slave selected signal will be always low.
Parameters
[in]hdlThe handle from the "open" function call.
[in]csThe SPI slave select. This is only valid for master SPI and the possible value are 0 or 1.
[in]speedThe SPI serial clock rate. They can be 16, 8, 4, 2, or 1 Mhz. Only for master.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]wbufThe ping/pong buffers pointer array for the TX. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]rbufThe ping/pong buffer pointer array for the RX. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buffer_lenThe ping/pong buffer size.
[in]argThe user provided argument for the ping/pong completed call back function.
[in]callbackThe user provided ping/pong completed call back function:
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_trx_dma_chain_stop()

int hal_spi_trx_dma_chain_stop ( void *  hdl)

Master or Slave SPI Transmit and Receive DMA block chain function (bi-direction)

Note
  1. Stop the DMA block chaining.
Parameters
[in]hdlThe handle from the "open" function call.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_trx_non_block()

int hal_spi_trx_non_block ( void *  hdl,
int  cs,
int  dfs,
void *  wbuf,
void *  rbuf,
uint16_t  buf_len,
void *  arg,
void(*)(void *arg, int status, uint16_t actual_size)  callback 
)

Master or Slave SPI Transmit and Receive function (bi-direction)

Note
  1. For SPI slave transmit, the master needs to provide the "Slave Select" signal. The SPI slave will transmit one unit (could be byte, short, or long depends on the data frame size) out per "Slave Select" signal. SPI slave can't do multiple transfer within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]csThe SPI slave select. This is only valid for master SPI and the possible value are 0 or 1.
[in]speedThe SPI serial clock rate. They can be 16, 8, 4, 2, or 1 Mhz. Only for master.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]wbufThe void pointer point to the TX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]rbufThe void pointer point to the RX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buf_lenThe TX and RX buffer length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_tx_dma()

int hal_spi_tx_dma ( void *  hdl,
int  cs,
void *  buffer,
uint16_t  buffer_len,
uint16_t *  actual_size 
)

Master or Slave SPI transmit DMA function.

Note
  1. For SPI slave transmit, the master needs to provide the "Slave Select" signal. The SPI slave will transmit one unit (could be byte, short, or long depends on the data frame size) out per "Slave Select" signal. SPI slave can't do multiple transfer within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]csThe SPI slave select. This is only valid for SPI master and the possible value are 0 or 1.
[in]speedThe SPI serial clock rate. They can be 16, 8, 4, 2, or 1 Mhz. Only for master.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]bufferThe void pointer point to the TX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buffer_lenThe TX buffer length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.

◆ hal_spi_tx_non_block()

int hal_spi_tx_non_block ( void *  hdl,
int  cs,
int  dfs,
void *  buffer,
uint16_t  buffer_len,
void *  arg,
void(*)(void *arg, int status, uint16_t size)  callback 
)

Master or Slave SPI transmit function.

Note
  1. For SPI slave transmit, the master needs to provide the "Slave Select" signal. The SPI slave will transmit one unit (could be byte, short, or long depends on the data frame size) out per "Slave Select" signal. SPI slave can't do multiple transfer within one "Slave Select" signal.
  2. SPI slave can only support speed up to D0 clock divided by 4. If D0 clock is 32 Mhz, then SPI master speed has to be less or equal to 8 Mhz.
Parameters
[in]hdlThe handle from the "open" function call.
[in]csThe SPI slave select. This is only valid for SPI master and the possible value are 0 or 1.
[in]speedThe SPI serial clock rate. They can be 16, 8, 4, 2, or 1 Mhz. Only for master.
[in]phaseThe SPI clock phase. 0: first edge of SPI clock, 1: trailing edge of SPI clock.
[in]polarityThe SPI clock polarity. 0: rising, 1: falling.
[in]dfsThe data frame size,
See also
enum spi_dfs_bit.
Parameters
[in]bufferThe void pointer point to the TX buffer. This pointer, depends on the data frame size, will be cast by the driver to byte, short, or long.
[in]buffer_lenThe TX buffer length.
Returns
SPI_ERR_OK if successful, otherwise failed.
See also
enum spi_err.