change(sdmmc): update ldo acquire driver to new API

pull/13550/head
morris 2024-03-25 15:41:20 +08:00
rodzic 56b40a028d
commit 4c2569e2fc
6 zmienionych plików z 14 dodań i 20 usunięć

Wyświetl plik

@ -19,7 +19,6 @@
#include "driver/gpio.h"
#include "driver/sdmmc_host.h"
#include "esp_private/periph_ctrl.h"
#include "esp_private/esp_ldo.h"
#include "sdmmc_private.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
@ -55,7 +54,6 @@ typedef struct slot_ctx_t {
size_t slot_width;
sdmmc_slot_io_info_t slot_gpio_num;
bool use_gpio_matrix;
esp_ldo_unit_handle_t ldo_unit;
} slot_ctx_t;
/**

Wyświetl plik

@ -39,7 +39,7 @@ void sdmmc_test_board_get_config_sdmmc(int slot_index, sdmmc_host_t *out_host_co
#define SDMMC_PWR_LDO_CHANNEL 4
sd_pwr_ctrl_ldo_config_t ldo_config = {
.ldo_unit_id = SDMMC_PWR_LDO_CHANNEL,
.ldo_chan_id = SDMMC_PWR_LDO_CHANNEL,
};
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;

Wyświetl plik

@ -12,7 +12,7 @@ set(srcs "sdmmc_cmd.c"
"sdmmc_sd.c"
"sd_pwr_ctrl/sd_pwr_ctrl.c")
if(CONFIG_SOC_MULTI_USAGE_LDO_SUPPORTED)
if(CONFIG_SOC_GP_LDO_SUPPORTED)
list(APPEND srcs "sd_pwr_ctrl/sd_pwr_ctrl_by_on_chip_ldo.c")
endif()

Wyświetl plik

@ -19,7 +19,7 @@ extern "C" {
* @brief LDO configurations
*/
typedef struct {
int ldo_unit_id; ///< On-chip LDO ID
int ldo_chan_id; ///< On-chip LDO channel ID, e.g. set to `4` is the `LDO_VO4` is connected to power the SDMMC IO
} sd_pwr_ctrl_ldo_config_t;
/**

Wyświetl plik

@ -12,14 +12,14 @@
#include "esp_log.h"
#include "esp_check.h"
#include "esp_heap_caps.h"
#include "esp_private/esp_ldo.h"
#include "esp_ldo_regulator.h"
#include "soc/soc_caps.h"
#include "sd_pwr_ctrl.h"
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
#include "sd_pwr_ctrl_interface.h"
typedef struct {
esp_ldo_unit_handle_t ldo_unit;
esp_ldo_channel_handle_t ldo_chan;
int voltage_mv;
} sd_pwr_ctrl_ldo_ctx_t;
@ -37,19 +37,16 @@ esp_err_t sd_pwr_ctrl_new_on_chip_ldo(const sd_pwr_ctrl_ldo_config_t *configs, s
sd_pwr_ctrl_ldo_ctx_t *ctx = (sd_pwr_ctrl_ldo_ctx_t *)heap_caps_calloc(1, sizeof(sd_pwr_ctrl_ldo_ctx_t), MALLOC_CAP_DEFAULT | MALLOC_CAP_8BIT);
ESP_GOTO_ON_FALSE(ctx, ESP_ERR_NO_MEM, err, TAG, "no mem for on-chip ldo control driver context");
esp_ldo_unit_init_cfg_t unit_cfg = {
.unit_id = configs->ldo_unit_id,
.cfg = {
.voltage_mv = 0, //will be adjusted dynamically by sdmmc driver later
},
esp_ldo_channel_config_t chan_cfg = {
.chan_id = configs->ldo_chan_id,
.flags.adjustable = true, // the SDMMC power control driver will adjust the voltage later according to different speed mode
};
esp_ldo_unit_handle_t ldo_unit = NULL;
ESP_GOTO_ON_ERROR(esp_ldo_init_unit(&unit_cfg, &ldo_unit), err, TAG, "failed to create an on-chip LDO unit handle");
ESP_GOTO_ON_ERROR(esp_ldo_enable_unit(ldo_unit), err, TAG, "failed to enable the on-chip LDO unit");
esp_ldo_channel_handle_t ldo_chan = NULL;
ESP_GOTO_ON_ERROR(esp_ldo_acquire_channel(&chan_cfg, &ldo_chan), err, TAG, "failed to enable the on-chip LDO unit");
driver->set_io_voltage = s_ldo_set_voltage;
driver->ctx = ctx;
ctx->ldo_unit = ldo_unit;
ctx->ldo_chan = ldo_chan;
ctx->voltage_mv = 0;
*ret_drv = driver;
@ -66,8 +63,7 @@ esp_err_t sd_pwr_ctrl_del_on_chip_ldo(sd_pwr_ctrl_handle_t handle)
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "invalid arg: null pointer");
sd_pwr_ctrl_ldo_ctx_t *ctx = handle->ctx;
ESP_RETURN_ON_ERROR(esp_ldo_disable_unit(ctx->ldo_unit), TAG, "failed to disable the on-chip LDO unit");
ESP_RETURN_ON_ERROR(esp_ldo_deinit_unit(ctx->ldo_unit), TAG, "failed to deinit the LDO unit handle");
ESP_RETURN_ON_ERROR(esp_ldo_release_channel(ctx->ldo_chan), TAG, "failed to release the on-chip LDO channel");
free(handle->ctx);
handle->ctx = NULL;
free(handle);
@ -80,7 +76,7 @@ static esp_err_t s_ldo_set_voltage(void *arg, int voltage_mv)
{
//API checks done by caller
sd_pwr_ctrl_ldo_ctx_t *ctx = arg;
ESP_RETURN_ON_ERROR(esp_ldo_set_voltage(ctx->ldo_unit, voltage_mv), TAG, "failed to set LDO unit output voltage");
ESP_RETURN_ON_ERROR(esp_ldo_channel_adjust_voltage(ctx->ldo_chan, voltage_mv), TAG, "failed to set LDO unit output voltage");
ctx->voltage_mv = voltage_mv;
return ESP_OK;
}

Wyświetl plik

@ -132,7 +132,7 @@ void app_main(void)
*/
#if CONFIG_EXAMPLE_SDMMC_IO_POWER_INTERNAL_LDO
sd_pwr_ctrl_ldo_config_t ldo_config = {
.ldo_unit_id = 4,
.ldo_chan_id = 4, // `LDO_VO4` is used as the SDMMC IO power
};
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;