Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TFT_eSPI_ESP32_C6.c and TFT_eSPI_ESP32_C6.h #3399

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
22 changes: 11 additions & 11 deletions Processors/TFT_eSPI_ESP32_C3.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#elif defined(USE_FSPI_PORT)
spi_host_device_t spi_host = SPI_HOST;
#else // use VSPI port
spi_host_device_t spi_host = VSPI_HOST;
spi_host_device_t spi_host = SPI2_HOST;
#endif
#else
#ifdef USE_HSPI_PORT
Expand Down Expand Up @@ -259,7 +259,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){
while (*_spi_cmd&SPI_USR);
for (i=0; i < rem; i+=2) *spi_w++ = color32;
*_spi_mosi_dlen = (rem << 4) - 1;
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
*_spi_cmd = SPI_UPDATE;
while (*_spi_cmd & SPI_UPDATE);
#endif
Expand All @@ -276,7 +276,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){
while(len)
{
while (*_spi_cmd&SPI_USR);
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
*_spi_cmd = SPI_UPDATE;
while (*_spi_cmd & SPI_UPDATE);
#endif
Expand Down Expand Up @@ -325,7 +325,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){
WRITE_PERI_REG(SPI_W13_REG(SPI_PORT), color[13]);
WRITE_PERI_REG(SPI_W14_REG(SPI_PORT), color[14]);
WRITE_PERI_REG(SPI_W15_REG(SPI_PORT), color[15]);
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_UPDATE);
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_UPDATE);
#endif
Expand All @@ -352,7 +352,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){
WRITE_PERI_REG(SPI_W5_REG(SPI_PORT), color[5]);
WRITE_PERI_REG(SPI_W6_REG(SPI_PORT), color[6]);
WRITE_PERI_REG(SPI_W7_REG(SPI_PORT), color[7]);
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_UPDATE);
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_UPDATE);
#endif
Expand All @@ -367,7 +367,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){
for (uint32_t i=0; i <= (len<<1); i+=4) {
WRITE_PERI_REG(SPI_W0_REG(SPI_PORT)+i, DAT8TO32(data)); data+=4;
}
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_UPDATE);
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_UPDATE);
#endif
Expand Down Expand Up @@ -412,7 +412,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){
WRITE_PERI_REG(SPI_W13_REG(SPI_PORT), *data++);
WRITE_PERI_REG(SPI_W14_REG(SPI_PORT), *data++);
WRITE_PERI_REG(SPI_W15_REG(SPI_PORT), *data++);
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_UPDATE);
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_UPDATE);
#endif
Expand All @@ -426,7 +426,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_USR);
WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), (len << 4) - 1);
for (uint32_t i=0; i <= (len<<1); i+=4) WRITE_PERI_REG((SPI_W0_REG(SPI_PORT) + i), *data++);
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_UPDATE);
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_UPDATE);
#endif
Expand Down Expand Up @@ -476,7 +476,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len)
WRITE_PERI_REG(SPI_W12_REG(SPI_PORT), r0);
WRITE_PERI_REG(SPI_W13_REG(SPI_PORT), r1);
WRITE_PERI_REG(SPI_W14_REG(SPI_PORT), r2);
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_UPDATE);
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_UPDATE);
#endif
Expand Down Expand Up @@ -507,7 +507,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len)
WRITE_PERI_REG(SPI_W13_REG(SPI_PORT), r1);
WRITE_PERI_REG(SPI_W14_REG(SPI_PORT), r2);
}
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_UPDATE);
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_UPDATE);
#endif
Expand Down Expand Up @@ -858,4 +858,4 @@ void TFT_eSPI::deInitDMA(void)

////////////////////////////////////////////////////////////////////////////////////////
#endif // End of DMA FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
44 changes: 36 additions & 8 deletions Processors/TFT_eSPI_ESP32_C3.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


////////////////////////////////////////////////////
// TFT_eSPI driver functions for ESP32 processors //
////////////////////////////////////////////////////
Expand All @@ -8,7 +10,7 @@
#define _TFT_eSPI_ESP32H_

#if !defined(DISABLE_ALL_LIBRARY_WARNINGS)
#warning >>>>------>> DMA is not supported on the ESP32 C3 (possible future update)
#warning >>>>------>> DMA is not supported on the ESP32 C3, C6(possible future update)
#endif

// Processor ID reported by getSetup()
Expand All @@ -19,7 +21,13 @@
#include "driver/spi_master.h"
#include "hal/gpio_ll.h"

#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32)

#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32c6)
#define CONFIG_IDF_TARGET_ESP32
#endif


#if !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32)
#define CONFIG_IDF_TARGET_ESP32
#endif

Expand All @@ -28,11 +36,25 @@
#endif

// Fix IDF problems with ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3
//#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
/*
// Fix ESP32C3 IDF bug for missing definition (VSPI/FSPI only tested at the moment)
#ifndef REG_SPI_BASE
#define REG_SPI_BASE(i) DR_REG_SPI2_BASE
#endif
*/

