boards/xtensa/esp32: use common board source for SDMMC

Deletes board specific sdmmc implementation in favor of a common source and header file.

Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
This commit is contained in:
Filipe Cavalcanti
2025-05-30 17:08:32 -03:00
committed by Xiang Xiao
parent 452292159b
commit aedce4c648
33 changed files with 107 additions and 709 deletions
@@ -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 <debug.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#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 */
+4
View File
@@ -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
@@ -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 <debug.h>
#include <nuttx/config.h>
#include <syslog.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#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;
}
@@ -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
@@ -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
*
@@ -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);
@@ -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
@@ -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
****************************************************************************/
@@ -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);
@@ -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 <debug.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#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;
}
@@ -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
@@ -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
*
@@ -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);
@@ -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 <debug.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#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;
}
@@ -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
@@ -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
*
@@ -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);
@@ -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 <debug.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#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;
}
@@ -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
@@ -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
*
@@ -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);
@@ -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 <debug.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#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;
}
@@ -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
@@ -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
*
@@ -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);
@@ -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 <debug.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#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;
}
@@ -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
@@ -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);
@@ -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
****************************************************************************/
@@ -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
@@ -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);
@@ -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 <debug.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#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;
}
@@ -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
****************************************************************************/