]> granicus.if.org Git - esp-idf/commitdiff
feature(sdio): allow to enable internal pullups of the SDIO host and slave as a debug...
authormichael <xiaoxufeng@espressif.com>
Fri, 25 May 2018 11:44:53 +0000 (19:44 +0800)
committermichael <xiaoxufeng@espressif.com>
Thu, 14 Jun 2018 04:04:22 +0000 (12:04 +0800)
NOTE: the internal pullups are not totally reliable, please do add external pullups on your bus.

13 files changed:
components/driver/include/driver/sdio_slave.h
components/driver/include/driver/sdmmc_host.h
components/driver/sdio_slave.c
components/driver/sdmmc_host.c
components/driver/sdmmc_private.h
components/driver/sdmmc_transaction.c
components/driver/sdspi_transaction.c
components/soc/esp32/include/soc/sdio_slave_pins.h [new file with mode: 0644]
components/soc/esp32/include/soc/sdmmc_pins.h [new file with mode: 0644]
components/soc/esp32/sdio_slave_periph.c [new file with mode: 0644]
components/soc/esp32/sdmmc_periph.c [new file with mode: 0644]
components/soc/include/soc/sdio_slave_periph.h [new file with mode: 0644]
components/soc/include/soc/sdmmc_periph.h [new file with mode: 0644]

index 66b3bc5e21df06fd012297ddf1e180b737bc33eb..ed0767b4926a3540ad55c76dc86e4179d9318433 100644 (file)
@@ -20,7 +20,7 @@
 #include "esp_err.h"
 #include "rom/queue.h"
 
-#include "soc/host_reg.h"
+#include "soc/sdio_slave_periph.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -71,6 +71,23 @@ typedef struct {
                             ///< All data that do not fully fill a buffer is still counted as one buffer. E.g. 10 bytes data costs 2 buffers if the size is 8 bytes per buffer.
                             ///< Buffer size of the slave pre-defined between host and slave before communication. All receive buffer given to the driver should be larger than this.
     sdio_event_cb_t     event_cb;           ///< when the host interrupts slave, this callback will be called with interrupt number (0-7).
+    uint32_t            flags; ///< Features to be enabled for the slave, combinations of ``SDIO_SLAVE_FLAG_*``.
+#define SDIO_SLAVE_FLAG_DAT2_DISABLED       BIT(0)      /**< It is required by the SD specification that all 4 data 
+        lines should be used and pulled up even in 1-bit mode or SPI mode. However, as a feature, the user can speicfy 
+        this flag to make use of DAT2 pin in 1-bit mode. Note that the host cannot read CCCR registers to know we don't 
+        support 4-bit mode anymore, please do this at your own risk.
+        */
+#define SDIO_SLAVE_FLAG_HOST_INTR_DISABLED  BIT(1)      /**< The DAT1 line is used as the interrupt line in SDIO        
+        protocol. However, as a feature, the user can speicfy this flag to make use of DAT1 pin of the slave in 1-bit 
+        mode. Note that the host has to do polling to the interrupt registers to know whether there are interrupts from
+        the slave. And it cannot read CCCR registers to know we don't support 4-bit mode anymore, please do this at 
+        your own risk.
+        */
+#define SDIO_SLAVE_FLAG_INTERNAL_PULLUP     BIT(2)      /**< Enable internal pullups for enabled pins. It is required 
+        by the SD specification that all the 4 data lines should be pulled up even in 1-bit mode or SPI mode. Note that 
+        the internal pull-ups are not sufficient for stable communication, please do connect external pull-ups on the 
+        bus. This is only for example and debug use.
+        */
 } sdio_slave_config_t;
 
 /** Handle of a receive buffer, register a handle by calling ``sdio_slave_recv_register_buf``. Use the handle to load the buffer to the
index 2c610ad365744ec0f83a524fda198fd2ae3f6700..f57b959cc73a7a22de02c515a7f524025f6a4806 100644 (file)
@@ -55,6 +55,12 @@ typedef struct {
     gpio_num_t gpio_cd;     ///< GPIO number of card detect signal
     gpio_num_t gpio_wp;     ///< GPIO number of write protect signal
     uint8_t width;          ///< Bus width used by the slot (might be less than the max width supported)
+    uint32_t flags;         ///< Features used by this slot
+#define SDMMC_SLOT_FLAG_INTERNAL_PULLUP  BIT(0) 
+        /**< Enable internal pullups on enabled pins. The internal pullups
+         are insufficient however, please make sure external pullups are
+         connected on the bus. This is for debug / example purpose only.
+         */
 } sdmmc_slot_config_t;
 
 #define SDMMC_SLOT_NO_CD      ((gpio_num_t) -1)     ///< indicates that card detect line is not used
