mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
example: Add user active mode trigger button for icd example
Closes CON-1486
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
dependencies:
|
||||
espressif/button:
|
||||
version: "^3.4.0"
|
||||
@@ -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,3 +1,4 @@
|
||||
CONFIG_IDF_TARGET="esp32c6"
|
||||
|
||||
CONFIG_ESP_PHY_MAC_BB_PD=y
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user