From f7e9a91eade601e05dc091de5586eb8779eaa2d6 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Thu, 28 Apr 2022 14:19:05 +0100 Subject: [PATCH] Fix #1800 Fix #1793 Added offsets for 170x320 ST7789 display Added offsets for 240x280 display to ST7789_2 dirver --- TFT_Drivers/ST7789_2_Defines.h | 20 ++++ TFT_Drivers/ST7789_2_Rotation.h | 202 +++++++++++++++++++++++++++++++- TFT_Drivers/ST7789_Defines.h | 6 + TFT_Drivers/ST7789_Rotation.h | 20 ++++ 4 files changed, 247 insertions(+), 1 deletion(-) diff --git a/TFT_Drivers/ST7789_2_Defines.h b/TFT_Drivers/ST7789_2_Defines.h index 9440b75..b2e5322 100644 --- a/TFT_Drivers/ST7789_2_Defines.h +++ b/TFT_Drivers/ST7789_2_Defines.h @@ -20,6 +20,26 @@ #endif #endif +// Adafruit 1.69 round corner TFT support +#if (TFT_HEIGHT == 280) && (TFT_WIDTH == 240) + #ifndef CGRAM_OFFSET + #define CGRAM_OFFSET + #endif +#endif + +// 1.47" 172x320 Round Rectangle Color IPS TFT Display +#if (TFT_HEIGHT == 320) && (TFT_WIDTH == 172) + #ifndef CGRAM_OFFSET + #define CGRAM_OFFSET + #endif +#endif + +#if (TFT_HEIGHT == 300) && (TFT_WIDTH == 240) + #ifndef CGRAM_OFFSET + #define CGRAM_OFFSET + #endif +#endif + // Delay between some initialisation commands #define TFT_INIT_DELAY 0x80 // Not used unless commandlist invoked diff --git a/TFT_Drivers/ST7789_2_Rotation.h b/TFT_Drivers/ST7789_2_Rotation.h index 44a363e..5bb8131 100644 --- a/TFT_Drivers/ST7789_2_Rotation.h +++ b/TFT_Drivers/ST7789_2_Rotation.h @@ -10,6 +10,21 @@ colstart = 52; rowstart = 40; } + else if(_init_height == 280) + { + colstart = 0; + rowstart = 20; + } + else if(_init_width == 172) + { + colstart = 34; + rowstart = 0; + } + else if(_init_width == 170) + { + colstart = 35; + rowstart = 0; + } else { colstart = 0; @@ -29,6 +44,21 @@ colstart = 40; rowstart = 53; } + else if(_init_height == 280) + { + colstart = 20; + rowstart = 0; + } + else if(_init_width == 172) + { + colstart = 0; + rowstart = 34; + } + else if(_init_width == 170) + { + colstart = 0; + rowstart = 35; + } else { colstart = 0; @@ -41,13 +71,28 @@ _height = _init_width; break; - case 2: // Inverter portrait + case 2: // Inverter portrait #ifdef CGRAM_OFFSET if (_init_width == 135) { colstart = 53; rowstart = 40; } + else if(_init_height == 280) + { + colstart = 0; + rowstart = 20; + } + else if(_init_width == 172) + { + colstart = 34; + rowstart = 0; + } + else if(_init_width == 170) + { + colstart = 35; + rowstart = 0; + } else { colstart = 0; @@ -66,6 +111,161 @@ colstart = 40; rowstart = 52; } + else if(_init_height == 280) + { + colstart = 20; + rowstart = 0; + } + else if(_init_width == 172) + { + colstart = 0; + rowstart = 34; + } + else if(_init_width == 170) + { + colstart = 0; + rowstart = 35; + } + else + { + colstart = 80; + rowstart = 0; + } +#endif + writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); + + _width = _init_height; + _height = _init_width; + break; + } + // This is the command sequence that rotates the ST7789 driver coordinate frame + + writecommand(TFT_MADCTL); + rotation = m % 4; + switch (rotation) { + case 0: // Portrait +#ifdef CGRAM_OFFSET + if (_init_width == 135) + { + colstart = 52; + rowstart = 40; + } + else if(_init_height == 280) + { + colstart = 0; + rowstart = 20; + } + else if(_init_width == 172) + { + colstart = 34; + rowstart = 0; + } + else if(_init_width == 170) + { + colstart = 35; + rowstart = 0; + } + else + { + colstart = 0; + rowstart = 0; + } +#endif + writedata(TFT_MAD_COLOR_ORDER); + + _width = _init_width; + _height = _init_height; + break; + + case 1: // Landscape (Portrait + 90) +#ifdef CGRAM_OFFSET + if (_init_width == 135) + { + colstart = 40; + rowstart = 53; + } + else if(_init_height == 280) + { + colstart = 20; + rowstart = 0; + } + else if(_init_width == 172) + { + colstart = 0; + rowstart = 34; + } + else if(_init_width == 170) + { + colstart = 0; + rowstart = 35; + } + else + { + colstart = 0; + rowstart = 0; + } +#endif + writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); + + _width = _init_height; + _height = _init_width; + break; + + case 2: // Inverter portrait +#ifdef CGRAM_OFFSET + if (_init_width == 135) + { + colstart = 53; + rowstart = 40; + } + else if(_init_height == 280) + { + colstart = 0; + rowstart = 20; + } + else if(_init_width == 172) + { + colstart = 34; + rowstart = 0; + } + else if(_init_width == 170) + { + colstart = 35; + rowstart = 0; + } + else + { + colstart = 0; + rowstart = 80; + } +#endif + writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); + + _width = _init_width; + _height = _init_height; + break; + case 3: // Inverted landscape +#ifdef CGRAM_OFFSET + if (_init_width == 135) + { + colstart = 40; + rowstart = 52; + } + else if(_init_height == 280) + { + colstart = 20; + rowstart = 0; + } + else if(_init_width == 172) + { + colstart = 0; + rowstart = 34; + } + else if(_init_width == 170) + { + colstart = 0; + rowstart = 35; + } else { colstart = 80; diff --git a/TFT_Drivers/ST7789_Defines.h b/TFT_Drivers/ST7789_Defines.h index 13ea722..b0ef25e 100644 --- a/TFT_Drivers/ST7789_Defines.h +++ b/TFT_Drivers/ST7789_Defines.h @@ -34,6 +34,12 @@ #endif #endif +#if (TFT_HEIGHT == 300) && (TFT_WIDTH == 240) + #ifndef CGRAM_OFFSET + #define CGRAM_OFFSET + #endif +#endif + // Delay between some initialisation commands #define TFT_INIT_DELAY 0x80 // Not used unless commandlist invoked diff --git a/TFT_Drivers/ST7789_Rotation.h b/TFT_Drivers/ST7789_Rotation.h index b3b8963..df5860c 100644 --- a/TFT_Drivers/ST7789_Rotation.h +++ b/TFT_Drivers/ST7789_Rotation.h @@ -20,6 +20,11 @@ colstart = 34; rowstart = 0; } + else if(_init_width == 170) + { + colstart = 35; + rowstart = 0; + } else { colstart = 0; @@ -49,6 +54,11 @@ colstart = 0; rowstart = 34; } + else if(_init_width == 170) + { + colstart = 0; + rowstart = 35; + } else { colstart = 0; @@ -78,6 +88,11 @@ colstart = 34; rowstart = 0; } + else if(_init_width == 170) + { + colstart = 35; + rowstart = 0; + } else { colstart = 0; @@ -106,6 +121,11 @@ colstart = 0; rowstart = 34; } + else if(_init_width == 170) + { + colstart = 0; + rowstart = 35; + } else { colstart = 80;