Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Baro/AP_Baro_MS5611.h
Views: 1798
#pragma once12#include "AP_Baro_Backend.h"34#if AP_BARO_MS56XX_ENABLED56#include <AP_HAL/AP_HAL.h>7#include <AP_HAL/Semaphores.h>8#include <AP_HAL/Device.h>910#ifndef HAL_BARO_MS5611_I2C_ADDR11#define HAL_BARO_MS5611_I2C_ADDR 0x7712#endif1314#ifndef HAL_BARO_MS5611_I2C_ADDR215#define HAL_BARO_MS5611_I2C_ADDR2 0x7616#endif1718#ifndef HAL_BARO_MS5607_I2C_ADDR19#define HAL_BARO_MS5607_I2C_ADDR 0x7720#endif2122#ifndef HAL_BARO_MS5837_I2C_ADDR23#define HAL_BARO_MS5837_I2C_ADDR 0x7624#endif2526#ifndef HAL_BARO_MS5637_I2C_ADDR27#define HAL_BARO_MS5637_I2C_ADDR 0x7628#endif2930class AP_Baro_MS56XX : public AP_Baro_Backend31{32public:33void update() override;3435enum MS56XX_TYPE {36BARO_MS5611 = 0,37BARO_MS5607 = 1,38BARO_MS5637 = 2,39BARO_MS5837 = 340};4142static AP_Baro_Backend *probe_5611(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev) {43return probe(baro, std::move(dev), BARO_MS5611);44}45static AP_Baro_Backend *probe_5607(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev) {46return probe(baro, std::move(dev), BARO_MS5607);47}48static AP_Baro_Backend *probe_5637(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev) {49return probe(baro, std::move(dev), BARO_MS5637);50}51static AP_Baro_Backend *probe_5837(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev) {52return probe(baro, std::move(dev), BARO_MS5837);53}5455static AP_Baro_Backend *probe(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev, enum MS56XX_TYPE ms56xx_type=BARO_MS5611);5657private:5859/*60* Update @accum and @count with the new sample in @val, taking into61* account a maximum number of samples given by @max_count; in case62* maximum number is reached, @accum and @count are updated appropriately63*/64static void _update_and_wrap_accumulator(uint32_t *accum, uint32_t val,65uint8_t *count, uint8_t max_count);6667AP_Baro_MS56XX(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev, enum MS56XX_TYPE ms56xx_type);6869bool _init();7071void _calculate_5611();72void _calculate_5607();73void _calculate_5637();74void _calculate_5837();75bool _read_prom_5611(uint16_t prom[8]);76bool _read_prom_5637(uint16_t prom[8]);7778uint16_t _read_prom_word(uint8_t word);79uint32_t _read_adc();8081void _timer();8283AP_HAL::OwnPtr<AP_HAL::Device> _dev;8485/* Shared values between thread sampling the HW and main thread */86struct {87uint32_t s_D1;88uint32_t s_D2;89uint8_t d1_count;90uint8_t d2_count;91} _accum;9293uint8_t _state;94uint8_t _instance;9596/* Last compensated values from accumulated sample */97float _D1, _D2;9899// Internal calibration registers100struct {101uint16_t c1, c2, c3, c4, c5, c6;102} _cal_reg;103104bool _discard_next;105106enum MS56XX_TYPE _ms56xx_type;107};108109#endif // AP_BARO_MS56XX_ENABLED110111112