From 47895f1e7b2f435d56d81aed2b07fe96c6ebe74c Mon Sep 17 00:00:00 2001 From: Bodmer Date: Thu, 27 Jan 2022 22:15:04 +0000 Subject: [PATCH] Allow RP2040 to read from SPI TFT --- Processors/TFT_eSPI_RP2040.c | 4 ++++ TFT_eSPI.cpp | 18 ++++++++++-------- TFT_eSPI.h | 2 +- library.json | 2 +- library.properties | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Processors/TFT_eSPI_RP2040.c b/Processors/TFT_eSPI_RP2040.c index fdea719..2b5486c 100644 --- a/Processors/TFT_eSPI_RP2040.c +++ b/Processors/TFT_eSPI_RP2040.c @@ -69,12 +69,16 @@ uint8_t TFT_eSPI::tft_Read_8(void) { uint8_t ret = 0; + /* for (uint8_t i = 0; i < 8; i++) { // read results ret <<= 1; SCLK_L; if (digitalRead(TFT_MOSI)) ret |= 1; SCLK_H; } + */ + + ret = spi.transfer(0x00); return ret; } diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index d773240..9703e71 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -941,10 +941,10 @@ uint16_t TFT_eSPI::readPixel(int32_t x0, int32_t y0) // Set masked pins D0- D7 to input busDir(dir_mask, INPUT); -#if !defined (SSD1963_DRIVER) + #if !defined (SSD1963_DRIVER) // Dummy read to throw away don't care value readByte(); -#endif + #endif // Fetch the 16 bit BRG pixel //uint16_t rgb = (readByte() << 8) | readByte(); @@ -989,9 +989,9 @@ uint16_t TFT_eSPI::readPixel(int32_t x0, int32_t y0) uint16_t color = 0; - begin_tft_read(); + begin_tft_read(); // Sets CS low - readAddrWindow(x0, y0, 1, 1); // Sets CS low + readAddrWindow(x0, y0, 1, 1); #ifdef TFT_SDA_READ begin_SDA_Read(); @@ -3171,6 +3171,10 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) addr_col = 0xFFFF; addr_row = 0xFFFF; +#if defined (SSD1963_DRIVER) + if ((rotation & 0x1) == 0) { swap_coord(xs, ys); swap_coord(xe, ye); } +#endif + #ifdef CGRAM_OFFSET xs += colstart; xe += colstart; @@ -3178,12 +3182,10 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) ye += rowstart; #endif -#if defined (SSD1963_DRIVER) - if ((rotation & 0x1) == 0) { swap_coord(xs, ys); swap_coord(xe, ye); } -#endif - // Temporary solution is to include the RP2040 optimised code here #if (defined(ARDUINO_ARCH_RP2040) || defined (ARDUINO_ARCH_MBED)) && !defined(RP2040_PIO_INTERFACE) + // Use hardware SPI port, this code does not swap from 8 to 16 bit + // to avoid the spi_set_format() call overhead while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; DC_C; hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 9d1a7fd..98189e2 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -16,7 +16,7 @@ #ifndef _TFT_eSPIH_ #define _TFT_eSPIH_ -#define TFT_ESPI_VERSION "2.4.30" +#define TFT_ESPI_VERSION "2.4.31" // Bit level feature flags // Bit 0 set: viewport capability diff --git a/library.json b/library.json index a0828ca..2aa5c17 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.4.30", + "version": "2.4.31", "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 1412512..448d498 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=2.4.30 +version=2.4.31 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for RP2040, STM32, ESP8266 and ESP32