Skip to content

Commit

Permalink
lcd: use writePattern for faster erases and lines.
Browse files Browse the repository at this point in the history
The ESP8266 SPI implementation has a 'writePattern' function that
writes a repeating sequence (in this case a solid colour) to the SPI
port.  This fills up the FIFO and increases the bus utilisation.

Using this for clearing the screen cuts the demo run time from 4721 ms
to 3601 ms.  Also using this for the fast lines cuts the run time to
3424 ms.

Signed-off-by: Michael Hope <mlhx@google.com>
  • Loading branch information
nzmichaelh committed May 17, 2015
1 parent a56ebc5 commit 51dddbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
48 changes: 17 additions & 31 deletions Adafruit_ST7735.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,34 +490,20 @@ void Adafruit_ST7735::pushColor(uint16_t color) {
}

void Adafruit_ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {

if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;

setAddrWindow(x,y,x+1,y+1);

setRS(true);
setCS(false);

spiwrite16(color);

setCS(true);
writedata16(color);
}


void Adafruit_ST7735::drawFastVLine(int16_t x, int16_t y, int16_t h,
uint16_t color) {

// Rudimentary clipping
if((x >= _width) || (y >= _height)) return;
if((y+h-1) >= _height) h = _height-y;
setAddrWindow(x, y, x, y+h-1);

setRS(true);
setCS(false);
while (h--) {
spiwrite16(color);
}
setCS(true);
writeColor(color, h);
}


Expand All @@ -529,12 +515,7 @@ void Adafruit_ST7735::drawFastHLine(int16_t x, int16_t y, int16_t w,
if((x+w-1) >= _width) w = _width-x;
setAddrWindow(x, y, x+w-1, y);

setRS(true);
setCS(false);
while (w--) {
spiwrite16(color);
}
setCS(true);
writeColor(color, w);
}


Expand All @@ -544,6 +525,19 @@ void Adafruit_ST7735::fillScreen(uint16_t color) {
}


void Adafruit_ST7735::writeColor(uint16_t color, uint16_t count) {
setRS(true);
setCS(false);
#if defined(ST7735_USE_HWSPI_WRITEPATTERN)
uint8_t pattern[] = { (uint8_t)(color >> 8), (uint8_t)(color >> 0) };
SPI.writePattern(pattern, sizeof(pattern), count);
#else
for (; count != 0; count--) {
spiwrite16(color);
}
#endif
setCS(true);
}

// fill a rectangle
void Adafruit_ST7735::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
Expand All @@ -555,15 +549,7 @@ void Adafruit_ST7735::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
if((y + h - 1) >= _height) h = _height - y;

setAddrWindow(x, y, x+w-1, y+h-1);

setRS(true);
setCS(false);
for(y=h; y>0; y--) {
for(x=w; x>0; x--) {
spiwrite16(color);
}
}
setCS(true);
writeColor(color, w*h);
}


Expand Down
2 changes: 2 additions & 0 deletions Adafruit_ST7735.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Adafruit_ST7735 : public Adafruit_GFX {
writecommand(uint8_t c),
writedata(uint8_t d),
writedata16(uint16_t d),
writeColor(uint16_t color, uint16_t count),
setCS(bool level),
setRS(bool level),
commandList(const uint8_t *addr),
Expand All @@ -181,6 +182,7 @@ volatile uint8_t *dataport, *clkport, *csport, *rsport;
#define ST7735_USE_GENERIC_IO
#define ST7735_USE_HWSPI_ONLY
#define ST7735_USE_HWSPI_WRITE16
#define ST7735_USE_HWSPI_WRITEPATTERN
uint8_t _cs, _rs, _rst, _sid, _sclk;
uint8_t colstart, rowstart;
#endif
Expand Down

0 comments on commit 51dddbd

Please sign in to comment.