mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Temperature_sensor: Add temperature support for ESP32-S3
This commit is contained in:
parent
441900caa2
commit
214e206111
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief temperature sensor range option.
|
||||
*/
|
||||
typedef enum {
|
||||
TSENS_DAC_L0 = 0, /*!< offset = -2, measure range: 50℃ ~ 125℃, error < 3℃. */
|
||||
TSENS_DAC_L1, /*!< offset = -1, measure range: 20℃ ~ 100℃, error < 2℃. */
|
||||
TSENS_DAC_L2, /*!< offset = 0, measure range:-10℃ ~ 80℃, error < 1℃. */
|
||||
TSENS_DAC_L3, /*!< offset = 1, measure range:-30℃ ~ 50℃, error < 2℃. */
|
||||
TSENS_DAC_L4, /*!< offset = 2, measure range:-40℃ ~ 20℃, error < 3℃. */
|
||||
TSENS_DAC_MAX,
|
||||
TSENS_DAC_DEFAULT = TSENS_DAC_L2,
|
||||
} temp_sensor_dac_offset_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration for temperature sensor reading
|
||||
*/
|
||||
typedef struct {
|
||||
temp_sensor_dac_offset_t dac_offset; /*!< The temperature measurement range is configured with a built-in temperature offset DAC. */
|
||||
uint8_t clk_div; /*!< Default: 6 */
|
||||
} temp_sensor_config_t;
|
||||
|
||||
/**
|
||||
* @brief temperature sensor default setting.
|
||||
*/
|
||||
#define TSENS_CONFIG_DEFAULT() {.dac_offset = TSENS_DAC_L2, \
|
||||
.clk_div = 6}
|
||||
|
||||
/**
|
||||
* @brief Set parameter of temperature sensor.
|
||||
* @param tsens
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens);
|
||||
|
||||
/**
|
||||
* @brief Get parameter of temperature sensor.
|
||||
* @param tsens
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens);
|
||||
|
||||
/**
|
||||
* @brief Start temperature sensor measure.
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG
|
||||
*/
|
||||
esp_err_t temp_sensor_start(void);
|
||||
|
||||
/**
|
||||
* @brief Stop temperature sensor measure.
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t temp_sensor_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Read temperature sensor raw data.
|
||||
* @param tsens_out Pointer to raw data, Range: 0 ~ 255
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG `tsens_out` is NULL
|
||||
* - ESP_ERR_INVALID_STATE temperature sensor dont start
|
||||
*/
|
||||
esp_err_t temp_sensor_read_raw(uint32_t *tsens_out);
|
||||
|
||||
/**
|
||||
* @brief Read temperature sensor data that is converted to degrees Celsius.
|
||||
* @note Should not be called from interrupt.
|
||||
* @param celsius The measure output value.
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG ARG is NULL.
|
||||
* - ESP_ERR_INVALID_STATE The ambient temperature is out of range.
|
||||
*/
|
||||
esp_err_t temp_sensor_read_celsius(float *celsius);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -96,3 +96,24 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal)
|
||||
{
|
||||
uint32_t version = esp_efuse_rtc_calib_get_ver();
|
||||
if (version != 1) {
|
||||
*tsens_cal = 0.0;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
const esp_efuse_desc_t** cal_temp_efuse;
|
||||
cal_temp_efuse = ESP_EFUSE_TEMP_CALIB;
|
||||
int cal_temp_size = esp_efuse_get_field_size(cal_temp_efuse);
|
||||
assert(cal_temp_size == 9);
|
||||
|
||||
uint32_t cal_temp = 0;
|
||||
esp_err_t err = esp_efuse_read_field_blob(cal_temp_efuse, &cal_temp, cal_temp_size);
|
||||
assert(err == ESP_OK);
|
||||
(void)err;
|
||||
// BIT(8) stands for sign: 1: negtive, 0: positive
|
||||
*tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -48,11 +48,12 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in
|
||||
/**
|
||||
* @brief Get the temperature sensor calibration number delta_T stored in the efuse.
|
||||
*
|
||||
* @param version Version of the stored efuse
|
||||
* @param tsens_cal Pointer of the specification of temperature sensor calibration number in efuse.
|
||||
*
|
||||
* @return The specification of temperature sensor calibration number in efuse.
|
||||
* @return ESP_OK if get the calibration value successfully.
|
||||
* ESP_ERR_INVALID_ARG if can't get the calibration value.
|
||||
*/
|
||||
float esp_efuse_rtc_calib_get_cal_temp(int version);
|
||||
esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
146
components/hal/esp32s3/include/hal/temperature_sensor_ll.h
Normal file
146
components/hal/esp32s3/include/hal/temperature_sensor_ll.h
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The hal is not public api, don't use in application code.
|
||||
* See readme.md in component/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The LL for temperature sensor
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "regi2c_ctrl.h"
|
||||
#include "soc/apb_saradc_struct.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/sens_struct.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ADC_FACTOR (0.4386)
|
||||
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
||||
#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR (20.52)
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_RANGE_NUM (5)
|
||||
|
||||
typedef struct {
|
||||
int offset;
|
||||
int reg_val;
|
||||
int range_min;
|
||||
int range_max;
|
||||
int error_max;
|
||||
} temp_sensor_ll_attribute_t;
|
||||
|
||||
static const temp_sensor_ll_attribute_t temp_sensor_ll_attributes[TEMPERATURE_SENSOR_LL_RANGE_NUM] = {
|
||||
/*Offset reg_val min max error */
|
||||
{-2, 5, 50, 125, 3},
|
||||
{-1, 7, 20, 100, 2},
|
||||
{ 0, 15, -10, 80, 1},
|
||||
{ 1, 11, -30, 50, 2},
|
||||
{ 2, 10, -40, 20, 3},
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enable the temperature sensor power.
|
||||
*
|
||||
* @param enable true: enable the power.
|
||||
*/
|
||||
static inline void temperature_sensor_ll_enable(bool enable)
|
||||
{
|
||||
SENS.sar_tctrl.tsens_power_up_force = enable;
|
||||
SENS.sar_tctrl2.tsens_xpd_force = enable;
|
||||
SENS.sar_tctrl.tsens_power_up = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_clk_enable(bool enable)
|
||||
{
|
||||
SENS.sar_peri_clk_gate_conf.tsens_clk_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Choose the clock. No need to choose the clock source on ESP32-S3. ESP32-S3
|
||||
* can use RTC clock.
|
||||
*/
|
||||
static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t clk_src)
|
||||
{
|
||||
// No need to select the temperature sensor clock on esp32s3.
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the hardware range, you can refer to the table ``temp_sensor_ll_attributes``
|
||||
*
|
||||
* @param tsens_dac ``reg_val`` in table ``temp_sensor_ll_attributes``
|
||||
*/
|
||||
static inline void temperature_sensor_ll_set_range(uint32_t tsens_dac)
|
||||
{
|
||||
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_PU);
|
||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_SAR_M);
|
||||
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, tsens_dac);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the raw value of temperature sensor.
|
||||
*
|
||||
* @return uint32_t raw_value
|
||||
*/
|
||||
static inline uint32_t temperature_sensor_ll_get_raw_value(void)
|
||||
{
|
||||
SENS.sar_tctrl.tsens_dump_out = 1;
|
||||
while (!SENS.sar_tctrl.tsens_ready) {
|
||||
}
|
||||
SENS.sar_tctrl.tsens_dump_out = 0;
|
||||
return SENS.sar_tctrl.tsens_out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the offset value of temperature sensor.
|
||||
*
|
||||
* @note This function is only used in legacy driver
|
||||
*
|
||||
* @return uint32_t offset value
|
||||
*/
|
||||
static inline uint32_t temperature_sensor_ll_get_offset(void)
|
||||
{
|
||||
return REGI2C_READ_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the clock division factor value.
|
||||
*
|
||||
* @note This function is only used in legacy driver
|
||||
*
|
||||
* @return uint32_t clock division factor
|
||||
*/
|
||||
static inline uint32_t temperature_sensor_ll_get_clk_div(void)
|
||||
{
|
||||
return SENS.sar_tctrl.tsens_clk_div;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the clock division factor value, actually this has no impact on temperature sensor.
|
||||
* Suggest just keep it as default value 6.
|
||||
*
|
||||
* @note This function is only used in legacy driver
|
||||
*
|
||||
* @param clk_div clock division factor, range from 1-10
|
||||
*/
|
||||
static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
|
||||
{
|
||||
SENS.sar_tctrl.tsens_clk_div = clk_div;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -83,14 +83,6 @@ config SOC_MPU_REGION_WO_SUPPORTED
|
||||
bool
|
||||
default n
|
||||
|
||||
config SOC_PCNT_PORT_NUM
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_PCNT_UNIT_NUM
|
||||
int
|
||||
default 4
|
||||
|
||||
config SOC_RTCIO_PIN_COUNT
|
||||
int
|
||||
default 22
|
||||
@ -243,6 +235,10 @@ config SOC_SIGMADELTA_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMP_SENSOR_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_APPCPU_HAS_CLOCK_GATING_BUG
|
||||
bool
|
||||
default y
|
||||
@ -863,6 +859,10 @@ config SOC_SDMMC_SUPPORT_XTAL_CLOCK
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TWAI_BRP_MIN
|
||||
int
|
||||
default 2
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -51,6 +51,7 @@ typedef enum {
|
||||
PERIPH_GDMA_MODULE,
|
||||
PERIPH_DEDIC_GPIO_MODULE,
|
||||
PERIPH_SARADC_MODULE,
|
||||
PERIPH_TEMPSENSOR_MODULE,
|
||||
PERIPH_MODULE_MAX
|
||||
} periph_module_t;
|
||||
|
||||
|
@ -59,6 +59,7 @@
|
||||
#define SOC_I2S_SUPPORTED 1
|
||||
#define SOC_RMT_SUPPORTED 1
|
||||
#define SOC_SIGMADELTA_SUPPORTED 1
|
||||
#define SOC_TEMP_SENSOR_SUPPORTED 1
|
||||
|
||||
/*-------------------------- SOC CAPS ----------------------------------------*/
|
||||
#define SOC_APPCPU_HAS_CLOCK_GATING_BUG (1)
|
||||
@ -369,3 +370,6 @@
|
||||
#define SOC_SDMMC_NUM_SLOTS 2
|
||||
/* Indicates that there is an option to use XTAL clock instead of PLL for SDMMC */
|
||||
#define SOC_SDMMC_SUPPORT_XTAL_CLOCK 1
|
||||
|
||||
/*-------------------------- Temperature Sensor CAPS -------------------------------------*/
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC (1)
|
||||
|
Loading…
Reference in New Issue
Block a user