From 1e24417db0a25ae4adaa233c65b93e80ff6cfdd2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 12 Jun 2025 18:09:39 -0500 Subject: [PATCH] help with setup --- esphome/components/esp32_touch/esp32_touch.h | 1 + .../esp32_touch/esp32_touch_common.cpp | 24 +++++++++++++++++++ .../components/esp32_touch/esp32_touch_v1.cpp | 20 ++-------------- .../components/esp32_touch/esp32_touch_v2.cpp | 17 ++----------- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/esphome/components/esp32_touch/esp32_touch.h b/esphome/components/esp32_touch/esp32_touch.h index 20db00fe15..a092b414ac 100644 --- a/esphome/components/esp32_touch/esp32_touch.h +++ b/esphome/components/esp32_touch/esp32_touch.h @@ -70,6 +70,7 @@ class ESP32TouchComponent : public Component { void dump_config_sensors_(); bool create_touch_queue(); void cleanup_touch_queue(); + void configure_wakeup_pads(); // Common members std::vector children_; diff --git a/esphome/components/esp32_touch/esp32_touch_common.cpp b/esphome/components/esp32_touch/esp32_touch_common.cpp index 7ca0b4155d..7e9de689de 100644 --- a/esphome/components/esp32_touch/esp32_touch_common.cpp +++ b/esphome/components/esp32_touch/esp32_touch_common.cpp @@ -61,6 +61,30 @@ void ESP32TouchComponent::cleanup_touch_queue() { } } +void ESP32TouchComponent::configure_wakeup_pads() { + bool is_wakeup_source = false; + + // Check if any pad is configured for wakeup + for (auto *child : this->children_) { + if (child->get_wakeup_threshold() != 0) { + is_wakeup_source = true; + +#ifdef USE_ESP32_VARIANT_ESP32 + // ESP32 v1: No filter available when using as wake-up source. + touch_pad_config(child->get_touch_pad(), child->get_wakeup_threshold()); +#else + // ESP32-S2/S3 v2: Set threshold for wakeup + touch_pad_set_thresh(child->get_touch_pad(), child->get_wakeup_threshold()); +#endif + } + } + + if (!is_wakeup_source) { + // If no pad is configured for wakeup, deinitialize touch pad + touch_pad_deinit(); + } +} + } // namespace esp32_touch } // namespace esphome diff --git a/esphome/components/esp32_touch/esp32_touch_v1.cpp b/esphome/components/esp32_touch/esp32_touch_v1.cpp index d28233d9c6..8feccf3604 100644 --- a/esphome/components/esp32_touch/esp32_touch_v1.cpp +++ b/esphome/components/esp32_touch/esp32_touch_v1.cpp @@ -181,29 +181,13 @@ void ESP32TouchComponent::on_shutdown() { touch_pad_isr_deregister(touch_isr_handler, this); this->cleanup_touch_queue(); - bool is_wakeup_source = false; - if (this->iir_filter_enabled_()) { touch_pad_filter_stop(); touch_pad_filter_delete(); } - for (auto *child : this->children_) { - if (child->get_wakeup_threshold() != 0) { - if (!is_wakeup_source) { - is_wakeup_source = true; - // Touch sensor FSM mode must be 'TOUCH_FSM_MODE_TIMER' to use it to wake-up. - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - } - - // No filter available when using as wake-up source. - touch_pad_config(child->get_touch_pad(), child->get_wakeup_threshold()); - } - } - - if (!is_wakeup_source) { - touch_pad_deinit(); - } + // Configure wakeup pads if any are set + this->configure_wakeup_pads(); } void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) { diff --git a/esphome/components/esp32_touch/esp32_touch_v2.cpp b/esphome/components/esp32_touch/esp32_touch_v2.cpp index 8ac21676d0..d5c7b9db9b 100644 --- a/esphome/components/esp32_touch/esp32_touch_v2.cpp +++ b/esphome/components/esp32_touch/esp32_touch_v2.cpp @@ -301,21 +301,8 @@ void ESP32TouchComponent::on_shutdown() { touch_pad_isr_deregister(touch_isr_handler, this); this->cleanup_touch_queue(); - // Check if any pad is configured for wakeup - bool is_wakeup_source = false; - for (auto *child : this->children_) { - if (child->get_wakeup_threshold() != 0) { - if (!is_wakeup_source) { - is_wakeup_source = true; - // Touch sensor FSM mode must be 'TOUCH_FSM_MODE_TIMER' to use it to wake-up. - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - } - } - } - - if (!is_wakeup_source) { - touch_pad_deinit(); - } + // Configure wakeup pads if any are set + this->configure_wakeup_pads(); } void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) {