kopia lustrzana https://github.com/espressif/esp-idf
temperature_sensor: Add temperature sensor support for ESP32-C2
rodzic
7d68098089
commit
3a820462ac
|
@ -11,12 +11,14 @@
|
||||||
#include "esp_types.h"
|
#include "esp_types.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "esp_private/regi2c_ctrl.h"
|
#include "esp_private/regi2c_ctrl.h"
|
||||||
#include "soc/regi2c_saradc.h"
|
#include "soc/regi2c_saradc.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_efuse_rtc_calib.h"
|
#include "esp_efuse_rtc_calib.h"
|
||||||
#include "hal/temperature_sensor_ll.h"
|
#include "hal/temperature_sensor_ll.h"
|
||||||
|
#include "hal/regi2c_ctrl_ll.h"
|
||||||
#include "driver/temp_sensor_types_legacy.h"
|
#include "driver/temp_sensor_types_legacy.h"
|
||||||
#include "esp_private/periph_ctrl.h"
|
#include "esp_private/periph_ctrl.h"
|
||||||
|
|
||||||
|
@ -26,6 +28,10 @@ static const char *TAG = "tsens";
|
||||||
#define TSENS_DAC_FACTOR (27.88)
|
#define TSENS_DAC_FACTOR (27.88)
|
||||||
#define TSENS_SYS_OFFSET (20.52)
|
#define TSENS_SYS_OFFSET (20.52)
|
||||||
|
|
||||||
|
extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished.
|
||||||
|
#define RTC_TEMP_SENSOR_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock)
|
||||||
|
#define RTC_TEMP_SENSOR_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int index;
|
int index;
|
||||||
int offset;
|
int offset;
|
||||||
|
@ -62,8 +68,11 @@ esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens)
|
||||||
err = ESP_ERR_INVALID_STATE;
|
err = ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
temperature_sensor_ll_set_clk_div(tsens.clk_div);
|
temperature_sensor_ll_set_clk_div(tsens.clk_div);
|
||||||
|
RTC_TEMP_SENSOR_ENTER_CRITICAL();
|
||||||
|
regi2c_ctrl_ll_i2c_saradc_enable();
|
||||||
temperature_sensor_ll_set_range(dac_offset[tsens.dac_offset].reg_val);
|
temperature_sensor_ll_set_range(dac_offset[tsens.dac_offset].reg_val);
|
||||||
temperature_sensor_ll_enable(true);
|
temperature_sensor_ll_enable(true);
|
||||||
|
RTC_TEMP_SENSOR_EXIT_CRITICAL();
|
||||||
ESP_LOGI(TAG, "Config range [%d°C ~ %d°C], error < %d°C",
|
ESP_LOGI(TAG, "Config range [%d°C ~ %d°C], error < %d°C",
|
||||||
dac_offset[tsens.dac_offset].range_min,
|
dac_offset[tsens.dac_offset].range_min,
|
||||||
dac_offset[tsens.dac_offset].range_max,
|
dac_offset[tsens.dac_offset].range_max,
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "esp_efuse_rtc_calib.h"
|
#include "esp_efuse_rtc_calib.h"
|
||||||
#include "esp_private/periph_ctrl.h"
|
#include "esp_private/periph_ctrl.h"
|
||||||
#include "hal/temperature_sensor_ll.h"
|
#include "hal/temperature_sensor_ll.h"
|
||||||
|
#include "hal/regi2c_ctrl_ll.h"
|
||||||
|
#include "soc/temperature_sensor_periph.h"
|
||||||
|
|
||||||
static const char *TAG = "temperature_sensor";
|
static const char *TAG = "temperature_sensor";
|
||||||
|
|
||||||
|
@ -42,33 +44,33 @@ static float s_deltaT = NAN; // unused number
|
||||||
typedef struct temperature_sensor_obj_t temperature_sensor_obj_t;
|
typedef struct temperature_sensor_obj_t temperature_sensor_obj_t;
|
||||||
|
|
||||||
struct temperature_sensor_obj_t {
|
struct temperature_sensor_obj_t {
|
||||||
const temp_sensor_ll_attribute_t *tsens_attribute;
|
const temperature_sensor_attribute_t *tsens_attribute;
|
||||||
temp_sensor_fsm_t fsm;
|
temp_sensor_fsm_t fsm;
|
||||||
temperature_sensor_clk_src_t clk_src;
|
temperature_sensor_clk_src_t clk_src;
|
||||||
};
|
};
|
||||||
|
|
||||||
static temp_sensor_ll_attribute_t *s_tsens_attribute_copy;
|
static temperature_sensor_attribute_t *s_tsens_attribute_copy;
|
||||||
|
|
||||||
static int inline accuracy_compare(const void *p1, const void *p2)
|
static int inline accuracy_compare(const void *p1, const void *p2)
|
||||||
{
|
{
|
||||||
return ((*(temp_sensor_ll_attribute_t *)p1).error_max < (*(temp_sensor_ll_attribute_t *)p2).error_max) ? -1 : 1;
|
return ((*(temperature_sensor_attribute_t *)p1).error_max < (*(temperature_sensor_attribute_t *)p2).error_max) ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t temperature_sensor_attribute_table_sort(void)
|
static esp_err_t temperature_sensor_attribute_table_sort(void)
|
||||||
{
|
{
|
||||||
s_tsens_attribute_copy = (temp_sensor_ll_attribute_t *)heap_caps_malloc(sizeof(temp_sensor_ll_attributes), MALLOC_CAP_DEFAULT);
|
s_tsens_attribute_copy = (temperature_sensor_attribute_t *)heap_caps_malloc(sizeof(temperature_sensor_attributes), MALLOC_CAP_DEFAULT);
|
||||||
ESP_RETURN_ON_FALSE(s_tsens_attribute_copy != NULL, ESP_ERR_NO_MEM, TAG, "No space for s_tsens_attribute_copy");
|
ESP_RETURN_ON_FALSE(s_tsens_attribute_copy != NULL, ESP_ERR_NO_MEM, TAG, "No space for s_tsens_attribute_copy");
|
||||||
for (int i = 0 ; i < TEMPERATURE_SENSOR_LL_RANGE_NUM; i++) {
|
for (int i = 0 ; i < TEMPERATURE_SENSOR_ATTR_RANGE_NUM; i++) {
|
||||||
s_tsens_attribute_copy[i] = temp_sensor_ll_attributes[i];
|
s_tsens_attribute_copy[i] = temperature_sensor_attributes[i];
|
||||||
}
|
}
|
||||||
// Sort from small to large by error_max.
|
// Sort from small to large by error_max.
|
||||||
qsort(s_tsens_attribute_copy, TEMPERATURE_SENSOR_LL_RANGE_NUM, sizeof(s_tsens_attribute_copy[0]), accuracy_compare);
|
qsort(s_tsens_attribute_copy, TEMPERATURE_SENSOR_ATTR_RANGE_NUM, sizeof(s_tsens_attribute_copy[0]), accuracy_compare);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t temperature_sensor_choose_best_range(temperature_sensor_handle_t tsens, const temperature_sensor_config_t *tsens_config)
|
static esp_err_t temperature_sensor_choose_best_range(temperature_sensor_handle_t tsens, const temperature_sensor_config_t *tsens_config)
|
||||||
{
|
{
|
||||||
for (int i = 0 ; i < TEMPERATURE_SENSOR_LL_RANGE_NUM; i++) {
|
for (int i = 0 ; i < TEMPERATURE_SENSOR_ATTR_RANGE_NUM; i++) {
|
||||||
if ((tsens_config->range_min >= s_tsens_attribute_copy[i].range_min) && (tsens_config->range_max <= s_tsens_attribute_copy[i].range_max)) {
|
if ((tsens_config->range_min >= s_tsens_attribute_copy[i].range_min) && (tsens_config->range_max <= s_tsens_attribute_copy[i].range_max)) {
|
||||||
tsens->tsens_attribute = &s_tsens_attribute_copy[i];
|
tsens->tsens_attribute = &s_tsens_attribute_copy[i];
|
||||||
break;
|
break;
|
||||||
|
@ -102,6 +104,7 @@ esp_err_t temperature_sensor_install(const temperature_sensor_config_t *tsens_co
|
||||||
tsens->tsens_attribute->error_max);
|
tsens->tsens_attribute->error_max);
|
||||||
|
|
||||||
TEMPERATURE_SENSOR_ENTER_CRITICAL();
|
TEMPERATURE_SENSOR_ENTER_CRITICAL();
|
||||||
|
regi2c_ctrl_ll_i2c_saradc_enable();
|
||||||
temperature_sensor_ll_set_range(tsens->tsens_attribute->reg_val);
|
temperature_sensor_ll_set_range(tsens->tsens_attribute->reg_val);
|
||||||
temperature_sensor_ll_enable(false); // disable the sensor by default
|
temperature_sensor_ll_enable(false); // disable the sensor by default
|
||||||
TEMPERATURE_SENSOR_EXIT_CRITICAL();
|
TEMPERATURE_SENSOR_EXIT_CRITICAL();
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
| Supported Targets | ESP32-S2 | ESP32-S3 | ESP32-C3 |
|
| Supported Targets | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 |
|
||||||
| ----------------- | -------- | -------- | -------- |
|
| ----------------- | -------- | -------- | -------- | -------- |
|
||||||
|
|
|
@ -8,6 +8,7 @@ from pytest_embedded import Dut
|
||||||
@pytest.mark.esp32s2
|
@pytest.mark.esp32s2
|
||||||
@pytest.mark.esp32c3
|
@pytest.mark.esp32c3
|
||||||
@pytest.mark.esp32s3
|
@pytest.mark.esp32s3
|
||||||
|
@pytest.mark.esp32c2
|
||||||
@pytest.mark.generic
|
@pytest.mark.generic
|
||||||
@pytest.mark.parametrize('config', [
|
@pytest.mark.parametrize('config', [
|
||||||
'release',
|
'release',
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
| Supported Targets | ESP32-S2 | ESP32-S3 | ESP32-C3 |
|
| Supported Targets | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 |
|
||||||
| ----------------- | -------- | -------- | -------- |
|
| ----------------- | -------- | -------- | -------- | -------- |
|
||||||
|
|
|
@ -8,6 +8,7 @@ from pytest_embedded import Dut
|
||||||
@pytest.mark.esp32s2
|
@pytest.mark.esp32s2
|
||||||
@pytest.mark.esp32c3
|
@pytest.mark.esp32c3
|
||||||
@pytest.mark.esp32s3
|
@pytest.mark.esp32s3
|
||||||
|
@pytest.mark.esp32c2
|
||||||
@pytest.mark.generic
|
@pytest.mark.generic
|
||||||
@pytest.mark.parametrize('config', [
|
@pytest.mark.parametrize('config', [
|
||||||
'release',
|
'release',
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <esp_bit_defs.h>
|
||||||
|
#include "esp_efuse.h"
|
||||||
|
#include "esp_efuse_table.h"
|
||||||
|
|
||||||
|
int esp_efuse_rtc_calib_get_ver(void)
|
||||||
|
{
|
||||||
|
uint32_t result = 0;
|
||||||
|
esp_efuse_read_field_blob(ESP_EFUSE_BLOCK2_VERSION, &result, 3);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal)
|
||||||
|
{
|
||||||
|
// Currently calibration is not supported on ESP32-C2, IDF-5236
|
||||||
|
*tsens_cal = 0.0;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <esp_types.h>
|
||||||
|
#include <esp_err.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the temperature sensor calibration number delta_T stored in the efuse.
|
||||||
|
*
|
||||||
|
* @param tsens_cal Pointer of 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.
|
||||||
|
*/
|
||||||
|
esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -1,3 +1,4 @@
|
||||||
set(EFUSE_SOC_SRCS "esp_efuse_table.c"
|
set(EFUSE_SOC_SRCS "esp_efuse_table.c"
|
||||||
"esp_efuse_fields.c"
|
"esp_efuse_fields.c"
|
||||||
|
"esp_efuse_rtc_calib.c"
|
||||||
"esp_efuse_utility.c")
|
"esp_efuse_utility.c")
|
||||||
|
|
|
@ -57,6 +57,8 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
|
||||||
return SYSTEM_BT_BASEBAND_EN;
|
return SYSTEM_BT_BASEBAND_EN;
|
||||||
case PERIPH_BT_LC_MODULE:
|
case PERIPH_BT_LC_MODULE:
|
||||||
return SYSTEM_BT_LC_EN;
|
return SYSTEM_BT_LC_EN;
|
||||||
|
case PERIPH_TEMPSENSOR_MODULE:
|
||||||
|
return SYSTEM_TSENS_CLK_EN;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -90,6 +92,8 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en
|
||||||
return SYSTEM_SPI01_RST;
|
return SYSTEM_SPI01_RST;
|
||||||
case PERIPH_SPI2_MODULE:
|
case PERIPH_SPI2_MODULE:
|
||||||
return SYSTEM_SPI2_RST;
|
return SYSTEM_SPI2_RST;
|
||||||
|
case PERIPH_TEMPSENSOR_MODULE:
|
||||||
|
return SYSTEM_TSENS_RST;
|
||||||
case PERIPH_SHA_MODULE:
|
case PERIPH_SHA_MODULE:
|
||||||
if (enable == true) {
|
if (enable == true) {
|
||||||
// Clear reset on digital signature and HMAC, otherwise SHA is held in reset
|
// Clear reset on digital signature and HMAC, otherwise SHA is held in reset
|
||||||
|
@ -119,6 +123,7 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
|
||||||
case PERIPH_SHA_MODULE:
|
case PERIPH_SHA_MODULE:
|
||||||
case PERIPH_GDMA_MODULE:
|
case PERIPH_GDMA_MODULE:
|
||||||
case PERIPH_ECC_MODULE:
|
case PERIPH_ECC_MODULE:
|
||||||
|
case PERIPH_TEMPSENSOR_MODULE:
|
||||||
return SYSTEM_PERIP_CLK_EN1_REG;
|
return SYSTEM_PERIP_CLK_EN1_REG;
|
||||||
default:
|
default:
|
||||||
return SYSTEM_PERIP_CLK_EN0_REG;
|
return SYSTEM_PERIP_CLK_EN0_REG;
|
||||||
|
@ -140,6 +145,7 @@ static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph)
|
||||||
case PERIPH_SHA_MODULE:
|
case PERIPH_SHA_MODULE:
|
||||||
case PERIPH_GDMA_MODULE:
|
case PERIPH_GDMA_MODULE:
|
||||||
case PERIPH_ECC_MODULE:
|
case PERIPH_ECC_MODULE:
|
||||||
|
case PERIPH_TEMPSENSOR_MODULE:
|
||||||
return SYSTEM_PERIP_RST_EN1_REG;
|
return SYSTEM_PERIP_RST_EN1_REG;
|
||||||
default:
|
default:
|
||||||
return SYSTEM_PERIP_RST_EN0_REG;
|
return SYSTEM_PERIP_RST_EN0_REG;
|
||||||
|
|
|
@ -39,6 +39,15 @@ static inline __attribute__((always_inline)) void regi2c_ctrl_ll_bbpll_calibrati
|
||||||
REG_SET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
|
REG_SET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable I2C_SAR
|
||||||
|
*/
|
||||||
|
static inline void regi2c_ctrl_ll_i2c_saradc_enable(void)
|
||||||
|
{
|
||||||
|
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
|
||||||
|
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include "esp_private/regi2c_ctrl.h"
|
||||||
|
#include "soc/regi2c_saradc.h"
|
||||||
|
#include "soc/apb_saradc_struct.h"
|
||||||
|
#include "soc/soc.h"
|
||||||
|
#include "soc/soc_caps.h"
|
||||||
|
#include "hal/temperature_sensor_types.h"
|
||||||
|
#include "hal/assert.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)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable the temperature sensor power.
|
||||||
|
*
|
||||||
|
* @param enable true: enable the power.
|
||||||
|
*/
|
||||||
|
static inline void temperature_sensor_ll_enable(bool enable)
|
||||||
|
{
|
||||||
|
APB_SARADC.saradc_apb_tsens_ctrl.saradc_reg_tsens_pu = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable the clock
|
||||||
|
*/
|
||||||
|
static inline void temperature_sensor_ll_clk_enable(bool enable)
|
||||||
|
{
|
||||||
|
// No need to enable the temperature clock on esp32c2
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Select the clock source for temperature sensor. On ESP32-C2, temperautre sensor
|
||||||
|
* can use XTAL or FOSC. To make it convenience, suggest using XTAL all the time.
|
||||||
|
*
|
||||||
|
* @param clk_src refer to ``temperature_sensor_clk_src_t``
|
||||||
|
*/
|
||||||
|
static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t clk_src)
|
||||||
|
{
|
||||||
|
uint8_t clk_sel = 0;
|
||||||
|
switch (clk_src) {
|
||||||
|
case TEMPERATURE_SENSOR_CLK_SRC_XTAL:
|
||||||
|
clk_sel = 1;
|
||||||
|
break;
|
||||||
|
case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST:
|
||||||
|
clk_sel = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
HAL_ASSERT(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
APB_SARADC.saradc_apb_tsens_ctrl2.saradc_tsens_clk_sel = clk_sel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes``
|
||||||
|
*
|
||||||
|
* @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes``
|
||||||
|
*/
|
||||||
|
static inline void temperature_sensor_ll_set_range(uint32_t range)
|
||||||
|
{
|
||||||
|
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the raw value of temperature sensor.
|
||||||
|
*
|
||||||
|
* @return uint32_t raw_value
|
||||||
|
*/
|
||||||
|
static inline uint32_t temperature_sensor_ll_get_raw_value(void)
|
||||||
|
{
|
||||||
|
return APB_SARADC.saradc_apb_tsens_ctrl.saradc_reg_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 APB_SARADC.saradc_apb_tsens_ctrl.saradc_reg_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)
|
||||||
|
{
|
||||||
|
APB_SARADC.saradc_apb_tsens_ctrl.saradc_reg_tsens_clk_div = clk_div;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -39,6 +39,15 @@ static inline __attribute__((always_inline)) void regi2c_ctrl_ll_bbpll_calibrati
|
||||||
REG_SET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
|
REG_SET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable I2C_SAR
|
||||||
|
*/
|
||||||
|
static inline void regi2c_ctrl_ll_i2c_saradc_enable(void)
|
||||||
|
{
|
||||||
|
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
|
||||||
|
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,25 +32,6 @@ extern "C" {
|
||||||
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
||||||
#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR (20.52)
|
#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.
|
* @brief Enable the temperature sensor power.
|
||||||
*
|
*
|
||||||
|
@ -93,14 +74,12 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the hardware range, you can refer to the table ``temp_sensor_ll_attributes``
|
* @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes``
|
||||||
*
|
*
|
||||||
* @param tsens_dac ``reg_val`` in table ``temp_sensor_ll_attributes``
|
* @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes``
|
||||||
*/
|
*/
|
||||||
static inline void temperature_sensor_ll_set_range(uint32_t range)
|
static inline void temperature_sensor_ll_set_range(uint32_t range)
|
||||||
{
|
{
|
||||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
|
|
||||||
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
|
|
||||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, range);
|
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,15 @@ static inline __attribute__((always_inline)) bool regi2c_ctrl_ll_bbpll_calibrati
|
||||||
return REG_GET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_CAL_DONE);
|
return REG_GET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_CAL_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable I2C_SAR
|
||||||
|
*/
|
||||||
|
static inline void regi2c_ctrl_ll_i2c_saradc_enable(void)
|
||||||
|
{
|
||||||
|
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
|
||||||
|
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,25 +32,6 @@ extern "C" {
|
||||||
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
||||||
#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR (20.52)
|
#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.
|
* @brief Enable the temperature sensor power.
|
||||||
*
|
*
|
||||||
|
@ -93,14 +74,12 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the hardware range, you can refer to the table ``temp_sensor_ll_attributes``
|
* @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes``
|
||||||
*
|
*
|
||||||
* @param tsens_dac ``reg_val`` in table ``temp_sensor_ll_attributes``
|
* @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes``
|
||||||
*/
|
*/
|
||||||
static inline void temperature_sensor_ll_set_range(uint32_t range)
|
static inline void temperature_sensor_ll_set_range(uint32_t range)
|
||||||
{
|
{
|
||||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
|
|
||||||
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
|
|
||||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, range);
|
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,17 @@ static inline void regi2c_ctrl_ll_i2c_apll_enable(void)
|
||||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_APLL_M);
|
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_APLL_M);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable I2C_SAR
|
||||||
|
*/
|
||||||
|
static inline void regi2c_ctrl_ll_i2c_saradc_enable(void)
|
||||||
|
{
|
||||||
|
CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M);
|
||||||
|
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M);
|
||||||
|
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_SAR_M);
|
||||||
|
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,25 +30,6 @@ extern "C" {
|
||||||
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
||||||
#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR (20.52)
|
#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.
|
* @brief Enable the temperature sensor power.
|
||||||
*
|
*
|
||||||
|
@ -79,16 +60,12 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the hardware range, you can refer to the table ``temp_sensor_ll_attributes``
|
* @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes``
|
||||||
*
|
*
|
||||||
* @param tsens_dac ``reg_val`` in table ``temp_sensor_ll_attributes``
|
* @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes``
|
||||||
*/
|
*/
|
||||||
static inline void temperature_sensor_ll_set_range(uint32_t tsens_dac)
|
static inline void temperature_sensor_ll_set_range(uint32_t tsens_dac)
|
||||||
{
|
{
|
||||||
CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M);
|
|
||||||
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M);
|
|
||||||
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);
|
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, tsens_dac);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ static inline void regi2c_ctrl_ll_i2c_bbpll_enable(void)
|
||||||
*/
|
*/
|
||||||
static inline void regi2c_ctrl_ll_i2c_saradc_enable(void)
|
static inline void regi2c_ctrl_ll_i2c_saradc_enable(void)
|
||||||
{
|
{
|
||||||
|
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_PU);
|
||||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_SAR_M);
|
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_SAR_M);
|
||||||
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
|
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,25 +30,6 @@ extern "C" {
|
||||||
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
|
||||||
#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR (20.52)
|
#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.
|
* @brief Enable the temperature sensor power.
|
||||||
*
|
*
|
||||||
|
@ -79,15 +60,12 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the hardware range, you can refer to the table ``temp_sensor_ll_attributes``
|
* @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes``
|
||||||
*
|
*
|
||||||
* @param tsens_dac ``reg_val`` in table ``temp_sensor_ll_attributes``
|
* @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes``
|
||||||
*/
|
*/
|
||||||
static inline void temperature_sensor_ll_set_range(uint32_t tsens_dac)
|
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);
|
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, tsens_dac);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ set(srcs
|
||||||
"ledc_periph.c"
|
"ledc_periph.c"
|
||||||
"i2c_periph.c"
|
"i2c_periph.c"
|
||||||
"uart_periph.c"
|
"uart_periph.c"
|
||||||
|
"temperature_sensor_periph.c"
|
||||||
"timer_periph.c")
|
"timer_periph.c")
|
||||||
|
|
||||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||||
|
|
|
@ -43,6 +43,10 @@ config SOC_EFUSE_CONSISTS_OF_ONE_KEY_BLOCK
|
||||||
bool
|
bool
|
||||||
default y
|
default y
|
||||||
|
|
||||||
|
config SOC_TEMP_SENSOR_SUPPORTED
|
||||||
|
bool
|
||||||
|
default y
|
||||||
|
|
||||||
config SOC_SHA_SUPPORTED
|
config SOC_SHA_SUPPORTED
|
||||||
bool
|
bool
|
||||||
default y
|
default y
|
||||||
|
|
|
@ -684,6 +684,7 @@ typedef struct {
|
||||||
volatile apb_saradc_apb_ctrl_date_reg_t saradc_apb_ctrl_date;
|
volatile apb_saradc_apb_ctrl_date_reg_t saradc_apb_ctrl_date;
|
||||||
} apb_dev_t;
|
} apb_dev_t;
|
||||||
|
|
||||||
|
extern apb_dev_t APB_SARADC;
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
_Static_assert(sizeof(apb_dev_t) == 0x400, "Invalid size of apb_dev_t structure");
|
_Static_assert(sizeof(apb_dev_t) == 0x400, "Invalid size of apb_dev_t structure");
|
||||||
|
|
|
@ -32,6 +32,7 @@ typedef enum {
|
||||||
PERIPH_GDMA_MODULE,
|
PERIPH_GDMA_MODULE,
|
||||||
PERIPH_SYSTIMER_MODULE,
|
PERIPH_SYSTIMER_MODULE,
|
||||||
PERIPH_SARADC_MODULE,
|
PERIPH_SARADC_MODULE,
|
||||||
|
PERIPH_TEMPSENSOR_MODULE,
|
||||||
PERIPH_MODEM_RPA_MODULE,
|
PERIPH_MODEM_RPA_MODULE,
|
||||||
PERIPH_MODULE_MAX
|
PERIPH_MODULE_MAX
|
||||||
} periph_module_t;
|
} periph_module_t;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#define SOC_SUPPORTS_SECURE_DL_MODE 1
|
#define SOC_SUPPORTS_SECURE_DL_MODE 1
|
||||||
#define SOC_EFUSE_KEY_PURPOSE_FIELD 0
|
#define SOC_EFUSE_KEY_PURPOSE_FIELD 0
|
||||||
#define SOC_EFUSE_CONSISTS_OF_ONE_KEY_BLOCK 1
|
#define SOC_EFUSE_CONSISTS_OF_ONE_KEY_BLOCK 1
|
||||||
|
#define SOC_TEMP_SENSOR_SUPPORTED 1
|
||||||
#define SOC_SHA_SUPPORTED 1
|
#define SOC_SHA_SUPPORTED 1
|
||||||
#define SOC_ECC_SUPPORTED 1
|
#define SOC_ECC_SUPPORTED 1
|
||||||
#define SOC_FLASH_ENC_SUPPORTED 1
|
#define SOC_FLASH_ENC_SUPPORTED 1
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "soc/temperature_sensor_periph.h"
|
||||||
|
|
||||||
|
const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_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},
|
||||||
|
};
|
|
@ -11,6 +11,7 @@ set(srcs
|
||||||
"i2s_periph.c"
|
"i2s_periph.c"
|
||||||
"i2c_periph.c"
|
"i2c_periph.c"
|
||||||
"uart_periph.c"
|
"uart_periph.c"
|
||||||
|
"temperature_sensor_periph.c"
|
||||||
"timer_periph.c")
|
"timer_periph.c")
|
||||||
|
|
||||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "soc/temperature_sensor_periph.h"
|
||||||
|
|
||||||
|
const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_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},
|
||||||
|
};
|
|
@ -11,6 +11,7 @@ set(srcs
|
||||||
"i2s_periph.c"
|
"i2s_periph.c"
|
||||||
"i2c_periph.c"
|
"i2c_periph.c"
|
||||||
"uart_periph.c"
|
"uart_periph.c"
|
||||||
|
"temperature_sensor_periph.c"
|
||||||
"timer_periph.c")
|
"timer_periph.c")
|
||||||
|
|
||||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "soc/temperature_sensor_periph.h"
|
||||||
|
|
||||||
|
const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_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},
|
||||||
|
};
|
|
@ -17,6 +17,7 @@ set(srcs
|
||||||
"touch_sensor_periph.c"
|
"touch_sensor_periph.c"
|
||||||
"uart_periph.c"
|
"uart_periph.c"
|
||||||
"usb_periph.c"
|
"usb_periph.c"
|
||||||
|
"temperature_sensor_periph.c"
|
||||||
"usb_phy_periph.c")
|
"usb_phy_periph.c")
|
||||||
|
|
||||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "soc/temperature_sensor_periph.h"
|
||||||
|
|
||||||
|
const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_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},
|
||||||
|
};
|
|
@ -18,6 +18,7 @@ set(srcs
|
||||||
"spi_periph.c"
|
"spi_periph.c"
|
||||||
"timer_periph.c"
|
"timer_periph.c"
|
||||||
"touch_sensor_periph.c"
|
"touch_sensor_periph.c"
|
||||||
|
"temperature_sensor_periph.c"
|
||||||
"uart_periph.c"
|
"uart_periph.c"
|
||||||
"usb_periph.c"
|
"usb_periph.c"
|
||||||
"usb_phy_periph.c")
|
"usb_phy_periph.c")
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "soc/temperature_sensor_periph.h"
|
||||||
|
|
||||||
|
const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_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},
|
||||||
|
};
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TEMPERATURE_SENSOR_ATTR_RANGE_NUM (5)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int offset;
|
||||||
|
int reg_val;
|
||||||
|
int range_min;
|
||||||
|
int range_max;
|
||||||
|
int error_max;
|
||||||
|
} temperature_sensor_attribute_t;
|
||||||
|
|
||||||
|
extern const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM];
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -86,7 +86,6 @@ api-reference/storage/index
|
||||||
api-reference/peripherals/adc
|
api-reference/peripherals/adc
|
||||||
api-reference/peripherals/sdspi_host
|
api-reference/peripherals/sdspi_host
|
||||||
api-reference/peripherals/lcd
|
api-reference/peripherals/lcd
|
||||||
api-reference/peripherals/temp_sensor
|
|
||||||
api-reference/kconfig
|
api-reference/kconfig
|
||||||
api-reference/network/esp_openthread
|
api-reference/network/esp_openthread
|
||||||
api-reference/network/esp_eth
|
api-reference/network/esp_eth
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
| Supported Targets | ESP32-S2 | ESP32-C3 | ESP32-S3 |
|
| Supported Targets | ESP32-S2 | ESP32-C3 | ESP32-S3 | ESP32-C2 |
|
||||||
| ----------------- | -------- | -------- | -------- |
|
| ----------------- | -------- | -------- | -------- | -------- |
|
||||||
|
|
||||||
# Temperature Sensor Example
|
# Temperature Sensor Example
|
||||||
|
|
||||||
The ESP32-S2/C3/S3 has a built-in temperature sensor. The temperature sensor module contains an 8-bit Sigma-Delta ADC and a temperature offset DAC.
|
The ESP32-S2/C3/S3/C2 has a built-in temperature sensor. The temperature sensor module contains an 8-bit Sigma-Delta ADC and a temperature offset DAC.
|
||||||
|
|
||||||
The conversion relationship is the first two columns of the table below. Among them, `offset = 0`(default) is the main measurement option, and other values are extended measurement options.
|
The conversion relationship is the first two columns of the table below. Among them, `offset = 0`(default) is the main measurement option, and other values are extended measurement options.
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ Before project configuration and build, be sure to set the correct chip target u
|
||||||
|
|
||||||
### Hardware Required
|
### Hardware Required
|
||||||
|
|
||||||
* A development board with ESP32-S2/C3/S3 SoC (e.g., ESP32-S2-Saola-1, ESP32-S2-DevKitM-1, ESP32-C3-DevKitM-1, ESP32-S3-WROOM-1, etc.)
|
* A development board with ESP32-S2/C3/S3/C2 SoC (e.g., ESP32-S2-Saola-1, ESP32-S2-DevKitM-1, ESP32-C3-DevKitM-1, ESP32-S3-WROOM-1, etc.)
|
||||||
* A USB cable for power supply and programming
|
* A USB cable for power supply and programming
|
||||||
|
|
||||||
### Build and Flash
|
### Build and Flash
|
||||||
|
|
|
@ -8,6 +8,7 @@ from pytest_embedded.dut import Dut
|
||||||
@pytest.mark.esp32s2
|
@pytest.mark.esp32s2
|
||||||
@pytest.mark.esp32c3
|
@pytest.mark.esp32c3
|
||||||
@pytest.mark.esp32s3
|
@pytest.mark.esp32s3
|
||||||
|
@pytest.mark.esp32c2
|
||||||
@pytest.mark.generic
|
@pytest.mark.generic
|
||||||
def test_temp_sensor_example(dut: Dut) -> None:
|
def test_temp_sensor_example(dut: Dut) -> None:
|
||||||
dut.expect_exact('Install temperature sensor')
|
dut.expect_exact('Install temperature sensor')
|
||||||
|
|
Ładowanie…
Reference in New Issue