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.
This commit is contained in:
Bodmer
2019-10-21 22:56:35 +01:00
parent d3210a7ee6
commit e9d405ea1f
12 changed files with 65 additions and 53 deletions

View File

@ -14,7 +14,7 @@ https://github.com/Bodmer/TFT_eFX
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.
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:
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:
//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
//#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red

View File

@ -51,6 +51,16 @@
#define TFT_MAD_MH 0x04
#define TFT_MAD_RGB 0x00
#ifdef TFT_RGB_ORDER
#if (TFT_RGB_ORDER == 1)
#define TFT_MAD_COLOR_ORDER TFT_MAD_RGB
#else
#define TFT_MAD_COLOR_ORDER TFT_MAD_BGR
#endif
#else
#define TFT_MAD_COLOR_ORDER TFT_MAD_BGR
#endif
#define TFT_INVOFF 0x20
#define TFT_INVON 0x21

View File

@ -56,9 +56,9 @@
writecommand(ILI9341_MADCTL); // Memory Access Control
#ifdef M5STACK
writedata(0xA8); // Rotation 0 (portrait mode)
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); // Rotation 0 (portrait mode)
#else
writedata(0x48); // Rotation 0 (portrait mode)
writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER); // Rotation 0 (portrait mode)
#endif
writecommand(ILI9341_PIXFMT);

View File

@ -7,36 +7,36 @@
switch (rotation) {
case 0:
#ifdef M5STACK
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
#else
writedata(TFT_MAD_MX | TFT_MAD_BGR);
writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
#endif
_width = _init_width;
_height = _init_height;
break;
case 1:
#ifdef M5STACK
writedata(TFT_MAD_BGR);
writedata(TFT_MAD_COLOR_ORDER);
#else
writedata(TFT_MAD_MV | TFT_MAD_BGR);
writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
#endif
_width = _init_height;
_height = _init_width;
break;
case 2:
#ifdef M5STACK
writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_BGR);
writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
#else
writedata(TFT_MAD_MY | TFT_MAD_BGR);
writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
#endif
_width = _init_width;
_height = _init_height;
break;
case 3:
#ifdef M5STACK
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR);
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
#else
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
#endif
_width = _init_height;
_height = _init_width;
@ -44,36 +44,36 @@
// These next rotations are for bottom up BMP drawing
case 4:
#ifdef M5STACK
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
#else
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR);
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
#endif
_width = _init_width;
_height = _init_height;
break;
case 5:
#ifdef M5STACK
writedata(TFT_MAD_MY | TFT_MAD_BGR);
writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
#else
writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_BGR);
writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
#endif
_width = _init_height;
_height = _init_width;
break;
case 6:
#ifdef M5STACK
writedata(TFT_MAD_MV | TFT_MAD_BGR);
writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
#else
writedata(TFT_MAD_BGR);
writedata(TFT_MAD_COLOR_ORDER);
#endif
_width = _init_width;
_height = _init_height;
break;
case 7:
#ifdef M5STACK
writedata(TFT_MAD_MX | TFT_MAD_BGR);
writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER);
#else
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
#endif
_width = _init_height;
_height = _init_width;

View File

