LCD TFT for ssd0139 driver 8 bit mode

Dependents:   receiver TFT_CJS_ssd0139 poster8x8_ranger

Fork of LCDTFT by Ale C.-

/media/uploads/cstevens/20140902_103801.jpg

Committer:
cstevens
Date:
Tue Jun 09 10:29:06 2015 +0000
Revision:
5:d910bf3b7bb0
Parent:
4:2feb189748f7
Updated so example code now has correct definition fo the port; uses a single 8 bit busout command.; May need slight change if one wants to speed things up and use the portout version....

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