Skip to content

Commit cbc2e66

Browse files
committed
Update for WROVER to address #232
The library supported 240x240 ST7789 displays only which require an 80 pixel offset in rotation 2 and 3 The library now also supports the 240x320 display which has a different RGB colour order.
1 parent 8d29c39 commit cbc2e66

File tree

7 files changed

+112
-45
lines changed

7 files changed

+112
-45
lines changed

TFT_Drivers/ST7789_Defines.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#define TFT_HEIGHT 320
88
#endif
99

10-
#define CGRAM_OFFSET
10+
#if (TFT_HEIGHT == 240) && (TFT_WIDTH == 240)
11+
#define CGRAM_OFFSET
12+
#endif
1113

1214
// Delay between some initialisation commands
1315
#define TFT_INIT_DELAY 0x80 // Not used unless commandlist invoked

TFT_Drivers/ST7789_Init.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
//------------------------------display and color format setting--------------------------------//
1515
writecommand(ST7789_MADCTL);
1616
writedata(0x00);
17-
writedata(0x48);
17+
#ifdef CGRAM_OFFSET
18+
writedata(0x48); // BGR colour order for 240 x 240 TFT
19+
#else
20+
writedata(0x40); // RGB colour order for 240 x 320 TFT (Issue #232)
21+
#endif
22+
1823

1924
// JLX240 display datasheet
2025
writecommand(0xB6);
@@ -114,7 +119,9 @@
114119

115120
writecommand(ST7789_DISPON); //Display on
116121

122+
#ifdef TFT_BL
117123
// Turn on the back-light LED
118124
digitalWrite(TFT_BL, HIGH);
119125
pinMode(TFT_BL, OUTPUT);
126+
#endif
120127
}

TFT_Drivers/ST7789_Rotation.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,36 @@
77
writedata(TFT_MAD_RGB);
88
_width = _init_width;
99
_height = _init_height;
10+
#ifdef CGRAM_OFFSET
1011
colstart = 0;
1112
rowstart = 0;
13+
#endif
1214
break;
1315
case 1: // Landscape (Portrait + 90)
1416
writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_RGB);
1517
_width = _init_height;
1618
_height = _init_width;
17-
colstart = 0;
18-
rowstart = 0;
19-
break;
19+
#ifdef CGRAM_OFFSET
20+
colstart = 0;
21+
rowstart = 0;
22+
#endif
23+
break;
2024
case 2: // Inverter portrait
2125
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_RGB);
2226
_width = _init_width;
2327
_height = _init_height;
24-
colstart = 0;
25-
rowstart = 80;
26-
break;
28+
#ifdef CGRAM_OFFSET
29+
colstart = 0;
30+
rowstart = 80;
31+
#endif
32+
break;
2733
case 3: // Inverted landscape
2834
writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_RGB);
2935
_width = _init_height;
3036
_height = _init_width;
31-
colstart = 80;
32-
rowstart = 0;
33-
break;
37+
#ifdef CGRAM_OFFSET
38+
colstart = 80;
39+
rowstart = 0;
40+
#endif
41+
break;
3442
}

User_Setup.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@
2424
//#define ILI9481_DRIVER
2525
//#define ILI9486_DRIVER
2626
//#define ILI9488_DRIVER
27-
//#define ST7789_DRIVER
27+
//#define ST7789_DRIVER // Define the screen size below for this display
2828

2929
// For M5Stack ESP32 module with integrated display ONLY, remove // in line below
3030
//#define M5STACK
3131

32-
// For ST7735 and ILI9163 ONLY, define the pixel width and height in portrait orientation
32+
// For ST7789, ST7735 and ILI9163 ONLY, define the pixel width and height in portrait orientation
3333
// #define TFT_WIDTH 80
3434
// #define TFT_WIDTH 128
35+
// #define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
3536
// #define TFT_HEIGHT 160
36-
//#define TFT_HEIGHT 128
37+
// #define TFT_HEIGHT 128
38+
// #define TFT_HEIGHT 240 // ST7789 240 x 240
39+
// #define TFT_HEIGHT 320 // ST7789 240 x 320
3740

3841
// For ST7735 ONLY, define the type of display, originally this was based on the
3942
// colour of the tab on the screen protector film but this is not always true, so try
@@ -46,10 +49,10 @@
4649
// #define ST7735_GREENTAB
4750
// #define ST7735_GREENTAB2
4851
// #define ST7735_GREENTAB3
49-
// #define ST7735_GREENTAB128 // For 128 x 128 display
52+
// #define ST7735_GREENTAB128 // For 128 x 128 display
5053
// #define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset)
5154
// #define ST7735_REDTAB
52-
//#define ST7735_BLACKTAB
55+
// #define ST7735_BLACKTAB
5356

