From b25839f94501514f7b82bca58e3590ac5fd6f36e Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 20 Dec 2025 23:17:04 +0100 Subject: [PATCH] [P116] Add ST77xx resolutions 240x320 and 240x280 --- lib/Adafruit_ST77xx/Adafruit_ST7735.cpp | 78 ++++++++++++++++++++-- lib/Adafruit_ST77xx/Adafruit_ST7735.h | 2 + lib/Adafruit_ST77xx/Adafruit_ST77xx.h | 2 + src/_P116_ST77xx.ino | 8 ++- src/src/PluginStructs/P116_data_struct.cpp | 24 +++++++ src/src/PluginStructs/P116_data_struct.h | 2 + 6 files changed, 110 insertions(+), 6 deletions(-) diff --git a/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp b/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp index f0494dd85..0957c2535 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp +++ b/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp @@ -206,6 +206,22 @@ static const uint8_t PROGMEM ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay: 0x00, 0x00, // XSTART = 0 320 >> 8, 320 & 0xFF }, // XEND = 320 + Rcmd2black240x320[] = { // 7735R init, part 2 (mini 240x320) + 2, // 2 commands in list: + ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay: + 0x00, 0x00, // XSTART = 0 + 0x00, 240, // XEND = 240 + ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay: + 0x00, 0x00, // XSTART = 0 + 320 >> 8, 320 & 0xFF }, // XEND = 320 + Rcmd2black240x280[] = { // 7735R init, part 2 (mini 240x280) + 2, // 2 commands in list: + ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay: + 0x00, 0x00, // XSTART = 0 + 0x00, 240, // XEND = 240 + ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay: + 0x00, 0x00, // XSTART = 0 + 280 >> 8, 280 & 0xFF }, // XEND = 240 #endif // if ST7735_EXTRA_INIT Rcmd3[] = { // 7735R init, part 3 (red or green tab) @@ -292,6 +308,20 @@ void Adafruit_ST7735::initR(uint8_t options) { const uint8_t data = 0x00; sendCommand(ST77XX_INVON, &data, 0); sendCommand(ST77XX_INVON, &data, 0); // Write twice... + } else if (options == INITR_BLACKTAB240x320) { + _height = ST7735_TFTHEIGHT_320; + _width = ST7735_TFTWIDTH_240; + displayInit(Rcmd2black240x320); + const uint8_t data = 0x00; + sendCommand(ST77XX_INVON, &data, 0); + sendCommand(ST77XX_INVON, &data, 0); // Write twice... + } else if (options == INITR_BLACKTAB240x280) { + _height = ST7735_TFTHEIGHT_280; + _width = ST7735_TFTWIDTH_240; + displayInit(Rcmd2black240x280); + 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 @@ -339,7 +369,7 @@ void Adafruit_ST7735::setRotation(uint8_t m) { 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) || (tabcolor == INITR_BLACKTAB172x320) || (tabcolor == INITR_BLACKTAB170x320)) { + } else if ((tabcolor == INITR_BLACKTAB135x240) || (tabcolor == INITR_BLACKTAB172x320) || (tabcolor == INITR_BLACKTAB170x320) || (tabcolor == INITR_BLACKTAB240x320) || (tabcolor == INITR_BLACKTAB240x280)) { madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; #endif // if ST7735_EXTRA_INIT } else { @@ -368,6 +398,16 @@ void Adafruit_ST7735::setRotation(uint8_t m) { _width = ST7735_TFTWIDTH_170; _colstart = 35; _rowstart = 0; + } else if (tabcolor == INITR_BLACKTAB240x320) { + _height = ST7735_TFTHEIGHT_320; + _width = ST7735_TFTWIDTH_240; + _colstart = 0; + _rowstart = 0; + } else if (tabcolor == INITR_BLACKTAB240x280) { + _height = ST7735_TFTHEIGHT_280; + _width = ST7735_TFTWIDTH_240; + _colstart = 0; + _rowstart = 20; #endif // if ST7735_EXTRA_INIT } else { _height = ST7735_TFTHEIGHT_160; @@ -380,7 +420,7 @@ void Adafruit_ST7735::setRotation(uint8_t m) { 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) || (tabcolor == INITR_BLACKTAB172x320) || (tabcolor == INITR_BLACKTAB170x320)) { + } else if ((tabcolor == INITR_BLACKTAB135x240) || (tabcolor == INITR_BLACKTAB172x320) || (tabcolor == INITR_BLACKTAB170x320) || (tabcolor == INITR_BLACKTAB240x320) || (tabcolor == INITR_BLACKTAB240x280)) { madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB; #endif // if ST7735_EXTRA_INIT } else { @@ -409,6 +449,16 @@ void Adafruit_ST7735::setRotation(uint8_t m) { _height = ST7735_TFTWIDTH_170; _colstart = 35; _rowstart = 0; + } else if (tabcolor == INITR_BLACKTAB240x320) { + _width = ST7735_TFTHEIGHT_320; + _height = ST7735_TFTWIDTH_240; + _colstart = 0; + _rowstart = 0; + } else if (tabcolor == INITR_BLACKTAB240x280) { + _width = ST7735_TFTHEIGHT_280; + _height = ST7735_TFTWIDTH_240; + _colstart = 0; + _rowstart = 20; #endif // if ST7735_EXTRA_INIT } else { _width = ST7735_TFTHEIGHT_160; @@ -421,7 +471,7 @@ void Adafruit_ST7735::setRotation(uint8_t m) { if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) { madctl = ST77XX_MADCTL_RGB; #if ST7735_EXTRA_INIT - } else if ((tabcolor == INITR_BLACKTAB135x240) || (tabcolor == INITR_BLACKTAB172x320) || (tabcolor == INITR_BLACKTAB170x320)) { + } else if ((tabcolor == INITR_BLACKTAB135x240) || (tabcolor == INITR_BLACKTAB172x320) || (tabcolor == INITR_BLACKTAB170x320) || (tabcolor == INITR_BLACKTAB240x320) || (tabcolor == INITR_BLACKTAB240x280)) { madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB; #endif // if ST7735_EXTRA_INIT } else { @@ -450,6 +500,16 @@ void Adafruit_ST7735::setRotation(uint8_t m) { _width = ST7735_TFTWIDTH_170; _colstart = 35; _rowstart = 0; + } else if (tabcolor == INITR_BLACKTAB240x320) { + _height = ST7735_TFTHEIGHT_320; + _width = ST7735_TFTWIDTH_240; + _colstart = 0; + _rowstart = 0; + } else if (tabcolor == INITR_BLACKTAB240x280) { + _height = ST7735_TFTHEIGHT_280; + _width = ST7735_TFTWIDTH_240; + _colstart = 0; + _rowstart = 20; #endif // if ST7735_EXTRA_INIT } else { _height = ST7735_TFTHEIGHT_160; @@ -462,7 +522,7 @@ void Adafruit_ST7735::setRotation(uint8_t m) { 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) || (tabcolor == INITR_BLACKTAB172x320) || (tabcolor == INITR_BLACKTAB170x320)) { + } else if ((tabcolor == INITR_BLACKTAB135x240) || (tabcolor == INITR_BLACKTAB172x320) || (tabcolor == INITR_BLACKTAB170x320) || (tabcolor == INITR_BLACKTAB240x320) || (tabcolor == INITR_BLACKTAB240x280)) { madctl = ST77XX_MADCTL_RGB; #endif // if ST7735_EXTRA_INIT } else { @@ -491,6 +551,16 @@ void Adafruit_ST7735::setRotation(uint8_t m) { _height = ST7735_TFTWIDTH_170; _colstart = 35; _rowstart = 0; + } else if (tabcolor == INITR_BLACKTAB240x320) { + _width = ST7735_TFTHEIGHT_320; + _height = ST7735_TFTWIDTH_240; + _colstart = 0; + _rowstart = 0; + } else if (tabcolor == INITR_BLACKTAB240x280) { + _width = ST7735_TFTHEIGHT_280; + _height = ST7735_TFTWIDTH_240; + _colstart = 0; + _rowstart = 20; #endif // if ST7735_EXTRA_INIT } else { _width = ST7735_TFTHEIGHT_160; diff --git a/lib/Adafruit_ST77xx/Adafruit_ST7735.h b/lib/Adafruit_ST77xx/Adafruit_ST7735.h index 8ad70e7c0..f47eff757 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST7735.h +++ b/lib/Adafruit_ST77xx/Adafruit_ST7735.h @@ -33,6 +33,8 @@ #define INITR_BLACKTAB135x240 0x07 #define INITR_BLACKTAB172x320 0x08 #define INITR_BLACKTAB170x320 0x09 +#define INITR_BLACKTAB240x320 0x0A +#define INITR_BLACKTAB240x280 0x0B // Some register settings #define ST7735_MADCTL_BGR 0x08 diff --git a/lib/Adafruit_ST77xx/Adafruit_ST77xx.h b/lib/Adafruit_ST77xx/Adafruit_ST77xx.h index e3af093d4..68b924203 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST77xx.h +++ b/lib/Adafruit_ST77xx/Adafruit_ST77xx.h @@ -36,9 +36,11 @@ #define ST7735_TFTWIDTH_135 135 #define ST7735_TFTWIDTH_172 172 #define ST7735_TFTWIDTH_170 170 +#define ST7735_TFTWIDTH_240 240 #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 ST7735_TFTHEIGHT_280 280 #define ST7735_TFTHEIGHT_320 320 #define ST_CMD_DELAY 0x80 // special signifier for command lists diff --git a/src/_P116_ST77xx.ino b/src/_P116_ST77xx.ino index d537bc249..49d947fe3 100644 --- a/src/_P116_ST77xx.ino +++ b/src/_P116_ST77xx.ino @@ -152,6 +152,8 @@ boolean Plugin_116(uint8_t function, struct EventStruct *event, String& string) ST77xx_type_toString(ST77xx_type_e::ST7735s_135x240), ST77xx_type_toString(ST77xx_type_e::ST7735s_172x320), ST77xx_type_toString(ST77xx_type_e::ST77xxs_170x320), + ST77xx_type_toString(ST77xx_type_e::ST77xxs_240x320), + ST77xx_type_toString(ST77xx_type_e::ST77xxs_240x280), # endif // if P116_EXTRA_ST7735 ST77xx_type_toString(ST77xx_type_e::ST7789vw_240x320), ST77xx_type_toString(ST77xx_type_e::ST7789vw_240x240), @@ -173,6 +175,8 @@ boolean Plugin_116(uint8_t function, struct EventStruct *event, String& string) static_cast(ST77xx_type_e::ST7735s_135x240), static_cast(ST77xx_type_e::ST7735s_172x320), static_cast(ST77xx_type_e::ST77xxs_170x320), + static_cast(ST77xx_type_e::ST77xxs_240x320), + static_cast(ST77xx_type_e::ST77xxs_240x280), # endif // if P116_EXTRA_ST7735 static_cast(ST77xx_type_e::ST7789vw_240x320), static_cast(ST77xx_type_e::ST7789vw_240x240), @@ -188,8 +192,8 @@ boolean Plugin_116(uint8_t function, struct EventStruct *event, String& string) constexpr int optCount4 = NR_ELEMENTS(optionValues4); const FormSelectorOptions selector(optCount4, options4, optionValues4); selector.addFormSelector(F("TFT display model"), - F("type"), - P116_CONFIG_FLAG_GET_TYPE); + F("type"), + P116_CONFIG_FLAG_GET_TYPE); } addFormSubHeader(F("Layout")); diff --git a/src/src/PluginStructs/P116_data_struct.cpp b/src/src/PluginStructs/P116_data_struct.cpp index b803d1703..ad65da83e 100644 --- a/src/src/PluginStructs/P116_data_struct.cpp +++ b/src/src/PluginStructs/P116_data_struct.cpp @@ -15,6 +15,8 @@ const __FlashStringHelper* ST77xx_type_toString(const ST77xx_type_e& device) { case ST77xx_type_e::ST7735s_135x240: return F("ST7735 135 x 240px"); case ST77xx_type_e::ST7735s_172x320: return F("ST7735 172 x 320px"); case ST77xx_type_e::ST77xxs_170x320: return F("ST77xx 170 x 320px"); + case ST77xx_type_e::ST77xxs_240x320: return F("ST77xx 240 x 320px"); + case ST77xx_type_e::ST77xxs_240x280: return F("ST77xx 240 x 280px"); # 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"); @@ -83,6 +85,14 @@ void ST77xx_type_toResolution(const ST77xx_type_e& device, x = 170; y = 320; break; + case ST77xx_type_e::ST77xxs_240x320: + x = 240; + y = 320; + break; + case ST77xx_type_e::ST77xxs_240x280: + x = 240; + y = 280; + break; # endif // if P116_EXTRA_ST7735 case ST77xx_type_e::ST7796s_320x480: x = 320; @@ -201,6 +211,20 @@ bool P116_data_struct::plugin_init(struct EventStruct *event) { initRoptions = INITR_BLACKTAB170x320; // 170x320px } + // fall through + case ST77xx_type_e::ST77xxs_240x320: + + if (initRoptions == 0xFF) { + initRoptions = INITR_BLACKTAB240x320; // 240x320px + } + + // fall through + case ST77xx_type_e::ST77xxs_240x280: + + if (initRoptions == 0xFF) { + initRoptions = INITR_BLACKTAB240x280; // 240x280px + } + // fall through # endif // if P116_EXTRA_ST7735 case ST77xx_type_e::ST7735s_80x160: diff --git a/src/src/PluginStructs/P116_data_struct.h b/src/src/PluginStructs/P116_data_struct.h index deaf3cfd4..9deaa340a 100644 --- a/src/src/PluginStructs/P116_data_struct.h +++ b/src/src/PluginStructs/P116_data_struct.h @@ -103,6 +103,8 @@ enum class ST77xx_type_e : uint8_t { ST7735s_135x240 = 12u, ST7735s_172x320 = 13u, ST77xxs_170x320 = 14u, + ST77xxs_240x320 = 15u, + ST77xxs_240x280 = 16u, # endif // if P116_EXTRA_ST7735 };