temp_sensor.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. /**
  20. * @brief temperature sensor range option.
  21. */
  22. typedef enum {
  23. TSENS_DAC_L0 = 0, /*!< offset = -2, measure range: 50℃ ~ 125℃, error < 3℃. */
  24. TSENS_DAC_L1, /*!< offset = -1, measure range: 20℃ ~ 100℃, error < 2℃. */
  25. TSENS_DAC_L2, /*!< offset = 0, measure range:-10℃ ~ 80℃, error < 1℃. */
  26. TSENS_DAC_L3, /*!< offset = 1, measure range:-30℃ ~ 50℃, error < 2℃. */
  27. TSENS_DAC_L4, /*!< offset = 2, measure range:-40℃ ~ 20℃, error < 3℃. */
  28. TSENS_DAC_MAX,
  29. TSENS_DAC_DEFAULT = TSENS_DAC_L2,
  30. } temp_sensor_dac_offset_t;
  31. /**
  32. * @brief Configuration for temperature sensor reading
  33. */
  34. typedef struct {
  35. temp_sensor_dac_offset_t dac_offset; /*!< The temperature measurement range is configured with a built-in temperature offset DAC. */
  36. uint8_t clk_div; /*!< Default: 6 */
  37. } temp_sensor_config_t;
  38. /**
  39. * @brief temperature sensor default setting.
  40. */
  41. #define TSENS_CONFIG_DEFAULT() {.dac_offset = TSENS_DAC_L2, \
  42. .clk_div = 6}
  43. /**
  44. * @brief Set parameter of temperature sensor.
  45. * @param tsens
  46. * @return
  47. * - ESP_OK Success
  48. */
  49. esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens);
  50. /**
  51. * @brief Get parameter of temperature sensor.
  52. * @param tsens
  53. * @return
  54. * - ESP_OK Success
  55. */
  56. esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens);
  57. /**
  58. * @brief Start temperature sensor measure.
  59. * @return
  60. * - ESP_OK Success
  61. * - ESP_ERR_INVALID_ARG
  62. */
  63. esp_err_t temp_sensor_start(void);
  64. /**
  65. * @brief Stop temperature sensor measure.
  66. * @return
  67. * - ESP_OK Success
  68. */
  69. esp_err_t temp_sensor_stop(void);
  70. /**
  71. * @brief Read temperature sensor raw data.
  72. * @param tsens_out Pointer to raw data, Range: 0 ~ 255
  73. * @return
  74. * - ESP_OK Success
  75. * - ESP_ERR_INVALID_ARG `tsens_out` is NULL
  76. * - ESP_ERR_INVALID_STATE temperature sensor dont start
  77. */
  78. esp_err_t temp_sensor_read_raw(uint32_t *tsens_out);
  79. /**
  80. * @brief Read temperature sensor data that is converted to degrees Celsius.
  81. * @note Should not be called from interrupt.
  82. * @param celsius The measure output value.
  83. * @return
  84. * - ESP_OK Success
  85. * - ESP_ERR_INVALID_ARG ARG is NULL.
  86. * - ESP_ERR_INVALID_STATE The ambient temperature is out of range.
  87. */
  88. esp_err_t temp_sensor_read_celsius(float *celsius);
  89. #ifdef __cplusplus
  90. }
  91. #endif