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