Skip to content

Commit 9c9d248

Browse files
committed
Added support for ST7789T3 driver
1 parent 5793878 commit 9c9d248

File tree

7 files changed

+203
-0
lines changed

7 files changed

+203
-0
lines changed

TFT_Drivers/ST7789T3_Defines.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef TFT_WIDTH
2+
#define TFT_WIDTH 240
3+
#endif
4+
#ifndef TFT_HEIGHT
5+
#define TFT_HEIGHT 320
6+
#endif
7+
8+
// Delay between some initialisation commands
9+
#define TFT_INIT_DELAY 0x80 // Not used unless commandlist invoked
10+
11+
12+
// Generic commands used by TFT_eSPI.cpp
13+
#define TFT_NOP 0x00
14+
#define TFT_SWRST 0x01
15+
16+
#define TFT_SLPIN 0x10
17+
#define TFT_SLPOUT 0x11
18+
#define TFT_NORON 0x13
19+
20+
#define TFT_INVOFF 0x20
21+
#define TFT_INVON 0x21
22+
#define TFT_DISPOFF 0x28
23+
#define TFT_DISPON 0x29
24+
#define TFT_CASET 0x2A
25+
#define TFT_PASET 0x2B
26+
#define TFT_RAMWR 0x2C
27+
#define TFT_RAMRD 0x2E
28+
#define TFT_MADCTL 0x36
29+
#define TFT_COLMOD 0x3A
30+
31+
// Flags for TFT_MADCTL
32+
#define TFT_MAD_MY 0x80
33+
#define TFT_MAD_MX 0x40
34+
#define TFT_MAD_MV 0x20
35+
#define TFT_MAD_ML 0x10
36+
#define TFT_MAD_RGB 0x00
37+
#define TFT_MAD_BGR 0x08
38+
#define TFT_MAD_MH 0x04
39+
#define TFT_MAD_SS 0x02
40+
#define TFT_MAD_GS 0x01
41+
42+
#define TFT_MAD_COLOR_ORDER TFT_MAD_BGR
43+
44+
#define ST7789T3_GCTRL 0xB7 // Gate control
45+
#define ST7789T3_LCMCTRL 0xC0 // LCM control
46+
#define ST7789T3_IDSET 0xC1 // ID setting
47+
#define ST7789T3_VDVVRHEN 0xC2 // VDV and VRH command enable
48+
#define ST7789T3_VCMOFSET 0xC5 // VCOMS offset set
49+
#define ST7789T3_PVGAMCTRL 0xE0 // Positive voltage gamma control
50+
#define ST7789T3_NVGAMCTRL 0xE1 // Negative voltage gamma control
51+
#define ST7789T3_PWCTRL2 0xE8 // Power control 2

TFT_Drivers/ST7789T3_Init.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
// Adapted from Waveshare RP2350-Touch-LCD-2 board example for the Pico C SDK
3+
writecommand(TFT_SLPOUT);
4+
delay(120);
5+
6+
writecommand(TFT_COLMOD);
7+
writedata(0x05);
8+
9+
writecommand(0xF0); // ?? not found in the datasheet
10+
writedata(0xC3);
11+
12+
writecommand(0xF0); // ?? not found in the datasheet
13+
writedata(0x96);
14+
15+
writecommand(0xB4); // ?? not found in the datasheet
16+
writedata(0x01);
17+
18+
writecommand(ST7789T3_GCTRL);
19+
writedata(0xC6);
20+
21+
writecommand(ST7789T3_LCMCTRL);
22+
writedata(0x80);
23+
writedata(0x45);
24+
25+
writecommand(ST7789T3_IDSET);
26+
writedata(0x13);
27+
28+
writecommand(ST7789T3_VDVVRHEN);
29+
writedata(0xA7);
30+
31+
writecommand(ST7789T3_VCMOFSET);
32+
writedata(0x0A);
33+
34+
writecommand(ST7789T3_PWCTRL2);
35+
writedata(0x40);
36+
writedata(0x8A);
37+
writedata(0x00);
38+
writedata(0x00);
39+
writedata(0x29);
40+
writedata(0x19);
41+
writedata(0xA5);
42+
writedata(0x33);
43+
44+
writecommand(ST7789T3_PVGAMCTRL);
45+
writedata(0xD0);
46+
writedata(0x08);
47+
writedata(0x0F);
48+
writedata(0x06);
49+
writedata(0x06);
50+
writedata(0x33);
51+
writedata(0x30);
52+
writedata(0x33);
53+
writedata(0x47);
54+
writedata(0x17);
55+
writedata(0x13);
56+
writedata(0x13);
57+
writedata(0x2B);
58+
writedata(0x31);
59+
60+
writecommand(ST7789T3_NVGAMCTRL);
61+
writedata(0xD0);
62+
writedata(0x0A);
63+
writedata(0x11);
64+
writedata(0x0B);
65+
writedata(0x09);
66+
writedata(0x07);
67+
writedata(0x2F);
68+
writedata(0x33);
69+
writedata(0x47);
70+
writedata(0x38);
71+
writedata(0x15);
72+
writedata(0x16);
73+
writedata(0x2C);
74+
writedata(0x32);
75+
76+
writecommand(0xF0); // ?? not found in the datasheet
77+
writedata(0x3C);
78+
79+
writecommand(0xF0); // ?? not found in the datasheet
80+
writedata(0x69);
81+
82+
delay(120);
83+
84+
writecommand(TFT_INVON);
85+
86+
writecommand(TFT_DISPON);
87+
}

