PER Firmware
Loading...
Searching...
No Matches
spi.h File Reference

G4 SPI public API. More...

#include <stddef.h>
#include "common/phal_G4/dma/dma.h"
Include dependency graph for spi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SPI_InitConfig_t
 Configuration entry for SPI initilization. More...
 

Enumerations

enum  SPI_Mode { SPI_MODE_MASTER = 0 , SPI_MODE_SLAVE = 1 }
 SPI operating mode. More...
 
enum  SPI_CPOL { SPI_CPOL_IDLE_LOW = 0 , SPI_CPOL_IDLE_HIGH = 1 }
 SPI clock polarity. More...
 
enum  SPI_CPHA { SPI_CPHA_FIRST_EDGE = 0 , SPI_CPHA_SECOND_EDGE = 1 }
 SPI clock phase. More...
 

Functions

bool PHAL_SPI_init (SPI_InitConfig_t *handle)
 Initialize an SPI peripheral for DMA-based transfers.
 
void PHAL_SPI_transfer (SPI_InitConfig_t *spi, const uint8_t *out_data, uint8_t *in_data, uint32_t data_len)
 Start a DMA-backed SPI transfer.
 
void PHAL_SPI_transferBlocking (SPI_InitConfig_t *spi, const uint8_t *out_data, uint8_t *in_data, uint32_t data_len)
 Perform a blocking DMA-backed SPI transfer. (Wrapper around PHAL_SPI_transfer.)
 
bool PHAL_SPI_busy (const SPI_InitConfig_t *cfg)
 Check whether the SPI peripheral is busy.
 
void PHAL_SPI_txCallback (SPI_InitConfig_t *spi)
 Weak callback fired when a DMA-backed SPI transfer completes.
 

Detailed Description

G4 SPI public API.

Author
Ronak Jain (jain7.nosp@m.17@p.nosp@m.urdue.nosp@m..edu)
Shriya Balu (balu@.nosp@m.purd.nosp@m.ue.ed.nosp@m.u)

Enumeration Type Documentation

◆ SPI_CPHA

enum SPI_CPHA

SPI clock phase.

Enumerator
SPI_CPHA_FIRST_EDGE 
SPI_CPHA_SECOND_EDGE 

◆ SPI_CPOL

enum SPI_CPOL

SPI clock polarity.

Enumerator
SPI_CPOL_IDLE_LOW 
SPI_CPOL_IDLE_HIGH 

◆ SPI_Mode

enum SPI_Mode

SPI operating mode.

Enumerator
SPI_MODE_MASTER 
SPI_MODE_SLAVE 

Function Documentation

◆ PHAL_SPI_busy()

bool PHAL_SPI_busy ( const SPI_InitConfig_t * cfg)

Check whether the SPI peripheral is busy.

Parameters
cfgSPI configuration.
Returns
true if a transfer is currently in progress.

◆ PHAL_SPI_init()

bool PHAL_SPI_init ( SPI_InitConfig_t * handle)

Initialize an SPI peripheral for DMA-based transfers.

Configures the SPI peripheral, initializes the associated DMA channels, and prepares the peripheral for subsequent transfers.

Parameters
handleSPI configuration structure.
Returns
true if initialization was successful, false otherwise. Only can be false if DMA initialization fails.

Initialize an SPI peripheral for DMA-based transfers.

Parameters
handleSPI handle to configure.
Returns
true
false

Peripheral configuration (See RM0440 42.5.7 Configuration of SPI section)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PHAL_SPI_transfer()

void PHAL_SPI_transfer ( SPI_InitConfig_t * spi,
const uint8_t * out_data,
uint8_t * in_data,
uint32_t data_len )

Start a DMA-backed SPI transfer.

Non-blocking: returns immediately after the DMA transfer has been started. If another transfer is already in progress, block until it completes before starting the new transfer.

Passing NULL for either buffer transmits or receives dummy data.

Parameters
spiSPI configuration.
out_dataTransmit buffer, or NULL to transmit dummy (zero) bytes.
in_dataReceive buffer, or NULL to discard received bytes.
data_lenNumber of bytes to transfer (includes both TX and RX).
Here is the call graph for this function:

◆ PHAL_SPI_transferBlocking()

void PHAL_SPI_transferBlocking ( SPI_InitConfig_t * spi,
const uint8_t * out_data,
uint8_t * in_data,
uint32_t data_len )

Perform a blocking DMA-backed SPI transfer. (Wrapper around PHAL_SPI_transfer.)

Blocks until the SPI peripheral is available, starts the transfer, and does not return until the transfer has completed.

Passing NULL for either buffer transmits or receives dummy data.

Parameters
spiSPI configuration.
out_dataTransmit buffer, or NULL to transmit dummy (zero) bytes.
in_dataReceive buffer, or NULL to discard received bytes.
data_lenNumber of bytes to transfer (includes both TX and RX).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PHAL_SPI_txCallback()

void PHAL_SPI_txCallback ( SPI_InitConfig_t * spi)
extern

Weak callback fired when a DMA-backed SPI transfer completes.

Called after the transfer has completed and the SPI handle has been marked idle.

Default implementation does nothing.

Parameters
spiSPI configuration that completed the transfer.
Here is the caller graph for this function: