diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_mmcsd.c b/boards/xtensa/esp32/common/include/esp32_board_sdmmc.h similarity index 58% rename from boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_mmcsd.c rename to boards/xtensa/esp32/common/include/esp32_board_sdmmc.h index e1c2c09890d..73117940dde 100644 --- a/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_mmcsd.c +++ b/boards/xtensa/esp32/common/include/esp32_board_sdmmc.h @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_mmcsd.c + * boards/xtensa/esp32/common/include/esp32_board_sdmmc.h * * SPDX-License-Identifier: Apache-2.0 * @@ -20,67 +20,52 @@ * ****************************************************************************/ +#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SDMMC_H +#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SDMMC_H + /**************************************************************************** * Included Files ****************************************************************************/ -#include #include -#include -#include -#include -#include -#include -#include - -#include "esp32_spi.h" -#include "ttgo_eink5_v2.h" /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + /**************************************************************************** - * Private Definitions + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: esp32_mmcsd_initialize + * Name: board_sdmmc_initialize * * Description: - * Initialize SPI-based SD card and card detect thread. + * Configure a SPI subsystem peripheral to communicate with SD card. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * ****************************************************************************/ -int esp32_mmcsd_initialize(int minor) -{ - struct spi_dev_s *spi; - int rv; +int board_sdmmc_initialize(void); - mcinfo("INFO: Initializing mmcsd card\n"); - - spi = esp32_spibus_initialize(2); - if (spi == NULL) - { - mcerr("ERROR: Failed to initialize SPI port %d\n", 2); - return -ENODEV; - } - - rv = mmcsd_spislotinitialize(minor, 0, spi); - if (rv < 0) - { - mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", - 2, 0); - return rv; - } - - spiinfo("INFO: mmcsd card has been initialized successfully\n"); - return OK; +#undef EXTERN +#if defined(__cplusplus) } +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SDMMC_H */ diff --git a/boards/xtensa/esp32/common/src/Make.defs b/boards/xtensa/esp32/common/src/Make.defs index 3bf716925e3..a49cbf93d71 100644 --- a/boards/xtensa/esp32/common/src/Make.defs +++ b/boards/xtensa/esp32/common/src/Make.defs @@ -170,6 +170,10 @@ ifeq ($(CONFIG_ESP_MCPWM),y) CSRCS += esp32_board_mcpwm.c endif +ifeq ($(CONFIG_MMCSD_SPI),y) + CSRCS += esp32_board_sdmmc.c +endif + DEPPATH += --dep-path src VPATH += :src CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c b/boards/xtensa/esp32/common/src/esp32_board_sdmmc.c similarity index 70% rename from boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c rename to boards/xtensa/esp32/common/src/esp32_board_sdmmc.c index 93705cee8fa..1badb1fa595 100644 --- a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c +++ b/boards/xtensa/esp32/common/src/esp32_board_sdmmc.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c + * boards/xtensa/esp32/common/src/esp32_board_sdmmc.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,17 +24,12 @@ * Included Files ****************************************************************************/ -#include #include +#include #include #include -#include -#include -#include -#include #include "esp32_spi.h" -#include "esp32-audio-kit.h" /**************************************************************************** * Pre-processor Definitions @@ -56,31 +51,43 @@ * Name: esp32_mmcsd_initialize * * Description: - * Initialize SPI-based SD card and card detect thread. + * Configure a SPI subsystem peripheral to communicate with SD card. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * ****************************************************************************/ -int esp32_mmcsd_initialize(int minor) +int board_sdmmc_initialize(void) { struct spi_dev_s *spi; - int rv; + int ret; - mcinfo("INFO: Initializing mmcsd card\n"); + syslog(LOG_INFO, "INFO: init MMC/SD slot %d on SPI%d: /dev/mmcsd%d\n", + CONFIG_NSH_MMCSDSLOTNO, CONFIG_NSH_MMCSDSPIPORTNO, + CONFIG_NSH_MMCSDMINOR); spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); + if (spi == NULL) { - mcerr("ERROR: Failed to initialize SPI port %d\n", 2); + syslog(LOG_ERR, "ERROR: failed to initialize SPI%d.\n", + CONFIG_NSH_MMCSDSPIPORTNO); return -ENODEV; } - rv = mmcsd_spislotinitialize(minor, 0, spi); - if (rv < 0) + /* Mounts to /dev/mmcsdN where N in the minor number */ + + ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, + CONFIG_NSH_MMCSDSLOTNO, spi); + if (ret < 0) { - mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", - 2, 0); - return rv; + syslog(LOG_ERR, "ERROR: failed to bind SPI%d to SD slot %d\n", + CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO); + return ret; } - spiinfo("INFO: mmcsd card has been initialized successfully\n"); + syslog(LOG_INFO, "INFO: MMCSD initialized\n"); return OK; } diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs b/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs index e5f9f0f1a4a..08b0e170c4e 100644 --- a/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs +++ b/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs @@ -33,10 +33,6 @@ CSRCS += esp32_reset.c endif endif -ifeq ($(CONFIG_MMCSD),y) -CSRCS += esp32_mmcsd.c -endif - ifeq ($(CONFIG_DEV_GPIO),y) CSRCS += esp32_gpio.c endif @@ -48,4 +44,3 @@ endif DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board - diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h b/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h index 1ecd025e3a4..a042aa708dd 100644 --- a/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h @@ -152,16 +152,6 @@ int esp32_es8388_initialize(int i2c_port, uint8_t i2c_addr, int i2c_freq, int board_i2sdev_initialize(int port); #endif -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - * - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor); - /**************************************************************************** * Name: esp32_spiflash_init * diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c index 4f5b71ddcae..50b11c22bb8 100644 --- a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c @@ -108,6 +108,10 @@ # include "esp32_lcd_backpack.h" #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32_board_sdmmc.h" +#endif + #include "esp32-audio-kit.h" /**************************************************************************** @@ -172,8 +176,8 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_MMCSD - ret = esp32_mmcsd_initialize(0); +#ifdef CONFIG_MMCSD_SPI + ret = board_sdmmc_initialize(); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); diff --git a/boards/xtensa/esp32/esp32-devkitc/src/Make.defs b/boards/xtensa/esp32/esp32-devkitc/src/Make.defs index 1c9f6f8cd7e..16b4cddaa66 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/Make.defs +++ b/boards/xtensa/esp32/esp32-devkitc/src/Make.defs @@ -29,10 +29,6 @@ CSRCS += esp32_reset.c endif endif -ifeq ($(CONFIG_MMCSD),y) -CSRCS += esp32_mmcsd.c -endif - ifeq ($(CONFIG_DEV_GPIO),y) CSRCS += esp32_gpio.c endif diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h b/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h index aa4399f0cfb..cb3aa58609f 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h +++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h @@ -111,15 +111,6 @@ int esp32_bringup(void); -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor); - /**************************************************************************** * Name: esp32_gpio_init ****************************************************************************/ diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c index bc6b7741644..a2baea659d8 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c @@ -191,6 +191,10 @@ # include "esp32_board_adc.h" #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32_board_sdmmc.h" +#endif + #include "esp32-devkitc.h" /**************************************************************************** @@ -272,8 +276,8 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_MMCSD - ret = esp32_mmcsd_initialize(0); +#ifdef CONFIG_MMCSD_SPI + ret = board_sdmmc_initialize(); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.c deleted file mode 100644 index 8feb2dda3aa..00000000000 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.c +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * boards/xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "esp32_spi.h" -#include "esp32-devkitc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor) -{ - struct spi_dev_s *spi; - int rv; - - mcinfo("INFO: Initializing mmcsd card\n"); - - spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); - if (spi == NULL) - { - mcerr("ERROR: Failed to initialize SPI port %d\n", 2); - return -ENODEV; - } - - rv = mmcsd_spislotinitialize(minor, 0, spi); - if (rv < 0) - { - mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", - 2, 0); - return rv; - } - - spiinfo("INFO: mmcsd card has been initialized successfully\n"); - return OK; -} diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs b/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs index ffaac61c1db..863d57f96cd 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs +++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs @@ -29,10 +29,6 @@ CSRCS += esp32_reset.c endif endif -ifeq ($(CONFIG_MMCSD),y) -CSRCS += esp32_mmcsd.c -endif - ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += esp32_buttons.c endif @@ -40,4 +36,3 @@ endif DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board - diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32-ethernet-kit.h b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32-ethernet-kit.h index 0a880131ca8..28891467729 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32-ethernet-kit.h +++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32-ethernet-kit.h @@ -83,15 +83,6 @@ int esp32_bringup(void); -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor); - /**************************************************************************** * Name: esp32_spiflash_init * diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c index fea11679dec..96511de3958 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c @@ -79,6 +79,10 @@ # include "esp32_rtc_lowerhalf.h" #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32_board_sdmmc.h" +#endif + #include "esp32-ethernet-kit.h" /**************************************************************************** @@ -133,8 +137,8 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_MMCSD - ret = esp32_mmcsd_initialize(0); +#ifdef CONFIG_MMCSD_SPI + ret = board_sdmmc_initialize(); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_mmcsd.c b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_mmcsd.c deleted file mode 100644 index 32732db91c6..00000000000 --- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_mmcsd.c +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_mmcsd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "esp32_spi.h" -#include "esp32-ethernet-kit.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor) -{ - struct spi_dev_s *spi; - int rv; - - mcinfo("INFO: Initializing mmcsd card\n"); - - spi = esp32_spibus_initialize(2); - if (spi == NULL) - { - mcerr("ERROR: Failed to initialize SPI port %d\n", 2); - return -ENODEV; - } - - rv = mmcsd_spislotinitialize(minor, 0, spi); - if (rv < 0) - { - mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", - 2, 0); - return rv; - } - - spiinfo("INFO: mmcsd card has been initialized successfully\n"); - return OK; -} diff --git a/boards/xtensa/esp32/esp32-lyrat/src/Make.defs b/boards/xtensa/esp32/esp32-lyrat/src/Make.defs index addad5fd72b..151ba475de3 100644 --- a/boards/xtensa/esp32/esp32-lyrat/src/Make.defs +++ b/boards/xtensa/esp32/esp32-lyrat/src/Make.defs @@ -33,10 +33,6 @@ CSRCS += esp32_reset.c endif endif -ifeq ($(CONFIG_MMCSD),y) -CSRCS += esp32_mmcsd.c -endif - ifeq ($(CONFIG_DEV_GPIO),y) CSRCS += esp32_gpio.c endif @@ -48,4 +44,3 @@ endif DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board - diff --git a/boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h b/boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h index ff95d9ba262..dad3cc92e24 100644 --- a/boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h +++ b/boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h @@ -148,16 +148,6 @@ int esp32_es8388_initialize(int i2c_port, uint8_t i2c_addr, int i2c_freq, int board_i2sdev_initialize(int port); #endif -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - * - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor); - /**************************************************************************** * Name: esp32_spiflash_init * diff --git a/boards/xtensa/esp32/esp32-lyrat/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-lyrat/src/esp32_bringup.c index 4efe5397ec7..42e3bee9990 100644 --- a/boards/xtensa/esp32/esp32-lyrat/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-lyrat/src/esp32_bringup.c @@ -109,6 +109,10 @@ # include "esp32_lcd_backpack.h" #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32_board_sdmmc.h" +#endif + #include "esp32-lyrat.h" /**************************************************************************** @@ -173,8 +177,8 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_MMCSD - ret = esp32_mmcsd_initialize(0); +#ifdef CONFIG_MMCSD_SPI + ret = board_sdmmc_initialize(); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); diff --git a/boards/xtensa/esp32/esp32-lyrat/src/esp32_mmcsd.c b/boards/xtensa/esp32/esp32-lyrat/src/esp32_mmcsd.c deleted file mode 100644 index 5a2fbfff8a6..00000000000 --- a/boards/xtensa/esp32/esp32-lyrat/src/esp32_mmcsd.c +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * boards/xtensa/esp32/esp32-lyrat/src/esp32_mmcsd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "esp32_spi.h" -#include "esp32-lyrat.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor) -{ - struct spi_dev_s *spi; - int rv; - - mcinfo("INFO: Initializing mmcsd card\n"); - - spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); - if (spi == NULL) - { - mcerr("ERROR: Failed to initialize SPI port %d\n", 2); - return -ENODEV; - } - - rv = mmcsd_spislotinitialize(minor, 0, spi); - if (rv < 0) - { - mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", - 2, 0); - return rv; - } - - spiinfo("INFO: mmcsd card has been initialized successfully\n"); - return OK; -} diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/src/Make.defs b/boards/xtensa/esp32/esp32-sparrow-kit/src/Make.defs index 1b1dcfafd55..ebcaac6be4a 100644 --- a/boards/xtensa/esp32/esp32-sparrow-kit/src/Make.defs +++ b/boards/xtensa/esp32/esp32-sparrow-kit/src/Make.defs @@ -35,10 +35,6 @@ CSRCS += esp32_reset.c endif endif -ifeq ($(CONFIG_MMCSD),y) -CSRCS += esp32_mmcsd.c -endif - ifeq ($(CONFIG_DEV_GPIO),y) CSRCS += esp32_gpio.c endif diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32-sparrow-kit.h b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32-sparrow-kit.h index 61ab018c684..c73afcf32d9 100644 --- a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32-sparrow-kit.h +++ b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32-sparrow-kit.h @@ -89,16 +89,6 @@ int esp32_bringup(void); -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - * - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor); - /**************************************************************************** * Name: esp32_spiflash_init * diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_bringup.c index a7a404f3562..593ba16795b 100644 --- a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_bringup.c @@ -120,6 +120,10 @@ # include "esp32_lcd_backpack.h" #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32_board_sdmmc.h" +#endif + #include "esp32-sparrow-kit.h" /**************************************************************************** @@ -184,8 +188,8 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_MMCSD - ret = esp32_mmcsd_initialize(0); +#ifdef CONFIG_MMCSD_SPI + ret = board_sdmmc_initialize(); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_mmcsd.c b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_mmcsd.c deleted file mode 100644 index 47f224f6637..00000000000 --- a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_mmcsd.c +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_mmcsd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "esp32_spi.h" -#include "esp32-sparrow-kit.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor) -{ - struct spi_dev_s *spi; - int rv; - - mcinfo("INFO: Initializing mmcsd card\n"); - - spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); - if (spi == NULL) - { - mcerr("ERROR: Failed to initialize SPI port %d\n", 2); - return -ENODEV; - } - - rv = mmcsd_spislotinitialize(minor, 0, spi); - if (rv < 0) - { - mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", - 2, 0); - return rv; - } - - spiinfo("INFO: mmcsd card has been initialized successfully\n"); - return OK; -} diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs b/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs index ab2bf6444ed..1b50c05b12d 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs @@ -35,10 +35,6 @@ CSRCS += esp32_reset.c endif endif -ifeq ($(CONFIG_MMCSD),y) -CSRCS += esp32_mmcsd.c -endif - ifeq ($(CONFIG_DEV_GPIO),y) CSRCS += esp32_gpio.c endif @@ -50,4 +46,3 @@ endif DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board - diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h index aea94dc4047..862cf630fed 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h @@ -92,16 +92,6 @@ int esp32_bringup(void); -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - * - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor); - /**************************************************************************** * Name: esp32_spiflash_init * diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c index 844284493e2..65d84ec9b47 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c @@ -108,6 +108,10 @@ # include "esp32_zerocross.h" #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32_board_sdmmc.h" +#endif + #include "esp32-wrover-kit.h" /**************************************************************************** @@ -172,8 +176,8 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_MMCSD - ret = esp32_mmcsd_initialize(0); +#ifdef CONFIG_MMCSD_SPI + ret = board_sdmmc_initialize(); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_mmcsd.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_mmcsd.c deleted file mode 100644 index c561908e503..00000000000 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_mmcsd.c +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * boards/xtensa/esp32/esp32-wrover-kit/src/esp32_mmcsd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "esp32_spi.h" -#include "esp32-wrover-kit.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor) -{ - struct spi_dev_s *spi; - int rv; - - mcinfo("INFO: Initializing mmcsd card\n"); - - spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); - if (spi == NULL) - { - mcerr("ERROR: Failed to initialize SPI port %d\n", 2); - return -ENODEV; - } - - rv = mmcsd_spislotinitialize(minor, 0, spi); - if (rv < 0) - { - mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", - 2, 0); - return rv; - } - - spiinfo("INFO: mmcsd card has been initialized successfully\n"); - return OK; -} diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs b/boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs index 15527116f0b..967db5dfa7e 100644 --- a/boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs +++ b/boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs @@ -29,10 +29,6 @@ CSRCS += esp32_reset.c endif endif -ifeq ($(CONFIG_MMCSD),y) -CSRCS += esp32_mmcsd.c -endif - ifeq ($(CONFIG_DEV_GPIO),y) CSRCS += esp32_gpio.c endif @@ -56,4 +52,3 @@ endif DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board - diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c b/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c index d72fdfbd01a..747840629a7 100644 --- a/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c +++ b/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c @@ -135,6 +135,10 @@ # include "esp32_lcd_backpack.h" #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32_board_sdmmc.h" +#endif + #include "ttgo_eink5_v2.h" /**************************************************************************** @@ -222,8 +226,8 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_MMCSD - ret = esp32_mmcsd_initialize(0); +#ifdef CONFIG_MMCSD_SPI + ret = board_sdmmc_initialize(); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h b/boards/xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h index c3eeb279422..b8033d050f5 100644 --- a/boards/xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h +++ b/boards/xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h @@ -100,15 +100,6 @@ int esp32_bringup(void); -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor); - /**************************************************************************** * Name: esp32_gpio_init ****************************************************************************/ diff --git a/boards/xtensa/esp32/ttgo_t_display_esp32/src/Make.defs b/boards/xtensa/esp32/ttgo_t_display_esp32/src/Make.defs index e5f3d24f8bd..722539876db 100644 --- a/boards/xtensa/esp32/ttgo_t_display_esp32/src/Make.defs +++ b/boards/xtensa/esp32/ttgo_t_display_esp32/src/Make.defs @@ -29,10 +29,6 @@ CSRCS += esp32_reset.c endif endif -ifeq ($(CONFIG_MMCSD),y) -CSRCS += esp32_mmcsd.c -endif - ifeq ($(CONFIG_DEV_GPIO),y) CSRCS += esp32_gpio.c endif @@ -56,4 +52,3 @@ endif DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board - diff --git a/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_bringup.c b/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_bringup.c index b986a6ce97f..48a0272e213 100644 --- a/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_bringup.c +++ b/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_bringup.c @@ -144,6 +144,10 @@ # include "esp32_lcd_backpack.h" #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32_board_sdmmc.h" +#endif + #include "ttgo_t_display_esp32.h" /**************************************************************************** @@ -225,8 +229,8 @@ int esp32_bringup(void) } #endif -#ifdef CONFIG_MMCSD - ret = esp32_mmcsd_initialize(0); +#ifdef CONFIG_MMCSD_SPI + ret = board_sdmmc_initialize(); if (ret < 0) { syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); diff --git a/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_mmcsd.c b/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_mmcsd.c deleted file mode 100644 index 39683322cfe..00000000000 --- a/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_mmcsd.c +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_mmcsd.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "esp32_spi.h" -#include "ttgo_t_display_esp32.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor) -{ - struct spi_dev_s *spi; - int rv; - - mcinfo("INFO: Initializing mmcsd card\n"); - - spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); - if (spi == NULL) - { - mcerr("ERROR: Failed to initialize SPI port %d\n", 2); - return -ENODEV; - } - - rv = mmcsd_spislotinitialize(minor, 0, spi); - if (rv < 0) - { - mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", - 2, 0); - return rv; - } - - spiinfo("INFO: mmcsd card has been initialized successfully\n"); - return OK; -} diff --git a/boards/xtensa/esp32/ttgo_t_display_esp32/src/ttgo_t_display_esp32.h b/boards/xtensa/esp32/ttgo_t_display_esp32/src/ttgo_t_display_esp32.h index 78736d2b1f8..f9b6a675c90 100644 --- a/boards/xtensa/esp32/ttgo_t_display_esp32/src/ttgo_t_display_esp32.h +++ b/boards/xtensa/esp32/ttgo_t_display_esp32/src/ttgo_t_display_esp32.h @@ -94,15 +94,6 @@ int esp32_bringup(void); -/**************************************************************************** - * Name: esp32_mmcsd_initialize - * - * Description: - * Initialize SPI-based SD card and card detect thread. - ****************************************************************************/ - -int esp32_mmcsd_initialize(int minor); - /**************************************************************************** * Name: esp32_gpio_init ****************************************************************************/