Skip to content

Commit 01dc3cb

Browse files
committed
example: Add user active mode trigger button for icd example
Closes CON-1486
1 parent 4d82fb7 commit 01dc3cb

10 files changed

+85
-14
lines changed

examples/icd_app/CMakeLists.txt

+1-14
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ if(NOT DEFINED ENV{ESP_MATTER_PATH})
66
message(FATAL_ERROR "Please set ESP_MATTER_PATH to the path of esp-matter repo")
77
endif(NOT DEFINED ENV{ESP_MATTER_PATH})
88

9-
if(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH})
10-
if("${IDF_TARGET}" STREQUAL "esp32h2")
11-
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32h2_devkit_c)
12-
elseif("${IDF_TARGET}" STREQUAL "esp32c6")
13-
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c6_devkit_c)
14-
else()
15-
message(FATAL_ERROR "Unsupported IDF_TARGET")
16-
endif()
17-
endif(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH})
18-
199
set(PROJECT_VER "1.0")
2010
set(PROJECT_VER_NUMBER 1)
2111

@@ -24,14 +14,11 @@ set(MATTER_SDK_PATH ${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip)
2414

2515
# This should be done before using the IDF_TARGET variable.
2616
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
27-
include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake)
2817

2918
set(EXTRA_COMPONENT_DIRS
3019
"${ESP_MATTER_PATH}/examples/common"
3120
"${MATTER_SDK_PATH}/config/esp32/components"
32-
"${ESP_MATTER_PATH}/components"
33-
"${ESP_MATTER_PATH}/device_hal/device"
34-
${extra_components_dirs_append})
21+
"${ESP_MATTER_PATH}/components")
3522

3623
project(icd_app)
3724

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
menu "Example Configuration"
2+
config ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
3+
bool "Enable User Active Mode Trigger Button"
4+
default y
5+
help
6+
Enable a button to trigger user active mode, after click this button, the device will keep staying
7+
active for ActiveModeDuration.
8+
9+
config USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN
10+
int "User Active Mode Trigger Button Pin"
11+
range 9 14 if IDF_TARGET_ESP32H2
12+
range 0 7 if IDF_TARGET_ESP32C6
13+
default 9 if IDF_TARGET_ESP32H2
14+
default 7 if IDF_TARGET_ESP32C6
15+
help
16+
GPIO number of the active mode trigger button. Note that the boot button of ESP32-C6 DevKits is
17+
GPIO9 which cannot be used to wake up the chip.
18+
19+
endmenu

examples/icd_app/main/app_driver.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <esp_log.h>
8+
#include <esp_matter.h>
9+
#include <iot_button.h>
10+
#include <sdkconfig.h>
11+
12+
#include <app/icd/server/ICDNotifier.h>
13+
14+
#include <app_priv.h>
15+
16+
#ifdef CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
17+
using namespace chip::app::Clusters;
18+
using namespace esp_matter;
19+
20+
static constexpr char *TAG = "app_driver";
21+
22+
static void app_driver_button_toggle_cb(void *arg, void *data)
23+
{
24+
// The device will stay active mode for Active Mode Threshold
25+
chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) {
26+
chip::app::ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
27+
});
28+
}
29+
30+
app_driver_handle_t app_driver_button_init()
31+
{
32+
/* Initialize button */
33+
button_config_t config;
34+
memset(&config, 0, sizeof(button_config_t));
35+
config.type = BUTTON_TYPE_GPIO;
36+
config.gpio_button_config.gpio_num = CONFIG_USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN;
37+
config.gpio_button_config.active_level = 0;
38+
config.gpio_button_config.enable_power_save = true;
39+
button_handle_t handle = iot_button_create(&config);
40+
41+
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
42+
return (app_driver_handle_t)handle;
43+
}
44+
45+
#endif // CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON

examples/icd_app/main/app_main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ extern "C" void app_main()
139139
#endif
140140
};
141141
err = esp_pm_configure(&pm_config);
142+
#endif
143+
#ifdef CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
144+
app_driver_button_init();
142145
#endif
143146
/* Create a Matter node and add the mandatory Root Node device type on endpoint 0 */
144147
node::config_t node_config;

examples/icd_app/main/app_priv.h

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include <esp_err.h>
1212
#include <esp_matter.h>
1313

14+
typedef void *app_driver_handle_t;
15+
16+
app_driver_handle_t app_driver_button_init();
17+
1418
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
1519
#include "esp_openthread_types.h"
1620
#endif
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies:
2+
espressif/button:
3+
version: "^3.4.0"

examples/icd_app/sdkconfig.defaults

+3
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ CONFIG_ICD_FAST_POLL_INTERVAL_MS=500
8484
CONFIG_ICD_IDLE_MODE_INTERVAL_SEC=60
8585
CONFIG_ICD_ACTIVE_MODE_INTERVAL_MS=1000
8686
CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS=1000
87+
88+
# Enable power save for the button
89+
CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE=y
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
CONFIG_IDF_TARGET="esp32c6"
22

33
CONFIG_ESP_PHY_MAC_BB_PD=y
4+

examples/icd_app/sdkconfig.defaults.esp32c6.lit

+3
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS=5000
6464
CONFIG_ENABLE_ICD_LIT=y
6565
CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC=2
6666
CONFIG_ICD_MAX_NOTIFICATION_SUBSCRIBERS=2
67+
68+
# Enable power save for the button
69+
CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE=y

examples/icd_app/sdkconfig.defaults.esp32h2.lit

+3
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ CONFIG_ICD_MAX_NOTIFICATION_SUBSCRIBERS=2
6363

6464
# Disable WiFi STA
6565
CONFIG_ENABLE_WIFI_STATION=n
66+
67+
# Enable power save for the button
68+
CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE=y

0 commit comments

Comments
 (0)