diff --git a/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp b/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp index 2ddd4e242..f08561bae 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp +++ b/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp @@ -181,6 +181,17 @@ static const uint8_t PROGMEM 0x00, 0x00, // XSTART = 0 0x00, 0x9F }, // XEND = 159 + #if ST7735_EXTRA_INIT + Rcmd2black135x240[] = { // 7735R init, part 2 (mini 160x80) + 2, // 2 commands in list: + ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay: + 0x00, 0x00, // XSTART = 0 + 0x00, 135, // XEND = 135 + ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay: + 0x00, 0x00, // XSTART = 0 + 240 >> 8, 240 & 0xFF }, // XEND = 240 + #endif // if ST7735_EXTRA_INIT + Rcmd3[] = { // 7735R init, part 3 (red or green tab) 4, // 4 commands in list: ST7735_GMCTRP1, 16 , // 1: Gamma Adjustments (pos. polarity), 16 args + delay: @@ -243,6 +254,15 @@ void Adafruit_ST7735::initR(uint8_t options) { sendCommand(ST77XX_INVON, &data, 0); // Write twice... _colstart = 26; _rowstart = 1; + #if ST7735_EXTRA_INIT + } else if (options == INITR_BLACKTAB135x240) { + _height = ST7735_TFTHEIGHT_240; + _width = ST7735_TFTWIDTH_135; + displayInit(Rcmd2black135x240); + const uint8_t data = 0x00; + sendCommand(ST77XX_INVON, &data, 0); + sendCommand(ST77XX_INVON, &data, 0); // Write twice... + #endif // if ST7735_EXTRA_INIT } else { // colstart, rowstart left at default '0' values displayInit(Rcmd2red); @@ -288,6 +308,10 @@ void Adafruit_ST7735::setRotation(uint8_t m) { case 0: if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) { madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB; + #if ST7735_EXTRA_INIT + } else if (tabcolor == INITR_BLACKTAB135x240) { + madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; + #endif // if ST7735_EXTRA_INIT } else { madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST7735_MADCTL_BGR; } @@ -298,6 +322,13 @@ void Adafruit_ST7735::setRotation(uint8_t m) { } else if (tabcolor == INITR_MINI160x80) { _height = ST7735_TFTHEIGHT_160; _width = ST7735_TFTWIDTH_80; + #if ST7735_EXTRA_INIT + } else if (tabcolor == INITR_BLACKTAB135x240) { + _height = ST7735_TFTHEIGHT_240; + _width = ST7735_TFTWIDTH_135; + _colstart = 52; + _rowstart = 40; + #endif // if ST7735_EXTRA_INIT } else { _height = ST7735_TFTHEIGHT_160; _width = ST7735_TFTWIDTH_128; @@ -308,6 +339,10 @@ void Adafruit_ST7735::setRotation(uint8_t m) { case 1: if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) { madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; + #if ST7735_EXTRA_INIT + } else if (tabcolor == INITR_BLACKTAB135x240) { + madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB; + #endif // if ST7735_EXTRA_INIT } else { madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST7735_MADCTL_BGR; } @@ -318,6 +353,13 @@ void Adafruit_ST7735::setRotation(uint8_t m) { } else if (tabcolor == INITR_MINI160x80) { _width = ST7735_TFTHEIGHT_160; _height = ST7735_TFTWIDTH_80; + #if ST7735_EXTRA_INIT + } else if (tabcolor == INITR_BLACKTAB135x240) { + _width = ST7735_TFTHEIGHT_240; + _height = ST7735_TFTWIDTH_135; + _colstart = 52; + _rowstart = 40; + #endif // if ST7735_EXTRA_INIT } else { _width = ST7735_TFTHEIGHT_160; _height = ST7735_TFTWIDTH_128; @@ -328,6 +370,10 @@ void Adafruit_ST7735::setRotation(uint8_t m) { case 2: if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) { madctl = ST77XX_MADCTL_RGB; + #if ST7735_EXTRA_INIT + } else if (tabcolor == INITR_BLACKTAB135x240) { + madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; + #endif // if ST7735_EXTRA_INIT } else { madctl = ST7735_MADCTL_BGR; } @@ -338,6 +384,13 @@ void Adafruit_ST7735::setRotation(uint8_t m) { } else if (tabcolor == INITR_MINI160x80) { _height = ST7735_TFTHEIGHT_160; _width = ST7735_TFTWIDTH_80; + #if ST7735_EXTRA_INIT + } else if (tabcolor == INITR_BLACKTAB135x240) { + _height = ST7735_TFTHEIGHT_240; + _width = ST7735_TFTWIDTH_135; + _colstart = 52; + _rowstart = 40; + #endif // if ST7735_EXTRA_INIT } else { _height = ST7735_TFTHEIGHT_160; _width = ST7735_TFTWIDTH_128; @@ -348,6 +401,10 @@ void Adafruit_ST7735::setRotation(uint8_t m) { case 3: if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) { madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; + #if ST7735_EXTRA_INIT + } else if (tabcolor == INITR_BLACKTAB135x240) { + madctl = ST77XX_MADCTL_RGB; + #endif // if ST7735_EXTRA_INIT } else { madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST7735_MADCTL_BGR; } @@ -358,6 +415,13 @@ void Adafruit_ST7735::setRotation(uint8_t m) { } else if (tabcolor == INITR_MINI160x80) { _width = ST7735_TFTHEIGHT_160; _height = ST7735_TFTWIDTH_80; + #if ST7735_EXTRA_INIT + } else if (tabcolor == INITR_BLACKTAB135x240) { + _width = ST7735_TFTHEIGHT_240; + _height = ST7735_TFTWIDTH_135; + _colstart = 52; + _rowstart = 40; + #endif // if ST7735_EXTRA_INIT } else { _width = ST7735_TFTHEIGHT_160; _height = ST7735_TFTWIDTH_128; diff --git a/lib/Adafruit_ST77xx/Adafruit_ST7735.h b/lib/Adafruit_ST77xx/Adafruit_ST7735.h index 6d138bce3..935dda4e3 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST7735.h +++ b/lib/Adafruit_ST77xx/Adafruit_ST7735.h @@ -3,6 +3,22 @@ #include "Adafruit_ST77xx.h" +/** + * 2024-03-17 tonhuisman: Add additional initialization sequences for ST7735 displays, with the intention to get 'm working + * on some devices that seem to use peculiarly configured hardware like LiliGO TTGO T-Display (16MB flash), + * and possibly the T-Display S3 + * By default only enabled on ESP32, unless -D ST7735_EXTRA_INIT=1 is defined, f.e. via the build script + */ + +#ifndef ST7735_EXTRA_INIT // Enable setting from 'outside', like Platformio.ini +# ifdef ESP8266 +# define ST7735_EXTRA_INIT 0 +# endif // ifdef ESP8266 +# ifdef ESP32 +# define ST7735_EXTRA_INIT 1 +# endif // ifdef ESP32 +#endif + // some flags for initR() :( #define INITR_GREENTAB 0x00 #define INITR_REDTAB 0x01 @@ -14,6 +30,7 @@ #define INITR_MINI160x80 0x04 #define INITR_HALLOWING 0x05 #define INITR_GREENTAB160x80 0x06 +#define INITR_BLACKTAB135x240 0x07 // Some register settings #define ST7735_MADCTL_BGR 0x08 diff --git a/lib/Adafruit_ST77xx/Adafruit_ST7789.cpp b/lib/Adafruit_ST77xx/Adafruit_ST7789.cpp index dca4b6997..6467aeb53 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST7789.cpp +++ b/lib/Adafruit_ST77xx/Adafruit_ST7789.cpp @@ -79,7 +79,7 @@ static const uint8_t PROGMEM #if ST7789_EXTRA_INIT static const uint8_t PROGMEM // Source: https://github.com/Xinyuan-LilyGO/TTGO-T-Display alt1_st7789[] = { // Init commands for 7789 screens Alternative 1 - 20, // 20 commands in list: + 21, // 21 commands in list: ST77XX_SLPOUT, ST_CMD_DELAY, // 1: Out of sleep mode, no args, w/delay 120, // 120 ms delay ST77XX_NORON, ST_CMD_DELAY, // 2: Normal display on, no args, w/delay @@ -125,8 +125,10 @@ static const uint8_t PROGMEM // Source: https://github.com/Xinyuan-LilyGO 0, // YSTART = 0 320>>8, 320&0xFF, // YEND = 320 - ST77XX_DISPON, ST_CMD_DELAY, // 20: Main screen turn on, no args, delay - 120 // 120 ms delay + ST77XX_INVON, ST_CMD_DELAY, // 20: Normal display on, no args, w/delay + 10, // 10 ms delay + ST77XX_DISPON, ST_CMD_DELAY, // 21: Main screen turn on, no args, delay + 255 // 120 ms delay }; static const uint8_t PROGMEM // Source: https://github.com/Bodmer/TFT_eSPI (ST7789_init.h, _NOT_ INIT_SEQUENCE_3) @@ -260,6 +262,8 @@ void Adafruit_ST7789::init(uint16_t width, uint16_t height, uint8_t mode, uint8_ // (Might get added similarly to other display types as needed on a // case-by-case basis.) + _init_seq = init_seq; + commonInit(NULL); if (width < 240) { @@ -285,11 +289,11 @@ void Adafruit_ST7789::init(uint16_t width, uint16_t height, uint8_t mode, uint8_ const uint8_t *init_ = generic_st7789; #if ST7789_EXTRA_INIT - if (1 == init_seq) { + if (1 == _init_seq) { init_ = alt1_st7789; - } else if (2 == init_seq) { + } else if (2 == _init_seq) { init_ = alt2_st7789; - } else if (3 == init_seq) { + } else if (3 == _init_seq) { init_ = alt3_st7789; } #endif // if ST7789_EXTRA_INIT @@ -310,28 +314,64 @@ void Adafruit_ST7789::setRotation(uint8_t m) { switch (rotation) { case 0: - madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB; + #if ST7789_EXTRA_INIT + if (_init_seq > 0) { + madctl = ST77XX_MADCTL_BGR; + _colstart = 52; + _rowstart = 40; + } else + #endif // if ST7789_EXTRA_INIT + { + madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB; + } _xstart = _colstart; _ystart = _rowstart; _width = windowWidth; _height = windowHeight; break; case 1: - madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; + #if ST7789_EXTRA_INIT + if (_init_seq > 0) { + madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_BGR; + _colstart = 40; + _rowstart = 53; + } else + #endif // if ST7789_EXTRA_INIT + { + madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; + } _xstart = _rowstart; _ystart = _colstart; _height = windowWidth; _width = windowHeight; break; case 2: - madctl = ST77XX_MADCTL_RGB; + #if ST7789_EXTRA_INIT + if (_init_seq > 0) { + madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB; + _colstart2 = 53; + _rowstart2 = 40; + } else + #endif // if ST7789_EXTRA_INIT + { + madctl = ST77XX_MADCTL_RGB; + } _xstart = _colstart2; _ystart = _rowstart2; _width = windowWidth; _height = windowHeight; break; case 3: - madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; + #if ST7789_EXTRA_INIT + if (_init_seq > 0) { + madctl = ST77XX_MADCTL_MV | ST77XX_MADCTL_MY | ST77XX_MADCTL_BGR; + _colstart2 = 40; + _rowstart2 = 52; + } else + #endif // if ST7789_EXTRA_INIT + { + madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; + } _xstart = _rowstart2; _ystart = _colstart2; _height = windowWidth; diff --git a/lib/Adafruit_ST77xx/Adafruit_ST7789.h b/lib/Adafruit_ST77xx/Adafruit_ST7789.h index 865780bc0..4714a9968 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST7789.h +++ b/lib/Adafruit_ST77xx/Adafruit_ST7789.h @@ -39,6 +39,7 @@ protected: private: uint16_t windowWidth; uint16_t windowHeight; + uint8_t _init_seq = 0u; }; #endif // _ADAFRUIT_ST7789H_ diff --git a/lib/Adafruit_ST77xx/Adafruit_ST77xx.h b/lib/Adafruit_ST77xx/Adafruit_ST77xx.h index 2ad2a6326..9a299b51f 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST77xx.h +++ b/lib/Adafruit_ST77xx/Adafruit_ST77xx.h @@ -33,8 +33,10 @@ #define ST7735_TFTWIDTH_128 128 // for 1.44 and mini #define ST7735_TFTWIDTH_80 80 // for mini +#define ST7735_TFTWIDTH_135 135 #define ST7735_TFTHEIGHT_128 128 // for 1.44" display #define ST7735_TFTHEIGHT_160 160 // for 1.8" and mini display +#define ST7735_TFTHEIGHT_240 240 #define ST_CMD_DELAY 0x80 // special signifier for command lists @@ -104,6 +106,7 @@ #define ST77XX_MADCTL_MV 0x20 #define ST77XX_MADCTL_ML 0x10 #define ST77XX_MADCTL_RGB 0x00 +#define ST77XX_MADCTL_BGR 0x08 #define ST77XX_RDID1 0xDA #define ST77XX_RDID2 0xDB diff --git a/src/_P116_ST77xx.ino b/src/_P116_ST77xx.ino index 3352d9149..ac85828e8 100644 --- a/src/_P116_ST77xx.ino +++ b/src/_P116_ST77xx.ino @@ -8,6 +8,10 @@ // History: +// 2024-03-17 tonhuisman: Add support for another alternative initialization for ST7735 displays, as the display controller +// used on the LilyGO TTGO T-Display (16 MB) seems to be a ST7735, despite being documented as ST7789 +// By default (also) only enabled on ESP32 builds +// Disabled the ST7789 alternatives for now, as that's not verified on any hardware // 2024-03-09 tonhuisman: Add support for alternative initialization sequences for ST7789 displays, like used on // some LilyGO models like the TTGO T-Display (16 MB Flash), and possibly the T-Display S3 // By default only enabled on ESP32 builds @@ -145,6 +149,9 @@ boolean Plugin_116(uint8_t function, struct EventStruct *event, String& string) ST77xx_type_toString(ST77xx_type_e::ST7735s_128x160), ST77xx_type_toString(ST77xx_type_e::ST7735s_80x160), ST77xx_type_toString(ST77xx_type_e::ST7735s_80x160_M5), + # if P116_EXTRA_ST7735 + ST77xx_type_toString(ST77xx_type_e::ST7735s_135x240), + # endif // if P116_EXTRA_ST7735 ST77xx_type_toString(ST77xx_type_e::ST7789vw_240x320), ST77xx_type_toString(ST77xx_type_e::ST7789vw_240x240), ST77xx_type_toString(ST77xx_type_e::ST7789vw_240x280), @@ -161,6 +168,9 @@ boolean Plugin_116(uint8_t function, struct EventStruct *event, String& string) static_cast(ST77xx_type_e::ST7735s_128x160), static_cast(ST77xx_type_e::ST7735s_80x160), static_cast(ST77xx_type_e::ST7735s_80x160_M5), + # if P116_EXTRA_ST7735 + static_cast(ST77xx_type_e::ST7735s_135x240), + # endif // if P116_EXTRA_ST7735 static_cast(ST77xx_type_e::ST7789vw_240x320), static_cast(ST77xx_type_e::ST7789vw_240x240), static_cast(ST77xx_type_e::ST7789vw_240x280), diff --git a/src/src/PluginStructs/P116_data_struct.cpp b/src/src/PluginStructs/P116_data_struct.cpp index 44327c746..1aa994c33 100644 --- a/src/src/PluginStructs/P116_data_struct.cpp +++ b/src/src/PluginStructs/P116_data_struct.cpp @@ -11,6 +11,9 @@ const __FlashStringHelper* ST77xx_type_toString(const ST77xx_type_e& device) { case ST77xx_type_e::ST7735s_128x160: return F("ST7735 128 x 160px"); case ST77xx_type_e::ST7735s_80x160: return F("ST7735 80 x 160px"); case ST77xx_type_e::ST7735s_80x160_M5: return F("ST7735 80 x 160px (Color inverted)"); + # if P116_EXTRA_ST7735 + case ST77xx_type_e::ST7735s_135x240: return F("ST7735 135 x 240px"); + # endif // if P116_EXTRA_ST7735 case ST77xx_type_e::ST7789vw_240x320: return F("ST7789 240 x 320px"); case ST77xx_type_e::ST7789vw_240x240: return F("ST7789 240 x 240px"); case ST77xx_type_e::ST7789vw_240x280: return F("ST7789 240 x 280px"); @@ -63,6 +66,9 @@ void ST77xx_type_toResolution(const ST77xx_type_e& device, case ST77xx_type_e::ST7789vw2_135x240: case ST77xx_type_e::ST7789vw3_135x240: # endif // if P116_EXTRA_ST7789 + # if P116_EXTRA_ST7735 + case ST77xx_type_e::ST7735s_135x240: + # endif // if P116_EXTRA_ST7735 x = 135; y = 240; break; @@ -154,7 +160,16 @@ bool P116_data_struct::plugin_init(struct EventStruct *event) { initRoptions = INITR_GREENTAB160x80; // 80x160px ST7735sv, inverted (M5Stack StickC) } - // fall through + // fall through + # if P116_EXTRA_ST7735 + case ST77xx_type_e::ST7735s_135x240: + + if (initRoptions == 0xFF) { + initRoptions = INITR_BLACKTAB135x240; // 135x240px + } + + // fall through + # endif // if P116_EXTRA_ST7735 case ST77xx_type_e::ST7735s_80x160: { if (initRoptions == 0xFF) { diff --git a/src/src/PluginStructs/P116_data_struct.h b/src/src/PluginStructs/P116_data_struct.h index baf735f5b..675102456 100644 --- a/src/src/PluginStructs/P116_data_struct.h +++ b/src/src/PluginStructs/P116_data_struct.h @@ -11,14 +11,23 @@ # include // include Adafruit ST7796 TFT library # if defined(ST7789_EXTRA_INIT) && !ST7789_EXTRA_INIT -# define P116_EXTRA_ST7789 0 // This will get disabled for ESP8266 in Adafruit_ST7789.h +# define P116_EXTRA_ST7789 0 // This will get disabled for ESP8266 in Adafruit_ST7789.h # endif // if defined(ST7789_EXTRA_INIT) && !ST7789_EXTRA_INIT # if defined(LIMIT_BUILD_SIZE) and !defined(P116_EXTRA_ST7789) # define P116_EXTRA_ST7789 0 # endif // if defined(LIMIT_BUILD_SIZE) and !defined(P116_EXTRA_ST7789) # ifndef P116_EXTRA_ST7789 -# define P116_EXTRA_ST7789 1 +# define P116_EXTRA_ST7789 0 // Disabled by default (not verified on any hardware yet) # endif // ifndef P116_EXTRA_ST7789 +# if defined(ST7735_EXTRA_INIT) && !ST7735_EXTRA_INIT +# define P116_EXTRA_ST7735 0 // This will get disabled for ESP8266 in Adafruit_ST7735.h +# endif // if defined(ST7735_EXTRA_INIT) && !ST7735_EXTRA_INIT +# if defined(LIMIT_BUILD_SIZE) and !defined(P116_EXTRA_ST7789) +# define P116_EXTRA_ST7735 0 +# endif // if defined(LIMIT_BUILD_SIZE) and !defined(P116_EXTRA_ST7735) +# ifndef P116_EXTRA_ST7735 +# define P116_EXTRA_ST7735 1 +# endif // ifndef P116_EXTRA_ST7735 # include "../Helpers/AdafruitGFX_helper.h" // Use Adafruit graphics helper object # include "../CustomBuild/StorageLayout.h" @@ -89,6 +98,9 @@ enum class ST77xx_type_e : uint8_t { ST7789vw2_135x240 = 10u, ST7789vw3_135x240 = 11u, # endif // if P116_EXTRA_ST7789 + # if P116_EXTRA_ST7735 + ST7735s_135x240 = 12u, + # endif // if P116_EXTRA_ST7735 }; enum class P116_CommandTrigger : uint8_t {