[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / pg / adc.c
blobb6105c01841e14a10933e4a534c1635c0366a0c4
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>
24 #include "platform.h"
26 #ifdef USE_ADC
28 #include "pg/pg.h"
29 #include "pg/pg_ids.h"
31 #include "drivers/adc.h"
32 #include "drivers/adc_impl.h"
33 #include "drivers/io.h"
35 #include "pg/adc.h"
38 PG_REGISTER_WITH_RESET_FN(adcConfig_t, adcConfig, PG_ADC_CONFIG, 0);
40 void pgResetFn_adcConfig(adcConfig_t *adcConfig)
42 adcConfig->device = ADC_DEV_TO_CFG(adcDeviceByInstance(ADC_INSTANCE));
43 adcConfig->dmaopt[ADCDEV_1] = ADC1_DMA_OPT;
44 // These conditionals need to match the ones used in 'src/main/drivers/adc.h'.
45 #if defined(ADC2)
46 adcConfig->dmaopt[ADCDEV_2] = ADC2_DMA_OPT;
47 #endif
48 #if defined(ADC3)
49 adcConfig->dmaopt[ADCDEV_3] = ADC3_DMA_OPT;
50 #endif
51 #if defined(ADC4)
52 adcConfig->dmaopt[ADCDEV_4] = ADC4_DMA_OPT;
53 #endif
54 #if defined(ADC5)
55 adcConfig->dmaopt[ADCDEV_5] = ADC5_DMA_OPT;
56 #endif
58 #ifdef VBAT_ADC_PIN
59 adcConfig->vbat.enabled = true;
60 adcConfig->vbat.ioTag = IO_TAG(VBAT_ADC_PIN);
61 #if defined(STM32H7)
62 #ifdef VBAT_ADC_INSTANCE
63 adcConfig->vbat.device = ADC_DEV_TO_CFG(adcDeviceByInstance(VBAT_ADC_INSTANCE));
64 #else
65 adcConfig->vbat.device = adcConfig->device;
66 #endif
67 #endif
68 #endif
70 #ifdef EXTERNAL1_ADC_PIN
71 adcConfig->external1.enabled = true;
72 adcConfig->external1.ioTag = IO_TAG(EXTERNAL1_ADC_PIN);
73 #if defined(STM32H7)
74 #ifdef EXTERNAL1_ADC_INSTANCE
75 adcConfig->external1.device = ADC_DEV_TO_CFG(adcDeviceByInstance(EXTERNAL1_ADC_INSTANCE));
76 #else
77 adcConfig->external1.device = adcConfig->device;
78 #endif
79 #endif
80 #endif
82 #ifdef CURRENT_METER_ADC_PIN
83 adcConfig->current.enabled = true;
84 adcConfig->current.ioTag = IO_TAG(CURRENT_METER_ADC_PIN);
85 #if defined(STM32H7)
86 #ifdef CURRENT_METER_ADC_INSTANCE
87 adcConfig->current.device = ADC_DEV_TO_CFG(adcDeviceByInstance(CURRENT_METER_ADC_INSTANCE));
88 #else
89 adcConfig->current.device = adcConfig->device;
90 #endif
91 #endif
92 #endif
94 #ifdef RSSI_ADC_PIN
95 adcConfig->rssi.enabled = true;
96 adcConfig->rssi.ioTag = IO_TAG(RSSI_ADC_PIN);
97 #if defined(STM32H7)
98 #ifdef RSSI_ADC_INSTANCE
99 adcConfig->rssi.device = ADC_DEV_TO_CFG(adcDeviceByInstance(RSSI_ADC_INSTANCE));
100 #else
101 adcConfig->rssi.device = adcConfig->device;
102 #endif
103 #endif
104 #endif
106 adcConfig->vrefIntCalibration = 0;
107 adcConfig->tempSensorCalibration1 = 0;
108 adcConfig->tempSensorCalibration2 = 0;
110 #endif // USE_ADC