diff --git a/components/esp32/pm_esp32.c b/components/esp32/pm_esp32.c index 3c7019bb23..0b26d9ddf8 100644 --- a/components/esp32/pm_esp32.c +++ b/components/esp32/pm_esp32.c @@ -237,6 +237,23 @@ esp_err_t esp_pm_configure(const void* vconfig) return ESP_OK; } +esp_err_t esp_pm_get_configuration(void* vconfig) +{ + if (vconfig == NULL) { + return ESP_ERR_INVALID_ARG; + } + + esp_pm_config_esp32_t* config = (esp_pm_config_esp32_t*) vconfig; + + portENTER_CRITICAL(&s_switch_lock); + config->light_sleep_enable = s_light_sleep_en; + config->max_freq_mhz = s_cpu_freq_by_mode[PM_MODE_CPU_MAX].freq_mhz; + config->min_freq_mhz = s_cpu_freq_by_mode[PM_MODE_APB_MIN].freq_mhz; + portEXIT_CRITICAL(&s_switch_lock); + + return ESP_OK; +} + static pm_mode_t IRAM_ATTR get_lowest_allowed_mode(void) { /* TODO: optimize using ffs/clz */ diff --git a/components/esp32s2/pm_esp32s2.c b/components/esp32s2/pm_esp32s2.c index 99eb75e548..8011bdce87 100644 --- a/components/esp32s2/pm_esp32s2.c +++ b/components/esp32s2/pm_esp32s2.c @@ -232,6 +232,23 @@ esp_err_t esp_pm_configure(const void* vconfig) return ESP_OK; } +esp_err_t esp_pm_get_configuration(void* vconfig) +{ + if (vconfig == NULL) { + return ESP_ERR_INVALID_ARG; + } + + esp_pm_config_esp32s2_t* config = (esp_pm_config_esp32s2_t*) vconfig; + + portENTER_CRITICAL(&s_switch_lock); + config->light_sleep_enable = s_light_sleep_en; + config->max_freq_mhz = s_cpu_freq_by_mode[PM_MODE_CPU_MAX].freq_mhz; + config->min_freq_mhz = s_cpu_freq_by_mode[PM_MODE_APB_MIN].freq_mhz; + portEXIT_CRITICAL(&s_switch_lock); + + return ESP_OK; +} + static pm_mode_t IRAM_ATTR get_lowest_allowed_mode(void) { /* TODO: optimize using ffs/clz */ diff --git a/components/esp_common/include/esp_pm.h b/components/esp_common/include/esp_pm.h index 15af6a4aca..ccc4ddf703 100644 --- a/components/esp_common/include/esp_pm.h +++ b/components/esp_common/include/esp_pm.h @@ -59,6 +59,14 @@ typedef enum { */ esp_err_t esp_pm_configure(const void* config); +/** + * @brief Get implementation-specific power management configuration + * @param config pointer to implementation-specific configuration structure (e.g. esp_pm_config_esp32) + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if the pointer is null + */ +esp_err_t esp_pm_get_configuration(void* config); /** * @brief Opaque handle to the power management lock