Moved 'config.[ch]' into the 'config/' directory.
[betaflight.git] / src / main / sensors / initialisation.c
blob3ace81ec112b72a1a94c37e7681d46e6755d1df4
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/feature.h"
30 #include "pg/pg.h"
31 #include "pg/pg_ids.h"
33 #include "config/config.h"
34 #include "fc/runtime_config.h"
36 #include "sensors/sensors.h"
37 #include "sensors/adcinternal.h"
38 #include "sensors/acceleration.h"
39 #include "sensors/barometer.h"
40 #include "sensors/gyro.h"
41 #include "sensors/compass.h"
42 #include "sensors/rangefinder.h"
43 #include "sensors/initialisation.h"
45 // requestedSensors is not actually used
46 uint8_t requestedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE };
47 uint8_t detectedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE };
49 void sensorsPreInit(void)
51 gyroPreInit();
53 #ifdef USE_MAG
54 compassPreInit();
55 #endif
57 #ifdef USE_BARO
58 baroPreInit();
59 #endif
62 bool sensorsAutodetect(void)
65 // gyro must be initialised before accelerometer
67 bool gyroDetected = gyroInit();
69 #ifdef USE_ACC
70 if (gyroDetected) {
71 accInit(gyro.targetLooptime);
73 #endif
75 #ifdef USE_MAG
76 compassInit();
77 #endif
79 #ifdef USE_BARO
80 baroDetect(&baro.dev, barometerConfig()->baro_hardware);
81 #endif
83 #ifdef USE_RANGEFINDER
84 rangefinderInit();
85 #endif
87 #ifdef USE_ADC_INTERNAL
88 adcInternalInit();
89 #endif
91 return gyroDetected;