mirror of
https://github.com/Bodmer/TFT_eSPI.git
synced 2025-08-04 21:24:44 +02:00
Allow init() to be called in sketch to reset and re-initialise TFT
Solution to Issue #85
This commit is contained in:
39
TFT_eSPI.cpp
39
TFT_eSPI.cpp
@@ -123,6 +123,8 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h)
|
|||||||
locked = true; // ESP32 transaction mutex lock flags
|
locked = true; // ESP32 transaction mutex lock flags
|
||||||
inTransaction = false;
|
inTransaction = false;
|
||||||
|
|
||||||
|
_booted = true;
|
||||||
|
|
||||||
addr_row = 0xFFFF;
|
addr_row = 0xFFFF;
|
||||||
addr_col = 0xFFFF;
|
addr_col = 0xFFFF;
|
||||||
|
|
||||||
@@ -169,6 +171,8 @@ void TFT_eSPI::begin(void)
|
|||||||
***************************************************************************************/
|
***************************************************************************************/
|
||||||
void TFT_eSPI::init(void)
|
void TFT_eSPI::init(void)
|
||||||
{
|
{
|
||||||
|
if (_booted)
|
||||||
|
{
|
||||||
#if !defined (ESP32)
|
#if !defined (ESP32)
|
||||||
#ifdef TFT_CS
|
#ifdef TFT_CS
|
||||||
cspinmask = (uint32_t) digitalPinToBitMask(TFT_CS);
|
cspinmask = (uint32_t) digitalPinToBitMask(TFT_CS);
|
||||||
@@ -189,7 +193,7 @@ void TFT_eSPI::init(void)
|
|||||||
SPI.pins(6, 7, 8, 0);
|
SPI.pins(6, 7, 8, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SPI.begin(); // This will set HMISO to input
|
SPI.begin(); // This will set HMISO to input
|
||||||
#else
|
#else
|
||||||
#if defined (TFT_MOSI) && !defined (TFT_SPI_OVERLAP)
|
#if defined (TFT_MOSI) && !defined (TFT_SPI_OVERLAP)
|
||||||
SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, -1);
|
SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, -1);
|
||||||
@@ -199,31 +203,35 @@ void TFT_eSPI::init(void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inTransaction = false;
|
inTransaction = false;
|
||||||
locked = true;
|
locked = true;
|
||||||
|
|
||||||
// SUPPORT_TRANSACTIONS is manadatory for ESP32 so the hal mutex is toggled
|
// SUPPORT_TRANSACTIONS is manadatory for ESP32 so the hal mutex is toggled
|
||||||
// so the code here is for ESP8266 only
|
// so the code here is for ESP8266 only
|
||||||
#if !defined (SUPPORT_TRANSACTIONS) && defined (ESP8266)
|
#if !defined (SUPPORT_TRANSACTIONS) && defined (ESP8266)
|
||||||
SPI.setBitOrder(MSBFIRST);
|
SPI.setBitOrder(MSBFIRST);
|
||||||
SPI.setDataMode(SPI_MODE0);
|
SPI.setDataMode(SPI_MODE0);
|
||||||
SPI.setFrequency(SPI_FREQUENCY);
|
SPI.setFrequency(SPI_FREQUENCY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set to output once again in case D6 (MISO) is used for CS
|
// Set to output once again in case D6 (MISO) is used for CS
|
||||||
#ifdef TFT_CS
|
#ifdef TFT_CS
|
||||||
digitalWrite(TFT_CS, HIGH); // Chip select high (inactive)
|
digitalWrite(TFT_CS, HIGH); // Chip select high (inactive)
|
||||||
pinMode(TFT_CS, OUTPUT);
|
pinMode(TFT_CS, OUTPUT);
|
||||||
#else
|
#else
|
||||||
SPI.setHwCs(1); // Use hardware SS toggling
|
SPI.setHwCs(1); // Use hardware SS toggling
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set to output once again in case D6 (MISO) is used for DC
|
// Set to output once again in case D6 (MISO) is used for DC
|
||||||
#ifdef TFT_DC
|
#ifdef TFT_DC
|
||||||
digitalWrite(TFT_DC, HIGH); // Data/Command high = data mode
|
digitalWrite(TFT_DC, HIGH); // Data/Command high = data mode
|
||||||
pinMode(TFT_DC, OUTPUT);
|
pinMode(TFT_DC, OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
_booted = false;
|
||||||
|
} // end of: if just _booted
|
||||||
|
|
||||||
|
|
||||||
// Toggle RST low to reset
|
// Toggle RST low to reset
|
||||||
#ifdef TFT_RST
|
#ifdef TFT_RST
|
||||||
if (TFT_RST >= 0) {
|
if (TFT_RST >= 0) {
|
||||||
@@ -234,13 +242,13 @@ void TFT_eSPI::init(void)
|
|||||||
digitalWrite(TFT_RST, HIGH);
|
digitalWrite(TFT_RST, HIGH);
|
||||||
delay(150);
|
delay(150);
|
||||||
}
|
}
|
||||||
#endif
|
#else
|
||||||
|
// Or use the software reset
|
||||||
spi_begin();
|
spi_begin();
|
||||||
writecommand(TFT_SWRST); // Software reset
|
writecommand(TFT_SWRST); // Software reset
|
||||||
spi_end();
|
spi_end();
|
||||||
|
delay(120); // Wait for software reset to complete
|
||||||
delay(5); // Wait for software reset to complete
|
#endif
|
||||||
|
|
||||||
spi_begin();
|
spi_begin();
|
||||||
|
|
||||||
@@ -264,6 +272,7 @@ void TFT_eSPI::init(void)
|
|||||||
|
|
||||||
spi_end();
|
spi_end();
|
||||||
|
|
||||||
|
setRotation(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -516,6 +516,7 @@ class TFT_eSPI : public Print {
|
|||||||
bool textwrap; // If set, 'wrap' text at right edge of display
|
bool textwrap; // If set, 'wrap' text at right edge of display
|
||||||
bool _swapBytes; // Swap the byte order for TFT pushImage()
|
bool _swapBytes; // Swap the byte order for TFT pushImage()
|
||||||
bool locked, inTransaction; // Transaction and mutex lock flags for ESP32
|
bool locked, inTransaction; // Transaction and mutex lock flags for ESP32
|
||||||
|
bool _booted;
|
||||||
|
|
||||||
int32_t _lastColor;
|
int32_t _lastColor;
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "TFT_eSPI",
|
"name": "TFT_eSPI",
|
||||||
"version": "0.18.12",
|
"version": "0.18.13",
|
||||||
"keywords": "TFT, ESP8266, NodeMCU, ESP32, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486",
|
"keywords": "TFT, ESP8266, NodeMCU, ESP32, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486",
|
||||||
"description": "A TFT SPI graphics library for ESP8266",
|
"description": "A TFT SPI graphics library for ESP8266",
|
||||||
"repository":
|
"repository":
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
name=TFT_eSPI
|
name=TFT_eSPI
|
||||||
version=0.18.12
|
version=0.18.13
|
||||||
author=Bodmer
|
author=Bodmer
|
||||||
maintainer=Bodmer
|
maintainer=Bodmer
|
||||||
sentence=A fast TFT library for ESP8266 processors and the Arduino IDE
|
sentence=A fast TFT library for ESP8266 processors and the Arduino IDE
|
||||||
|
Reference in New Issue
Block a user