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:
13:5ceeba86bbe4
Child:
21:e5c1e8ffada1
--- a/lcd_base.cpp	Thu Dec 13 03:37:22 2012 +0000
+++ b/lcd_base.cpp	Fri Dec 21 06:05:15 2012 +0000
@@ -333,43 +333,18 @@
     if ( scale == 1 )
     {
         SetXY( x, y, x + img->Width - 1, y + img->Height - 1 );
-        
+
         if ( img->Format == RGB16 )
         {
             const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
-            if ( _colorDepth == RGB16 )
-                for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
-                    WriteData( *pixel++ );
-            else if ( _colorDepth == RGB18 )
-            {
-                unsigned short r, g, b;
-                for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
-                {
-                    r = ( *pixel & 0xF800 ) >> 8;
-                    g = ( *pixel & 0x07E0 ) >> 3;
-                    b = ( *pixel & 0x001F ) << 3;
-                    pixel++;
-                    SetPixelColor( RGB( r, g, b ) );
-                }
-            }
+            for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
+                SetPixelColor( *pixel++, img->Format );
         }
         else if ( img->Format == RGB18 )
         {
             const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
-            if ( _colorDepth == RGB16 )
-            {
-                unsigned short r, g, b;
-                for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
-                {
-                    r = ( *pixel >> 16 ) & 0xF8;
-                    g = ( *pixel >> 8 ) & 0xFC;
-                    b = ( *pixel++ & 0xF8 ) >> 3;
-                    WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b );
-                }
-            }
-            else if ( _colorDepth == RGB18 )
-                for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
-                    SetPixelColor( *pixel++ );
+            for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
+                SetPixelColor( *pixel++, img->Format );
         }
     }
     else
@@ -377,35 +352,6 @@
         if ( img->Format == RGB16 )
         {
             const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
-            unsigned short r, g, b;
-                            
-            for ( ty = 0; ty < img->Height; ty++ )
-            {
-                SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale );
-                for ( tsy = 0; tsy < scale; tsy++ )
-                {
-                    for ( tx = 0; tx < img->Width; tx++ )
-                    {
-                        for ( tsx = 0; tsx < scale; tsx++ )
-                        {
-                            if ( _colorDepth == RGB16 )
-                                WriteData( pixel[ ( ty * img->Width ) + tx ] );
-                            else if ( _colorDepth == RGB18 )
-                            {
-                                r = ( pixel[ ( ty * img->Width ) + tx ] & 0xF800 ) >> 8;
-                                g = ( pixel[ ( ty * img->Width ) + tx ] & 0x07E0 ) >> 3;
-                                b = ( pixel[ ( ty * img->Width ) + tx ] & 0x001F ) << 3;
-                                SetPixelColor( RGB( r, g, b ) );
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        else if ( img->Format == RGB18 )
-        {
-            const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
-            unsigned short r, g, b;
             
             for ( ty = 0; ty < img->Height; ty++ )
             {
@@ -415,17 +361,24 @@
                     for ( tx = 0; tx < img->Width; tx++ )
                     {
                         for ( tsx = 0; tsx < scale; tsx++ )
-                        {
-                            if ( _colorDepth == RGB16 )
-                            {                                
-                                r = ( pixel[ ( ty * img->Width ) + tx ] >> 16 ) & 0xF8;
-                                g = ( pixel[ ( ty * img->Width ) + tx ] >> 8 ) & 0xFC;
-                                b = ( pixel[ ( ty * img->Width ) + tx ] & 0xF8 ) >> 3;
-                                WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b );
-                            }
-                            else if ( _colorDepth == RGB18 )
-                                SetPixelColor( pixel[ ( ty * img->Width ) + tx ] );
-                        }
+                            SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
+                    }
+                }
+            }
+        }
+        else if ( img->Format == RGB18 )
+        {
+            const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
+            
+            for ( ty = 0; ty < img->Height; ty++ )
+            {
+                SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale );
+                for ( tsy = 0; tsy < scale; tsy++ )
+                {
+                    for ( tx = 0; tx < img->Width; tx++ )
+                    {
+                        for ( tsx = 0; tsx < scale; tsx++ )
+                            SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
                     }
                 }
             }
@@ -449,7 +402,6 @@
         if ( img->Format == RGB16 )
         {
             const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
-            unsigned short r, g, b;
             
             for ( ty = 0; ty < img->Height; ty++ )
                 for ( tx = 0; tx < img->Width; tx++ )
@@ -458,21 +410,12 @@
                     newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
     
                     SetXY( newx, newy, newx, newy );
-                    if ( _colorDepth == RGB16 )
-                        WriteData( pixel[ ( ty * img->Width ) + tx ] );
-                    else if ( _colorDepth == RGB18 )
-                    {
-                        r = ( pixel[ ( ty * img->Width ) + tx ] & 0xF800 ) >> 8;
-                        g = ( pixel[ ( ty * img->Width ) + tx ] & 0x07E0 ) >> 3;
-                        b = ( pixel[ ( ty * img->Width ) + tx ] & 0x001F ) << 3;
-                        SetPixelColor( RGB( r, g, b ) );
-                    }
+                    SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
                 }
         }
         else if ( img->Format == RGB18 )
         {
             const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
-            unsigned short r, g, b;
             
             for ( ty = 0; ty < img->Height; ty++ )
                 for ( tx = 0; tx < img->Width; tx++ )
@@ -481,15 +424,7 @@
                     newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
     
                     SetXY( newx, newy, newx, newy );
-                    if ( _colorDepth == RGB16 )
-                    {
-                        r = ( pixel[ ( ty * img->Width ) + tx ] >> 16 ) & 0xF8;
-                        g = ( pixel[ ( ty * img->Width ) + tx ] >> 8 ) & 0xFC;
-                        b = ( pixel[ ( ty * img->Width ) + tx ] & 0xF8 ) >> 3;
-                        WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b );
-                    }
-                    else if ( _colorDepth == RGB18 )
-                        SetPixelColor( pixel[ ( ty * img->Width ) + tx ] );
+                    SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
                 }
         }
         Deactivate();