Skip to content

Commit 068c8ab

Browse files
committed
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
2 parents 5609859 + 023981b commit 068c8ab

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

components/esp_driver_tsens/include/driver/temperature_sensor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ typedef struct {
4646
.range_min = min, \
4747
.range_max = max, \
4848
.clk_src = TEMPERATURE_SENSOR_CLK_SRC_DEFAULT, \
49+
.flags = { \
50+
.allow_pd = 0, \
51+
}, \
4952
}
5053

5154
/**

components/esp_driver_tsens/test_apps/temperature_sensor/main/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
set(srcs "test_app_main.c"
2-
"test_temperature_sensor.c"
3-
"test_temperature_phy.c")
2+
"test_temperature_sensor.cpp"
3+
"test_temperature_phy.cpp")
44

55
if(CONFIG_SOC_TEMPERATURE_SENSOR_SUPPORT_ETM)
6-
list(APPEND srcs "test_temperature_etm.c")
6+
list(APPEND srcs "test_temperature_etm.cpp")
77
endif()
88

99
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,

components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_etm.c renamed to components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_etm.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -21,7 +21,7 @@
2121
// from 0 to 1 on logic analyzer or oscilloscope.
2222
TEST_CASE("temperature sensor alarm cause gpio pull up", "[etm]")
2323
{
24-
const uint32_t output_gpio = 5;
24+
const gpio_num_t output_gpio = GPIO_NUM_5;
2525
// temperature sensor alarm ---> ETM channel A ---> GPIO level to high
2626
printf("allocate etm channel\r\n");
2727
esp_etm_channel_config_t etm_config = {};
@@ -30,19 +30,23 @@ TEST_CASE("temperature sensor alarm cause gpio pull up", "[etm]")
3030

3131
printf("allocate GPIO etm task\r\n");
3232
esp_etm_task_handle_t gpio_task = NULL;
33-
gpio_etm_task_config_t gpio_task_config = {
34-
.action = GPIO_ETM_TASK_ACTION_SET,
35-
};
33+
gpio_etm_task_config_t gpio_task_config = {};
34+
gpio_task_config.actions[0] = GPIO_ETM_TASK_ACTION_SET;
3635
TEST_ESP_OK(gpio_new_etm_task(&gpio_task_config, &gpio_task));
3736
// set gpio number for the gpio etm primitives
3837
TEST_ESP_OK(gpio_etm_task_add_gpio(gpio_task, output_gpio));
3938

4039
printf("initialize gpio\r\n");
4140
gpio_set_level(output_gpio, 0);
4241
gpio_config_t task_gpio_config = {
43-
.intr_type = GPIO_INTR_DISABLE,
44-
.mode = GPIO_MODE_OUTPUT,
4542
.pin_bit_mask = 1ULL << output_gpio,
43+
.mode = GPIO_MODE_OUTPUT,
44+
.pull_up_en = GPIO_PULLUP_DISABLE,
45+
.pull_down_en = GPIO_PULLDOWN_DISABLE,
46+
.intr_type = GPIO_INTR_DISABLE,
47+
#if SOC_GPIO_SUPPORT_PIN_HYS_FILTER
48+
.hys_ctrl_mode = GPIO_HYS_SOFT_DISABLE,
49+
#endif
4650
};
4751
TEST_ESP_OK(gpio_config(&task_gpio_config));
4852

components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_phy.c renamed to components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_phy.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@ struct temperature_sensor_obj_t {
4141
static void start_wifi_as_softap(void)
4242
{
4343
uint8_t ssid_len = strlen(TEST_DEFAULT_SSID);
44-
wifi_config_t w_config = {
45-
.ap.ssid = TEST_DEFAULT_SSID,
46-
.ap.password = TEST_DEFAULT_PWD,
47-
.ap.ssid_len = ssid_len,
48-
.ap.channel = TEST_DEFAULT_CHANNEL,
49-
.ap.authmode = WIFI_AUTH_WPA2_PSK,
50-
.ap.ssid_hidden = false,
51-
.ap.max_connection = 4,
52-
.ap.beacon_interval = 100,
53-
};
44+
wifi_config_t w_config = {}; // Zero-initialize the structure
45+
46+
// Assign members
47+
strncpy((char *)w_config.ap.ssid, TEST_DEFAULT_SSID, sizeof(w_config.ap.ssid) - 1);
48+
w_config.ap.ssid[sizeof(w_config.ap.ssid) - 1] = 0; // Ensure null termination
49+
strncpy((char *)w_config.ap.password, TEST_DEFAULT_PWD, sizeof(w_config.ap.password) - 1);
50+
w_config.ap.password[sizeof(w_config.ap.password) - 1] = 0; // Ensure null termination
51+
52+
w_config.ap.ssid_len = ssid_len;
53+
w_config.ap.channel = TEST_DEFAULT_CHANNEL;
54+
w_config.ap.authmode = WIFI_AUTH_WPA2_PSK;
55+
w_config.ap.ssid_hidden = false;
56+
w_config.ap.max_connection = 4;
57+
w_config.ap.beacon_interval = 100;
5458

5559
TEST_ESP_OK(esp_wifi_set_mode(WIFI_MODE_AP));
5660
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_AP, &w_config));
@@ -72,10 +76,13 @@ static void stop_wifi(void)
7276

7377
static void wifi_connect(void)
7478
{
75-
wifi_config_t w_config = {
76-
.sta.ssid = TEST_DEFAULT_SSID,
77-
.sta.password = TEST_DEFAULT_PWD,
78-
};
79+
wifi_config_t w_config = {}; // Zero-initialize the structure
80+
81+
// Assign members
82+
strncpy((char *)w_config.sta.ssid, TEST_DEFAULT_SSID, sizeof(w_config.sta.ssid) - 1);
83+
w_config.sta.ssid[sizeof(w_config.sta.ssid) - 1] = 0; // Ensure null termination
84+
strncpy((char *)w_config.sta.password, TEST_DEFAULT_PWD, sizeof(w_config.sta.password) - 1);
85+
w_config.sta.password[sizeof(w_config.sta.password) - 1] = 0; // Ensure null termination
7986

8087
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_STA, &w_config));
8188
TEST_ESP_OK(esp_wifi_connect());

components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_sensor.c renamed to components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_sensor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ static void test_temperature_sensor_sleep_retention(bool allow_pd)
162162
.range_min = 10,
163163
.range_max = 50,
164164
.clk_src = TEMPERATURE_SENSOR_CLK_SRC_DEFAULT,
165-
.flags.allow_pd = allow_pd,
165+
.flags = {
166+
.allow_pd = allow_pd,
167+
},
166168
};
167169
temperature_sensor_handle_t temp_handle = NULL;
168170
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));

0 commit comments

Comments
 (0)