libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
spi.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_SPI_H
3#define DSY_SPI_H
4
5#include "daisy_core.h"
6
7#if !UNIT_TEST
8#include "util/hal_map.h"
9#endif
10
11/* TODO:
12- Add documentation
13- Add IT
14*/
15
16namespace daisy
17{
24{
25 public:
26 struct Config
27 {
28 enum class Peripheral
29 {
30 SPI_1,
31 SPI_2,
32 SPI_3,
33 SPI_4,
34 SPI_5,
35 SPI_6,
36 };
37
38 enum class Mode
39 {
40 MASTER,
41 SLAVE,
42 };
43
44 enum class Direction
45 {
50 };
51
52 enum class ClockPolarity
53 {
54 LOW,
55 HIGH,
56 };
57
58 enum class ClockPhase
59 {
62 };
63
64 enum class NSS
65 {
66 SOFT,
69 };
70
71 enum class BaudPrescaler
72 {
73 PS_2,
74 PS_4,
75 PS_8,
76 PS_16,
77 PS_32,
78 PS_64,
79 PS_128,
80 PS_256,
81 };
82
83 struct
84 {
90
92 {
93 // user must specify periph, mode, direction, nss, and pin_config
94 datasize = 8;
98 }
99
103 unsigned long datasize;
108 };
109
110 SpiHandle() : pimpl_(nullptr) {}
111 SpiHandle(const SpiHandle& other) = default;
112 SpiHandle& operator=(const SpiHandle& other) = default;
113
115 enum class Result
116 {
117 OK,
118 ERR
119 };
120
121 enum class DmaDirection
122 {
123 RX,
124 TX,
125 RX_TX,
126 };
127
130
132 const Config& GetConfig() const;
133
135 typedef void (*StartCallbackFunctionPtr)(void* context);
137 typedef void (*EndCallbackFunctionPtr)(void* context, Result result);
138
139
147
155
165 size_t size,
166 uint32_t timeout = 100);
167
179 size_t size,
182 void* callback_context);
183
195 size_t size,
198 void* callback_context);
199
211 Result
214 size_t size,
217 void* callback_context);
218
221
222 class Impl;
224 private:
225 Impl* pimpl_;
226};
227
228extern "C"
229{
232};
233
235} // namespace daisy
236
237#endif
Definition leddriver.h:33
Definition spi.h:24
Result BlockingTransmitAndReceive(uint8_t *tx_buff, uint8_t *rx_buff, size_t size, uint32_t timeout=100)
Result DmaTransmit(uint8_t *buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
void(* EndCallbackFunctionPtr)(void *context, Result result)
Definition spi.h:137
Result DmaReceive(uint8_t *buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
Result DmaTransmitAndReceive(uint8_t *tx_buff, uint8_t *rx_buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
SpiHandle(const SpiHandle &other)=default
const Config & GetConfig() const
Result BlockingTransmit(uint8_t *buff, size_t size, uint32_t timeout=100)
Result BlockingReceive(uint8_t *buffer, uint16_t size, uint32_t timeout)
Result Init(const Config &config)
DmaDirection
Definition spi.h:122
SpiHandle & operator=(const SpiHandle &other)=default
SpiHandle()
Definition spi.h:110
void(* StartCallbackFunctionPtr)(void *context)
Definition spi.h:135
Result
Definition spi.h:116
void dsy_spi_global_init()
Hardware defines and helpers for daisy field platform.
Definition index.h:2
representation of hardware port/pin combination
Definition daisy_core.h:193
Definition spi.h:27
Mode
Definition spi.h:39
ClockPolarity clock_polarity
Definition spi.h:104
BaudPrescaler
Definition spi.h:72
Peripheral periph
Definition spi.h:100
NSS
Definition spi.h:65
Pin nss
Definition spi.h:88
ClockPolarity
Definition spi.h:53
struct daisy::SpiHandle::Config::@18 pin_config
Direction
Definition spi.h:45
ClockPhase
Definition spi.h:59
Mode mode
Definition spi.h:101
Peripheral
Definition spi.h:29
NSS nss
Definition spi.h:106
Pin mosi
Definition spi.h:87
Pin sclk
Definition spi.h:85
ClockPhase clock_phase
Definition spi.h:105
BaudPrescaler baud_prescaler
Definition spi.h:107
Config()
Definition spi.h:91
Pin miso
Definition spi.h:86
Direction direction
Definition spi.h:102
unsigned long datasize
Definition spi.h:103