Skip to content

Commit e9d405e

Browse files
committed
Fix image cropping bug plus minor update
Images/sprites overlapping both sides of the display were not correctly cropped. Option added to allow RGB<>BGR colourr swap option to be used. ESP8266 Wemos D1 R1 pin numbering difference accomodated. TTGO T4 setup changed to use HSPI port.
1 parent d3210a7 commit e9d405e

12 files changed

+66
-54
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ https://github.com/Bodmer/TFT_eFX
1414

1515
5. The capability to read from an ST7789V TFT with a single bidirectional SDA pin has been added. At the moment this **ONLY** works with an ESP32. It is enabled with a #define TFT_SDA_READ in the setup file.
1616

17-
6. ST7789V displays are manufactured in two variants that have the red and blue pixels swapped, this is catered for by a new option in the setup file:
17+
6. ST7789V and ILI9341 displays are manufactured in two variants that have the red and blue pixels swapped, this is catered for by a new option in the setup file:
1818
//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
1919
//#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
2020

TFT_Drivers/ILI9341_Defines.h

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@
5151
#define TFT_MAD_MH 0x04
5252
#define TFT_MAD_RGB 0x00
5353

54+
#ifdef TFT_RGB_ORDER
55+
#if (TFT_RGB_ORDER == 1)
56+
#define TFT_MAD_COLOR_ORDER TFT_MAD_RGB
57+
#else
58+
#define TFT_MAD_COLOR_ORDER TFT_MAD_BGR
59+
#endif
60+
#else
61+
#define TFT_MAD_COLOR_ORDER TFT_MAD_BGR
62+
#endif
63+
5464
#define TFT_INVOFF 0x20
5565
#define TFT_INVON 0x21
5666

TFT_Drivers/ILI9341_Init.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656

5757
writecommand(ILI9341_MADCTL); // Memory Access Control
5858
#ifdef M5STACK
59-
writedata(0xA8); // Rotation 0 (portrait mode)
59+
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); // Rotation 0 (portrait mode)
6060
#else
61-
writedata(0x48); // Rotation 0 (portrait mode)
61+
writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER); // Rotation 0 (portrait mode)
6262
#endif
6363

6464
writecommand(ILI9341_PIXFMT);

TFT_Drivers/ILI9341_Rotation.h

+16-16
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,73 @@
77
switch (rotation) {
88
case 0:
99
#ifdef M5STACK
10-
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
10+
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
1111
#else
12-
writedata(TFT_MAD_MX | TFT_MAD_BGR);
12+
writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
1313
#endif
1414
_width = _init_width;
1515
_height = _init_height;
1616
break;
1717
case 1:
1818
#ifdef M5STACK
19-
writedata(TFT_MAD_BGR);
19+
writedata(TFT_MAD_COLOR_ORDER);
2020
#else
21-
writedata(TFT_MAD_MV | TFT_MAD_BGR);
21+
writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
2222
#endif
2323
_width = _init_height;
2424
_height = _init_width;
2525
break;
2626
case 2:
2727
#ifdef M5STACK
28-
writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_BGR);
28+
writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
2929
#else
30-
writedata(TFT_MAD_MY | TFT_MAD_BGR);
30+
writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
3131
#endif
3232
_width = _init_width;
3333
_height = _init_height;
3434
break;
3535
case 3:
3636
#ifdef M5STACK
37-
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR);
37+
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
3838
#else
39-
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
39+
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
4040
#endif
4141
_width = _init_height;
4242
_height = _init_width;
4343
break;
4444
// These next rotations are for bottom up BMP drawing
4545
case 4:
4646
#ifdef M5STACK
47-
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
47+
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
4848
#else
49-
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR);
49+
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
5050
#endif
5151
_width = _init_width;
5252
_height = _init_height;
5353
break;
5454
case 5:
5555
#ifdef M5STACK
56-
writedata(TFT_MAD_MY | TFT_MAD_BGR);
56+
writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
5757
#else
58-
writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_BGR);
58+
writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
5959
#endif
6060
_width = _init_height;
6161
_height = _init_width;
6262
break;
6363
case 6:
6464
#ifdef M5STACK
65-
writedata(TFT_MAD_MV | TFT_MAD_BGR);
65+
writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
6666
#else
67-
writedata(TFT_MAD_BGR);
67+
writedata(TFT_MAD_COLOR_ORDER);
6868
#endif
6969
_width = _init_width;
7070
_height = _init_height;
7171
break;
7272
case 7:
7373
#ifdef M5STACK
74-
writedata(TFT_MAD_MX | TFT_MAD_BGR);
74+
writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
7575
#else
76-
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
76+
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
7777
#endif
7878
_width = _init_height;
7979
_height = _init_width;

