2019-04-18 10:13:05 -04:00
|
|
|
#include "hal/spi_slave_hal.h"
|
|
|
|
#include "hal/spi_ll.h"
|
2020-09-23 09:01:13 -04:00
|
|
|
#include "soc/soc_caps.h"
|
|
|
|
|
2020-09-08 05:05:49 -04:00
|
|
|
//This GDMA related part will be introduced by GDMA dedicated APIs in the future. Here we temporarily use macros.
|
2023-08-31 07:17:40 -04:00
|
|
|
#if SOC_GDMA_SUPPORTED
|
|
|
|
#if (SOC_GDMA_TRIG_PERIPH_SPI2_BUS == SOC_GDMA_BUS_AHB) && (SOC_AHB_GDMA_VERSION == 1)
|
2020-09-23 09:01:13 -04:00
|
|
|
#include "soc/gdma_struct.h"
|
|
|
|
#include "hal/gdma_ll.h"
|
2021-01-27 08:56:16 -05:00
|
|
|
#define spi_dma_ll_rx_enable_burst_data(dev, chan, enable) gdma_ll_rx_enable_data_burst(&GDMA, chan, enable);
|
|
|
|
#define spi_dma_ll_tx_enable_burst_data(dev, chan, enable) gdma_ll_tx_enable_data_burst(&GDMA, chan, enable);
|
|
|
|
#define spi_dma_ll_rx_enable_burst_desc(dev, chan, enable) gdma_ll_rx_enable_descriptor_burst(&GDMA, chan, enable);
|
|
|
|
#define spi_dma_ll_tx_enable_burst_desc(dev, chan, enable) gdma_ll_tx_enable_descriptor_burst(&GDMA, chan, enable);
|
|
|
|
#define spi_dma_ll_enable_out_auto_wrback(dev, chan, enable) gdma_ll_tx_enable_auto_write_back(&GDMA, chan, enable);
|
|
|
|
#define spi_dma_ll_set_out_eof_generation(dev, chan, enable) gdma_ll_tx_set_eof_mode(&GDMA, chan, enable);
|
2023-08-31 07:17:40 -04:00
|
|
|
|
|
|
|
#elif (SOC_GDMA_TRIG_PERIPH_SPI2_BUS == SOC_GDMA_BUS_AXI) //TODO: IDF-6152, refactor spi hal layer
|
|
|
|
#include "hal/axi_dma_ll.h"
|
|
|
|
#define spi_dma_ll_rx_enable_burst_data(dev, chan, enable) axi_dma_ll_rx_enable_data_burst(&AXI_DMA, chan, enable);
|
|
|
|
#define spi_dma_ll_tx_enable_burst_data(dev, chan, enable) axi_dma_ll_tx_enable_data_burst(&AXI_DMA, chan, enable);
|
|
|
|
#define spi_dma_ll_rx_enable_burst_desc(dev, chan, enable) axi_dma_ll_rx_enable_descriptor_burst(&AXI_DMA, chan, enable);
|
|
|
|
#define spi_dma_ll_tx_enable_burst_desc(dev, chan, enable) axi_dma_ll_tx_enable_descriptor_burst(&AXI_DMA, chan, enable);
|
|
|
|
#define spi_dma_ll_enable_out_auto_wrback(dev, chan, enable) axi_dma_ll_tx_enable_auto_write_back(&AXI_DMA, chan, enable);
|
|
|
|
#define spi_dma_ll_set_out_eof_generation(dev, chan, enable) axi_dma_ll_tx_set_eof_mode(&AXI_DMA, chan, enable);
|
2020-09-23 09:01:13 -04:00
|
|
|
#endif
|
2023-08-31 07:17:40 -04:00
|
|
|
#endif //SOC_GDMA_SUPPORTED
|
2019-04-18 10:13:05 -04:00
|
|
|
|
2020-09-14 05:33:10 -04:00
|
|
|
static void s_spi_slave_hal_dma_init_config(const spi_slave_hal_context_t *hal)
|
|
|
|
{
|
2021-01-27 08:56:16 -05:00
|
|
|
spi_dma_ll_rx_enable_burst_data(hal->dma_in, hal->rx_dma_chan, 1);
|
|
|
|
spi_dma_ll_tx_enable_burst_data(hal->dma_out, hal->tx_dma_chan, 1);
|
|
|
|
spi_dma_ll_rx_enable_burst_desc(hal->dma_in, hal->rx_dma_chan, 1);
|
|
|
|
spi_dma_ll_tx_enable_burst_desc(hal->dma_out, hal->tx_dma_chan, 1);
|
2020-09-14 05:33:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void spi_slave_hal_init(spi_slave_hal_context_t *hal, const spi_slave_hal_config_t *hal_config)
|
2019-04-18 10:13:05 -04:00
|
|
|
{
|
|
|
|
memset(hal, 0, sizeof(spi_slave_hal_context_t));
|
2020-09-14 05:33:10 -04:00
|
|
|
spi_dev_t *hw = SPI_LL_GET_HW(hal_config->host_id);
|
2019-04-18 10:13:05 -04:00
|
|
|
hal->hw = hw;
|
2020-09-14 05:33:10 -04:00
|
|
|
hal->dma_in = hal_config->dma_in;
|
|
|
|
hal->dma_out = hal_config->dma_out;
|
2019-04-18 10:13:05 -04:00
|
|
|
|
2020-09-14 05:33:10 -04:00
|
|
|
s_spi_slave_hal_dma_init_config(hal);
|
2019-04-18 10:13:05 -04:00
|
|
|
spi_ll_slave_init(hal->hw);
|
|
|
|
|
|
|
|
//Force a transaction done interrupt. This interrupt won't fire yet because we initialized the SPI interrupt as
|
|
|
|
//disabled. This way, we can just enable the SPI interrupt and the interrupt handler will kick in, handling
|
|
|
|
//any transactions that are queued.
|
|
|
|
spi_ll_set_int_stat(hal->hw);
|
2020-09-14 05:33:10 -04:00
|
|
|
spi_ll_enable_int(hal->hw);
|
2019-04-18 10:13:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void spi_slave_hal_setup_device(const spi_slave_hal_context_t *hal)
|
|
|
|
{
|
|
|
|
spi_ll_set_rx_lsbfirst(hal->hw, hal->rx_lsbfirst);
|
|
|
|
spi_ll_set_tx_lsbfirst(hal->hw, hal->tx_lsbfirst);
|
|
|
|
spi_ll_slave_set_mode(hal->hw, hal->mode, hal->use_dma);
|
|
|
|
}
|
|
|
|
|
|
|
|
void spi_slave_hal_deinit(spi_slave_hal_context_t *hal)
|
|
|
|
{
|
|
|
|
|
2020-09-08 05:05:49 -04:00
|
|
|
}
|