• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015-2019 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 #pragma once
16 
17 #include "esp_attr.h"
18 #include <esp_bit_defs.h>
19 #include "soc/soc_caps.h"
20 #include "sdkconfig.h"
21 
22 /**
23  * @brief Enum with the three SPI peripherals that are software-accessible in it
24  */
25 typedef enum {
26 //SPI1 can be used as GPSPI only on ESP32
27     SPI1_HOST=0,    ///< SPI1
28     SPI2_HOST=1,    ///< SPI2
29     SPI3_HOST=2,    ///< SPI3
30 } spi_host_device_t;
31 
32 /// SPI Events
33 typedef enum {
34     /* Slave HD Only */
35     SPI_EV_BUF_TX         = BIT(0), ///< The buffer has sent data to master.
36     SPI_EV_BUF_RX         = BIT(1), ///< The buffer has received data from master.
37     SPI_EV_SEND_DMA_READY = BIT(2), ///< Slave has loaded its TX data buffer to the hardware (DMA).
38     SPI_EV_SEND           = BIT(3), ///< Master has received certain number of the data, the number is determined by Master.
39     SPI_EV_RECV_DMA_READY = BIT(4), ///< Slave has loaded its RX data buffer to the hardware (DMA).
40     SPI_EV_RECV           = BIT(5), ///< Slave has received certain number of data from master, the number is determined by Master.
41     SPI_EV_CMD9           = BIT(6), ///< Received CMD9 from master.
42     SPI_EV_CMDA           = BIT(7), ///< Received CMDA from master.
43     /* Common Event */
44     SPI_EV_TRANS          = BIT(8), ///< A transaction has done
45 } spi_event_t;
46 FLAG_ATTR(spi_event_t)
47 
48 
49 /** @cond */    //Doxy command to hide preprocessor definitions from docs */
50 
51 //alias for different chips, deprecated for the chips after esp32s2
52 #ifdef CONFIG_IDF_TARGET_ESP32
53 #define SPI_HOST    SPI1_HOST
54 #define HSPI_HOST   SPI2_HOST
55 #define VSPI_HOST   SPI3_HOST
56 #elif CONFIG_IDF_TARGET_ESP32S2
57 // SPI_HOST (SPI1_HOST) is not supported by the SPI Master and SPI Slave driver on ESP32-S2 and later
58 #define SPI_HOST    SPI1_HOST
59 #define FSPI_HOST   SPI2_HOST
60 #define HSPI_HOST   SPI3_HOST
61 #endif
62 
63 /** @endcond */
64