LCD TFT for ssd0139 driver 8 bit mode - using portout for max speed

Fork of LCDTFT_ssd0139 by chris stevens

Committer:
cstevens
Date:
Tue Sep 02 14:13:31 2014 +0000
Revision:
3:f999653c1069
Parent:
2:ebedda77b33b
Child:
4:1c2f9e3b9b12
modified for ssd0139 driver and 240x320 tftlcd display;

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 ////
cstevens 2:ebedda77b33b 17 //// Este c�digo puede ser usado, modificado y distribuido libremente ////
cstevens 2:ebedda77b33b 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 }
cstevens 2:ebedda77b33b 34 // global variable for screen orientation set by init
cstevens 2:ebedda77b33b 35 bool orient=0;
Suky 1:1085b6177f6e 36
cstevens 2:ebedda77b33b 37 static const unsigned short regValues[] = {
cstevens 2:ebedda77b33b 38 0x0000, 0x0001, // start oscillation
cstevens 2:ebedda77b33b 39 0x00FF, 0x0010, // wait 16 ms
cstevens 2:ebedda77b33b 40 0x0007, 0x0000, //display control - zeros everything ???
cstevens 2:ebedda77b33b 41 0x0013, 0x0000, // power control 3 setting = all zero
cstevens 2:ebedda77b33b 42 0x0011, 0x2604, //power control 2 seting = gvd voltage 0x26 vci1 voltage 0x04
cstevens 2:ebedda77b33b 43 0x0014, 0x0015, // power contrlol 4 setting vcmr=0 vcomh=0 vml=13 = amplitude of vcom voltage
cstevens 2:ebedda77b33b 44 0x0010, 0x3C00, // power control 1 bt3=0 sap=7 (0b111) bt=4 (0b100)
cstevens 2:ebedda77b33b 45 0x0013, 0x0040, //power control 3 PON=1 PON1=0 AON=0
cstevens 2:ebedda77b33b 46 0x00FF,0x0010, // wait 16ms
cstevens 2:ebedda77b33b 47 0x0013, 0x0060, // power control 3 PON=1 PON1=1 AON=0
cstevens 2:ebedda77b33b 48 0x00FF, 0x0032, // wait 50ms
cstevens 2:ebedda77b33b 49 0x0013, 0x0070, //power control 3 PON=1 PON1=1 AON=1
cstevens 2:ebedda77b33b 50 0x00FF, 0x0028, // wait 40ms
cstevens 2:ebedda77b33b 51
cstevens 2:ebedda77b33b 52 0x0001, 0x0127, // driver ouptut control
cstevens 2:ebedda77b33b 53 0x0002, 0x0700, //LCD driving waveform settings
cstevens 2:ebedda77b33b 54 0x0003, 0x1030, // entry mode settingtri=0 dfm=0 bgr=1 id1:id0=11
cstevens 2:ebedda77b33b 55 0x0007, 0x0000, // display control 1 pt1-0=0 vle2-1=0 spt=0 gon=0 rev=0 d1-0=0
cstevens 2:ebedda77b33b 56 0x0008, 0x0404, //black period control fp3-0=4 bp3-0=4
cstevens 2:ebedda77b33b 57 0x000B, 0x0200, //frame cycle setting nd1-0=0 sdt1-0=2 ecs2-0=0 div1-0=0 dcr_ex=0 dcr2-0=0 rtn1-0=0
cstevens 2:ebedda77b33b 58 0x000C, 0x0000, //external interface controlrm=0 dm1-0=0 rim1-0=0
cstevens 2:ebedda77b33b 59 0x00015,0x0000, //sub panel control sub_im1-0=0 stn_en=0 mpu_mode=0 fcv_en=0
cstevens 2:ebedda77b33b 60
cstevens 2:ebedda77b33b 61 //gamma setting
cstevens 2:ebedda77b33b 62 0x0030, 0x0000,
cstevens 2:ebedda77b33b 63 0x0031, 0x0606,
cstevens 2:ebedda77b33b 64 0x0032, 0x0006,
cstevens 2:ebedda77b33b 65 0x0033, 0x0403,
cstevens 2:ebedda77b33b 66 0x0034, 0x0107,
cstevens 2:ebedda77b33b 67 0x0035, 0x0101,
cstevens 2:ebedda77b33b 68 0x0036, 0x0707,
cstevens 2:ebedda77b33b 69 0x0037, 0x0304,
cstevens 2:ebedda77b33b 70 0x0038, 0x0A00,
cstevens 2:ebedda77b33b 71 0x0039, 0x0706,
cstevens 2:ebedda77b33b 72 // end of gamma settings
cstevens 2:ebedda77b33b 73 0x0040, 0x0000, // gate scan position (start g1 scan) scn5-0=0
cstevens 2:ebedda77b33b 74 0x0041, 0x0000, // vertical scroll setting vl8-0=0
cstevens 2:ebedda77b33b 75 0x0042, 0x013F, // screen end position se18-10=0x13F
cstevens 2:ebedda77b33b 76 0x0043, 0x0000, // screen_start position ss28-20=0
cstevens 2:ebedda77b33b 77 0x0044, 0x0000, // 2nd screen driving position end 00
cstevens 2:ebedda77b33b 78 0x0045, 0x0000, //2nd screen driving position start =00
cstevens 2:ebedda77b33b 79 0x0046, 0xEF00, //window addre horizontal ram for x0,x1 HEA=0xEF HSA=00 ie x=0 and x=239
cstevens 2:ebedda77b33b 80 0x0047, 0x013F, //vertical ram address end vea=0x13F ie y=319
cstevens 2:ebedda77b33b 81 0x0048, 0x0000, //vertical ram address start=00 ie y=0
cstevens 2:ebedda77b33b 82 0x0007, 0x0011, //dispaly control 1
cstevens 2:ebedda77b33b 83 0x00FF, 0x0028, //wait 40ms
cstevens 2:ebedda77b33b 84 0x0007, 0x0017, //display control 1
cstevens 2:ebedda77b33b 85
cstevens 2:ebedda77b33b 86 };
cstevens 2:ebedda77b33b 87
cstevens 2:ebedda77b33b 88
cstevens 2:ebedda77b33b 89 void LCDTFT::vLCDTFTSetParametersPrintf(unsigned short Xo,unsigned short Yo,unsigned short Xmin,unsigned short Xmax,unsigned char Alto, unsigned short Color,unsigned short BackColor){
Suky 1:1085b6177f6e 90
Suky 1:1085b6177f6e 91 X=Xo;
Suky 1:1085b6177f6e 92 Y=Yo;
Suky 1:1085b6177f6e 93 X_min=Xmin;
Suky 1:1085b6177f6e 94 X_max=Xmax;
Suky 1:1085b6177f6e 95 _Alto=Alto;
Suky 1:1085b6177f6e 96 _Color=Color;
cstevens 2:ebedda77b33b 97 _Background=BackColor;
Suky 1:1085b6177f6e 98 }
Suky 1:1085b6177f6e 99
Suky 1:1085b6177f6e 100 int LCDTFT::_putc(int value){
Suky 1:1085b6177f6e 101 char Fmt[2]={value,0};
Suky 1:1085b6177f6e 102
Suky 1:1085b6177f6e 103 if(value=='\n'){
Suky 1:1085b6177f6e 104 X=X_min;
cstevens 2:ebedda77b33b 105 Y+=8*_Alto + 1;
Suky 1:1085b6177f6e 106 }else{
cstevens 2:ebedda77b33b 107 vLCDTFTText(X,Y,(const char *)&Fmt[0],&ARIAL[0],_Alto,_Color,_Background);
Suky 1:1085b6177f6e 108 X+=5*_Alto+1;
Suky 1:1085b6177f6e 109 if(X >= X_max){
Suky 1:1085b6177f6e 110 X = X_min;
cstevens 2:ebedda77b33b 111 Y += 8*_Alto + 1;
Suky 1:1085b6177f6e 112 }
Suky 1:1085b6177f6e 113 }
Suky 1:1085b6177f6e 114 return(value);
Suky 1:1085b6177f6e 115 }
Suky 1:1085b6177f6e 116
Suky 1:1085b6177f6e 117 int LCDTFT::_getc(){
Suky 1:1085b6177f6e 118 return(-1);
Suky 1:1085b6177f6e 119 }
Suky 1:1085b6177f6e 120
Suky 1:1085b6177f6e 121 void LCDTFT::vLCDTFTWriteCommand(unsigned short Data){
Suky 1:1085b6177f6e 122
Suky 1:1085b6177f6e 123 LCD_PIN_RS=0;
Suky 1:1085b6177f6e 124 LCD_PIN_CS=0;
cstevens 2:ebedda77b33b 125 LCD_PORT->write(Data>>8); // MSB so with an 8 bit port we need to write here the high and ,low bytes successively
Suky 1:1085b6177f6e 126 LCD_PIN_WR=0;
Suky 1:1085b6177f6e 127 LCD_PIN_WR=1;
cstevens 2:ebedda77b33b 128 LCD_PORT->write(Data & 0x00FF); // LSB
cstevens 2:ebedda77b33b 129 LCD_PIN_WR=0;
cstevens 2:ebedda77b33b 130 LCD_PIN_WR=1;
cstevens 2:ebedda77b33b 131
Suky 1:1085b6177f6e 132 LCD_PIN_CS=1;
Suky 1:1085b6177f6e 133 }
Suky 1:1085b6177f6e 134
Suky 1:1085b6177f6e 135 void LCDTFT::vLCDTFTWriteData(unsigned short Data){
Suky 1:1085b6177f6e 136 LCD_PIN_RS=1;
Suky 1:1085b6177f6e 137 LCD_PIN_CS=0;
cstevens 2:ebedda77b33b 138 LCD_PORT->write(Data>>8); // MSB so with an 8 bit port we need to write here the high and ,low bytes successively
cstevens 2:ebedda77b33b 139 LCD_PIN_WR=0;
cstevens 2:ebedda77b33b 140 LCD_PIN_WR=1;
cstevens 2:ebedda77b33b 141 LCD_PORT->write(Data & 0x00FF); // LSB
Suky 1:1085b6177f6e 142 LCD_PIN_WR=0;
Suky 1:1085b6177f6e 143 LCD_PIN_WR=1;
Suky 1:1085b6177f6e 144 LCD_PIN_CS =1;
Suky 1:1085b6177f6e 145 }
Suky 1:1085b6177f6e 146
Suky 1:1085b6177f6e 147
Suky 1:1085b6177f6e 148 void LCDTFT::vLCDTFTWriteCommandData(unsigned short CMD,unsigned short Data){
Suky 1:1085b6177f6e 149 vLCDTFTWriteCommand(CMD);
Suky 1:1085b6177f6e 150 vLCDTFTWriteData(Data);
Suky 1:1085b6177f6e 151 }
Suky 1:1085b6177f6e 152
Suky 1:1085b6177f6e 153 void LCDTFT::vLCDTFTAddressSet(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2){
Suky 1:1085b6177f6e 154
Suky 1:1085b6177f6e 155 vLCDTFTWriteCommandData(0x0044,(x2<<8)+x1);
Suky 1:1085b6177f6e 156 vLCDTFTWriteCommandData(0x0045,y1);
Suky 1:1085b6177f6e 157 vLCDTFTWriteCommandData(0x0046,y2);
Suky 1:1085b6177f6e 158 vLCDTFTWriteCommandData(0x004e,x1);
Suky 1:1085b6177f6e 159 vLCDTFTWriteCommandData(0x004f,y1);
Suky 1:1085b6177f6e 160 vLCDTFTWriteCommand(0x0022);
Suky 1:1085b6177f6e 161 }
Suky 1:1085b6177f6e 162
Suky 1:1085b6177f6e 163 void LCDTFT::vLCDTFTAddressSetPoint(unsigned short x,unsigned short y){
Suky 1:1085b6177f6e 164
cstevens 2:ebedda77b33b 165 // CGRAM addresses are given by (x+y*256) - for some reason the y cordinate
cstevens 2:ebedda77b33b 166 // addresses require 17 bits
cstevens 2:ebedda77b33b 167 // equiv if y is given by 0xYYY and x by 0xXX
cstevens 2:ebedda77b33b 168 // then address of point x,y is 0xYYYXXX
cstevens 2:ebedda77b33b 169 int add;
cstevens 2:ebedda77b33b 170 int adl,adh;
cstevens 2:ebedda77b33b 171 if(orient==0){ // portrait
cstevens 2:ebedda77b33b 172 add=x+y*256; //240 x 320 y but 256 bytes for each x row
cstevens 2:ebedda77b33b 173
cstevens 2:ebedda77b33b 174 }
cstevens 2:ebedda77b33b 175 else{
cstevens 2:ebedda77b33b 176 add=(239-y)+x*256;
cstevens 2:ebedda77b33b 177 }
cstevens 2:ebedda77b33b 178 adl=add & 0x00FF; // selects the 8 low bits
cstevens 2:ebedda77b33b 179 adh=(add >>8); // the 9 high bits
cstevens 2:ebedda77b33b 180 vLCDTFTWriteCommandData(0x0020,adl); // 8 lsb of address
cstevens 2:ebedda77b33b 181 vLCDTFTWriteCommandData(0x0021,adh); //9 msb of address
cstevens 2:ebedda77b33b 182 vLCDTFTWriteCommand(0x0022); // prepare to send rgb data
Suky 1:1085b6177f6e 183 }
Suky 1:1085b6177f6e 184
cstevens 2:ebedda77b33b 185 void LCDTFT::vLCDTFTInit(bool format){
Suky 1:1085b6177f6e 186
cstevens 2:ebedda77b33b 187 int i;
cstevens 2:ebedda77b33b 188 unsigned short address,data;
cstevens 2:ebedda77b33b 189 orient=format;
Suky 1:1085b6177f6e 190 LCD_PIN_RESET=1;
cstevens 2:ebedda77b33b 191 wait_ms(5); // must hold for at least 1ms after reset
Suky 1:1085b6177f6e 192 LCD_PIN_RESET=0;
cstevens 2:ebedda77b33b 193 wait_ms(10); // wait for stable R-C oscillation
Suky 1:1085b6177f6e 194 LCD_PIN_RESET=1;
cstevens 2:ebedda77b33b 195 wait_ms(5); // final wait for rest to be acitvated
Suky 1:1085b6177f6e 196 LCD_PIN_CS=1;
Suky 1:1085b6177f6e 197 LCD_PIN_RD=1;
Suky 1:1085b6177f6e 198 LCD_PIN_WR=1;
Suky 1:1085b6177f6e 199 wait_ms(20);
cstevens 2:ebedda77b33b 200
cstevens 2:ebedda77b33b 201 for(i=0;i<sizeof(regValues)/4;i++)
cstevens 2:ebedda77b33b 202 {
cstevens 2:ebedda77b33b 203 address=regValues[i*2];
cstevens 2:ebedda77b33b 204 data=regValues[i*2+1];
cstevens 2:ebedda77b33b 205
cstevens 2:ebedda77b33b 206 if(address==0xFF)
cstevens 2:ebedda77b33b 207 {
cstevens 2:ebedda77b33b 208 wait_ms(data);
cstevens 2:ebedda77b33b 209 }
cstevens 2:ebedda77b33b 210 else {
cstevens 2:ebedda77b33b 211 vLCDTFTWriteCommandData(address,data);
cstevens 2:ebedda77b33b 212 }
cstevens 2:ebedda77b33b 213 }
cstevens 2:ebedda77b33b 214 wait_ms(1);
cstevens 2:ebedda77b33b 215
Suky 1:1085b6177f6e 216
cstevens 2:ebedda77b33b 217 /*
Suky 1:1085b6177f6e 218 vLCDTFTWriteCommandData(0x0000,0x0001); wait_ms(1);
Suky 1:1085b6177f6e 219 vLCDTFTWriteCommandData(0x0003,0xA8A4); wait_ms(1);
Suky 1:1085b6177f6e 220 vLCDTFTWriteCommandData(0x000C,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 221 vLCDTFTWriteCommandData(0x000D,0x080C); wait_ms(1);
Suky 1:1085b6177f6e 222 vLCDTFTWriteCommandData(0x000E,0x2B00); wait_ms(1);
Suky 1:1085b6177f6e 223 vLCDTFTWriteCommandData(0x001E,0x00B0); wait_ms(1);
Suky 1:1085b6177f6e 224 vLCDTFTWriteCommandData(0x0001,0x2B3F); wait_ms(1);
Suky 1:1085b6177f6e 225 vLCDTFTWriteCommandData(0x0002,0x0600); wait_ms(1);
Suky 1:1085b6177f6e 226 vLCDTFTWriteCommandData(0x0010,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 227 vLCDTFTWriteCommandData(0x0011,0x6070); wait_ms(1);
Suky 1:1085b6177f6e 228 vLCDTFTWriteCommandData(0x0005,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 229 vLCDTFTWriteCommandData(0x0006,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 230 vLCDTFTWriteCommandData(0x0016,0xEF1C); wait_ms(1);
Suky 1:1085b6177f6e 231 vLCDTFTWriteCommandData(0x0017,0x0003); wait_ms(1);
Suky 1:1085b6177f6e 232 vLCDTFTWriteCommandData(0x0007,0x0233); wait_ms(1);
Suky 1:1085b6177f6e 233 vLCDTFTWriteCommandData(0x000B,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 234 vLCDTFTWriteCommandData(0x000F,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 235 vLCDTFTWriteCommandData(0x0041,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 236 vLCDTFTWriteCommandData(0x0042,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 237 vLCDTFTWriteCommandData(0x0048,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 238 vLCDTFTWriteCommandData(0x0049,0x013F); wait_ms(1);
Suky 1:1085b6177f6e 239 vLCDTFTWriteCommandData(0x004A,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 240 vLCDTFTWriteCommandData(0x004B,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 241 vLCDTFTWriteCommandData(0x0044,0xEF00); wait_ms(1);
Suky 1:1085b6177f6e 242 vLCDTFTWriteCommandData(0x0045,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 243 vLCDTFTWriteCommandData(0x0046,0x013F); wait_ms(1);
Suky 1:1085b6177f6e 244 vLCDTFTWriteCommandData(0x0030,0x0707); wait_ms(1);
Suky 1:1085b6177f6e 245 vLCDTFTWriteCommandData(0x0031,0x0204); wait_ms(1);
Suky 1:1085b6177f6e 246 vLCDTFTWriteCommandData(0x0032,0x0204); wait_ms(1);
Suky 1:1085b6177f6e 247 vLCDTFTWriteCommandData(0x0033,0x0502); wait_ms(1);
Suky 1:1085b6177f6e 248 vLCDTFTWriteCommandData(0x0034,0x0507); wait_ms(1);
Suky 1:1085b6177f6e 249 vLCDTFTWriteCommandData(0x0035,0x0204); wait_ms(1);
Suky 1:1085b6177f6e 250 vLCDTFTWriteCommandData(0x0036,0x0204); wait_ms(1);
Suky 1:1085b6177f6e 251 vLCDTFTWriteCommandData(0x0037,0x0502); wait_ms(1);
Suky 1:1085b6177f6e 252 vLCDTFTWriteCommandData(0x003A,0x0302); wait_ms(1);
Suky 1:1085b6177f6e 253 vLCDTFTWriteCommandData(0x003B,0x0302); wait_ms(1);
Suky 1:1085b6177f6e 254 vLCDTFTWriteCommandData(0x0023,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 255 vLCDTFTWriteCommandData(0x0024,0x0000); wait_ms(1);
Suky 1:1085b6177f6e 256 vLCDTFTWriteCommandData(0x0025,0x8000); wait_ms(1);
Suky 1:1085b6177f6e 257 vLCDTFTWriteCommandData(0x004f,0);
Suky 1:1085b6177f6e 258 vLCDTFTWriteCommandData(0x004e,0);
Suky 1:1085b6177f6e 259 vLCDTFTWriteCommand(0x0022);
cstevens 2:ebedda77b33b 260 */
Suky 1:1085b6177f6e 261 }
Suky 1:1085b6177f6e 262
Suky 1:1085b6177f6e 263 void LCDTFT::vLCDTFTFillScreen(unsigned short Color){
Suky 1:1085b6177f6e 264 unsigned short i,j;
cstevens 2:ebedda77b33b 265
cstevens 2:ebedda77b33b 266 vLCDTFTWriteCommandData(0x0020,00); //set x=0
cstevens 2:ebedda77b33b 267 vLCDTFTWriteCommandData(0x0021,00); // set y=0
cstevens 2:ebedda77b33b 268 vLCDTFTWriteCommand(0x0022);
Suky 1:1085b6177f6e 269
Suky 1:1085b6177f6e 270 for(i=0;i<320;i++){
Suky 1:1085b6177f6e 271 for (j=0;j<240;j++){
Suky 1:1085b6177f6e 272 vLCDTFTWriteData(Color);
Suky 1:1085b6177f6e 273 }
Suky 1:1085b6177f6e 274 }
Suky 1:1085b6177f6e 275 }
Suky 1:1085b6177f6e 276
Suky 1:1085b6177f6e 277 void LCDTFT::vLCDTFTPoint(unsigned short x,unsigned short y,unsigned short Color){
Suky 1:1085b6177f6e 278
Suky 1:1085b6177f6e 279 vLCDTFTAddressSetPoint(x,y);
Suky 1:1085b6177f6e 280 vLCDTFTWriteData(Color);
Suky 1:1085b6177f6e 281 }
Suky 1:1085b6177f6e 282
cstevens 2:ebedda77b33b 283 void LCDTFT::vLCDTFTText(unsigned short x,unsigned short y,const char *PtrText,const char (*Fuente)[5],unsigned char Alto,unsigned short Color,unsigned short BackColor){
cstevens 3:f999653c1069 284 unsigned short i, j, k, l, m, temp,lmax;
Suky 1:1085b6177f6e 285 char DataPunto[5];
Suky 1:1085b6177f6e 286 const char *Ptr;
cstevens 3:f999653c1069 287 if(orient==0) lmax=LCD_X_MAX;
cstevens 3:f999653c1069 288 else lmax=LCD_Y_MAX;
Suky 1:1085b6177f6e 289
Suky 1:1085b6177f6e 290 while(*PtrText!='\0'){
Suky 1:1085b6177f6e 291 Ptr=(Fuente+*PtrText-' ')[0];
Suky 1:1085b6177f6e 292 for(i=0;i<5;i++){DataPunto[i]=*Ptr++;}
Suky 1:1085b6177f6e 293 switch(*PtrText){
Suky 1:1085b6177f6e 294 case '\n':
Suky 1:1085b6177f6e 295 y += 7*Alto + 1;
Suky 1:1085b6177f6e 296 break;
Suky 1:1085b6177f6e 297 case '\r':
Suky 1:1085b6177f6e 298 x = 0;
Suky 1:1085b6177f6e 299 break;
Suky 1:1085b6177f6e 300 default:
cstevens 3:f999653c1069 301 if(x+5*Alto >= lmax){
Suky 1:1085b6177f6e 302 x = 0;
Suky 1:1085b6177f6e 303 y += 7*Alto + 1;
Suky 1:1085b6177f6e 304 }
Suky 1:1085b6177f6e 305 for(j=0; j<5; ++j, x+=Alto){
Suky 1:1085b6177f6e 306 for(k=0; k < 7; k++){
Suky 1:1085b6177f6e 307 temp=(0x01<<k);
Suky 1:1085b6177f6e 308 if((DataPunto[j]&temp)==temp){
Suky 1:1085b6177f6e 309 for(l=0; l < Alto; ++l){
Suky 1:1085b6177f6e 310 for(m=0; m < Alto; ++m){
Suky 1:1085b6177f6e 311 vLCDTFTPoint(x+m,y+k*Alto+l,Color);
cstevens 2:ebedda77b33b 312 }//endform
cstevens 2:ebedda77b33b 313 }//endforl
cstevens 2:ebedda77b33b 314 }//endif
cstevens 2:ebedda77b33b 315 else{
cstevens 2:ebedda77b33b 316 for(l=0; l < Alto; ++l){
cstevens 2:ebedda77b33b 317 for(m=0; m < Alto; ++m){
cstevens 2:ebedda77b33b 318 vLCDTFTPoint(x+m,y+k*Alto+l,BackColor);
cstevens 2:ebedda77b33b 319 }//endform
cstevens 2:ebedda77b33b 320 }//endforl
cstevens 2:ebedda77b33b 321 }
Suky 1:1085b6177f6e 322 }
Suky 1:1085b6177f6e 323 }
Suky 1:1085b6177f6e 324 x++;
Suky 1:1085b6177f6e 325 break;
Suky 1:1085b6177f6e 326 }
Suky 1:1085b6177f6e 327 *PtrText++;
Suky 1:1085b6177f6e 328 }
Suky 1:1085b6177f6e 329 }
Suky 1:1085b6177f6e 330
Suky 1:1085b6177f6e 331 void LCDTFT::vLCDTFTLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short Color){
Suky 1:1085b6177f6e 332
Suky 1:1085b6177f6e 333 unsigned short dy, dx;
Suky 1:1085b6177f6e 334 short addx=1, addy=1;
Suky 1:1085b6177f6e 335 short P, diff;
Suky 1:1085b6177f6e 336 unsigned short i=0;
Suky 1:1085b6177f6e 337
Suky 1:1085b6177f6e 338 diff=((short)x2-x1);
Suky 1:1085b6177f6e 339 if(diff<0) diff*=-1;
Suky 1:1085b6177f6e 340 dx=diff;
Suky 1:1085b6177f6e 341 diff=((short)y2-y1);
Suky 1:1085b6177f6e 342 if(diff<0) diff*=-1;
Suky 1:1085b6177f6e 343 dy=diff;
Suky 1:1085b6177f6e 344
Suky 1:1085b6177f6e 345
Suky 1:1085b6177f6e 346 if(x1 > x2)addx = -1;
Suky 1:1085b6177f6e 347 if(y1 > y2)addy = -1;
Suky 1:1085b6177f6e 348 if(dx >= dy){
Suky 1:1085b6177f6e 349 dy *= 2;
Suky 1:1085b6177f6e 350 P = dy - dx;
Suky 1:1085b6177f6e 351 diff = P - dx;
Suky 1:1085b6177f6e 352 for(;i<=dx;++i){
Suky 1:1085b6177f6e 353 vLCDTFTPoint(x1, y1, Color);
Suky 1:1085b6177f6e 354 if(P < 0){
Suky 1:1085b6177f6e 355 P += dy;
Suky 1:1085b6177f6e 356 x1 += addx;
Suky 1:1085b6177f6e 357 }else{
Suky 1:1085b6177f6e 358 P += diff;
Suky 1:1085b6177f6e 359 x1 += addx;
Suky 1:1085b6177f6e 360 y1 += addy;
Suky 1:1085b6177f6e 361 }
Suky 1:1085b6177f6e 362 }
Suky 1:1085b6177f6e 363 }else{
Suky 1:1085b6177f6e 364 dx *= 2;
Suky 1:1085b6177f6e 365 P = dx - dy;
Suky 1:1085b6177f6e 366 diff = P - dy;
Suky 1:1085b6177f6e 367 for(; i<=dy; ++i){
Suky 1:1085b6177f6e 368 vLCDTFTPoint(x1, y1, Color);
Suky 1:1085b6177f6e 369 if(P < 0){
Suky 1:1085b6177f6e 370 P += dx;
Suky 1:1085b6177f6e 371 y1 += addy;
Suky 1:1085b6177f6e 372 }else{
Suky 1:1085b6177f6e 373 P += diff;
Suky 1:1085b6177f6e 374 x1 += addx;
Suky 1:1085b6177f6e 375 y1 += addy;
Suky 1:1085b6177f6e 376 }
Suky 1:1085b6177f6e 377 }
Suky 1:1085b6177f6e 378 }
Suky 1:1085b6177f6e 379 }
Suky 1:1085b6177f6e 380
Suky 1:1085b6177f6e 381
Suky 1:1085b6177f6e 382 void LCDTFT::vLCDTFTRectangle(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,bool Filled,unsigned short Color){
Suky 1:1085b6177f6e 383
Suky 1:1085b6177f6e 384 if(Filled){
cstevens 2:ebedda77b33b 385 int Lenght=(int)(x2-x1);
Suky 1:1085b6177f6e 386
cstevens 2:ebedda77b33b 387
Suky 1:1085b6177f6e 388 for(int i=0;i<Lenght;i++){
cstevens 2:ebedda77b33b 389 vLCDTFTLine(x1,y1+i,x2,y1+i,Color);
Suky 1:1085b6177f6e 390 }
Suky 1:1085b6177f6e 391 }else{
Suky 1:1085b6177f6e 392 vLCDTFTLine(x1, y1, x2, y1, Color);
Suky 1:1085b6177f6e 393 vLCDTFTLine(x1, y2, x2, y2, Color);
Suky 1:1085b6177f6e 394 vLCDTFTLine(x1, y1, x1, y2, Color);
Suky 1:1085b6177f6e 395 vLCDTFTLine(x2, y1, x2, y2, Color);
Suky 1:1085b6177f6e 396 }
Suky 1:1085b6177f6e 397 }
Suky 1:1085b6177f6e 398
Suky 1:1085b6177f6e 399
Suky 1:1085b6177f6e 400 void LCDTFT::vLCDTFTCircle(unsigned short x,unsigned short y,unsigned short Radius,bool Filled,unsigned short Color){
Suky 1:1085b6177f6e 401 short a, b, P;
Suky 1:1085b6177f6e 402
Suky 1:1085b6177f6e 403 a = 0;
Suky 1:1085b6177f6e 404 b = Radius;
Suky 1:1085b6177f6e 405 P = 1 - Radius;
Suky 1:1085b6177f6e 406
Suky 1:1085b6177f6e 407 do{
Suky 1:1085b6177f6e 408 if(Filled){
Suky 1:1085b6177f6e 409 vLCDTFTLine(x-a, y+b, x+a, y+b, Color);
Suky 1:1085b6177f6e 410 vLCDTFTLine(x-a, y-b, x+a, y-b, Color);
Suky 1:1085b6177f6e 411 vLCDTFTLine(x-b, y+a, x+b, y+a, Color);
Suky 1:1085b6177f6e 412 vLCDTFTLine(x-b, y-a, x+b, y-a, Color);
Suky 1:1085b6177f6e 413 }else{
Suky 1:1085b6177f6e 414 vLCDTFTPoint(a+x, b+y, Color);
Suky 1:1085b6177f6e 415 vLCDTFTPoint(b+x, a+y, Color);
Suky 1:1085b6177f6e 416 vLCDTFTPoint(x-a, b+y, Color);
Suky 1:1085b6177f6e 417 vLCDTFTPoint(x-b, a+y, Color);
Suky 1:1085b6177f6e 418 vLCDTFTPoint(b+x, y-a, Color);
Suky 1:1085b6177f6e 419 vLCDTFTPoint(a+x, y-b, Color);
Suky 1:1085b6177f6e 420 vLCDTFTPoint(x-a, y-b, Color);
Suky 1:1085b6177f6e 421 vLCDTFTPoint(x-b, y-a, Color);
Suky 1:1085b6177f6e 422 }
Suky 1:1085b6177f6e 423 if(P < 0) P += 3 + 2 * a++;
Suky 1:1085b6177f6e 424 else P += 5 + 2 * (a++ - b--);
Suky 1:1085b6177f6e 425 }while(a <= b);
Suky 1:1085b6177f6e 426 }
cstevens 2:ebedda77b33b 427 /*
Suky 1:1085b6177f6e 428 void LCDTFT::vDrawImageBMP24Bits(const char *NameImagen){
Suky 1:1085b6177f6e 429
Suky 1:1085b6177f6e 430 #define OffsetWidthPixel 18
Suky 1:1085b6177f6e 431 #define OffsetHeighPixel 22
Suky 1:1085b6177f6e 432 #define OffsetSizeFile 34
Suky 1:1085b6177f6e 433 #define OffsetInitData 10
Suky 1:1085b6177f6e 434 #define OffserTipeFile 28
Suky 1:1085b6177f6e 435 char Nombre[80],k;
Suky 1:1085b6177f6e 436 unsigned short PosXImagen,PosYImagen;
Suky 1:1085b6177f6e 437 unsigned char Temp,BufferHeader[54],BufferTemp[3],Adicional;
Suky 1:1085b6177f6e 438 unsigned int WidthPixel,HeighPixel;
Suky 1:1085b6177f6e 439 unsigned short TipeFile,InitData,Temp16bits;
Suky 1:1085b6177f6e 440 union{
Suky 1:1085b6177f6e 441 unsigned short Val;
Suky 1:1085b6177f6e 442 struct{
Suky 1:1085b6177f6e 443 unsigned Blue:5;
Suky 1:1085b6177f6e 444 unsigned Green:6;
Suky 1:1085b6177f6e 445 unsigned Red:5;
Suky 1:1085b6177f6e 446 };
Suky 1:1085b6177f6e 447 }Color;
Suky 1:1085b6177f6e 448
Suky 1:1085b6177f6e 449 LocalFileSystem local("mbedMemory");
Suky 1:1085b6177f6e 450 sprintf(&Nombre[0],"/mbedMemory/");
Suky 1:1085b6177f6e 451 k=12;
Suky 1:1085b6177f6e 452 while(*NameImagen!='\0'){
Suky 1:1085b6177f6e 453 Nombre[k++]=*NameImagen++;
Suky 1:1085b6177f6e 454 }
Suky 1:1085b6177f6e 455
Suky 1:1085b6177f6e 456 FILE *Imagen = fopen((const char *)&Nombre[0], "r"); // Abrimos archivo para lectura.
Suky 1:1085b6177f6e 457 // Si no se pudo encontrar archivo:
Suky 1:1085b6177f6e 458 if(!Imagen) {
Suky 1:1085b6177f6e 459 vLCDTFTFillScreen(ColorBlack);
Suky 1:1085b6177f6e 460 return;
Suky 1:1085b6177f6e 461 }
Suky 1:1085b6177f6e 462 // Leemos cabecera de archivo
Suky 1:1085b6177f6e 463 fread(&BufferHeader[0],1,54,Imagen);
Suky 1:1085b6177f6e 464
Suky 1:1085b6177f6e 465 WidthPixel = ((unsigned int)BufferHeader[OffsetWidthPixel + 3]*16777216+BufferHeader[OffsetWidthPixel + 2]*65536+BufferHeader[OffsetWidthPixel + 1]*256+BufferHeader[OffsetWidthPixel]);
Suky 1:1085b6177f6e 466 HeighPixel = ((unsigned int)BufferHeader[OffsetHeighPixel + 3]*16777216+BufferHeader[OffsetHeighPixel + 2]*65536+BufferHeader[OffsetHeighPixel + 1]*256+BufferHeader[OffsetHeighPixel]);
Suky 1:1085b6177f6e 467 InitData = ((unsigned short)BufferHeader[OffsetInitData]);
Suky 1:1085b6177f6e 468 TipeFile = ((unsigned short)BufferHeader[OffserTipeFile + 1]*256 + BufferHeader[OffserTipeFile]);
Suky 1:1085b6177f6e 469
Suky 1:1085b6177f6e 470 if((WidthPixel>LCD_X_MAX) || (HeighPixel>LCD_Y_MAX) || (TipeFile!=24)){
Suky 1:1085b6177f6e 471 fclose(Imagen);
Suky 1:1085b6177f6e 472 return;
Suky 1:1085b6177f6e 473 }
Suky 1:1085b6177f6e 474
Suky 1:1085b6177f6e 475 if(InitData!=54){
Suky 1:1085b6177f6e 476 for(int k=54;k<InitData;k++){
Suky 1:1085b6177f6e 477 fread(&Temp,1,1,Imagen);
Suky 1:1085b6177f6e 478 }
Suky 1:1085b6177f6e 479 }
Suky 1:1085b6177f6e 480
Suky 1:1085b6177f6e 481 PosXImagen=(LCD_X_MAX/2)-(WidthPixel/2);
Suky 1:1085b6177f6e 482 PosYImagen=(LCD_Y_MAX/2)+(HeighPixel/2);
Suky 1:1085b6177f6e 483
Suky 1:1085b6177f6e 484 Temp16bits=WidthPixel*3;
Suky 1:1085b6177f6e 485 Adicional=0;
Suky 1:1085b6177f6e 486 while(((Temp16bits)%4)!=0){
Suky 1:1085b6177f6e 487 Adicional++;
Suky 1:1085b6177f6e 488 Temp16bits++;
Suky 1:1085b6177f6e 489 }
Suky 1:1085b6177f6e 490
Suky 1:1085b6177f6e 491 for(int k=0,y=PosYImagen;k<HeighPixel;k++,y--){
Suky 1:1085b6177f6e 492 vLCDTFTAddressSet(PosXImagen,y,PosXImagen+WidthPixel-1,y);
Suky 1:1085b6177f6e 493 for(int i=0;i<WidthPixel;i++){
Suky 1:1085b6177f6e 494 fread(&BufferTemp[0],1,3,Imagen); // Leemos 3 bytes (R,G,B)
Suky 1:1085b6177f6e 495 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 496 vLCDTFTWriteData(Color.Val);
Suky 1:1085b6177f6e 497 }
Suky 1:1085b6177f6e 498 // Bytes adicionales para que linea sea multiplo de 4.-
Suky 1:1085b6177f6e 499 for(int p=0;p<Adicional;p++){
Suky 1:1085b6177f6e 500 fread(&Temp,1,1,Imagen);
Suky 1:1085b6177f6e 501 }
Suky 1:1085b6177f6e 502 }
Suky 1:1085b6177f6e 503 fclose(Imagen);
Suky 1:1085b6177f6e 504 }
cstevens 2:ebedda77b33b 505 */
Suky 1:1085b6177f6e 506 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 507
Suky 1:1085b6177f6e 508 vLCDTFTAddressSet(x,y,x+Width-1,y+Heigh-1);
Suky 1:1085b6177f6e 509 for(int i=0;i<Lenght;i++){
Suky 1:1085b6177f6e 510 vLCDTFTWriteData(*Imagen++);
Suky 1:1085b6177f6e 511 }
Suky 0:359653f39307 512 }