mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[esp32_dac] Always use esp-idf APIs (#9833)
This commit is contained in:
		| @@ -2,11 +2,7 @@ | |||||||
| #include "esphome/core/helpers.h" | #include "esphome/core/helpers.h" | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
|  |  | ||||||
| #ifdef USE_ESP32 | #if defined(USE_ESP32_VARIANT_ESP32) || defined(USE_ESP32_VARIANT_ESP32S2) | ||||||
|  |  | ||||||
| #ifdef USE_ARDUINO |  | ||||||
| #include <esp32-hal-dac.h> |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace esp32_dac { | namespace esp32_dac { | ||||||
| @@ -23,18 +19,12 @@ void ESP32DAC::setup() { | |||||||
|   this->pin_->setup(); |   this->pin_->setup(); | ||||||
|   this->turn_off(); |   this->turn_off(); | ||||||
|  |  | ||||||
| #ifdef USE_ESP_IDF |  | ||||||
|   const dac_channel_t channel = this->pin_->get_pin() == DAC0_PIN ? DAC_CHAN_0 : DAC_CHAN_1; |   const dac_channel_t channel = this->pin_->get_pin() == DAC0_PIN ? DAC_CHAN_0 : DAC_CHAN_1; | ||||||
|   const dac_oneshot_config_t oneshot_cfg{channel}; |   const dac_oneshot_config_t oneshot_cfg{channel}; | ||||||
|   dac_oneshot_new_channel(&oneshot_cfg, &this->dac_handle_); |   dac_oneshot_new_channel(&oneshot_cfg, &this->dac_handle_); | ||||||
| #endif |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void ESP32DAC::on_safe_shutdown() { | void ESP32DAC::on_safe_shutdown() { dac_oneshot_del_channel(this->dac_handle_); } | ||||||
| #ifdef USE_ESP_IDF |  | ||||||
|   dac_oneshot_del_channel(this->dac_handle_); |  | ||||||
| #endif |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void ESP32DAC::dump_config() { | void ESP32DAC::dump_config() { | ||||||
|   ESP_LOGCONFIG(TAG, "ESP32 DAC:"); |   ESP_LOGCONFIG(TAG, "ESP32 DAC:"); | ||||||
| @@ -48,15 +38,10 @@ void ESP32DAC::write_state(float state) { | |||||||
|  |  | ||||||
|   state = state * 255; |   state = state * 255; | ||||||
|  |  | ||||||
| #ifdef USE_ESP_IDF |  | ||||||
|   dac_oneshot_output_voltage(this->dac_handle_, state); |   dac_oneshot_output_voltage(this->dac_handle_, state); | ||||||
| #endif |  | ||||||
| #ifdef USE_ARDUINO |  | ||||||
|   dacWrite(this->pin_->get_pin(), state); |  | ||||||
| #endif |  | ||||||
| } | } | ||||||
|  |  | ||||||
| }  // namespace esp32_dac | }  // namespace esp32_dac | ||||||
| }  // namespace esphome | }  // namespace esphome | ||||||
|  |  | ||||||
| #endif | #endif  // USE_ESP32_VARIANT_ESP32 || USE_ESP32_VARIANT_ESP32S2 | ||||||
|   | |||||||
| @@ -1,15 +1,13 @@ | |||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
|  | #include "esphome/components/output/float_output.h" | ||||||
|  | #include "esphome/core/automation.h" | ||||||
| #include "esphome/core/component.h" | #include "esphome/core/component.h" | ||||||
| #include "esphome/core/hal.h" | #include "esphome/core/hal.h" | ||||||
| #include "esphome/core/automation.h" |  | ||||||
| #include "esphome/components/output/float_output.h" |  | ||||||
|  |  | ||||||
| #ifdef USE_ESP32 | #if defined(USE_ESP32_VARIANT_ESP32) || defined(USE_ESP32_VARIANT_ESP32S2) | ||||||
|  |  | ||||||
| #ifdef USE_ESP_IDF |  | ||||||
| #include <driver/dac_oneshot.h> | #include <driver/dac_oneshot.h> | ||||||
| #endif |  | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace esp32_dac { | namespace esp32_dac { | ||||||
| @@ -29,12 +27,10 @@ class ESP32DAC : public output::FloatOutput, public Component { | |||||||
|   void write_state(float state) override; |   void write_state(float state) override; | ||||||
|  |  | ||||||
|   InternalGPIOPin *pin_; |   InternalGPIOPin *pin_; | ||||||
| #ifdef USE_ESP_IDF |  | ||||||
|   dac_oneshot_handle_t dac_handle_; |   dac_oneshot_handle_t dac_handle_; | ||||||
| #endif |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| }  // namespace esp32_dac | }  // namespace esp32_dac | ||||||
| }  // namespace esphome | }  // namespace esphome | ||||||
|  |  | ||||||
| #endif | #endif  // USE_ESP32_VARIANT_ESP32 || USE_ESP32_VARIANT_ESP32S2 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user