Diagnostic sketch update + others

Read_User_Setup updated to be compatible with STM32 and new structure format.
Reduction in compiler warnings
Update Sprite destructor
Update version to 2.2.1
This commit is contained in:
Bodmer
2020-04-16 14:33:42 +01:00
parent 875b451590
commit e937a3496f
9 changed files with 122 additions and 93 deletions

View File

@@ -117,6 +117,10 @@ void TFT_eSPI::loadFont(String fontName, bool flash)
fontFile.seek(0, fs::SeekSet); fontFile.seek(0, fs::SeekSet);
} }
#else
// Avoid unused varaible warning
fontName = fontName;
flash = flash;
#endif #endif
gFont.gArray = (const uint8_t*)fontPtr; gFont.gArray = (const uint8_t*)fontPtr;

View File

@@ -105,6 +105,10 @@ void* TFT_eSprite::createSprite(int16_t w, int16_t h, uint8_t frames)
TFT_eSprite::~TFT_eSprite(void) TFT_eSprite::~TFT_eSprite(void)
{ {
deleteSprite(); deleteSprite();
#ifdef SMOOTH_FONT
if(this->fontLoaded) this->unloadFont();
#endif
} }

View File

@@ -2,6 +2,9 @@
// TFT_eSPI generic driver functions // // TFT_eSPI generic driver functions //
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// This is a generic driver for Arduino boards, it supports SPI interface displays
// 8 bit parallel interface to TFT is not supported for generic processors
#ifndef _TFT_eSPI_GENERICH_ #ifndef _TFT_eSPI_GENERICH_
#define _TFT_eSPI_GENERICH_ #define _TFT_eSPI_GENERICH_

View File

@@ -45,7 +45,7 @@
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// Write strobe timing setup // Write strobe timing setup
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
#if defined (ILI9341_DRIVER) || defined (ST7796_DRIVER) // WRX twc spec is 66ns = 15.15MHz #if defined (ILI9341_DRIVER) || defined (ST7796_DRIVER) || defined (ILI9486_DRIVER) // WRX twc spec is <=66ns = 15.15MHz
// Extra write pulse low time (delay for data setup) // Extra write pulse low time (delay for data setup)
#if defined (STM32F1xx) #if defined (STM32F1xx)
@@ -63,7 +63,7 @@
#if defined (STM32F1xx) #if defined (STM32F1xx)
#define WR_TWRH_0 #define WR_TWRH_0
#elif defined (STM32F2xx) || defined (STM32F4xx) #elif defined (STM32F2xx) || defined (STM32F4xx)
#define WR_TWRH_1 // Tested with STM32F446 #define WR_TWRH_0 // Tested with STM32F446
//#define WR_TWRL_3 //#define WR_TWRL_3
#elif defined (STM32F7xx) #elif defined (STM32F7xx)
#define WR_TWRH_1 //Tested with STM32F767 #define WR_TWRH_1 //Tested with STM32F767

View File

