-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathi2s_transmitter.cc
126 lines (117 loc) · 3.99 KB
/
i2s_transmitter.cc
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "drivers/stm32/i2s_transmitter.h"
#include "stm32f4xx_rcc.h"
I2STransmitter::I2STransmitter(GPIOPin& i2s_mck_pin,
GPIOPin& i2s_ck_pin,
GPIOPin& i2s_sd_pin,
GPIOPin& i2s_ws_pin,
uint8_t i2s_spi,
uint8_t i2s_dma,
uint32_t i2s_dma_channel,
uint8_t i2s_dma_stream)
: mck_pin(i2s_mck_pin),
ck_pin(i2s_ck_pin),
sd_pin(i2s_sd_pin),
ws_pin(i2s_ws_pin),
spi(i2s_spi),
dma(i2s_dma),
dma_channel(i2s_dma_channel),
dma_stream(i2s_dma_stream)
{}
DMA_Stream_TypeDef* I2STransmitter::get_dma_stream() {
switch (dma) {
case 1:
switch (dma_stream) {
case 0: return DMA1_Stream0;
case 1: return DMA1_Stream1;
case 2: return DMA1_Stream2;
case 3: return DMA1_Stream3;
case 4: return DMA1_Stream4;
case 5: return DMA1_Stream5;
case 6: return DMA1_Stream6;
case 7: return DMA1_Stream7;
default: return DMA1_Stream0;
}
case 2:
switch (dma_stream) {
case 0: return DMA2_Stream0;
case 1: return DMA2_Stream1;
case 2: return DMA2_Stream2;
case 3: return DMA2_Stream3;
case 4: return DMA2_Stream4;
case 5: return DMA2_Stream5;
case 6: return DMA2_Stream6;
case 7: return DMA2_Stream7;
default: return DMA2_Stream0;
}
default: return nullptr;
}
}
IRQn_Type I2STransmitter::get_irq() {
switch (dma) {
case 1:
switch (dma_stream) {
case 0: return DMA1_Stream0_IRQn;
case 1: return DMA1_Stream1_IRQn;
case 2: return DMA1_Stream2_IRQn;
case 3: return DMA1_Stream3_IRQn;
case 4: return DMA1_Stream4_IRQn;
case 5: return DMA1_Stream5_IRQn;
case 6: return DMA1_Stream6_IRQn;
case 7: return DMA1_Stream7_IRQn;
default: return DMA1_Stream0_IRQn;
}
case 2:
switch (dma_stream) {
case 0: return DMA2_Stream0_IRQn;
case 1: return DMA2_Stream1_IRQn;
case 2: return DMA2_Stream2_IRQn;
case 3: return DMA2_Stream3_IRQn;
case 4: return DMA2_Stream4_IRQn;
case 5: return DMA2_Stream5_IRQn;
case 6: return DMA2_Stream6_IRQn;
case 7: return DMA2_Stream7_IRQn;
default: return DMA2_Stream0_IRQn;
}
default: return DMA1_Stream0_IRQn;
}
}
uint32_t I2STransmitter::get_dma_channel() {
switch (dma_channel) {
case 0: return DMA_Channel_0;
case 1: return DMA_Channel_1;
case 2: return DMA_Channel_2;
case 3: return DMA_Channel_3;
case 4: return DMA_Channel_4;
case 5: return DMA_Channel_5;
case 6: return DMA_Channel_6;
case 7: return DMA_Channel_7;
default: return DMA_Channel_0;
}
}
uint32_t I2STransmitter::get_dma_flags() {
switch (dma_stream) {
case 0: return DMA_FLAG_TCIF0;
case 1: return DMA_FLAG_TCIF1;
case 2: return DMA_FLAG_TCIF2;
case 3: return DMA_FLAG_TCIF3;
case 4: return DMA_FLAG_TCIF4;
case 5: return DMA_FLAG_TCIF5;
case 6: return DMA_FLAG_TCIF6;
case 7: return DMA_FLAG_TCIF7;
default: return 0;
}
}
uint32_t I2STransmitter::get_spi_clock() {
switch (spi) {
case 2: return RCC_APB1Periph_SPI2;
case 3: return RCC_APB1Periph_SPI3;
default: return 0;
}
}
SPI_TypeDef* I2STransmitter::get_spi() {
switch (spi) {
case 2: return SPI2;
case 3: return SPI3;
default: return nullptr;
}
}