bme280.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. /*! @file bme280.h
  49. * @brief Sensor driver for BME280 sensor
  50. */
  51. /*!
  52. * @defgroup BME280 SENSOR API
  53. */
  54. #ifndef BME280_H_
  55. #define BME280_H_
  56. /*! CPP guard */
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60. /* Header includes */
  61. #include "bme280_defs.h"
  62. /*!
  63. * @brief This API is the entry point.
  64. * It reads the chip-id and calibration data from the sensor.
  65. *
  66. * @param[in,out] dev : Structure instance of bme280_dev
  67. *
  68. * @return Result of API execution status
  69. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  70. */
  71. int8_t bme280_init(struct bme280_dev *dev);
  72. /*!
  73. * @brief This API writes the given data to the register address
  74. * of the sensor.
  75. *
  76. * @param[in] reg_addr : Register address from where the data to be written.
  77. * @param[in] reg_data : Pointer to data buffer which is to be written
  78. * in the sensor.
  79. * @param[in] len : No of bytes of data to write..
  80. * @param[in] dev : Structure instance of bme280_dev.
  81. *
  82. * @return Result of API execution status
  83. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  84. */
  85. int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, const struct bme280_dev *dev);
  86. /*!
  87. * @brief This API reads the data from the given register address of the sensor.
  88. *
  89. * @param[in] reg_addr : Register address from where the data to be read
  90. * @param[out] reg_data : Pointer to data buffer to store the read data.
  91. * @param[in] len : No of bytes of data to be read.
  92. * @param[in] dev : Structure instance of bme280_dev.
  93. *
  94. * @return Result of API execution status
  95. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  96. */
  97. int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bme280_dev *dev);
  98. /*!
  99. * @brief This API sets the oversampling, filter and standby duration
  100. * (normal mode) settings in the sensor.
  101. *
  102. * @param[in] dev : Structure instance of bme280_dev.
  103. * @param[in] desired_settings : Variable used to select the settings which
  104. * are to be set in the sensor.
  105. *
  106. * @note : Below are the macros to be used by the user for selecting the
  107. * desired settings. User can do OR operation of these macros for configuring
  108. * multiple settings.
  109. *
  110. * Macros | Functionality
  111. * -----------------------|----------------------------------------------
  112. * BME280_OSR_PRESS_SEL | To set pressure oversampling.
  113. * BME280_OSR_TEMP_SEL | To set temperature oversampling.
  114. * BME280_OSR_HUM_SEL | To set humidity oversampling.
  115. * BME280_FILTER_SEL | To set filter setting.
  116. * BME280_STANDBY_SEL | To set standby duration setting.
  117. *
  118. * @return Result of API execution status
  119. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
  120. */
  121. int8_t bme280_set_sensor_settings(uint8_t desired_settings, const struct bme280_dev *dev);
  122. /*!
  123. * @brief This API gets the oversampling, filter and standby duration
  124. * (normal mode) settings from the sensor.
  125. *
  126. * @param[in,out] dev : Structure instance of bme280_dev.
  127. *
  128. * @return Result of API execution status
  129. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
  130. */
  131. int8_t bme280_get_sensor_settings(struct bme280_dev *dev);
  132. /*!
  133. * @brief This API sets the power mode of the sensor.
  134. *
  135. * @param[in] dev : Structure instance of bme280_dev.
  136. * @param[in] sensor_mode : Variable which contains the power mode to be set.
  137. *
  138. * sensor_mode | Macros
  139. * ---------------------|-------------------
  140. * 0 | BME280_SLEEP_MODE
  141. * 1 | BME280_FORCED_MODE
  142. * 3 | BME280_NORMAL_MODE
  143. *
  144. * @return Result of API execution status
  145. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  146. */
  147. int8_t bme280_set_sensor_mode(uint8_t sensor_mode, const struct bme280_dev *dev);
  148. /*!
  149. * @brief This API gets the power mode of the sensor.
  150. *
  151. * @param[in] dev : Structure instance of bme280_dev.
  152. * @param[out] sensor_mode : Pointer variable to store the power mode.
  153. *
  154. * sensor_mode | Macros
  155. * ---------------------|-------------------
  156. * 0 | BME280_SLEEP_MODE
  157. * 1 | BME280_FORCED_MODE
  158. * 3 | BME280_NORMAL_MODE
  159. *
  160. * @return Result of API execution status
  161. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  162. */
  163. int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, const struct bme280_dev *dev);
  164. /*!
  165. * @brief This API performs the soft reset of the sensor.
  166. *
  167. * @param[in] dev : Structure instance of bme280_dev.
  168. *
  169. * @return Result of API execution status
  170. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
  171. */
  172. int8_t bme280_soft_reset(const struct bme280_dev *dev);
  173. /*!
  174. * @brief This API reads the pressure, temperature and humidity data from the
  175. * sensor, compensates the data and store it in the bme280_data structure
  176. * instance passed by the user.
  177. *
  178. * @param[in] sensor_comp : Variable which selects which data to be read from
  179. * the sensor.
  180. *
  181. * sensor_comp | Macros
  182. * ------------|-------------------
  183. * 1 | BME280_PRESS
  184. * 2 | BME280_TEMP
  185. * 4 | BME280_HUM
  186. * 7 | BME280_ALL
  187. *
  188. * @param[out] comp_data : Structure instance of bme280_data.
  189. * @param[in] dev : Structure instance of bme280_dev.
  190. *
  191. * @return Result of API execution status
  192. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  193. */
  194. int8_t bme280_get_sensor_data(uint8_t sensor_comp, struct bme280_data *comp_data, struct bme280_dev *dev);
  195. /*!
  196. * @brief This API is used to parse the pressure, temperature and
  197. * humidity data and store it in the bme280_uncomp_data structure instance.
  198. *
  199. * @param[in] reg_data : Contains register data which needs to be parsed
  200. * @param[out] uncomp_data : Contains the uncompensated pressure, temperature
  201. * and humidity data.
  202. */
  203. void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data);
  204. /*!
  205. * @brief This API is used to compensate the pressure and/or
  206. * temperature and/or humidity data according to the component selected by the
  207. * user.
  208. *
  209. * @param[in] sensor_comp : Used to select pressure and/or temperature and/or
  210. * humidity.
  211. * @param[in] uncomp_data : Contains the uncompensated pressure, temperature and
  212. * humidity data.
  213. * @param[out] comp_data : Contains the compensated pressure and/or temperature
  214. * and/or humidity data.
  215. * @param[in] calib_data : Pointer to the calibration data structure.
  216. *
  217. * @return Result of API execution status.
  218. * @retval zero -> Success / -ve value -> Error
  219. */
  220. int8_t bme280_compensate_data(uint8_t sensor_comp,
  221. const struct bme280_uncomp_data *uncomp_data,
  222. struct bme280_data *comp_data,
  223. struct bme280_calib_data *calib_data);
  224. #ifdef __cplusplus
  225. }
  226. #endif /* End of CPP guard */
  227. #endif /* BME280_H_ */
  228. /** @}*/