SPI based library for the ST7735 LCD controller.
Dependents: RayCastingEngine RETRO_LCD_PerformanceTest RETRO_loop_test RETRO_RickGame ... more
Diff: LCD_ST7735.cpp
- Revision:
- 3:451148656b76
- Parent:
- 1:33ff5fad4320
- Child:
- 4:88d22437119c
--- a/LCD_ST7735.cpp Sat Sep 20 05:43:17 2014 +0000 +++ b/LCD_ST7735.cpp Sat Sep 20 19:09:16 2014 +0000 @@ -24,6 +24,52 @@ setBackgroundColor(0x0000); } +void LCD_ST7735::setOrientation(Orientation orientation, bool flip) +{ + const static uint8_t my = 0x80; + const static uint8_t mx = 0x40; + const static uint8_t mv = 0x20; + + uint8_t madctlData = 0x08; + switch(orientation) + { + case Rotate0: + _width = 128; + _height = 160; + madctlData |= flip ? mx : 0; + break; + + case Rotate90: + _width = 160; + _height = 128; + madctlData |= flip ? my | mv | mx : mv | mx; + break; + + case Rotate180: + _width = 128; + _height = 160; + madctlData |= flip ? my : mx | my; + break; + + case Rotate270: + _width = 160; + _height = 128; + madctlData |= flip ? mv : mv | my; + break; + } + write(CMD_MADCTL, (uint8_t[]){madctlData}, 1); +} + +int LCD_ST7735::getWidth() +{ + return _width; +} + +int LCD_ST7735::getHeight() +{ + return _height; +} + void LCD_ST7735::setBacklight(bool state) { _backlight = state ? 1 : 0; @@ -31,7 +77,7 @@ void LCD_ST7735::clearScreen(uint16_t color) { - clipRect(0, 0, 127, 159); + clipRect(0, 0, _width - 1, _height - 1); beginBatchCommand(CMD_RAMWR); for(int i = 0; i < 128 * 160 * 2; ++i) {