@@ -68,6 +74,7 @@ typedef struct {
     .gpio_cd = SDMMC_SLOT_NO_CD, \
     .gpio_wp = SDMMC_SLOT_NO_WP, \
     .width   = SDMMC_SLOT_WIDTH_DEFAULT, \
+    .flags = 0, \
 }
 
 /**
@@ -199,6 +206,23 @@ esp_err_t sdmmc_host_io_int_wait(int slot, TickType_t timeout_ticks);
  */
 esp_err_t sdmmc_host_deinit();
 
+/**
+ * @brief Enable the pull-ups of sd pins.
+ * 
+ * @note You should always place actual pullups on the lines instead of using
+ * this function. Internal pullup resistance are high and not sufficient, may
+ * cause instability in products. This is for debug or examples only.
+ * 
+ * @param slot Slot to use, normally set it to 1.
+ * @param width Bit width of your configuration, 1 or 4.
+ * 
+ * @return
+ *      - ESP_OK: if success
+ *      - ESP_ERR_INVALID_ARG: if configured width larger than maximum the slot can
+ *              support
+ */
+esp_err_t sdmmc_host_pullup_en(int slot, int width);
+
 #ifdef __cplusplus
 }
 #endif
index 1727e4349c87ca5ab3baa39f02f34bb46538a3e6..8402878deaffd5ed56752992247e0371ab1670fe 100644 (file)
@@ -86,10 +86,7 @@ The driver of FIFOs works as below:
 
 #include <string.h>
 #include "driver/sdio_slave.h"
-#include "soc/slc_struct.h"
-#include "soc/slc_reg.h"
-#include "soc/host_struct.h"
-#include "soc/hinf_struct.h"
+#include "soc/sdio_slave_periph.h"
 #include "rom/lldesc.h"
 #include "esp_log.h"
 #include "esp_intr_alloc.h"
@@ -119,41 +116,6 @@ typedef enum {
     STATE_SENDING = 3,
 } send_state_t;
 
-typedef struct {
-    uint32_t clk;
-    uint32_t cmd;
-    uint32_t d0;
-    uint32_t d1;
-    uint32_t d2;
-    uint32_t d3;
-    int      func;
-} sdio_slave_slot_info_t ;
-
-// I/O slot of sdio slave:
-// 0: GPIO 6, 11, 7, 8, 9, 10,
-// 1: GPIO 14, 15, 2, 4, 12, 13 for CLK, CMD, D0, D1, D2, D3 respectively.
-// only one peripheral for SDIO and only one slot can work at the same time.
-// currently slot 0 is occupied by SPI for flash
-static const sdio_slave_slot_info_t s_slot_info[2]  = {
-    {
-        .clk = PERIPHS_IO_MUX_SD_CLK_U,
-        .cmd = PERIPHS_IO_MUX_SD_CMD_U,
-        .d0 = PERIPHS_IO_MUX_SD_DATA0_U,
-        .d1 = PERIPHS_IO_MUX_SD_DATA1_U,
-        .d2 = PERIPHS_IO_MUX_SD_DATA2_U,
-        .d3 = PERIPHS_IO_MUX_SD_DATA3_U,
-        .func = 0,
-    }, {
-        .clk = PERIPHS_IO_MUX_MTMS_U,
-        .cmd = PERIPHS_IO_MUX_MTDO_U,
-        .d0 = PERIPHS_IO_MUX_GPIO2_U,
-        .d1 = PERIPHS_IO_MUX_GPIO4_U,
-        .d2 = PERIPHS_IO_MUX_MTDI_U,
-        .d3 = PERIPHS_IO_MUX_MTCK_U,
-        .func = 4,
-    },
-};
-
 // first 3 WORDs of this struct is defined by and compatible to the DMA link list format.
 // sdio_slave_buf_handle_t is of type buf_desc_t*;
 typedef struct  buf_desc_s{
@@ -499,13 +461,21 @@ no_mem:
     return ESP_ERR_NO_MEM;
 }
 
