This is a port of Henning Kralsen's UTFT library for Arduino/chipKIT to mbed, refactored to make full use of C inheritance and access control, in order to reduce work when implementing new drivers and at the same time make the code more readable and easier to maintain. As of now supported are SSD1289 (16-bit interface), HX8340-B (serial interface) and ST7735 (serial interface). Drivers for other controllers will be added as time and resources to acquire the displays to test the code permit.

Dependents:   UTFT_SSD1289

Fork of TFTLCD by Todor Todorov

Revision:
20:4bdca8d8dadc
Parent:
18:b934d95cc380
Child:
22:4c169297f374
--- a/ssd1289.cpp	Thu Dec 13 03:37:22 2012 +0000
+++ b/ssd1289.cpp	Fri Dec 21 06:05:15 2012 +0000
@@ -222,7 +222,7 @@
     pulseLow( _lcd_pin_wr );
 }
 
-void SSD1289_LCD::SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 )
+void SSD1289_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 )
 {
     if ( _orientation == PORTRAIT || _orientation == PORTRAIT_REV )
     {
@@ -243,22 +243,58 @@
     WriteCmd( 0x22 );
 }
 
-void SSD1289_LCD::SetPixelColor( unsigned int color )
+void SSD1289_LCD::SetPixelColor( unsigned int color, colordepth_t mode )
 {
     unsigned char r, g, b;
     unsigned short clr;
-    r = ( color >> 16 ) & 0xFF;
-    g = ( color >> 8 ) & 0xFF;
-    b = color & 0xFF;
     if ( _colorDepth == RGB16 )
     {
-        clr = ( ( ( ( r ) & 0xF8 ) | ( ( g ) >> 5 ) ) << 8 ) | ( ( ( ( g ) & 0x1C ) << 3 ) | ( ( b ) >> 3 ) );
-        WriteData( clr );
+        switch ( mode )
+        {
+            case RGB16:
+                WriteData( color & 0xFFFF );
+                break;
+            case RGB18:
+                r = ( color >> 10 ) & 0xF8;
+                g = ( color >> 4 ) & 0xFC;
+                b = ( color >> 1 ) & 0x1F;
+                clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | b );
+                WriteData( clr );
+                break;
+            case RGB24:
+                r = ( color >> 16 ) & 0xF8;
+                g = ( color >> 8 ) & 0xFC;
+                b = color & 0xF8;
+                clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | ( b >> 3 ) );
+                WriteData( clr );
+                break;
+        }
     }
     else if ( _colorDepth == RGB18 )
     {
-        clr = ( ( r & 0xFC ) << 8 ) | ( g & 0xFC );
-        WriteData( clr );
-        WriteData( b & 0xFC );
+        switch ( mode )
+        {
+            case RGB16:
+                r = ( ( color >> 8 ) & 0xF8 ) | ( ( color & 0x8000 ) >> 13 );
+                g = ( color >> 3 ) & 0xFC;
+                b = ( ( color << 3 ) & 0xFC ) | ( ( color >> 3 ) & 0x01 );
+                WriteData( ( r << 8 ) | g );
+                WriteData( b );
+                break;
+            case RGB18:
+                b = ( color << 2 ) & 0xFC;
+                g = ( color >> 4 ) & 0xFC;
+                r = ( color >> 10 ) & 0xFC;
+                WriteData( ( r << 8 ) | g );
+                WriteData( b );
+                break;
+            case RGB24:
+                r = ( color >> 16 ) & 0xFC;
+                g = ( color >> 8 ) & 0xFC;
+                b = color & 0xFC;
+                WriteData( ( r << 8 ) | g );
+                WriteData( b );
+                break;
+        }
     }
 }