]> git.itanic.dy.fi Git - BME280_driver/blob - bme280.h
Merge pull request #73 from byteneumann/patch-1
[BME280_driver] / bme280.h
1 /**
2  * Copyright (C) 2018 - 2019 Bosch Sensortec GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * Neither the name of the copyright holder nor the names of the
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
23  * OR CONTRIBUTORS BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25  * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
33  *
34  * The information provided is believed to be accurate and reliable.
35  * The copyright holder assumes no responsibility
36  * for the consequences of use
37  * of such information nor for any infringement of patents or
38  * other rights of third parties which may result from its use.
39  * No license is granted by implication or otherwise under any patent or
40  * patent rights of the copyright holder.
41  *
42  * @file    bme280.h
43  * @date    08 Mar 2019
44  * @version 3.3.6
45  * @brief
46  *
47  */
48
49 /*! @file bme280.h
50  * @brief Sensor driver for BME280 sensor
51  */
52
53 /*!
54  * @defgroup BME280 SENSOR API
55  */
56 #ifndef BME280_H_
57 #define BME280_H_
58
59 /*! CPP guard */
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64 /* Header includes */
65 #include "bme280_defs.h"
66
67 /*!
68  *  @brief This API is the entry point.
69  *  It reads the chip-id and calibration data from the sensor.
70  *
71  *  @param[in,out] dev : Structure instance of bme280_dev
72  *
73  *  @return Result of API execution status
74  *  @retval zero -> Success / +ve value -> Warning / -ve value -> Error
75  */
76 int8_t bme280_init(struct bme280_dev *dev);
77
78 /*!
79  * @brief This API writes the given data to the register address
80  * of the sensor.
81  *
82  * @param[in] reg_addr : Register address from where the data to be written.
83  * @param[in] reg_data : Pointer to data buffer which is to be written
84  * in the sensor.
85  * @param[in] len : No of bytes of data to write..
86  * @param[in] dev : Structure instance of bme280_dev.
87  *
88  * @return Result of API execution status
89  * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
90  */
91 int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, const struct bme280_dev *dev);
92
93 /*!
94  * @brief This API reads the data from the given register address of the sensor.
95  *
96  * @param[in] reg_addr : Register address from where the data to be read
97  * @param[out] reg_data : Pointer to data buffer to store the read data.
98  * @param[in] len : No of bytes of data to be read.
99  * @param[in] dev : Structure instance of bme280_dev.
100  *
101  * @return Result of API execution status
102  * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
103  */
104 int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bme280_dev *dev);
105
106 /*!
107  * @brief This API sets the oversampling, filter and standby duration
108  * (normal mode) settings in the sensor.
109  *
110  * @param[in] dev : Structure instance of bme280_dev.
111  * @param[in] desired_settings : Variable used to select the settings which
112  * are to be set in the sensor.
113  *
114  * @note : Below are the macros to be used by the user for selecting the
115  * desired settings. User can do OR operation of these macros for configuring
116  * multiple settings.
117  *
118  * Macros         |   Functionality
119  * -----------------------|----------------------------------------------
120  * BME280_OSR_PRESS_SEL    |   To set pressure oversampling.
121  * BME280_OSR_TEMP_SEL     |   To set temperature oversampling.
122  * BME280_OSR_HUM_SEL    |   To set humidity oversampling.
123  * BME280_FILTER_SEL     |   To set filter setting.
124  * BME280_STANDBY_SEL  |   To set standby duration setting.
125  *
126  * @return Result of API execution status
127  * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
128  */
129 int8_t bme280_set_sensor_settings(uint8_t desired_settings, const struct bme280_dev *dev);
130
131 /*!
132  * @brief This API gets the oversampling, filter and standby duration
133  * (normal mode) settings from the sensor.
134  *
135  * @param[in,out] dev : Structure instance of bme280_dev.
136  *
137  * @return Result of API execution status
138  * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
139  */
140 int8_t bme280_get_sensor_settings(struct bme280_dev *dev);
141
142 /*!
143  * @brief This API sets the power mode of the sensor.
144  *
145  * @param[in] dev : Structure instance of bme280_dev.
146  * @param[in] sensor_mode : Variable which contains the power mode to be set.
147  *
148  *    sensor_mode           |   Macros
149  * ---------------------|-------------------
150  *     0                | BME280_SLEEP_MODE
151  *     1                | BME280_FORCED_MODE
152  *     3                | BME280_NORMAL_MODE
153  *
154  * @return Result of API execution status
155  * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
156  */
157 int8_t bme280_set_sensor_mode(uint8_t sensor_mode, const struct bme280_dev *dev);
158
159 /*!
160  * @brief This API gets the power mode of the sensor.
161  *
162  * @param[in] dev : Structure instance of bme280_dev.
163  * @param[out] sensor_mode : Pointer variable to store the power mode.
164  *
165  *   sensor_mode            |   Macros
166  * ---------------------|-------------------
167  *     0                | BME280_SLEEP_MODE
168  *     1                | BME280_FORCED_MODE
169  *     3                | BME280_NORMAL_MODE
170  *
171  * @return Result of API execution status
172  * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
173  */
174 int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, const struct bme280_dev *dev);
175
176 /*!
177  * @brief This API performs the soft reset of the sensor.
178  *
179  * @param[in] dev : Structure instance of bme280_dev.
180  *
181  * @return Result of API execution status
182  * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
183  */
184 int8_t bme280_soft_reset(const struct bme280_dev *dev);
185
186 /*!
187  * @brief This API reads the pressure, temperature and humidity data from the
188  * sensor, compensates the data and store it in the bme280_data structure
189  * instance passed by the user.
190  *
191  * @param[in] sensor_comp : Variable which selects which data to be read from
192  * the sensor.
193  *
194  * sensor_comp |   Macros
195  * ------------|-------------------
196  *     1       | BME280_PRESS
197  *     2       | BME280_TEMP
198  *     4       | BME280_HUM
199  *     7       | BME280_ALL
200  *
201  * @param[out] comp_data : Structure instance of bme280_data.
202  * @param[in] dev : Structure instance of bme280_dev.
203  *
204  * @return Result of API execution status
205  * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
206  */
207 int8_t bme280_get_sensor_data(uint8_t sensor_comp, struct bme280_data *comp_data, struct bme280_dev *dev);
208
209 /*!
210  *  @brief This API is used to parse the pressure, temperature and
211  *  humidity data and store it in the bme280_uncomp_data structure instance.
212  *
213  *  @param[in] reg_data     : Contains register data which needs to be parsed
214  *  @param[out] uncomp_data : Contains the uncompensated pressure, temperature
215  *  and humidity data.
216  */
217 void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data);
218
219 /*!
220  * @brief This API is used to compensate the pressure and/or
221  * temperature and/or humidity data according to the component selected by the
222  * user.
223  *
224  * @param[in] sensor_comp : Used to select pressure and/or temperature and/or
225  * humidity.
226  * @param[in] uncomp_data : Contains the uncompensated pressure, temperature and
227  * humidity data.
228  * @param[out] comp_data : Contains the compensated pressure and/or temperature
229  * and/or humidity data.
230  * @param[in] calib_data : Pointer to the calibration data structure.
231  *
232  * @return Result of API execution status.
233  * @retval zero -> Success / -ve value -> Error
234  */
235 int8_t bme280_compensate_data(uint8_t sensor_comp,
236                               const struct bme280_uncomp_data *uncomp_data,
237                               struct bme280_data *comp_data,
238                               struct bme280_calib_data *calib_data);
239
240 #ifdef __cplusplus
241 }
242 #endif /* End of CPP guard */
243 #endif /* BME280_H_ */
244 /** @}*/