#ifdef REG_SPI_BASE //?// ESP32-C3 + ESP32-C6 + ESP32-H2
#undef REG_SPI_BASE
#endif

#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // GPSPI2 and GPSPI3

//#if CONFIG_IDF_TARGET_ESP32C6 //?// Speedlimit ESP32-C6 40MHz why ?
// #undef APB_CLK_FREQ
// #define APB_CLK_FREQ ( 80*1000000 )
//#endif

// Fix ESP32C3 IDF bug for name change
#ifndef SPI_MOSI_DLEN_REG
Expand Down Expand Up @@ -67,8 +89,12 @@ SPI2_HOST = 1
SPI3_HOST = 2
*/

// ESP32 specific SPI port selection - only SPI2_HOST available on C3
#define SPI_PORT SPI2_HOST
// ESP32 specific SPI port selection - only SPI2_HOST available on C3
#if ESP_ARDUINO_VERSION_MAJOR < 3
#define SPI_PORT 2
#else
#define SPI_PORT 2
#endif

#ifdef RPI_DISPLAY_TYPE
#define CMD_BITS (16-1)
Expand Down Expand Up @@ -313,7 +339,7 @@ SPI3_HOST = 2
#define TFT_SCLK 18
#endif

#if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2)
#if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C6)
#if (TFT_MISO == -1)
#undef TFT_MISO
#define TFT_MISO TFT_MOSI
Expand Down Expand Up @@ -532,7 +558,7 @@ SPI3_HOST = 2
#define tft_Write_32D(C) TFT_WRITE_BITS((uint16_t)((C)<<8 | (C)>>8)<<16 | (uint16_t)((C)<<8 | (C)>>8), 32)
//*/
//* Replacement slimmer macros
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6)
#define TFT_WRITE_BITS(D, B) *_spi_mosi_dlen = B-1; \
*_spi_w = D; \
*_spi_cmd = SPI_USR; \
Expand All @@ -552,7 +578,8 @@ SPI3_HOST = 2
#define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16)

// Future option for transfer without wait
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
// #if !defined(CONFIG_IDF_TARGET_ESP32C3)
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6)
#define tft_Write_16N(C) *_spi_mosi_dlen = 16-1; \
*_spi_w = ((C)<<8 | (C)>>8); \
*_spi_cmd = SPI_USR;
Expand Down Expand Up @@ -596,3 +623,4 @@ SPI3_HOST = 2
#define DAT8TO32(P) ( (uint32_t)P[0]<<8 | P[1] | P[2]<<24 | P[3]<<16 )

#endif // Header end

2 changes: 1 addition & 1 deletion Processors/TFT_eSPI_ESP32_S3.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SPI3_HOST = 2
#elif CONFIG_IDF_TARGET_ESP32S2
#define SPI_PORT 2 //FSPI(ESP32 S2)
#elif CONFIG_IDF_TARGET_ESP32S3
#define SPI_PORT FSPI
#define SPI_PORT 2//FSPI->2 asd1
#endif
#endif

Expand Down
5 changes: 2 additions & 3 deletions TFT_eSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
hardware driver, the graphics functions and the
proportional fonts.

The larger fonts are Run Length Encoded to reduce their
The larger fonts are Run Length Encoded to reduce their
size.

Created by Bodmer 2/12/16
Expand All @@ -18,7 +18,7 @@
#if defined (ESP32)
#if defined(CONFIG_IDF_TARGET_ESP32S3)
#include "Processors/TFT_eSPI_ESP32_S3.c" // Tested with SPI and 8-bit parallel
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)
#include "Processors/TFT_eSPI_ESP32_C3.c" // Tested with SPI (8-bit parallel will probably work too!)
#else
#include "Processors/TFT_eSPI_ESP32.c"
Expand Down Expand Up @@ -6155,4 +6155,3 @@ void TFT_eSPI::getSetup(setup_t &tft_settings)
#include "Extensions/AA_graphics.cpp" // Loaded if SMOOTH_FONT is defined by user
#endif
////////////////////////////////////////////////////////////////////////////////////////

5 changes: 3 additions & 2 deletions TFT_eSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
// Include the processor specific drivers
#if defined(CONFIG_IDF_TARGET_ESP32S3)
#include "Processors/TFT_eSPI_ESP32_S3.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
//#elif defined(CONFIG_IDF_TARGET_ESP32C3)
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)
#include "Processors/TFT_eSPI_ESP32_C3.h"
#elif defined (ESP32)
#include "Processors/TFT_eSPI_ESP32.h"
Expand Down Expand Up @@ -1008,4 +1009,4 @@ fastBlend(A alpha, F fgc, B bgc)
// Load the Sprite Class
#include "Extensions/Sprite.h"

#endif // ends #ifndef _TFT_eSPIH_
#endif // ends #ifndef _TFT_eSPIH_