ESPHome 2026.5.0b1
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::esp_ldo {
7
8static const char *const TAG = "esp_ldo";
10 esp_ldo_channel_config_t config{};
11 config.chan_id = this->channel_;
12 config.voltage_mv = this->voltage_mv_;
13 config.flags.adjustable = this->adjustable_;
14 auto err = esp_ldo_acquire_channel(&config, &this->handle_);
15 if (err != ESP_OK) {
16 ESP_LOGE(TAG, "Failed to acquire LDO channel %d with voltage %dmV", this->channel_, this->voltage_mv_);
17 this->mark_failed(LOG_STR("Failed to acquire LDO channel"));
18 } else {
19 ESP_LOGD(TAG, "Acquired LDO channel %d with voltage %dmV", this->channel_, this->voltage_mv_);
20 }
21}
23 ESP_LOGCONFIG(TAG,
24 "ESP LDO Channel %d:\n"
25 " Voltage: %dmV\n"
26 " Adjustable: %s",
27 this->channel_, this->voltage_mv_, YESNO(this->adjustable_));
28}
29
30void EspLdo::adjust_voltage(float voltage) {
31 if (!std::isfinite(voltage) || voltage < 0.5f || voltage > 2.7f) {
32 ESP_LOGE(TAG, "Invalid voltage %fV for LDO channel %d (must be 0.5V-2.7V)", voltage, this->channel_);
33 return;
34 }
35 int voltage_mv = (int) roundf(voltage * 1000.0f);
36 auto err = esp_ldo_channel_adjust_voltage(this->handle_, voltage_mv);
37 if (err != ESP_OK) {
38 ESP_LOGE(TAG, "Failed to adjust LDO channel %d to voltage %dmV: %s", this->channel_, voltage_mv,
39 esp_err_to_name(err));
40 }
41}
42
43} // namespace esphome::esp_ldo
44
45#endif // USE_ESP32_VARIANT_ESP32P4
void mark_failed()
Mark this component as failed.
void adjust_voltage(float voltage)
Definition esp_ldo.cpp:30
void setup() override
Definition esp_ldo.cpp:9
void dump_config() override
Definition esp_ldo.cpp:22
esp_ldo_channel_handle_t handle_
Definition esp_ldo.h:27