TFT_eSPI.cpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ inline void TFT_eSPI::spi_end(void){
6767
SPI1U = SPI1U_READ;
6868
#endif
6969
#else
70-
if(!inTransaction) CS_H;
70+
if(!inTransaction) {CS_H;}
7171
#endif
7272
}
7373

@@ -92,7 +92,7 @@ inline void TFT_eSPI::spi_end_read(void){
9292
#if !defined(ESP32_PARALLEL)
9393
spi.setFrequency(SPI_FREQUENCY);
9494
#endif
95-
if(!inTransaction) CS_H;
95+
if(!inTransaction) {CS_H;}
9696
#endif
9797
#ifdef ESP8266
9898
SPI1U = SPI1U_WRITE;
@@ -999,8 +999,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d
999999
if (x < 0) { dw += x; dx = -x; x = 0; }
10001000
if (y < 0) { dh += y; dy = -y; y = 0; }
10011001

1002-
if ((x + w) > _width ) dw = _width - x;
1003-
if ((y + h) > _height) dh = _height - y;
1002+
if ((x + dw) > _width ) dw = _width - x;
1003+
if ((y + dh) > _height) dh = _height - y;
10041004

10051005
if (dw < 1 || dh < 1) return;
10061006

@@ -1038,8 +1038,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d
10381038
if (x < 0) { dw += x; dx = -x; x = 0; }
10391039
if (y < 0) { dh += y; dy = -y; y = 0; }
10401040

1041-
if ((x + w) > _width ) dw = _width - x;
1042-
if ((y + h) > _height) dh = _height - y;
1041+
if ((x + dw) > _width ) dw = _width - x;
1042+
if ((y + dh) > _height) dh = _height - y;
10431043

10441044
if (dw < 1 || dh < 1) return;
10451045

@@ -1113,8 +1113,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1
11131113
if (x < 0) { dw += x; dx = -x; x = 0; }
11141114
if (y < 0) { dh += y; dy = -y; y = 0; }
11151115

1116-
if ((x + w) > _width ) dw = _width - x;
1117-
if ((y + h) > _height) dh = _height - y;
1116+
if ((x + dw) > _width ) dw = _width - x;
1117+
if ((y + dh) > _height) dh = _height - y;
11181118

11191119
if (dw < 1 || dh < 1) return;
11201120

@@ -1177,8 +1177,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1
11771177
if (x < 0) { dw += x; dx = -x; x = 0; }
11781178
if (y < 0) { dh += y; dy = -y; y = 0; }
11791179

1180-
if ((x + w) > _width ) dw = _width - x;
1181-
if ((y + h) > _height) dh = _height - y;
1180+
if ((x + dw) > _width ) dw = _width - x;
1181+
if ((y + dh) > _height) dh = _height - y;
11821182

11831183
if (dw < 1 || dh < 1) return;
11841184

@@ -1251,8 +1251,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da
12511251
if (x < 0) { dw += x; dx = -x; x = 0; }
12521252
if (y < 0) { dh += y; dy = -y; y = 0; }
12531253

1254-
if ((x + w) > _width ) dw = _width - x;
1255-
if ((y + h) > _height) dh = _height - y;
1254+
if ((x + dw) > _width ) dw = _width - x;
1255+
if ((y + dh) > _height) dh = _height - y;
12561256

12571257
if (dw < 1 || dh < 1) return;
12581258

@@ -1357,8 +1357,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da
13571357
if (x < 0) { dw += x; dx = -x; x = 0; }
13581358
if (y < 0) { dh += y; dy = -y; y = 0; }
13591359

1360-
if ((x + w) > _width ) dw = _width - x;
1361-
if ((y + h) > _height) dh = _height - y;
1360+
if ((x + dw) > _width ) dw = _width - x;
1361+
if ((y + dh) > _height) dh = _height - y;
13621362

13631363
if (dw < 1 || dh < 1) return;
13641364

@@ -3938,6 +3938,7 @@ void TFT_eSPI::setAttribute(uint8_t attr_id, uint8_t param) {
39383938
break;
39393939
case 2:
39403940
_utf8 = param;
3941+
decoderState = 0;
39413942
break;
39423943
//case 3: // TBD future feature control
39433944
// _tbd = param;
@@ -3998,7 +3999,7 @@ uint16_t TFT_eSPI::decodeUTF8(uint8_t c)
39983999
return 0;
39994000
}
40004001
// 21 bit Unicode Code Point not supported so fall-back to extended ASCII
4001-
if ((c & 0xF8) == 0xF0) return (uint16_t)c;
4002+
// if ((c & 0xF8) == 0xF0) return (uint16_t)c;
40024003
}
40034004
else
40044005
{

TFT_eSPI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef _TFT_eSPIH_
1616
#define _TFT_eSPIH_
1717

18-
#define TFT_ESPI_VERSION "1.4.16"
18+
#define TFT_ESPI_VERSION "1.4.18"
1919

2020
//#define ESP32 //Just used to test ESP32 options
2121

User_Setup.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
// #define TFT_SDA_READ // This option is for ESP32 ONLY, tested with ST7789 display only
3838

39-
// For ST7789 ONLY, define the colour order IF the blue and red are swapped on your display
39+
// For ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display
4040
// Try ONE option at a time to find the correct colour order for your display
4141

4242
// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue

User_Setup_Select.h

+15-15
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,21 @@
126126
#endif
127127

128128

129-
// These are the pins for all ESP8266 boards
130-
// Name GPIO Function
131-
#define PIN_D0 16 // WAKE
132-
#define PIN_D1 5 // User purpose
133-
#define PIN_D2 4 // User purpose
134-
#define PIN_D3 0 // Low on boot means enter FLASH mode
135-
#define PIN_D4 2 // TXD1 (must be high on boot to go to UART0 FLASH mode)
136-
#define PIN_D5 14 // HSCLK
137-
#define PIN_D6 12 // HMISO
138-
#define PIN_D7 13 // HMOSI RXD2
139-
#define PIN_D8 15 // HCS TXD0 (must be low on boot to enter UART0 FLASH mode)
140-
#define PIN_D9 3 // RXD0
141-
#define PIN_D10 1 // TXD0
142-
143-
#define PIN_MOSI 8 // SD1
129+
// These are the pins for ESP8266 boards
130+
// Name GPIO NodeMCU Function
131+
#define PIN_D0 D0 // GPIO16 WAKE
132+
#define PIN_D1 D1 // GPIO5 User purpose
133+
#define PIN_D2 D2 // GPIO4 User purpose
134+
#define PIN_D3 D3 // GPIO0 Low on boot means enter FLASH mode
135+
#define PIN_D4 D4 // GPIO2 TXD1 (must be high on boot to go to UART0 FLASH mode)
136+
#define PIN_D5 D5 // GPIO14 HSCLK
137+
#define PIN_D6 D6 // GPIO12 HMISO
138+
#define PIN_D7 D7 // GPIO13 HMOSI RXD2
139+
#define PIN_D8 D8 // GPIO15 HCS TXD0 (must be low on boot to enter UART0 FLASH mode)
140+
#define PIN_D9 3 // RXD0
141+
#define PIN_D10 1 // TXD0
142+
143+
#define PIN_MOSI 8 // SD1 FLASH and overlap mode
144144
#define PIN_MISO 7 // SD0
145145
#define PIN_SCLK 6 // CLK
146146
#define PIN_HWCS 0 // D3

User_Setups/Setup22_TTGO_T4.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
//#define SPI_FREQUENCY 27000000
2626
#define SPI_FREQUENCY 40000000 // Maximum for ILI9341
2727

28+
#define USE_HSPI_PORT
2829

2930
#define SPI_READ_FREQUENCY 6000000 // 6 MHz is the maximum SPI read speed for the ST7789V

User_Setups/SetupX_Template.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
// #define TFT_SDA_READ // This option if for ESP32 ONLY, tested with ST7789 display only
3737

38-
// For ST7789 ONLY, define the colour order IF the blue and red are swapped on your display
38+
// For ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display
3939
// Try ONE option at a time to find the correct colour order for your display
4040

4141
// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue

library.json

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

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=TFT_eSPI
2-
version=1.4.17
2+
version=1.4.18
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)