Add support for ST7735 128x128 display

May not cater for 128x128 ST7735 displays with different RGB and offset
configurations.
This commit is contained in:
Bodmer
2017-04-16 16:13:12 +01:00
parent a71a98a59c
commit c2dcf25cc1
8 changed files with 50 additions and 31 deletions

View File

@@ -14,6 +14,7 @@
#define INITR_BLACKTAB 0x2
#define INITR_GREENTAB2 0x3 // Use if you get random pixels on two edges of green tab display
#define INITR_GREENTAB3 0x4 // Use if you get random pixels on edge(s) of 128x128 screen
#define INITR_GREENTAB128 0x5 // Use if you only get part of 128x128 screen in rotation 0 & 1
#define INITB 0xB
@@ -23,12 +24,19 @@
#elif defined (ST7735_GREENTAB)
#define TAB_COLOUR INITR_GREENTAB
#define CGRAM_OFFSET
#elif defined (ST7735_GREENTAB2)
#define TAB_COLOUR INITR_GREENTAB2
#define CGRAM_OFFSET
#elif defined (ST7735_GREENTAB3)
#define TAB_COLOUR INITR_GREENTAB3
#define CGRAM_OFFSET
#elif defined (ST7735_GREENTAB128)
#define TAB_COLOUR INITR_GREENTAB128
#define CGRAM_OFFSET
#elif defined (ST6635_REDTAB)
#define TAB_COLOUR INITR_REDTAB

View File

@@ -169,6 +169,12 @@
colstart = 2;
rowstart = 3;
}
else if (tabcolor == INITR_GREENTAB128)
{
commandList(Rcmd2green);
colstart = 0;
rowstart = 32;
}
else if (tabcolor == INITR_REDTAB)
{
commandList(Rcmd2red);

View File

@@ -16,6 +16,10 @@
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR);
colstart = 2;
rowstart = 3;
} else if(tabcolor == INITR_GREENTAB128) {
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MH | TFT_MAD_BGR);
colstart = 0;
rowstart = 32;
} else {
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_BGR);
}
@@ -33,6 +37,10 @@
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
colstart = 3;
rowstart = 2;
} else if(tabcolor == INITR_GREENTAB128) {
writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_BGR);
colstart = 32;
rowstart = 0;
} else {
writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_BGR);
}
@@ -50,6 +58,10 @@
writedata(TFT_MAD_BGR);
colstart = 2;
rowstart = 1;
} else if(tabcolor == INITR_GREENTAB128) {
writedata(TFT_MAD_BGR);
colstart = 0;
rowstart = 0;
} else {
writedata(TFT_MAD_BGR);
}
@@ -67,6 +79,10 @@
writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR);
colstart = 1;
rowstart = 2;
} else if(tabcolor == INITR_GREENTAB128) {
writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR);
colstart = 0;
rowstart = 0;
} else {
writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_BGR);
}

View File