5457
// ##################################################################################
5558
//
@@ -94,7 +97,9 @@
9497
#define TFT_CS PIN_D8 // Chip select control pin D8
9598
#define TFT_DC PIN_D3 // Data Command control pin
9699
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
97-
//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
100+
//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
101+
102+
//#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin)
98103

99104
//#define TOUCH_CS PIN_D2 // Chip select pin (T_CS) of touch screen
100105

@@ -124,10 +129,12 @@
124129
//#define TFT_MISO 19
125130
//#define TFT_MOSI 23
126131
//#define TFT_SCLK 18
127-
//#define TFT_CS 15 // Chip select control pin
132+
//#define TFT_CS 15 // Chip select control pin
128133
//#define TFT_DC 2 // Data Command control pin
129134
//#define TFT_RST 4 // Reset pin (could connect to RST pin)
130135
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
136+
//#define TFT_BL 32 // LED back-light (only for ST7789 with backlight control pin)
137+
131138

132139
// For the M5Stack module use these #define lines
133140
//#define TFT_MISO 19
@@ -136,7 +143,7 @@
136143
//#define TFT_CS 14 // Chip select control pin
137144
//#define TFT_DC 27 // Data Command control pin
138145
//#define TFT_RST 33 // Reset pin (could connect to Arduino RESET pin)
139-
//#define TFT_BL 32 // LED back-light
146+
//#define TFT_BL 32 // LED back-light (required for M5Stack)
140147

141148
//#define TOUCH_CS 21 // Chip select pin (T_CS) of touch screen
142149

User_Setups/SetupX_Template.h

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
// If this file is edited correctly then all the library example sketches should
88
// run without the need to make any more changes for a particular hardware setup!
9+
// Note that some sketches are designed for a particular TFT pixel width/height
910

1011
// ##################################################################################
1112
//
@@ -19,15 +20,23 @@
1920
//#define ILI9163_DRIVER
2021
//#define S6D02A1_DRIVER
2122
//#define RPI_ILI9486_DRIVER // 20MHz maximum SPI
23+
//#define HX8357D_DRIVER
24+
//#define ILI9481_DRIVER
25+
//#define ILI9486_DRIVER
26+
//#define ILI9488_DRIVER
27+
//#define ST7789_DRIVER // Define the screen size below for this display
2228

2329
// For M5Stack ESP32 module with integrated display ONLY, remove // in line below
2430
//#define M5STACK
2531

26-
// For ST7735 and ILI9163 ONLY, define the pixel width and height in portrait orientation
27-
//#define TFT_WIDTH 80
28-
//#define TFT_WIDTH 128
29-
//#define TFT_HEIGHT 160
30-
//#define TFT_HEIGHT 128
32+
// For ST7789, ST7735 and ILI9163 ONLY, define the pixel width and height in portrait orientation
33+
// #define TFT_WIDTH 80
34+
// #define TFT_WIDTH 128
35+
// #define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
36+
// #define TFT_HEIGHT 160
37+
// #define TFT_HEIGHT 128
38+
// #define TFT_HEIGHT 240 // ST7789 240 x 240
39+
// #define TFT_HEIGHT 320 // ST7789 240 x 320
3140

3241
// For ST7735 ONLY, define the type of display, originally this was based on the
3342
// colour of the tab on the screen protector film but this is not always true, so try
@@ -36,14 +45,14 @@
3645
// Comment out ALL BUT ONE of these options for a ST7735 display driver, save this
3746
// this User_Setup file, then rebuild and upload the sketch to the board again:
3847

39-
//#define ST7735_INITB
40-
//#define ST7735_GREENTAB
41-
//#define ST7735_GREENTAB2
42-
//#define ST7735_GREENTAB3
43-
//#define ST7735_GREENTAB128 // For 128 x 128 display
44-
//#define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset)
45-
//#define ST7735_REDTAB
46-
//#define ST7735_BLACKTAB
48+
// #define ST7735_INITB
49+
// #define ST7735_GREENTAB
50+
// #define ST7735_GREENTAB2
51+
// #define ST7735_GREENTAB3
52+
// #define ST7735_GREENTAB128 // For 128 x 128 display
53+
// #define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset)
54+
// #define ST7735_REDTAB
55+
// #define ST7735_BLACKTAB
4756

4857
// ##################################################################################
4958
//
@@ -88,9 +97,11 @@
8897
#define TFT_CS PIN_D8 // Chip select control pin D8
8998
#define TFT_DC PIN_D3 // Data Command control pin
9099
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
91-
//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
100+
//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
101+
102+
//#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin)
92103

93-
//#define TOUCH_CS PIN_D1 // Chip select pin (T_CS) of touch screen
104+
//#define TOUCH_CS PIN_D2 // Chip select pin (T_CS) of touch screen
94105

