.

Committer:
dreschpe
Date:
Mon Oct 26 12:49:02 2015 +0000
Revision:
27:acb2594b8aa4
Parent:
25:daacdcf34e52
Child:
30:87855d03d91a
fix handling of PAR8 / PAR16 includes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 20:14daa48ffd4c 1 /* mbed UniGraphic library - custom TFT driver class, ILI932x specific
Geremia 20:14daa48ffd4c 2 * Copyright (c) 2015 Giuliano Dianda
Geremia 20:14daa48ffd4c 3 * Released under the MIT License: http://mbed.org/license/mit
Geremia 20:14daa48ffd4c 4 */
dreschpe 27:acb2594b8aa4 5
dreschpe 27:acb2594b8aa4 6 #include "platform.h"
dreschpe 27:acb2594b8aa4 7 #include "TFT932x.h"
Geremia 20:14daa48ffd4c 8
dreschpe 27:acb2594b8aa4 9 #if DEVICE_PORTINOUT
dreschpe 27:acb2594b8aa4 10 #include "PAR8.h"
dreschpe 27:acb2594b8aa4 11 #include "PAR16.h"
dreschpe 27:acb2594b8aa4 12 #endif
Geremia 20:14daa48ffd4c 13
Geremia 20:14daa48ffd4c 14 //#include "mbed_debug.h"
Geremia 20:14daa48ffd4c 15
Geremia 20:14daa48ffd4c 16 #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; }
Geremia 20:14daa48ffd4c 17
dreschpe 25:daacdcf34e52 18 #if DEVICE_PORTINOUT
Geremia 20:14daa48ffd4c 19 TFT932x::TFT932x(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const char *name)
Geremia 20:14daa48ffd4c 20 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y)
Geremia 20:14daa48ffd4c 21 {
Geremia 20:14daa48ffd4c 22 if(displayproto==PAR_8)
Geremia 20:14daa48ffd4c 23 {
Geremia 20:14daa48ffd4c 24 proto = new PAR8(port, CS, reset, DC, WR, RD);
Geremia 20:14daa48ffd4c 25 dummycycles=1;
Geremia 20:14daa48ffd4c 26 }
Geremia 20:14daa48ffd4c 27 else if(displayproto==PAR_16)
Geremia 20:14daa48ffd4c 28 {
Geremia 20:14daa48ffd4c 29 proto = new PAR16(port, CS, reset, DC, WR, RD);
Geremia 20:14daa48ffd4c 30 dummycycles=0;
Geremia 20:14daa48ffd4c 31 }
Geremia 20:14daa48ffd4c 32 // set_orientation(0);
Geremia 20:14daa48ffd4c 33 foreground(White);
Geremia 20:14daa48ffd4c 34 background(Black);
Geremia 20:14daa48ffd4c 35 set_auto_up(false); //we don't have framebuffer
Geremia 20:14daa48ffd4c 36 usefastwindow=false;
Geremia 20:14daa48ffd4c 37 fastwindowready=false;
Geremia 20:14daa48ffd4c 38 is18bit=false;
Geremia 20:14daa48ffd4c 39 isBGR=false;
Geremia 20:14daa48ffd4c 40 // cls();
Geremia 20:14daa48ffd4c 41 // locate(0,0);
Geremia 20:14daa48ffd4c 42 }
dreschpe 25:daacdcf34e52 43 #endif
dreschpe 27:acb2594b8aa4 44
Geremia 21:ae0a4eedfc90 45 TFT932x::TFT932x(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const char *name)
Geremia 21:ae0a4eedfc90 46 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y)
Geremia 21:ae0a4eedfc90 47 {
Geremia 21:ae0a4eedfc90 48 if(displayproto==BUS_8)
Geremia 21:ae0a4eedfc90 49 {
Geremia 21:ae0a4eedfc90 50 PinName pins[16];
Geremia 21:ae0a4eedfc90 51 for(int i=0; i<16; i++) pins[i]=NC;
Geremia 21:ae0a4eedfc90 52 for(int i=0; i<8; i++) pins[i]=buspins[i];
Geremia 21:ae0a4eedfc90 53 proto = new BUS8(pins, CS, reset, DC, WR, RD);
Geremia 21:ae0a4eedfc90 54 dummycycles=1;
Geremia 21:ae0a4eedfc90 55 }
Geremia 21:ae0a4eedfc90 56 else if(displayproto==BUS_16)
Geremia 21:ae0a4eedfc90 57 {
Geremia 21:ae0a4eedfc90 58 proto = new BUS16(buspins, CS, reset, DC, WR, RD);
Geremia 21:ae0a4eedfc90 59 dummycycles=0;
Geremia 21:ae0a4eedfc90 60 }
Geremia 21:ae0a4eedfc90 61 // set_orientation(0);
Geremia 21:ae0a4eedfc90 62 foreground(White);
Geremia 21:ae0a4eedfc90 63 background(Black);
Geremia 21:ae0a4eedfc90 64 set_auto_up(false); //we don't have framebuffer
Geremia 21:ae0a4eedfc90 65 usefastwindow=false;
Geremia 21:ae0a4eedfc90 66 fastwindowready=false;
Geremia 21:ae0a4eedfc90 67 is18bit=false;
Geremia 21:ae0a4eedfc90 68 isBGR=false;
Geremia 21:ae0a4eedfc90 69 // cls();
Geremia 21:ae0a4eedfc90 70 // locate(0,0);
Geremia 21:ae0a4eedfc90 71 }
Geremia 20:14daa48ffd4c 72 TFT932x::TFT932x(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, const int lcdsize_x, const int lcdsize_y, const char *name)
Geremia 20:14daa48ffd4c 73 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y)
Geremia 20:14daa48ffd4c 74 {
Geremia 20:14daa48ffd4c 75 if(displayproto==SPI_8)
Geremia 20:14daa48ffd4c 76 {
Geremia 20:14daa48ffd4c 77 proto = new SPI8(Hz, mosi, miso, sclk, CS, reset);
Geremia 20:14daa48ffd4c 78 dummycycles=4;
Geremia 20:14daa48ffd4c 79 }
Geremia 20:14daa48ffd4c 80 else if(displayproto==SPI_16)
Geremia 20:14daa48ffd4c 81 {
Geremia 20:14daa48ffd4c 82 proto = new SPI16(Hz, mosi, miso, sclk, CS, reset);
Geremia 20:14daa48ffd4c 83 dummycycles=2;
Geremia 20:14daa48ffd4c 84 }
Geremia 20:14daa48ffd4c 85 // set_orientation(0);
Geremia 20:14daa48ffd4c 86 foreground(White);
Geremia 20:14daa48ffd4c 87 background(Black);
Geremia 20:14daa48ffd4c 88 set_auto_up(false);
Geremia 20:14daa48ffd4c 89 usefastwindow=false;
Geremia 20:14daa48ffd4c 90 fastwindowready=false;
Geremia 20:14daa48ffd4c 91 is18bit=false;
Geremia 20:14daa48ffd4c 92 isBGR=false;
Geremia 20:14daa48ffd4c 93 // locate(0,0);
Geremia 20:14daa48ffd4c 94 }
Geremia 20:14daa48ffd4c 95 // dummy read needed before read gram
Geremia 20:14daa48ffd4c 96 // read gram protocol function does 1 dymmy read as for MIPI standard, but ILI932x needs more and protocol specific number of cycles
Geremia 20:14daa48ffd4c 97 // for example in spi mode, 5 dummy byte read needed, so for SPI16 2x16bit clocks done here and the 5th dummy will be handled by read gram function
Geremia 20:14daa48ffd4c 98 void TFT932x::dummyread()
Geremia 20:14daa48ffd4c 99 {
Geremia 20:14daa48ffd4c 100 for(unsigned int i=0; i<dummycycles; i++) proto->dummyread();
Geremia 20:14daa48ffd4c 101 }
Geremia 20:14daa48ffd4c 102 void TFT932x::reg_select(unsigned char reg, bool forread)
Geremia 20:14daa48ffd4c 103 {
Geremia 20:14daa48ffd4c 104 proto->reg_select(reg, forread);
Geremia 20:14daa48ffd4c 105 }
Geremia 20:14daa48ffd4c 106 void TFT932x::reg_write(unsigned char reg, unsigned short data)
Geremia 20:14daa48ffd4c 107 {
Geremia 20:14daa48ffd4c 108 proto->reg_write(reg, data);
Geremia 20:14daa48ffd4c 109 }
Geremia 20:14daa48ffd4c 110 unsigned short TFT932x::reg_read(unsigned char reg)
Geremia 20:14daa48ffd4c 111 {
Geremia 20:14daa48ffd4c 112 return proto->reg_read(reg);
Geremia 20:14daa48ffd4c 113 }
Geremia 20:14daa48ffd4c 114 void TFT932x::wr_gram(unsigned short data)
Geremia 20:14daa48ffd4c 115 {
Geremia 20:14daa48ffd4c 116 proto->wr_gram(data);
Geremia 20:14daa48ffd4c 117 }
Geremia 20:14daa48ffd4c 118 void TFT932x::wr_gram(unsigned short data, unsigned int count)
Geremia 20:14daa48ffd4c 119 {
Geremia 20:14daa48ffd4c 120 proto->wr_gram(data, count);
Geremia 20:14daa48ffd4c 121 }
Geremia 20:14daa48ffd4c 122 void TFT932x::wr_grambuf(unsigned short* data, unsigned int lenght)
Geremia 20:14daa48ffd4c 123 {
Geremia 20:14daa48ffd4c 124 proto->wr_grambuf(data, lenght);
Geremia 20:14daa48ffd4c 125 }
Geremia 20:14daa48ffd4c 126 unsigned short TFT932x::rd_gram()
Geremia 20:14daa48ffd4c 127 {
Geremia 20:14daa48ffd4c 128 return proto->rd_gram(is18bit); // protocol will handle 18to16 bit conversion
Geremia 20:14daa48ffd4c 129
Geremia 20:14daa48ffd4c 130 }
Geremia 20:14daa48ffd4c 131 //for TFT, just send data, position counters are in hw
Geremia 20:14daa48ffd4c 132 void TFT932x::window_pushpixel(unsigned short color)
Geremia 20:14daa48ffd4c 133 {
Geremia 20:14daa48ffd4c 134 proto->wr_gram(color);
Geremia 20:14daa48ffd4c 135 }
Geremia 20:14daa48ffd4c 136 void TFT932x::window_pushpixel(unsigned short color, unsigned int count)
Geremia 20:14daa48ffd4c 137 {
Geremia 20:14daa48ffd4c 138 proto->wr_gram(color, count);
Geremia 20:14daa48ffd4c 139 }
Geremia 20:14daa48ffd4c 140 void TFT932x::window_pushpixelbuf(unsigned short* color, unsigned int lenght)
Geremia 20:14daa48ffd4c 141 {
Geremia 20:14daa48ffd4c 142 proto->wr_grambuf(color, lenght);
Geremia 20:14daa48ffd4c 143 }
Geremia 20:14daa48ffd4c 144 void TFT932x::hw_reset()
Geremia 20:14daa48ffd4c 145 {
Geremia 20:14daa48ffd4c 146 proto->hw_reset();
Geremia 20:14daa48ffd4c 147 BusEnable(true);
Geremia 20:14daa48ffd4c 148 }
Geremia 20:14daa48ffd4c 149 void TFT932x::BusEnable(bool enable)
Geremia 20:14daa48ffd4c 150 {
Geremia 20:14daa48ffd4c 151 proto->BusEnable(enable);
Geremia 20:14daa48ffd4c 152 }
Geremia 20:14daa48ffd4c 153 // ILI932x can't rotate in hw (swap raw<->columns) for landscape views,
Geremia 20:14daa48ffd4c 154 // but can change the way address counter is auto incremented/decremented
Geremia 20:14daa48ffd4c 155 void TFT932x::set_orientation(int o)
Geremia 20:14daa48ffd4c 156 {
Geremia 20:14daa48ffd4c 157 // if(orientation == o) return;
Geremia 20:14daa48ffd4c 158 orientation = o;
Geremia 20:14daa48ffd4c 159 switch (orientation)
Geremia 20:14daa48ffd4c 160 // BGR bit set for all modes, seems most TFT are like that, in case override set_orientation() in init
Geremia 20:14daa48ffd4c 161 // ORG bit set for all modes
Geremia 20:14daa48ffd4c 162 {
Geremia 20:14daa48ffd4c 163 case 0:// default, portrait view 0°
Geremia 20:14daa48ffd4c 164 reg_write(0x0001,0x0100); // S720 to S1
Geremia 20:14daa48ffd4c 165 reg_write(0x0060,0xA700); // G320 to G1
Geremia 20:14daa48ffd4c 166 reg_write(0x03, 0x10B0);
Geremia 20:14daa48ffd4c 167 set_width(screensize_X);
Geremia 20:14daa48ffd4c 168 set_height(screensize_Y);
Geremia 20:14daa48ffd4c 169 break;
Geremia 20:14daa48ffd4c 170 case 1:// landscape view +90°
Geremia 20:14daa48ffd4c 171 reg_write(0x0001,0x0000); // S1 to S720
Geremia 20:14daa48ffd4c 172 reg_write(0x0060,0xA700); // G320 to G1
Geremia 20:14daa48ffd4c 173 reg_write(0x03, 0x10B8); // AM=1 increase addr ctr first vertically then horizontally
Geremia 20:14daa48ffd4c 174 set_width(screensize_Y);
Geremia 20:14daa48ffd4c 175 set_height(screensize_X);
Geremia 20:14daa48ffd4c 176 break;
Geremia 20:14daa48ffd4c 177 case 2:// portrait view +180°
Geremia 20:14daa48ffd4c 178 reg_write(0x0001,0x0000); // S1 to S720
Geremia 20:14daa48ffd4c 179 reg_write(0x0060,0x2700); // G1 to G320
Geremia 20:14daa48ffd4c 180 reg_write(0x03, 0x10B0);
Geremia 20:14daa48ffd4c 181 set_width(screensize_X);
Geremia 20:14daa48ffd4c 182 set_height(screensize_Y);
Geremia 20:14daa48ffd4c 183 break;
Geremia 20:14daa48ffd4c 184 case 3:// landscape view -90°
Geremia 20:14daa48ffd4c 185 reg_write(0x0001,0x0100); // S720 to S1
Geremia 20:14daa48ffd4c 186 reg_write(0x0060,0x2700); // G1 to G320
Geremia 20:14daa48ffd4c 187 reg_write(0x03, 0x10B8); // AM=1 increase addr ctr first vertically then horizontally
Geremia 20:14daa48ffd4c 188 set_width(screensize_Y);
Geremia 20:14daa48ffd4c 189 set_height(screensize_X);
Geremia 20:14daa48ffd4c 190 break;
Geremia 20:14daa48ffd4c 191 }
Geremia 20:14daa48ffd4c 192 }
Geremia 20:14daa48ffd4c 193 void TFT932x::invert(unsigned char o)
Geremia 20:14daa48ffd4c 194 {
Geremia 20:14daa48ffd4c 195 unsigned short oldreg = reg_read(0x61);
Geremia 20:14daa48ffd4c 196 if(o == 0) reg_write(0x61, oldreg|1); // seems most TFT have REV bit enabled for normal display
Geremia 20:14daa48ffd4c 197 else reg_write(0x61, oldreg&0xFFFE);
Geremia 20:14daa48ffd4c 198 }
Geremia 20:14daa48ffd4c 199 void TFT932x::FastWindow(bool enable)
Geremia 20:14daa48ffd4c 200 {
Geremia 20:14daa48ffd4c 201 usefastwindow=enable;
Geremia 20:14daa48ffd4c 202 }
Geremia 20:14daa48ffd4c 203 // TFT have both column and raw autoincrement inside a window, with internal counters
Geremia 20:14daa48ffd4c 204 void TFT932x::window(int x, int y, int w, int h)
Geremia 20:14daa48ffd4c 205 {
Geremia 20:14daa48ffd4c 206 if(orientation==1 || orientation==3)
Geremia 20:14daa48ffd4c 207 {
Geremia 20:14daa48ffd4c 208 SWAP(x,y);
Geremia 20:14daa48ffd4c 209 SWAP(w,h);
Geremia 20:14daa48ffd4c 210 }
Geremia 20:14daa48ffd4c 211 fastwindowready=false; // end raw/column going to be set to lower value than bottom-right corner
Geremia 20:14daa48ffd4c 212 reg_write(0x50, x);//start column
Geremia 20:14daa48ffd4c 213 reg_write(0x51, x+w-1);//end column
Geremia 20:14daa48ffd4c 214 reg_write(0x52, y);//start page
Geremia 20:14daa48ffd4c 215 reg_write(0x53, y+h-1);//end page
Geremia 20:14daa48ffd4c 216
Geremia 20:14daa48ffd4c 217 reg_write(0x20, 0); // since ORG bit is set, address is windows relative, so should be set always to 0000
Geremia 20:14daa48ffd4c 218 reg_write(0x21, 0);
Geremia 20:14daa48ffd4c 219
Geremia 20:14daa48ffd4c 220 reg_select(0x22, false); //write mem, just write gram next
Geremia 20:14daa48ffd4c 221 }
Geremia 20:14daa48ffd4c 222 void TFT932x::window4read(int x, int y, int w, int h)
Geremia 20:14daa48ffd4c 223 {
Geremia 20:14daa48ffd4c 224 if(orientation==1 || orientation==3)
Geremia 20:14daa48ffd4c 225 {
Geremia 20:14daa48ffd4c 226 SWAP(x,y);
Geremia 20:14daa48ffd4c 227 SWAP(w,h);
Geremia 20:14daa48ffd4c 228 }
Geremia 20:14daa48ffd4c 229 fastwindowready=false; // end raw/column going to be set to lower value than bottom-right corner
Geremia 20:14daa48ffd4c 230 reg_write(0x50, x);//start column
Geremia 20:14daa48ffd4c 231 reg_write(0x51, x+w-1);//end column
Geremia 20:14daa48ffd4c 232 reg_write(0x52, y);//start page
Geremia 20:14daa48ffd4c 233 reg_write(0x53, y+h-1);//end page
Geremia 20:14daa48ffd4c 234
Geremia 20:14daa48ffd4c 235 reg_write(0x20, 0); // since ORG bit is set, address is windows relative, so should be set always to 0000
Geremia 20:14daa48ffd4c 236 reg_write(0x21, 0);
Geremia 20:14daa48ffd4c 237
Geremia 20:14daa48ffd4c 238 reg_select(0x22, true); //read mem, just read gram next
Geremia 20:14daa48ffd4c 239 dummyread();
Geremia 20:14daa48ffd4c 240 }
Geremia 20:14daa48ffd4c 241 void TFT932x::pixel(int x, int y, unsigned short color)
Geremia 20:14daa48ffd4c 242 {
Geremia 20:14daa48ffd4c 243 if(usefastwindow)
Geremia 20:14daa48ffd4c 244 {
Geremia 20:14daa48ffd4c 245 if(fastwindowready) //setting only start column/page does speedup, but needs end raw/column previously set to bottom-right corner
Geremia 20:14daa48ffd4c 246 {
Geremia 20:14daa48ffd4c 247 if(orientation==1 || orientation==3) SWAP(x,y);
Geremia 20:14daa48ffd4c 248 reg_write(0x50, x);//start column only
Geremia 20:14daa48ffd4c 249 reg_write(0x52, y);//start page only
Geremia 20:14daa48ffd4c 250 reg_write(0x20, 0); // since ORG bit is set, address is window relative, so should be set always to 0000
Geremia 20:14daa48ffd4c 251 reg_write(0x21, 0);
Geremia 20:14daa48ffd4c 252 reg_select(0x22, false); //write mem, just write gram next
Geremia 20:14daa48ffd4c 253 }
Geremia 20:14daa48ffd4c 254 else
Geremia 20:14daa48ffd4c 255 {
Geremia 20:14daa48ffd4c 256 window(x,y,width()-x,height()-y); // set also end raw/column to bottom-right corner
Geremia 20:14daa48ffd4c 257 fastwindowready=true;
Geremia 20:14daa48ffd4c 258 }
Geremia 20:14daa48ffd4c 259 }
Geremia 20:14daa48ffd4c 260 else window(x,y,1,1);
Geremia 20:14daa48ffd4c 261 wr_gram(color);
Geremia 20:14daa48ffd4c 262 }
Geremia 20:14daa48ffd4c 263 unsigned short TFT932x::pixelread(int x, int y)
Geremia 20:14daa48ffd4c 264 {
Geremia 20:14daa48ffd4c 265 /* if(usefastwindow) // for ILI9325 fastwindows for reading works only in PAR16
Geremia 20:14daa48ffd4c 266 {
Geremia 20:14daa48ffd4c 267 if(fastwindowready) //setting only start column/page does speedup, but needs end raw/column previously set to bottom-right corner
Geremia 20:14daa48ffd4c 268 {
Geremia 20:14daa48ffd4c 269 if(orientation==1 || orientation==3) SWAP(x,y);
Geremia 20:14daa48ffd4c 270 reg_write(0x50, x);//start column only
Geremia 20:14daa48ffd4c 271 reg_write(0x52, y);//start page only
Geremia 20:14daa48ffd4c 272 reg_write(0x20, 0); // since ORG bit is set, address is window relative, so should be set always to 0000
Geremia 20:14daa48ffd4c 273 reg_write(0x21, 0);
Geremia 20:14daa48ffd4c 274 reg_select(0x22, true); //read mem, just read gram next
Geremia 20:14daa48ffd4c 275 }
Geremia 20:14daa48ffd4c 276 else
Geremia 20:14daa48ffd4c 277 {
Geremia 20:14daa48ffd4c 278 window4read(x,y,width()-x,height()-y); // set also end raw/column to bottom-right corner
Geremia 20:14daa48ffd4c 279 fastwindowready=true;
Geremia 20:14daa48ffd4c 280 }
Geremia 20:14daa48ffd4c 281 }
Geremia 20:14daa48ffd4c 282 else*/
Geremia 20:14daa48ffd4c 283 window4read(x,y,1,1);
Geremia 20:14daa48ffd4c 284
Geremia 20:14daa48ffd4c 285 unsigned short color;
Geremia 20:14daa48ffd4c 286 color = rd_gram();
Geremia 20:14daa48ffd4c 287 if(isBGR) color = BGR2RGB(color); // in case, convert BGR to RGB
Geremia 20:14daa48ffd4c 288 return color;
Geremia 20:14daa48ffd4c 289 }
Geremia 20:14daa48ffd4c 290 void TFT932x::setscrollarea (int startY, int areasize) // ie 0,480 for whole screen
Geremia 20:14daa48ffd4c 291 {
Geremia 20:14daa48ffd4c 292 // ILI932x allows only ful lscreen scrolling
Geremia 20:14daa48ffd4c 293 unsigned short oldreg = reg_read(0x61);
Geremia 20:14daa48ffd4c 294 reg_write(0x61, oldreg|2); // enable scroll
Geremia 20:14daa48ffd4c 295 }
Geremia 20:14daa48ffd4c 296 void TFT932x::scroll (int lines) // ie 1= scrollup 1, 479= scrolldown 1
Geremia 20:14daa48ffd4c 297 {
Geremia 20:14daa48ffd4c 298 reg_write(0x6A, lines%screensize_Y); // select the (absolute)line which will be displayed as first line
Geremia 20:14daa48ffd4c 299 }
Geremia 20:14daa48ffd4c 300 void TFT932x::scrollreset()
Geremia 20:14daa48ffd4c 301 {
Geremia 20:14daa48ffd4c 302 unsigned short oldreg = reg_read(0x61);
Geremia 20:14daa48ffd4c 303 // reg_write(0x61, oldreg&0xFFFD); // disable scroll
Geremia 20:14daa48ffd4c 304 reg_write(0x6A, 0);
Geremia 20:14daa48ffd4c 305 }
Geremia 20:14daa48ffd4c 306 void TFT932x::cls (void)
Geremia 20:14daa48ffd4c 307 {
Geremia 20:14daa48ffd4c 308 WindowMax();
Geremia 20:14daa48ffd4c 309 wr_gram(_background,screensize_X*screensize_Y);
Geremia 20:14daa48ffd4c 310 }
Geremia 20:14daa48ffd4c 311 // try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR
Geremia 20:14daa48ffd4c 312 void TFT932x::auto_gram_read_format()
Geremia 20:14daa48ffd4c 313 {
Geremia 20:14daa48ffd4c 314 unsigned short px=0xCDB1;
Geremia 20:14daa48ffd4c 315 unsigned short rback, rback18;
Geremia 20:14daa48ffd4c 316 pixel(0,0,px);
Geremia 20:14daa48ffd4c 317 window4read(0,0,1,1);
Geremia 20:14daa48ffd4c 318 rback=proto->rd_gram(0); // try 16bit
Geremia 20:14daa48ffd4c 319 window4read(0,0,1,1);
Geremia 20:14daa48ffd4c 320 rback18=proto->rd_gram(1); // try 18bit converted to 16
Geremia 20:14daa48ffd4c 321 if((rback18==px) || (BGR2RGB(rback18)==px))
Geremia 20:14daa48ffd4c 322 {
Geremia 20:14daa48ffd4c 323 is18bit=true;
Geremia 20:14daa48ffd4c 324 if(BGR2RGB(rback18)==px) isBGR=true;
Geremia 20:14daa48ffd4c 325 }
Geremia 20:14daa48ffd4c 326 else if((rback==px) || (BGR2RGB(rback)==px))
Geremia 20:14daa48ffd4c 327 {
Geremia 20:14daa48ffd4c 328 if(BGR2RGB(rback)==px) isBGR=true;
Geremia 20:14daa48ffd4c 329 }
Geremia 20:14daa48ffd4c 330 // debug("\r\nIdentify gram read color format,\r\nsent %.4X read16 %.4X(bgr%.4X) read18 %.4X(bgr%.4X)", px, rback, BGR2RGB(rback), rback18, BGR2RGB(rback18));
Geremia 20:14daa48ffd4c 331 }
Geremia 20:14daa48ffd4c 332 // try to identify display controller
Geremia 20:14daa48ffd4c 333 void TFT932x::identify()
Geremia 20:14daa48ffd4c 334 {
Geremia 20:14daa48ffd4c 335 tftID = reg_read(0x00);
Geremia 20:14daa48ffd4c 336 hw_reset(); // in case wrong cmd messed up important settings
Geremia 20:14daa48ffd4c 337 }
Geremia 20:14daa48ffd4c 338 int TFT932x::sizeX()
Geremia 20:14daa48ffd4c 339 {
Geremia 20:14daa48ffd4c 340 return screensize_X;
Geremia 20:14daa48ffd4c 341 }
Geremia 20:14daa48ffd4c 342 int TFT932x::sizeY()
Geremia 20:14daa48ffd4c 343 {
Geremia 20:14daa48ffd4c 344 return screensize_Y;
Geremia 20:14daa48ffd4c 345 }