From 938c77ebeab617f4488eb65f58cd7713856ad765 Mon Sep 17 00:00:00 2001 From: Armando Date: Tue, 26 Nov 2024 17:43:52 +0800 Subject: [PATCH] change(sdmmc): allow speciying pins for IOMUX slots as well --- .../include/driver/sdmmc_default_configs.h | 23 +++++++++++-------- .../include/driver/sdmmc_host.h | 2 -- components/esp_driver_sdmmc/src/sdmmc_host.c | 12 +++++++++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/components/esp_driver_sdmmc/include/driver/sdmmc_default_configs.h b/components/esp_driver_sdmmc/include/driver/sdmmc_default_configs.h index add6c4c859..1f6fbee7d0 100644 --- a/components/esp_driver_sdmmc/include/driver/sdmmc_default_configs.h +++ b/components/esp_driver_sdmmc/include/driver/sdmmc_default_configs.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -53,23 +53,28 @@ extern "C" { #define SDMMC_SLOT_NO_WP GPIO_NUM_NC ///< indicates that write protect line is not used #define SDMMC_SLOT_WIDTH_DEFAULT 0 ///< use the maximum possible width for the slot -#if SOC_SDMMC_USE_IOMUX && !SOC_SDMMC_USE_GPIO_MATRIX /** * Macro defining default configuration of SDMMC host slot */ +#if CONFIG_IDF_TARGET_ESP32 #define SDMMC_SLOT_CONFIG_DEFAULT() {\ + .clk = GPIO_NUM_6, \ + .cmd = GPIO_NUM_11, \ + .d0 = GPIO_NUM_7, \ + .d1 = GPIO_NUM_8, \ + .d2 = GPIO_NUM_9, \ + .d3 = GPIO_NUM_10, \ + .d4 = GPIO_NUM_16, \ + .d5 = GPIO_NUM_17, \ + .d6 = GPIO_NUM_5, \ + .d7 = GPIO_NUM_18, \ .cd = SDMMC_SLOT_NO_CD, \ .wp = SDMMC_SLOT_NO_WP, \ .width = SDMMC_SLOT_WIDTH_DEFAULT, \ .flags = 0, \ } -#else - -/** - * Macro defining default configuration of SDMMC host slot - */ -#if CONFIG_IDF_TARGET_ESP32P4 +#elif CONFIG_IDF_TARGET_ESP32P4 #define SDMMC_SLOT_CONFIG_DEFAULT() {\ .clk = GPIO_NUM_43, \ .cmd = GPIO_NUM_44, \ @@ -106,8 +111,6 @@ extern "C" { } #endif // GPIO Matrix chips -#endif - #ifdef __cplusplus } #endif diff --git a/components/esp_driver_sdmmc/include/driver/sdmmc_host.h b/components/esp_driver_sdmmc/include/driver/sdmmc_host.h index e596835005..2b6059d023 100644 --- a/components/esp_driver_sdmmc/include/driver/sdmmc_host.h +++ b/components/esp_driver_sdmmc/include/driver/sdmmc_host.h @@ -24,7 +24,6 @@ extern "C" { * Extra configuration for SDMMC peripheral slot */ typedef struct { -#ifdef SOC_SDMMC_USE_GPIO_MATRIX gpio_num_t clk; ///< GPIO number of CLK signal. gpio_num_t cmd; ///< GPIO number of CMD signal. gpio_num_t d0; ///< GPIO number of D0 signal. @@ -35,7 +34,6 @@ typedef struct { gpio_num_t d5; ///< GPIO number of D5 signal. Ignored in 1- or 4- line mode. gpio_num_t d6; ///< GPIO number of D6 signal. Ignored in 1- or 4- line mode. gpio_num_t d7; ///< GPIO number of D7 signal. Ignored in 1- or 4- line mode. -#endif // SOC_SDMMC_USE_GPIO_MATRIX union { gpio_num_t gpio_cd; ///< GPIO number of card detect signal gpio_num_t cd; ///< GPIO number of card detect signal; shorter name. diff --git a/components/esp_driver_sdmmc/src/sdmmc_host.c b/components/esp_driver_sdmmc/src/sdmmc_host.c index 2362e03028..848d7c1d35 100644 --- a/components/esp_driver_sdmmc/src/sdmmc_host.c +++ b/components/esp_driver_sdmmc/src/sdmmc_host.c @@ -544,7 +544,17 @@ esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t *slot_config) if (slot == 0) { #if !SDMMC_LL_SLOT_SUPPORT_GPIO_MATRIX(0) - ESP_RETURN_ON_FALSE(!use_gpio_matrix, ESP_ERR_INVALID_ARG, TAG, "doesn't support routing from GPIO matrix, driver uses dedicated IOs"); + if (use_gpio_matrix && + SDMMC_SLOT0_IOMUX_PIN_NUM_CLK == slot_config->clk && + SDMMC_SLOT0_IOMUX_PIN_NUM_CMD == slot_config->cmd && + SDMMC_SLOT0_IOMUX_PIN_NUM_D0 == slot_config->d0 && + SDMMC_SLOT0_IOMUX_PIN_NUM_D1 == slot_config->d1 && + SDMMC_SLOT0_IOMUX_PIN_NUM_D2 == slot_config->d2 && + SDMMC_SLOT0_IOMUX_PIN_NUM_D3 == slot_config->d3) { + use_gpio_matrix = false; + } else { + ESP_RETURN_ON_FALSE(!use_gpio_matrix, ESP_ERR_INVALID_ARG, TAG, "doesn't support routing from GPIO matrix, driver uses dedicated IOs"); + } #endif } else { #if !SDMMC_LL_SLOT_SUPPORT_GPIO_MATRIX(1)