Skip to content

Commit

Permalink
Merge pull request #5003 from tonhuisman/feature/P116-add-alternative…
Browse files Browse the repository at this point in the history
…-st7789-revisions

[P116] Add alternative model selections for ST7789/ST7735
  • Loading branch information
TD-er authored Mar 31, 2024
2 parents 33de614 + 66ed1b5 commit 6f15538
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/source/Plugin/P095_commands.repl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"
| ``tftcmd,clear``
","
| Clear the display, using the default background color.
| Clear the display, using the **default** background color. For clearing with a custom background color see the ``<trigger>,clear[,<color>]`` command.
"
"
| ``tftcmd,backlight,<percentage>``
Expand Down
7 changes: 6 additions & 1 deletion docs/source/Plugin/P116.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The ST7735, ST7789 and ST7796 chip families drive color TFT displays in various

This plugin supports these display models:

* **ST7735** with resolutions 128 x 128, 128 x 160 and 80 x 160 pixels
* **ST7735** with resolutions 128 x 128, 128 x 160, 80 x 160 and 135 x 240 pixels
* **ST7789** with resolutions 240 x 320, 240 x 240, 240 x 280 and 135 x 240 pixels
* **ST7796** with resolution of 320 x 480 pixels.

Expand Down Expand Up @@ -140,6 +140,7 @@ Available options:
* *ST7735 128 x 160px* Allows 16 lines of text in the smallest font scaling setting.
* *ST7735 80 x 160px* Allows 16 lines of text in the smallest font scaling setting.
* *ST7735 80 x 160px (Color inverted)* Special color inverted configuration as used in f.e. M5Stack StickC.
* *ST7735 135 x 240px* Added to support a revision of the TTGO T-Display 16MB Flash module, that won't work with the ST7789 driver, the seller is claiming to use, but does work with this specially crafted ST7735 driver.
* *ST7789 240 x 320px* Allows 32 lines of text in the smallest font scaling setting. Predefined text only goes to 24, extra lines can be displayed from rules or external commands.
* *ST7789 240 x 240px* Allows 24 lines of text in the smallest font scaling setting.
* *ST7789 240 x 280px* Allows 28 lines of text in the smallest font scaling setting. Predefined text only goes to 24, extra lines can be displayed from rules or external commands.
Expand Down Expand Up @@ -260,6 +261,10 @@ Change log
.. versionadded:: 2.0
...

|added| 2024-03-26 Add support for ST7735, 135x240 resolution

|added| 2022-07-06 Add support for ST7735 (Color inverted), for M5StickC support

|added| 2021-11-06 Add support for ST7796 displays

|added| 2021-08 Moved from an external forum to ESPEasy.
Binary file modified docs/source/Plugin/P116_TFTDisplayModelOptions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/source/Plugin/P116_commands.repl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"
| ``st77xxcmd,clear``
","
| Clear the display, using the default background color.
| Clear the display, using the **default** background color. For clearing with a custom background color see the ``<trigger>,clear[,<color>]`` command.
"
"
| ``st77xxcmd,backlight,<percentage>``
Expand Down
64 changes: 64 additions & 0 deletions lib/Adafruit_ST77xx/Adafruit_ST7735.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 = 53;
_rowstart = 40;
#endif // if ST7735_EXTRA_INIT
} else {
_height = ST7735_TFTHEIGHT_160;
_width = ST7735_TFTWIDTH_128;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 = 53;
_rowstart = 40;
#endif // if ST7735_EXTRA_INIT
} else {
_width = ST7735_TFTHEIGHT_160;
_height = ST7735_TFTWIDTH_128;
Expand Down
17 changes: 17 additions & 0 deletions lib/Adafruit_ST77xx/Adafruit_ST7735.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 6f15538

Please sign in to comment.