LCD TFT

Dependents:   Example_Menu_LCD_TFT

Files at this revision

API Documentation at this revision

Comitter:
Suky
Date:
Tue Mar 15 01:47:35 2011 +0000
Parent:
0:359653f39307
Commit message:

Changed in this revision

LCDTFT.cpp Show annotated file Show diff for this revision Revisions of this file
LCDTFT.h Show annotated file Show diff for this revision Revisions of this file
diff -r 359653f39307 -r 1085b6177f6e LCDTFT.cpp
--- a/LCDTFT.cpp	Sun Jan 30 20:25:48 2011 +0000
+++ b/LCDTFT.cpp	Tue Mar 15 01:47:35 2011 +0000
@@ -1,393 +1,401 @@
-/*
-  @file LCDTFT.cpp
-  @version: 1.0
- 
-  @web www.micros-designs.com.ar
-  @date 30/01/11
-  
-*- Version Log --------------------------------------------------------------*
-*   Fecha       Autor                Comentarios                             *
-*----------------------------------------------------------------------------*
-* 30/01/11      Suky        Original                                         *
-*----------------------------------------------------------------------------*/ 
-///////////////////////////////////////////////////////////////////////////
-////                                                                   ////
-////                                                                   ////
-////        (C) Copyright 2011 www.micros-designs.com.ar               ////
-//// Este código puede ser usado, modificado y distribuido libremente  ////
-//// sin eliminar esta cabecera y  sin garantía de ningún tipo.        ////
-////                                                                   ////
-////                                                                   ////
-/////////////////////////////////////////////////////////////////////////// 
-#include "LCDTFT.h"
-
-LCDTFT::LCDTFT(PinName PIN_RD,PinName PIN_WR,PinName PIN_RS,PinName PIN_CS,PinName PIN_RESET, BusOut *BUSLCD)
-	: LCD_PIN_RD(PIN_RD),LCD_PIN_WR(PIN_WR),LCD_PIN_RS(PIN_RS),LCD_PIN_CS(PIN_CS),LCD_PIN_RESET(PIN_RESET){
-	LCD_PORT=BUSLCD;
-	X=0;
-	Y=0;
-	X_min=0;
-	X_max=LCD_X_MAX;
-	_Alto=1;
-	_Color=0x0000;
-}
-
-void LCDTFT::vLCDTFTSetParametersPrintf(unsigned short Xo,unsigned short Yo,unsigned short Xmin,unsigned short Xmax,unsigned char Alto, unsigned short Color){
-
-	X=Xo;
-	Y=Yo;
-	X_min=Xmin;
-	X_max=Xmax;
-	_Alto=Alto;
-	_Color=Color;
-}
-
-int LCDTFT::_putc(int value){
-	char Fmt[2]={value,0};
-
-	if(value=='\n'){
-		X=X_min;
-		Y+=7*_Alto + 1;
-	}else{
-		vLCDTFTText(X,Y,(const char *)&Fmt[0],&ARIAL[0],_Alto,_Color);
-		X+=5*_Alto+1;
-		if(X >= X_max){
-			X = X_min;                           
-			Y += 7*_Alto + 1;                
-		}
-	}
-	return(value);
-}
-
-int LCDTFT::_getc(){
-	return(-1);
-}
-
-void LCDTFT::vLCDTFTWriteCommand(unsigned short Data){   
-    
-    LCD_PIN_RS=0;
-    LCD_PIN_CS=0;   
-    LCD_PORT->write(Data);   
-    LCD_PIN_WR=0;
-    LCD_PIN_WR=1;
-    LCD_PIN_CS=1;   
-}
-
-void LCDTFT::vLCDTFTWriteData(unsigned short Data){
-    LCD_PIN_RS=1;
-    LCD_PIN_CS=0;   
-    LCD_PORT->write(Data);   
-    LCD_PIN_WR=0;
-    LCD_PIN_WR=1;
-    LCD_PIN_CS =1;   
-}
-
-
-void LCDTFT::vLCDTFTWriteCommandData(unsigned short CMD,unsigned short Data){
-    vLCDTFTWriteCommand(CMD);
-    vLCDTFTWriteData(Data);
-}
-
-void LCDTFT::vLCDTFTAddressSet(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2){ 
-
-    vLCDTFTWriteCommandData(0x0044,(x2<<8)+x1);
-    vLCDTFTWriteCommandData(0x0045,y1);
-    vLCDTFTWriteCommandData(0x0046,y2);
-    vLCDTFTWriteCommandData(0x004e,x1);
-    vLCDTFTWriteCommandData(0x004f,y1);
-    vLCDTFTWriteCommand(0x0022);       
-}  
-
-void LCDTFT::vLCDTFTAddressSetPoint(unsigned short x,unsigned short y){ 
-
-    vLCDTFTWriteCommandData(0x004e,x);
-    vLCDTFTWriteCommandData(0x004f,y);
-    vLCDTFTWriteCommand(0x0022);       
-}  
-
-void LCDTFT::vLCDTFTInit(void){
-
-	LCD_PIN_RESET=1;
-    wait_ms(5);   
-    LCD_PIN_RESET=0;
-    wait_ms(10);
-    LCD_PIN_RESET=1;
-    LCD_PIN_CS=1;
-    LCD_PIN_RD=1;
-    LCD_PIN_WR=1;
-    wait_ms(20);
-
-	vLCDTFTWriteCommandData(0x0000,0x0001);    wait_ms(1);  
-	vLCDTFTWriteCommandData(0x0003,0xA8A4);    wait_ms(1);  
-    vLCDTFTWriteCommandData(0x000C,0x0000);    wait_ms(1);   
-    vLCDTFTWriteCommandData(0x000D,0x080C);    wait_ms(1);   
-    vLCDTFTWriteCommandData(0x000E,0x2B00);    wait_ms(1);   
-    vLCDTFTWriteCommandData(0x001E,0x00B0);    wait_ms(1);   
-    vLCDTFTWriteCommandData(0x0001,0x2B3F);    wait_ms(1);   
-    vLCDTFTWriteCommandData(0x0002,0x0600);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0010,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0011,0x6070);    wait_ms(1);        
-    vLCDTFTWriteCommandData(0x0005,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0006,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0016,0xEF1C);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0017,0x0003);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0007,0x0233);    wait_ms(1);          
-    vLCDTFTWriteCommandData(0x000B,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x000F,0x0000);    wait_ms(1);        
-    vLCDTFTWriteCommandData(0x0041,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0042,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0048,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0049,0x013F);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x004A,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x004B,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0044,0xEF00);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0045,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0046,0x013F);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0030,0x0707);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0031,0x0204);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0032,0x0204);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0033,0x0502);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0034,0x0507);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0035,0x0204);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0036,0x0204);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0037,0x0502);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x003A,0x0302);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x003B,0x0302);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0023,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0024,0x0000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x0025,0x8000);    wait_ms(1);
-    vLCDTFTWriteCommandData(0x004f,0);        
-    vLCDTFTWriteCommandData(0x004e,0);        
-    vLCDTFTWriteCommand(0x0022);
-}
-
-void LCDTFT::vLCDTFTFillScreen(unsigned short Color){
-    unsigned short i,j;
-    vLCDTFTAddressSet(0,0,239,319);
-
-    for(i=0;i<320;i++){
-        for (j=0;j<240;j++){
-            vLCDTFTWriteData(Color);
-        }
-    }      
-}
-
-void LCDTFT::vLCDTFTPoint(unsigned short x,unsigned short y,unsigned short Color){
-
-    vLCDTFTAddressSetPoint(x,y);
-    vLCDTFTWriteData(Color);
-}
- 
-void LCDTFT::vLCDTFTText(unsigned short x,unsigned short y,const char *PtrText,const char (*Fuente)[5],unsigned char Alto,unsigned short Color){
-   unsigned short i, j, k, l, m, temp;           
-   char DataPunto[5]; 
-   const char *Ptr;
-    
-   while(*PtrText!='\0'){
-      Ptr=(Fuente+*PtrText-' ')[0];
-      for(i=0;i<5;i++){DataPunto[i]=*Ptr++;}
-      switch(*PtrText){
-         case '\n':
-            y += 7*Alto + 1;
-         break;
-         case '\r':
-            x = 0;
-         break;
-         default:
-            if(x+5*Alto >= LCD_X_MAX){
-                 x = 0;                           
-                 y += 7*Alto + 1;                
-              }
-              for(j=0; j<5; ++j, x+=Alto){
-                 for(k=0; k < 7; k++){
-                    temp=(0x01<<k);
-                    if((DataPunto[j]&temp)==temp){
-                       for(l=0; l < Alto; ++l){                         
-                          for(m=0; m < Alto; ++m){
-                             vLCDTFTPoint(x+m,y+k*Alto+l,Color);
-                          }
-                       }
-                    }
-                 }
-              }
-              x++;
-          break;
-      } 
-      *PtrText++;     
-   }
-}
-
-void LCDTFT::vLCDTFTLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short Color){
-
-   unsigned short dy, dx;
-   short addx=1, addy=1;
-   short P, diff;
-   unsigned short i=0;
-
-   diff=((short)x2-x1);
-   if(diff<0) diff*=-1;
-   dx=diff;
-   diff=((short)y2-y1);
-   if(diff<0) diff*=-1;
-   dy=diff;
-
-
-   if(x1 > x2)addx = -1;
-   if(y1 > y2)addy = -1;
-   if(dx >= dy){
-      dy *= 2;
-      P = dy - dx;
-      diff = P - dx;
-      for(;i<=dx;++i){
-         vLCDTFTPoint(x1, y1, Color);
-         if(P < 0){
-            P  += dy;
-            x1 += addx;
-         }else{
-            P  += diff;
-            x1 += addx;
-            y1 += addy;
-         }
-      }
-   }else{
-      dx *= 2;
-      P = dx - dy;
-      diff = P - dy;
-      for(; i<=dy; ++i){
-         vLCDTFTPoint(x1, y1, Color);
-         if(P < 0){
-            P  += dx;
-            y1 += addy;
-         }else{
-            P  += diff;
-            x1 += addx;
-            y1 += addy;
-         }
-      }
-   }
-}
-
-
-void LCDTFT::vLCDTFTRectangle(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,bool Filled,unsigned short Color){
-   
-    if(Filled){
-        int Lenght=((int)(x2-x1+1)*(y2-y1+1));  
-       
-        vLCDTFTAddressSet(x1,y1,x2,y2);      
-        for(int i=0;i<Lenght;i++){
-            vLCDTFTWriteData(Color);                         
-        }   
-    }else{
-        vLCDTFTLine(x1, y1, x2, y1, Color);     
-        vLCDTFTLine(x1, y2, x2, y2, Color);
-        vLCDTFTLine(x1, y1, x1, y2, Color);
-        vLCDTFTLine(x2, y1, x2, y2, Color);
-    }
-}
-
-
-void LCDTFT::vLCDTFTCircle(unsigned short x,unsigned short y,unsigned short Radius,bool Filled,unsigned short Color){
-    short  a, b, P;
-
-    a = 0;
-    b = Radius;
-    P = 1 - Radius;
-
-    do{
-        if(Filled){
-            vLCDTFTLine(x-a, y+b, x+a, y+b, Color);
-            vLCDTFTLine(x-a, y-b, x+a, y-b, Color);
-            vLCDTFTLine(x-b, y+a, x+b, y+a, Color);
-            vLCDTFTLine(x-b, y-a, x+b, y-a, Color);
-        }else{
-            vLCDTFTPoint(a+x, b+y, Color);
-            vLCDTFTPoint(b+x, a+y, Color);
-            vLCDTFTPoint(x-a, b+y, Color);
-            vLCDTFTPoint(x-b, a+y, Color);
-            vLCDTFTPoint(b+x, y-a, Color);
-            vLCDTFTPoint(a+x, y-b, Color);
-            vLCDTFTPoint(x-a, y-b, Color);
-            vLCDTFTPoint(x-b, y-a, Color);
-        }
-        if(P < 0) P += 3 + 2 * a++;
-        else P += 5 + 2 * (a++ - b--);
-    }while(a <= b);
-}
-
-void LCDTFT::vDrawImageBMP24Bits(const char *NameImagen){
-
-    #define OffsetWidthPixel    18
-    #define OffsetHeighPixel    22
-    #define OffsetSizeFile      34
-    #define OffsetInitData      10
-    #define OffserTipeFile      28
-    char Nombre[80],k;
-    unsigned short PosXImagen,PosYImagen;
-    unsigned char Temp,BufferHeader[54],BufferTemp[3],Adicional;
-    unsigned int WidthPixel,HeighPixel;
-    unsigned short TipeFile,InitData,Temp16bits;
-    union{
-        unsigned short Val;
-        struct{
-            unsigned Blue:5;
-            unsigned Green:6;
-            unsigned Red:5;
-        };
-    }Color; 
-
-    LocalFileSystem local("mbedMemory");
-    sprintf(&Nombre[0],"/mbedMemory/");
-    k=12;
-    while(*NameImagen!='\0'){
-        Nombre[k++]=*NameImagen++;
-    }
-    
-    FILE *Imagen = fopen((const char *)&Nombre[0], "r"); // Abrimos archivo para lectura.
-    // Si no se pudo encontrar archivo:
-    if(!Imagen) {
-		vLCDTFTFillScreen(ColorBlack);
-        return;
-    }
-    // Leemos cabecera de archivo
-    fread(&BufferHeader[0],1,54,Imagen);
-    
-    WidthPixel = ((unsigned int)BufferHeader[OffsetWidthPixel + 3]*16777216+BufferHeader[OffsetWidthPixel + 2]*65536+BufferHeader[OffsetWidthPixel + 1]*256+BufferHeader[OffsetWidthPixel]);
-    HeighPixel = ((unsigned int)BufferHeader[OffsetHeighPixel + 3]*16777216+BufferHeader[OffsetHeighPixel + 2]*65536+BufferHeader[OffsetHeighPixel + 1]*256+BufferHeader[OffsetHeighPixel]);
-    InitData = ((unsigned short)BufferHeader[OffsetInitData]);
-    TipeFile = ((unsigned short)BufferHeader[OffserTipeFile + 1]*256 + BufferHeader[OffserTipeFile]);
-    
-    if((WidthPixel>LCD_X_MAX) || (HeighPixel>LCD_Y_MAX) || (TipeFile!=24)){
-        fclose(Imagen);
-        return;
-    }
-    
-    if(InitData!=54){
-        for(int k=54;k<InitData;k++){
-            fread(&Temp,1,1,Imagen);
-        }
-    }
-    
-    PosXImagen=(LCD_X_MAX/2)-(WidthPixel/2);
-    PosYImagen=(LCD_Y_MAX/2)+(HeighPixel/2);
-    
-    Temp16bits=WidthPixel*3;
-    Adicional=0;
-    while(((Temp16bits)%4)!=0){
-        Adicional++;
-        Temp16bits++;
-    }
-    
-    for(int k=0,y=PosYImagen;k<HeighPixel;k++,y--){
-        vLCDTFTAddressSet(PosXImagen,y,PosXImagen+WidthPixel-1,y);
-        for(int i=0;i<WidthPixel;i++){
-            fread(&BufferTemp[0],1,3,Imagen); // Leemos 3 bytes (R,G,B)
-            Color.Blue=BufferTemp[0]>>3;Color.Green=BufferTemp[1]>>2;Color.Red=BufferTemp[2]>>3; // Conversion de 24-bits a 16-bits.-
-            vLCDTFTWriteData(Color.Val);
-        }
-        // Bytes adicionales para que linea sea multiplo de 4.-
-        for(int p=0;p<Adicional;p++){
-            fread(&Temp,1,1,Imagen);
-        }
-    }
-    fclose(Imagen);
+/*
+  @file LCDTFT.cpp
+  @version: 1.0
+ 
+  @web www.micros-designs.com.ar
+  @date 30/01/11
+  
+*- Version Log --------------------------------------------------------------*
+*   Fecha       Autor                Comentarios                             *
+*----------------------------------------------------------------------------*
+* 30/01/11      Suky        Original                                         *
+*----------------------------------------------------------------------------*/ 
+///////////////////////////////////////////////////////////////////////////
+////                                                                   ////
+////                                                                   ////
+////        (C) Copyright 2011 www.micros-designs.com.ar               ////
+//// Este código puede ser usado, modificado y distribuido libremente  ////
+//// sin eliminar esta cabecera y  sin garantía de ningún tipo.        ////
+////                                                                   ////
+////                                                                   ////
+/////////////////////////////////////////////////////////////////////////// 
+#include "LCDTFT.h"
+
+LCDTFT::LCDTFT(PinName PIN_RD,PinName PIN_WR,PinName PIN_RS,PinName PIN_CS,PinName PIN_RESET, BusOut *BUSLCD)
+    : LCD_PIN_RD(PIN_RD),LCD_PIN_WR(PIN_WR),LCD_PIN_RS(PIN_RS),LCD_PIN_CS(PIN_CS),LCD_PIN_RESET(PIN_RESET){
+    LCD_PORT=BUSLCD;
+    X=0;
+    Y=0;
+    X_min=0;
+    X_max=LCD_X_MAX;
+    _Alto=1;
+    _Color=0x0000;
+}
+
+void LCDTFT::vLCDTFTSetParametersPrintf(unsigned short Xo,unsigned short Yo,unsigned short Xmin,unsigned short Xmax,unsigned char Alto, unsigned short Color){
+
+    X=Xo;
+    Y=Yo;
+    X_min=Xmin;
+    X_max=Xmax;
+    _Alto=Alto;
+    _Color=Color;
+}
+
+int LCDTFT::_putc(int value){
+    char Fmt[2]={value,0};
+
+    if(value=='\n'){
+        X=X_min;
+        Y+=7*_Alto + 1;
+    }else{
+        vLCDTFTText(X,Y,(const char *)&Fmt[0],&ARIAL[0],_Alto,_Color);
+        X+=5*_Alto+1;
+        if(X >= X_max){
+            X = X_min;                           
+            Y += 7*_Alto + 1;                
+        }
+    }
+    return(value);
+}
+
+int LCDTFT::_getc(){
+    return(-1);
+}
+
+void LCDTFT::vLCDTFTWriteCommand(unsigned short Data){   
+    
+    LCD_PIN_RS=0;
+    LCD_PIN_CS=0;   
+    LCD_PORT->write(Data);   
+    LCD_PIN_WR=0;
+    LCD_PIN_WR=1;
+    LCD_PIN_CS=1;   
+}
+
+void LCDTFT::vLCDTFTWriteData(unsigned short Data){
+    LCD_PIN_RS=1;
+    LCD_PIN_CS=0;   
+    LCD_PORT->write(Data);   
+    LCD_PIN_WR=0;
+    LCD_PIN_WR=1;
+    LCD_PIN_CS =1;   
+}
+
+
+void LCDTFT::vLCDTFTWriteCommandData(unsigned short CMD,unsigned short Data){
+    vLCDTFTWriteCommand(CMD);
+    vLCDTFTWriteData(Data);
+}
+
+void LCDTFT::vLCDTFTAddressSet(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2){ 
+
+    vLCDTFTWriteCommandData(0x0044,(x2<<8)+x1);
+    vLCDTFTWriteCommandData(0x0045,y1);
+    vLCDTFTWriteCommandData(0x0046,y2);
+    vLCDTFTWriteCommandData(0x004e,x1);
+    vLCDTFTWriteCommandData(0x004f,y1);
+    vLCDTFTWriteCommand(0x0022);       
+}  
+
+void LCDTFT::vLCDTFTAddressSetPoint(unsigned short x,unsigned short y){ 
+
+    vLCDTFTWriteCommandData(0x004e,x);
+    vLCDTFTWriteCommandData(0x004f,y);
+    vLCDTFTWriteCommand(0x0022);       
+}  
+
+void LCDTFT::vLCDTFTInit(void){
+
+    LCD_PIN_RESET=1;
+    wait_ms(5);   
+    LCD_PIN_RESET=0;
+    wait_ms(10);
+    LCD_PIN_RESET=1;
+    LCD_PIN_CS=1;
+    LCD_PIN_RD=1;
+    LCD_PIN_WR=1;
+    wait_ms(20);
+
+    vLCDTFTWriteCommandData(0x0000,0x0001);    wait_ms(1);  
+    vLCDTFTWriteCommandData(0x0003,0xA8A4);    wait_ms(1);  
+    vLCDTFTWriteCommandData(0x000C,0x0000);    wait_ms(1);   
+    vLCDTFTWriteCommandData(0x000D,0x080C);    wait_ms(1);   
+    vLCDTFTWriteCommandData(0x000E,0x2B00);    wait_ms(1);   
+    vLCDTFTWriteCommandData(0x001E,0x00B0);    wait_ms(1);   
+    vLCDTFTWriteCommandData(0x0001,0x2B3F);    wait_ms(1);   
+    vLCDTFTWriteCommandData(0x0002,0x0600);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0010,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0011,0x6070);    wait_ms(1);        
+    vLCDTFTWriteCommandData(0x0005,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0006,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0016,0xEF1C);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0017,0x0003);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0007,0x0233);    wait_ms(1);          
+    vLCDTFTWriteCommandData(0x000B,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x000F,0x0000);    wait_ms(1);        
+    vLCDTFTWriteCommandData(0x0041,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0042,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0048,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0049,0x013F);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x004A,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x004B,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0044,0xEF00);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0045,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0046,0x013F);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0030,0x0707);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0031,0x0204);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0032,0x0204);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0033,0x0502);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0034,0x0507);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0035,0x0204);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0036,0x0204);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0037,0x0502);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x003A,0x0302);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x003B,0x0302);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0023,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0024,0x0000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x0025,0x8000);    wait_ms(1);
+    vLCDTFTWriteCommandData(0x004f,0);        
+    vLCDTFTWriteCommandData(0x004e,0);        
+    vLCDTFTWriteCommand(0x0022);
+}
+
+void LCDTFT::vLCDTFTFillScreen(unsigned short Color){
+    unsigned short i,j;
+    vLCDTFTAddressSet(0,0,239,319);
+
+    for(i=0;i<320;i++){
+        for (j=0;j<240;j++){
+            vLCDTFTWriteData(Color);
+        }
+    }      
+}
+
+void LCDTFT::vLCDTFTPoint(unsigned short x,unsigned short y,unsigned short Color){
+
+    vLCDTFTAddressSetPoint(x,y);
+    vLCDTFTWriteData(Color);
+}
+ 
+void LCDTFT::vLCDTFTText(unsigned short x,unsigned short y,const char *PtrText,const char (*Fuente)[5],unsigned char Alto,unsigned short Color){
+   unsigned short i, j, k, l, m, temp;           
+   char DataPunto[5]; 
+   const char *Ptr;
+    
+   while(*PtrText!='\0'){
+      Ptr=(Fuente+*PtrText-' ')[0];
+      for(i=0;i<5;i++){DataPunto[i]=*Ptr++;}
+      switch(*PtrText){
+         case '\n':
+            y += 7*Alto + 1;
+         break;
+         case '\r':
+            x = 0;
+         break;
+         default:
+            if(x+5*Alto >= LCD_X_MAX){
+                 x = 0;                           
+                 y += 7*Alto + 1;                
+              }
+              for(j=0; j<5; ++j, x+=Alto){
+                 for(k=0; k < 7; k++){
+                    temp=(0x01<<k);
+                    if((DataPunto[j]&temp)==temp){
+                       for(l=0; l < Alto; ++l){                         
+                          for(m=0; m < Alto; ++m){
+                             vLCDTFTPoint(x+m,y+k*Alto+l,Color);
+                          }
+                       }
+                    }
+                 }
+              }
+              x++;
+          break;
+      } 
+      *PtrText++;     
+   }
+}
+
+void LCDTFT::vLCDTFTLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short Color){
+
+   unsigned short dy, dx;
+   short addx=1, addy=1;
+   short P, diff;
+   unsigned short i=0;
+
+   diff=((short)x2-x1);
+   if(diff<0) diff*=-1;
+   dx=diff;
+   diff=((short)y2-y1);
+   if(diff<0) diff*=-1;
+   dy=diff;
+
+
+   if(x1 > x2)addx = -1;
+   if(y1 > y2)addy = -1;
+   if(dx >= dy){
+      dy *= 2;
+      P = dy - dx;
+      diff = P - dx;
+      for(;i<=dx;++i){
+         vLCDTFTPoint(x1, y1, Color);
+         if(P < 0){
+            P  += dy;
+            x1 += addx;
+         }else{
+            P  += diff;
+            x1 += addx;
+            y1 += addy;
+         }
+      }
+   }else{
+      dx *= 2;
+      P = dx - dy;
+      diff = P - dy;
+      for(; i<=dy; ++i){
+         vLCDTFTPoint(x1, y1, Color);
+         if(P < 0){
+            P  += dx;
+            y1 += addy;
+         }else{
+            P  += diff;
+            x1 += addx;
+            y1 += addy;
+         }
+      }
+   }
+}
+
+
+void LCDTFT::vLCDTFTRectangle(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,bool Filled,unsigned short Color){
+   
+    if(Filled){
+        int Lenght=((int)(x2-x1+1)*(y2-y1+1));  
+       
+        vLCDTFTAddressSet(x1,y1,x2,y2);      
+        for(int i=0;i<Lenght;i++){
+            vLCDTFTWriteData(Color);                         
+        }   
+    }else{
+        vLCDTFTLine(x1, y1, x2, y1, Color);     
+        vLCDTFTLine(x1, y2, x2, y2, Color);
+        vLCDTFTLine(x1, y1, x1, y2, Color);
+        vLCDTFTLine(x2, y1, x2, y2, Color);
+    }
+}
+
+
+void LCDTFT::vLCDTFTCircle(unsigned short x,unsigned short y,unsigned short Radius,bool Filled,unsigned short Color){
+    short  a, b, P;
+
+    a = 0;
+    b = Radius;
+    P = 1 - Radius;
+
+    do{
+        if(Filled){
+            vLCDTFTLine(x-a, y+b, x+a, y+b, Color);
+            vLCDTFTLine(x-a, y-b, x+a, y-b, Color);
+            vLCDTFTLine(x-b, y+a, x+b, y+a, Color);
+            vLCDTFTLine(x-b, y-a, x+b, y-a, Color);
+        }else{
+            vLCDTFTPoint(a+x, b+y, Color);
+            vLCDTFTPoint(b+x, a+y, Color);
+            vLCDTFTPoint(x-a, b+y, Color);
+            vLCDTFTPoint(x-b, a+y, Color);
+            vLCDTFTPoint(b+x, y-a, Color);
+            vLCDTFTPoint(a+x, y-b, Color);
+            vLCDTFTPoint(x-a, y-b, Color);
+            vLCDTFTPoint(x-b, y-a, Color);
+        }
+        if(P < 0) P += 3 + 2 * a++;
+        else P += 5 + 2 * (a++ - b--);
+    }while(a <= b);
+}
+
+void LCDTFT::vDrawImageBMP24Bits(const char *NameImagen){
+
+    #define OffsetWidthPixel    18
+    #define OffsetHeighPixel    22
+    #define OffsetSizeFile      34
+    #define OffsetInitData      10
+    #define OffserTipeFile      28
+    char Nombre[80],k;
+    unsigned short PosXImagen,PosYImagen;
+    unsigned char Temp,BufferHeader[54],BufferTemp[3],Adicional;
+    unsigned int WidthPixel,HeighPixel;
+    unsigned short TipeFile,InitData,Temp16bits;
+    union{
+        unsigned short Val;
+        struct{
+            unsigned Blue:5;
+            unsigned Green:6;
+            unsigned Red:5;
+        };
+    }Color; 
+
+    LocalFileSystem local("mbedMemory");
+    sprintf(&Nombre[0],"/mbedMemory/");
+    k=12;
+    while(*NameImagen!='\0'){
+        Nombre[k++]=*NameImagen++;
+    }
+    
+    FILE *Imagen = fopen((const char *)&Nombre[0], "r"); // Abrimos archivo para lectura.
+    // Si no se pudo encontrar archivo:
+    if(!Imagen) {
+        vLCDTFTFillScreen(ColorBlack);
+        return;
+    }
+    // Leemos cabecera de archivo
+    fread(&BufferHeader[0],1,54,Imagen);
+    
+    WidthPixel = ((unsigned int)BufferHeader[OffsetWidthPixel + 3]*16777216+BufferHeader[OffsetWidthPixel + 2]*65536+BufferHeader[OffsetWidthPixel + 1]*256+BufferHeader[OffsetWidthPixel]);
+    HeighPixel = ((unsigned int)BufferHeader[OffsetHeighPixel + 3]*16777216+BufferHeader[OffsetHeighPixel + 2]*65536+BufferHeader[OffsetHeighPixel + 1]*256+BufferHeader[OffsetHeighPixel]);
+    InitData = ((unsigned short)BufferHeader[OffsetInitData]);
+    TipeFile = ((unsigned short)BufferHeader[OffserTipeFile + 1]*256 + BufferHeader[OffserTipeFile]);
+    
+    if((WidthPixel>LCD_X_MAX) || (HeighPixel>LCD_Y_MAX) || (TipeFile!=24)){
+        fclose(Imagen);
+        return;
+    }
+    
+    if(InitData!=54){
+        for(int k=54;k<InitData;k++){
+            fread(&Temp,1,1,Imagen);
+        }
+    }
+    
+    PosXImagen=(LCD_X_MAX/2)-(WidthPixel/2);
+    PosYImagen=(LCD_Y_MAX/2)+(HeighPixel/2);
+    
+    Temp16bits=WidthPixel*3;
+    Adicional=0;
+    while(((Temp16bits)%4)!=0){
+        Adicional++;
+        Temp16bits++;
+    }
+    
+    for(int k=0,y=PosYImagen;k<HeighPixel;k++,y--){
+        vLCDTFTAddressSet(PosXImagen,y,PosXImagen+WidthPixel-1,y);
+        for(int i=0;i<WidthPixel;i++){
+            fread(&BufferTemp[0],1,3,Imagen); // Leemos 3 bytes (R,G,B)
+            Color.Blue=BufferTemp[0]>>3;Color.Green=BufferTemp[1]>>2;Color.Red=BufferTemp[2]>>3; // Conversion de 24-bits a 16-bits.-
+            vLCDTFTWriteData(Color.Val);
+        }
+        // Bytes adicionales para que linea sea multiplo de 4.-
+        for(int p=0;p<Adicional;p++){
+            fread(&Temp,1,1,Imagen);
+        }
+    }
+    fclose(Imagen);
+}
+
+void LCDTFT::vLCDTFTDrawImage(unsigned short x,unsigned short y, unsigned short Width, unsigned short Heigh, unsigned int Lenght, const unsigned short *Imagen){
+
+    vLCDTFTAddressSet(x,y,x+Width-1,y+Heigh-1);      
+    for(int i=0;i<Lenght;i++){
+        vLCDTFTWriteData(*Imagen++);                         
+    }
 }
