LCD TFT

Dependents:   Example_Menu_LCD_TFT

Committer:
Suky
Date:
Tue Mar 15 01:47:35 2011 +0000
Revision:
1:1085b6177f6e
Parent:
0:359653f39307

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Suky 1:1085b6177f6e 1 /*
Suky 1:1085b6177f6e 2 @file LCDTFT.cpp
Suky 1:1085b6177f6e 3 @version: 1.0
Suky 1:1085b6177f6e 4
Suky 1:1085b6177f6e 5 @web www.micros-designs.com.ar
Suky 1:1085b6177f6e 6 @date 30/01/11
Suky 1:1085b6177f6e 7
Suky 1:1085b6177f6e 8 *- Version Log --------------------------------------------------------------*
Suky 1:1085b6177f6e 9 * Fecha Autor Comentarios *
Suky 1:1085b6177f6e 10 *----------------------------------------------------------------------------*
Suky 1:1085b6177f6e 11 * 30/01/11 Suky Original *
Suky 1:1085b6177f6e 12 *----------------------------------------------------------------------------*/
Suky 1:1085b6177f6e 13 ///////////////////////////////////////////////////////////////////////////
Suky 1:1085b6177f6e 14 //// ////
Suky 1:1085b6177f6e 15 //// ////
Suky 1:1085b6177f6e 16 //// (C) Copyright 2011 www.micros-designs.com.ar ////
Suky 1:1085b6177f6e 17 //// Este código puede ser usado, modificado y distribuido libremente ////
Suky 1:1085b6177f6e 18 //// sin eliminar esta cabecera y sin garantía de ningún tipo. ////
Suky 1:1085b6177f6e 19 //// ////
Suky 1:1085b6177f6e 20 //// ////
Suky 1:1085b6177f6e 21 ///////////////////////////////////////////////////////////////////////////
Suky 1:1085b6177f6e 22 #include "LCDTFT.h"
Suky 1:1085b6177f6e 23
Suky 1:1085b6177f6e 24 LCDTFT::LCDTFT(PinName PIN_RD,PinName PIN_WR,PinName PIN_RS,PinName PIN_CS,PinName PIN_RESET, BusOut *BUSLCD)
Suky 1:1085b6177f6e 25 : 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){
Suky 1:1085b6177f6e 26 LCD_PORT=BUSLCD;
Suky 1:1085b6177f6e 27 X=0;
Suky 1:1085b6177f6e 28 Y=0;
Suky 1:1085b6177f6e 29 X_min=0;
Suky 1:1085b6177f6e 30 X_max=LCD_X_MAX;
Suky 1:1085b6177f6e 31 _Alto=1;
Suky 1:1085b6177f6e 32 _Color=0x0000;
Suky 1:1085b6177f6e 33 }
Suky 1:1085b6177f6e 34
Suky 1:1085b6177f6e 35 void LCDTFT::vLCDTFTSetParametersPrintf(unsigned short Xo,unsigned short Yo,unsigned short Xmin,unsigned short Xmax,unsigned char Alto, unsigned short Color){
Suky 1:1085b6177f6e 36
Suky 1:1085b6177f6e 37 X=Xo;
Suky 1:1085b6177f6e 38 Y=Yo;
Suky 1:1085b6177f6e 39 X_min=Xmin;
Suky 1:1085b6177f6e 40 X_max=Xmax;
Suky 1:1085b6177f6e 41 _Alto=Alto;
Suky 1:1085b6177f6e 42 _Color=Color;
Suky 1:1085b6177f6e 43 }
Suky 1:1085b6177f6e 44
Suky 1:1085b6177f6e 45 int LCDTFT::_putc(int value){
Suky 1:1085b6177f6e 46 char Fmt[2]={value,0};
Suky 1:1085b6177f6e 47
Suky 1:1085b6177f6e 48 if(value=='\n'){
Suky 1:1085b6177f6e 49 X=X_min;
Suky 1:1085b6177f6e 50 Y+=7*_Alto + 1;
Suky 1:1085b6177f6e 51 }else{
Suky 1:1085b6177f6e 52 vLCDTFTText(X,Y,(const char *)&Fmt[0],&ARIAL[0],_Alto,_Color);
Suky 1:1085b6177f6e 53 X+=5*_Alto+1;
Suky 1:1085b6177f6e 54 if(X >= X_max){
Suky 1:1085b6177f6e 55 X = X_min;
Suky 1:1085b6177f6e 56 Y += 7*_Alto + 1;
Suky 1:1085b6177f6e 57 }
Suky 1:1085b6177f6e 58 }
Suky 1:1085b6177f6e 59 return(value);
Suky 1:1085b6177f6e 60 }
Suky 1:1085b6177f6e 61
Suky 1:1085b6177f6e 62 int LCDTFT::_getc(){
Suky 1:1085b6177f6e 63 return(-1);
Suky 1:1085b6177f6e 64 }
Suky 1:1085b6177f6e 65
Suky 1:1085b6177f6e 66 void LCDTFT::vLCDTFTWriteCommand(unsigned short Data){
Suky 1:1085b6177f6e 67
Suky 1:1085b6177f6e 68 LCD_PIN_RS=0;
Suky 1:1085b6177f6e 69 LCD_PIN_CS=0;
Suky 1:1085b6177f6e 70 LCD_PORT->write(Data);
Suky 1:1085b6177f6e 71 LCD_PIN_WR=0;
Suky 1:1085b6177f6e 72 LCD_PIN_WR=1;
Suky 1:1085b6177f6e 73 LCD_PIN_CS=1;
Suky 1:1085b6177f6e 74 }
Suky 1:1085b6177f6e 75
Suky 1:1085b6177f6e 76 void LCDTFT::vLCDTFTWriteData(unsigned short Data){
Suky 1:1085b6177f6e 77 LCD_PIN_RS=1;
Suky 1:1085b6177f6e 78 LCD_PIN_CS=0;
Suky 1:1085b6177f6e 79 LCD_PORT->write(Data);
Suky 1:1085b6177f6e 80 LCD_PIN_WR=0;
Suky 1:1085b6177f6e 81 LCD_PIN_WR=1;
Suky 1:1085b6177f6e 82 LCD_PIN_CS =1;
Suky 1:1085b6177f6e 83 }
Suky 1:1085b6177f6e 84
Suky 1:1085b6177f6e 85
Suky 1:1085b6177f6e 86 void LCDTFT::vLCDTFTWriteCommandData(unsigned short CMD,unsigned short Data){
Suky 1:1085b6177f6e 87 vLCDTFTWriteCommand(CMD);
Suky 1:1085b6177f6e 88 vLCDTFTWriteData(Data);
Suky 1:1085b6177f6e 89 }
Suky 1:1085b6177f6e 90
Suky 1:1085b6177f6e 91 void LCDTFT::vLCDTFTAddressSet(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2){
Suky 1:1085b6177f6e 92
Suky 1:1085b6177f6e 93 vLCDTFTWriteCommandData(0x0044,(x2<<8)+x1);
Suky 1:1085b6177f6e 94 vLCDTFTWriteCommandData(0x0045,y1);
Suky 1:1085b6177f6e 95 vLCDTFTWriteCommandData(0x0046,y2);
Suky 1:1085b6177f6e 96 vLCDTFTWriteCommandData(0x004e,x1);
Suky 1:1085b6177f6e 97 vLCDTFTWriteCommandData(0x004f,y1);
Suky 1:1085b6177f6e 98 vLCDTFTWriteCommand(0x0022);
Suky 1:1085b6177f6e 99 }
Suky 1:1085b6177f6e 100
Suky 1:1085b6177f6e 101 void LCDTFT::vLCDTFTAddressSetPoint(unsigned short x,unsigned short y){
Suky 1:1085b6177f6e 102
Suky 1:1085b6177f6e 103 vLCDTFTWriteCommandData(0x004e,x);
Suky 1:1085b6177f6e 104 vLCDTFTWriteCommandData(0x004f,y);
Suky 1:1085b6177f6e 105 vLCDTFTWriteCommand(0x0022);
Suky 1:1085b6177f6e 106 }
Suky 1:1085b6177f6e 107
Suky 1:1085b6177f6e 108 void LCDTFT::vLCDTFTInit(void){
Suky 1:1085b6177f6e 109
Suky 1:1085b6177f6e 110 LCD_PIN_RESET=1;
Suky 1:1085b6177f6e 111 wait_ms(5);
Suky 1:1085b6177f6e 112 LCD_PIN_RESET=0;
Suky 1:1085b6177f6e 113 wait_ms(10);
Suky 1:1085b6177f6e 114 LCD_PIN_RESET=1;
Suky 1:1085b6177f6e 115 LCD_PIN_CS=1;
Suky 1:1085b6177f6e 116 LCD_PIN_RD=1;
Suky 1:1085b6177f6e 117 LCD_PIN_WR=1;
Suky 1:1085b6177f6e 118 wait_ms(20);
Suky 1:1085b6177f6e 119
Suky 1:1085b6177f6e 120 vLCDTFTWriteCommandData(0x0000,0x0001); wait_ms(1);
Suky 1:1085b6177f6e 121 vLCDTFTWriteCommandData(0x0003,0xA8A4); wait_ms(1);
Suky 1:1085b6177f6e 122 vLCDTFTWriteCommandData(0x000C,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 123 vLCDTFTWriteCommandData(0x000D,0x080C); wait_ms(1);
Suky 1:1085b6177f6e 124 vLCDTFTWriteCommandData(0x000E,0x2B00); wait_ms(1);
Suky 1:1085b6177f6e 125 vLCDTFTWriteCommandData(0x001E,0x00B0); wait_ms(1);
Suky 1:1085b6177f6e 126 vLCDTFTWriteCommandData(0x0001,0x2B3F); wait_ms(1);
Suky 1:1085b6177f6e 127 vLCDTFTWriteCommandData(0x0002,0x0600); wait_ms(1);
Suky 1:1085b6177f6e 128 vLCDTFTWriteCommandData(0x0010,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 129 vLCDTFTWriteCommandData(0x0011,0x6070); wait_ms(1);
Suky 1:1085b6177f6e 130 vLCDTFTWriteCommandData(0x0005,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 131 vLCDTFTWriteCommandData(0x0006,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 132 vLCDTFTWriteCommandData(0x0016,0xEF1C); wait_ms(1);
Suky 1:1085b6177f6e 133 vLCDTFTWriteCommandData(0x0017,0x0003); wait_ms(1);
Suky 1:1085b6177f6e 134 vLCDTFTWriteCommandData(0x0007,0x0233); wait_ms(1);
Suky 1:1085b6177f6e 135 vLCDTFTWriteCommandData(0x000B,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 136 vLCDTFTWriteCommandData(0x000F,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 137 vLCDTFTWriteCommandData(0x0041,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 138 vLCDTFTWriteCommandData(0x0042,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 139 vLCDTFTWriteCommandData(0x0048,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 140 vLCDTFTWriteCommandData(0x0049,0x013F); wait_ms(1);
Suky 1:1085b6177f6e 141 vLCDTFTWriteCommandData(0x004A,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 142 vLCDTFTWriteCommandData(0x004B,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 143 vLCDTFTWriteCommandData(0x0044,0xEF00); wait_ms(1);
Suky 1:1085b6177f6e 144 vLCDTFTWriteCommandData(0x0045,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 145 vLCDTFTWriteCommandData(0x0046,0x013F); wait_ms(1);
Suky 1:1085b6177f6e 146 vLCDTFTWriteCommandData(0x0030,0x0707); wait_ms(1);
Suky 1:1085b6177f6e 147 vLCDTFTWriteCommandData(0x0031,0x0204); wait_ms(1);
Suky 1:1085b6177f6e 148 vLCDTFTWriteCommandData(0x0032,0x0204); wait_ms(1);
Suky 1:1085b6177f6e 149 vLCDTFTWriteCommandData(0x0033,0x0502); wait_ms(1);
Suky 1:1085b6177f6e 150 vLCDTFTWriteCommandData(0x0034,0x0507); wait_ms(1);
Suky 1:1085b6177f6e 151 vLCDTFTWriteCommandData(0x0035,0x0204); wait_ms(1);
Suky 1:1085b6177f6e 152 vLCDTFTWriteCommandData(0x0036,0x0204); wait_ms(1);
Suky 1:1085b6177f6e 153 vLCDTFTWriteCommandData(0x0037,0x0502); wait_ms(1);
Suky 1:1085b6177f6e 154 vLCDTFTWriteCommandData(0x003A,0x0302); wait_ms(1);
Suky 1:1085b6177f6e 155 vLCDTFTWriteCommandData(0x003B,0x0302); wait_ms(1);
Suky 1:1085b6177f6e 156 vLCDTFTWriteCommandData(0x0023,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 157 vLCDTFTWriteCommandData(0x0024,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 158 vLCDTFTWriteCommandData(0x0025,0x8000); wait_ms(1);
Suky 1:1085b6177f6e 159 vLCDTFTWriteCommandData(0x004f,0);
Suky 1:1085b6177f6e 160 vLCDTFTWriteCommandData(0x004e,0);
Suky 1:1085b6177f6e 161 vLCDTFTWriteCommand(0x0022);
Suky 1:1085b6177f6e 162 }
Suky 1:1085b6177f6e 163
Suky 1:1085b6177f6e 164 void LCDTFT::vLCDTFTFillScreen(unsigned short Color){
Suky 1:1085b6177f6e 165 unsigned short i,j;
Suky 1:1085b6177f6e 166 vLCDTFTAddressSet(0,0,239,319);
Suky 1:1085b6177f6e 167
Suky 1:1085b6177f6e 168 for(i=0;i<320;i++){
Suky 1:1085b6177f6e 169 for (j=0;j<240;j++){
Suky 1:1085b6177f6e 170 vLCDTFTWriteData(Color);
Suky 1:1085b6177f6e 171 }
Suky 1:1085b6177f6e 172 }
Suky 1:1085b6177f6e 173 }
Suky 1:1085b6177f6e 174
Suky 1:1085b6177f6e 175 void LCDTFT::vLCDTFTPoint(unsigned short x,unsigned short y,unsigned short Color){
Suky 1:1085b6177f6e 176
Suky 1:1085b6177f6e 177 vLCDTFTAddressSetPoint(x,y);
Suky 1:1085b6177f6e 178 vLCDTFTWriteData(Color);
Suky 1:1085b6177f6e 179 }
Suky 1:1085b6177f6e 180
Suky 1:1085b6177f6e 181 void LCDTFT::vLCDTFTText(unsigned short x,unsigned short y,const char *PtrText,const char (*Fuente)[5],unsigned char Alto,unsigned short Color){
Suky 1:1085b6177f6e 182 unsigned short i, j, k, l, m, temp;
Suky 1:1085b6177f6e 183 char DataPunto[5];
Suky 1:1085b6177f6e 184 const char *Ptr;
Suky 1:1085b6177f6e 185
Suky 1:1085b6177f6e 186 while(*PtrText!='\0'){
Suky 1:1085b6177f6e 187 Ptr=(Fuente+*PtrText-' ')[0];
Suky 1:1085b6177f6e 188 for(i=0;i<5;i++){DataPunto[i]=*Ptr++;}
Suky 1:1085b6177f6e 189 switch(*PtrText){
Suky 1:1085b6177f6e 190 case '\n':
Suky 1:1085b6177f6e 191 y += 7*Alto + 1;
Suky 1:1085b6177f6e 192 break;
Suky 1:1085b6177f6e 193 case '\r':
Suky 1:1085b6177f6e 194 x = 0;
Suky 1:1085b6177f6e 195 break;
Suky 1:1085b6177f6e 196 default:
Suky 1:1085b6177f6e 197 if(x+5*Alto >= LCD_X_MAX){
Suky 1:1085b6177f6e 198 x = 0;
Suky 1:1085b6177f6e 199 y += 7*Alto + 1;
Suky 1:1085b6177f6e 200 }
Suky 1:1085b6177f6e 201 for(j=0; j<5; ++j, x+=Alto){
Suky 1:1085b6177f6e 202 for(k=0; k < 7; k++){
Suky 1:1085b6177f6e 203 temp=(0x01<<k);
Suky 1:1085b6177f6e 204 if((DataPunto[j]&temp)==temp){
Suky 1:1085b6177f6e 205 for(l=0; l < Alto; ++l){
Suky 1:1085b6177f6e 206 for(m=0; m < Alto; ++m){
Suky 1:1085b6177f6e 207 vLCDTFTPoint(x+m,y+k*Alto+l,Color);
Suky 1:1085b6177f6e 208 }
Suky 1:1085b6177f6e 209 }
Suky 1:1085b6177f6e 210 }
Suky 1:1085b6177f6e 211 }
Suky 1:1085b6177f6e 212 }
Suky 1:1085b6177f6e 213 x++;
Suky 1:1085b6177f6e 214 break;
Suky 1:1085b6177f6e 215 }
Suky 1:1085b6177f6e 216 *PtrText++;
Suky 1:1085b6177f6e 217 }
Suky 1:1085b6177f6e 218 }
Suky 1:1085b6177f6e 219
Suky 1:1085b6177f6e 220 void LCDTFT::vLCDTFTLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short Color){
Suky 1:1085b6177f6e 221
Suky 1:1085b6177f6e 222 unsigned short dy, dx;
Suky 1:1085b6177f6e 223 short addx=1, addy=1;
Suky 1:1085b6177f6e 224 short P, diff;
Suky 1:1085b6177f6e 225 unsigned short i=0;
Suky 1:1085b6177f6e 226
Suky 1:1085b6177f6e 227 diff=((short)x2-x1);
Suky 1:1085b6177f6e 228 if(diff<0) diff*=-1;
Suky 1:1085b6177f6e 229 dx=diff;
Suky 1:1085b6177f6e 230 diff=((short)y2-y1);
Suky 1:1085b6177f6e 231 if(diff<0) diff*=-1;
Suky 1:1085b6177f6e 232 dy=diff;
Suky 1:1085b6177f6e 233
Suky 1:1085b6177f6e 234
Suky 1:1085b6177f6e 235 if(x1 > x2)addx = -1;
Suky 1:1085b6177f6e 236 if(y1 > y2)addy = -1;
Suky 1:1085b6177f6e 237 if(dx >= dy){
Suky 1:1085b6177f6e 238 dy *= 2;
Suky 1:1085b6177f6e 239 P = dy - dx;
Suky 1:1085b6177f6e 240 diff = P - dx;
Suky 1:1085b6177f6e 241 for(;i<=dx;++i){
Suky 1:1085b6177f6e 242 vLCDTFTPoint(x1, y1, Color);
Suky 1:1085b6177f6e 243 if(P < 0){
Suky 1:1085b6177f6e 244 P += dy;
Suky 1:1085b6177f6e 245 x1 += addx;
Suky 1:1085b6177f6e 246 }else{
Suky 1:1085b6177f6e 247 P += diff;
Suky 1:1085b6177f6e 248 x1 += addx;
Suky 1:1085b6177f6e 249 y1 += addy;
Suky 1:1085b6177f6e 250 }
Suky 1:1085b6177f6e 251 }
Suky 1:1085b6177f6e 252 }else{
Suky 1:1085b6177f6e 253 dx *= 2;
Suky 1:1085b6177f6e 254 P = dx - dy;
Suky 1:1085b6177f6e 255 diff = P - dy;
Suky 1:1085b6177f6e 256 for(; i<=dy; ++i){
Suky 1:1085b6177f6e 257 vLCDTFTPoint(x1, y1, Color);
Suky 1:1085b6177f6e 258 if(P < 0){
Suky 1:1085b6177f6e 259 P += dx;
Suky 1:1085b6177f6e 260 y1 += addy;
Suky 1:1085b6177f6e 261 }else{
Suky 1:1085b6177f6e 262 P += diff;
Suky 1:1085b6177f6e 263 x1 += addx;
Suky 1:1085b6177f6e 264 y1 += addy;
Suky 1:1085b6177f6e 265 }
Suky 1:1085b6177f6e 266 }
Suky 1:1085b6177f6e 267 }
Suky 1:1085b6177f6e 268 }
Suky 1:1085b6177f6e 269
Suky 1:1085b6177f6e 270
Suky 1:1085b6177f6e 271 void LCDTFT::vLCDTFTRectangle(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,bool Filled,unsigned short Color){
Suky 1:1085b6177f6e 272
Suky 1:1085b6177f6e 273 if(Filled){
Suky 1:1085b6177f6e 274 int Lenght=((int)(x2-x1+1)*(y2-y1+1));
Suky 1:1085b6177f6e 275
Suky 1:1085b6177f6e 276 vLCDTFTAddressSet(x1,y1,x2,y2);
Suky 1:1085b6177f6e 277 for(int i=0;i<Lenght;i++){
Suky 1:1085b6177f6e 278 vLCDTFTWriteData(Color);
Suky 1:1085b6177f6e 279 }
Suky 1:1085b6177f6e 280 }else{
Suky 1:1085b6177f6e 281 vLCDTFTLine(x1, y1, x2, y1, Color);
Suky 1:1085b6177f6e 282 vLCDTFTLine(x1, y2, x2, y2, Color);
Suky 1:1085b6177f6e 283 vLCDTFTLine(x1, y1, x1, y2, Color);
Suky 1:1085b6177f6e 284 vLCDTFTLine(x2, y1, x2, y2, Color);
Suky 1:1085b6177f6e 285 }
Suky 1:1085b6177f6e 286 }
Suky 1:1085b6177f6e 287
Suky 1:1085b6177f6e 288
Suky 1:1085b6177f6e 289 void LCDTFT::vLCDTFTCircle(unsigned short x,unsigned short y,unsigned short Radius,bool Filled,unsigned short Color){
Suky 1:1085b6177f6e 290 short a, b, P;
Suky 1:1085b6177f6e 291
Suky 1:1085b6177f6e 292 a = 0;
Suky 1:1085b6177f6e 293 b = Radius;
Suky 1:1085b6177f6e 294 P = 1 - Radius;
Suky 1:1085b6177f6e 295
Suky 1:1085b6177f6e 296 do{
Suky 1:1085b6177f6e 297 if(Filled){
Suky 1:1085b6177f6e 298 vLCDTFTLine(x-a, y+b, x+a, y+b, Color);
Suky 1:1085b6177f6e 299 vLCDTFTLine(x-a, y-b, x+a, y-b, Color);
Suky 1:1085b6177f6e 300 vLCDTFTLine(x-b, y+a, x+b, y+a, Color);
Suky 1:1085b6177f6e 301 vLCDTFTLine(x-b, y-a, x+b, y-a, Color);
Suky 1:1085b6177f6e 302 }else{
Suky 1:1085b6177f6e 303 vLCDTFTPoint(a+x, b+y, Color);
Suky 1:1085b6177f6e 304 vLCDTFTPoint(b+x, a+y, Color);
Suky 1:1085b6177f6e 305 vLCDTFTPoint(x-a, b+y, Color);
Suky 1:1085b6177f6e 306 vLCDTFTPoint(x-b, a+y, Color);
Suky 1:1085b6177f6e 307 vLCDTFTPoint(b+x, y-a, Color);
Suky 1:1085b6177f6e 308 vLCDTFTPoint(a+x, y-b, Color);
Suky 1:1085b6177f6e 309 vLCDTFTPoint(x-a, y-b, Color);
Suky 1:1085b6177f6e 310 vLCDTFTPoint(x-b, y-a, Color);
Suky 1:1085b6177f6e 311 }
Suky 1:1085b6177f6e 312 if(P < 0) P += 3 + 2 * a++;
Suky 1:1085b6177f6e 313 else P += 5 + 2 * (a++ - b--);
Suky 1:1085b6177f6e 314 }while(a <= b);
Suky 1:1085b6177f6e 315 }
Suky 1:1085b6177f6e 316
Suky 1:1085b6177f6e 317 void LCDTFT::vDrawImageBMP24Bits(const char *NameImagen){
Suky 1:1085b6177f6e 318
Suky 1:1085b6177f6e 319 #define OffsetWidthPixel 18
Suky 1:1085b6177f6e 320 #define OffsetHeighPixel 22
Suky 1:1085b6177f6e 321 #define OffsetSizeFile 34
Suky 1:1085b6177f6e 322 #define OffsetInitData 10
Suky 1:1085b6177f6e 323 #define OffserTipeFile 28
Suky 1:1085b6177f6e 324 char Nombre[80],k;
Suky 1:1085b6177f6e 325 unsigned short PosXImagen,PosYImagen;
Suky 1:1085b6177f6e 326 unsigned char Temp,BufferHeader[54],BufferTemp[3],Adicional;
Suky 1:1085b6177f6e 327 unsigned int WidthPixel,HeighPixel;
Suky 1:1085b6177f6e 328 unsigned short TipeFile,InitData,Temp16bits;
Suky 1:1085b6177f6e 329 union{
Suky 1:1085b6177f6e 330 unsigned short Val;
Suky 1:1085b6177f6e 331 struct{
Suky 1:1085b6177f6e 332 unsigned Blue:5;
Suky 1:1085b6177f6e 333 unsigned Green:6;
Suky 1:1085b6177f6e 334 unsigned Red:5;
Suky 1:1085b6177f6e 335 };
Suky 1:1085b6177f6e 336 }Color;
Suky 1:1085b6177f6e 337
Suky 1:1085b6177f6e 338 LocalFileSystem local("mbedMemory");
Suky 1:1085b6177f6e 339 sprintf(&Nombre[0],"/mbedMemory/");
Suky 1:1085b6177f6e 340 k=12;
Suky 1:1085b6177f6e 341 while(*NameImagen!='\0'){
Suky 1:1085b6177f6e 342 Nombre[k++]=*NameImagen++;
Suky 1:1085b6177f6e 343 }
Suky 1:1085b6177f6e 344
Suky 1:1085b6177f6e 345 FILE *Imagen = fopen((const char *)&Nombre[0], "r"); // Abrimos archivo para lectura.
Suky 1:1085b6177f6e 346 // Si no se pudo encontrar archivo:
Suky 1:1085b6177f6e 347 if(!Imagen) {
Suky 1:1085b6177f6e 348 vLCDTFTFillScreen(ColorBlack);
Suky 1:1085b6177f6e 349 return;
Suky 1:1085b6177f6e 350 }
Suky 1:1085b6177f6e 351 // Leemos cabecera de archivo
Suky 1:1085b6177f6e 352 fread(&BufferHeader[0],1,54,Imagen);
Suky 1:1085b6177f6e 353
Suky 1:1085b6177f6e 354 WidthPixel = ((unsigned int)BufferHeader[OffsetWidthPixel + 3]*16777216+BufferHeader[OffsetWidthPixel + 2]*65536+BufferHeader[OffsetWidthPixel + 1]*256+BufferHeader[OffsetWidthPixel]);
Suky 1:1085b6177f6e 355 HeighPixel = ((unsigned int)BufferHeader[OffsetHeighPixel + 3]*16777216+BufferHeader[OffsetHeighPixel + 2]*65536+BufferHeader[OffsetHeighPixel + 1]*256+BufferHeader[OffsetHeighPixel]);
Suky 1:1085b6177f6e 356 InitData = ((unsigned short)BufferHeader[OffsetInitData]);
Suky 1:1085b6177f6e 357 TipeFile = ((unsigned short)BufferHeader[OffserTipeFile + 1]*256 + BufferHeader[OffserTipeFile]);
Suky 1:1085b6177f6e 358
Suky 1:1085b6177f6e 359 if((WidthPixel>LCD_X_MAX) || (HeighPixel>LCD_Y_MAX) || (TipeFile!=24)){
Suky 1:1085b6177f6e 360 fclose(Imagen);
Suky 1:1085b6177f6e 361 return;
Suky 1:1085b6177f6e 362 }
Suky 1:1085b6177f6e 363
Suky 1:1085b6177f6e 364 if(InitData!=54){
Suky 1:1085b6177f6e 365 for(int k=54;k<InitData;k++){
Suky 1:1085b6177f6e 366 fread(&Temp,1,1,Imagen);
Suky 1:1085b6177f6e 367 }
Suky 1:1085b6177f6e 368 }
Suky 1:1085b6177f6e 369
Suky 1:1085b6177f6e 370 PosXImagen=(LCD_X_MAX/2)-(WidthPixel/2);
Suky 1:1085b6177f6e 371 PosYImagen=(LCD_Y_MAX/2)+(HeighPixel/2);
Suky 1:1085b6177f6e 372
Suky 1:1085b6177f6e 373 Temp16bits=WidthPixel*3;
Suky 1:1085b6177f6e 374 Adicional=0;
Suky 1:1085b6177f6e 375 while(((Temp16bits)%4)!=0){
Suky 1:1085b6177f6e 376 Adicional++;
Suky 1:1085b6177f6e 377 Temp16bits++;
Suky 1:1085b6177f6e 378 }
Suky 1:1085b6177f6e 379
Suky 1:1085b6177f6e 380 for(int k=0,y=PosYImagen;k<HeighPixel;k++,y--){
Suky 1:1085b6177f6e 381 vLCDTFTAddressSet(PosXImagen,y,PosXImagen+WidthPixel-1,y);
Suky 1:1085b6177f6e 382 for(int i=0;i<WidthPixel;i++){
Suky 1:1085b6177f6e 383 fread(&BufferTemp[0],1,3,Imagen); // Leemos 3 bytes (R,G,B)
Suky 1:1085b6177f6e 384 Color.Blue=BufferTemp[0]>>3;Color.Green=BufferTemp[1]>>2;Color.Red=BufferTemp[2]>>3; // Conversion de 24-bits a 16-bits.-
Suky 1:1085b6177f6e 385 vLCDTFTWriteData(Color.Val);
Suky 1:1085b6177f6e 386 }
Suky 1:1085b6177f6e 387 // Bytes adicionales para que linea sea multiplo de 4.-
Suky 1:1085b6177f6e 388 for(int p=0;p<Adicional;p++){
Suky 1:1085b6177f6e 389 fread(&Temp,1,1,Imagen);
Suky 1:1085b6177f6e 390 }
Suky 1:1085b6177f6e 391 }
Suky 1:1085b6177f6e 392 fclose(Imagen);
Suky 1:1085b6177f6e 393 }
Suky 1:1085b6177f6e 394
Suky 1:1085b6177f6e 395 void LCDTFT::vLCDTFTDrawImage(unsigned short x,unsigned short y, unsigned short Width, unsigned short Heigh, unsigned int Lenght, const unsigned short *Imagen){
Suky 1:1085b6177f6e 396
Suky 1:1085b6177f6e 397 vLCDTFTAddressSet(x,y,x+Width-1,y+Heigh-1);
Suky 1:1085b6177f6e 398 for(int i=0;i<Lenght;i++){
Suky 1:1085b6177f6e 399 vLCDTFTWriteData(*Imagen++);
Suky 1:1085b6177f6e 400 }
Suky 0:359653f39307 401 }