Merge pull request #11500 from klutvott123/crsf-baud-negotiation-improvements-2
[betaflight.git] / src / main / sensors / barometer.h
blob2d2c6d514d236b35fea5af6ae53157a5d8638555
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 #pragma once
23 #include "pg/pg.h"
24 #include "drivers/barometer/barometer.h"
26 typedef enum {
27 BARO_DEFAULT = 0,
28 BARO_NONE = 1,
29 BARO_BMP085 = 2,
30 BARO_MS5611 = 3,
31 BARO_BMP280 = 4,
32 BARO_LPS = 5,
33 BARO_QMP6988 = 6,
34 BARO_BMP388 = 7,
35 BARO_DPS310 = 8,
36 } baroSensor_e;
38 #define BARO_SAMPLE_COUNT_MAX 48
40 typedef struct barometerConfig_s {
41 uint8_t baro_busType;
42 uint8_t baro_spi_device;
43 ioTag_t baro_spi_csn; // Also used as XCLR (positive logic) for BMP085
44 uint8_t baro_i2c_device;
45 uint8_t baro_i2c_address;
46 uint8_t baro_hardware; // Barometer hardware to use
47 uint8_t baro_sample_count; // size of baro filter array
48 uint16_t baro_noise_lpf; // additional LPF to reduce baro noise
49 uint16_t baro_cf_vel; // apply Complimentary Filter to keep the calculated velocity based on baro velocity (i.e. near real velocity)
50 ioTag_t baro_eoc_tag;
51 ioTag_t baro_xclr_tag;
52 } barometerConfig_t;
54 PG_DECLARE(barometerConfig_t, barometerConfig);
56 typedef struct baro_s {
57 baroDev_t dev;
58 int32_t BaroAlt;
59 int32_t baroTemperature; // Use temperature for telemetry
60 int32_t baroPressure; // Use pressure for telemetry
61 } baro_t;
63 extern baro_t baro;
65 void baroPreInit(void);
66 bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse);
67 bool baroIsCalibrationComplete(void);
68 void baroStartCalibration(void);
69 void baroSetGroundLevel(void);
70 uint32_t baroUpdate(timeUs_t currentTimeUs);
71 bool isBaroReady(void);
72 int32_t baroCalculateAltitude(void);
73 void performBaroCalibrationCycle(void);