From 28b2e5f2bb8084adfdbad32f58ec6b846ead8b8d Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Thu, 18 Apr 2024 10:31:50 +0800 Subject: [PATCH] feat(jpeg): update example use ldo for sd card --- .../jpeg/jpeg_decode/main/Kconfig.projbuild | 9 ++++++++ .../jpeg/jpeg_decode/main/jpeg_decode_main.c | 23 +++++++++++++++++++ .../jpeg/jpeg_encode/main/Kconfig.projbuild | 9 ++++++++ .../jpeg/jpeg_encode/main/jpeg_encode_main.c | 23 +++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/examples/peripherals/jpeg/jpeg_decode/main/Kconfig.projbuild b/examples/peripherals/jpeg/jpeg_decode/main/Kconfig.projbuild index a33f65db3b..f6154c38ed 100644 --- a/examples/peripherals/jpeg/jpeg_decode/main/Kconfig.projbuild +++ b/examples/peripherals/jpeg/jpeg_decode/main/Kconfig.projbuild @@ -6,4 +6,13 @@ menu "JPEG Decode Example menu" help If this config item is set, format_if_mount_failed will be set to true and the card will be formatted if the mount has failed. + + config EXAMPLE_SDMMC_IO_POWER_INTERNAL_LDO + depends on SOC_SDMMC_IO_POWER_EXTERNAL + bool "SDMMC IO power supply comes from internal LDO (READ HELP!)" + default y + help + Please read the schematic first and check if the SDMMC VDD is connected to any internal LDO output. + If the SDMMC is powered by an external supplier, unselect me + endmenu diff --git a/examples/peripherals/jpeg/jpeg_decode/main/jpeg_decode_main.c b/examples/peripherals/jpeg/jpeg_decode/main/jpeg_decode_main.c index 6d467f337e..e5f0243bf8 100644 --- a/examples/peripherals/jpeg/jpeg_decode/main/jpeg_decode_main.c +++ b/examples/peripherals/jpeg/jpeg_decode/main/jpeg_decode_main.c @@ -11,6 +11,7 @@ #include "driver/sdmmc_host.h" #include "esp_attr.h" #include "driver/jpeg_decode.h" +#include "sd_pwr_ctrl_by_on_chip_ldo.h" static const char *TAG = "jpeg.example"; static sdmmc_card_t *s_card; @@ -38,6 +39,21 @@ static esp_err_t sdcard_init(void) sdmmc_host_t host = SDMMC_HOST_DEFAULT(); host.max_freq_khz = SDMMC_FREQ_HIGHSPEED; + +#if CONFIG_EXAMPLE_SDMMC_IO_POWER_INTERNAL_LDO + sd_pwr_ctrl_ldo_config_t ldo_config = { + .ldo_chan_id = 4, // `LDO_VO4` is used as the SDMMC IO power + }; + sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; + + ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to new an on-chip ldo power control driver"); + return ret; + } + host.pwr_ctrl_handle = pwr_ctrl_handle; +#endif + // This initializes the slot without card detect (CD) and write protect (WP) signals. // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); @@ -65,6 +81,13 @@ static void sdcard_deinit(void) { const char mount_point[] = MOUNT_POINT; esp_vfs_fat_sdcard_unmount(mount_point, s_card); +#if SOC_SDMMC_IO_POWER_EXTERNAL + esp_err_t ret = sd_pwr_ctrl_del_on_chip_ldo(s_card->host.pwr_ctrl_handle); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to delete on-chip ldo power control driver"); + return; + } +#endif } void app_main(void) diff --git a/examples/peripherals/jpeg/jpeg_encode/main/Kconfig.projbuild b/examples/peripherals/jpeg/jpeg_encode/main/Kconfig.projbuild index af809cf149..7677cd73bd 100644 --- a/examples/peripherals/jpeg/jpeg_encode/main/Kconfig.projbuild +++ b/examples/peripherals/jpeg/jpeg_encode/main/Kconfig.projbuild @@ -6,4 +6,13 @@ menu "JPEG Encode Example menu" help If this config item is set, format_if_mount_failed will be set to true and the card will be formatted if the mount has failed. + + config EXAMPLE_SDMMC_IO_POWER_INTERNAL_LDO + depends on SOC_SDMMC_IO_POWER_EXTERNAL + bool "SDMMC IO power supply comes from internal LDO (READ HELP!)" + default y + help + Please read the schematic first and check if the SDMMC VDD is connected to any internal LDO output. + If the SDMMC is powered by an external supplier, unselect me + endmenu diff --git a/examples/peripherals/jpeg/jpeg_encode/main/jpeg_encode_main.c b/examples/peripherals/jpeg/jpeg_encode/main/jpeg_encode_main.c index 8ee0a49a86..cc38e62b8b 100644 --- a/examples/peripherals/jpeg/jpeg_encode/main/jpeg_encode_main.c +++ b/examples/peripherals/jpeg/jpeg_encode/main/jpeg_encode_main.c @@ -10,6 +10,7 @@ #include "sdmmc_cmd.h" #include "driver/sdmmc_host.h" #include "driver/jpeg_encode.h" +#include "sd_pwr_ctrl_by_on_chip_ldo.h" static const char *TAG = "jpeg.example"; static sdmmc_card_t *s_card; @@ -35,6 +36,21 @@ static esp_err_t sdcard_init(void) sdmmc_host_t host = SDMMC_HOST_DEFAULT(); host.max_freq_khz = SDMMC_FREQ_HIGHSPEED; + +#if CONFIG_EXAMPLE_SDMMC_IO_POWER_INTERNAL_LDO + sd_pwr_ctrl_ldo_config_t ldo_config = { + .ldo_chan_id = 4, // `LDO_VO4` is used as the SDMMC IO power + }; + sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; + + ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to new an on-chip ldo power control driver"); + return ret; + } + host.pwr_ctrl_handle = pwr_ctrl_handle; +#endif + // This initializes the slot without card detect (CD) and write protect (WP) signals. // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); @@ -62,6 +78,13 @@ static void sdcard_deinit(void) { const char mount_point[] = MOUNT_POINT; esp_vfs_fat_sdcard_unmount(mount_point, s_card); +#if SOC_SDMMC_IO_POWER_EXTERNAL + esp_err_t ret = sd_pwr_ctrl_del_on_chip_ldo(s_card->host.pwr_ctrl_handle); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to delete on-chip ldo power control driver"); + return; + } +#endif } void app_main(void)