ESPHome 2026.1.4
Loading...
Searching...
No Matches
esp_ldo.cpp
Go to the documentation of this file.
1#ifdef USE_ESP32_VARIANT_ESP32P4
2#include "esp_ldo.h"
3#include "esphome/core/log.h"
5
6namespace esphome {
7namespace esp_ldo {
8
9static const char *const TAG = "esp_ldo";
11 esp_ldo_channel_config_t config{};
12 config.chan_id = this->channel_;
13 config.voltage_mv = (int) (this->voltage_ * 1000.0f);
14 config.flags.adjustable = this->adjustable_;
15 auto err = esp_ldo_acquire_channel(&config, &this->handle_);
16 if (err != ESP_OK) {
17 ESP_LOGE(TAG, "Failed to acquire LDO channel %d with voltage %fV", this->channel_, this->voltage_);
18 this->mark_failed(LOG_STR("Failed to acquire LDO channel"));
19 } else {
20 ESP_LOGD(TAG, "Acquired LDO channel %d with voltage %fV", this->channel_, this->voltage_);
21 }
22}
24 ESP_LOGCONFIG(TAG,
25 "ESP LDO Channel %d:\n"
26 " Voltage: %fV\n"
27 " Adjustable: %s",
28 this->channel_, this->voltage_, YESNO(this->adjustable_));
29}
30
31void EspLdo::adjust_voltage(float voltage) {
32 if (!std::isfinite(voltage) || voltage < 0.5f || voltage > 2.7f) {
33 ESP_LOGE(TAG, "Invalid voltage %fV for LDO channel %d", voltage, this->channel_);
34 return;
35 }
36 auto erro = esp_ldo_channel_adjust_voltage(this->handle_, (int) (voltage * 1000.0f));
37 if (erro != ESP_OK) {
38 ESP_LOGE(TAG, "Failed to adjust LDO channel %d to voltage %fV: %s", this->channel_, voltage, esp_err_to_name(erro));
39 }
40}
41
42} // namespace esp_ldo
43} // namespace esphome
44
45#endif // USE_ESP32_VARIANT_ESP32P4
virtual void mark_failed()
Mark this component as failed.
void adjust_voltage(float voltage)
Definition esp_ldo.cpp:31
void setup() override
Definition esp_ldo.cpp:10
void dump_config() override
Definition esp_ldo.cpp:23
esp_ldo_channel_handle_t handle_
Definition esp_ldo.h:28
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7