Merge branch 'master' into abo_stats_pages_auto_swap
[inav.git] / src / main / sensors / initialisation.c
blob274b76eb86d33d6abf0b8269f04f3d35428bd8d6
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
17 #include <stdbool.h>
18 #include <stdint.h>
19 #include <string.h>
21 #include "platform.h"
23 #include "common/utils.h"
25 #include "config/config_eeprom.h"
27 #include "fc/config.h"
28 #include "fc/runtime_config.h"
30 #include "sensors/acceleration.h"
31 #include "sensors/barometer.h"
32 #include "sensors/compass.h"
33 #include "sensors/gyro.h"
34 #include "sensors/initialisation.h"
35 #include "sensors/irlock.h"
36 #include "sensors/opflow.h"
37 #include "sensors/pitotmeter.h"
38 #include "sensors/rangefinder.h"
39 #include "sensors/sensors.h"
40 #include "sensors/temperature.h"
42 uint8_t requestedSensors[SENSOR_INDEX_COUNT] = { GYRO_AUTODETECT, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE, PITOT_NONE, OPFLOW_NONE };
43 uint8_t detectedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE, PITOT_NONE, OPFLOW_NONE };
46 bool sensorsAutodetect(void)
48 bool eepromUpdatePending = false;
50 if (!gyroInit()) {
51 return false;
54 accInit(getLooptime());
56 #ifdef USE_BARO
57 baroInit();
58 #endif
60 #ifdef USE_PITOT
61 pitotInit();
62 #endif
64 #ifdef USE_MAG
65 compassInit();
66 #endif
68 #ifdef USE_TEMPERATURE_SENSOR
69 temperatureInit();
70 #endif
72 #ifdef USE_RANGEFINDER
73 rangefinderInit();
74 #endif
76 #ifdef USE_OPFLOW
77 opflowInit();
78 #endif
80 if (accelerometerConfig()->acc_hardware == ACC_AUTODETECT) {
81 accelerometerConfigMutable()->acc_hardware = detectedSensors[SENSOR_INDEX_ACC];
82 eepromUpdatePending = true;
85 #ifdef USE_BARO
86 if (barometerConfig()->baro_hardware == BARO_AUTODETECT) {
87 barometerConfigMutable()->baro_hardware = detectedSensors[SENSOR_INDEX_BARO];
88 eepromUpdatePending = true;
90 #endif
92 #ifdef USE_MAG
93 if (compassConfig()->mag_hardware == MAG_AUTODETECT) {
94 compassConfigMutable()->mag_hardware = detectedSensors[SENSOR_INDEX_MAG];
95 eepromUpdatePending = true;
97 #endif
99 #ifdef USE_PITOT
100 if (pitotmeterConfig()->pitot_hardware == PITOT_AUTODETECT) {
101 pitotmeterConfigMutable()->pitot_hardware = detectedSensors[SENSOR_INDEX_PITOT];
102 eepromUpdatePending = true;
104 #endif
106 #ifdef USE_IRLOCK
107 irlockInit();
108 #endif
110 if (eepromUpdatePending) {
111 writeEEPROM();
114 return true;