From 0ad6de91618d9f63ba41c2f256e822e51e31df52 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Fri, 5 Nov 2021 00:09:42 +0000 Subject: [PATCH] Fix RP2040 with RPi type display RPi display requires 16 bit commands and slower DC and CS strobe timings. --- Processors/TFT_eSPI_RP2040.h | 18 ++++++++++++++---- TFT_eSPI.cpp | 20 ++++++++++++++++---- TFT_eSPI.h | 2 +- library.json | 2 +- library.properties | 2 +- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Processors/TFT_eSPI_RP2040.h b/Processors/TFT_eSPI_RP2040.h index 0237ed8..6ef1877 100644 --- a/Processors/TFT_eSPI_RP2040.h +++ b/Processors/TFT_eSPI_RP2040.h @@ -59,8 +59,13 @@ #else //#define DC_C sio_hw->gpio_clr = (1ul << TFT_DC) //#define DC_D sio_hw->gpio_set = (1ul << TFT_DC) - #define DC_C sio_hw->gpio_clr = (1ul << TFT_DC) - #define DC_D sio_hw->gpio_set = (1ul << TFT_DC) + #if defined (RPI_DISPLAY_TYPE) + #define DC_C digitalWrite(TFT_DC, LOW); + #define DC_D digitalWrite(TFT_DC, HIGH); + #else + #define DC_C sio_hw->gpio_clr = (1ul << TFT_DC) + #define DC_D sio_hw->gpio_set = (1ul << TFT_DC) + #endif #endif //////////////////////////////////////////////////////////////////////////////////////// @@ -70,8 +75,13 @@ #define CS_L // No macro allocated so it generates no code #define CS_H // No macro allocated so it generates no code #else - #define CS_L sio_hw->gpio_clr = (1ul << TFT_CS) - #define CS_H sio_hw->gpio_set = (1ul << TFT_CS) + #if defined (RPI_DISPLAY_TYPE) + #define CS_L digitalWrite(TFT_CS, LOW); + #define CS_H digitalWrite(TFT_CS, HIGH); + #else + #define CS_L sio_hw->gpio_clr = (1ul << TFT_CS) + #define CS_H sio_hw->gpio_set = (1ul << TFT_CS) + #endif #endif //////////////////////////////////////////////////////////////////////////////////////// diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 493d01f..84d8a09 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -3093,7 +3093,11 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {}; DC_C; #if !defined (SPI_18BIT_DRIVER) - spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST); + #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers + spi_set_format(spi0, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST); + #else + spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST); + #endif #endif spi_get_hw(spi0)->dr = (uint32_t)TFT_CASET; @@ -3282,7 +3286,11 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color) // a busy check is not needed. while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {}; DC_C; - spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST); + #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers + spi_set_format(spi0, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST); + #else + spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST); + #endif spi_get_hw(spi0)->dr = (uint32_t)TFT_CASET; while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS){}; @@ -3317,8 +3325,12 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color) #else while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {}; DC_D; - spi_get_hw(spi0)->dr = (uint32_t)color>>8; - spi_get_hw(spi0)->dr = (uint32_t)color; + #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers + spi_get_hw(spi0)->dr = (uint32_t)color; + #else + spi_get_hw(spi0)->dr = (uint32_t)color>>8; + spi_get_hw(spi0)->dr = (uint32_t)color; + #endif #endif /* // Subsequent pixel reads work OK without draining the FIFO... diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 75d076c..3cc3615 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.72" +#define TFT_ESPI_VERSION "2.3.73" // Bit level feature flags // Bit 0 set: viewport capability diff --git a/library.json b/library.json index 25c5dc1..da44e14 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.3.72", + "version": "2.3.73", "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 cbf2339..6745500 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=2.3.72 +version=2.3.73 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for RP2040, STM32, ESP8266 and ESP32