1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-14 17:22:20 +01:00
This commit is contained in:
J. Nick Koston
2025-06-12 15:53:42 -05:00
parent efb2e5e7a8
commit 5d765413ef

View File

@@ -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_t>(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_t>(
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<ESP32TouchComponent *>(arg);
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) {
ESP32TouchComponent *component = static_cast<ESP32TouchComponent *>(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