ms5611.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef MS5611_H
33 #define MS5611_H
34 
35 #include "i2c.h"
36 #include "system.h"
37 
38 class MS5611
39 {
40 private:
41  enum : uint8_t
42  {
43  RESET = 0x1E, // ADC reset command
44  ADC_READ = 0x00, // ADC read command
45  ADC_CONV = 0x40, // ADC conversion command
46  ADC_D1 = 0x00, // ADC D1 conversion
47  ADC_D2 = 0x10, // ADC D2 conversion
48  ADC_256 = 0x00, // ADC OSR=256
49  ADC_512 = 0x02, // ADC OSR=512
50  ADC_1024 = 0x04, // ADC OSR=1024
51  ADC_2048 = 0x06, // ADC OSR=2048
52  ADC_4096 = 0x08, // ADC OSR=4096
53  PROM_RD = 0xA0 // Prom read command
54  };
55 
56  typedef enum
57  {
59  READ_TEMP = 1,
62  } state_t;
64 
65  typedef enum
66  {
76 
77  static const uint8_t ADDR = 0x77;
78 
79  void reset();
80  bool read_prom();
81  int8_t calc_crc();
82  bool read_pres_mess();
83  bool read_temp_mess();
84  bool start_temp_meas();
85  bool start_pres_meas();
86  void convert();
87 
88  I2C *i2c_{nullptr};
89  uint8_t pres_buf_[3];
90  uint8_t temp_buf_[3];
91  int32_t pres_raw_;
92  int32_t temp_raw_;
93  float pressure_;
94  float temperature_;
95  uint16_t prom[8];
96  uint32_t next_update_ms_;
97  uint32_t next_reboot_ms_;
98  uint32_t last_update_ms_;
100  bool new_data_;
101  bool baro_present_{false};
102 
103  callback_type_t callback_type_;
104 
105 public:
106  bool init(I2C *_i2c);
107  void update();
108  void read(float *press, float *temp);
109  bool present();
110 
111  void master_cb(uint8_t result);
112  void temp_read_cb1(uint8_t result);
113  void pres_read_cb1(uint8_t result);
114  void temp_read_cb2(uint8_t result);
115  void pres_read_cb2(uint8_t result);
116  void temp_start_cb(uint8_t result);
117  void pres_start_cb(uint8_t result);
118  void write_zero_cb(uint8_t result);
119  void reset_cb(uint8_t result);
120  inline bool is_initialized() { return i2c_; }
121 };
122 
123 #endif // MS5611_H
bool start_temp_meas()
Definition: ms5611.cpp:275
bool new_data_
Definition: ms5611.h:100
float temperature_
Definition: ms5611.h:94
void temp_start_cb(uint8_t result)
Definition: ms5611.cpp:345
int8_t calc_crc()
Definition: ms5611.cpp:172
bool waiting_for_cb_
Definition: ms5611.h:99
uint32_t last_update_ms_
Definition: ms5611.h:98
float pressure_
Definition: ms5611.h:93
int32_t pres_raw_
Definition: ms5611.h:91
bool read_prom()
Definition: ms5611.cpp:149
callback_type_t callback_type_
Definition: ms5611.h:103
Definition: ms5611.h:38
uint32_t next_reboot_ms_
Definition: ms5611.h:97
void temp_read_cb2(uint8_t result)
Definition: ms5611.cpp:325
void reset()
Definition: ms5611.cpp:147
void pres_read_cb2(uint8_t result)
Definition: ms5611.cpp:335
void pres_read_cb1(uint8_t result)
Definition: ms5611.cpp:316
bool read_temp_mess()
Definition: ms5611.cpp:299
state_t state_
Definition: ms5611.h:63
void reset_cb(uint8_t result)
Definition: ms5611.cpp:363
bool init(I2C *_i2c)
Definition: ms5611.cpp:39
void convert()
Definition: ms5611.cpp:233
bool read_pres_mess()
Definition: ms5611.cpp:291
bool is_initialized()
Definition: ms5611.h:120
static volatile int16_t temp
Definition: drv_mpu6050.c:278
void temp_read_cb1(uint8_t result)
Definition: ms5611.cpp:307
void master_cb(uint8_t result)
Definition: ms5611.cpp:390
void update()
Definition: ms5611.cpp:101
state_t
Definition: ms5611.h:56
uint32_t next_update_ms_
Definition: ms5611.h:96
Definition: i2c.h:39
int32_t temp_raw_
Definition: ms5611.h:92
bool present()
Definition: ms5611.cpp:94
void pres_start_cb(uint8_t result)
Definition: ms5611.cpp:354
I2C * i2c_
Definition: ms5611.h:88
callback_type_t
Definition: ms5611.h:65
bool baro_present_
Definition: ms5611.h:101
uint8_t temp_buf_[3]
Definition: ms5611.h:90
void write_zero_cb(uint8_t result)
Definition: ms5611.cpp:374
void read(float *press, float *temp)
Definition: ms5611.cpp:384
uint8_t pres_buf_[3]
Definition: ms5611.h:89
uint16_t prom[8]
Definition: ms5611.h:95
bool start_pres_meas()
Definition: ms5611.cpp:283
static const uint8_t ADDR
Definition: ms5611.h:77


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:47