Line data Source code
1 : #pragma once 2 : 3 : #include "AP_Baro_Backend.h" 4 : 5 : #if AP_BARO_DPS280_ENABLED 6 : 7 : #include <AP_HAL/AP_HAL.h> 8 : #include <AP_HAL/Device.h> 9 : 10 : #ifndef HAL_BARO_DPS280_I2C_ADDR 11 : #define HAL_BARO_DPS280_I2C_ADDR 0x76 12 : #endif 13 : #ifndef HAL_BARO_DPS280_I2C_ADDR2 14 : #define HAL_BARO_DPS280_I2C_ADDR2 0x77 15 : #endif 16 : 17 : class AP_Baro_DPS280 : public AP_Baro_Backend { 18 : public: 19 : AP_Baro_DPS280(AP_Baro &baro, AP_HAL::Device &dev); 20 : 21 : /* AP_Baro public interface: */ 22 : void update() override; 23 : 24 : static AP_Baro_Backend *probe(AP_Baro &baro, AP_HAL::Device &dev); 25 : 26 : protected: 27 : bool init(); 28 : bool read_calibration(void); 29 : void timer(void); 30 : void calculate_PT(int32_t UT, int32_t UP, float &pressure, float &temperature); 31 : 32 : void fix_config_bits16(int16_t &v, uint8_t bits) const; 33 : void fix_config_bits32(int32_t &v, uint8_t bits) const; 34 : virtual void set_config_registers(void); 35 : void check_health(); 36 0 : virtual DevTypes device_type(void) const { return DEVTYPE_BARO_DPS280; } 37 : 38 : AP_HAL::Device *dev; 39 : 40 : uint8_t instance; 41 : 42 : uint32_t count; 43 : uint8_t err_count; 44 : float pressure_sum; 45 : float temperature_sum; 46 : float last_temperature; 47 : bool pending_reset; 48 : 49 : struct dps280_cal { 50 : int16_t C0; // 12bit 51 : int16_t C1; // 12bit 52 : int32_t C00; // 20bit 53 : int32_t C10; // 20bit 54 : int16_t C01; // 16bit 55 : int16_t C11; // 16bit 56 : int16_t C20; // 16bit 57 : int16_t C21; // 16bit 58 : int16_t C30; // 16bit 59 : uint8_t temp_source; 60 : } calibration; 61 : }; 62 : 63 : class AP_Baro_DPS310 : public AP_Baro_DPS280 { 64 : // like DPS280 but workaround for temperature bug 65 : public: 66 : using AP_Baro_DPS280::AP_Baro_DPS280; 67 : static AP_Baro_Backend *probe(AP_Baro &baro, AP_HAL::Device &dev); 68 0 : DevTypes device_type(void) const override { return DEVTYPE_BARO_DPS310; } 69 : void set_config_registers() override; 70 : }; 71 : 72 : 73 : #endif // AP_BARO_DPS280_ENABLED