Commit f96c4225 authored by Bodmer's avatar Bodmer

Add support for choosing colour order on ST7735

See #639
parent c8c63172
......@@ -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
......
......@@ -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
......@@ -147,6 +147,7 @@
else
{
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);
}
}
......@@ -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;
*/
}
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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!
......
......@@ -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
......
{
"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":
......
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment