From bcb6b8533394ec1eb51550f72d9afeaf4115faf8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 12 Jun 2025 15:54:15 -0500 Subject: [PATCH] cleanup --- .../components/esp32_touch/esp32_touch_v2.cpp | 85 ++++++++++--------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/esphome/components/esp32_touch/esp32_touch_v2.cpp b/esphome/components/esp32_touch/esp32_touch_v2.cpp index a502e95991..9d6f222f65 100644 --- a/esphome/components/esp32_touch/esp32_touch_v2.cpp +++ b/esphome/components/esp32_touch/esp32_touch_v2.cpp @@ -331,55 +331,56 @@ void ESP32TouchComponent::loop() { } this->setup_mode_last_log_print_ = now; } +} - void ESP32TouchComponent::on_shutdown() { - // Disable interrupts - touch_pad_intr_disable(static_cast( - TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE | TOUCH_PAD_INTR_MASK_TIMEOUT)); - touch_pad_isr_deregister(touch_isr_handler, this); - if (this->touch_queue_) { - vQueueDelete(this->touch_queue_); - } +void ESP32TouchComponent::on_shutdown() { + // Disable interrupts + touch_pad_intr_disable(static_cast(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE | + TOUCH_PAD_INTR_MASK_TIMEOUT)); + touch_pad_isr_deregister(touch_isr_handler, this); + if (this->touch_queue_) { + vQueueDelete(this->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); - } + // 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(); - } } - void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) { - ESP32TouchComponent *component = static_cast(arg); - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - - // Read interrupt status and pad status - TouchPadEventV2 event; - event.intr_mask = touch_pad_read_intr_status_mask(); - event.pad_status = touch_pad_get_status(); - event.pad = touch_pad_get_current_meas_channel(); - - // Debug logging from ISR (using ROM functions for ISR safety) - only log non-timeout events for now - // if (event.intr_mask != 0x10 || event.pad_status != 0) { - // ets_printf("ISR: intr=0x%x, status=0x%x, pad=%d\n", event.intr_mask, event.pad_status, event.pad); - // } - - // Send event to queue for processing in main loop - xQueueSendFromISR(component->touch_queue_, &event, &xHigherPriorityTaskWoken); - - if (xHigherPriorityTaskWoken) { - portYIELD_FROM_ISR(); - } + if (!is_wakeup_source) { + touch_pad_deinit(); } +} + +void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) { + ESP32TouchComponent *component = static_cast(arg); + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + + // Read interrupt status and pad status + TouchPadEventV2 event; + event.intr_mask = touch_pad_read_intr_status_mask(); + event.pad_status = touch_pad_get_status(); + event.pad = touch_pad_get_current_meas_channel(); + + // Debug logging from ISR (using ROM functions for ISR safety) - only log non-timeout events for now + // if (event.intr_mask != 0x10 || event.pad_status != 0) { + // ets_printf("ISR: intr=0x%x, status=0x%x, pad=%d\n", event.intr_mask, event.pad_status, event.pad); + // } + + // Send event to queue for processing in main loop + xQueueSendFromISR(component->touch_queue_, &event, &xHigherPriorityTaskWoken); + + if (xHigherPriorityTaskWoken) { + portYIELD_FROM_ISR(); + } +} } // namespace esp32_touch } // namespace esphome