SPI based library for the ST7735 LCD controller.
Dependents: RayCastingEngine RETRO_LCD_PerformanceTest RETRO_loop_test RETRO_RickGame ... more
Revision 8:12f16befa7e1, committed 2014-10-25
- Comitter:
- taylorza
- Date:
- Sat Oct 25 04:10:47 2014 +0000
- Parent:
- 7:f39c980a589c
- Child:
- 9:7ecd74dcb8ef
- Commit message:
- Added support for RGB and BGR panels
Changed in this revision
LCD_ST7735.cpp | Show annotated file Show diff for this revision Revisions of this file |
LCD_ST7735.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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[])
--- a/LCD_ST7735.h Sun Oct 05 23:57:36 2014 +0000 +++ b/LCD_ST7735.h Sat Oct 25 04:10:47 2014 +0000 @@ -23,6 +23,16 @@ Rotate270 }; + /** Type of color filter of the panel */ + enum PanelColorFilter + { + /** RGB color filter panel */ + RGB = 0, + + /** BGR color filter panel */ + BGR = 8, + }; + public: /**Creates an instance of the LCD_ST7735 driver * @param backlightPin pin used to control the backlight @@ -40,7 +50,8 @@ PinName mosiPin, PinName misoPin, PinName clkPin, - PinName csPin + PinName csPin, + PanelColorFilter colorFilter = BGR ); /** Set the orientation of the display @@ -187,7 +198,12 @@ * @param pString ASCIIZ string to draw to the display. * @note The font is currently limited to an 8x8 font. See the font_IBM.h file for an example font. */ - void drawString(const uint8_t *pFont, int x, int y, const char *pString); + void drawString(const uint8_t *pFont, int x, int y, const char *pString); + + /** Select the device on the SPI bus. + selectDevice needs to be called before accessing the screen if there are multiple devices on the SPI bus. + */ + void selectDevice(); private: void setPixelFast(int x, int y, uint16_t color); @@ -219,6 +235,7 @@ int _width; int _height; Orientation _orientation; + PanelColorFilter _colorFilter; bool _flip; uint8_t _foregroundColorHigh; uint8_t _foregroundColorLow; @@ -270,7 +287,7 @@ } }; - private: + private: DigitalOut _backlight; DigitalOut _reset; DigitalOut _ds;