From aabacb745431257e66a8bf940e8e52c16563268e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 12 Jun 2025 17:47:25 -0500 Subject: [PATCH] help with setup --- esphome/components/esp32_touch/esp32_touch.h | 19 +++++++++++++++++++ .../esp32_touch/esp32_touch_common.cpp | 14 -------------- .../components/esp32_touch/esp32_touch_v1.cpp | 14 +++----------- .../components/esp32_touch/esp32_touch_v2.cpp | 5 ----- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/esphome/components/esp32_touch/esp32_touch.h b/esphome/components/esp32_touch/esp32_touch.h index 965494f523..20db00fe15 100644 --- a/esphome/components/esp32_touch/esp32_touch.h +++ b/esphome/components/esp32_touch/esp32_touch.h @@ -92,6 +92,16 @@ class ESP32TouchComponent : public Component { static void touch_isr_handler(void *arg); QueueHandle_t touch_queue_{nullptr}; + private: + // Touch event structure for ESP32 v1 + // Contains touch pad info, value, and touch state for queue communication + struct TouchPadEventV1 { + touch_pad_t pad; + uint32_t value; + bool is_touched; + }; + + protected: // Design note: last_touch_time_ does not require synchronization primitives because: // 1. ESP32 guarantees atomic 32-bit aligned reads/writes // 2. ISR only writes timestamps, main loop only reads (except sentinel value 1) @@ -110,6 +120,15 @@ class ESP32TouchComponent : public Component { static void touch_isr_handler(void *arg); QueueHandle_t touch_queue_{nullptr}; + private: + // Touch event structure for ESP32 v2 (S2/S3) + // Contains touch pad and interrupt mask for queue communication + struct TouchPadEventV2 { + touch_pad_t pad; + uint32_t intr_mask; + }; + + protected: // Filter configuration touch_filter_mode_t filter_mode_{TOUCH_PAD_FILTER_MAX}; uint32_t debounce_count_{0}; diff --git a/esphome/components/esp32_touch/esp32_touch_common.cpp b/esphome/components/esp32_touch/esp32_touch_common.cpp index d9c1c22320..7ca0b4155d 100644 --- a/esphome/components/esp32_touch/esp32_touch_common.cpp +++ b/esphome/components/esp32_touch/esp32_touch_common.cpp @@ -9,20 +9,6 @@ namespace esp32_touch { static const char *const TAG = "esp32_touch"; -// Forward declare the event structures that are defined in the variant-specific files -#ifdef USE_ESP32_VARIANT_ESP32 -struct TouchPadEventV1 { - touch_pad_t pad; - uint32_t value; - bool is_touched; -}; -#else -struct TouchPadEventV2 { - touch_pad_t pad; - uint32_t intr_mask; -}; -#endif - void ESP32TouchComponent::dump_config_base_() { const char *lv_s = get_low_voltage_reference_str(this->low_voltage_reference_); const char *hv_s = get_high_voltage_reference_str(this->high_voltage_reference_); diff --git a/esphome/components/esp32_touch/esp32_touch_v1.cpp b/esphome/components/esp32_touch/esp32_touch_v1.cpp index d6cf2983d5..c4be859b3f 100644 --- a/esphome/components/esp32_touch/esp32_touch_v1.cpp +++ b/esphome/components/esp32_touch/esp32_touch_v1.cpp @@ -18,18 +18,7 @@ namespace esp32_touch { static const char *const TAG = "esp32_touch"; -struct TouchPadEventV1 { - touch_pad_t pad; - uint32_t value; - bool is_touched; -}; - void ESP32TouchComponent::setup() { - ESP_LOGCONFIG(TAG, "Running setup for ESP32"); - - touch_pad_init(); - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - // Create queue for touch events // Queue size calculation: children * 4 allows for burst scenarios where ISR // fires multiple times before main loop processes. This is important because @@ -38,6 +27,9 @@ void ESP32TouchComponent::setup() { return; } + touch_pad_init(); + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + // Set up IIR filter if enabled if (this->iir_filter_enabled_()) { touch_pad_filter_start(this->iir_filter_); diff --git a/esphome/components/esp32_touch/esp32_touch_v2.cpp b/esphome/components/esp32_touch/esp32_touch_v2.cpp index 08d3d0aba0..f0737a6cec 100644 --- a/esphome/components/esp32_touch/esp32_touch_v2.cpp +++ b/esphome/components/esp32_touch/esp32_touch_v2.cpp @@ -10,11 +10,6 @@ namespace esp32_touch { static const char *const TAG = "esp32_touch"; -struct TouchPadEventV2 { - touch_pad_t pad; - uint32_t intr_mask; -}; - void ESP32TouchComponent::setup() { // Create queue for touch events first if (!this->create_touch_queue()) {