TFT_Drivers/ST7789T3_Rotation.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This is the command sequence that rotates the ST7789T3 driver coordinate frame
2+
3+
writecommand(TFT_MADCTL);
4+
rotation = m % 4;
5+
switch (rotation) {
6+
case 0: // Portrait
7+
writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
8+
_width = _init_width;
9+
_height = _init_height;
10+
break;
11+
12+
case 1: // Landscape (Portrait + 90)
13+
writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
14+
_width = _init_height;
15+
_height = _init_width;
16+
break;
17+
18+
case 2: // Inverter portrait
19+
writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
20+
_width = _init_width;
21+
_height = _init_height;
22+
break;
23+
case 3: // Inverted landscape
24+
writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
25+
_width = _init_height;
26+
_height = _init_width;
27+
break;
28+
}

TFT_eSPI.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ void TFT_eSPI::init(uint8_t tc)
769769
#elif defined (HX8357C_DRIVER)
770770
#include "TFT_Drivers/HX8357C_Init.h"
771771

772+
#elif defined(ST7789T3_DRIVER)
773+
#include "TFT_Drivers/ST7789T3_Init.h"
774+
772775
#endif
773776

774777
#ifdef TFT_INVERSION_ON
@@ -870,6 +873,9 @@ void TFT_eSPI::setRotation(uint8_t m)
870873
#elif defined (HX8357C_DRIVER)
871874
#include "TFT_Drivers/HX8357C_Rotation.h"
872875

876+
#elif defined (ST7789T3_DRIVER)
877+
#include "TFT_Drivers/ST7789T3_Rotation.h"
878+
873879
#endif
874880

875881
delayMicroseconds(10);

User_Setup_Select.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143

144144
//#include <User_Setups/Setup301_BW16_ST7735.h> // Setup file for Bw16-based boards with ST7735 160 x 80 TFT
145145
//#include <User_Setups/Setup302_Waveshare_ESP32S3_GC9A01.h> // Setup file for Waveshare ESP32-S3-Touch-LCD-1.28 board with GC9A01 240*240 TFT
146+
//#include <User_Setups/Setup303_Waveshare_RP2350_ST7789T3.h> // Setup file for Waveshare RP2350-Touch-LCD-2 board with ST7789T3 240*320 TFT
146147

147148
//#include <User_Setups/SetupX_Template.h> // Template file for a setup
148149

@@ -271,6 +272,9 @@
271272
#elif defined (HX8357C_DRIVER)
272273
#include "TFT_Drivers/HX8357C_Defines.h"
273274
#define TFT_DRIVER 0x835C
275+
#elif defined (ST7789T3_DRIVER)
276+
#include "TFT_Drivers/ST7789T3_Defines.h"
277+
#define TFT_DRIVER 0x7789
274278

275279
// <<<<<<<<<<<<<<<<<<<<<<<< ADD NEW DRIVER HERE
276280
// XYZZY_init.h and XYZZY_rotation.h must also be added in TFT_eSPI.cpp
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// See SetupX_Template.h for all options available
2+
#define USER_SETUP_ID 303
3+
4+
#define ST7789T3_DRIVER
5+
6+
#define TFT_MOSI 19
7+
#define TFT_SCLK 18
8+
#define TFT_CS 17 // Chip select control pin
9+
#define TFT_DC 16 // Data Command control pin
10+
#define TFT_RST 20 // Reset pin (could connect to RST pin)
11+
#define TFT_BL 15
12+
#define TFT_BACKLIGHT_ON HIGH
13+
14+
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
15+
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
16+
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
17+
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
18+
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
19+
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
20+
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
21+
#define SMOOTH_FONT
22+
23+
#define TFT_WIDTH 240
24+
#define TFT_HEIGHT 320
25+
26+
#define SPI_FREQUENCY 40000000

User_Setups/SetupX_Template.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
//#define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)
5757
//#define ST7789_DRIVER // Full configuration option, define additional parameters below for this display
5858
//#define ST7789_2_DRIVER // Minimal configuration option, define additional parameters below for this display
59+
//#define ST7789T3_DRIVER
5960
//#define R61581_DRIVER
6061
//#define RM68120_DRIVER // Untested
6162
//#define RM68140_DRIVER

0 commit comments

Comments
 (0)