-static inline void configure_pin(uint32_t io_mux_reg, uint32_t func)
+static void configure_pin(int pin, uint32_t func, bool pullup)
 {
     const int sdmmc_func = func;
     const int drive_strength = 3;
-    PIN_INPUT_ENABLE(io_mux_reg);
-    PIN_FUNC_SELECT(io_mux_reg, sdmmc_func);
-    PIN_SET_DRV(io_mux_reg, drive_strength);
+    assert(pin!=-1);
+    uint32_t reg = GPIO_PIN_MUX_REG[pin];
+    assert(reg!=UINT32_MAX);
+
+    PIN_INPUT_ENABLE(reg);
+    PIN_FUNC_SELECT(reg, sdmmc_func);
+    PIN_SET_DRV(reg, drive_strength);
+    if (pullup) {
+        gpio_pullup_en(pin);
+        gpio_pulldown_dis(pin);
+    }
 }
 
 static inline esp_err_t sdio_slave_hw_init(sdio_slave_config_t *config)
@@ -514,13 +484,20 @@ static inline esp_err_t sdio_slave_hw_init(sdio_slave_config_t *config)
     SLC.slc0_int_ena.val = 0;
 
     //initialize pin
-    const sdio_slave_slot_info_t *slot = &s_slot_info[1];
-    configure_pin(slot->clk, slot->func);
-    configure_pin(slot->cmd, slot->func);
-    configure_pin(slot->d0, slot->func);
-    configure_pin(slot->d1, slot->func);
-    configure_pin(slot->d2, slot->func);
-    configure_pin(slot->d3, slot->func);
+    const sdio_slave_slot_info_t *slot = &sdio_slave_slot_info[1];
+
+    bool pullup = config->flags & SDIO_SLAVE_FLAG_INTERNAL_PULLUP;
+    configure_pin(slot->clk_gpio, slot->func, false);   //clk doesn't need a pullup
+    configure_pin(slot->cmd_gpio, slot->func, pullup);
+    configure_pin(slot->d0_gpio, slot->func, pullup);
+    if ((config->flags & SDIO_SLAVE_FLAG_HOST_INTR_DISABLED)==0) {
+        configure_pin(slot->d1_gpio, slot->func, pullup);
+    } 
+    if ((config->flags & SDIO_SLAVE_FLAG_DAT2_DISABLED)==0) {
+       configure_pin(slot->d2_gpio, slot->func, pullup); 
+    }
+    configure_pin(slot->d3_gpio, slot->func, pullup);
+
     //enable module and config
     periph_module_reset(PERIPH_SDIO_SLAVE_MODULE);
     periph_module_enable(PERIPH_SDIO_SLAVE_MODULE);
index 95cb81fdcfda2b7c70bd62abf4b21f5e387ee9bf..0887e04293c8b30c072ababd4d47e5a1c0d03e3c 100644 (file)
 #include <sys/param.h>
 #include "esp_log.h"
 #include "esp_intr_alloc.h"
-#include "soc/sdmmc_struct.h"
-#include "soc/sdmmc_reg.h"
 #include "soc/io_mux_reg.h"
-#include "soc/gpio_sig_map.h"
 #include "rom/gpio.h"
 #include "driver/gpio.h"
 #include "driver/sdmmc_host.h"
 #include "driver/periph_ctrl.h"
 #include "sdmmc_private.h"
 #include "freertos/semphr.h"
+#include "soc/sdmmc_periph.h"
 
 #define SDMMC_EVENT_QUEUE_LENGTH 32
 
-typedef struct {
-    uint32_t clk;
-    uint32_t cmd;
-    uint32_t d0;
-    uint32_t d1;
-    uint32_t d2;
-    uint32_t d3;
-    uint32_t d4;
-    uint32_t d5;
-    uint32_t d6;
-    uint32_t d7;
-    uint8_t d1_gpio;
-    uint8_t d3_gpio;
-    uint8_t card_detect;
-    uint8_t write_protect;
-    uint8_t card_int;
-    uint8_t width;
-} sdmmc_slot_info_t;
-
 
 static void sdmmc_isr(void* arg);
 static void sdmmc_host_dma_init();
 
