Skip to content

Commit

Permalink
Merge branch 'icd_example/add_uat_button' into 'main'
Browse files Browse the repository at this point in the history
example: Add user active mode trigger button for icd example

Closes CON-1486

See merge request app-frameworks/esp-matter!991
  • Loading branch information
chshu committed Dec 27, 2024
2 parents bdc7f55 + 01dc3cb commit d27bc46
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 14 deletions.
15 changes: 1 addition & 14 deletions examples/icd_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ if(NOT DEFINED ENV{ESP_MATTER_PATH})
message(FATAL_ERROR "Please set ESP_MATTER_PATH to the path of esp-matter repo")
endif(NOT DEFINED ENV{ESP_MATTER_PATH})

if(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH})
if("${IDF_TARGET}" STREQUAL "esp32h2")
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32h2_devkit_c)
elseif("${IDF_TARGET}" STREQUAL "esp32c6")
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c6_devkit_c)
else()
message(FATAL_ERROR "Unsupported IDF_TARGET")
endif()
endif(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH})

set(PROJECT_VER "1.0")
set(PROJECT_VER_NUMBER 1)

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

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

set(EXTRA_COMPONENT_DIRS
"${ESP_MATTER_PATH}/examples/common"
"${MATTER_SDK_PATH}/config/esp32/components"
"${ESP_MATTER_PATH}/components"
"${ESP_MATTER_PATH}/device_hal/device"
${extra_components_dirs_append})
"${ESP_MATTER_PATH}/components")

project(icd_app)

Expand Down
19 changes: 19 additions & 0 deletions examples/icd_app/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
menu "Example Configuration"
config ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
bool "Enable User Active Mode Trigger Button"
default y
help
Enable a button to trigger user active mode, after click this button, the device will keep staying
active for ActiveModeDuration.

config USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN
int "User Active Mode Trigger Button Pin"
range 9 14 if IDF_TARGET_ESP32H2
range 0 7 if IDF_TARGET_ESP32C6
default 9 if IDF_TARGET_ESP32H2
default 7 if IDF_TARGET_ESP32C6
help
GPIO number of the active mode trigger button. Note that the boot button of ESP32-C6 DevKits is
GPIO9 which cannot be used to wake up the chip.

endmenu
45 changes: 45 additions & 0 deletions examples/icd_app/main/app_driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <esp_log.h>
#include <esp_matter.h>
#include <iot_button.h>
#include <sdkconfig.h>

#include <app/icd/server/ICDNotifier.h>

#include <app_priv.h>

#ifdef CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
using namespace chip::app::Clusters;
using namespace esp_matter;

static constexpr char *TAG = "app_driver";

static void app_driver_button_toggle_cb(void *arg, void *data)
{
// The device will stay active mode for Active Mode Threshold
chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) {
chip::app::ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
});
}

app_driver_handle_t app_driver_button_init()
{
/* Initialize button */
button_config_t config;
memset(&config, 0, sizeof(button_config_t));
config.type = BUTTON_TYPE_GPIO;
config.gpio_button_config.gpio_num = CONFIG_USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN;
config.gpio_button_config.active_level = 0;
config.gpio_button_config.enable_power_save = true;
button_handle_t handle = iot_button_create(&config);

iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
return (app_driver_handle_t)handle;
}

#endif // CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
3 changes: 3 additions & 0 deletions examples/icd_app/main/app_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ extern "C" void app_main()
#endif
};
err = esp_pm_configure(&pm_config);
#endif
#ifdef CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
app_driver_button_init();
#endif
/* Create a Matter node and add the mandatory Root Node device type on endpoint 0 */
node::config_t node_config;
Expand Down
4 changes: 4 additions & 0 deletions examples/icd_app/main/app_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <esp_err.h>
#include <esp_matter.h>

typedef void *app_driver_handle_t;

app_driver_handle_t app_driver_button_init();

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include "esp_openthread_types.h"
#endif
Expand Down
3 changes: 3 additions & 0 deletions examples/icd_app/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
espressif/button:
version: "^3.4.0"
3 changes: 3 additions & 0 deletions examples/icd_app/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ CONFIG_ICD_FAST_POLL_INTERVAL_MS=500
CONFIG_ICD_IDLE_MODE_INTERVAL_SEC=60
CONFIG_ICD_ACTIVE_MODE_INTERVAL_MS=1000
CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS=1000

# Enable power save for the button
CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE=y
1 change: 1 addition & 0 deletions examples/icd_app/sdkconfig.defaults.esp32c6
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_IDF_TARGET="esp32c6"

CONFIG_ESP_PHY_MAC_BB_PD=y

3 changes: 3 additions & 0 deletions examples/icd_app/sdkconfig.defaults.esp32c6.lit
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS=5000
CONFIG_ENABLE_ICD_LIT=y
CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC=2
CONFIG_ICD_MAX_NOTIFICATION_SUBSCRIBERS=2

# Enable power save for the button
CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE=y
3 changes: 3 additions & 0 deletions examples/icd_app/sdkconfig.defaults.esp32h2.lit
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ CONFIG_ICD_MAX_NOTIFICATION_SUBSCRIBERS=2

# Disable WiFi STA
CONFIG_ENABLE_WIFI_STATION=n

# Enable power save for the button
CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE=y

0 comments on commit d27bc46

Please sign in to comment.