From 31b2de56c13ff8aa773acfd45c2403e107b3ab45 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Sat, 12 Mar 2022 20:04:41 +0000 Subject: [PATCH] Update HX8357D driver to support RGB and BGR displays In setup add the following lines: // If green and blue swapped on display then change the RGB colour order // Only uncomment ONE of the following options #define TFT_RGB_ORDER TFT_RGB // Red-Green-Blue //#define TFT_RGB_ORDER TFT_BGR // Blue-Green-RED --- TFT_Drivers/HX8357D_Defines.h | 10 ++++++++++ TFT_Drivers/HX8357D_Init.h | 2 +- TFT_Drivers/HX8357D_Rotation.h | 8 ++++---- User_Setups/Setup15_HX8357D.h | 4 ++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/TFT_Drivers/HX8357D_Defines.h b/TFT_Drivers/HX8357D_Defines.h index 7dcbdad..b3def6c 100644 --- a/TFT_Drivers/HX8357D_Defines.h +++ b/TFT_Drivers/HX8357D_Defines.h @@ -39,6 +39,16 @@ #define TFT_MAD_SS 0x02 #define TFT_MAD_GS 0x01 +#ifdef TFT_RGB_ORDER + #if (TFT_RGB_ORDER == 1) + #define TFT_MAD_COLOR_ORDER TFT_MAD_RGB + #else + #define TFT_MAD_COLOR_ORDER TFT_MAD_BGR + #endif +#else + #define TFT_MAD_COLOR_ORDER TFT_MAD_RGB +#endif + #define TFT_IDXRD 0x00 // ILI9341 only, indexed control register read diff --git a/TFT_Drivers/HX8357D_Init.h b/TFT_Drivers/HX8357D_Init.h index 50389bb..9b5f05a 100644 --- a/TFT_Drivers/HX8357D_Init.h +++ b/TFT_Drivers/HX8357D_Init.h @@ -97,7 +97,7 @@ writedata(0x55); // 16 bit writecommand(HX8357_MADCTL); - writedata(0xC0); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); writecommand(HX8357_TEON); // TE off writedata(0x00); diff --git a/TFT_Drivers/HX8357D_Rotation.h b/TFT_Drivers/HX8357D_Rotation.h index bc40cb3..befe91a 100644 --- a/TFT_Drivers/HX8357D_Rotation.h +++ b/TFT_Drivers/HX8357D_Rotation.h @@ -4,22 +4,22 @@ rotation = m % 4; switch (rotation) { case 0: // Portrait - writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_RGB); + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); _width = TFT_WIDTH; _height = TFT_HEIGHT; break; case 1: // Landscape (Portrait + 90) - writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_RGB); + writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); _width = TFT_HEIGHT; _height = TFT_WIDTH; break; case 2: // Inverter portrait - writedata(TFT_MAD_RGB); + writedata(TFT_MAD_COLOR_ORDER); _width = TFT_WIDTH; _height = TFT_HEIGHT; break; case 3: // Inverted landscape - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_RGB); + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); _width = TFT_HEIGHT; _height = TFT_WIDTH; break; diff --git a/User_Setups/Setup15_HX8357D.h b/User_Setups/Setup15_HX8357D.h index f4ee614..5987451 100644 --- a/User_Setups/Setup15_HX8357D.h +++ b/User_Setups/Setup15_HX8357D.h @@ -2,6 +2,10 @@ #define HX8357D_DRIVER +// If green and blue swapped on display then change the RGB colour order +// Only uncomment ONE of the following options +#define TFT_RGB_ORDER TFT_RGB // Red-Green-Blue +//#define TFT_RGB_ORDER TFT_BGR // 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