From 9a084839bd7bcd6a2b0208834a8455e70da5ff3d Mon Sep 17 00:00:00 2001 From: Bodmer Date: Thu, 18 Nov 2021 16:44:32 +0000 Subject: [PATCH] Add ESP32 S2 support Tested with ESP32 board package 2.0.1 Additional boards manager URL may need to be updated to load the latest ESP32 board package! --- Processors/TFT_eSPI_ESP32.c | 33 +++++++++++++++++++------- Processors/TFT_eSPI_ESP32.h | 30 +++++++++++++++++++++-- TFT_eSPI.h | 12 ++++++---- User_Setup_Select.h | 2 ++ User_Setups/Setup70_ESP32_S2_ILI9341.h | 33 ++++++++++++++++++++++++++ library.json | 2 +- library.properties | 2 +- 7 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 User_Setups/Setup70_ESP32_S2_ILI9341.h diff --git a/Processors/TFT_eSPI_ESP32.c b/Processors/TFT_eSPI_ESP32.c index a715ebc..2c018e0 100644 --- a/Processors/TFT_eSPI_ESP32.c +++ b/Processors/TFT_eSPI_ESP32.c @@ -8,21 +8,38 @@ // Select the SPI port to use, ESP32 has 2 options #if !defined (TFT_PARALLEL_8_BIT) - #ifdef USE_HSPI_PORT - SPIClass spi = SPIClass(HSPI); - #else // use default VSPI port - //SPIClass& spi = SPI; - SPIClass spi = SPIClass(VSPI); + #ifdef CONFIG_IDF_TARGET_ESP32 + #ifdef USE_HSPI_PORT + SPIClass spi = SPIClass(HSPI); + #else // use default VSPI port + //SPIClass& spi = SPI; + SPIClass spi = SPIClass(VSPI); + #endif + #else + #ifdef USE_HSPI_PORT + SPIClass spi = SPIClass(HSPI); + #else // use FSPI port + //SPIClass& spi = SPI; + SPIClass spi = SPIClass(FSPI); + #endif #endif #endif #ifdef ESP32_DMA // DMA SPA handle spi_device_handle_t dmaHAL; - #ifdef USE_HSPI_PORT - spi_host_device_t spi_host = HSPI_HOST; + #ifdef CONFIG_IDF_TARGET_ESP32 + #ifdef USE_HSPI_PORT + spi_host_device_t spi_host = HSPI_HOST; + #else // use VSPI port + spi_host_device_t spi_host = VSPI_HOST; + #endif #else - spi_host_device_t spi_host = VSPI_HOST; + #ifdef USE_HSPI_PORT + spi_host_device_t spi_host = (spi_host_device_t)1; // 1 scrambles display area! + #else // use FSPI port + spi_host_device_t spi_host = (spi_host_device_t)1; // 1 draws once then freezes + #endif #endif #endif diff --git a/Processors/TFT_eSPI_ESP32.h b/Processors/TFT_eSPI_ESP32.h index 0d0b255..debc32e 100644 --- a/Processors/TFT_eSPI_ESP32.h +++ b/Processors/TFT_eSPI_ESP32.h @@ -17,11 +17,37 @@ #define SUPPORT_TRANSACTIONS #endif +/* +ESP32: +FSPI not defined +HSPI = 2, uses SPI2 +VSPI = 3, uses SPI3 + +ESP32-S2: +FSPI = 1, uses SPI2 +HSPI = 2, uses SPI3 +VSPI not defined + +ESP32 C3: +FSPI = 0, uses SPI2 ???? To be checked +HSPI = 1, uses SPI3 ???? To be checked +VSPI not defined + +For ESP32/S2/C3: +SPI1_HOST = 0 +SPI2_HOST = 1 +SPI3_HOST = 2 +*/ + // ESP32 specific SPI port selection #ifdef USE_HSPI_PORT - #define SPI_PORT HSPI + #ifdef CONFIG_IDF_TARGET_ESP32 + #define SPI_PORT HSPI //HSPI is port 2 on ESP32 + #else + #define SPI_PORT 3 //HSPI is port 3 on ESP32 S2 + #endif #else - #define SPI_PORT VSPI + #define SPI_PORT 2 //FSPI(ESP32 S2) or VSPI (ESP32) #endif #ifdef RPI_DISPLAY_TYPE diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 3cc3615..44f83d8 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -16,7 +16,7 @@ #ifndef _TFT_eSPIH_ #define _TFT_eSPIH_ -#define TFT_ESPI_VERSION "2.3.73" +#define TFT_ESPI_VERSION "2.3.80" // Bit level feature flags // Bit 0 set: viewport capability @@ -317,15 +317,19 @@ int32_t esp; // Processor code uint8_t trans; // SPI transaction support uint8_t serial; // Serial (SPI) or parallel uint8_t overlap; // ESP8266 overlap mode - +/* #if defined (ESP32) // TODO: make generic for other processors #if defined (USE_HSPI_PORT) uint8_t port = HSPI; #else - uint8_t port = VSPI; + #ifdef CONFIG_IDF_TARGET_ESP32 + uint8_t port = VSPI; + #else + uint8_t port = FSPI; + #endif #endif #endif - +*/ uint16_t tft_driver; // Hexadecimal code uint16_t tft_width; // Rotation 0 width and height uint16_t tft_height; diff --git a/User_Setup_Select.h b/User_Setup_Select.h index 1d13ef0..da009a3 100644 --- a/User_Setup_Select.h +++ b/User_Setup_Select.h @@ -81,6 +81,8 @@ //#include // Setup file for Raspberry Pi Pico with SPI ILI9341 +//#include // Setup file for ESP32 S2 with SPI ILI9341 + //#include // Setup file for ESP8266 and ST7789 135 x 240 TFT //#include // Setup file for ESP32 and Lilygo TTV ST7789 SPI bus TFT 135x240 diff --git a/User_Setups/Setup70_ESP32_S2_ILI9341.h b/User_Setups/Setup70_ESP32_S2_ILI9341.h new file mode 100644 index 0000000..47d7166 --- /dev/null +++ b/User_Setups/Setup70_ESP32_S2_ILI9341.h @@ -0,0 +1,33 @@ +// Setup for the ESP32 S2 with ILI9341 display +// Note SPI DMA with ESP32 S2 is not currently supported + +// See SetupX_Template.h for all options available +#define ILI9341_DRIVER + + // Typical board default pins +#define TFT_CS 10 // 10 or 34 + +#define TFT_MOSI 11 // 11 or 35 +#define TFT_SCLK 12 // 12 or 36 +#define TFT_MISO 13 // 13 or 37 + +#define TFT_DC 14 +#define TFT_RST 15 + +#define LOAD_GLCD +#define LOAD_FONT2 +#define LOAD_FONT4 +#define LOAD_FONT6 +#define LOAD_FONT7 +#define LOAD_FONT8 +#define LOAD_GFXFF + +#define SMOOTH_FONT + +// FSPI port will be used unless the following is defined +#define USE_HSPI_PORT + +//#define SPI_FREQUENCY 27000000 +#define SPI_FREQUENCY 40000000 // Maximum for ILI9341 + +#define SPI_READ_FREQUENCY 6000000 // 6 MHz is the maximum SPI read speed for the ST7789V diff --git a/library.json b/library.json index da44e14..b8f59df 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.3.73", + "version": "2.3.80", "keywords": "Arduino, tft, ePaper, display, Pico, RP2040, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9481, ILI9486, ILI9488, ST7789, RM68140, SSD1351, SSD1963, ILI9225, HX8357D", "description": "A TFT and ePaper SPI graphics library with optimisation for Raspberry Pi Pico, ESP8266, ESP32 and STM32", "repository": diff --git a/library.properties b/library.properties index 6745500..2bf31bc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=2.3.73 +version=2.3.80 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for RP2040, STM32, ESP8266 and ESP32