Wirepas SDK
spi.h
Go to the documentation of this file.
1 /* Copyright 2018 Wirepas Ltd. All Rights Reserved.
2  *
3  * See file LICENSE.txt for full license details.
4  *
5  */
6 
12 #ifndef SPI_H_
13 #define SPI_H_
14 
15 #include <stdbool.h>
16 #include <stdint.h>
17 
26 typedef enum
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
32 } spi_mode_e;
33 
35 typedef enum
36 {
37  SPI_ORDER_MSB, //< Most Significant Bit first
38  SPI_ORDER_LSB //< Less Significant Bit first
40 
42 typedef struct
43 {
44  uint32_t clock; //< SPI speed in Hz
45  spi_mode_e mode; //< SPI mode of operation
46  spi_bit_order_e bit_order; //< SPI bit order
47 } spi_conf_t;
48 
50 typedef struct
51 {
52  uint8_t * write_ptr; //< Pointer to bytes to write (Must be NULL for pure read)
53  size_t write_size; //< Number of bytes to write (Must be 0 for pure read)
54  uint8_t * read_ptr; //< Pointer to store bytes to read (Must be NULL for pure write)
55  size_t read_size; //< Number of bytes to read (Must be 0 for pure write)
56  uint32_t custom; //< Custom param (can be used to implement state machine)
57 } spi_xfer_t;
58 
60 typedef enum
61 {
70 } spi_res_e;
71 
74  spi_xfer_t * xfer_p);
75 
82 spi_res_e SPI_init(spi_conf_t * conf_p);
83 
89 
101 
102 
103 #endif /* SPI_H_ */
SPI_MODE_LOW_SECOND
@ SPI_MODE_LOW_SECOND
Definition: spi.h:29
spi_mode_e
spi_mode_e
Different SPI modes.
Definition: spi.h:26
spi_xfer_t::read_ptr
uint8_t * read_ptr
Definition: spi.h:54
SPI_ORDER_MSB
@ SPI_ORDER_MSB
Definition: spi.h:37
SPI_RES_BUSY
@ SPI_RES_BUSY
Definition: spi.h:67
SPI_MODE_HIGH_FIRST
@ SPI_MODE_HIGH_FIRST
Definition: spi.h:30
spi_conf_t::mode
spi_mode_e mode
Definition: spi.h:45
SPI_RES_OK
@ SPI_RES_OK
Definition: spi.h:62
SPI_close
spi_res_e SPI_close()
Close an already initialized SPI module.
SPI_RES_ALREADY_INITIALIZED
@ SPI_RES_ALREADY_INITIALIZED
Definition: spi.h:66
spi_conf_t
Definition: spi.h:42
spi_conf_t::bit_order
spi_bit_order_e bit_order
Definition: spi.h:46
SPI_RES_ONLY_BLOCKING_AVAILABLE
@ SPI_RES_ONLY_BLOCKING_AVAILABLE
Definition: spi.h:69
spi_on_transfer_done_cb_f
void(* spi_on_transfer_done_cb_f)(spi_res_e res, spi_xfer_t *xfer_p)
Definition: spi.h:73
SPI_RES_INVALID_CONFIG
@ SPI_RES_INVALID_CONFIG
Definition: spi.h:63
spi_bit_order_e
spi_bit_order_e
Definition: spi.h:35
spi_xfer_t::custom
uint32_t custom
Definition: spi.h:56
SPI_init
spi_res_e SPI_init(spi_conf_t *conf_p)
Initialize SPI module.
spi_conf_t::clock
uint32_t clock
Definition: spi.h:44
spi_xfer_t::write_ptr
uint8_t * write_ptr
Definition: spi.h:52
SPI_MODE_LOW_FIRST
@ SPI_MODE_LOW_FIRST
Definition: spi.h:28
spi_res_e
spi_res_e
Definition: spi.h:60
SPI_RES_INVALID_XFER
@ SPI_RES_INVALID_XFER
Definition: spi.h:64
SPI_RES_NOT_INITIALIZED
@ SPI_RES_NOT_INITIALIZED
Definition: spi.h:65
SPI_ORDER_LSB
@ SPI_ORDER_LSB
Definition: spi.h:38
spi_xfer_t
Definition: spi.h:50
spi_xfer_t::write_size
size_t write_size
Definition: spi.h:53
SPI_RES_BLOCKING_NOT_AVAILABLE
@ SPI_RES_BLOCKING_NOT_AVAILABLE
Definition: spi.h:68
SPI_MODE_HIGH_SECOND
@ SPI_MODE_HIGH_SECOND
Definition: spi.h:31
SPI_transfer
spi_res_e SPI_transfer(spi_xfer_t *xfer_p, spi_on_transfer_done_cb_f cb)
Enable or disable USART.
spi_xfer_t::read_size
size_t read_size
Definition: spi.h:55