-static const sdmmc_slot_info_t s_slot_info[2]  = {
-    {
-        .clk = PERIPHS_IO_MUX_SD_CLK_U,
-        .cmd = PERIPHS_IO_MUX_SD_CMD_U,
-        .d0 = PERIPHS_IO_MUX_SD_DATA0_U,
-        .d1 = PERIPHS_IO_MUX_SD_DATA1_U,
-        .d2 = PERIPHS_IO_MUX_SD_DATA2_U,
-        .d3 = PERIPHS_IO_MUX_SD_DATA3_U,
-        .d1_gpio = 8,
-        .d3_gpio = 10,
-        .d4 = PERIPHS_IO_MUX_GPIO16_U,
-        .d5 = PERIPHS_IO_MUX_GPIO17_U,
-        .d6 = PERIPHS_IO_MUX_GPIO5_U,
-        .d7 = PERIPHS_IO_MUX_GPIO18_U,
-        .card_detect = HOST_CARD_DETECT_N_1_IDX,
-        .write_protect = HOST_CARD_WRITE_PRT_1_IDX,
-        .card_int = HOST_CARD_INT_N_1_IDX,
-        .width = 8
-    },
-    {
-        .clk = PERIPHS_IO_MUX_MTMS_U,
-        .cmd = PERIPHS_IO_MUX_MTDO_U,
-        .d0 = PERIPHS_IO_MUX_GPIO2_U,
-        .d1 = PERIPHS_IO_MUX_GPIO4_U,
-        .d2 = PERIPHS_IO_MUX_MTDI_U,
-        .d3 = PERIPHS_IO_MUX_MTCK_U,
-        .d1_gpio = 4,
-        .d3_gpio = 13,
-        .card_detect = HOST_CARD_DETECT_N_2_IDX,
-        .write_protect = HOST_CARD_WRITE_PRT_2_IDX,
-        .card_int = HOST_CARD_INT_N_2_IDX,
-        .width = 4
-    }
-};
 
 static const char* TAG = "sdmmc_periph";
 static intr_handle_t s_intr_handle;
@@ -340,18 +285,24 @@ esp_err_t sdmmc_host_init()
     return ESP_OK;
 }
 
-
-static inline void configure_pin(uint32_t io_mux_reg)
+static void configure_pin(int pin)
 {
     const int sdmmc_func = 3;
     const int drive_strength = 3;
-    PIN_INPUT_ENABLE(io_mux_reg);
-    PIN_FUNC_SELECT(io_mux_reg, sdmmc_func);
-    PIN_SET_DRV(io_mux_reg, drive_strength);
+    assert(pin!=-1);
+    uint32_t reg = GPIO_PIN_MUX_REG[pin];
+    assert(reg != UINT32_MAX);
+    PIN_INPUT_ENABLE(reg);
+    PIN_FUNC_SELECT(reg, sdmmc_func);
+    PIN_SET_DRV(reg, drive_strength);
 }
 
 esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t* slot_config)
 {
+    bool pullup = slot_config->flags & SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
+    if (pullup) {
+        sdmmc_host_pullup_en(slot, slot_config->width);
+    }
     if (!s_intr_handle) {
         return ESP_ERR_INVALID_STATE;
     }
@@ -366,7 +317,7 @@ esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t* slot_config)
     uint8_t slot_width = slot_config->width;
 
     // Configure pins
-    const sdmmc_slot_info_t* pslot = &s_slot_info[slot];
+    const sdmmc_slot_info_t* pslot = &sdmmc_slot_info[slot];
 
     if (slot_width == SDMMC_SLOT_WIDTH_DEFAULT) {
         slot_width = pslot->width;
@@ -376,13 +327,13 @@ esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t* slot_config)
     }
     s_slot_width[slot] = slot_width;
 
