xtensa/esp32s3: SPI slave driver

This commit is contained in:
Dong Heng 2023-05-15 20:05:19 +08:00 committed by Xiang Xiao
parent 27fb0c76c9
commit 97d2d6376d
5 changed files with 1778 additions and 3 deletions

View file

@ -301,12 +301,14 @@ config ESP32S3_SPI2
default n
select ESP32S3_SPI
select SPI
select ESP32S3_GPIO_IRQ if SPI_SLAVE
config ESP32S3_SPI3
bool "SPI 3"
default n
select ESP32S3_SPI
select SPI
select ESP32S3_GPIO_IRQ if SPI_SLAVE
config ESP32S3_DMA
bool "General DMA (GDMA)"
@ -596,6 +598,11 @@ config ESP32S3_SPI_UDCS
---help---
Use user-defined CS.
config ESP32S3_SPI_SLAVE_BUFSIZE
int "SPI slave buffer size"
default 2048
depends on SPI_SLAVE
if ESP32S3_SPI2
config ESP32S3_SPI2_DMA
@ -645,6 +652,13 @@ endif # ESP32S3_SPI2
if ESP32S3_SPI3
config ESP32S3_SPI3_DMA
bool "SPI3 use GDMA"
default n
depends on ESP32S3_DMA
---help---
Enable support for transfers using the GDMA engine.
config ESP32S3_SPI3_CSPIN
int "SPI3 CS Pin"
default 10

View file

@ -107,6 +107,9 @@ endif
ifeq ($(CONFIG_ESP32S3_SPI),y)
CHIP_CSRCS += esp32s3_spi.c
ifeq ($(CONFIG_SPI_SLAVE),y)
CHIP_CSRCS += esp32s3_spi_slave.c
endif
endif
ifeq ($(CONFIG_ESP32S3_SPIFLASH),y)

View file

@ -66,6 +66,7 @@
static bool g_dma_chan_used[ESP32S3_DMA_CHAN_MAX];
static mutex_t g_dma_lock = NXMUTEX_INITIALIZER;
static int g_dma_ref;
/****************************************************************************
* Public Functions
@ -368,9 +369,18 @@ void esp32s3_dma_wait_idle(int chan, bool tx)
void esp32s3_dma_init(void)
{
modifyreg32(SYSTEM_PERIP_CLK_EN1_REG, 0, SYSTEM_DMA_CLK_EN_M);
modifyreg32(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST_M, 0);
nxmutex_lock(&g_dma_lock);
modifyreg32(DMA_MISC_CONF_REG, 0, DMA_CLK_EN_M);
if (!g_dma_ref)
{
modifyreg32(SYSTEM_PERIP_CLK_EN1_REG, 0, SYSTEM_DMA_CLK_EN_M);
modifyreg32(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST_M, 0);
modifyreg32(DMA_MISC_CONF_REG, 0, DMA_CLK_EN_M);
}
g_dma_ref++;
nxmutex_unlock(&g_dma_lock);
}

View file

@ -46,6 +46,10 @@ extern "C"
#include <nuttx/spi/spi.h>
#ifdef CONFIG_SPI_SLAVE
# include <nuttx/spi/slave.h>
#endif
#ifdef CONFIG_ESP32S3_SPI2
# define ESP32S3_SPI2 2
#endif
@ -139,6 +143,39 @@ int esp32s3_spi3_cmddata(struct spi_dev_s *dev,
int esp32s3_spibus_uninitialize(struct spi_dev_s *dev);
/****************************************************************************
* Name: esp32s3_spislave_ctrlr_initialize
*
* Description:
* Initialize the selected SPI Slave bus.
*
* Input Parameters:
* port - Port number (for hardware that has multiple SPI Slave interfaces)
*
* Returned Value:
* Valid SPI Slave controller structure reference on success;
* NULL on failure.
*
****************************************************************************/
struct spi_slave_ctrlr_s *esp32s3_spislave_ctrlr_initialize(int port);
/****************************************************************************
* Name: esp32s3_spislave_ctrlr_uninitialize
*
* Description:
* Uninitialize an SPI Slave bus.
*
* Input Parameters:
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* Zero (OK) is returned on success. Otherwise -1 (ERROR).
*
****************************************************************************/
int esp32s3_spislave_ctrlr_uninitialize(struct spi_slave_ctrlr_s *ctrlr);
#endif /* CONFIG_ESP32S3_SPI */
#ifdef __cplusplus

File diff suppressed because it is too large Load diff