1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "hal/spi_slave_hal.h"
16 #include "hal/spi_ll.h"
17 #include "soc/soc_caps.h"
18
19 //This GDMA related part will be introduced by GDMA dedicated APIs in the future. Here we temporarily use macros.
20 #if SOC_GDMA_SUPPORTED
21 #include "soc/gdma_struct.h"
22 #include "hal/gdma_ll.h"
23
24 #define spi_dma_ll_rx_enable_burst_data(dev, chan, enable) gdma_ll_rx_enable_data_burst(&GDMA, chan, enable);
25 #define spi_dma_ll_tx_enable_burst_data(dev, chan, enable) gdma_ll_tx_enable_data_burst(&GDMA, chan, enable);
26 #define spi_dma_ll_rx_enable_burst_desc(dev, chan, enable) gdma_ll_rx_enable_descriptor_burst(&GDMA, chan, enable);
27 #define spi_dma_ll_tx_enable_burst_desc(dev, chan, enable) gdma_ll_tx_enable_descriptor_burst(&GDMA, chan, enable);
28 #define spi_dma_ll_enable_out_auto_wrback(dev, chan, enable) gdma_ll_tx_enable_auto_write_back(&GDMA, chan, enable);
29 #define spi_dma_ll_set_out_eof_generation(dev, chan, enable) gdma_ll_tx_set_eof_mode(&GDMA, chan, enable);
30 #endif
31
s_spi_slave_hal_dma_init_config(const spi_slave_hal_context_t * hal)32 static void s_spi_slave_hal_dma_init_config(const spi_slave_hal_context_t *hal)
33 {
34 spi_dma_ll_rx_enable_burst_data(hal->dma_in, hal->rx_dma_chan, 1);
35 spi_dma_ll_tx_enable_burst_data(hal->dma_out, hal->tx_dma_chan, 1);
36 spi_dma_ll_rx_enable_burst_desc(hal->dma_in, hal->rx_dma_chan, 1);
37 spi_dma_ll_tx_enable_burst_desc(hal->dma_out, hal->tx_dma_chan, 1);
38 }
39
spi_slave_hal_init(spi_slave_hal_context_t * hal,const spi_slave_hal_config_t * hal_config)40 void spi_slave_hal_init(spi_slave_hal_context_t *hal, const spi_slave_hal_config_t *hal_config)
41 {
42 memset(hal, 0, sizeof(spi_slave_hal_context_t));
43 spi_dev_t *hw = SPI_LL_GET_HW(hal_config->host_id);
44 hal->hw = hw;
45 hal->dma_in = hal_config->dma_in;
46 hal->dma_out = hal_config->dma_out;
47
48 s_spi_slave_hal_dma_init_config(hal);
49 spi_ll_slave_init(hal->hw);
50
51 //Force a transaction done interrupt. This interrupt won't fire yet because we initialized the SPI interrupt as
52 //disabled. This way, we can just enable the SPI interrupt and the interrupt handler will kick in, handling
53 //any transactions that are queued.
54 spi_ll_set_int_stat(hal->hw);
55 spi_ll_enable_int(hal->hw);
56 }
57
spi_slave_hal_setup_device(const spi_slave_hal_context_t * hal)58 void spi_slave_hal_setup_device(const spi_slave_hal_context_t *hal)
59 {
60 spi_ll_set_rx_lsbfirst(hal->hw, hal->rx_lsbfirst);
61 spi_ll_set_tx_lsbfirst(hal->hw, hal->tx_lsbfirst);
62 spi_ll_slave_set_mode(hal->hw, hal->mode, hal->use_dma);
63 }
64
spi_slave_hal_deinit(spi_slave_hal_context_t * hal)65 void spi_slave_hal_deinit(spi_slave_hal_context_t *hal)
66 {
67
68 }
69