Wirepas SDK
spi.h File Reference

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. More...
 
spi_res_e SPI_close ()
 Close an already initialized SPI module. More...
 
spi_res_e SPI_transfer (spi_xfer_t *xfer_p, spi_on_transfer_done_cb_f cb)
 Enable or disable USART. More...
 

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 }
 Simple minimal SPI master driver It only manages one SPI instance at a time. 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 65 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 transfert 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 34 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 42 of file spi.h.

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

Enumeration Type Documentation

◆ spi_bit_order_e

Different bit orders

Enumerator
SPI_ORDER_MSB 
SPI_ORDER_LSB 

Definition at line 27 of file spi.h.

28 {
29  SPI_ORDER_MSB, //< Most Significant Bit first
30  SPI_ORDER_LSB //< Less Significant Bit first

◆ spi_mode_e

enum spi_mode_e

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

Different SPI modes

Enumerator
SPI_MODE_LOW_FIRST 
SPI_MODE_LOW_SECOND 
SPI_MODE_HIGH_FIRST 
SPI_MODE_HIGH_SECOND 

Definition at line 18 of file spi.h.

19 {
20  SPI_MODE_LOW_FIRST, //< Low Polarity, First Clock edge
21  SPI_MODE_LOW_SECOND, //< Low Polarity, Second Clock edge
22  SPI_MODE_HIGH_FIRST, //< High Polarity, First Clock edge
23  SPI_MODE_HIGH_SECOND //< High Polarity, Second Clock edge
24 } spi_mode_e;

◆ 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 52 of file spi.h.

SPI_MODE_LOW_SECOND
@ SPI_MODE_LOW_SECOND
Definition: spi.h:21
spi_mode_e
spi_mode_e
Simple minimal SPI master driver It only manages one SPI instance at a time.
Definition: spi.h:18
SPI_ORDER_MSB
@ SPI_ORDER_MSB
Definition: spi.h:29
SPI_RES_BUSY
@ SPI_RES_BUSY
Definition: spi.h:59
SPI_MODE_HIGH_FIRST
@ SPI_MODE_HIGH_FIRST
Definition: spi.h:22
SPI_RES_OK
@ SPI_RES_OK
Definition: spi.h:54
SPI_RES_ALREADY_INITIALIZED
@ SPI_RES_ALREADY_INITIALIZED
Definition: spi.h:58
SPI_RES_ONLY_BLOCKING_AVAILABLE
@ SPI_RES_ONLY_BLOCKING_AVAILABLE
Definition: spi.h:61
SPI_RES_INVALID_CONFIG
@ SPI_RES_INVALID_CONFIG
Definition: spi.h:55
spi_bit_order_e
spi_bit_order_e
Definition: spi.h:27
SPI_MODE_LOW_FIRST
@ SPI_MODE_LOW_FIRST
Definition: spi.h:20
spi_res_e
spi_res_e
Definition: spi.h:52
SPI_RES_INVALID_XFER
@ SPI_RES_INVALID_XFER
Definition: spi.h:56
SPI_RES_NOT_INITIALIZED
@ SPI_RES_NOT_INITIALIZED
Definition: spi.h:57
SPI_ORDER_LSB
@ SPI_ORDER_LSB
Definition: spi.h:30
SPI_RES_BLOCKING_NOT_AVAILABLE
@ SPI_RES_BLOCKING_NOT_AVAILABLE
Definition: spi.h:60
SPI_MODE_HIGH_SECOND
@ SPI_MODE_HIGH_SECOND
Definition: spi.h:23