1 #include "hal/spi_slave_hal.h"
2 #include "hal/spi_ll.h"
3 #include "soc/soc_caps.h"
4
5 //This GDMA related part will be introduced by GDMA dedicated APIs in the future. Here we temporarily use macros.
6 #if SOC_GDMA_SUPPORTED
7 #include "soc/gdma_struct.h"
8 #include "hal/gdma_ll.h"
9
10 #define spi_dma_ll_rx_enable_burst_data(dev, chan, enable) gdma_ll_rx_enable_data_burst(&GDMA, chan, enable);
11 #define spi_dma_ll_tx_enable_burst_data(dev, chan, enable) gdma_ll_tx_enable_data_burst(&GDMA, chan, enable);
12 #define spi_dma_ll_rx_enable_burst_desc(dev, chan, enable) gdma_ll_rx_enable_descriptor_burst(&GDMA, chan, enable);
13 #define spi_dma_ll_tx_enable_burst_desc(dev, chan, enable) gdma_ll_tx_enable_descriptor_burst(&GDMA, chan, enable);
14 #define spi_dma_ll_enable_out_auto_wrback(dev, chan, enable) gdma_ll_tx_enable_auto_write_back(&GDMA, chan, enable);
15 #define spi_dma_ll_set_out_eof_generation(dev, chan, enable) gdma_ll_tx_set_eof_mode(&GDMA, chan, enable);
16 #endif
17
s_spi_slave_hal_dma_init_config(const spi_slave_hal_context_t * hal)18 static void s_spi_slave_hal_dma_init_config(const spi_slave_hal_context_t *hal)
19 {
20 spi_dma_ll_rx_enable_burst_data(hal->dma_in, hal->rx_dma_chan, 1);
21 spi_dma_ll_tx_enable_burst_data(hal->dma_out, hal->tx_dma_chan, 1);
22 spi_dma_ll_rx_enable_burst_desc(hal->dma_in, hal->rx_dma_chan, 1);
23 spi_dma_ll_tx_enable_burst_desc(hal->dma_out, hal->tx_dma_chan, 1);
24 }
25
spi_slave_hal_init(spi_slave_hal_context_t * hal,const spi_slave_hal_config_t * hal_config)26 void spi_slave_hal_init(spi_slave_hal_context_t *hal, const spi_slave_hal_config_t *hal_config)
27 {
28 memset(hal, 0, sizeof(spi_slave_hal_context_t));
29 spi_dev_t *hw = SPI_LL_GET_HW(hal_config->host_id);
30 hal->hw = hw;
31 hal->dma_in = hal_config->dma_in;
32 hal->dma_out = hal_config->dma_out;
33
34 s_spi_slave_hal_dma_init_config(hal);
35 spi_ll_slave_init(hal->hw);
36
37 //Force a transaction done interrupt. This interrupt won't fire yet because we initialized the SPI interrupt as
38 //disabled. This way, we can just enable the SPI interrupt and the interrupt handler will kick in, handling
39 //any transactions that are queued.
40 spi_ll_set_int_stat(hal->hw);
41 spi_ll_enable_int(hal->hw);
42 }
43
spi_slave_hal_setup_device(const spi_slave_hal_context_t * hal)44 void spi_slave_hal_setup_device(const spi_slave_hal_context_t *hal)
45 {
46 spi_ll_set_rx_lsbfirst(hal->hw, hal->rx_lsbfirst);
47 spi_ll_set_tx_lsbfirst(hal->hw, hal->tx_lsbfirst);
48 spi_ll_slave_set_mode(hal->hw, hal->mode, hal->use_dma);
49 }
50
spi_slave_hal_deinit(spi_slave_hal_context_t * hal)51 void spi_slave_hal_deinit(spi_slave_hal_context_t *hal)
52 {
53
54 }
55