mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Fix InterruptLock on ESP-IDF (#2388)
This commit is contained in:
		| @@ -11,13 +11,17 @@ dallas_ns = cg.esphome_ns.namespace("dallas") | |||||||
| DallasComponent = dallas_ns.class_("DallasComponent", cg.PollingComponent) | DallasComponent = dallas_ns.class_("DallasComponent", cg.PollingComponent) | ||||||
| ESPOneWire = dallas_ns.class_("ESPOneWire") | ESPOneWire = dallas_ns.class_("ESPOneWire") | ||||||
|  |  | ||||||
| CONFIG_SCHEMA = cv.Schema( | CONFIG_SCHEMA = cv.All( | ||||||
|  |     cv.Schema( | ||||||
|         { |         { | ||||||
|             cv.GenerateID(): cv.declare_id(DallasComponent), |             cv.GenerateID(): cv.declare_id(DallasComponent), | ||||||
|             cv.GenerateID(CONF_ONE_WIRE_ID): cv.declare_id(ESPOneWire), |             cv.GenerateID(CONF_ONE_WIRE_ID): cv.declare_id(ESPOneWire), | ||||||
|             cv.Required(CONF_PIN): pins.internal_gpio_output_pin_schema, |             cv.Required(CONF_PIN): pins.internal_gpio_output_pin_schema, | ||||||
|         } |         } | ||||||
| ).extend(cv.polling_component_schema("60s")) |     ).extend(cv.polling_component_schema("60s")), | ||||||
|  |     # pin_mode call logs in esp-idf, but InterruptLock is active -> crash | ||||||
|  |     cv.only_with_arduino, | ||||||
|  | ) | ||||||
|  |  | ||||||
|  |  | ||||||
| async def to_code(config): | async def to_code(config): | ||||||
|   | |||||||
| @@ -79,9 +79,6 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r | |||||||
|   int8_t i = 0; |   int8_t i = 0; | ||||||
|   uint8_t data[5] = {0, 0, 0, 0, 0}; |   uint8_t data[5] = {0, 0, 0, 0, 0}; | ||||||
|  |  | ||||||
|   { |  | ||||||
|     InterruptLock lock; |  | ||||||
|  |  | ||||||
|   this->pin_->digital_write(false); |   this->pin_->digital_write(false); | ||||||
|   this->pin_->pin_mode(gpio::FLAG_OUTPUT); |   this->pin_->pin_mode(gpio::FLAG_OUTPUT); | ||||||
|   this->pin_->digital_write(false); |   this->pin_->digital_write(false); | ||||||
| @@ -101,6 +98,8 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r | |||||||
|   } |   } | ||||||
|   this->pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); |   this->pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); | ||||||
|  |  | ||||||
|  |   { | ||||||
|  |     InterruptLock lock; | ||||||
|     // Host pull up 20-40us then DHT response 80us |     // Host pull up 20-40us then DHT response 80us | ||||||
|     // Start waiting for initial rising edge at the center when we |     // Start waiting for initial rising edge at the center when we | ||||||
|     // expect the DHT response (30us+40us) |     // expect the DHT response (30us+40us) | ||||||
|   | |||||||
| @@ -350,7 +350,7 @@ std::string hexencode(const uint8_t *data, uint32_t len) { | |||||||
| IRAM_ATTR InterruptLock::InterruptLock() { xt_state_ = xt_rsil(15); } | IRAM_ATTR InterruptLock::InterruptLock() { xt_state_ = xt_rsil(15); } | ||||||
| IRAM_ATTR InterruptLock::~InterruptLock() { xt_wsr_ps(xt_state_); } | IRAM_ATTR InterruptLock::~InterruptLock() { xt_wsr_ps(xt_state_); } | ||||||
| #endif | #endif | ||||||
| #ifdef USE_ESP32_FRAMEWORK_ARDUINO | #ifdef USE_ESP32 | ||||||
| IRAM_ATTR InterruptLock::InterruptLock() { portDISABLE_INTERRUPTS(); } | IRAM_ATTR InterruptLock::InterruptLock() { portDISABLE_INTERRUPTS(); } | ||||||
| IRAM_ATTR InterruptLock::~InterruptLock() { portENABLE_INTERRUPTS(); } | IRAM_ATTR InterruptLock::~InterruptLock() { portENABLE_INTERRUPTS(); } | ||||||
| #endif | #endif | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user