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/>.
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
28 #define ADC_TAG_MAP_COUNT 10
32 #define ADC_VALUES_ALIGNMENT(def) DMA_RAM def __attribute__ ((aligned (32)))
34 #define ADC_VALUES_ALIGNMENT(def) def
37 typedef enum ADCDevice
{
40 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
43 ADCDEV_MAX
= ADCDEV_3
,
45 ADCDEV_MAX
= ADCDEV_1
,
47 ADCDEV_COUNT
= ADCDEV_MAX
+ 1
50 typedef struct adcTagMap_s
{
55 typedef struct adcDevice_s
{
61 rccPeriphTag_t rccADC
;
62 rccPeriphTag_t rccDMA
;
63 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
64 DMA_Stream_TypeDef
* DMAy_Streamx
;
66 #elif defined(AT32F43x)
67 dma_channel_type
* DMAy_Channelx
;
68 uint32_t dmaMuxid
; // dmamux request type
70 DMA_Channel_TypeDef
* DMAy_Channelx
;
72 #if defined(STM32F7) || defined(STM32H7)
73 ADC_HandleTypeDef ADCHandle
;
74 DMA_HandleTypeDef DmaHandle
;
80 typedef struct adc_config_s
{
83 uint32_t adcChannel
; // ADC1_INxx channel number
84 uint8_t dmaIndex
; // index into DMA buffer in case of sparse channels
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
);
95 ADCDevice
adcDeviceByInstance(adc_type
*instance
);
97 ADCDevice
adcDeviceByInstance(ADC_TypeDef
*instance
);
99 uint32_t adcChannelByTag(ioTag_t ioTag
);