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