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)
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/>.
25 #include "drivers/io_types.h"
26 #include "drivers/time.h"
29 #define ADC_INSTANCE ADC1
32 #if defined(STM32F4) || defined(STM32F7)
33 #ifndef ADC1_DMA_STREAM
34 #define ADC1_DMA_STREAM DMA2_Stream4 // ST0 or ST4
37 #ifndef ADC2_DMA_STREAM
38 #define ADC2_DMA_STREAM DMA2_Stream3 // ST2 or ST3
41 #ifndef ADC3_DMA_STREAM
42 #define ADC3_DMA_STREAM DMA2_Stream0 // ST0 or ST1
46 typedef enum ADCDevice
{
64 #define ADC_CFG_TO_DEV(x) ((x) - 1)
65 #define ADC_DEV_TO_CFG(x) ((x) + 1)
72 #if defined(STM32H7) || defined(STM32G4)
73 // On H7 and G4, internal sensors are treated in the similar fashion as regular ADC inputs
74 ADC_CHANNEL_INTERNAL_FIRST_ID
= 4,
83 typedef struct adcOperatingConfig_s
{
85 #if defined(STM32H7) || defined(STM32G4)
86 ADCDevice adcDevice
; // ADCDEV_x for this input
87 uint32_t adcChannel
; // Channel number for this input. Note that H7 and G4 HAL requires this to be 32-bit encoded number.
89 uint8_t adcChannel
; // ADCy_INxx channel number for this input (XXX May be consolidated with uint32_t case)
91 uint8_t dmaIndex
; // index into DMA buffer in case of sparse channels
94 } adcOperatingConfig_t
;
97 void adcInit(const struct adcConfig_s
*config
);
98 uint16_t adcGetChannel(uint8_t channel
);
100 #ifdef USE_ADC_INTERNAL
101 bool adcInternalIsBusy(void);
102 void adcInternalStartConversion(void);
103 uint16_t adcInternalReadVrefint(void);
104 uint16_t adcInternalReadTempsensor(void);
105 uint16_t adcInternalCompensateVref(uint16_t vrefAdcValue
);
106 int16_t adcInternalComputeTemperature(uint16_t tempAdcValue
, uint16_t vrefValue
);
109 #if !defined(SIMULATOR_BUILD)
110 ADCDevice
adcDeviceByInstance(ADC_TypeDef
*instance
);