-    configure_pin(pslot->clk);
-    configure_pin(pslot->cmd);
-    configure_pin(pslot->d0);
+    configure_pin(pslot->clk_gpio);
+    configure_pin(pslot->cmd_gpio);
+    configure_pin(pslot->d0_gpio);
 
     if (slot_width >= 4) {
-        configure_pin(pslot->d1);
-        configure_pin(pslot->d2);
+        configure_pin(pslot->d1_gpio);
+        configure_pin(pslot->d2_gpio);
         //force pull-up D3 to make slave detect SD mode. connect to peripheral after width configuration.
         gpio_config_t gpio_conf = {
             .pin_bit_mask = BIT(pslot->d3_gpio),
@@ -394,10 +345,10 @@ esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t* slot_config)
         gpio_config( &gpio_conf );
         gpio_set_level( pslot->d3_gpio, 1 );
         if (slot_width == 8) {
-            configure_pin(pslot->d4);
-            configure_pin(pslot->d5);
-            configure_pin(pslot->d6);
-            configure_pin(pslot->d7);
+            configure_pin(pslot->d4_gpio);
+            configure_pin(pslot->d5_gpio);
+            configure_pin(pslot->d6_gpio);
+            configure_pin(pslot->d7_gpio);
         }
     }
 
@@ -482,7 +433,7 @@ esp_err_t sdmmc_host_set_bus_width(int slot, size_t width)
     if (!(slot == 0 || slot == 1)) {
         return ESP_ERR_INVALID_ARG;
     }
-    if (s_slot_info[slot].width < width) {
+    if (sdmmc_slot_info[slot].width < width) {
         return ESP_ERR_INVALID_ARG;
     }
     const uint16_t mask = BIT(slot);
@@ -492,10 +443,10 @@ esp_err_t sdmmc_host_set_bus_width(int slot, size_t width)
     } else if (width == 4) {
         SDMMC.ctype.card_width_8 &= ~mask;
         SDMMC.ctype.card_width |= mask;
-        configure_pin(s_slot_info[slot].d3);   // D3 was set to GPIO high to force slave into SD 1-bit mode, until 4-bit mode is set
+        configure_pin(sdmmc_slot_info[slot].d3_gpio);   // D3 was set to GPIO high to force slave into SD 1-bit mode, until 4-bit mode is set
     } else if (width == 8){
         SDMMC.ctype.card_width_8 |= mask;
-        configure_pin(s_slot_info[slot].d3);   // D3 was set to GPIO high to force slave into SD 1-bit mode, until 4-bit mode is set
+        configure_pin(sdmmc_slot_info[slot].d3_gpio);   // D3 was set to GPIO high to force slave into SD 1-bit mode, until 4-bit mode is set
     } else {
         return ESP_ERR_INVALID_ARG;
     }
@@ -550,7 +501,7 @@ void sdmmc_host_dma_resume()
 
 esp_err_t sdmmc_host_io_int_enable(int slot)
 {
-    configure_pin(s_slot_info[slot].d1);
+    configure_pin(sdmmc_slot_info[slot].d1_gpio);
     return ESP_OK;
 }
 
@@ -566,7 +517,7 @@ esp_err_t sdmmc_host_io_int_wait(int slot, TickType_t timeout_ticks)
 
     SDMMC.intmask.sdio &= ~BIT(slot);   /* Disable SDIO interrupt */
     SDMMC.rintsts.sdio = BIT(slot);
