mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	help with setup
This commit is contained in:
		| @@ -68,6 +68,8 @@ class ESP32TouchComponent : public Component { | |||||||
|   // Common helper methods |   // Common helper methods | ||||||
|   void dump_config_base_(); |   void dump_config_base_(); | ||||||
|   void dump_config_sensors_(); |   void dump_config_sensors_(); | ||||||
|  |   bool create_touch_queue(); | ||||||
|  |   void cleanup_touch_queue(); | ||||||
|  |  | ||||||
|   // Common members |   // Common members | ||||||
|   std::vector<ESP32TouchBinarySensor *> children_; |   std::vector<ESP32TouchBinarySensor *> children_; | ||||||
|   | |||||||
| @@ -9,6 +9,20 @@ namespace esp32_touch { | |||||||
|  |  | ||||||
| static const char *const TAG = "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_() { | void ESP32TouchComponent::dump_config_base_() { | ||||||
|   const char *lv_s = get_low_voltage_reference_str(this->low_voltage_reference_); |   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_); |   const char *hv_s = get_high_voltage_reference_str(this->high_voltage_reference_); | ||||||
| @@ -33,6 +47,34 @@ void ESP32TouchComponent::dump_config_sensors_() { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | bool ESP32TouchComponent::create_touch_queue() { | ||||||
|  |   // Queue size calculation: children * 4 allows for burst scenarios where ISR | ||||||
|  |   // fires multiple times before main loop processes. | ||||||
|  |   size_t queue_size = this->children_.size() * 4; | ||||||
|  |   if (queue_size < 8) | ||||||
|  |     queue_size = 8; | ||||||
|  |  | ||||||
|  | #ifdef USE_ESP32_VARIANT_ESP32 | ||||||
|  |   this->touch_queue_ = xQueueCreate(queue_size, sizeof(TouchPadEventV1)); | ||||||
|  | #else | ||||||
|  |   this->touch_queue_ = xQueueCreate(queue_size, sizeof(TouchPadEventV2)); | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  |   if (this->touch_queue_ == nullptr) { | ||||||
|  |     ESP_LOGE(TAG, "Failed to create touch event queue of size %d", queue_size); | ||||||
|  |     this->mark_failed(); | ||||||
|  |     return false; | ||||||
|  |   } | ||||||
|  |   return true; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ESP32TouchComponent::cleanup_touch_queue() { | ||||||
|  |   if (this->touch_queue_) { | ||||||
|  |     vQueueDelete(this->touch_queue_); | ||||||
|  |     this->touch_queue_ = nullptr; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| }  // namespace esp32_touch | }  // namespace esp32_touch | ||||||
| }  // namespace esphome | }  // namespace esphome | ||||||
|  |  | ||||||
|   | |||||||
| @@ -34,14 +34,7 @@ void ESP32TouchComponent::setup() { | |||||||
|   // Queue size calculation: children * 4 allows for burst scenarios where ISR |   // Queue size calculation: children * 4 allows for burst scenarios where ISR | ||||||
|   // fires multiple times before main loop processes. This is important because |   // fires multiple times before main loop processes. This is important because | ||||||
|   // ESP32 v1 scans all pads on each interrupt, potentially sending multiple events. |   // ESP32 v1 scans all pads on each interrupt, potentially sending multiple events. | ||||||
|   size_t queue_size = this->children_.size() * 4; |   if (!this->create_touch_queue()) { | ||||||
|   if (queue_size < 8) |  | ||||||
|     queue_size = 8; |  | ||||||
|  |  | ||||||
|   this->touch_queue_ = xQueueCreate(queue_size, sizeof(TouchPadEventV1)); |  | ||||||
|   if (this->touch_queue_ == nullptr) { |  | ||||||
|     ESP_LOGE(TAG, "Failed to create touch event queue of size %d", queue_size); |  | ||||||
|     this->mark_failed(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -68,8 +61,7 @@ void ESP32TouchComponent::setup() { | |||||||
|   esp_err_t err = touch_pad_isr_register(touch_isr_handler, this); |   esp_err_t err = touch_pad_isr_register(touch_isr_handler, this); | ||||||
|   if (err != ESP_OK) { |   if (err != ESP_OK) { | ||||||
|     ESP_LOGE(TAG, "Failed to register touch ISR: %s", esp_err_to_name(err)); |     ESP_LOGE(TAG, "Failed to register touch ISR: %s", esp_err_to_name(err)); | ||||||
|     vQueueDelete(this->touch_queue_); |     this->cleanup_touch_queue(); | ||||||
|     this->touch_queue_ = nullptr; |  | ||||||
|     this->mark_failed(); |     this->mark_failed(); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
| @@ -192,9 +184,7 @@ void ESP32TouchComponent::loop() { | |||||||
| void ESP32TouchComponent::on_shutdown() { | void ESP32TouchComponent::on_shutdown() { | ||||||
|   touch_pad_intr_disable(); |   touch_pad_intr_disable(); | ||||||
|   touch_pad_isr_deregister(touch_isr_handler, this); |   touch_pad_isr_deregister(touch_isr_handler, this); | ||||||
|   if (this->touch_queue_) { |   this->cleanup_touch_queue(); | ||||||
|     vQueueDelete(this->touch_queue_); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   bool is_wakeup_source = false; |   bool is_wakeup_source = false; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,19 +13,11 @@ static const char *const TAG = "esp32_touch"; | |||||||
| struct TouchPadEventV2 { | struct TouchPadEventV2 { | ||||||
|   touch_pad_t pad; |   touch_pad_t pad; | ||||||
|   uint32_t intr_mask; |   uint32_t intr_mask; | ||||||
|   uint32_t pad_status; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| void ESP32TouchComponent::setup() { | void ESP32TouchComponent::setup() { | ||||||
|   // Create queue for touch events first |   // Create queue for touch events first | ||||||
|   size_t queue_size = this->children_.size() * 4; |   if (!this->create_touch_queue()) { | ||||||
|   if (queue_size < 8) |  | ||||||
|     queue_size = 8; |  | ||||||
|  |  | ||||||
|   this->touch_queue_ = xQueueCreate(queue_size, sizeof(TouchPadEventV2)); |  | ||||||
|   if (this->touch_queue_ == nullptr) { |  | ||||||
|     ESP_LOGE(TAG, "Failed to create touch event queue of size %d", queue_size); |  | ||||||
|     this->mark_failed(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -89,8 +81,7 @@ void ESP32TouchComponent::setup() { | |||||||
|       touch_pad_isr_register(touch_isr_handler, this, static_cast<touch_pad_intr_mask_t>(TOUCH_PAD_INTR_MASK_ALL)); |       touch_pad_isr_register(touch_isr_handler, this, static_cast<touch_pad_intr_mask_t>(TOUCH_PAD_INTR_MASK_ALL)); | ||||||
|   if (err != ESP_OK) { |   if (err != ESP_OK) { | ||||||
|     ESP_LOGE(TAG, "Failed to register touch ISR: %s", esp_err_to_name(err)); |     ESP_LOGE(TAG, "Failed to register touch ISR: %s", esp_err_to_name(err)); | ||||||
|     vQueueDelete(this->touch_queue_); |     this->cleanup_touch_queue(); | ||||||
|     this->touch_queue_ = nullptr; |  | ||||||
|     this->mark_failed(); |     this->mark_failed(); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
| @@ -313,9 +304,7 @@ void ESP32TouchComponent::on_shutdown() { | |||||||
|   touch_pad_intr_disable(static_cast<touch_pad_intr_mask_t>(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE | |   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_INTR_MASK_TIMEOUT)); | ||||||
|   touch_pad_isr_deregister(touch_isr_handler, this); |   touch_pad_isr_deregister(touch_isr_handler, this); | ||||||
|   if (this->touch_queue_) { |   this->cleanup_touch_queue(); | ||||||
|     vQueueDelete(this->touch_queue_); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   // Check if any pad is configured for wakeup |   // Check if any pad is configured for wakeup | ||||||
|   bool is_wakeup_source = false; |   bool is_wakeup_source = false; | ||||||
| @@ -338,10 +327,9 @@ void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) { | |||||||
|   ESP32TouchComponent *component = static_cast<ESP32TouchComponent *>(arg); |   ESP32TouchComponent *component = static_cast<ESP32TouchComponent *>(arg); | ||||||
|   BaseType_t x_higher_priority_task_woken = pdFALSE; |   BaseType_t x_higher_priority_task_woken = pdFALSE; | ||||||
|  |  | ||||||
|   // Read interrupt status and pad status |   // Read interrupt status | ||||||
|   TouchPadEventV2 event; |   TouchPadEventV2 event; | ||||||
|   event.intr_mask = touch_pad_read_intr_status_mask(); |   event.intr_mask = touch_pad_read_intr_status_mask(); | ||||||
|   event.pad_status = touch_pad_get_status(); |  | ||||||
|   event.pad = touch_pad_get_current_meas_channel(); |   event.pad = touch_pad_get_current_meas_channel(); | ||||||
|  |  | ||||||
|   // Send event to queue for processing in main loop |   // Send event to queue for processing in main loop | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user