From bb51cdab3eab4df194c4c28ff0e0410dba8175e6 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 15 Sep 2018 01:32:26 +0800 Subject: [PATCH] fix ILI9225 set window --- TFT_Drivers/ILI9225_Defines.h | 16 ----- TFT_eSPI.cpp | 129 +++++++++++++++++++++++++++++++++- TFT_eSPI.h | 2 +- 3 files changed, 127 insertions(+), 20 deletions(-) diff --git a/TFT_Drivers/ILI9225_Defines.h b/TFT_Drivers/ILI9225_Defines.h index b434e8d..b9de0e1 100644 --- a/TFT_Drivers/ILI9225_Defines.h +++ b/TFT_Drivers/ILI9225_Defines.h @@ -48,19 +48,3 @@ // Delay between some initialisation commands #define TFT_INIT_DELAY 0x80 // Not used unless commandlist invoked - -// autoincrement modes (register ILI9225_ENTRY_MODE, bit 5..3 ) -enum autoIncMode_t { R2L_BottomUp, BottomUp_R2L, L2R_BottomUp, BottomUp_L2R, R2L_TopDown, TopDown_R2L, L2R_TopDown, TopDown_L2R }; - - // correspondig modes if orientation changed: - const autoIncMode_t modeTab [3][8] = { - // { R2L_BottomUp, BottomUp_R2L, L2R_BottomUp, BottomUp_L2R, R2L_TopDown, TopDown_R2L, L2R_TopDown, TopDown_L2R }// - /* 90° */ { BottomUp_L2R, L2R_BottomUp, TopDown_L2R, L2R_TopDown, BottomUp_R2L, R2L_BottomUp, TopDown_R2L, R2L_TopDown }, - /*180° */ { L2R_TopDown , TopDown_L2R, R2L_TopDown, TopDown_R2L, L2R_BottomUp, BottomUp_L2R, R2L_BottomUp, BottomUp_R2L}, - /*270° */ { TopDown_R2L , R2L_TopDown, BottomUp_R2L, R2L_BottomUp, TopDown_L2R, L2R_TopDown, BottomUp_L2R, L2R_BottomUp} - }; - -#define TFT_CASET 0x20 -#define TFT_PASET 0x21 -#define TFT_RAMWR 0x22 -#define TFT_RAMRD 0x23 diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 1aa2cd9..dffae83 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -2690,6 +2690,43 @@ inline void TFT_eSPI::setAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1+=rowstart; #endif +#ifdef ILI9225_DRIVER + // Column addr set + DC_C; + CS_L; + + tft_Write_8(ILI9225_HORIZONTAL_WINDOW_ADDR1); + DC_D; + tft_Write_16(x1); + DC_C; + tft_Write_8(ILI9225_HORIZONTAL_WINDOW_ADDR2); + DC_D; + tft_Write_16(x0); + + // Row addr set + DC_C; + tft_Write_8(ILI9225_VERTICAL_WINDOW_ADDR1); + DC_D; + tft_Write_16(y1); + DC_C; + tft_Write_8(ILI9225_VERTICAL_WINDOW_ADDR2); + DC_D; + tft_Write_16(y0); + + DC_C; + tft_Write_8(ILI9225_RAM_ADDR_SET1); + DC_D; + tft_Write_16(x1); + DC_C; + tft_Write_8(ILI9225_RAM_ADDR_SET2); + DC_D; + tft_Write_16(y1); + + // write to RAM + DC_C; + tft_Write_8(ILI9225_GRAM_DATA_REG); + DC_D; +#else #if !defined (RPI_ILI9486_DRIVER) uint32_t xaw = ((uint32_t)x0 << 16) | x1; uint32_t yaw = ((uint32_t)y0 << 16) | y1; @@ -2731,6 +2768,7 @@ inline void TFT_eSPI::setAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t DC_D; //spi_end(); +#endif // end ILI9225_DRIVER check } #endif // end RPI_ILI9486_DRIVER check #endif // end ESP32 check @@ -2822,6 +2860,43 @@ void TFT_eSPI::readAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) y1+=rowstart; #endif +#ifdef ILI9225_DRIVER + // Column addr set + DC_C; + CS_L; + + tft_Write_8(ILI9225_HORIZONTAL_WINDOW_ADDR1); + DC_D; + tft_Write_16(x1); + DC_C; + tft_Write_8(ILI9225_HORIZONTAL_WINDOW_ADDR2); + DC_D; + tft_Write_16(x0); + + // Row addr set + DC_C; + tft_Write_8(ILI9225_VERTICAL_WINDOW_ADDR1); + DC_D; + tft_Write_16(y1); + DC_C; + tft_Write_8(ILI9225_VERTICAL_WINDOW_ADDR2); + DC_D; + tft_Write_16(y0); + + DC_C; + tft_Write_8(ILI9225_RAM_ADDR_SET1); + DC_D; + tft_Write_16(x1); + DC_C; + tft_Write_8(ILI9225_RAM_ADDR_SET1); + DC_D; + tft_Write_16(y1); + + DC_C; + tft_Write_8(ILI9225_GRAM_DATA_REG); // Read CGRAM command + + DC_D; +#else uint32_t xaw = ((uint32_t)x0 << 16) | x1; uint32_t yaw = ((uint32_t)y0 << 16) | y1; @@ -2831,7 +2906,6 @@ void TFT_eSPI::readAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) tft_Write_8(TFT_CASET); - DC_D; tft_Write_32(xaw); @@ -2849,7 +2923,7 @@ void TFT_eSPI::readAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) tft_Write_8(TFT_RAMRD); // Read CGRAM command DC_D; - +#endif //spi_end(); } @@ -3045,7 +3119,7 @@ void TFT_eSPI::drawPixel(uint32_t x, uint32_t y, uint32_t color) #else // ESP32 -void TFT_eSPI::drawPixel(uint32_t x, uint32_t y, uint32_t color) +void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color) { // Faster range checking, possible because x and y are unsigned if ((x >= _width) || (y >= _height)) return; @@ -3056,6 +3130,54 @@ void TFT_eSPI::drawPixel(uint32_t x, uint32_t y, uint32_t color) y+=rowstart; #endif +#ifdef ILI9225_DRIVER + // Column addr set + CS_L; + + // No need to send x if it has not changed (speeds things up) + if (addr_col != x) { + + DC_C; + tft_Write_8(ILI9225_HORIZONTAL_WINDOW_ADDR1); + DC_D; + tft_Write_16(x); + DC_C; + tft_Write_8(ILI9225_HORIZONTAL_WINDOW_ADDR2); + DC_D; + tft_Write_16(x); + DC_C; + tft_Write_8(ILI9225_RAM_ADDR_SET1); + DC_D; + tft_Write_16(x); + + addr_col = x; + } + + // No need to send y if it has not changed (speeds things up) + if (addr_row != y) { + DC_C; + tft_Write_8(ILI9225_VERTICAL_WINDOW_ADDR1); + DC_D; + tft_Write_16(y); + DC_C; + tft_Write_8(ILI9225_VERTICAL_WINDOW_ADDR2); + DC_D; + tft_Write_16(y); + DC_C; + tft_Write_8(ILI9225_RAM_ADDR_SET2); + DC_D; + tft_Write_16(y); + + addr_row = y; + } + + DC_C; + tft_Write_8(ILI9225_GRAM_DATA_REG); + DC_D; + tft_Write_16(color); + + CS_H; +#else #if !defined (RPI_ILI9486_DRIVER) uint32_t xaw = ((uint32_t)x << 16) | x; uint32_t yaw = ((uint32_t)y << 16) | y; @@ -3111,6 +3233,7 @@ void TFT_eSPI::drawPixel(uint32_t x, uint32_t y, uint32_t color) CS_H; +#endif spi_end(); } #endif diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 5729a37..f6dccf5 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -529,7 +529,7 @@ class TFT_eSPI : public Print { void init(uint8_t tc = TAB_COLOUR), begin(uint8_t tc = TAB_COLOUR); // Same - begin included for backwards compatibility // These are virtual so the TFT_eSprite class can override them with sprite specific functions - virtual void drawPixel(uint32_t x, uint32_t y, uint32_t color), + virtual void drawPixel(int32_t x, int32_t y, uint32_t color), drawChar(int32_t x, int32_t y, unsigned char c, uint32_t color, uint32_t bg, uint8_t size), drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color), drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color),