Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / sensors / initialisation.c
blobdeafc1fc162d1be32de81443291f832111fc2c6e
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"
49 // requestedSensors is not actually used
50 uint8_t requestedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE };
51 uint8_t detectedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE };
53 void sensorsPreInit(void)
55 gyroPreInit();
57 #ifdef USE_MAG
58 compassPreInit();
59 #endif
61 #ifdef USE_BARO
62 baroPreInit();
63 #endif
66 bool sensorsAutodetect(void)
69 // gyro must be initialised before accelerometer
71 bool gyroDetected = gyroInit();
73 #ifdef USE_ACC
74 if (gyroDetected) {
75 accInit(gyro.accSampleRateHz);
77 #endif
79 #ifdef USE_MAG
80 compassInit();
81 #endif
83 #ifdef USE_BARO
84 baroDetect(&baro.dev, barometerConfig()->baro_hardware);
85 #endif
87 #ifdef USE_RANGEFINDER
88 rangefinderInit();
89 #endif
91 #ifdef USE_ADC_INTERNAL
92 adcInternalInit();
93 #endif
95 return gyroDetected;