\ No newline at end of file
diff -r 359653f39307 -r 1085b6177f6e LCDTFT.h
--- a/LCDTFT.h	Sun Jan 30 20:25:48 2011 +0000
+++ b/LCDTFT.h	Tue Mar 15 01:47:35 2011 +0000
@@ -1,156 +1,157 @@
-/*
-  @file LCDTFT.h
-  @version: 1.0
-  
-  @web www.micros-designs.com.ar
-  @date 30/01/11
-  
-*- Version Log --------------------------------------------------------------*
-*   Fecha       Autor                Comentarios                             *
-*----------------------------------------------------------------------------*
-* 30/01/11      Suky        Original                                         *
-*----------------------------------------------------------------------------*/ 
-///////////////////////////////////////////////////////////////////////////
-////                                                                   ////
-////                                                                   ////
-////        (C) Copyright 2011 www.micros-designs.com.ar               ////
-//// Este código puede ser usado, modificado y distribuido libremente  ////
-//// sin eliminar esta cabecera y  sin garantía de ningún tipo.        ////
-////                                                                   ////
-////                                                                   ////
-/////////////////////////////////////////////////////////////////////////// 
-
-/** Libreria para LCD TFT chip Himax HX8347-A
- *
- *
- * @code
- * #include "mbed.h"
- * #include "LCDTFT.h"
- * 
- *BusOut 	MyBus(p13,p14,p15,p16,p17,p18,p19,p20,p30,p29,p28,p27,p26,p25,p24,p23);
- *LCDTFT 	MyLCD(p5,p6,p7,p22,p21,&MyBus);
- *
- *int main(){
- *	MyLCD.vLCDTFTInit();
- *	MyLCD.vLCDTFTFillScreen(ColorWhite);
- *	MyLCD.printf("Hola mbed!!!");
- *
- *	MyLCD.vDrawImageBMP24Bits("IMG0.BMP");
- *
- *    while(1){  
- *    }
- *}
- * @endcode
- */
-
-#include "mbed.h"
-#include "Fuentes.h"
-
-#define    ColorRed        		0xf800
-#define    ColorGreen        	0x400
-#define    ColorBlue        	0x001f
-#define    ColorMarron        	0x8208
-#define    ColorBlack        	0x0
-#define    ColorWhite        	0xffff
-#define    ColorMaroon        	0x8000
-#define    ColorFuchsia    		0xf81f
-#define    ColorVioleta    		0x801f
-#define    ColorAzulMarino    	0x14
-#define    ColorGray        	0x8410
-#define    ColorOlive        	0x8400
-#define    ColorNaranja    		0xfc08
-#define    ColorYellow        	0xffe0
-#define    ColorCian        	0x87ff
-#define    ColorRosado        	0xf810
-#define    ColorNavy        	0x10
-#define    ColorPurple        	0x8010
-#define    ColorTeal        	0x410
-#define    ColorLime        	0x7e0
-#define    ColorAqua        	0x7ff
-
-#define	   LCD_X_MAX			240
-#define	   LCD_Y_MAX			320
-
-class LCDTFT: public Stream {
-	public:
-    	 /** Crea LCDTFT interface
-         *
-         * @param RD    
-         * @param WR     
-         * @param RS
-         * @param CS
-         * @param RESET
-         * @param BusLCD (16-bits) 
-         */
-		LCDTFT(PinName PIN_RD,PinName PIN_WR,PinName PIN_RS,PinName PIN_CS,PinName PIN_RESET, BusOut *BUSLCD);
-		/** Inicializa LCD
-		*
-		*/
-		void vLCDTFTInit(void);
-		/** Fija parametros para escritura mediante printf
-		*
-		* @param Xo X inicial
-		* @param Yo Y inicial
-		* @param Xmin X minimo
-		* @param Xmax X maximo
-		* @param Alto Alto de letra (1,2,3..)
-		* @param Color Color de letra 16-bits
-		*/
-		void vLCDTFTSetParametersPrintf(unsigned short Xo,unsigned short Yo,unsigned short Xmin,unsigned short Xmax,unsigned char Alto, unsigned short Color);
-		/** Pinta pantalla completa de color
-		* @param Color Color de 16-bits
-		*/
-		void vLCDTFTFillScreen(unsigned short Color);
-		/** Dibuja punto en pantalla
-		* @param x Posicion x
-		* @param y Posicion y
-		* @param Color Color 16-bits
-		*/
-		void vLCDTFTPoint(unsigned short x,unsigned short y,unsigned short Color);
-		/** Escribe string en LCD
-		* @param x X inicial
-		* @param y Y inicial
-		* @param *PtrText Texto a escribir
-		* @param *Fuente Fuente de letra a escribir (ARIAL)
-		* @param Alto Alto de letra (1,2,3)
-		* @param Color Color de 16-bits
-		*/
-		void vLCDTFTText(unsigned short x,unsigned short y,const char *PtrText,const char (*Fuente)[5],unsigned char Alto,unsigned short Color);
-		
-		void vLCDTFTLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short Color);
-		void vLCDTFTRectangle(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,bool Filled,unsigned short Color);
-		void vLCDTFTCircle(unsigned short x,unsigned short y,unsigned short Radius,bool Filled,unsigned short Color);
-		/** Dibuja imagen ubicada en memoria de mbed (2Mbytes) centrada en patalla
-		* @param NameImagen nombre de imagen (ejm: IMAGEN.BMP)
-		*/		
-		void vDrawImageBMP24Bits(const char *NameImagen);
-	#if DOXYGEN_ONLY
-	    /** Escribe un caracter en LCD
-	     *
-	     * @param c El caracter a escribir en LCD
-	     */
-	    int putc(int c);
-	
-	    /** Escribe un string formateado en LCD
-	     *
-	     * @param format A printf-style format string, followed by the
-	     *               variables to use in formating the string.
-	     */
-	    int printf(const char* format, ...);
-	#endif	    	    
-
-	private:
-		DigitalOut LCD_PIN_RD,LCD_PIN_WR,LCD_PIN_RS,LCD_PIN_CS,LCD_PIN_RESET;	
-		BusOut *LCD_PORT;	
-		unsigned short X,Y,X_min,X_max,_Alto,_Color;
-		// Stream implementation functions
-	    virtual int _putc(int value);
-	    virtual int _getc();
-
-		virtual void vLCDTFTWriteCommand(unsigned short Data);
-		virtual void vLCDTFTWriteData(unsigned short Data);
-		virtual void vLCDTFTWriteCommandData(unsigned short CMD,unsigned short Data);
-		virtual void vLCDTFTAddressSet(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2);
-		virtual void vLCDTFTAddressSetPoint(unsigned short x,unsigned short y);	
-};
-// **************************************************************************************************************************************
+/*
+  @file LCDTFT.h
+  @version: 1.0
+  
+  @web www.micros-designs.com.ar
+  @date 30/01/11
+  
+*- Version Log --------------------------------------------------------------*
+*   Fecha       Autor                Comentarios                             *
+*----------------------------------------------------------------------------*
+* 30/01/11      Suky        Original                                         *
+*----------------------------------------------------------------------------*/ 
+///////////////////////////////////////////////////////////////////////////
+////                                                                   ////
+////                                                                   ////
+////        (C) Copyright 2011 www.micros-designs.com.ar               ////
+//// Este código puede ser usado, modificado y distribuido libremente  ////
+//// sin eliminar esta cabecera y  sin garantía de ningún tipo.        ////
+////                                                                   ////
+////                                                                   ////
+/////////////////////////////////////////////////////////////////////////// 
+
+/** Libreria para LCD TFT chip Himax HX8347-A
+ *
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "LCDTFT.h"
+ * 
+ *BusOut     MyBus(p13,p14,p15,p16,p17,p18,p19,p20,p30,p29,p28,p27,p26,p25,p24,p23);
+ *LCDTFT     MyLCD(p5,p6,p7,p22,p21,&MyBus);
+ *
+ *int main(){
+ *    MyLCD.vLCDTFTInit();
+ *    MyLCD.vLCDTFTFillScreen(ColorWhite);
+ *    MyLCD.printf("Hola mbed!!!");
+ *
+ *    MyLCD.vDrawImageBMP24Bits("IMG0.BMP");
+ *
+ *    while(1){  
+ *    }
+ *}
+ * @endcode
+ */
+
+#include "mbed.h"
+#include "Fuentes.h"
+
+#define    ColorRed                0xf800
+#define    ColorGreen            0x400
+#define    ColorBlue            0x001f
+#define    ColorMarron            0x8208
+#define    ColorBlack            0x0
+#define    ColorWhite            0xffff
+#define    ColorMaroon            0x8000
+#define    ColorFuchsia            0xf81f
+#define    ColorVioleta            0x801f
+#define    ColorAzulMarino        0x14
+#define    ColorGray            0x8410
+#define    ColorOlive            0x8400
+#define    ColorNaranja            0xfc08
+#define    ColorYellow            0xffe0
+#define    ColorCian            0x87ff
+#define    ColorRosado            0xf810
+#define    ColorNavy            0x10
+#define    ColorPurple            0x8010
+#define    ColorTeal            0x410
+#define    ColorLime            0x7e0
+#define    ColorAqua            0x7ff
+
+#define       LCD_X_MAX            240
+#define       LCD_Y_MAX            320
+
+class LCDTFT: public Stream {
+    public:
+         /** Crea LCDTFT interface
+         *
+         * @param RD    
+         * @param WR     
+         * @param RS
+         * @param CS
+         * @param RESET
+         * @param BusLCD (16-bits) 
+         */
+        LCDTFT(PinName PIN_RD,PinName PIN_WR,PinName PIN_RS,PinName PIN_CS,PinName PIN_RESET, BusOut *BUSLCD);
+        /** Inicializa LCD
+        *
+        */
+        void vLCDTFTInit(void);
+        /** Fija parametros para escritura mediante printf
+        *
+        * @param Xo X inicial
+        * @param Yo Y inicial
+        * @param Xmin X minimo
+        * @param Xmax X maximo
+        * @param Alto Alto de letra (1,2,3..)
+        * @param Color Color de letra 16-bits
+        */
+        void vLCDTFTSetParametersPrintf(unsigned short Xo,unsigned short Yo,unsigned short Xmin,unsigned short Xmax,unsigned char Alto, unsigned short Color);
+        /** Pinta pantalla completa de color
+        * @param Color Color de 16-bits
+        */
+        void vLCDTFTFillScreen(unsigned short Color);
+        /** Dibuja punto en pantalla
+        * @param x Posicion x
+        * @param y Posicion y
+        * @param Color Color 16-bits
+        */
+        void vLCDTFTPoint(unsigned short x,unsigned short y,unsigned short Color);
+        /** Escribe string en LCD
+        * @param x X inicial
+        * @param y Y inicial
+        * @param *PtrText Texto a escribir
+        * @param *Fuente Fuente de letra a escribir (ARIAL)
+        * @param Alto Alto de letra (1,2,3)
+        * @param Color Color de 16-bits
+        */
+        void vLCDTFTText(unsigned short x,unsigned short y,const char *PtrText,const char (*Fuente)[5],unsigned char Alto,unsigned short Color);
+        
+        void vLCDTFTLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short Color);
+        void vLCDTFTRectangle(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,bool Filled,unsigned short Color);
+        void vLCDTFTCircle(unsigned short x,unsigned short y,unsigned short Radius,bool Filled,unsigned short Color);
+        /** Dibuja imagen ubicada en memoria de mbed (2Mbytes) centrada en patalla
+        * @param NameImagen nombre de imagen (ejm: IMAGEN.BMP)
+        */        
+        void vDrawImageBMP24Bits(const char *NameImagen);
+        void vLCDTFTDrawImage(unsigned short x,unsigned short y, unsigned short Width, unsigned short Heigh, unsigned int Lenght, const unsigned short *Imagen);
+    #if DOXYGEN_ONLY
+        /** Escribe un caracter en LCD
+         *
+         * @param c El caracter a escribir en LCD
+         */
+        int putc(int c);
+    
+        /** Escribe un string formateado en LCD
+         *
+         * @param format A printf-style format string, followed by the
+         *               variables to use in formating the string.
+         */
+        int printf(const char* format, ...);
+    #endif                
+
+    private:
+        DigitalOut LCD_PIN_RD,LCD_PIN_WR,LCD_PIN_RS,LCD_PIN_CS,LCD_PIN_RESET;    
+        BusOut *LCD_PORT;    
+        unsigned short X,Y,X_min,X_max,_Alto,_Color;
+        // Stream implementation functions
+        virtual int _putc(int value);
+        virtual int _getc();
+
+        virtual void vLCDTFTWriteCommand(unsigned short Data);
+        virtual void vLCDTFTWriteData(unsigned short Data);
+        virtual void vLCDTFTWriteCommandData(unsigned short CMD,unsigned short Data);
+        virtual void vLCDTFTAddressSet(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2);
+        virtual void vLCDTFTAddressSetPoint(unsigned short x,unsigned short y);    
+};
+// **************************************************************************************************************************************