CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Baro/AP_Baro_MS5611.h
Views: 1798
1
#pragma once
2
3
#include "AP_Baro_Backend.h"
4
5
#if AP_BARO_MS56XX_ENABLED
6
7
#include <AP_HAL/AP_HAL.h>
8
#include <AP_HAL/Semaphores.h>
9
#include <AP_HAL/Device.h>
10
11
#ifndef HAL_BARO_MS5611_I2C_ADDR
12
#define HAL_BARO_MS5611_I2C_ADDR 0x77
13
#endif
14
15
#ifndef HAL_BARO_MS5611_I2C_ADDR2
16
#define HAL_BARO_MS5611_I2C_ADDR2 0x76
17
#endif
18
19
#ifndef HAL_BARO_MS5607_I2C_ADDR
20
#define HAL_BARO_MS5607_I2C_ADDR 0x77
21
#endif
22
23
#ifndef HAL_BARO_MS5837_I2C_ADDR
24
#define HAL_BARO_MS5837_I2C_ADDR 0x76
25
#endif
26
27
#ifndef HAL_BARO_MS5637_I2C_ADDR
28
#define HAL_BARO_MS5637_I2C_ADDR 0x76
29
#endif
30
31
class AP_Baro_MS56XX : public AP_Baro_Backend
32
{
33
public:
34
void update() override;
35
36
enum MS56XX_TYPE {
37
BARO_MS5611 = 0,
38
BARO_MS5607 = 1,
39
BARO_MS5637 = 2,
40
BARO_MS5837 = 3
41
};
42
43
static AP_Baro_Backend *probe_5611(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev) {
44
return probe(baro, std::move(dev), BARO_MS5611);
45
}
46
static AP_Baro_Backend *probe_5607(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev) {
47
return probe(baro, std::move(dev), BARO_MS5607);
48
}
49
static AP_Baro_Backend *probe_5637(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev) {
50
return probe(baro, std::move(dev), BARO_MS5637);
51
}
52
static AP_Baro_Backend *probe_5837(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev) {
53
return probe(baro, std::move(dev), BARO_MS5837);
54
}
55
56
static AP_Baro_Backend *probe(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev, enum MS56XX_TYPE ms56xx_type=BARO_MS5611);
57
58
private:
59
60
/*
61
* Update @accum and @count with the new sample in @val, taking into
62
* account a maximum number of samples given by @max_count; in case
63
* maximum number is reached, @accum and @count are updated appropriately
64
*/
65
static void _update_and_wrap_accumulator(uint32_t *accum, uint32_t val,
66
uint8_t *count, uint8_t max_count);
67
68
AP_Baro_MS56XX(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev, enum MS56XX_TYPE ms56xx_type);
69
70
bool _init();
71
72
void _calculate_5611();
73
void _calculate_5607();
74
void _calculate_5637();
75
void _calculate_5837();
76
bool _read_prom_5611(uint16_t prom[8]);
77
bool _read_prom_5637(uint16_t prom[8]);
78
79
uint16_t _read_prom_word(uint8_t word);
80
uint32_t _read_adc();
81
82
void _timer();
83
84
AP_HAL::OwnPtr<AP_HAL::Device> _dev;
85
86
/* Shared values between thread sampling the HW and main thread */
87
struct {
88
uint32_t s_D1;
89
uint32_t s_D2;
90
uint8_t d1_count;
91
uint8_t d2_count;
92
} _accum;
93
94
uint8_t _state;
95
uint8_t _instance;
96
97
/* Last compensated values from accumulated sample */
98
float _D1, _D2;
99
100
// Internal calibration registers
101
struct {
102
uint16_t c1, c2, c3, c4, c5, c6;
103
} _cal_reg;
104
105
bool _discard_next;
106
107
enum MS56XX_TYPE _ms56xx_type;
108
};
109
110
#endif // AP_BARO_MS56XX_ENABLED
111
112