From 1f2d4b0a7503a83bf698cf49f84b0b95da3a77ca Mon Sep 17 00:00:00 2001 From: Bodmer Date: Fri, 1 May 2020 20:57:03 +0100 Subject: [PATCH] Issue #510 part STM32F103 workaround --- Processors/TFT_eSPI_Generic.c | 8 ++++---- Processors/TFT_eSPI_STM32.c | 6 +++--- Processors/TFT_eSPI_STM32.h | 14 +++++++++++--- TFT_eSPI.cpp | 2 ++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Processors/TFT_eSPI_Generic.c b/Processors/TFT_eSPI_Generic.c index a30f1fb..fbc6f66 100644 --- a/Processors/TFT_eSPI_Generic.c +++ b/Processors/TFT_eSPI_Generic.c @@ -142,7 +142,7 @@ uint8_t TFT_eSPI::readByte(void) } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (RPI_WRITE_STROBE) // For RPi TFT with write strobe ############# UNTESTED ################### +#elif defined (RPI_WRITE_STROBE) // For RPi TFT with write strobe //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -168,7 +168,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len) } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (ILI9488_DRIVER) // For 24 bit SPI colour TFT ############# UNTESTED ################### +#elif defined (ILI9488_DRIVER) // For 24 bit SPI colour TFT //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -212,7 +212,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#else // Standard SPI 16 bit colour TFT All Tested +#else // Standard SPI 16 bit colour TFT //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -242,7 +242,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ //////////////////////////////////////////////////////////////////////////////////////// -// DMA FUNCTIONS All tested on STM32F767 +// DMA FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////// // Placeholder for DMA functions diff --git a/Processors/TFT_eSPI_STM32.c b/Processors/TFT_eSPI_STM32.c index 9650ae4..c3acaa7 100644 --- a/Processors/TFT_eSPI_STM32.c +++ b/Processors/TFT_eSPI_STM32.c @@ -440,15 +440,15 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t // If image is clipped, copy pixels into a contiguous block if ( (dw != w) || (dh != h) ) { if(_swapBytes) { - for (uint32_t yb = 0; yb < dh; yb++) { - for (uint32_t xb = 0; xb < dw; xb++) { + for (int32_t yb = 0; yb < dh; yb++) { + for (int32_t xb = 0; xb < dw; xb++) { uint32_t src = xb + dx + w * (yb + dy); (buffer[xb + yb * dw] = image[src] << 8 | image[src] >> 8); } } } else { - for (uint32_t yb = 0; yb < dh; yb++) { + for (int32_t yb = 0; yb < dh; yb++) { memcpy((uint8_t*) (buffer + yb * dw), (uint8_t*) (image + dx + w * (yb + dy)), dw << 1); } } diff --git a/Processors/TFT_eSPI_STM32.h b/Processors/TFT_eSPI_STM32.h index 3119b4f..4da52f7 100644 --- a/Processors/TFT_eSPI_STM32.h +++ b/Processors/TFT_eSPI_STM32.h @@ -187,6 +187,7 @@ #if !defined (TFT_DC) || (TFT_DC < 0) #define DC_C // No macro allocated so it generates no code #define DC_D // No macro allocated so it generates no code + #undef TFT_DC #else // Convert Arduino pin reference Dn or STM pin reference PXn to port and mask #define DC_PORT digitalPinToPort(TFT_DC) @@ -202,6 +203,7 @@ #if !defined (TFT_CS) || (TFT_CS < 0) #define CS_L // No macro allocated so it generates no code #define CS_H // No macro allocated so it generates no code + #undef TFT_CS #else // Convert Arduino pin reference Dx or STM pin reference PXn to port and mask #define CS_PORT digitalPinToPort(TFT_CS) @@ -892,11 +894,17 @@ //////////////////////////////////////////////////////////////////////////////////////// // Macros for all other SPI displays //////////////////////////////////////////////////////////////////////////////////////// + #else - #define tft_Write_8(C) \ - { spiBuffer[0] = C; \ - HAL_SPI_Transmit(&spiHal, spiBuffer, 1, 10); } + #if defined(ST7789_DRIVER) || defined(ST7789_2_DRIVER) + // Temporary workaround for issue #510 part 2 + #define tft_Write_8(C) spi.transfer(C) + #else + #define tft_Write_8(C) \ + { spiBuffer[0] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 1, 10); delayMicroseconds(1);} + #endif #define tft_Write_16(C) \ { spiBuffer[0] = (C)>>8; spiBuffer[1] = C; \ diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 77ec03e..aa94662 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -526,7 +526,9 @@ void TFT_eSPI::commandList (const uint8_t *addr) ***************************************************************************************/ void TFT_eSPI::spiwrite(uint8_t c) { + begin_tft_write(); tft_Write_8(c); + end_tft_write(); }