Repo for ESP32 Weather Station Development
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

247 lignes
8.8KB

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