Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / dma_stm32f7xx.c
blob14ece8e35c861830dd14a3c7df1efbe8b1f5b079
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
25 #include "platform.h"
27 #ifdef USE_DMA
29 #include "drivers/nvic.h"
30 #include "drivers/dma.h"
31 #include "drivers/rcc.h"
32 #include "drivers/resource.h"
35 * DMA descriptors.
37 dmaChannelDescriptor_t dmaDescriptors[DMA_LAST_HANDLER] = {
38 DEFINE_DMA_CHANNEL(DMA1, 0, 0),
39 DEFINE_DMA_CHANNEL(DMA1, 1, 6),
40 DEFINE_DMA_CHANNEL(DMA1, 2, 16),
41 DEFINE_DMA_CHANNEL(DMA1, 3, 22),
42 DEFINE_DMA_CHANNEL(DMA1, 4, 32),
43 DEFINE_DMA_CHANNEL(DMA1, 5, 38),
44 DEFINE_DMA_CHANNEL(DMA1, 6, 48),
45 DEFINE_DMA_CHANNEL(DMA1, 7, 54),
47 DEFINE_DMA_CHANNEL(DMA2, 0, 0),
48 DEFINE_DMA_CHANNEL(DMA2, 1, 6),
49 DEFINE_DMA_CHANNEL(DMA2, 2, 16),
50 DEFINE_DMA_CHANNEL(DMA2, 3, 22),
51 DEFINE_DMA_CHANNEL(DMA2, 4, 32),
52 DEFINE_DMA_CHANNEL(DMA2, 5, 38),
53 DEFINE_DMA_CHANNEL(DMA2, 6, 48),
54 DEFINE_DMA_CHANNEL(DMA2, 7, 54),
59 * DMA IRQ Handlers
61 DEFINE_DMA_IRQ_HANDLER(1, 0, DMA1_ST0_HANDLER)
62 DEFINE_DMA_IRQ_HANDLER(1, 1, DMA1_ST1_HANDLER)
63 DEFINE_DMA_IRQ_HANDLER(1, 2, DMA1_ST2_HANDLER)
64 DEFINE_DMA_IRQ_HANDLER(1, 3, DMA1_ST3_HANDLER)
65 DEFINE_DMA_IRQ_HANDLER(1, 4, DMA1_ST4_HANDLER)
66 DEFINE_DMA_IRQ_HANDLER(1, 5, DMA1_ST5_HANDLER)
67 DEFINE_DMA_IRQ_HANDLER(1, 6, DMA1_ST6_HANDLER)
68 DEFINE_DMA_IRQ_HANDLER(1, 7, DMA1_ST7_HANDLER)
69 DEFINE_DMA_IRQ_HANDLER(2, 0, DMA2_ST0_HANDLER)
70 DEFINE_DMA_IRQ_HANDLER(2, 1, DMA2_ST1_HANDLER)
71 DEFINE_DMA_IRQ_HANDLER(2, 2, DMA2_ST2_HANDLER)
72 DEFINE_DMA_IRQ_HANDLER(2, 3, DMA2_ST3_HANDLER)
73 DEFINE_DMA_IRQ_HANDLER(2, 4, DMA2_ST4_HANDLER)
74 DEFINE_DMA_IRQ_HANDLER(2, 5, DMA2_ST5_HANDLER)
75 DEFINE_DMA_IRQ_HANDLER(2, 6, DMA2_ST6_HANDLER)
76 DEFINE_DMA_IRQ_HANDLER(2, 7, DMA2_ST7_HANDLER)
78 static void enableDmaClock(int index)
80 RCC_ClockCmd(dmaDescriptors[index].dma == DMA1 ? RCC_AHB1(DMA1) : RCC_AHB1(DMA2), ENABLE);
83 void dmaEnable(dmaIdentifier_e identifier)
85 const int index = DMA_IDENTIFIER_TO_INDEX(identifier);
87 enableDmaClock(index);
90 void dmaSetHandler(dmaIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam)
92 const int index = DMA_IDENTIFIER_TO_INDEX(identifier);
94 enableDmaClock(index);
95 dmaDescriptors[index].irqHandlerCallback = callback;
96 dmaDescriptors[index].userParam = userParam;
98 HAL_NVIC_SetPriority(dmaDescriptors[index].irqN, NVIC_PRIORITY_BASE(priority), NVIC_PRIORITY_SUB(priority));
99 HAL_NVIC_EnableIRQ(dmaDescriptors[index].irqN);
101 #endif