PX4 Firmware
PX4 Autopilot Software http://px4.io
bmp280.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2016-2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file bmp280.h
36  *
37  * Shared defines for the bmp280 driver.
38  */
39 #pragma once
40 
41 #define BMP280_ADDR_CAL 0x88 /* address of 12x 2 bytes calibration data */
42 #define BMP280_ADDR_DATA 0xF7 /* address of 2x 3 bytes p-t data */
43 
44 #define BMP280_ADDR_CONFIG 0xF5 /* configuration */
45 #define BMP280_ADDR_CTRL 0xF4 /* controll */
46 #define BMP280_ADDR_STATUS 0xF3 /* state */
47 #define BMP280_ADDR_RESET 0xE0 /* reset */
48 #define BMP280_ADDR_ID 0xD0 /* id */
49 
50 #define BMP280_VALUE_ID 0x58 /* chip id */
51 #define BMP280_VALUE_RESET 0xB6 /* reset */
52 
53 #define BMP280_STATUS_MEASURING (1<<3) /* if in process of measure */
54 #define BMP280_STATUS_COPING (1<<0) /* if in process of data copy */
55 
56 #define BMP280_CTRL_P0 (0x0<<2) /* no p measure */
57 #define BMP280_CTRL_P1 (0x1<<2)
58 #define BMP280_CTRL_P2 (0x2<<2)
59 #define BMP280_CTRL_P4 (0x3<<2)
60 #define BMP280_CTRL_P8 (0x4<<2)
61 #define BMP280_CTRL_P16 (0x5<<2)
62 
63 #define BMP280_CTRL_T0 (0x0<<5) /* no t measure */
64 #define BMP280_CTRL_T1 (0x1<<5)
65 #define BMP280_CTRL_T2 (0x2<<5)
66 #define BMP280_CTRL_T4 (0x3<<5)
67 #define BMP280_CTRL_T8 (0x4<<5)
68 #define BMP280_CTRL_T16 (0x5<<5)
69 
70 #define BMP280_CONFIG_F0 (0x0<<2) /* no filter */
71 #define BMP280_CONFIG_F2 (0x1<<2)
72 #define BMP280_CONFIG_F4 (0x2<<2)
73 #define BMP280_CONFIG_F8 (0x3<<2)
74 #define BMP280_CONFIG_F16 (0x4<<2)
75 
76 
77 #define BMP280_CTRL_MODE_SLEEP 0x0
78 #define BMP280_CTRL_MODE_FORCE 0x1 /* on demand, goes to sleep after */
79 #define BMP280_CTRL_MODE_NORMAL 0x3
80 
81 #define BMP280_MT_INIT 6400 /* max measure time of initial p + t in us */
82 #define BMP280_MT 2300 /* max measure time of p or t in us */
83 
84 namespace bmp280
85 {
86 
87 #pragma pack(push,1)
88 struct calibration_s {
89  uint16_t t1;
90  int16_t t2;
91  int16_t t3;
92 
93  uint16_t p1;
94  int16_t p2;
95  int16_t p3;
96  int16_t p4;
97  int16_t p5;
98  int16_t p6;
99  int16_t p7;
100  int16_t p8;
101  int16_t p9;
102 }; //calibration data
103 
104 struct data_s {
105  uint8_t p_msb;
106  uint8_t p_lsb;
107  uint8_t p_xlsb;
108 
109  uint8_t t_msb;
110  uint8_t t_lsb;
111  uint8_t t_xlsb;
112 }; // data
113 #pragma pack(pop)
114 
116  float t1;
117  float t2;
118  float t3;
119 
120  float p1;
121  float p2;
122  float p3;
123  float p4;
124  float p5;
125  float p6;
126  float p7;
127  float p8;
128  float p9;
129 };
130 
131 class IBMP280
132 {
133 public:
134  virtual ~IBMP280() = default;
135 
136  virtual int init() = 0;
137 
138  // read reg value
139  virtual uint8_t get_reg(uint8_t addr) = 0;
140 
141  // write reg value
142  virtual int set_reg(uint8_t value, uint8_t addr) = 0;
143 
144  // bulk read of data into buffer, return same pointer
145  virtual bmp280::data_s *get_data(uint8_t addr) = 0;
146 
147  // bulk read of calibration data into buffer, return same pointer
148  virtual bmp280::calibration_s *get_calibration(uint8_t addr) = 0;
149 
150  virtual uint32_t get_device_id() const = 0;
151 
152 };
153 
154 } /* namespace */
155 
156 
157 /* interface factories */
158 extern bmp280::IBMP280 *bmp280_spi_interface(uint8_t busnum, uint32_t device);
159 extern bmp280::IBMP280 *bmp280_i2c_interface(uint8_t busnum, uint32_t device);
160 typedef bmp280::IBMP280 *(*BMP280_constructor)(uint8_t, uint32_t);
bmp280::IBMP280 * bmp280_spi_interface(uint8_t busnum, uint32_t device)
uint8_t p_msb
Definition: bmp280.h:105
Definition: bmp280.h:84
Namespace encapsulating all device framework classes, functions and data.
Definition: CDev.cpp:47
bmp280::IBMP280 * bmp280_i2c_interface(uint8_t busnum, uint32_t device)
uint8_t t_msb
Definition: bmp280.h:109
void init()
Activates/configures the hardware registers.
uint8_t p_lsb
Definition: bmp280.h:106
uint8_t t_lsb
Definition: bmp280.h:110
uint8_t t_xlsb
Definition: bmp280.h:111
uint8_t p_xlsb
Definition: bmp280.h:107