@@ -55,11 +55,17 @@ inline void TFT_eSPI::spi_begin(void){
5555#else
5656 CS_L;
5757#endif
58+ #ifdef ESP8266
59+ SPI1U = SPI1U_WRITE;
60+ #endif
5861}
5962
6063inline void TFT_eSPI::spi_end (void ){
6164#if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) && !defined(ESP32_PARALLEL)
6265 if (!inTransaction) {if (!locked) {locked = true ; CS_H; spi.endTransaction ();}}
66+ #ifdef ESP8266
67+ SPI1U = SPI1U_READ;
68+ #endif
6369#else
6470 if (!inTransaction) CS_H;
6571#endif
@@ -96,19 +102,33 @@ inline void TFT_eSPI::spi_end_read(void){
96102#if defined (TOUCH_CS) && defined (SPI_TOUCH_FREQUENCY) // && !defined(ESP32_PARALLEL)
97103
98104 inline void TFT_eSPI::spi_begin_touch (void ){
105+ CS_H; // Just in case it has been left low
106+
99107 #if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS)
100108 if (locked) {locked = false ; spi.beginTransaction (SPISettings (SPI_TOUCH_FREQUENCY, MSBFIRST, SPI_MODE0));}
101109 #else
102110 spi.setFrequency (SPI_TOUCH_FREQUENCY);
103111 #endif
112+
113+ #ifdef ESP8266
114+ SPI1U = SPI1U_READ;
115+ #endif
116+
117+ T_CS_L;
104118 }
105119
106120 inline void TFT_eSPI::spi_end_touch (void ){
121+ T_CS_H;
122+
107123 #if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS)
108124 if (!inTransaction) {if (!locked) {locked = true ; spi.endTransaction ();}}
109125 #else
110126 spi.setFrequency (SPI_FREQUENCY);
111127 #endif
128+
129+ #ifdef ESP8266
130+ SPI1U = SPI1U_WRITE;
131+ #endif
112132 }
113133
114134#endif
@@ -325,6 +345,7 @@ void TFT_eSPI::init(uint8_t tc)
325345#endif
326346
327347 _booted = false ;
348+ spi_end ();
328349 } // end of: if just _booted
329350
330351 // Toggle RST low to reset
@@ -475,8 +496,6 @@ void TFT_eSPI::commandList (const uint8_t *addr)
475496 uint8_t numArgs;
476497 uint8_t ms;
477498
478- spi_begin ();
479-
480499 numCommands = pgm_read_byte (addr++); // Number of commands to follow
481500
482501 while (numCommands--) // For each command...
@@ -497,7 +516,7 @@ void TFT_eSPI::commandList (const uint8_t *addr)
497516 delay ( (ms==255 ? 500 : ms) );
498517 }
499518 }
500- spi_end ();
519+
501520}
502521
503522
@@ -2671,7 +2690,6 @@ void TFT_eSPI::setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye)
26712690 // Column addr set
26722691 DC_C;
26732692
2674- SPI1U = SPI1U_WRITE;
26752693 SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO);
26762694
26772695 SPI1W0 = TFT_CASET;
@@ -2733,7 +2751,6 @@ void TFT_eSPI::setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye)
27332751 // Column addr set
27342752 DC_C;
27352753
2736- SPI1U = SPI1U_WRITE;
27372754 SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO);
27382755
27392756 SPI1W0 = TFT_CASET<<8 ;
@@ -2779,7 +2796,6 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
27792796{
27802797 // spi_begin(); // Must be called before setWimdow
27812798
2782- SPI1U = SPI1U_WRITE;
27832799 SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO);
27842800
27852801 // Column addr set
@@ -2912,7 +2928,6 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
29122928#if defined (ESP8266) && !defined (RPI_WRITE_STROBE)
29132929void TFT_eSPI::readAddrWindow (int32_t xs, int32_t ys, int32_t w, int32_t h)
29142930{
2915- spi_begin ();
29162931
29172932 int32_t xe = xs + w - 1 ;
29182933 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)
29302945 // Column addr set
29312946 DC_C;
29322947
2933- SPI1U = SPI1U_WRITE;
29342948 SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO);
29352949
29362950 SPI1W0 = TFT_CASET;
@@ -2971,14 +2985,13 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h)
29712985 while (SPI1CMD & SPIBUSY) {}
29722986
29732987 DC_D;
2974- // spi_end();
2988+
29752989}
29762990
29772991#else // ESP32
29782992
29792993void TFT_eSPI::readAddrWindow (int32_t xs, int32_t ys, int32_t w, int32_t h)
29802994{
2981- spi_begin ();
29822995
29832996 int32_t xe = xs + w - 1 ;
29842997 int32_t ye = ys + h - 1 ;
@@ -3017,7 +3030,6 @@ ye += rowstart;
30173030
30183031 DC_D;
30193032
3020- // spi_end();
30213033}
30223034
30233035#endif
@@ -3039,7 +3051,6 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color)
30393051
30403052 spi_begin ();
30413053
3042- SPI1U = SPI1U_WRITE;
30433054 // No need to send x if it has not changed (speeds things up)
30443055 if (addr_col != x) {
30453056
@@ -3129,7 +3140,6 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color)
31293140
31303141 spi_begin ();
31313142
3132- SPI1U = SPI1U_WRITE;
31333143 SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO);
31343144 // No need to send x if it has not changed (speeds things up)
31353145 if (addr_col != x) {
@@ -3398,7 +3408,6 @@ void TFT_eSPI::pushColors(uint16_t *data, uint32_t len, bool swap)
33983408
33993409 uint32_t color[8 ];
34003410
3401- SPI1U = SPI1U_WRITE;
34023411 SPI1U1 = (255 << SPILMOSI) | (255 << SPILMISO);
34033412
34043413
@@ -4351,14 +4360,10 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font)
43514360 pc += line;
43524361 }
43534362 }
4354-
4355- inTransaction = false ;
4356- spi_end ();
43574363 }
43584364 else // Text colour != background && textsize = 1
43594365 // so use faster drawing of characters and background using block write
43604366 {
4361- // spi_begin();
43624367 setWindow (x, y, x + width - 1 , y + height - 1 );
43634368
43644369#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)
43984403#endif
43994404 }
44004405 }
4401-
4402- spi_end ();
44034406 }
4407+ inTransaction = false ;
4408+ spi_end ();
44044409 }
44054410 // End of RLE font rendering
44064411#endif
@@ -4616,6 +4621,7 @@ int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY, uint8
46164621 {
46174622 poX +=xo; // Adjust for negative offset start character
46184623 poY -= glyph_ab * textsize;
4624+ sumX += poX;
46194625 }
46204626#endif
46214627 switch (padding) {
@@ -4668,7 +4674,7 @@ int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY, uint8
46684674#endif
46694675// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DEBUG ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46704676
4671- return sumX + poX ;
4677+ return sumX;
46724678}
46734679
46744680
@@ -4896,8 +4902,6 @@ void writeBlock(uint16_t color, uint32_t repeat)
48964902 uint16_t color16 = (color >> 8 ) | (color << 8 );
48974903 uint32_t color32 = color16 | color16 << 16 ;
48984904
4899- SPI1U = SPI1U_WRITE;
4900-
49014905 SPI1W0 = color32;
49024906 SPI1W1 = color32;
49034907 SPI1W2 = color32;
@@ -4954,8 +4958,6 @@ void writeBlock(uint16_t color, uint32_t repeat)
49544958void writeBlock (uint16_t color, uint32_t repeat)
49554959{
49564960
4957- SPI1U = SPI1U_WRITE;
4958-
49594961 // Split out the colours
49604962 uint8_t r = (color & 0xF800 )>>8 ;
49614963 uint8_t g = (color & 0x07E0 )>>3 ;
0 commit comments