SPI based library for the ST7735 LCD controller.
Dependents: RayCastingEngine RETRO_LCD_PerformanceTest RETRO_loop_test RETRO_RickGame ... more
Diff: LCD_ST7735.cpp
- Revision:
- 8:12f16befa7e1
- Parent:
- 7:f39c980a589c
- Child:
- 9:7ecd74dcb8ef
--- a/LCD_ST7735.cpp Sun Oct 05 23:57:36 2014 +0000 +++ b/LCD_ST7735.cpp Sat Oct 25 04:10:47 2014 +0000 @@ -8,7 +8,10 @@ PinName mosiPin, PinName misoPin, PinName clkPin, - PinName csPin) : + PinName csPin, + PanelColorFilter colorFilter + ) : + _colorFilter(colorFilter), _backlight(backlightPin, 0), _reset(resetPin, 1), _ds(dsPin, 0), @@ -30,7 +33,7 @@ const static uint8_t mx = 0x40; const static uint8_t mv = 0x20; - uint8_t madctlData = 0x08; + uint8_t madctlData = _colorFilter; switch(orientation) { case Rotate0: @@ -77,7 +80,6 @@ void LCD_ST7735::clearScreen(uint16_t color) { - _spi.prepareFastSPI(); clipRect(0, 0, _width - 1, _height - 1); beginBatchCommand(CMD_RAMWR); uint8_t colorHigh = color >> 8; @@ -91,13 +93,11 @@ void LCD_ST7735::setPixel(int x, int y, uint16_t color) { - _spi.prepareFastSPI(); setPixelFast(x, y, color); } void LCD_ST7735::drawLine(int x1, int y1, int x2, int y2, uint16_t color) { - _spi.prepareFastSPI(); int dx = abs(x2 - x1); int dy = abs(y2 - y1); @@ -142,7 +142,6 @@ void LCD_ST7735::drawRect(int x1, int y1, int x2, int y2, uint16_t color) { - _spi.prepareFastSPI(); if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); @@ -154,7 +153,6 @@ void LCD_ST7735::drawCircle(int x, int y, int r, uint16_t color) { - _spi.prepareFastSPI(); int ix = r; int iy = 0; int err = 1 - r; @@ -184,7 +182,6 @@ void LCD_ST7735::drawEllipse(int x, int y, int rx, int ry, uint16_t color) { - _spi.prepareFastSPI(); int a2 = rx * rx; int b2 = ry * ry; int fa2 = 4 * a2; @@ -221,7 +218,6 @@ } void LCD_ST7735::fillRect(int x1, int y1, int x2, int y2, uint16_t fillColor) { - _spi.prepareFastSPI(); clipRect(x1, y1, x2, y2); int c = ((x2-x1) * (y2-y1)) << 1; uint8_t colorHigh = fillColor >> 8; @@ -236,7 +232,6 @@ void LCD_ST7735::fillRect(int x1, int y1, int x2, int y2, uint16_t borderColor, uint16_t fillColor) { - _spi.prepareFastSPI(); if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); @@ -255,7 +250,6 @@ void LCD_ST7735::fillCircle(int x, int y, int r, uint16_t borderColor, uint16_t fillColor) { - _spi.prepareFastSPI(); int ix = r; int iy = 0; int err = 1 - r; @@ -292,7 +286,6 @@ void LCD_ST7735::fillEllipse(int x, int y, int rx, int ry, uint16_t borderColor, uint16_t fillColor) { - _spi.prepareFastSPI(); int a2 = rx * rx; int b2 = ry * ry; int fa2 = 4 * a2; @@ -337,7 +330,6 @@ void LCD_ST7735::drawBitmap(int x, int y, const uint16_t *pbmp) { - _spi.prepareFastSPI(); int w = *pbmp++; int h = *pbmp++; @@ -353,7 +345,6 @@ void LCD_ST7735::drawBitmap(int x, int y, const uint16_t *pbmp, int srcX, int srcY, int srcWidth, int srcHeight) { - _spi.prepareFastSPI(); int w = *pbmp++; int h = *pbmp++; @@ -385,7 +376,6 @@ void LCD_ST7735::drawString(const uint8_t *pFont, int x, int y, const char *pString) { - _spi.prepareFastSPI(); char *p = (char*)pString; while(*p != 0) { @@ -394,6 +384,11 @@ } } +void LCD_ST7735::selectDevice() +{ + _spi.prepareFastSPI(); +} + void LCD_ST7735::setPixelFast(int x, int y, uint16_t color) { write(CMD_CASET, (uint8_t[]){0, x, 0, x}, 4); @@ -459,7 +454,7 @@ void LCD_ST7735::initDisplay() { - _spi.prepareFastSPI(); + selectDevice(); reset(); writeCommand(CMD_SLPOUT); @@ -478,7 +473,7 @@ write(CMD_VMCTR1, (uint8_t[]){0x0e}, 1); - write(CMD_MADCTL, (uint8_t[]){0xc8}, 1); + write(CMD_MADCTL, (uint8_t[]){0xc0 | _colorFilter}, 1); // Gama sequence write(CMD_GAMCTRP1, (uint8_t[])