Position hold depends on GPS (#14101)
[betaflight.git] / src / main / sensors / initialisation.c
blobf128df173b20e931d8b730c43759caae54a47522
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>
23 #include <string.h>
25 #include "platform.h"
27 #include "common/utils.h"
29 #include "config/config.h"
30 #include "config/feature.h"
32 #include "fc/runtime_config.h"
34 #include "flight/pid.h"
36 #include "pg/pg.h"
37 #include "pg/pg_ids.h"
39 #include "sensors/acceleration.h"
40 #include "sensors/adcinternal.h"
41 #include "sensors/barometer.h"
42 #include "sensors/compass.h"
43 #include "sensors/gyro.h"
44 #include "sensors/gyro_init.h"
45 #include "sensors/initialisation.h"
46 #include "sensors/rangefinder.h"
47 #include "sensors/sensors.h"
48 #include "sensors/opticalflow.h"
50 // requestedSensors is not actually used
51 uint8_t requestedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE, OPTICALFLOW_NONE};
52 uint8_t detectedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE, OPTICALFLOW_NONE};
54 void sensorsPreInit(void)
56 gyroPreInit();
58 #ifdef USE_MAG
59 compassPreInit();
60 #endif
62 #ifdef USE_BARO
63 baroPreInit();
64 #endif
67 bool sensorsAutodetect(void)
70 // gyro must be initialised before accelerometer
72 bool gyroDetected = gyroInit();
74 #ifdef USE_ACC
75 if (gyroDetected) {
76 accInit(gyro.accSampleRateHz);
78 #endif
80 #ifdef USE_BARO
81 baroInit();
82 #endif
84 #ifdef USE_MAG
85 compassInit();
86 #endif
88 #ifdef USE_RANGEFINDER
89 rangefinderInit();
90 #endif
92 #ifdef USE_OPTICALFLOW
93 opticalflowInit();
94 #endif
96 #ifdef USE_ADC_INTERNAL
97 adcInternalInit();
98 #endif
100 return gyroDetected;