95106
//#define TFT_WR PIN_D2 // Write strobe for modified Raspberry Pi TFT only
96107

@@ -118,14 +129,12 @@
118129
//#define TFT_MISO 19
119130
//#define TFT_MOSI 23
120131
//#define TFT_SCLK 18
121-
//#define TFT_CS 15 // Chip select control pin
132+
//#define TFT_CS 15 // Chip select control pin
122133
//#define TFT_DC 2 // Data Command control pin
123134
//#define TFT_RST 4 // Reset pin (could connect to RST pin)
124135
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
136+
//#define TFT_BL 32 // LED back-light (only for ST7789 with backlight control pin)
125137

126-
//#define TOUCH_CS 22 // Chip select pin (T_CS) of touch screen
127-
128-
//#define TFT_WR 21 // Write strobe for modified Raspberry Pi TFT only
129138

130139
// For the M5Stack module use these #define lines
131140
//#define TFT_MISO 19
@@ -134,8 +143,40 @@
134143
//#define TFT_CS 14 // Chip select control pin
135144
//#define TFT_DC 27 // Data Command control pin
136145
//#define TFT_RST 33 // Reset pin (could connect to Arduino RESET pin)
137-
//#define TFT_BL 32 // LED back-light
146+
//#define TFT_BL 32 // LED back-light (required for M5Stack)
147+
148+
//#define TOUCH_CS 21 // Chip select pin (T_CS) of touch screen
149+
150+
//#define TFT_WR 22 // Write strobe for modified Raspberry Pi TFT only
151+
152+
// ###### EDIT THE PINs BELOW TO SUIT YOUR ESP32 PARALLEL TFT SETUP ######
153+
154+
// The library supports 8 bit parallel TFTs with the ESP32, the pin
155+
// selection below is compatible with ESP32 boards in UNO format.
156+
// Wemos D32 boards need to be modified, see diagram in Tools folder.
157+
// Only ILI9481 and ILI9341 based displays have been tested!
138158

159+
// Parallel bus is only supported on ESP32
160+
// Uncomment line below to use ESP32 Parallel interface instead of SPI
161+
162+
//#define ESP32_PARALLEL
163+
164+
// The ESP32 and TFT the pins used for testing are:
165+
//#define TFT_CS 33 // Chip select control pin (library pulls permanently low
166+
//#define TFT_DC 15 // Data Command control pin - use a pin in the range 0-31
167+
//#define TFT_RST 32 // Reset pin, toggles on startup
168+
169+
//#define TFT_WR 4 // Write strobe control pin - use a pin in the range 0-31
170+
//#define TFT_RD 2 // Read strobe control pin - use a pin in the range 0-31
171+
172+
//#define TFT_D0 12 // Must use pins in the range 0-31 for the data bus
173+
//#define TFT_D1 13 // so a single register write sets/clears all bits.
174+
//#define TFT_D2 26 // Pins can be randomly assigned, this does not affect
175+
//#define TFT_D3 25 // TFT screen update performance.
176+
//#define TFT_D4 17
177+
//#define TFT_D5 16
178+
//#define TFT_D6 27
179+
//#define TFT_D7 14
139180

140181
// ##################################################################################
141182
//
@@ -167,9 +208,9 @@
167208
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
168209
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
169210
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
170-
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
171-
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
211+
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
172212
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
213+
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
173214
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
174215

175216
// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
@@ -202,9 +243,11 @@
202243
// #define SPI_FREQUENCY 20000000
203244
#define SPI_FREQUENCY 27000000 // Actually sets it to 26.67MHz = 80/3
204245
// #define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS
205-
// #define SPI_FREQUENCY 53400000
206246
// #define SPI_FREQUENCY 80000000
207247

248+
// Optional reduced SPI frequency for reading TFT
249+
#define SPI_READ_FREQUENCY 20000000
250+
208251
// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
209252
#define SPI_TOUCH_FREQUENCY 2500000
210253

@@ -219,4 +262,4 @@
219262
// Transactions are automatically enabled by the library for an ESP32 (to use HAL mutex)
220263
// so changing it here has no effect
221264

222-
// #define SUPPORT_TRANSACTIONS
265+
//#define SUPPORT_TRANSACTIONS

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "TFT_eSPI",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"keywords": "tft, ePaper, display, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789",
55
"description": "A TFT and ePaper SPI graphics library for ESP8266 and ESP32",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=TFT_eSPI
2-
version=1.1.2
2+
version=1.1.3
33
author=Bodmer
44
maintainer=Bodmer
55
sentence=A fast TFT graphics library for ESP8266 and ESP32 processors for the Arduino IDE

0 commit comments

Comments
 (0)