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 "system.h"
36 #include "i2c.h"
37 
38 
39 class MS5611
40 {
41 private:
42 
43  enum : uint8_t
44  {
45  RESET = 0x1E, // ADC reset command
46  ADC_READ = 0x00, // ADC read command
47  ADC_CONV = 0x40, // ADC conversion command
48  ADC_D1 = 0x00, // ADC D1 conversion
49  ADC_D2 = 0x10, // ADC D2 conversion
50  ADC_256 = 0x00, // ADC OSR=256
51  ADC_512 = 0x02, // ADC OSR=512
52  ADC_1024 = 0x04, // ADC OSR=1024
53  ADC_2048 = 0x06, // ADC OSR=2048
54  ADC_4096 = 0x08, // ADC OSR=4096
55  PROM_RD = 0xA0 // Prom read command
56  };
57 
58  typedef enum
59  {
61  READ_TEMP = 1,
64  } state_t;
66 
67  typedef enum
68  {
78 
79  static const uint8_t ADDR = 0x77;
80 
81  void reset();
82  bool read_prom();
83  int8_t calc_crc();
84  bool read_pres_mess();
85  bool read_temp_mess();
86  bool start_temp_meas();
87  bool start_pres_meas();
88  void convert();
89 
91  uint8_t pres_buf_[3];
92  uint8_t temp_buf_[3];
93  int32_t pres_raw_;
94  int32_t temp_raw_;
95  float pressure_;
96  float temperature_;
97  uint16_t prom[8];
98  uint32_t next_update_ms_;
99  uint32_t next_reboot_ms_;
100  uint32_t last_update_ms_;
102  bool new_data_;
104 
105  callback_type_t callback_type_;
106 
107 public:
108  bool init(I2C* _i2c);
109  void update();
110  void read(float *press, float *temp);
111  bool present();
112 
113  void master_cb(uint8_t result);
114  void temp_read_cb1(uint8_t result);
115  void pres_read_cb1(uint8_t result);
116  void temp_read_cb2(uint8_t result);
117  void pres_read_cb2(uint8_t result);
118  void temp_start_cb(uint8_t result);
119  void pres_start_cb(uint8_t result);
120  void write_zero_cb(uint8_t result);
121  void reset_cb(uint8_t result);
122 };
123 
124 
125 #endif // MS5611_H
bool start_temp_meas()
Definition: ms5611.cpp:278
bool new_data_
Definition: ms5611.h:102
float temperature_
Definition: ms5611.h:96
void temp_start_cb(uint8_t result)
Definition: ms5611.cpp:349
int8_t calc_crc()
Definition: ms5611.cpp:175
bool waiting_for_cb_
Definition: ms5611.h:101
uint32_t last_update_ms_
Definition: ms5611.h:100
float pressure_
Definition: ms5611.h:95
int32_t pres_raw_
Definition: ms5611.h:93
bool read_prom()
Definition: ms5611.cpp:152
callback_type_t callback_type_
Definition: ms5611.h:105
Definition: ms5611.h:39
uint32_t next_reboot_ms_
Definition: ms5611.h:99
void temp_read_cb2(uint8_t result)
Definition: ms5611.cpp:329
void reset()
Definition: ms5611.cpp:147
void pres_read_cb2(uint8_t result)
Definition: ms5611.cpp:339
void pres_read_cb1(uint8_t result)
Definition: ms5611.cpp:319
bool read_temp_mess()
Definition: ms5611.cpp:302
state_t state_
Definition: ms5611.h:65
void reset_cb(uint8_t result)
Definition: ms5611.cpp:367
bool init(I2C *_i2c)
Definition: ms5611.cpp:39
void convert()
Definition: ms5611.cpp:236
bool read_pres_mess()
Definition: ms5611.cpp:294
static volatile int16_t temp
Definition: drv_mpu6050.c:278
void temp_read_cb1(uint8_t result)
Definition: ms5611.cpp:310
void master_cb(uint8_t result)
Definition: ms5611.cpp:394
void update()
Definition: ms5611.cpp:100
state_t
Definition: ms5611.h:58
uint32_t next_update_ms_
Definition: ms5611.h:98
Definition: i2c.h:40
int32_t temp_raw_
Definition: ms5611.h:94
bool present()
Definition: ms5611.cpp:93
void pres_start_cb(uint8_t result)
Definition: ms5611.cpp:358
I2C * i2c_
Definition: ms5611.h:90
callback_type_t
Definition: ms5611.h:67
bool baro_present_
Definition: ms5611.h:103
uint8_t temp_buf_[3]
Definition: ms5611.h:92
void write_zero_cb(uint8_t result)
Definition: ms5611.cpp:378
void read(float *press, float *temp)
Definition: ms5611.cpp:388
uint8_t pres_buf_[3]
Definition: ms5611.h:91
uint16_t prom[8]
Definition: ms5611.h:97
bool start_pres_meas()
Definition: ms5611.cpp:286
static const uint8_t ADDR
Definition: ms5611.h:79


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:19