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
26typedef 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
33
35typedef enum
36{
37 SPI_ORDER_MSB, //< Most Significant Bit first
38 SPI_ORDER_LSB //< Less Significant Bit first
40
42typedef 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
48
50typedef 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)
58
71
74 spi_xfer_t * xfer_p);
75
83
89
101
102
103#endif /* SPI_H_ */
void(* spi_on_transfer_done_cb_f)(spi_res_e res, spi_xfer_t *xfer_p)
Definition spi.h:73
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 SPI_transfer(spi_xfer_t *xfer_p, spi_on_transfer_done_cb_f cb)
Enable or disable USART.
uint32_t custom
Definition spi.h:56
uint8_t * read_ptr
Definition spi.h:54
size_t write_size
Definition spi.h:53
size_t read_size
Definition spi.h:55
spi_bit_order_e bit_order
Definition spi.h:46
uint8_t * write_ptr
Definition spi.h:52
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
spi_res_e SPI_init(spi_conf_t *conf_p)
Initialize SPI module.
spi_mode_e mode
Definition spi.h:45
spi_res_e SPI_close()
Close an already initialized SPI module.
uint32_t clock
Definition spi.h:44
spi_bit_order_e
Definition spi.h:36
@ SPI_ORDER_MSB
Definition spi.h:37
@ SPI_ORDER_LSB
Definition spi.h:38