mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
temperature_sensor: Add temperature sensor support for ESP32-C2
This commit is contained in:
@@ -57,6 +57,8 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
|
||||
return SYSTEM_BT_BASEBAND_EN;
|
||||
case PERIPH_BT_LC_MODULE:
|
||||
return SYSTEM_BT_LC_EN;
|
||||
case PERIPH_TEMPSENSOR_MODULE:
|
||||
return SYSTEM_TSENS_CLK_EN;
|
||||
default:
|
||||
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;
|
||||
case PERIPH_SPI2_MODULE:
|
||||
return SYSTEM_SPI2_RST;
|
||||
case PERIPH_TEMPSENSOR_MODULE:
|
||||
return SYSTEM_TSENS_RST;
|
||||
case PERIPH_SHA_MODULE:
|
||||
if (enable == true) {
|
||||
// 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_GDMA_MODULE:
|
||||
case PERIPH_ECC_MODULE:
|
||||
case PERIPH_TEMPSENSOR_MODULE:
|
||||
return SYSTEM_PERIP_CLK_EN1_REG;
|
||||
default:
|
||||
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_GDMA_MODULE:
|
||||
case PERIPH_ECC_MODULE:
|
||||
case PERIPH_TEMPSENSOR_MODULE:
|
||||
return SYSTEM_PERIP_RST_EN1_REG;
|
||||
default:
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
}
|
||||
#endif
|
||||
|
135
components/hal/esp32c2/include/hal/temperature_sensor_ll.h
Normal file
135
components/hal/esp32c2/include/hal/temperature_sensor_ll.h
Normal file
@@ -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
|
Reference in New Issue
Block a user