-    if (gpio_get_level(s_slot_info[slot].d1_gpio) == 0) {
+    if (gpio_get_level(sdmmc_slot_info[slot].d1_gpio) == 0) {
         return ESP_OK;
     }
     /* Otherwise, need to wait for an interrupt. Since D1 was high,
@@ -627,3 +578,34 @@ static void sdmmc_isr(void* arg) {
     }
 }
 
+esp_err_t sdmmc_host_pullup_en(int slot, int width)
+{
+    if (width > sdmmc_slot_info[slot].width) {
+        //in esp32 we only support 8 bit in slot 0, note this is occupied by the flash by default
+        return ESP_ERR_INVALID_ARG;
+    }
+    //according to the spec, the host control the clk, we don't to pull it up here
+    gpio_pullup_en(sdmmc_slot_info[slot].cmd_gpio);
+    gpio_pulldown_dis(sdmmc_slot_info[slot].cmd_gpio);
+    gpio_pullup_en(sdmmc_slot_info[slot].d0_gpio);
+    gpio_pulldown_dis(sdmmc_slot_info[slot].d0_gpio);
+    if (width >= 4) {
+        gpio_pullup_en(sdmmc_slot_info[slot].d1_gpio);
+        gpio_pulldown_dis(sdmmc_slot_info[slot].d1_gpio);
+        gpio_pullup_en(sdmmc_slot_info[slot].d2_gpio);
+        gpio_pulldown_dis(sdmmc_slot_info[slot].d2_gpio);
+        gpio_pullup_en(sdmmc_slot_info[slot].d3_gpio);
+        gpio_pulldown_dis(sdmmc_slot_info[slot].d3_gpio);
+    }
+    if (width == 8) {
+        gpio_pullup_en(sdmmc_slot_info[slot].d4_gpio);
+        gpio_pulldown_dis(sdmmc_slot_info[slot].d4_gpio);
+        gpio_pullup_en(sdmmc_slot_info[slot].d5_gpio);
+        gpio_pulldown_dis(sdmmc_slot_info[slot].d5_gpio);
+        gpio_pullup_en(sdmmc_slot_info[slot].d6_gpio);
+        gpio_pulldown_dis(sdmmc_slot_info[slot].d6_gpio);
+        gpio_pullup_en(sdmmc_slot_info[slot].d7_gpio);
+        gpio_pulldown_dis(sdmmc_slot_info[slot].d7_gpio);
+    }
+    return ESP_OK;
+}
\ No newline at end of file
index 5a10a3b672dfeff9848c83fc78ad9a6d29a45ca9..8f0aab78b2b056e9a8d15eda481359f3b2508b15 100644 (file)
@@ -19,7 +19,7 @@
 #include "esp_err.h"
 #include "freertos/FreeRTOS.h"
 #include "freertos/queue.h"
-#include "soc/sdmmc_struct.h"
+#include "soc/sdmmc_periph.h"
 
 typedef struct {
     uint32_t sdmmc_status;      ///< masked SDMMC interrupt status
index 8abf9bb923e94e588ea9462329930261685ffc43..495d3d4a158488be061dcee8d01f2bd03a3012a4 100644 (file)
@@ -19,8 +19,7 @@
 #include "freertos/FreeRTOS.h"
 #include "freertos/queue.h"
 #include "freertos/semphr.h"
-#include "soc/sdmmc_reg.h"
-#include "soc/sdmmc_struct.h"
+#include "soc/sdmmc_periph.h"
 #include "soc/soc_memory_layout.h"
 #include "driver/sdmmc_types.h"
 #include "driver/sdmmc_defs.h"
index 4b9c695846f40d4c517c9c71f49218a88afd8bc6..d25521deaa7d111b356b4f92fa71d57e0057c25d 100644 (file)
@@ -17,7 +17,7 @@
 #include "esp_log.h"
 #include "sys/lock.h"
 #include "soc/sdmmc_reg.h"
-#include "soc/sdmmc_struct.h"
+#include "soc/sdmmc_periph.h"
 #include "driver/sdmmc_types.h"
 #include "driver/sdmmc_defs.h"
 #include "driver/sdmmc_host.h"
diff --git a/components/soc/esp32/include/soc/sdio_slave_pins.h b/components/soc/esp32/include/soc/sdio_slave_pins.h
new file mode 100644 (file)
index 0000000..968f194
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+\r
+//     http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+#ifndef _SOC_SDIO_SLAVE_PINS_H_\r
+#define _SOC_SDIO_SLAVE_PINS_H_\r
+\r
+#define SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_CLK  6\r
+#define SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_CMD  11\r
+#define SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_D0   7\r
+#define SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_D1   8\r
+#define SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_D2   9\r
+#define SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_D3   10\r
+#define SDIO_SLAVE_SLOT0_FUNC               0\r
+\r
+#define SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_CLK  14\r
+#define SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_CMD  15\r
+#define SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_D0   2\r
+#define SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_D1   4\r
+#define SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_D2   12\r
+#define SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_D3   13\r
+#define SDIO_SLAVE_SLOT1_FUNC               4\r
+\r
+#endif /* _SOC_SDIO_SLAVE_PINS_H_ */
\ No newline at end of file
diff --git a/components/soc/esp32/include/soc/sdmmc_pins.h b/components/soc/esp32/include/soc/sdmmc_pins.h
new file mode 100644 (file)
index 0000000..9a37ad0
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+\r
+//     http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+#ifndef _SOC_SDMMC_PINS_H_\r
+#define _SOC_SDMMC_PINS_H_\r
+\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_CLK  6\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_CMD  11\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_D0   7\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_D1   8\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_D2   9\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_D3   10\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_D4   16\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_D5   17\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_D6   5\r
+#define SDMMC_SLOT0_IOMUX_PIN_NUM_D7   18\r
+#define SDMMC_SLOT0_FUNC               0\r
+\r
+#define SDMMC_SLOT1_IOMUX_PIN_NUM_CLK  14\r
+#define SDMMC_SLOT1_IOMUX_PIN_NUM_CMD  15\r
+#define SDMMC_SLOT1_IOMUX_PIN_NUM_D0   2\r
+#define SDMMC_SLOT1_IOMUX_PIN_NUM_D1   4\r
+#define SDMMC_SLOT1_IOMUX_PIN_NUM_D2   12\r
+#define SDMMC_SLOT1_IOMUX_PIN_NUM_D3   13\r
+#define SDMMC_SLOT1_FUNC               4\r
+\r
+#endif /* _SOC_SDMMC_PINS_H_ */
\ No newline at end of file
diff --git a/components/soc/esp32/sdio_slave_periph.c b/components/soc/esp32/sdio_slave_periph.c
new file mode 100644 (file)
index 0000000..d3b8cfc
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+\r
+//     http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+#include <stdint.h>\r
+#include "soc/sdio_slave_periph.h"\r
+#include "soc/io_mux_reg.h"\r
+#include "soc/sdio_slave_pins.h"\r
+\r
+// I/O slot of sdio slave:\r
+// 0: GPIO 6, 11, 7, 8, 9, 10,\r
+// 1: GPIO 14, 15, 2, 4, 12, 13 for CLK, CMD, D0, D1, D2, D3 respectively.\r
+// only one peripheral for SDIO and only one slot can work at the same time.\r
+// currently slot 0 is occupied by SPI for flash\r
+const sdio_slave_slot_info_t sdio_slave_slot_info[2]  = {\r
+    {\r
+        .clk_gpio = SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_CLK,\r
+        .cmd_gpio = SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_CMD,\r
+        .d0_gpio = SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_D0,\r
+        .d1_gpio = SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_D1,\r
+        .d2_gpio = SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_D2,\r
+        .d3_gpio = SDIO_SLAVE_SLOT0_IOMUX_PIN_NUM_D3,\r
+        .func = SDIO_SLAVE_SLOT0_FUNC,\r
+    }, {\r
+        .clk_gpio = SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_CLK,\r
+        .cmd_gpio = SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_CMD,\r
+        .d0_gpio = SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_D0,\r
+        .d1_gpio = SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_D1,\r
+        .d2_gpio = SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_D2,\r
+        .d3_gpio = SDIO_SLAVE_SLOT1_IOMUX_PIN_NUM_D3,\r
+        .func = SDIO_SLAVE_SLOT1_FUNC,\r
+    },\r
+};\r
diff --git a/components/soc/esp32/sdmmc_periph.c b/components/soc/esp32/sdmmc_periph.c
new file mode 100644 (file)
index 0000000..319e5e4
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+\r
+//     http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+#include "soc/sdmmc_periph.h"\r
+\r
+const sdmmc_slot_info_t sdmmc_slot_info[2]  = {\r
+    {\r
+        .clk_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_CLK,\r
+        .cmd_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_CMD,\r
+        .d0_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_D0,\r
+        .d1_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_D1,\r
+        .d2_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_D2,\r
+        .d3_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_D3,\r
+        .d4_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_D4,\r
+        .d5_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_D5,\r
+        .d6_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_D6,\r
+        .d7_gpio = SDMMC_SLOT0_IOMUX_PIN_NUM_D7,\r
+        .card_detect = HOST_CARD_DETECT_N_1_IDX,\r
+        .write_protect = HOST_CARD_WRITE_PRT_1_IDX,\r
+        .card_int = HOST_CARD_INT_N_1_IDX,\r
+        .width = 8\r
+    },\r
+    {\r
+        .clk_gpio = SDMMC_SLOT1_IOMUX_PIN_NUM_CLK,\r
+        .cmd_gpio = SDMMC_SLOT1_IOMUX_PIN_NUM_CMD,\r
+        .d0_gpio = SDMMC_SLOT1_IOMUX_PIN_NUM_D0,\r
+        .d1_gpio = SDMMC_SLOT1_IOMUX_PIN_NUM_D1,\r
+        .d2_gpio = SDMMC_SLOT1_IOMUX_PIN_NUM_D2,\r
+        .d3_gpio = SDMMC_SLOT1_IOMUX_PIN_NUM_D3,\r
+        .d4_gpio = -1,  //slot1 has no D4-7\r
+        .d5_gpio = -1,\r
+        .d6_gpio = -1,\r
+        .d7_gpio = -1,\r
+        .card_detect = HOST_CARD_DETECT_N_2_IDX,\r
+        .write_protect = HOST_CARD_WRITE_PRT_2_IDX,\r
+        .card_int = HOST_CARD_INT_N_2_IDX,\r
+        .width = 4\r
+    }\r
+};
\ No newline at end of file
diff --git a/components/soc/include/soc/sdio_slave_periph.h b/components/soc/include/soc/sdio_slave_periph.h
new file mode 100644 (file)
index 0000000..cc1c8cb
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+\r
+//     http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+#ifndef _SOC_SDIO_SLAVE_PERIPH_H_\r
+#define _SOC_SDIO_SLAVE_PERIPH_H_\r
+\r
+#include <stdint.h>\r
+//include soc related (generated) definitions\r
+#include "soc/sdio_slave_pins.h"\r
+#include "soc/slc_reg.h"\r
+#include "soc/slc_struct.h"\r
+#include "soc/host_reg.h"\r
+#include "soc/host_struct.h"\r
+#include "soc/hinf_reg.h"\r
+#include "soc/hinf_struct.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/** pin and signal information of each slot */\r
+typedef struct {\r
+    uint32_t clk_gpio;\r
+    uint32_t cmd_gpio;\r
+    uint32_t d0_gpio;\r
+    uint32_t d1_gpio;\r
+    uint32_t d2_gpio;\r
+    uint32_t d3_gpio;\r
+    int      func;\r
+} sdio_slave_slot_info_t;\r
+\r
+extern const sdio_slave_slot_info_t sdio_slave_slot_info[];\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _SOC_SDIO_SLAVE_PERIPH_H_ */
\ No newline at end of file
diff --git a/components/soc/include/soc/sdmmc_periph.h b/components/soc/include/soc/sdmmc_periph.h
new file mode 100644 (file)
index 0000000..183a658
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+\r
+//     http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+#ifndef _SOC_SDMMC_PERIPH_H_\r
+#define _SOC_SDMMC_PERIPH_H_\r
+\r
+#include <stdint.h>\r
+//include soc related (generated) definitions\r
+#include "soc/sdmmc_pins.h"\r
+#include "soc/sdmmc_reg.h"\r
+#include "soc/sdmmc_struct.h"\r
+#include "soc/gpio_sig_map.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    uint8_t clk_gpio;\r
+    uint8_t cmd_gpio;\r
+    uint8_t d0_gpio;\r
+    uint8_t d1_gpio;\r
+    uint8_t d2_gpio;\r
+    uint8_t d3_gpio;\r
+    uint8_t d4_gpio;\r
+    uint8_t d5_gpio;\r
+    uint8_t d6_gpio;\r
+    uint8_t d7_gpio;\r
+    uint8_t card_detect;\r
+    uint8_t write_protect;\r
+    uint8_t card_int;\r
+    uint8_t width;\r
+} sdmmc_slot_info_t;\r
+\r
+/** pin and signal information of each slot */\r
+extern const sdmmc_slot_info_t sdmmc_slot_info[];\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _SOC_SDMMC_PERIPH_H_ */
\ No newline at end of file