From d3d877c8e21bade4488f0ab0f4edf81d526d8ad2 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Mon, 27 Mar 2017 02:15:30 +0100 Subject: [PATCH] Add RPi display support for write strobe mod --- TFT_Drivers/RPI_ILI9486_Defines.h | 4 + TFT_Drivers/RPI_ILI9486_Init.h | 2 +- TFT_eSPI.cpp | 317 +++++++++++++++--- TFT_eSPI.h | 7 +- User_Setup.h | 11 +- User_Setup_Select.h | 2 + ...{Setup5_ILI9486.h => Setup5_RPi_ILI9486.h} | 22 +- User_Setups/Setup6_RPi_Wr_ILI9486.h | 162 +++++++++ library.json | 2 +- library.properties | 2 +- 10 files changed, 476 insertions(+), 55 deletions(-) rename User_Setups/{Setup5_ILI9486.h => Setup5_RPi_ILI9486.h} (92%) create mode 100644 User_Setups/Setup6_RPi_Wr_ILI9486.h diff --git a/TFT_Drivers/RPI_ILI9486_Defines.h b/TFT_Drivers/RPI_ILI9486_Defines.h index 70bd26c..5ba1007 100644 --- a/TFT_Drivers/RPI_ILI9486_Defines.h +++ b/TFT_Drivers/RPI_ILI9486_Defines.h @@ -3,6 +3,10 @@ #define TFT_WIDTH 320 #define TFT_HEIGHT 480 +// For Raspberry Pi ILI9486 only with a modified board to add a write strobe: +#ifdef TFT_WR + #define RPI_WRITE_STROBE +#endif // Color definitions for backwards compatibility with old sketches // use colour definitions like TFT_BLACK to make sketches more portable diff --git a/TFT_Drivers/RPI_ILI9486_Init.h b/TFT_Drivers/RPI_ILI9486_Init.h index f7ce458..db6bd80 100644 --- a/TFT_Drivers/RPI_ILI9486_Init.h +++ b/TFT_Drivers/RPI_ILI9486_Init.h @@ -63,7 +63,7 @@ writecommand(0x20); // display inversion OFF writecommand(0x36); - writedata(0x0A); + writedata(0x48); writecommand(0x29); // display on delay(150); diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 80eaa4a..858b375 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -74,6 +74,10 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h) pinMode(TFT_CS, OUTPUT); #endif +#ifdef TFT_WR + digitalWrite(TFT_WR, HIGH); // Chip select high (inactive) + pinMode(TFT_WR, OUTPUT); +#endif digitalWrite(TFT_DC, HIGH); // Data/Command high = data mode pinMode(TFT_DC, OUTPUT); @@ -150,6 +154,10 @@ void TFT_eSPI::init(void) dcport = portOutputRegister(digitalPinToPort(TFT_DC)); dcpinmask = (uint32_t) digitalPinToBitMask(TFT_DC); +#ifdef TFT_WR + wrpinmask = (uint32_t) digitalPinToBitMask(TFT_WR); +#endif + SPI.begin(); // This will set MISO to input #ifndef SUPPORT_TRANSACTIONS @@ -1462,7 +1470,7 @@ void TFT_eSPI::setWindow(int16_t x0, int16_t y0, int16_t x1, int16_t y1) ***************************************************************************************/ // Chip select stays low, use setWindow() from sketches -#if defined (ESP8266) && !defined (RPI_ILI9486_DRIVER) +#if defined (ESP8266) && !defined (RPI_WRITE_STROBE) && !defined (RPI_ILI9486_DRIVER) inline void TFT_eSPI::setAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye) { spi_begin(); @@ -1543,7 +1551,7 @@ inline void TFT_eSPI::setAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t spi_end(); } -#elif defined (ESP8266) && defined (RPI_ILI9486_DRIVER) // This is for the RPi display that needs 16 bits +#elif defined (ESP8266) && !defined (RPI_WRITE_STROBE) && defined (RPI_ILI9486_DRIVER) // This is for the RPi display that needs 16 bits inline void TFT_eSPI::setAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye) { @@ -1607,12 +1615,97 @@ inline void TFT_eSPI::setAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t addr_col = 0xFFFF; addr_row = 0xFFFF; -#if defined (ST7735_DRIVER) && (defined (ST7735_GREENTAB) || defined (ST7735_GREENTAB2) || defined (ST7735_GREENTAB3)) - x0+=colstart; - x1+=colstart; - y0+=rowstart; - y1+=rowstart; -#endif + CS_L; + uint32_t mask = ~((SPIMMOSI << SPILMOSI) | (SPIMMISO << SPILMISO)); + mask = SPI1U1 & mask; + SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + + // Column addr set + DC_C; + + //SPI.write16(TFT_CASET); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = TFT_CASET<<(CMD_BITS + 1 - 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + DC_D; + + //SPI.write16(x >> 8); // Not tested on ESP32 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = x0 >> 0; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(x); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = x0 << 8; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(x >> 8); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = x1 >> 0; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(x); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = x1 << 8; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + + // Row addr set + DC_C; + + //SPI.write16(TFT_PASET); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = TFT_PASET<<(CMD_BITS + 1 - 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + DC_D; + + //SPI.write16(y >> 8); // Not tested on ESP32 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = y0 >> 0; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(y); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = y0 << 8; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(y >> 8); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = y1 >> 0; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(y); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = y1 << 8; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + + // write to RAM + DC_C; + + SPI1W0 = TFT_RAMWR<<(CMD_BITS + 1 - 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + + DC_D; + + spi_end(); +} +/* +inline void TFT_eSPI::setAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) +{ + spi_begin(); + + addr_col = 0xFFFF; + addr_row = 0xFFFF; // Column addr set DC_C; @@ -1650,7 +1743,7 @@ inline void TFT_eSPI::setAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t spi_end(); } - +*/ #else inline void TFT_eSPI::setAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) @@ -1708,7 +1801,7 @@ inline void TFT_eSPI::setAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t ** Description: define an area to read a stream of pixels ***************************************************************************************/ // Chip select stays low -#ifdef ESP8266 +#if defined (ESP8266) && !defined (RPI_WRITE_STROBE) void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye) { //spi_begin(); @@ -1825,7 +1918,7 @@ void TFT_eSPI::readAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) ** Function name: drawPixel ** Description: push a single pixel at an arbitrary position ***************************************************************************************/ -#if defined (ESP8266) +#if defined (ESP8266) && !defined (RPI_WRITE_STROBE) void TFT_eSPI::drawPixel(uint32_t x, uint32_t y, uint32_t color) { // Faster range checking, possible because x and y are unsigned @@ -1929,51 +2022,100 @@ void TFT_eSPI::drawPixel(uint32_t x, uint32_t y, uint32_t color) spi_begin(); CS_L; - + uint32_t mask = ~((SPIMMOSI << SPILMOSI) | (SPIMMISO << SPILMISO)); + mask = SPI1U1 & mask; + SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); // No need to send x if it has not changed (speeds things up) if (addr_col != x) { - DC_C; - SPI.write16(TFT_CASET<<8); - + //SPI.write16(TFT_CASET); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = TFT_CASET<<(CMD_BITS + 1 - 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} DC_D; - SPI.write16(x >> 8); // Not tested on ESP32 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - SPI.write16(x); - - SPI.write16(x >> 8); - SPI.write16(x); - - + //SPI.write16(x >> 8); // Not tested on ESP32 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = x >> 0; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(x); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = x << 8; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(x >> 8); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = x >> 0; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(x); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = x << 8; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + addr_col = x; } // No need to send y if it has not changed (speeds things up) if (addr_row != y) { - DC_C; - SPI.write16(TFT_PASET<<8); - + //SPI.write16(TFT_PASET); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = TFT_PASET<<(CMD_BITS + 1 - 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} DC_D; - SPI.write16(y >> 8); // Not tested on ESP32 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - SPI.write16(y); - - SPI.write16(y >> 8); - SPI.write16(y); - + //SPI.write16(y >> 8); // Not tested on ESP32 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = y >> 0; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(y); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = y << 8; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(y >> 8); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = y >> 0; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + //DC_D; // Small delay + //SPI.write16(y); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = y << 8; + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + addr_row = y; } DC_C; - SPI.write16(TFT_RAMWR<<8); + //SPI.write16(TFT_RAMWR); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = TFT_RAMWR<<(CMD_BITS + 1 - 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} DC_D; - SPI.write16((color >> 8) | (color << 8)); + //SPI.write16((color));// >> 8) | (color << 8)); + //SPI1U1 = mask | (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); + SPI1W0 = (color >> 8) | (color << 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} CS_H; @@ -2074,8 +2216,14 @@ void TFT_eSPI::pushColor(uint16_t color, uint16_t len) CS_L; uint8_t colorBin[] = { (uint8_t) (color >> 8), (uint8_t) color }; + +#ifdef RPI_WRITE_STROBE + if(len) SPI.writePattern(&colorBin[0], 2, 1); len--; + while(len--) {WR_L; WR_H;} +#else while(len>32) { SPI.writePattern(&colorBin[0], 2, 32); len-=32;} SPI.writePattern(&colorBin[0], 2, len); +#endif CS_H; @@ -2118,10 +2266,14 @@ void TFT_eSPI::pushColors(uint8_t *data, uint32_t len) CS_L; - while ( len >=64 ) {SPI.writePattern(data, 64, 1); data += 64; len -= 64; } - if (len) SPI.writePattern(data, len, 1); +#if defined (RPI_WRITE_STROBE) + while ( len ) {SPI.writePattern(data, 2, 1); data += 2; len -= 2; } +#else + while ( len >=64 ) {SPI.writePattern(data, 64, 1); data += 64; len -= 64; } + if (len) SPI.writePattern(data, len, 1); +#endif - CS_H; + CS_H; spi_end(); } @@ -2134,10 +2286,11 @@ void TFT_eSPI::pushColors(uint8_t *data, uint32_t len) // Bresenham's algorithm - thx wikipedia - speed enhanced by Bodmer to use // an eficient FastH/V Line draw routine for line segments of 2 pixels or more -#ifdef ESP32 +#if defined (ESP32) || defined (RPI_WRITE_STROBE) void TFT_eSPI::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color) { + boolean steep = abs(y1 - y0) > abs(x1 - x0); if (steep) { swap(x0, y0); @@ -2151,7 +2304,6 @@ void TFT_eSPI::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t int32_t dx = x1 - x0, dy = abs(y1 - y0);; - int32_t err = dx >> 1, ystep = -1, xs = x0, dlen = 0; if (y0 < y1) ystep = 1; @@ -2281,7 +2433,7 @@ void TFT_eSPI::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t if ((y0 < 0) || (y0 >= _height)) break; err += dx; while(SPI1CMD & SPIBUSY) {} - setAddrWindow(x0+1, y0, _width, y0); + setAddrWindow(x0+1, y0, _width, y0); SPI1U1 = mask; } } @@ -2298,6 +2450,7 @@ void TFT_eSPI::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t ** Function name: drawFastVLine ** Description: draw a vertical line ***************************************************************************************/ +#if defined (ESP8266) && !defined (RPI_WRITE_STROBE) void TFT_eSPI::drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color) { // Rudimentary clipping @@ -2315,13 +2468,38 @@ void TFT_eSPI::drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color) spi_end(); } +#else +void TFT_eSPI::drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color) +{ + // Rudimentary clipping + if ((x >= _width) || (y >= _height) || (h < 1)) return; + if ((y + h - 1) >= _height) h = _height - y; -//Done! Total = 1028742 + spi_begin(); + + setAddrWindow(x, y, x, y + h - 1); + +#ifdef RPI_WRITE_STROBE + SPI1W0 = (color >> 8) | (color << 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + h--; + while(h--) {WR_L; WR_H;} +#else + while(h--) SPI.write16(color); +#endif + + CS_H; + + spi_end(); +} +#endif /*************************************************************************************** ** Function name: drawFastHLine ** Description: draw a horizontal line ***************************************************************************************/ +#if defined (ESP8266) && !defined (RPI_WRITE_STROBE) void TFT_eSPI::drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color) { // Rudimentary clipping @@ -2339,12 +2517,37 @@ void TFT_eSPI::drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color) spi_end(); } +#else +void TFT_eSPI::drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color) +{ + // Rudimentary clipping + if ((x >= _width) || (y >= _height) || (w < 1)) return; + if ((x + w - 1) >= _width) w = _width - x; + spi_begin(); + setAddrWindow(x, y, x + w - 1, y); + +#ifdef RPI_WRITE_STROBE + SPI1W0 = (color >> 8) | (color << 8); + SPI1CMD |= SPIBUSY; + while(SPI1CMD & SPIBUSY) {} + w--; + while(w--) {WR_L; WR_H;} +#else + while(w--) SPI.write16(color); +#endif + + CS_H; + + spi_end(); +} +#endif /*************************************************************************************** ** Function name: fillRect ** Description: draw a filled rectangle ***************************************************************************************/ +#if defined (ESP8266) && !defined (RPI_WRITE_STROBE) void TFT_eSPI::fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) { // rudimentary clipping (drawChar w/big text requires this) @@ -2363,7 +2566,31 @@ void TFT_eSPI::fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t col spi_end(); } +#else +void TFT_eSPI::fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) +{ + // rudimentary clipping (drawChar w/big text requires this) + if ((x > _width) || (y > _height) || (w < 1) || (h < 1)) return; + if ((x + w - 1) > _width) w = _width - x; + if ((y + h - 1) > _height) h = _height - y; + spi_begin(); + setAddrWindow(x, y, x + w - 1, y + h - 1); + + uint32_t n = (uint32_t)w * (uint32_t)h; + +#ifdef RPI_WRITE_STROBE + if(n) {SPI.write16(color); n--;} + while(n--) {WR_L; WR_H;} +#else + while(n--) SPI.write16(color); +#endif + + CS_H; + + spi_end(); +} +#endif /*************************************************************************************** ** Function name: color565 @@ -2753,13 +2980,23 @@ int16_t TFT_eSPI::drawChar(unsigned int uniCode, int x, int y, int font) if (line & 0x80) { line &= 0x7F; line++; w -= line; +#ifdef RPI_WRITE_STROBE + SPI.writePattern(&textcolorBin[0], 2, 1); line--; + while(line--) {WR_L; WR_H;} +#else while(line>32) { SPI.writePattern(&textcolorBin[0], 2, 32); line-=32;} SPI.writePattern(&textcolorBin[0], 2, line); +#endif } else { line++; w -= line; +#ifdef RPI_WRITE_STROBE + SPI.writePattern(&textbgcolorBin[0], 2, 1); line--; + while(line--) {WR_L; WR_H;} +#else while(line>32) { SPI.writePattern(&textbgcolorBin[0], 2, 32); line-=32;} SPI.writePattern(&textbgcolorBin[0], 2, line); +#endif } } CS_H; diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 05b3cf5..58b793e 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -92,6 +92,11 @@ #endif #endif +#ifdef TFT_WR + #define WR_L GPOC=wrpinmask + #define WR_H GPOS=wrpinmask +#endif + // We can include all the free fonts and they will only be built into // the sketch if they are used @@ -405,7 +410,7 @@ inline void spi_end() __attribute__((always_inline)); volatile uint32_t *dcport, *csport;//, *mosiport, *clkport, *rsport; - uint32_t cspinmask, dcpinmask;//, mosipinmask, clkpinmask; + uint32_t cspinmask, dcpinmask, wrpinmask;//, mosipinmask, clkpinmask; //uint8_t fifoBuffer[64]; // SPI graphics pipeline buffer - not used yet diff --git a/User_Setup.h b/User_Setup.h index 47c9549..12e516c 100644 --- a/User_Setup.h +++ b/User_Setup.h @@ -81,6 +81,8 @@ #define TFT_RST D4 // Reset pin (could connect to NodeMCU RST, see next line) //#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V +//#define TFT_WR D2 // Write strobe for modified Raspberry Pi TFT only + // ESP32 Dev board (planned, not supported yet) //#define TFT_CS 5 // Chip select control pin //#define TFT_DC 2 // Data Command control pin @@ -123,13 +125,10 @@ // ################################################################################## // -// Section 4. Define the character to be used to detemine the text bounding box for datum changes +// Section 4. Not used section // // ################################################################################## -#define FF_HEIGHT '/' // '/' character used to set free font height above the baseline -#define FF_BOTTOM 'y' // 'y' character used to set free font height below baseline - // ################################################################################## // @@ -145,8 +144,8 @@ // #define SPI_FREQUENCY 1000000 // #define SPI_FREQUENCY 5000000 // #define SPI_FREQUENCY 10000000 - #define SPI_FREQUENCY 20000000 -// #define SPI_FREQUENCY 27000000 // Actually sets it to 26.67MHz = 80/3 +// #define SPI_FREQUENCY 20000000 + #define SPI_FREQUENCY 27000000 // Actually sets it to 26.67MHz = 80/3 // #define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS // #define SPI_FREQUENCY 80000000 diff --git a/User_Setup_Select.h b/User_Setup_Select.h index af781a2..4f5bbc9 100644 --- a/User_Setup_Select.h +++ b/User_Setup_Select.h @@ -22,6 +22,8 @@ //#include // Setup file configured for my ST7735 //#include // Setup file configured for my ILI9163 //#include // Setup file configured for my S6D02A1 +//#include // Setup file configured for my stock RPi TFT +//#include // Setup file configured for my modified RPi TFT //#include // Setup file template for copying/editting diff --git a/User_Setups/Setup5_ILI9486.h b/User_Setups/Setup5_RPi_ILI9486.h similarity index 92% rename from User_Setups/Setup5_ILI9486.h rename to User_Setups/Setup5_RPi_ILI9486.h index 8a6ef81..b88b2c4 100644 --- a/User_Setups/Setup5_ILI9486.h +++ b/User_Setups/Setup5_RPi_ILI9486.h @@ -1,9 +1,9 @@ // USER DEFINED SETTINGS -// -// The User_Setup header that will be called up is defined in User_Setup_Select.h -// // Set driver type, fonts to be loaded, pins used and SPI control method etc -// +// +// See the User_Setup_Select.h file if you wish to be able to define multiple +// setups and then easily select which setup file is used by the compiler. +// // If this file is editted correctly then all the library example sketches should // run without the need to make any more changes for a particular hardware setup! @@ -14,8 +14,11 @@ // ################################################################################## // Only define one driver, the other ones must be commented out -#define RPI_ILI9486_DRIVER +//#define ILI9341_DRIVER //#define ST7735_DRIVER +//#define ILI9163_DRIVER +//#define S6D02A1_DRIVER +#define RPI_ILI9486_DRIVER // 20MHz maximum SPI // For ST7735 ONLY, define the type of display, originally this was based on the // colour of the tab on the screen protector film but this is not always true, so try @@ -27,9 +30,15 @@ //#define ST7735_INITB //#define ST7735_GREENTAB //#define ST7735_GREENTAB2 +//#define ST7735_GREENTAB3 //#define ST7735_REDTAB //#define ST7735_BLACKTAB +// For ST7735 ONLY, define the pixel width and height in portrait orientation +//#define TFT_WIDTH 128 +//#define TFT_HEIGHT 160 +//#define TFT_HEIGHT 128 + // ################################################################################## // // Section 1. Define the pins that are used to interface with the display here @@ -72,6 +81,8 @@ #define TFT_RST D4 // Reset pin (could connect to NodeMCU RST, see next line) //#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V +//#define TFT_WR D2 // Write strobe for modified Raspberry Pi TFT only + // ESP32 Dev board (planned, not supported yet) //#define TFT_CS 5 // Chip select control pin //#define TFT_DC 2 // Data Command control pin @@ -131,6 +142,7 @@ // Define the SPI clock frequency // With an ILI9341 display 40MHz works OK, 80MHz sometimes fails // With a ST7735 display more than 27MHz may not work (spurious pixels and lines) +// With an ILI9163 display TBD MHz works OK, // #define SPI_FREQUENCY 1000000 // #define SPI_FREQUENCY 5000000 diff --git a/User_Setups/Setup6_RPi_Wr_ILI9486.h b/User_Setups/Setup6_RPi_Wr_ILI9486.h new file mode 100644 index 0000000..25c6d54 --- /dev/null +++ b/User_Setups/Setup6_RPi_Wr_ILI9486.h @@ -0,0 +1,162 @@ +// USER DEFINED SETTINGS +// Set driver type, fonts to be loaded, pins used and SPI control method etc +// +// See the User_Setup_Select.h file if you wish to be able to define multiple +// setups and then easily select which setup file is used by the compiler. +// +// If this file is editted correctly then all the library example sketches should +// run without the need to make any more changes for a particular hardware setup! + +// ################################################################################## +// +// Section 0. Call up the right driver file and any options for it +// +// ################################################################################## + +// Only define one driver, the other ones must be commented out +//#define ILI9341_DRIVER +//#define ST7735_DRIVER +//#define ILI9163_DRIVER +//#define S6D02A1_DRIVER +#define RPI_ILI9486_DRIVER // 20MHz maximum SPI + +// For ST7735 ONLY, define the type of display, originally this was based on the +// colour of the tab on the screen protector film but this is not always true, so try +// out the different options below if the screen does not display graphics correctly, +// e.g. colours wrong, mirror images, or tray pixels at the edges. +// Comment out ALL BUT ONE of these options for a ST7735 display driver, save this +// this User_Setup file, then rebuild and upload the sketch to the board again: + +//#define ST7735_INITB +//#define ST7735_GREENTAB +//#define ST7735_GREENTAB2 +//#define ST7735_GREENTAB3 +//#define ST7735_REDTAB +//#define ST7735_BLACKTAB + +// For ST7735 ONLY, define the pixel width and height in portrait orientation +//#define TFT_WIDTH 128 +//#define TFT_HEIGHT 160 +//#define TFT_HEIGHT 128 + +// ################################################################################## +// +// Section 1. Define the pins that are used to interface with the display here +// +// ################################################################################## + +// We must use hardware SPI, a minimum of 3 GPIO pins is needed. +// Typical setup for NodeMCU ESP-12 is : +// +// Display SDO/MISO to NodeMCU pin D6 (or leave disconnected if not reading TFT) +// Display LED to NodeMCU pin VIN (or 5V, see below) +// Display SCK to NodeMCU pin D5 +// Display SDI/MOSI to NodeMCU pin D7 +// Display DC (or AO)to NodeMCU pin D3 +// Display RESET to NodeMCU pin D4 (or RST, see below) +// Display CS to NodeMCU pin D8 (or GND, see below) +// Display GND to NodeMCU pin GND (0V) +// Display VCC to NodeMCU 5V or 3.3V +// +// The TFT RESET pin can be connected to the NodeMCU RST pin or 3.3V to free up a control pin +// +// With some displays such as the ILI9341 the TFT CS pin can be connected to GND if no more +// SPI deivces (e.g. an SD Card) are connected, in this case comment out the #define TFT_CS +// line below so it is NOT defined. Other displays such at the ST7735 require the TFT CS pin +// to be toggled during setup, so in these cases the TFT_CS line must be defined and connected. +// +// The NodeMCU D0 pin can be used for RST +// +// See Section 2. below if DC or CS is connected to D0 +// +// Note: only some versions of the NodeMCU provide the USB 5V on the VIN pin +// If 5V is not available at a pin you can use 3.3V but backlight brightness +// will be lower. + +// ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR SETUP ###### + +// ModeMCU +#define TFT_CS D8 // Chip select control pin D8 +#define TFT_DC D3 // Data Command control pin +#define TFT_RST D4 // Reset pin (could connect to NodeMCU RST, see next line) +//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V + +#define TFT_WR D2 // Write strobe for modified Raspberry Pi TFT only + +// ESP32 Dev board (planned, not supported yet) +//#define TFT_CS 5 // Chip select control pin +//#define TFT_DC 2 // Data Command control pin +//#define TFT_RST 4 // Reset pin (could connect to Arduino RESET pin) +//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST + +// ################################################################################## +// +// Section 2. Define the way the DC and/or CS lines are driven +// +// ################################################################################## + +// Normally the library uses direct register access for the DC and CS lines for speed +// If D0 (GPIO16) is used for CS or DC then a different slower method must be used +// Uncomment one line if D0 is used for DC or CS +// DC on D0 = 6% performance penalty at 40MHz SPI running graphics test +// CS on D0 = 2% performance penalty at 40MHz SPI running graphics test + +// #define D0_USED_FOR_DC +// #define D0_USED_FOR_CS + +// ################################################################################## +// +// Section 3. Define the fonts that are to be used here +// +// ################################################################################## + +// Comment out the #defines below with // to stop that font being loaded +// The ESP8366 had plenty of memory so commenting out fonts is not normally necessary +// If all fonts are loaded the extra FLASH space required is about 17Kbytes... +// To save FLASH space only enable the fonts you need! + +#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH +#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters +#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters +#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm +#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:. +#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-. +#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts + +// ################################################################################## +// +// Section 4. Define the character to be used to detemine the text bounding box for datum changes +// +// ################################################################################## + +#define FF_HEIGHT '/' // '/' character used to set free font height above the baseline +#define FF_BOTTOM 'y' // 'y' character used to set free font height below baseline + + +// ################################################################################## +// +// Section 5. Other options +// +// ################################################################################## + +// Define the SPI clock frequency +// With an ILI9341 display 40MHz works OK, 80MHz sometimes fails +// With a ST7735 display more than 27MHz may not work (spurious pixels and lines) +// With an ILI9163 display TBD MHz works OK, + +// #define SPI_FREQUENCY 1000000 +// #define SPI_FREQUENCY 5000000 +// #define SPI_FREQUENCY 10000000 +// #define SPI_FREQUENCY 20000000 + #define SPI_FREQUENCY 27000000 // Actually sets it to 26.67MHz = 80/3 +// #define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS +// #define SPI_FREQUENCY 80000000 + + +// Comment out the following #define if "SPI Transactions" do not need to be +// supported. Tranaction support is required if other SPI devices are connected. +// When commented out the code size will be smaller and sketches will +// run slightly faster, so leave it commented out unless you need it! +// Transaction support is needed to work with SD library but not needed with TFT_SdFat + +// #define SUPPORT_TRANSACTIONS diff --git a/library.json b/library.json index 10c9f8a..256a00f 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "0.14.0", + "version": "0.16.0", "keywords": "ILI9341, ST7735, ESP8266, TFT", "description": "A TFT SPI graphics library for ESP8266", "repository": diff --git a/library.properties b/library.properties index 5d77ef8..1409a39 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=0.14 +version=0.16 author=Bodmer maintainer=Bodmer sentence=A fast TFT library for ESP8266 processors and the Arduino IDE