From 9d5eab5c4166acdb00d0534dd9db57834407a312 Mon Sep 17 00:00:00 2001 From: Phil Dale Date: Fri, 21 May 2021 21:59:41 +0100 Subject: [PATCH] add pixelRead() for ILI9341 --- Adafruit_TFTLCD.cpp | 21 +++++++++++++++++++-- registers.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Adafruit_TFTLCD.cpp b/Adafruit_TFTLCD.cpp index 7ee270f..50f028e 100644 --- a/Adafruit_TFTLCD.cpp +++ b/Adafruit_TFTLCD.cpp @@ -1000,8 +1000,25 @@ uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) { CS_IDLE; return (((uint16_t)r & B11111000) << 8) | (((uint16_t)g & B11111100) << 3) | (b >> 3); - } else - return 0; + } else if(driver == ID_9341) { + uint8_t r, g, b; + setAddrWindow(x, y, width()-1, height()-1); + CS_ACTIVE; + CD_COMMAND; + write8(ILI9341_MEMORYREAD); + setReadDir(); + CD_DATA; + delayMicroseconds(50); + read8(r); + read8(r); + read8(g); + read8(b); + setWriteDir(); + CS_IDLE; + return (((uint16_t)r & B11111000) << 8) | (((uint16_t)g & B11111100) << 3) | + (b >> 3); + + } else return 0; } // Ditto with the read/write port directions, as above. diff --git a/registers.h b/registers.h index c8bb816..436285f 100644 --- a/registers.h +++ b/registers.h @@ -72,6 +72,7 @@ #define ILI9341_COLADDRSET 0x2A #define ILI9341_PAGEADDRSET 0x2B #define ILI9341_MEMORYWRITE 0x2C +#define ILI9341_MEMORYREAD 0x2E #define ILI9341_PIXELFORMAT 0x3A #define ILI9341_FRAMECONTROL 0xB1 #define ILI9341_DISPLAYFUNC 0xB6