ESPHome 2025.6.2
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 auto msg = str_sprintf("Failed to acquire LDO channel %d with voltage %fV", this->channel_, this->voltage_);
18 this->mark_failed(msg.c_str());
19 } else {
20 ESP_LOGD(TAG, "Acquired LDO channel %d with voltage %fV", this->channel_, this->voltage_);
21 }
22}
24 ESP_LOGCONFIG(TAG, "ESP LDO Channel %d:", this->channel_);
25 ESP_LOGCONFIG(TAG, " Voltage: %fV", this->voltage_);
26 ESP_LOGCONFIG(TAG, " Adjustable: %s", YESNO(this->adjustable_));
27}
28
29void EspLdo::adjust_voltage(float voltage) {
30 if (!std::isfinite(voltage) || voltage < 0.5f || voltage > 2.7f) {
31 ESP_LOGE(TAG, "Invalid voltage %fV for LDO channel %d", voltage, this->channel_);
32 return;
33 }
34 auto erro = esp_ldo_channel_adjust_voltage(this->handle_, (int) (voltage * 1000.0f));
35 if (erro != ESP_OK) {
36 ESP_LOGE(TAG, "Failed to adjust LDO channel %d to voltage %fV: %s", this->channel_, voltage, esp_err_to_name(erro));
37 }
38}
39
40} // namespace esp_ldo
41} // namespace esphome
42
43#endif // USE_ESP32_VARIANT_ESP32P4
virtual void mark_failed()
Mark this component as failed.
void adjust_voltage(float voltage)
Definition esp_ldo.cpp:29
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:25
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string str_sprintf(const char *fmt,...)
Definition helpers.cpp:323