temp_sensor.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2010-2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include <stdint.h>
  15. #include "esp_err.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. typedef enum {
  20. TSENS_DAC_L0 = 0, /*!< offset = -2, measure range: 50℃ ~ 125℃, error < 3℃. */
  21. TSENS_DAC_L1, /*!< offset = -1, measure range: 20℃ ~ 100℃, error < 2℃. */
  22. TSENS_DAC_L2, /*!< offset = 0, measure range:-10℃ ~ 80℃, error < 1℃. */
  23. TSENS_DAC_L3, /*!< offset = 1, measure range:-30℃ ~ 50℃, error < 2℃. */
  24. TSENS_DAC_L4, /*!< offset = 2, measure range:-40℃ ~ 20℃, error < 3℃. */
  25. TSENS_DAC_MAX,
  26. TSENS_DAC_DEFAULT = TSENS_DAC_L2,
  27. } temp_sensor_dac_offset_t;
  28. /**
  29. * @brief Configuration for temperature sensor reading
  30. */
  31. typedef struct {
  32. temp_sensor_dac_offset_t dac_offset; /*!< The temperature measurement range is configured with a built-in temperature offset DAC. */
  33. uint8_t clk_div; /*!< Default: 6 */
  34. } temp_sensor_config_t;
  35. #define TSENS_CONFIG_DEFAULT() {.dac_offset = TSENS_DAC_L2, \
  36. .clk_div = 6}
  37. /**
  38. * @brief Set parameter of temperature sensor.
  39. * @param tsens
  40. * @return
  41. * - ESP_OK Success
  42. */
  43. esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens);
  44. /**
  45. * @brief Get parameter of temperature sensor.
  46. * @param tsens
  47. * @return
  48. * - ESP_OK Success
  49. */
  50. esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens);
  51. /**
  52. * @brief Start temperature sensor measure.
  53. * @return
  54. * - ESP_OK Success
  55. * - ESP_ERR_INVALID_ARG
  56. */
  57. esp_err_t temp_sensor_start(void);
  58. /**
  59. * @brief Stop temperature sensor measure.
  60. * @return
  61. * - ESP_OK Success
  62. */
  63. esp_err_t temp_sensor_stop(void);
  64. /**
  65. * @brief Read temperature sensor raw data.
  66. * @param tsens_out Pointer to raw data, Range: 0 ~ 255
  67. * @return
  68. * - ESP_OK Success
  69. * - ESP_ERR_INVALID_ARG `tsens_out` is NULL
  70. * - ESP_ERR_INVALID_STATE temperature sensor dont start
  71. */
  72. esp_err_t temp_sensor_read_raw(uint32_t *tsens_out);
  73. /**
  74. * @brief Read temperature sensor data that is converted to degrees Celsius.
  75. * @note Should not be called from interrupt.
  76. * @param celsius The measure output value.
  77. * @return
  78. * - ESP_OK Success
  79. * - ESP_ERR_INVALID_ARG ARG is NULL.
  80. * - ESP_ERR_INVALID_STATE The ambient temperature is out of range.
  81. */
  82. esp_err_t temp_sensor_read_celsius(float *celsius);
  83. #ifdef __cplusplus
  84. }
  85. #endif