ESPHome 2026.3.0-dev
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 = this->voltage_mv_;
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 %dmV", this->channel_, this->voltage_mv_);
18 this->mark_failed(LOG_STR("Failed to acquire LDO channel"));
19 } else {
20 ESP_LOGD(TAG, "Acquired LDO channel %d with voltage %dmV", this->channel_, this->voltage_mv_);
21 }
22}
24 ESP_LOGCONFIG(TAG,
25 "ESP LDO Channel %d:\n"
26 " Voltage: %dmV\n"
27 " Adjustable: %s",
28 this->channel_, this->voltage_mv_, 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 (must be 0.5V-2.7V)", voltage, this->channel_);
34 return;
35 }
36 int voltage_mv = (int) roundf(voltage * 1000.0f);
37 auto err = esp_ldo_channel_adjust_voltage(this->handle_, voltage_mv);
38 if (err != ESP_OK) {
39 ESP_LOGE(TAG, "Failed to adjust LDO channel %d to voltage %dmV: %s", this->channel_, voltage_mv,
40 esp_err_to_name(err));
41 }
42}
43
44} // namespace esp_ldo
45} // namespace esphome
46
47#endif // USE_ESP32_VARIANT_ESP32P4
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