diff --git a/TFT_Drivers/ST7735_Defines.h b/TFT_Drivers/ST7735_Defines.h index 494c673..1e02c1d 100644 --- a/TFT_Drivers/ST7735_Defines.h +++ b/TFT_Drivers/ST7735_Defines.h @@ -106,6 +106,20 @@ #define TFT_MAD_MH 0x04 #define TFT_MAD_RGB 0x00 +#ifndef TFT_RGB_ORDER + #if defined(INITR_BLACKTAB) || defined(INITR_GREENTAB2) || defined(INITB) + #define TFT_MAD_COLOR_ORDER TFT_MAD_RGB + #else + #define TFT_MAD_COLOR_ORDER TFT_MAD_BGR + #endif +#else + #if (TFT_RGB_ORDER == 1) + #define TFT_MAD_COLOR_ORDER TFT_MAD_RGB + #else + #define TFT_MAD_COLOR_ORDER TFT_MAD_BGR + #endif +#endif + #define TFT_INVOFF 0x20 #define TFT_INVON 0x21 diff --git a/TFT_Drivers/ST7735_Init.h b/TFT_Drivers/ST7735_Init.h index a528785..08e2913 100644 --- a/TFT_Drivers/ST7735_Init.h +++ b/TFT_Drivers/ST7735_Init.h @@ -24,7 +24,7 @@ 0x03, // 3 lines back porch 10, // 10 ms delay ST7735_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg: - 0x40, // Row addr/col addr, bottom to top refresh + 0x40 | TFT_MAD_COLOR_ORDER, // Row addr/col addr, bottom to top refresh ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay: 0x15, // 1 clk cycle nonoverlap, 2 cycle gate // rise, 3 cycle osc equalize @@ -101,7 +101,7 @@ 0x0E, ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg: - 0xC8, // row addr/col addr, bottom to top refresh + 0xC0 | TFT_MAD_COLOR_ORDER, // row addr/col addr, bottom to top refresh ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay: 0x05 }, // 16-bit color @@ -146,7 +146,8 @@ } else { - commandList(Rcmd1); + commandList(Rcmd1); + if (tabcolor == INITR_GREENTAB) { commandList(Rcmd2green); @@ -157,7 +158,7 @@ { commandList(Rcmd2green); writecommand(ST7735_MADCTL); - writedata(0xC0); + writedata(0xC0 | TFT_MAD_COLOR_ORDER); colstart = 2; rowstart = 1; } @@ -193,8 +194,9 @@ else if (tabcolor == INITR_BLACKTAB) { writecommand(ST7735_MADCTL); - writedata(0xC0); + writedata(0xC0 | TFT_MAD_COLOR_ORDER); } + commandList(Rcmd3); } } diff --git a/TFT_Drivers/ST7735_Rotation.h b/TFT_Drivers/ST7735_Rotation.h index 73df2ab..3c17b71 100644 --- a/TFT_Drivers/ST7735_Rotation.h +++ b/TFT_Drivers/ST7735_Rotation.h @@ -7,149 +7,126 @@ switch (rotation) { case 0: if (tabcolor == INITR_BLACKTAB) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_RGB); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); } else if(tabcolor == INITR_GREENTAB2) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_RGB); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); colstart = 2; rowstart = 1; } else if(tabcolor == INITR_GREENTAB3) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); colstart = 2; rowstart = 3; } else if(tabcolor == INITR_GREENTAB128) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MH | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MH | TFT_MAD_COLOR_ORDER); colstart = 0; rowstart = 32; } else if(tabcolor == INITR_GREENTAB160x80) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MH | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MH | TFT_MAD_COLOR_ORDER); colstart = 26; rowstart = 1; } else if(tabcolor == INITR_REDTAB160x80) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MH | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MH | TFT_MAD_COLOR_ORDER); colstart = 24; rowstart = 0; } else if(tabcolor == INITB) { - writedata(TFT_MAD_MX | TFT_MAD_RGB); + writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER); } else { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); } _width = _init_width; _height = _init_height; break; case 1: if (tabcolor == INITR_BLACKTAB) { - writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_RGB); + writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); } else if(tabcolor == INITR_GREENTAB2) { - writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_RGB); + writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); colstart = 1; rowstart = 2; } else if(tabcolor == INITR_GREENTAB3) { - writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR); + writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); colstart = 3; rowstart = 2; } else if(tabcolor == INITR_GREENTAB128) { - writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_BGR); + writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); colstart = 32; rowstart = 0; } else if(tabcolor == INITR_GREENTAB160x80) { - writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_BGR); + writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); colstart = 1; rowstart = 26; } else if(tabcolor == INITR_REDTAB160x80) { - writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_BGR); + writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); colstart = 0; rowstart = 24; } else if(tabcolor == INITB) { - writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_RGB); + writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); } else { - writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR); + writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); } _width = _init_height; _height = _init_width; break; case 2: if (tabcolor == INITR_BLACKTAB) { - writedata(TFT_MAD_RGB); + writedata(TFT_MAD_COLOR_ORDER); } else if(tabcolor == INITR_GREENTAB2) { - writedata(TFT_MAD_RGB); + writedata(TFT_MAD_COLOR_ORDER); colstart = 2; rowstart = 1; } else if(tabcolor == INITR_GREENTAB3) { - writedata(TFT_MAD_BGR); + writedata(TFT_MAD_COLOR_ORDER); colstart = 2; rowstart = 1; } else if(tabcolor == INITR_GREENTAB128) { - writedata(TFT_MAD_BGR); + writedata(TFT_MAD_COLOR_ORDER); colstart = 0; rowstart = 0; } else if(tabcolor == INITR_GREENTAB160x80) { - writedata(TFT_MAD_BGR); + writedata(TFT_MAD_COLOR_ORDER); colstart = 26; rowstart = 1; } else if(tabcolor == INITR_REDTAB160x80) { - writedata(TFT_MAD_BGR); + writedata(TFT_MAD_COLOR_ORDER); colstart = 24; rowstart = 0; } else if(tabcolor == INITB) { - writedata(TFT_MAD_MY | TFT_MAD_RGB); + writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER); } else { - writedata(TFT_MAD_BGR); + writedata(TFT_MAD_COLOR_ORDER); } _width = _init_width; _height = _init_height; break; case 3: if (tabcolor == INITR_BLACKTAB) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_RGB); + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); } else if(tabcolor == INITR_GREENTAB2) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_RGB); + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); colstart = 1; rowstart = 2; } else if(tabcolor == INITR_GREENTAB3) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); colstart = 1; rowstart = 2; } else if(tabcolor == INITR_GREENTAB128) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); colstart = 0; rowstart = 0; } else if(tabcolor == INITR_GREENTAB160x80) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); colstart = 1; rowstart = 26; } else if(tabcolor == INITR_REDTAB160x80) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); colstart = 0; rowstart = 24; } else if(tabcolor == INITB) { - writedata(TFT_MAD_MV | TFT_MAD_RGB); + writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER); } else { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); } _width = _init_height; _height = _init_width; break; - - // These next rotations are for bottum up BMP drawing - /* case 4: - writedata(ST7735_TFT_MAD_MX | ST7735_TFT_MAD_MY | ST7735_TFT_MAD_BGR); - _width = _init_width; - _height = _init_height; - break; - case 5: - writedata(ST7735_TFT_MAD_MV | ST7735_TFT_MAD_MX | ST7735_TFT_MAD_BGR); - _width = _init_height; - _height = _init_width; - break; - case 6: - writedata(ST7735_TFT_MAD_BGR); - _width = _init_width; - _height = _init_height; - break; - case 7: - writedata(ST7735_TFT_MAD_MY | ST7735_TFT_MAD_MV | ST7735_TFT_MAD_BGR); - _width = _init_height; - _height = _init_width; - break; - */ } diff --git a/TFT_eSPI.h b/TFT_eSPI.h index dc17d34..9b06a75 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.3" +#define TFT_ESPI_VERSION "2.3.4" // Bit level feature flags // Bit 0 set: viewport capability diff --git a/User_Setup.h b/User_Setup.h index 0fb8bf4..3297b26 100644 --- a/User_Setup.h +++ b/User_Setup.h @@ -60,7 +60,7 @@ // #define TFT_SDA_READ // This option is for ESP32 ONLY, tested with ST7789 display only -// For ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display +// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display // Try ONE option at a time to find the correct colour order for your display // #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue diff --git a/User_Setups/Setup2_ST7735.h b/User_Setups/Setup2_ST7735.h index b9e618f..3832601 100644 --- a/User_Setups/Setup2_ST7735.h +++ b/User_Setups/Setup2_ST7735.h @@ -9,6 +9,11 @@ #define ST7735_REDTAB +// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display +// Try ONE option at a time to find the correct colour order for your display + +// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue +// #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red // For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation #define TFT_CS PIN_D8 // Chip select control pin D8 diff --git a/User_Setups/Setup43_ST7735.h b/User_Setups/Setup43_ST7735.h index 46f6e7e..520f8c9 100644 --- a/User_Setups/Setup43_ST7735.h +++ b/User_Setups/Setup43_ST7735.h @@ -11,6 +11,12 @@ #define ST7735_GREENTAB160x80 +// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display +// Try ONE option at a time to find the correct colour order for your display + +// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue +// #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red + #ifdef ESP32 #define TFT_MISO 19 #define TFT_MOSI 23 diff --git a/User_Setups/Setup7_ST7735_128x128.h b/User_Setups/Setup7_ST7735_128x128.h index 6821f47..828bfc6 100644 --- a/User_Setups/Setup7_ST7735_128x128.h +++ b/User_Setups/Setup7_ST7735_128x128.h @@ -9,6 +9,11 @@ #define ST7735_GREENTAB128 // For 128 x 128 display +// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display +// Try ONE option at a time to find the correct colour order for your display + +// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue +// #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red // For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation #define TFT_CS PIN_D8 // Chip select control pin D8 diff --git a/User_Setups/Setup9_ST7735_Overlap.h b/User_Setups/Setup9_ST7735_Overlap.h index 2c7c82b..4e417c2 100644 --- a/User_Setups/Setup9_ST7735_Overlap.h +++ b/User_Setups/Setup9_ST7735_Overlap.h @@ -9,6 +9,12 @@ #define ST7735_REDTAB +// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display +// Try ONE option at a time to find the correct colour order for your display + +// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue +// #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red + // Overlap mode shares the ESP8266 FLASH SPI bus with the TFT so has a performance impact // but saves pins for other functions. It is best not to connect MISO as some displays // do not tristate that line wjen chip select is high! diff --git a/User_Setups/SetupX_Template.h b/User_Setups/SetupX_Template.h index 32eea56..dbe4aee 100644 --- a/User_Setups/SetupX_Template.h +++ b/User_Setups/SetupX_Template.h @@ -57,7 +57,7 @@ // #define TFT_SDA_READ // This option is for ESP32 ONLY, tested with ST7789 display only -// For ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display +// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display // Try ONE option at a time to find the correct colour order for your display // #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue diff --git a/library.json b/library.json index 1efb790..a353b11 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.3.3", + "version": "2.3.4", "keywords": "Arduino, tft, ePaper, display, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789, RM68140", "description": "A TFT and ePaper SPI graphics library with optimisation for ESP8266, ESP32 and STM32", "repository": diff --git a/library.properties b/library.properties index cddea49..1ac9203 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=2.3.3 +version=2.3.4 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32