@ -67,7 +67,7 @@ inline void TFT_eSPI::spi_end(void){
SPI1U = SPI1U_READ;
#endif
#else
if(!inTransaction) CS_H;
if(!inTransaction) {CS_H;}
#endif
}
@ -92,7 +92,7 @@ inline void TFT_eSPI::spi_end_read(void){
#if !defined(ESP32_PARALLEL)
spi.setFrequency(SPI_FREQUENCY);
#endif
if(!inTransaction) CS_H;
if(!inTransaction) {CS_H;}
#endif
#ifdef ESP8266
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
if (x < 0) { dw += x; dx = -x; x = 0; }
if (y < 0) { dh += y; dy = -y; y = 0; }
if ((x + w) > _width ) dw = _width - x;
if ((y + h) > _height) dh = _height - y;
if ((x + dw) > _width ) dw = _width - x;
if ((y + dh) > _height) dh = _height - y;
if (dw < 1 || dh < 1) return;
@ -1038,8 +1038,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d
if (x < 0) { dw += x; dx = -x; x = 0; }
if (y < 0) { dh += y; dy = -y; y = 0; }
if ((x + w) > _width ) dw = _width - x;
if ((y + h) > _height) dh = _height - y;
if ((x + dw) > _width ) dw = _width - x;
if ((y + dh) > _height) dh = _height - y;
if (dw < 1 || dh < 1) return;
@ -1113,8 +1113,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1
if (x < 0) { dw += x; dx = -x; x = 0; }
if (y < 0) { dh += y; dy = -y; y = 0; }
if ((x + w) > _width ) dw = _width - x;
if ((y + h) > _height) dh = _height - y;
if ((x + dw) > _width ) dw = _width - x;
if ((y + dh) > _height) dh = _height - y;
if (dw < 1 || dh < 1) return;
@ -1177,8 +1177,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1
if (x < 0) { dw += x; dx = -x; x = 0; }
if (y < 0) { dh += y; dy = -y; y = 0; }
if ((x + w) > _width ) dw = _width - x;
if ((y + h) > _height) dh = _height - y;
if ((x + dw) > _width ) dw = _width - x;
if ((y + dh) > _height) dh = _height - y;
if (dw < 1 || dh < 1) return;
@ -1251,8 +1251,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da
if (x < 0) { dw += x; dx = -x; x = 0; }
if (y < 0) { dh += y; dy = -y; y = 0; }
if ((x + w) > _width ) dw = _width - x;
if ((y + h) > _height) dh = _height - y;
if ((x + dw) > _width ) dw = _width - x;
if ((y + dh) > _height) dh = _height - y;
if (dw < 1 || dh < 1) return;
@ -1357,8 +1357,8 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da
if (x < 0) { dw += x; dx = -x; x = 0; }
if (y < 0) { dh += y; dy = -y; y = 0; }
if ((x + w) > _width ) dw = _width - x;
if ((y + h) > _height) dh = _height - y;
if ((x + dw) > _width ) dw = _width - x;
if ((y + dh) > _height) dh = _height - y;
if (dw < 1 || dh < 1) return;
@ -3938,6 +3938,7 @@ void TFT_eSPI::setAttribute(uint8_t attr_id, uint8_t param) {
break;
case 2:
_utf8 = param;
decoderState = 0;
break;
//case 3: // TBD future feature control
// _tbd = param;
@ -3998,7 +3999,7 @@ uint16_t TFT_eSPI::decodeUTF8(uint8_t c)
return 0;
}
// 21 bit Unicode Code Point not supported so fall-back to extended ASCII
if ((c & 0xF8) == 0xF0) return (uint16_t)c;
// if ((c & 0xF8) == 0xF0) return (uint16_t)c;
}
else
{

View File

@ -15,7 +15,7 @@
#ifndef _TFT_eSPIH_
#define _TFT_eSPIH_
#define TFT_ESPI_VERSION "1.4.16"
#define TFT_ESPI_VERSION "1.4.18"
//#define ESP32 //Just used to test ESP32 options

View File

@ -36,7 +36,7 @@
// #define TFT_SDA_READ // This option is for ESP32 ONLY, tested with ST7789 display only
// For ST7789 ONLY, define the colour order IF the blue and red are swapped on your display
// For ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display
// Try ONE option at a time to find the correct colour order for your display
// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue

View File

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

View File

@ -25,5 +25,6 @@
//#define SPI_FREQUENCY 27000000
#define SPI_FREQUENCY 40000000 // Maximum for ILI9341
#define USE_HSPI_PORT
#define SPI_READ_FREQUENCY 6000000 // 6 MHz is the maximum SPI read speed for the ST7789V

View File

@ -35,7 +35,7 @@
// #define TFT_SDA_READ // This option if for ESP32 ONLY, tested with ST7789 display only
// For ST7789 ONLY, define the colour order IF the blue and red are swapped on your display
// For ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display
// Try ONE option at a time to find the correct colour order for your display
// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue

View File

@ -1,6 +1,6 @@
{
"name": "TFT_eSPI",
"version": "1.4.17",
"version": "1.4.18",
"keywords": "tft, ePaper, display, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789, RM68140",
"description": "A TFT and ePaper SPI graphics library for ESP8266 and ESP32",
"repository":

View File

@ -1,5 +1,5 @@
name=TFT_eSPI
version=1.4.17
version=1.4.18
author=Bodmer
maintainer=Bodmer
sentence=A fast TFT graphics library for ESP8266 and ESP32 processors for the Arduino IDE