diff --git a/TFT_Drivers/Basic_Rotation.h b/TFT_Drivers/Basic_Rotation.h new file mode 100644 index 0000000..50029f5 --- /dev/null +++ b/TFT_Drivers/Basic_Rotation.h @@ -0,0 +1,43 @@ +// This is the command sequence that rotates the ST7735/ILI9163/S6D02A1 driver coordinate frame + + rotation = m % 4; // Limit the range of values to 0-3 + + writecommand(TFT_MADCTL); + switch (rotation) { + case 0: + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_COLOR_ORDER); + _width = _width_orig; + _height = _height_orig; +#ifdef CGRAM_OFFSET + colstart = R0_OFFSET_X; + rowstart = R0_OFFSET_Y; +#endif + break; + case 1: + writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_COLOR_ORDER); + _width = _height_orig; + _height = _width_orig; +#ifdef CGRAM_OFFSET + colstart = R1_OFFSET_X; + rowstart = R1_OFFSET_Y; +#endif + break; + case 2: + writedata(TFT_COLOR_ORDER); + _width = _width_orig; + _height = _height_orig; +#ifdef CGRAM_OFFSET + colstart = R2_OFFSET_X; + rowstart = R2_OFFSET_Y; +#endif + break; + case 3: + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_COLOR_ORDER); + _width = _height_orig; + _height = _width_orig; +#ifdef CGRAM_OFFSET + colstart = R3_OFFSET_X; + rowstart = R3_OFFSET_Y; +#endif + break; + } diff --git a/TFT_Drivers/ILI9163_Defines.h b/TFT_Drivers/ILI9163_Defines.h index 0aa230c..dfd8813 100644 --- a/TFT_Drivers/ILI9163_Defines.h +++ b/TFT_Drivers/ILI9163_Defines.h @@ -56,3 +56,6 @@ #define TFT_INVOFF 0x20 #define TFT_INVON 0x21 + +// Defines pixel color configuration: RGB/BGR +#define TFT_COLOR_ORDER TFT_MAD_BGR diff --git a/TFT_Drivers/ILI9163_Rotation.h b/TFT_Drivers/ILI9163_Rotation.h deleted file mode 100644 index eebfea5..0000000 --- a/TFT_Drivers/ILI9163_Rotation.h +++ /dev/null @@ -1,56 +0,0 @@ - -// This is the command sequence that rotates the ILI9163 driver coordinate frame - - rotation = m % 4; - - writecommand(TFT_MADCTL); - switch (rotation) { - case 0: - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR); - _width = _width_orig; - _height = _height_orig; -#if CGRAM_OFFSET == OFFSET_FROM_START - colstart = 0; - rowstart = 32; -#else - colstart = 0; - rowstart = 0; -#endif - break; - case 1: - writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_BGR); - _width = _height_orig; - _height = _width_orig; -#if CGRAM_OFFSET == OFFSET_FROM_START - colstart = 32; - rowstart = 0; -#else - colstart = 0; - rowstart = 0; -#endif - break; - case 2: - writedata(TFT_MAD_BGR); - _width = _width_orig; - _height = _height_orig; -#if CGRAM_OFFSET == OFFSET_FROM_START - colstart = 0; - rowstart = 0; -#else - colstart = 0; - rowstart = 32; -#endif - break; - case 3: - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); - _width = _height_orig; - _height = _width_orig; -#if CGRAM_OFFSET == OFFSET_FROM_START - colstart = 0; - rowstart = 0; -#else - colstart = 32; - rowstart = 0; -#endif - break; - } diff --git a/TFT_Drivers/S6D02A1_Defines.h b/TFT_Drivers/S6D02A1_Defines.h index 96aea85..d9960ac 100644 --- a/TFT_Drivers/S6D02A1_Defines.h +++ b/TFT_Drivers/S6D02A1_Defines.h @@ -53,3 +53,6 @@ #define TFT_INVOFF 0x20 #define TFT_INVON 0x21 + +// Defines pixel color configuration: RGB/BGR +#define TFT_COLOR_ORDER TFT_MAD_BGR diff --git a/TFT_Drivers/S6D02A1_Rotation.h b/TFT_Drivers/S6D02A1_Rotation.h deleted file mode 100644 index dfa6cdb..0000000 --- a/TFT_Drivers/S6D02A1_Rotation.h +++ /dev/null @@ -1,28 +0,0 @@ - -// This is the command sequence that rotates the S6D02A1 driver coordinate frame - - rotation = m % 4; - - writecommand(TFT_MADCTL); - switch (rotation) { - case 0: - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR); - _width = _width_orig; - _height = _height_orig; - break; - case 1: - writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_BGR); - _width = _height_orig; - _height = _width_orig; - break; - case 2: - writedata(TFT_MAD_BGR); - _width = _width_orig; - _height = _height_orig; - break; - case 3: - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); - _width = _height_orig; - _height = _width_orig; - break; - } diff --git a/TFT_Drivers/ST7735_Defines.h b/TFT_Drivers/ST7735_Defines.h index 5fe2662..6e1b5dd 100644 --- a/TFT_Drivers/ST7735_Defines.h +++ b/TFT_Drivers/ST7735_Defines.h @@ -29,14 +29,38 @@ #elif defined (ST7735_GREENTAB2) #define TAB_COLOUR INITR_GREENTAB2 #define CGRAM_OFFSET + #define R0_OFFSET_X 2 + #define R0_OFFSET_Y 1 + #define R1_OFFSET_X 1 + #define R1_OFFSET_Y 2 + #define R2_OFFSET_X 2 + #define R2_OFFSET_Y 1 + #define R3_OFFSET_X 1 + #define R3_OFFSET_Y 2 #elif defined (ST7735_GREENTAB3) #define TAB_COLOUR INITR_GREENTAB3 #define CGRAM_OFFSET + #define R0_OFFSET_X 2 + #define R0_OFFSET_Y 3 + #define R1_OFFSET_X 3 + #define R1_OFFSET_Y 2 + #define R2_OFFSET_X 2 + #define R2_OFFSET_Y 1 + #define R3_OFFSET_X 1 + #define R3_OFFSET_Y 2 #elif defined (ST7735_GREENTAB128) #define TAB_COLOUR INITR_GREENTAB128 #define CGRAM_OFFSET + #define R0_OFFSET_X 0 + #define R0_OFFSET_Y 32 + #define R1_OFFSET_X 32 + #define R1_OFFSET_Y 0 + #define R2_OFFSET_X 0 + #define R2_OFFSET_Y 0 + #define R3_OFFSET_X 0 + #define R3_OFFSET_Y 0 #elif defined (ST7735_REDTAB) #define TAB_COLOUR INITR_REDTAB @@ -48,6 +72,12 @@ #define TAB_COLOUR INITR_BLACKTAB #endif +#if defined(ST7735_BLACKTAB) || defined(INITR_GREENTAB2) + #define TFT_COLOR_ORDER TFT_MAD_RGB +#else + #define TFT_COLOR_ORDER TFT_MAD_BGR +#endif + // Color definitions for backwards compatibility with old sketches // use colour definitions like TFT_BLACK to make sketches more portable diff --git a/TFT_Drivers/ST7735_Rotation.h b/TFT_Drivers/ST7735_Rotation.h deleted file mode 100644 index 6113886..0000000 --- a/TFT_Drivers/ST7735_Rotation.h +++ /dev/null @@ -1,115 +0,0 @@ - -// This is the command sequence that rotates the ST7735 driver coordinate frame - - rotation = m % 4; // Limit the range of values to 0-3 - - writecommand(TFT_MADCTL); - switch (rotation) { - case 0: - if (tabcolor == INITR_BLACKTAB) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_RGB); - } else if(tabcolor == INITR_GREENTAB2) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_RGB); - colstart = 2; - rowstart = 1; - } else if(tabcolor == INITR_GREENTAB3) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR); - colstart = 2; - rowstart = 3; - } else if(tabcolor == INITR_GREENTAB128) { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MH | TFT_MAD_BGR); - colstart = 0; - rowstart = 32; - } else { - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR); - } - _width = _width_orig; - _height = _height_orig; - break; - case 1: - if (tabcolor == INITR_BLACKTAB) { - writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_RGB); - } else if(tabcolor == INITR_GREENTAB2) { - writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_RGB); - colstart = 1; - rowstart = 2; - } else if(tabcolor == INITR_GREENTAB3) { - writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR); - colstart = 3; - rowstart = 2; - } else if(tabcolor == INITR_GREENTAB128) { - writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_BGR); - colstart = 32; - rowstart = 0; - } else { - writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR); - } - _width = _height_orig; - _height = _width_orig; - break; - case 2: - if (tabcolor == INITR_BLACKTAB) { - writedata(TFT_MAD_RGB); - } else if(tabcolor == INITR_GREENTAB2) { - writedata(TFT_MAD_RGB); - colstart = 2; - rowstart = 1; - } else if(tabcolor == INITR_GREENTAB3) { - writedata(TFT_MAD_BGR); - colstart = 2; - rowstart = 1; - } else if(tabcolor == INITR_GREENTAB128) { - writedata(TFT_MAD_BGR); - colstart = 0; - rowstart = 0; - } else { - writedata(TFT_MAD_BGR); - } - _width = _width_orig; - _height = _height_orig; - break; - case 3: - if (tabcolor == INITR_BLACKTAB) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_RGB); - } else if(tabcolor == INITR_GREENTAB2) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_RGB); - colstart = 1; - rowstart = 2; - } else if(tabcolor == INITR_GREENTAB3) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); - colstart = 1; - rowstart = 2; - } else if(tabcolor == INITR_GREENTAB128) { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); - colstart = 0; - rowstart = 0; - } else { - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR); - } - _width = _height_orig; - _height = _width_orig; - 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 = _width_orig; - _height = _height_orig; - break; - case 5: - writedata(ST7735_TFT_MAD_MV | ST7735_TFT_MAD_MX | ST7735_TFT_MAD_BGR); - _width = _height_orig; - _height = _width_orig; - break; - case 6: - writedata(ST7735_TFT_MAD_BGR); - _width = _width_orig; - _height = _height_orig; - break; - case 7: - writedata(ST7735_TFT_MAD_MY | ST7735_TFT_MAD_MV | ST7735_TFT_MAD_BGR); - _width = _height_orig; - _height = _width_orig; - break; - */ - } diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index ea82c7b..3b3007e 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -277,21 +277,12 @@ void TFT_eSPI::setRotation(uint8_t m) spi_begin(); // This loads the driver specific rotation code <<<<<<<<<<<<<<<<<<<<< ADD NEW DRIVERS TO THE LIST HERE <<<<<<<<<<<<<<<<<<<<<<< -#if defined (ILI9341_DRIVER) +#if defined (ILI9341_DRIVER) #include "TFT_Drivers/ILI9341_Rotation.h" - -#elif defined (ST7735_DRIVER) - #include "TFT_Drivers/ST7735_Rotation.h" - -#elif defined (ILI9163_DRIVER) - #include "TFT_Drivers/ILI9163_Rotation.h" - -#elif defined (S6D02A1_DRIVER) - #include "TFT_Drivers/S6D02A1_Rotation.h" - #elif defined (RPI_ILI9486_DRIVER) #include "TFT_Drivers/RPI_ILI9486_Rotation.h" - +#else + #include "TFT_Drivers/Basic_Rotation.h" #endif delayMicroseconds(10); diff --git a/User_Setups/Setup8_ILI9163_128x128.h b/User_Setups/Setup8_ILI9163_128x128.h index a273d18..015f59b 100644 --- a/User_Setups/Setup8_ILI9163_128x128.h +++ b/User_Setups/Setup8_ILI9163_128x128.h @@ -14,20 +14,23 @@ // ################################################################################## // Only define one driver, the other ones must be commented out -//#define ILI9341_DRIVER -//#define ST7735_DRIVER #define ILI9163_DRIVER // For ST7735 and ILI9163 ONLY, define the pixel width and height in portrait orientation #define TFT_WIDTH 128 #define TFT_HEIGHT 128 -// There are two variants of 128x128 IL9163. One has CGRAM offset due to unused 32 lines on the beginning of the memory, and one on the end -// If You see that your screen is shifted by 32 pixel change to other setting -#ifndef CGRAM_OFFSET - //#define CGRAM_OFFSET OFFSET_FROM_START - #define CGRAM_OFFSET OFFSET_FROM_END -#endif +// Multiple variants of CGRAM to display mapping exist. Here define offset for x and y axis for each rotation. Offsets are used in Basic_Rotation.h +#define CGRAM_OFFSET +#define R0_OFFSET_X 0 +#define R0_OFFSET_Y 0 +#define R1_OFFSET_X 0 +#define R1_OFFSET_Y 0 +#define R2_OFFSET_X 0 +#define R2_OFFSET_Y 32 +#define R3_OFFSET_X 32 +#define R3_OFFSET_Y 0 + // // ################################################################################## //