From 6ee5a1e49267a70e6fede6e2f9b8bc276be3f8f8 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 2 Mar 2017 17:18:44 +1100 Subject: [PATCH] sdmmc: Use slot width as default slot_config width parameter, instead of 4 Ref #361 https://github.com/espressif/esp-idf/pull/361 --- components/driver/include/driver/sdmmc_host.h | 3 ++- components/driver/sdmmc_host.c | 10 +++++++--- docs/api/storage/sdmmc.rst | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/components/driver/include/driver/sdmmc_host.h b/components/driver/include/driver/sdmmc_host.h index f9f4f7d377..dc3e9ef6bf 100644 --- a/components/driver/include/driver/sdmmc_host.h +++ b/components/driver/include/driver/sdmmc_host.h @@ -55,6 +55,7 @@ typedef struct { #define SDMMC_SLOT_NO_CD ((gpio_num_t) -1) ///< indicates that card detect line is not used #define SDMMC_SLOT_NO_WP ((gpio_num_t) -1) ///< indicates that write protect line is not used +#define SDMMC_SLOT_WIDTH_DEFAULT 0 ///< use the default width for the slot (8 for slot 0, 4 for slot 1) /** * Macro defining default configuration of SDMMC host slot @@ -62,7 +63,7 @@ typedef struct { #define SDMMC_SLOT_CONFIG_DEFAULT() {\ .gpio_cd = SDMMC_SLOT_NO_CD, \ .gpio_wp = SDMMC_SLOT_NO_WP, \ - .width = 4, \ + .width = SDMMC_SLOT_WIDTH_DEFAULT, \ } /** diff --git a/components/driver/sdmmc_host.c b/components/driver/sdmmc_host.c index 54c7997b0a..706a1e3fef 100644 --- a/components/driver/sdmmc_host.c +++ b/components/driver/sdmmc_host.c @@ -299,22 +299,26 @@ esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t* slot_config) } int gpio_cd = slot_config->gpio_cd; int gpio_wp = slot_config->gpio_wp; + uint8_t slot_width = slot_config->width; // Configure pins const sdmmc_slot_info_t* pslot = &s_slot_info[slot]; - if (slot_config->width > pslot->width) { + if (slot_width == SDMMC_SLOT_WIDTH_DEFAULT) { + slot_width = pslot->width; + } + else if (slot_width > pslot->width) { return ESP_ERR_INVALID_ARG; } configure_pin(pslot->clk); configure_pin(pslot->cmd); configure_pin(pslot->d0); - if (slot_config->width >= 4) { + if (slot_width >= 4) { configure_pin(pslot->d1); configure_pin(pslot->d2); configure_pin(pslot->d3); - if (slot_config->width == 8) { + if (slot_width == 8) { configure_pin(pslot->d4); configure_pin(pslot->d5); configure_pin(pslot->d6); diff --git a/docs/api/storage/sdmmc.rst b/docs/api/storage/sdmmc.rst index fe2e5c27f8..4ea2f62606 100644 --- a/docs/api/storage/sdmmc.rst +++ b/docs/api/storage/sdmmc.rst @@ -79,6 +79,7 @@ Of all the funtions listed below, only ``sdmmc_host_init``, ``sdmmc_host_init_sl .. doxygendefine:: SDMMC_HOST_SLOT_0 .. doxygendefine:: SDMMC_HOST_SLOT_1 .. doxygendefine:: SDMMC_HOST_DEFAULT +.. doxygendefine:: SDMMC_SLOT_WIDTH_DEFAULT .. doxygenfunction:: sdmmc_host_init_slot -- 2.40.0