Merge branch 'refactor/temperature_cpp' into 'master'

refactor(temperature_sensor): Make temperature sensor adapt to cpp

Closes IDFGH-16532 and IDF-14190

See merge request espressif/esp-idf!42247
This commit is contained in:
C.S.M
2025-10-09 15:24:52 +08:00
5 changed files with 41 additions and 25 deletions

View File

@@ -46,6 +46,9 @@ typedef struct {
.range_min = min, \
.range_max = max, \
.clk_src = TEMPERATURE_SENSOR_CLK_SRC_DEFAULT, \
.flags = { \
.allow_pd = 0, \
}, \
}
/**

View File

@@ -1,9 +1,9 @@
set(srcs "test_app_main.c"
"test_temperature_sensor.c"
"test_temperature_phy.c")
"test_temperature_sensor.cpp"
"test_temperature_phy.cpp")
if(CONFIG_SOC_TEMPERATURE_SENSOR_SUPPORT_ETM)
list(APPEND srcs "test_temperature_etm.c")
list(APPEND srcs "test_temperature_etm.cpp")
endif()
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -21,7 +21,7 @@
// from 0 to 1 on logic analyzer or oscilloscope.
TEST_CASE("temperature sensor alarm cause gpio pull up", "[etm]")
{
const uint32_t output_gpio = 5;
const gpio_num_t output_gpio = GPIO_NUM_5;
// temperature sensor alarm ---> ETM channel A ---> GPIO level to high
printf("allocate etm channel\r\n");
esp_etm_channel_config_t etm_config = {};
@@ -30,9 +30,8 @@ TEST_CASE("temperature sensor alarm cause gpio pull up", "[etm]")
printf("allocate GPIO etm task\r\n");
esp_etm_task_handle_t gpio_task = NULL;
gpio_etm_task_config_t gpio_task_config = {
.action = GPIO_ETM_TASK_ACTION_SET,
};
gpio_etm_task_config_t gpio_task_config = {};
gpio_task_config.actions[0] = GPIO_ETM_TASK_ACTION_SET;
TEST_ESP_OK(gpio_new_etm_task(&gpio_task_config, &gpio_task));
// set gpio number for the gpio etm primitives
TEST_ESP_OK(gpio_etm_task_add_gpio(gpio_task, output_gpio));
@@ -40,9 +39,14 @@ TEST_CASE("temperature sensor alarm cause gpio pull up", "[etm]")
printf("initialize gpio\r\n");
gpio_set_level(output_gpio, 0);
gpio_config_t task_gpio_config = {
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1ULL << output_gpio,
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
#if SOC_GPIO_SUPPORT_PIN_HYS_FILTER
.hys_ctrl_mode = GPIO_HYS_SOFT_DISABLE,
#endif
};
TEST_ESP_OK(gpio_config(&task_gpio_config));

View File

@@ -41,16 +41,20 @@ struct temperature_sensor_obj_t {
static void start_wifi_as_softap(void)
{
uint8_t ssid_len = strlen(TEST_DEFAULT_SSID);
wifi_config_t w_config = {
.ap.ssid = TEST_DEFAULT_SSID,
.ap.password = TEST_DEFAULT_PWD,
.ap.ssid_len = ssid_len,
.ap.channel = TEST_DEFAULT_CHANNEL,
.ap.authmode = WIFI_AUTH_WPA2_PSK,
.ap.ssid_hidden = false,
.ap.max_connection = 4,
.ap.beacon_interval = 100,
};
wifi_config_t w_config = {}; // Zero-initialize the structure
// Assign members
strncpy((char *)w_config.ap.ssid, TEST_DEFAULT_SSID, sizeof(w_config.ap.ssid) - 1);
w_config.ap.ssid[sizeof(w_config.ap.ssid) - 1] = 0; // Ensure null termination
strncpy((char *)w_config.ap.password, TEST_DEFAULT_PWD, sizeof(w_config.ap.password) - 1);
w_config.ap.password[sizeof(w_config.ap.password) - 1] = 0; // Ensure null termination
w_config.ap.ssid_len = ssid_len;
w_config.ap.channel = TEST_DEFAULT_CHANNEL;
w_config.ap.authmode = WIFI_AUTH_WPA2_PSK;
w_config.ap.ssid_hidden = false;
w_config.ap.max_connection = 4;
w_config.ap.beacon_interval = 100;
TEST_ESP_OK(esp_wifi_set_mode(WIFI_MODE_AP));
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_AP, &w_config));
@@ -72,10 +76,13 @@ static void stop_wifi(void)
static void wifi_connect(void)
{
wifi_config_t w_config = {
.sta.ssid = TEST_DEFAULT_SSID,
.sta.password = TEST_DEFAULT_PWD,
};
wifi_config_t w_config = {}; // Zero-initialize the structure
// Assign members
strncpy((char *)w_config.sta.ssid, TEST_DEFAULT_SSID, sizeof(w_config.sta.ssid) - 1);
w_config.sta.ssid[sizeof(w_config.sta.ssid) - 1] = 0; // Ensure null termination
strncpy((char *)w_config.sta.password, TEST_DEFAULT_PWD, sizeof(w_config.sta.password) - 1);
w_config.sta.password[sizeof(w_config.sta.password) - 1] = 0; // Ensure null termination
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_STA, &w_config));
TEST_ESP_OK(esp_wifi_connect());

View File

@@ -162,7 +162,9 @@ static void test_temperature_sensor_sleep_retention(bool allow_pd)
.range_min = 10,
.range_max = 50,
.clk_src = TEMPERATURE_SENSOR_CLK_SRC_DEFAULT,
.flags.allow_pd = allow_pd,
.flags = {
.allow_pd = allow_pd,
},
};
temperature_sensor_handle_t temp_handle = NULL;
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));