@@ -1526,7 +1526,8 @@ void TFT_eSPI::readRectRGB(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_
readRect(x0, y0, w, h, (uint16_t*)buf565); readRect(x0, y0, w, h, (uint16_t*)buf565);
while (len--) { while (len--) {
uint16_t pixel565 = (*buf565++)<<8 | (*buf565++); uint16_t pixel565 = (*buf565++)<<8;
pixel565 |= *buf565++;
uint8_t red = (pixel565 & 0xF800) >> 8; red |= red >> 5; uint8_t red = (pixel565 & 0xF800) >> 8; red |= red >> 5;
uint8_t green = (pixel565 & 0x07E0) >> 3; green |= green >> 6; uint8_t green = (pixel565 & 0x07E0) >> 3; green |= green >> 6;
uint8_t blue = (pixel565 & 0x001F) << 3; blue |= blue >> 5; uint8_t blue = (pixel565 & 0x001F) << 3; blue |= blue >> 5;
@@ -1685,23 +1686,21 @@ void TFT_eSPI::drawCircleHelper( int32_t x0, int32_t y0, int32_t r, uint8_t corn
// Improved algorithm avoids repetition of lines // Improved algorithm avoids repetition of lines
void TFT_eSPI::fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color) void TFT_eSPI::fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color)
{ {
int32_t x = 1; int32_t x = 0;
int32_t dx = 1; int32_t dx = 1;
int32_t dy = r+r; int32_t dy = r+r;
int32_t ly = y0;
int32_t p = -(r>>1); int32_t p = -(r>>1);
int32_t xo = 0;
//begin_tft_write(); // Sprite class can use this function, avoiding begin_tft_write() //begin_tft_write(); // Sprite class can use this function, avoiding begin_tft_write()
inTransaction = true; inTransaction = true;
drawFastHLine(x0 - r, y0, dy+1, color); drawFastHLine(x0 - r, y0, dy+1, color);
while(xo<r){ while(x<r){
if(p>=0) { if(p>=0) {
drawFastHLine(x0 - xo, y0 + r, 2 * xo+1, color); drawFastHLine(x0 - x + 1, y0 + r, dx-1, color);
drawFastHLine(x0 - xo, y0 - r, 2 * xo+1, color); drawFastHLine(x0 - x + 1, y0 - r, dx-1, color);
dy-=2; dy-=2;
p-=dy; p-=dy;
r--; r--;
@@ -1709,11 +1708,11 @@ void TFT_eSPI::fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color)
dx+=2; dx+=2;
p+=dx; p+=dx;
xo = x;
drawFastHLine(x0 - r, y0 + x, 2 * r+1, color);
drawFastHLine(x0 - r, y0 - x, 2 * r+1, color);
x++; x++;
drawFastHLine(x0 - r, y0 + x, dy+1, color);
drawFastHLine(x0 - r, y0 - x, dy+1, color);
} }
inTransaction = false; inTransaction = false;

View File

@@ -16,7 +16,7 @@
#ifndef _TFT_eSPIH_ #ifndef _TFT_eSPIH_
#define _TFT_eSPIH_ #define _TFT_eSPIH_
#define TFT_ESPI_VERSION "2.2.0" #define TFT_ESPI_VERSION "2.2.1"
/*************************************************************************************** /***************************************************************************************
** Section 1: Load required header files ** Section 1: Load required header files

View File

@@ -12,6 +12,7 @@
Written by Bodmer 9/4/18 Written by Bodmer 9/4/18
*/ */
//>>>>> Note: STM32 pin references above D15 may not reflect board markings <<<<<
#include <SPI.h> #include <SPI.h>
#include <TFT_eSPI.h> // Graphics library #include <TFT_eSPI.h> // Graphics library
@@ -40,116 +41,134 @@ void loop(void) {
tft.getSetup(user); // tft.getSetup(user); //
Serial.printf("\n[code]\n"); Serial.print("\n[code]\n");
Serial.print ("TFT_eSPI ver = " + user.version + "\n"); Serial.print ("TFT_eSPI ver = "); Serial.println(user.version);
Serial.printf("Processor = ESP%i\n", user.esp, HEX); printProcessorName();
Serial.printf("Frequency = %i MHz\n", ESP.getCpuFreqMHz()); #if defined (ESP32) || defined (ESP8266)
#ifdef ESP8266 if (user.esp < 0x32F000 || user.esp > 0x32FFFF) { Serial.print("Frequency = "); Serial.print(ESP.getCpuFreqMHz());Serial.println("MHz"); }
Serial.printf("Voltage = %2.2f V\n", ESP.getVcc() / 918.0); // 918 empirically determined
#endif #endif
Serial.printf("Transactions = %s \n", (user.trans == 1) ? "Yes" : "No");
Serial.printf("Interface = %s \n", (user.serial == 1) ? "SPI" : "Parallel");
#ifdef ESP8266 #ifdef ESP8266
if (user.serial == 1) Serial.print("Voltage = "); Serial.print(ESP.getVcc() / 918.0); Serial.println("V"); // 918 empirically determined
Serial.printf("SPI overlap = %s \n\n", (user.overlap == 1) ? "Yes" : "No"); #endif
Serial.print("Transactions = "); Serial.println((user.trans == 1) ? "Yes" : "No");
Serial.print("Interface = "); Serial.println((user.serial == 1) ? "SPI" : "Parallel");
#ifdef ESP8266
if (user.serial == 1){ Serial.print("SPI overlap = "); Serial.println((user.overlap == 1) ? "Yes\n" : "No\n"); }
#endif #endif
if (user.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch if (user.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch
{ {
Serial.printf("Display driver = "); Serial.println(user.tft_driver, HEX); // Hexadecimal code Serial.print("Display driver = "); Serial.println(user.tft_driver, HEX); // Hexadecimal code
Serial.printf("Display width = %i \n", user.tft_width); // Rotation 0 width and height Serial.print("Display width = "); Serial.println(user.tft_width); // Rotation 0 width and height
Serial.printf("Display height = %i \n\n", user.tft_height); Serial.print("Display height = "); Serial.println(user.tft_height);
} }
else if (user.tft_driver == 0xE9D) Serial.printf("Display driver = ePaper\n\n"); else if (user.tft_driver == 0xE9D) Serial.println("Display driver = ePaper\n");
if (user.r0_x_offset != 0) Serial.printf("R0 x offset = %i \n", user.r0_x_offset); // Offsets, not all used yet if (user.r0_x_offset != 0) { Serial.print("R0 x offset = "); Serial.println(user.r0_x_offset); } // Offsets, not all used yet
if (user.r0_y_offset != 0) Serial.printf("R0 y offset = %i \n", user.r0_y_offset); if (user.r0_y_offset != 0) { Serial.print("R0 y offset = "); Serial.println(user.r0_y_offset); }
if (user.r1_x_offset != 0) Serial.printf("R1 x offset = %i \n", user.r1_x_offset); if (user.r1_x_offset != 0) { Serial.print("R1 x offset = "); Serial.println(user.r1_x_offset); }
if (user.r1_y_offset != 0) Serial.printf("R1 y offset = %i \n", user.r1_y_offset); if (user.r1_y_offset != 0) { Serial.print("R1 y offset = "); Serial.println(user.r1_y_offset); }
if (user.r2_x_offset != 0) Serial.printf("R2 x offset = %i \n", user.r2_x_offset); if (user.r2_x_offset != 0) { Serial.print("R2 x offset = "); Serial.println(user.r2_x_offset); }
if (user.r2_y_offset != 0) Serial.printf("R2 y offset = %i \n", user.r2_y_offset); if (user.r2_y_offset != 0) { Serial.print("R2 y offset = "); Serial.println(user.r2_y_offset); }
if (user.r3_x_offset != 0) Serial.printf("R3 x offset = %i \n", user.r3_x_offset); if (user.r3_x_offset != 0) { Serial.print("R3 x offset = "); Serial.println(user.r3_x_offset); }
if (user.r3_y_offset != 0) Serial.printf("R3 y offset = %i \n\n", user.r3_y_offset); if (user.r3_y_offset != 0) { Serial.print("R3 y offset = "); Serial.println(user.r3_y_offset); }
if (user.pin_tft_mosi != -1) Serial.printf("MOSI = D%i (GPIO %i)\n", getPinName(user.pin_tft_mosi), user.pin_tft_mosi); if (user.pin_tft_mosi != -1) { Serial.print("MOSI = "); Serial.print("GPIO "); Serial.print(getPinName(user.pin_tft_mosi)); Serial.println(user.pin_tft_mosi); }
if (user.pin_tft_miso != -1) Serial.printf("MISO = D%i (GPIO %i)\n", getPinName(user.pin_tft_miso), user.pin_tft_miso); if (user.pin_tft_miso != -1) { Serial.print("MISO = "); Serial.print("GPIO "); Serial.print(getPinName(user.pin_tft_miso)); Serial.println(user.pin_tft_miso); }
if (user.pin_tft_clk != -1) Serial.printf("SCK = D%i (GPIO %i)\n", getPinName(user.pin_tft_clk), user.pin_tft_clk); if (user.pin_tft_clk != -1) { Serial.print("SCK = "); Serial.print("GPIO "); Serial.print(getPinName(user.pin_tft_clk)); Serial.println(user.pin_tft_clk); }
#ifdef ESP8266 #ifdef ESP8266
if (user.overlap == true) if (user.overlap == true)
{ {
Serial.printf("Overlap selected, following pins MUST be used:\n"); Serial.println("Overlap selected, following pins MUST be used:");
Serial.printf("MOSI = SD1 (GPIO 8)\n"); Serial.println("MOSI = SD1 (GPIO 8)");
Serial.printf("MISO = SD0 (GPIO 7)\n"); Serial.println("MISO = SD0 (GPIO 7)");
Serial.printf("SCK = CLK (GPIO 6)\n"); Serial.println("SCK = CLK (GPIO 6)");
Serial.printf("TFT_CS = D3 (GPIO 0)\n\n"); Serial.println("TFT_CS = D3 (GPIO 0)\n");
Serial.printf("TFT_DC and TFT_RST pins can be user defined\n"); Serial.println("TFT_DC and TFT_RST pins can be user defined");
} }
#endif #endif
if (user.pin_tft_cs != -1) Serial.printf("TFT_CS = D%i (GPIO %i)\n", getPinName(user.pin_tft_cs), user.pin_tft_cs); String pinNameRef = "GPIO ";
if (user.pin_tft_dc != -1) Serial.printf("TFT_DC = D%i (GPIO %i)\n", getPinName(user.pin_tft_dc), user.pin_tft_dc); if (user.esp == 0x32F) {
if (user.pin_tft_rst != -1) Serial.printf("TFT_RST = D%i (GPIO %i)\n\n", getPinName(user.pin_tft_rst), user.pin_tft_rst); Serial.println("\n>>>>> Note: STM32 pin references above D15 may not reflect board markings <<<<<");
pinNameRef = "D";
}
if (user.pin_tft_cs != -1) { Serial.print("TFT_CS = " + pinNameRef); Serial.println(getPinName(user.pin_tft_cs)); }
if (user.pin_tft_dc != -1) { Serial.print("TFT_DC = " + pinNameRef); Serial.println(getPinName(user.pin_tft_dc)); }
if (user.pin_tft_rst!= -1) { Serial.print("TFT_RST = " + pinNameRef); Serial.println(getPinName(user.pin_tft_rst)); }
if (user.pin_tch_cs != -1) Serial.printf("TOUCH_CS = D%i (GPIO %i)\n\n", getPinName(user.pin_tch_cs), user.pin_tch_cs); if (user.pin_tch_cs != -1) { Serial.print("TOUCH_CS = " + pinNameRef); Serial.println(getPinName(user.pin_tch_cs)); }
if (user.pin_tft_wr != -1) Serial.printf("TFT_WR = D%i (GPIO %i)\n", getPinName(user.pin_tft_wr), user.pin_tft_wr); if (user.pin_tft_wr != -1) { Serial.print("TFT_WR = " + pinNameRef); Serial.println(getPinName(user.pin_tft_wr)); }
if (user.pin_tft_rd != -1) Serial.printf("TFT_RD = D%i (GPIO %i)\n\n", getPinName(user.pin_tft_rd), user.pin_tft_rd); if (user.pin_tft_rd != -1) { Serial.print("TFT_RD = " + pinNameRef); Serial.println(getPinName(user.pin_tft_rd)); }
if (user.pin_tft_d0 != -1) Serial.printf("TFT_D0 = D%i (GPIO %i)\n", getPinName(user.pin_tft_d0), user.pin_tft_d0); if (user.pin_tft_d0 != -1) { Serial.print("\nTFT_D0 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d0)); }
if (user.pin_tft_d1 != -1) Serial.printf("TFT_D1 = D%i (GPIO %i)\n", getPinName(user.pin_tft_d1), user.pin_tft_d1); if (user.pin_tft_d1 != -1) { Serial.print("TFT_D1 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d1)); }
if (user.pin_tft_d2 != -1) Serial.printf("TFT_D2 = D%i (GPIO %i)\n", getPinName(user.pin_tft_d2), user.pin_tft_d2); if (user.pin_tft_d2 != -1) { Serial.print("TFT_D2 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d2)); }
if (user.pin_tft_d3 != -1) Serial.printf("TFT_D3 = D%i (GPIO %i)\n", getPinName(user.pin_tft_d3), user.pin_tft_d3); if (user.pin_tft_d3 != -1) { Serial.print("TFT_D3 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d3)); }
if (user.pin_tft_d4 != -1) Serial.printf("TFT_D4 = D%i (GPIO %i)\n", getPinName(user.pin_tft_d4), user.pin_tft_d4); if (user.pin_tft_d4 != -1) { Serial.print("TFT_D4 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d4)); }
if (user.pin_tft_d5 != -1) Serial.printf("TFT_D5 = D%i (GPIO %i)\n", getPinName(user.pin_tft_d5), user.pin_tft_d5); if (user.pin_tft_d5 != -1) { Serial.print("TFT_D5 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d5)); }
if (user.pin_tft_d6 != -1) Serial.printf("TFT_D6 = D%i (GPIO %i)\n", getPinName(user.pin_tft_d6), user.pin_tft_d6); if (user.pin_tft_d6 != -1) { Serial.print("TFT_D6 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d6)); }
if (user.pin_tft_d7 != -1) Serial.printf("TFT_D7 = D%i (GPIO %i)\n\n", getPinName(user.pin_tft_d7), user.pin_tft_d7); if (user.pin_tft_d7 != -1) { Serial.print("TFT_D7 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d7)); }
uint16_t fonts = tft.fontsLoaded(); uint16_t fonts = tft.fontsLoaded();
if (fonts & (1 << 1)) Serial.printf("Font GLCD loaded\n"); if (fonts & (1 << 1)) Serial.print("Font GLCD loaded\n");
if (fonts & (1 << 2)) Serial.printf("Font 2 loaded\n"); if (fonts & (1 << 2)) Serial.print("Font 2 loaded\n");
if (fonts & (1 << 4)) Serial.printf("Font 4 loaded\n"); if (fonts & (1 << 4)) Serial.print("Font 4 loaded\n");
if (fonts & (1 << 6)) Serial.printf("Font 6 loaded\n"); if (fonts & (1 << 6)) Serial.print("Font 6 loaded\n");
if (fonts & (1 << 7)) Serial.printf("Font 7 loaded\n"); if (fonts & (1 << 7)) Serial.print("Font 7 loaded\n");
if (fonts & (1 << 9)) Serial.printf("Font 8N loaded\n"); if (fonts & (1 << 9)) Serial.print("Font 8N loaded\n");
else else
if (fonts & (1 << 8)) Serial.printf("Font 8 loaded\n"); if (fonts & (1 << 8)) Serial.print("Font 8 loaded\n");
if (fonts & (1 << 15)) Serial.printf("Smooth font enabled\n"); if (fonts & (1 << 15)) Serial.print("Smooth font enabled\n");
Serial.printf("\n"); Serial.print("\n");
if (user.serial==1) Serial.printf("Display SPI frequency = %2.1f MHz \n", user.tft_spi_freq/10.0); if (user.serial==1) { Serial.print("Display SPI frequency = "); Serial.println(user.tft_spi_freq/10.0); }
if (user.pin_tch_cs != -1) Serial.printf("Touch SPI frequency = %2.1f MHz \n", user.tch_spi_freq/10.0); if (user.pin_tch_cs != -1) { Serial.print("Touch SPI frequency = "); Serial.println(user.tch_spi_freq/10.0); }
Serial.printf("[/code]\n"); Serial.println("[/code]");
while(1) yield(); while(1) yield();
} }
// Get pin name for ESP8266 void printProcessorName(void)
{
Serial.print("Processor = ");
if ( user.esp == 0x8266) Serial.println("ESP8266");
if ( user.esp == 0x32) Serial.println("ESP32");
if ( user.esp == 0x32F) Serial.println("STM32");
if ( user.esp == 0x0000) Serial.println("Generic");
}
// Get pin name
int8_t getPinName(int8_t pin) int8_t getPinName(int8_t pin)
{ {
// For ESP32 pin labels on boards use the GPIO number // For ESP32 pin labels on boards use the GPIO number
if (user.esp == 32) return pin; if (user.esp == 0x32) return pin;
// For ESP8266 the pin labels are not the same as the GPIO number if (user.esp == 0x8266) {
// These are for the NodeMCU pin definitions: // For ESP8266 the pin labels are not the same as the GPIO number
// GPIO Dxx // These are for the NodeMCU pin definitions:
if (pin == 16) return 0; // GPIO Dxx
if (pin == 5) return 1; if (pin == 16) return 0;
if (pin == 4) return 2; if (pin == 5) return 1;
if (pin == 0) return 3; if (pin == 4) return 2;
if (pin == 2) return 4; if (pin == 0) return 3;
if (pin == 14) return 5; if (pin == 2) return 4;
if (pin == 12) return 6; if (pin == 14) return 5;
if (pin == 13) return 7; if (pin == 12) return 6;
if (pin == 15) return 8; if (pin == 13) return 7;
if (pin == 3) return 9; if (pin == 15) return 8;
if (pin == 1) return 10; if (pin == 3) return 9;
if (pin == 9) return 11; if (pin == 1) return 10;
if (pin == 10) return 12; if (pin == 9) return 11;
if (pin == 10) return 12;
}
if (user.esp == 0x32F) return pin;
return -1; // Invalid pin return -1; // Invalid pin
} }

View File

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

View File

@@ -1,5 +1,5 @@
name=TFT_eSPI name=TFT_eSPI
version=2.2.0 version=2.2.1
author=Bodmer author=Bodmer
maintainer=Bodmer maintainer=Bodmer
sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32 sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32