A first port of the excellent Adafruit ST7735 library

Dependents:   mbed-pong

Files at this revision

API Documentation at this revision

Comitter:
SomeRandomBloke
Date:
Sun Nov 22 15:59:30 2015 +0000
Parent:
5:9c04464cd1b4
Commit message:
Updated setRotation to correct colour problem when rotating display

Changed in this revision

Adafruit_ST7735.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9c04464cd1b4 -r c964b41674fc Adafruit_ST7735.cpp
--- a/Adafruit_ST7735.cpp	Sun Nov 22 13:15:07 2015 +0000
+++ b/Adafruit_ST7735.cpp	Sun Nov 22 15:59:30 2015 +0000
@@ -414,36 +414,70 @@
 #define MADCTL_MX  0x40
 #define MADCTL_MV  0x20
 #define MADCTL_ML  0x10
-#define MADCTL_RGB 0x08
+#define MADCTL_RGB 0x00
+#define MADCTL_BGR 0x08
 #define MADCTL_MH  0x04
 
-void Adafruit_ST7735::setRotation(uint8_t m)
-{
+void Adafruit_ST7735::setRotation(uint8_t m) {
+
+  writecommand(ST7735_MADCTL);
+  rotation = m % 4; // can't be higher than 3
+  switch (rotation) {
+   case 0:
+     if (tabcolor == INITR_BLACKTAB) {
+       writedata(MADCTL_MX | MADCTL_MY | MADCTL_RGB);
+     } else {
+       writedata(MADCTL_MX | MADCTL_MY | MADCTL_BGR);
+     }
+     _width  = ST7735_TFTWIDTH;
+
+     if (tabcolor == INITR_144GREENTAB) 
+       _height = ST7735_TFTHEIGHT_144;
+     else
+       _height = ST7735_TFTHEIGHT_18;
+
+     break;
+   case 1:
+     if (tabcolor == INITR_BLACKTAB) {
+       writedata(MADCTL_MY | MADCTL_MV | MADCTL_RGB);
+     } else {
+       writedata(MADCTL_MY | MADCTL_MV | MADCTL_BGR);
+     }
 
-    writecommand(ST7735_MADCTL);
-    rotation = m % 4; // can't be higher than 3
-    switch (rotation) {
-        case 0:
-            writedata(MADCTL_MX | MADCTL_MY | MADCTL_RGB);
-            _width  = ST7735_TFTWIDTH;
-            _height = ST7735_TFTHEIGHT;
-            break;
-        case 1:
-            writedata(MADCTL_MY | MADCTL_MV | MADCTL_RGB);
-            _width  = ST7735_TFTHEIGHT;
-            _height = ST7735_TFTWIDTH;
-            break;
-        case 2:
-            writedata(MADCTL_RGB);
-            _width  = ST7735_TFTWIDTH;
-            _height = ST7735_TFTHEIGHT;
-            break;
-        case 3:
-            writedata(MADCTL_MX | MADCTL_MV | MADCTL_RGB);
-            _width  = ST7735_TFTHEIGHT;
-            _height = ST7735_TFTWIDTH;
-            break;
-    }
+     if (tabcolor == INITR_144GREENTAB) 
+       _width = ST7735_TFTHEIGHT_144;
+     else
+       _width = ST7735_TFTHEIGHT_18;
+
+     _height = ST7735_TFTWIDTH;
+     break;
+  case 2:
+     if (tabcolor == INITR_BLACKTAB) {
+       writedata(MADCTL_RGB);
+     } else {
+       writedata(MADCTL_BGR);
+     }
+     _width  = ST7735_TFTWIDTH;
+     if (tabcolor == INITR_144GREENTAB) 
+       _height = ST7735_TFTHEIGHT_144;
+     else
+       _height = ST7735_TFTHEIGHT_18;
+
+    break;
+   case 3:
+     if (tabcolor == INITR_BLACKTAB) {
+       writedata(MADCTL_MX | MADCTL_MV | MADCTL_RGB);
+     } else {
+       writedata(MADCTL_MX | MADCTL_MV | MADCTL_BGR);
+     }
+     if (tabcolor == INITR_144GREENTAB) 
+       _width = ST7735_TFTHEIGHT_144;
+     else
+       _width = ST7735_TFTHEIGHT_18;
+
+     _height = ST7735_TFTWIDTH;
+     break;
+  }
 }