Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / dma_reqmap.h
blobd35d05de13d91abca4e1346c4526194bd348a6a2
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 #pragma once
23 #include "platform.h"
25 #include "drivers/dma.h"
26 #include "drivers/timer.h"
28 typedef uint16_t dmaCode_t;
30 typedef struct dmaChannelSpec_s {
31 dmaCode_t code;
32 dmaResource_t *ref;
33 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32G4)
34 uint32_t channel;
35 #endif
36 } dmaChannelSpec_t;
38 #define DMA_CODE(dma, stream, chanreq) ((dma << 12)|(stream << 8)|(chanreq << 0))
39 #define DMA_CODE_CONTROLLER(code) ((code >> 12) & 0xf)
40 #define DMA_CODE_STREAM(code) ((code >> 8) & 0xf)
41 #define DMA_CODE_CHANNEL(code) ((code >> 0) & 0xff)
42 #define DMA_CODE_REQUEST(code) DMA_CODE_CHANNEL(code)
44 typedef enum {
45 DMA_PERIPH_SPI_MOSI,
46 DMA_PERIPH_SPI_MISO,
47 DMA_PERIPH_ADC,
48 DMA_PERIPH_SDIO,
49 DMA_PERIPH_UART_TX,
50 DMA_PERIPH_UART_RX,
51 DMA_PERIPH_TIMUP,
52 } dmaPeripheral_e;
54 typedef int8_t dmaoptValue_t;
56 #define DMA_OPT_UNUSED (-1)
58 #if defined(STM32H7) || defined(STM32G4)
59 #define MAX_PERIPHERAL_DMA_OPTIONS 16
60 #define MAX_TIMER_DMA_OPTIONS 16
61 #else
62 #define MAX_PERIPHERAL_DMA_OPTIONS 2
63 #define MAX_TIMER_DMA_OPTIONS 3
64 #endif
66 struct timerHardware_s;
68 dmaoptValue_t dmaoptByTag(ioTag_t ioTag);
69 const dmaChannelSpec_t *dmaGetChannelSpecByPeripheral(dmaPeripheral_e device, uint8_t index, int8_t opt);
70 const dmaChannelSpec_t *dmaGetChannelSpecByTimerValue(TIM_TypeDef *tim, uint8_t channel, dmaoptValue_t dmaopt);
71 const dmaChannelSpec_t *dmaGetChannelSpecByTimer(const struct timerHardware_s *timer);
72 dmaoptValue_t dmaGetOptionByTimer(const struct timerHardware_s *timer);
73 dmaoptValue_t dmaGetUpOptionByTimer(const struct timerHardware_s *timer);