-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspi_dma.h
56 lines (44 loc) · 1.1 KB
/
spi_dma.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* author : Shuichi TAKANO
* since : Sun Aug 25 2019 15:39:25
*/
#ifndef E010AF3D_A134_1650_EAE0_1F6097E2920D
#define E010AF3D_A134_1650_EAE0_1F6097E2920D
#include <spi.h>
#include <functional>
class SPIDMA
{
spi_device_num_t spiNum_{};
volatile spi_t *spi_{};
spi_chip_select_t cs_;
dmac_channel_number_t dmaCh_;
int priority_;
std::function<void()> callback_;
public:
void init(spi_device_num_t spiNum,
dmac_channel_number_t dmaCh,
int ssPin, int ss,
int prio);
void waitDone();
void waitIdle();
spi_device_num_t getSPINum() const
{
return spiNum_;
}
void setCallback(std::function<void()> &&f)
{
callback_ = f;
}
void resetCallback()
{
callback_ = std::function<void()>();
}
void _setupTransfer();
void _transferBE(const uint32_t *data, uint32_t count);
void transferBE(const uint32_t *data, uint32_t count);
static SPIDMA &instance();
private:
static int irqEntry(void *ctx);
void irq();
};
#endif /* E010AF3D_A134_1650_EAE0_1F6097E2920D */