diff --git a/Extensions/Touch.cpp b/Extensions/Touch.cpp index 943d2e0..3f45102 100644 --- a/Extensions/Touch.cpp +++ b/Extensions/Touch.cpp @@ -16,11 +16,8 @@ ***************************************************************************************/ uint8_t TFT_eSPI::getTouchRaw(uint16_t *x, uint16_t *y){ uint16_t tmp; - CS_H; spi_begin_touch(); - - T_CS_L; // Start YP sample request for x position, read 4 times and keep last sample spi.transfer(0xd0); // Start new YP conversion @@ -51,8 +48,6 @@ uint8_t TFT_eSPI::getTouchRaw(uint16_t *x, uint16_t *y){ *y = tmp; - T_CS_H; - spi_end_touch(); return true; @@ -63,20 +58,15 @@ uint8_t TFT_eSPI::getTouchRaw(uint16_t *x, uint16_t *y){ ** Description: read raw pressure on touchpad and return Z value. ***************************************************************************************/ uint16_t TFT_eSPI::getTouchRawZ(void){ - CS_H; spi_begin_touch(); - T_CS_L; - - // Calculate Z + // Z sample request int16_t tz = 0xFFF; spi.transfer(0xb0); // Start new Z1 conversion tz += spi.transfer16(0xc0) >> 3; // Read Z1 and start Z2 conversion tz -= spi.transfer16(0x00) >> 3; // Read Z2 - T_CS_H; - spi_end_touch(); return (uint16_t)tz; @@ -86,7 +76,7 @@ uint16_t TFT_eSPI::getTouchRawZ(void){ ** Function name: validTouch ** Description: read validated position. Return false if not pressed. ***************************************************************************************/ -#define _RAWERR 10 // Deadband error allowed in successive position samples +#define _RAWERR 20 // Deadband error allowed in successive position samples uint8_t TFT_eSPI::validTouch(uint16_t *x, uint16_t *y, uint16_t threshold){ uint16_t x_tmp, y_tmp, x_tmp2, y_tmp2; diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 9c4fc66..36760b3 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -55,11 +55,17 @@ inline void TFT_eSPI::spi_begin(void){ #else CS_L; #endif +#ifdef ESP8266 + SPI1U = SPI1U_WRITE; +#endif } inline void TFT_eSPI::spi_end(void){ #if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) && !defined(ESP32_PARALLEL) if(!inTransaction) {if (!locked) {locked = true; CS_H; spi.endTransaction();}} + #ifdef ESP8266 + SPI1U = SPI1U_READ; + #endif #else if(!inTransaction) CS_H; #endif @@ -96,19 +102,33 @@ inline void TFT_eSPI::spi_end_read(void){ #if defined (TOUCH_CS) && defined (SPI_TOUCH_FREQUENCY) // && !defined(ESP32_PARALLEL) inline void TFT_eSPI::spi_begin_touch(void){ + CS_H; // Just in case it has been left low + #if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) if (locked) {locked = false; spi.beginTransaction(SPISettings(SPI_TOUCH_FREQUENCY, MSBFIRST, SPI_MODE0));} #else spi.setFrequency(SPI_TOUCH_FREQUENCY); #endif + + #ifdef ESP8266 + SPI1U = SPI1U_READ; + #endif + + T_CS_L; } inline void TFT_eSPI::spi_end_touch(void){ + T_CS_H; + #if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) if(!inTransaction) {if (!locked) {locked = true; spi.endTransaction();}} #else spi.setFrequency(SPI_FREQUENCY); #endif + + #ifdef ESP8266 + SPI1U = SPI1U_WRITE; + #endif } #endif @@ -325,6 +345,7 @@ void TFT_eSPI::init(uint8_t tc) #endif _booted = false; + spi_end(); } // end of: if just _booted // Toggle RST low to reset @@ -475,8 +496,6 @@ void TFT_eSPI::commandList (const uint8_t *addr) uint8_t numArgs; uint8_t ms; - spi_begin(); - numCommands = pgm_read_byte(addr++); // Number of commands to follow while (numCommands--) // For each command... @@ -497,7 +516,7 @@ void TFT_eSPI::commandList (const uint8_t *addr) delay( (ms==255 ? 500 : ms) ); } } - spi_end(); + } @@ -2671,7 +2690,6 @@ void TFT_eSPI::setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye) // Column addr set DC_C; - SPI1U = SPI1U_WRITE; SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); SPI1W0 = TFT_CASET; @@ -2733,7 +2751,6 @@ void TFT_eSPI::setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye) // Column addr set DC_C; - SPI1U = SPI1U_WRITE; SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); SPI1W0 = TFT_CASET<<8; @@ -2779,7 +2796,6 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) { //spi_begin(); // Must be called before setWimdow - SPI1U = SPI1U_WRITE; SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); // Column addr set @@ -2912,7 +2928,6 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) #if defined (ESP8266) && !defined (RPI_WRITE_STROBE) void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) { - spi_begin(); int32_t xe = xs + w - 1; int32_t ye = ys + h - 1; @@ -2930,7 +2945,6 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) // Column addr set DC_C; - SPI1U = SPI1U_WRITE; SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); SPI1W0 = TFT_CASET; @@ -2971,14 +2985,13 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) while(SPI1CMD & SPIBUSY) {} DC_D; - //spi_end(); + } #else //ESP32 void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) { - spi_begin(); int32_t xe = xs + w - 1; int32_t ye = ys + h - 1; @@ -3017,7 +3030,6 @@ ye += rowstart; DC_D; - //spi_end(); } #endif @@ -3039,7 +3051,6 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color) spi_begin(); - SPI1U = SPI1U_WRITE; // No need to send x if it has not changed (speeds things up) if (addr_col != x) { @@ -3129,7 +3140,6 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color) spi_begin(); - SPI1U = SPI1U_WRITE; SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); // No need to send x if it has not changed (speeds things up) if (addr_col != x) { @@ -3398,7 +3408,6 @@ void TFT_eSPI::pushColors(uint16_t *data, uint32_t len, bool swap) uint32_t color[8]; - SPI1U = SPI1U_WRITE; SPI1U1 = (255 << SPILMOSI) | (255 << SPILMISO); @@ -4351,14 +4360,10 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) pc += line; } } - - inTransaction = false; - spi_end(); } else // Text colour != background && textsize = 1 // so use faster drawing of characters and background using block write { - //spi_begin(); setWindow(x, y, x + width - 1, y + height - 1); #ifdef RPI_WRITE_STROBE @@ -4398,9 +4403,9 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) #endif } } - - spi_end(); } + inTransaction = false; + spi_end(); } // End of RLE font rendering #endif @@ -4616,6 +4621,7 @@ int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY, uint8 { poX +=xo; // Adjust for negative offset start character poY -= glyph_ab * textsize; + sumX += poX; } #endif switch(padding) { @@ -4668,7 +4674,7 @@ int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY, uint8 #endif //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DEBUG ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -return sumX + poX; +return sumX; } @@ -4896,8 +4902,6 @@ void writeBlock(uint16_t color, uint32_t repeat) uint16_t color16 = (color >> 8) | (color << 8); uint32_t color32 = color16 | color16 << 16; - SPI1U = SPI1U_WRITE; - SPI1W0 = color32; SPI1W1 = color32; SPI1W2 = color32; @@ -4954,8 +4958,6 @@ void writeBlock(uint16_t color, uint32_t repeat) void writeBlock(uint16_t color, uint32_t repeat) { - SPI1U = SPI1U_WRITE; - // Split out the colours uint8_t r = (color & 0xF800)>>8; uint8_t g = (color & 0x07E0)>>3; diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 93de46b..2d52ac9 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -15,7 +15,7 @@ #ifndef _TFT_eSPIH_ #define _TFT_eSPIH_ -#define TFT_ESPI_VERSION "1.4.4" +#define TFT_ESPI_VERSION "1.4.5" //#define ESP32 //Just used to test ESP32 options diff --git a/examples/Test and diagnostics/Read_User_Setup/Read_User_Setup.ino b/examples/Test and diagnostics/Read_User_Setup/Read_User_Setup.ino index fb49cf3..f13cb16 100644 --- a/examples/Test and diagnostics/Read_User_Setup/Read_User_Setup.ino +++ b/examples/Test and diagnostics/Read_User_Setup/Read_User_Setup.ino @@ -42,7 +42,7 @@ tft.getSetup(user); // Serial.printf("\n[code]\n"); -Serial.print ("TFT_eSPI ver = " + user.version +"\n"); +Serial.print ("TFT_eSPI ver = " + user.version + "\n"); Serial.printf("Processor = ESP%i\n", user.esp, HEX); Serial.printf("Frequency = %i MHz\n", ESP.getCpuFreqMHz()); #ifdef ESP8266 diff --git a/library.json b/library.json index f3f1f04..3e84942 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "1.4.4", + "version": "1.4.5", "keywords": "tft, ePaper, display, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789", "description": "A TFT and ePaper SPI graphics library for ESP8266 and ESP32", "repository": diff --git a/library.properties b/library.properties index d65fa12..43ac980 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=1.4.4 +version=1.4.5 author=Bodmer maintainer=Bodmer sentence=A fast TFT graphics library for ESP8266 and ESP32 processors for the Arduino IDE