Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / drivers / adc_impl.h
blob32f4414e83f3e669768522b8f32379edb9754d41
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include "drivers/io_types.h"
21 #include "rcc_types.h"
23 #if defined(STM32F4) || defined(STM32F7) || defined(AT32F43x)
24 #define ADC_TAG_MAP_COUNT 16
25 #elif defined(STM32H7)
26 #define ADC_TAG_MAP_COUNT 28
27 #else
28 #define ADC_TAG_MAP_COUNT 10
29 #endif
31 #if defined(STM32H7)
32 #define ADC_VALUES_ALIGNMENT(def) DMA_RAM def __attribute__ ((aligned (32)))
33 #else
34 #define ADC_VALUES_ALIGNMENT(def) def
35 #endif
37 typedef enum ADCDevice {
38 ADCINVALID = -1,
39 ADCDEV_1 = 0,
40 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
41 ADCDEV_2,
42 ADCDEV_3,
43 ADCDEV_MAX = ADCDEV_3,
44 #else
45 ADCDEV_MAX = ADCDEV_1,
46 #endif
47 ADCDEV_COUNT = ADCDEV_MAX + 1
48 } ADCDevice;
50 typedef struct adcTagMap_s {
51 ioTag_t tag;
52 uint32_t channel;
53 } adcTagMap_t;
55 typedef struct adcDevice_s {
56 #if defined(AT32F43x)
57 adc_type* ADCx;
58 #else
59 ADC_TypeDef* ADCx;
60 #endif
61 rccPeriphTag_t rccADC;
62 rccPeriphTag_t rccDMA;
63 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
64 DMA_Stream_TypeDef* DMAy_Streamx;
65 uint32_t channel;
66 #elif defined(AT32F43x)
67 dma_channel_type* DMAy_Channelx;
68 uint32_t dmaMuxid; // dmamux request type
69 #else
70 DMA_Channel_TypeDef* DMAy_Channelx;
71 #endif
72 #if defined(STM32F7) || defined(STM32H7)
73 ADC_HandleTypeDef ADCHandle;
74 DMA_HandleTypeDef DmaHandle;
75 #endif
76 bool enabled;
77 int usedChannelCount;
78 } adcDevice_t;
80 typedef struct adc_config_s {
81 ioTag_t tag;
82 ADCDevice adcDevice;
83 uint32_t adcChannel; // ADC1_INxx channel number
84 uint8_t dmaIndex; // index into DMA buffer in case of sparse channels
85 bool enabled;
86 uint8_t sampleTime;
87 } adc_config_t;
89 extern const adcTagMap_t adcTagMap[ADC_TAG_MAP_COUNT];
90 extern adc_config_t adcConfig[ADC_CHN_COUNT];
91 extern volatile ADC_VALUES_ALIGNMENT(uint16_t adcValues[ADCDEV_COUNT][ADC_CHN_COUNT * ADC_AVERAGE_N_SAMPLES]);
93 void adcHardwareInit(drv_adc_config_t *init);
94 #if defined(AT32F43x)
95 ADCDevice adcDeviceByInstance(adc_type *instance);
96 #else
97 ADCDevice adcDeviceByInstance(ADC_TypeDef *instance);
98 #endif
99 uint32_t adcChannelByTag(ioTag_t ioTag);