@@ -151,12 +151,12 @@ void TFT_eSPI::begin(void)
void TFT_eSPI::init(void)
{
#ifdef TFT_CS
csport = portOutputRegister(digitalPinToPort(TFT_CS));
//csport = portOutputRegister(digitalPinToPort(TFT_CS));
cspinmask = (uint32_t) digitalPinToBitMask(TFT_CS);
#endif
#ifdef TFT_DC
dcport = portOutputRegister(digitalPinToPort(TFT_DC));
//dcport = portOutputRegister(digitalPinToPort(TFT_DC));
dcpinmask = (uint32_t) digitalPinToBitMask(TFT_DC);
#endif
@@ -1476,7 +1476,7 @@ inline void TFT_eSPI::setAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t
addr_col = 0xFFFF;
addr_row = 0xFFFF;
#if defined (ST7735_DRIVER) && (defined (ST7735_GREENTAB) || defined (ST7735_GREENTAB2) || defined (ST7735_GREENTAB3))
#ifdef CGRAM_OFFSET
xs+=colstart;
xe+=colstart;
ys+=rowstart;
@@ -1504,21 +1504,6 @@ inline void TFT_eSPI::setAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t
SPI1CMD |= SPIBUSY;
while(SPI1CMD & SPIBUSY) {}
// This proves we can only change the byte level bit SPI register read-out order, not the actual byte order
// So we can't use this method to avoid coordinate byte order swapping!
//uint32_t x = (xs << 16) | xe;
// Swap bits in 32 bit word end for end
//x = (((x & 0xAAAAAAAA) >> 1) | ((x & 0x55555555) << 1));
//x = (((x & 0xCCCCCCCC) >> 2) | ((x & 0x33333333) << 2));
//x = (((x & 0xF0F0F0F0) >> 4) | ((x & 0x0F0F0F0F) << 4));
//x = (((x & 0xFF00FF00) >> 8) | ((x & 0x00FF00FF) << 8));
//x = (x >> 16) | (x << 16);
//SPI1W0 = x;
//SPI1C |= (SPICWBO | SPICRBO); // LSB first
//SPI1CMD |= SPIBUSY;
//while(SPI1CMD & SPIBUSY) {}
//SPI1C &= ~(SPICWBO | SPICRBO); // MSB first = default
// Row addr set
DC_C;
@@ -1690,7 +1675,7 @@ 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))
#ifdef CGRAM_OFFSET
x0+=colstart;
x1+=colstart;
y0+=rowstart;
@@ -1746,7 +1731,7 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye)
addr_col = 0xFFFF;
addr_row = 0xFFFF;
#if defined (ST7735_DRIVER) && (defined (ST7735_GREENTAB) || defined (ST7735_GREENTAB2) || defined (ST7735_GREENTAB3))
#ifdef CGRAM_OFFSET
xs+=colstart;
xe+=colstart;
ys+=rowstart;
@@ -1812,7 +1797,7 @@ void TFT_eSPI::readAddrWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
addr_col = 0xFFFF;
addr_row = 0xFFFF;
#if defined (ST7735_DRIVER) && (defined (ST7735_GREENTAB) || defined (ST7735_GREENTAB2) || defined (ST7735_GREENTAB3))
#ifdef CGRAM_OFFSET
x0+=colstart;
x1+=colstart;
y0+=rowstart;
@@ -1861,7 +1846,7 @@ void TFT_eSPI::drawPixel(uint32_t x, uint32_t y, uint32_t color)
// Faster range checking, possible because x and y are unsigned
if ((x >= _width) || (y >= _height)) return;
#if defined (ST7735_DRIVER) && (defined (ST7735_GREENTAB) || defined (ST7735_GREENTAB2) || defined (ST7735_GREENTAB3))
#ifdef CGRAM_OFFSET
x+=colstart;
y+=rowstart;
#endif
@@ -2043,7 +2028,7 @@ void TFT_eSPI::drawPixel(uint32_t x, uint32_t y, uint32_t color)
if ((x >= _width) || (y >= _height)) return;
spi_begin();
#if defined (ST7735_DRIVER) && (defined (ST7735_GREENTAB) || defined (ST7735_GREENTAB2) || defined (ST7735_GREENTAB3))
#ifdef CGRAM_OFFSET
x+=colstart;
y+=rowstart;
#endif

View File

@@ -31,6 +31,7 @@
//#define ST7735_GREENTAB
//#define ST7735_GREENTAB2
//#define ST7735_GREENTAB3
//#define ST7735_GREENTAB128 // For 128 x 128 display
//#define ST7735_REDTAB
//#define ST7735_BLACKTAB
@@ -52,7 +53,7 @@
// 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 DC (RS/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)
@@ -60,6 +61,8 @@
//
// The TFT RESET pin can be connected to the NodeMCU RST pin or 3.3V to free up a control pin
//
// The DC (Data Command) pin may be labell AO or RS (Register Select)
//
// 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
@@ -146,8 +149,8 @@
// #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 27000000 // Actually sets it to 26.67MHz = 80/3
#define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS
// #define SPI_FREQUENCY 80000000

View File

@@ -24,6 +24,7 @@
//#include <User_Setups/Setup4_S6D02A1.h> // Setup file configured for my S6D02A1
//#include <User_Setups/Setup5_RPi_ILI9486.h> // Setup file configured for my stock RPi TFT
//#include <User_Setups/Setup6_RPi_Wr_ILI9486.h> // Setup file configured for my modified RPi TFT
//#include <User_Setups/Setup7_ST7735_128x128.h> // Setup file configured for my ST7735 128x128 display
//#include <User_Setups/SetupX_Template.h> // Setup file template for copying/editting
@@ -32,7 +33,7 @@
/////////////////////////////////////////////////////////////////////////////////////
// //
// DON'T TINKER WITH ANY OF THE FOLLOWING LINES, THESE ADD THE TFT DRIVERS //
// THEY ARE HERE FOR BODMER'S CONVENIENCE! //
// AND ESP8266 PIN DEFINITONS THEY ARE HERE FOR BODMER'S CONVENIENCE! //
// //
/////////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,6 +1,6 @@
{
"name": "TFT_eSPI",
"version": "0.16.3",
"version": "0.16.4",
"keywords": "TFT, ESP8266, NodeMCU, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486",
"description": "A TFT SPI graphics library for ESP8266",
"repository":

View File

@@ -1,5 +1,5 @@
name=TFT_eSPI
version=0.16.3
version=0.16.4
author=Bodmer
maintainer=Bodmer
sentence=A fast TFT library for ESP8266 processors and the Arduino IDE