From 5d765413ef0a62fef1f8f1dbcd82ef99bcf7ce20 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 12 Jun 2025 15:53:42 -0500 Subject: [PATCH] cleanup --- .../components/esp32_touch/esp32_touch_v2.cpp | 115 +++++++++--------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/esphome/components/esp32_touch/esp32_touch_v2.cpp b/esphome/components/esp32_touch/esp32_touch_v2.cpp index 344ec109fe..a502e95991 100644 --- a/esphome/components/esp32_touch/esp32_touch_v2.cpp +++ b/esphome/components/esp32_touch/esp32_touch_v2.cpp @@ -309,78 +309,77 @@ void ESP32TouchComponent::loop() { break; } } -} -// In setup mode, periodically log all pad values -if (this->setup_mode_ && now - this->setup_mode_last_log_print_ > SETUP_MODE_LOG_INTERVAL_MS) { - for (auto *child : this->children_) { - uint32_t raw = 0; - uint32_t benchmark = 0; - uint32_t smooth = 0; + // In setup mode, periodically log all pad values + if (this->setup_mode_ && now - this->setup_mode_last_log_print_ > SETUP_MODE_LOG_INTERVAL_MS) { + for (auto *child : this->children_) { + uint32_t raw = 0; + uint32_t benchmark = 0; + uint32_t smooth = 0; - touch_pad_read_raw_data(child->get_touch_pad(), &raw); - touch_pad_read_benchmark(child->get_touch_pad(), &benchmark); + touch_pad_read_raw_data(child->get_touch_pad(), &raw); + touch_pad_read_benchmark(child->get_touch_pad(), &benchmark); - if (this->filter_configured_()) { - touch_pad_filter_read_smooth(child->get_touch_pad(), &smooth); - ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, smooth=%d, threshold=%d", child->get_touch_pad(), raw, benchmark, - smooth, child->get_threshold()); - } else { - ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, threshold=%d", child->get_touch_pad(), raw, benchmark, - child->get_threshold()); - } - } - 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_); - } - - // 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 (this->filter_configured_()) { + touch_pad_filter_read_smooth(child->get_touch_pad(), &smooth); + ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, smooth=%d, threshold=%d", child->get_touch_pad(), raw, + benchmark, smooth, child->get_threshold()); + } else { + ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, threshold=%d", child->get_touch_pad(), raw, benchmark, + child->get_threshold()); } } + this->setup_mode_last_log_print_ = now; } - if (!is_wakeup_source) { - touch_pad_deinit(); + 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); + } + } + } + + 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; + 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(); + // 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); - // } + // 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); + // Send event to queue for processing in main loop + xQueueSendFromISR(component->touch_queue_, &event, &xHigherPriorityTaskWoken); - if (xHigherPriorityTaskWoken) { - portYIELD_FROM_ISR(); + if (xHigherPriorityTaskWoken) { + portYIELD_FROM_ISR(); + } } -} } // namespace esp32_touch } // namespace esphome