Wirepas SDK
spi.h File Reference

Simple minimal SPI master driver It only manages one SPI instance at a time. More...

Detailed Description

Simple minimal SPI master driver It only manages one SPI instance at a time.

Definition in file spi.h.

Go to the source code of this file.

Typedefs

typedef void(* spi_on_transfer_done_cb_f) (spi_res_e res, spi_xfer_t *xfer_p)
 

Functions

spi_res_e SPI_init (spi_conf_t *conf_p)
 Initialize SPI module.
 
spi_res_e SPI_close ()
 Close an already initialized SPI module.
 
spi_res_e SPI_transfer (spi_xfer_t *xfer_p, spi_on_transfer_done_cb_f cb)
 Enable or disable USART.
 

Data Structures

struct  spi_conf_t
 
struct  spi_xfer_t
 

Enumerations

enum  spi_mode_e { SPI_MODE_LOW_FIRST , SPI_MODE_LOW_SECOND , SPI_MODE_HIGH_FIRST , SPI_MODE_HIGH_SECOND }
 Different SPI modes. More...
 
enum  spi_bit_order_e { SPI_ORDER_MSB , SPI_ORDER_LSB }
 
enum  spi_res_e {
  SPI_RES_OK , SPI_RES_INVALID_CONFIG , SPI_RES_INVALID_XFER , SPI_RES_NOT_INITIALIZED ,
  SPI_RES_ALREADY_INITIALIZED , SPI_RES_BUSY , SPI_RES_BLOCKING_NOT_AVAILABLE , SPI_RES_ONLY_BLOCKING_AVAILABLE
}
 

Typedef Documentation

◆ spi_on_transfer_done_cb_f

typedef void(* spi_on_transfer_done_cb_f) (spi_res_e res, spi_xfer_t *xfer_p)

User callback when transfer is done

Definition at line 73 of file spi.h.

Function Documentation

◆ SPI_close()

spi_res_e SPI_close ( )

Close an already initialized SPI module.

Returns
Return code of operation

◆ SPI_init()

spi_res_e SPI_init ( spi_conf_t *  conf_p)

Initialize SPI module.

Parameters
conf_pPointer to an spi configuration
Returns
Return code of operation
Examples
ruuvi_evk/app.c.

◆ SPI_transfer()

spi_res_e SPI_transfer ( spi_xfer_t *  xfer_p,
spi_on_transfer_done_cb_f  cb 
)

Enable or disable USART.

Parameters
xfer_pPointer to the transfer description
cbCallback to call at end of transfer (Can be NULL for a blocking call)
Returns
Return code of operation
Note
Application is in charge to select the write slave with chip select signal

Data Structure Documentation

◆ spi_conf_t

struct spi_conf_t

Structure to configure the SPI

Examples
ruuvi_evk/app.c.

Definition at line 42 of file spi.h.

Data Fields
spi_bit_order_e bit_order
uint32_t clock
spi_mode_e mode

◆ spi_xfer_t

struct spi_xfer_t

Structure to describe a SPI transfer

Definition at line 50 of file spi.h.

Data Fields
uint32_t custom
uint8_t * read_ptr
size_t read_size
uint8_t * write_ptr
size_t write_size

Enumeration Type Documentation

◆ spi_bit_order_e

Different bit orders

Enumerator
SPI_ORDER_MSB 
SPI_ORDER_LSB 

Definition at line 35 of file spi.h.

36{
37 SPI_ORDER_MSB, //< Most Significant Bit first
38 SPI_ORDER_LSB //< Less Significant Bit first
spi_bit_order_e
Definition spi.h:36
@ SPI_ORDER_MSB
Definition spi.h:37
@ SPI_ORDER_LSB
Definition spi.h:38

◆ spi_mode_e

enum spi_mode_e

Different SPI modes.

Note
The enum values are handled differently in Silabs and Nordic chips:
  • In Nordic chips, this controls the polarity on active state.
  • In Silabs chips, this controls the polarity on idle state.
  • In TI chips, this controls the polarity on active state.

    Hence the same enum value results in inverse polarity on Silabs chips.
Enumerator
SPI_MODE_LOW_FIRST 
SPI_MODE_LOW_SECOND 
SPI_MODE_HIGH_FIRST 
SPI_MODE_HIGH_SECOND 

Definition at line 26 of file spi.h.

27{
28 SPI_MODE_LOW_FIRST, //< Low Polarity, leading edge
29 SPI_MODE_LOW_SECOND, //< Low Polarity, trailing edge
30 SPI_MODE_HIGH_FIRST, //< High Polarity, leading edge
31 SPI_MODE_HIGH_SECOND //< High Polarity, trailing edge
spi_mode_e
Different SPI modes.
Definition spi.h:27
@ SPI_MODE_HIGH_FIRST
Definition spi.h:30
@ SPI_MODE_HIGH_SECOND
Definition spi.h:31
@ SPI_MODE_LOW_SECOND
Definition spi.h:29
@ SPI_MODE_LOW_FIRST
Definition spi.h:28

◆ spi_res_e

enum spi_res_e

Return codes of SPI functions

Enumerator
SPI_RES_OK 
SPI_RES_INVALID_CONFIG 
SPI_RES_INVALID_XFER 
SPI_RES_NOT_INITIALIZED 
SPI_RES_ALREADY_INITIALIZED 
SPI_RES_BUSY 
SPI_RES_BLOCKING_NOT_AVAILABLE 
SPI_RES_ONLY_BLOCKING_AVAILABLE 

Definition at line 60 of file spi.h.

61{
70} spi_res_e;
spi_res_e
Definition spi.h:61
@ SPI_RES_INVALID_CONFIG
Definition spi.h:63
@ SPI_RES_INVALID_XFER
Definition spi.h:64
@ SPI_RES_ONLY_BLOCKING_AVAILABLE
Definition spi.h:69
@ SPI_RES_ALREADY_INITIALIZED
Definition spi.h:66
@ SPI_RES_NOT_INITIALIZED
Definition spi.h:65
@ SPI_RES_OK
Definition spi.h:62
@ SPI_RES_BUSY
Definition spi.h:67
@ SPI_RES_BLOCKING_NOT_AVAILABLE
Definition spi.h:68