.

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 4:12ba0ecc2c1f 1 /* mbed UniGraphic library - universal TFT driver class
Geremia 4:12ba0ecc2c1f 2 * Copyright (c) 2015 Giuliano Dianda
Geremia 4:12ba0ecc2c1f 3 * Released under the MIT License: http://mbed.org/license/mit
Geremia 4:12ba0ecc2c1f 4 *
Geremia 4:12ba0ecc2c1f 5 * Derived work of:
Geremia 4:12ba0ecc2c1f 6 *
Geremia 4:12ba0ecc2c1f 7 * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller
Geremia 3:48f3282c2be8 8 * Copyright (c) 2013 Peter Drescher - DC2PD
Geremia 3:48f3282c2be8 9 *
Geremia 3:48f3282c2be8 10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Geremia 3:48f3282c2be8 11 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Geremia 3:48f3282c2be8 12 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Geremia 3:48f3282c2be8 13 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Geremia 3:48f3282c2be8 14 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Geremia 3:48f3282c2be8 15 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Geremia 3:48f3282c2be8 16 * THE SOFTWARE.
Geremia 3:48f3282c2be8 17 */
Geremia 3:48f3282c2be8 18
Geremia 2:713844a55c4e 19 #include "TFT.h"
Geremia 2:713844a55c4e 20
Geremia 15:b9483ba842c8 21 //#include "mbed_debug.h"
Geremia 2:713844a55c4e 22
Geremia 2:713844a55c4e 23 #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; }
Geremia 2:713844a55c4e 24
dreschpe 27:acb2594b8aa4 25 #if DEVICE_PORTINOUT
Geremia 2:713844a55c4e 26 TFT::TFT(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 7:bb0383b91104 27 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y)
Geremia 2:713844a55c4e 28 {
Geremia 2:713844a55c4e 29 if(displayproto==PAR_8) proto = new PAR8(port, CS, reset, DC, WR, RD);
dreschpe 27:acb2594b8aa4 30 else if(displayproto==PAR_16) proto = new PAR16(port, CS, reset, DC, WR, RD);
Geremia 2:713844a55c4e 31 useNOP=false;
Geremia 4:12ba0ecc2c1f 32 scrollbugfix=0;
Geremia 4:12ba0ecc2c1f 33 mipistd=false;
Geremia 2:713844a55c4e 34 set_orientation(0);
Geremia 2:713844a55c4e 35 foreground(White);
Geremia 2:713844a55c4e 36 background(Black);
Geremia 2:713844a55c4e 37 set_auto_up(false); //we don't have framebuffer
Geremia 7:bb0383b91104 38 topfixedareasize=0;
Geremia 7:bb0383b91104 39 scrollareasize=0;
Geremia 10:668cf78ff93a 40 usefastwindow=false;
Geremia 10:668cf78ff93a 41 fastwindowready=false;
Geremia 11:b842b8e332cb 42 is18bit=false;
Geremia 11:b842b8e332cb 43 isBGR=false;
Geremia 2:713844a55c4e 44 // cls();
Geremia 2:713844a55c4e 45 // locate(0,0);
Geremia 2:713844a55c4e 46 }
dreschpe 27:acb2594b8aa4 47 #endif
dreschpe 27:acb2594b8aa4 48
Geremia 21:ae0a4eedfc90 49 TFT::TFT(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 50 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y)
Geremia 21:ae0a4eedfc90 51 {
Geremia 21:ae0a4eedfc90 52 if(displayproto==BUS_8)
Geremia 21:ae0a4eedfc90 53 {
Geremia 21:ae0a4eedfc90 54 PinName pins[16];
Geremia 21:ae0a4eedfc90 55 for(int i=0; i<16; i++) pins[i]=NC;
Geremia 21:ae0a4eedfc90 56 for(int i=0; i<8; i++) pins[i]=buspins[i];
Geremia 21:ae0a4eedfc90 57 proto = new BUS8(pins, CS, reset, DC, WR, RD);
Geremia 21:ae0a4eedfc90 58 }
Geremia 21:ae0a4eedfc90 59 else if(displayproto==BUS_16)
Geremia 21:ae0a4eedfc90 60 {
Geremia 21:ae0a4eedfc90 61 proto = new BUS16(buspins, CS, reset, DC, WR, RD);
Geremia 21:ae0a4eedfc90 62 }
Geremia 21:ae0a4eedfc90 63 useNOP=false;
Geremia 21:ae0a4eedfc90 64 scrollbugfix=0;
Geremia 21:ae0a4eedfc90 65 mipistd=false;
Geremia 21:ae0a4eedfc90 66 set_orientation(0);
Geremia 21:ae0a4eedfc90 67 foreground(White);
Geremia 21:ae0a4eedfc90 68 background(Black);
Geremia 21:ae0a4eedfc90 69 set_auto_up(false); //we don't have framebuffer
Geremia 21:ae0a4eedfc90 70 topfixedareasize=0;
Geremia 21:ae0a4eedfc90 71 scrollareasize=0;
Geremia 21:ae0a4eedfc90 72 usefastwindow=false;
Geremia 21:ae0a4eedfc90 73 fastwindowready=false;
Geremia 21:ae0a4eedfc90 74 is18bit=false;
Geremia 21:ae0a4eedfc90 75 isBGR=false;
Geremia 21:ae0a4eedfc90 76 // cls();
Geremia 21:ae0a4eedfc90 77 // locate(0,0);
Geremia 21:ae0a4eedfc90 78 }
Geremia 2:713844a55c4e 79 TFT::TFT(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const char *name)
Geremia 7:bb0383b91104 80 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y)
Geremia 2:713844a55c4e 81 {
Geremia 2:713844a55c4e 82 if(displayproto==SPI_8)
Geremia 2:713844a55c4e 83 {
Geremia 2:713844a55c4e 84 proto = new SPI8(Hz, mosi, miso, sclk, CS, reset, DC);
Geremia 2:713844a55c4e 85 useNOP=false;
Geremia 2:713844a55c4e 86 }
Geremia 2:713844a55c4e 87 else if(displayproto==SPI_16)
Geremia 2:713844a55c4e 88 {
Geremia 2:713844a55c4e 89 proto = new SPI16(Hz, mosi, miso, sclk, CS, reset, DC);
Geremia 2:713844a55c4e 90 useNOP=true;
Geremia 2:713844a55c4e 91 }
Geremia 4:12ba0ecc2c1f 92 scrollbugfix=0;
Geremia 4:12ba0ecc2c1f 93 mipistd=false;
Geremia 2:713844a55c4e 94 set_orientation(0);
Geremia 2:713844a55c4e 95 foreground(White);
Geremia 2:713844a55c4e 96 background(Black);
Geremia 2:713844a55c4e 97 set_auto_up(false);
Geremia 7:bb0383b91104 98 topfixedareasize=0;
Geremia 7:bb0383b91104 99 scrollareasize=0;
Geremia 10:668cf78ff93a 100 usefastwindow=false;
Geremia 10:668cf78ff93a 101 fastwindowready=false;
Geremia 11:b842b8e332cb 102 is18bit=false;
Geremia 11:b842b8e332cb 103 isBGR=false;
Geremia 2:713844a55c4e 104 // locate(0,0);
Geremia 2:713844a55c4e 105 }
Geremia 2:713844a55c4e 106 void TFT::wr_cmd8(unsigned char cmd)
Geremia 2:713844a55c4e 107 {
Geremia 2:713844a55c4e 108 if(useNOP) proto->wr_cmd16(cmd); // 0x0000|cmd, 00 is NOP cmd for TFT
Geremia 2:713844a55c4e 109 else proto->wr_cmd8(cmd);
Geremia 2:713844a55c4e 110 }
Geremia 2:713844a55c4e 111 void TFT::wr_data8(unsigned char data)
Geremia 2:713844a55c4e 112 {
Geremia 2:713844a55c4e 113 proto->wr_data8(data);
Geremia 2:713844a55c4e 114 }
Geremia 2:713844a55c4e 115 void TFT::wr_data16(unsigned short data)
Geremia 2:713844a55c4e 116 {
Geremia 2:713844a55c4e 117 proto->wr_data16(data);
Geremia 2:713844a55c4e 118 }
Geremia 4:12ba0ecc2c1f 119 void TFT::wr_gram(unsigned short data)
Geremia 4:12ba0ecc2c1f 120 {
Geremia 4:12ba0ecc2c1f 121 proto->wr_gram(data);
Geremia 4:12ba0ecc2c1f 122 }
Geremia 4:12ba0ecc2c1f 123 void TFT::wr_gram(unsigned short data, unsigned int count)
Geremia 2:713844a55c4e 124 {
Geremia 4:12ba0ecc2c1f 125 proto->wr_gram(data, count);
Geremia 4:12ba0ecc2c1f 126 }
Geremia 4:12ba0ecc2c1f 127 void TFT::wr_grambuf(unsigned short* data, unsigned int lenght)
Geremia 4:12ba0ecc2c1f 128 {
Geremia 4:12ba0ecc2c1f 129 proto->wr_grambuf(data, lenght);
Geremia 2:713844a55c4e 130 }
Geremia 5:b222a9461d6b 131 unsigned short TFT::rd_gram()
Geremia 5:b222a9461d6b 132 {
Geremia 11:b842b8e332cb 133 return proto->rd_gram(is18bit); // protocol will handle 18to16 bit conversion
Geremia 7:bb0383b91104 134 }
Geremia 7:bb0383b91104 135 unsigned int TFT::rd_reg_data32(unsigned char reg)
Geremia 7:bb0383b91104 136 {
Geremia 7:bb0383b91104 137 return proto->rd_reg_data32(reg);
Geremia 7:bb0383b91104 138 }
Geremia 7:bb0383b91104 139 unsigned int TFT::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd)
Geremia 7:bb0383b91104 140 {
Geremia 7:bb0383b91104 141 return proto->rd_extcreg_data32(reg, SPIreadenablecmd);
Geremia 5:b222a9461d6b 142 }
Geremia 4:12ba0ecc2c1f 143 //for TFT, just send data, position counters are in hw
Geremia 4:12ba0ecc2c1f 144 void TFT::window_pushpixel(unsigned short color)
Geremia 4:12ba0ecc2c1f 145 {
Geremia 4:12ba0ecc2c1f 146 proto->wr_gram(color);
Geremia 4:12ba0ecc2c1f 147 }
Geremia 4:12ba0ecc2c1f 148 void TFT::window_pushpixel(unsigned short color, unsigned int count)
Geremia 4:12ba0ecc2c1f 149 {
Geremia 4:12ba0ecc2c1f 150 proto->wr_gram(color, count);
Geremia 4:12ba0ecc2c1f 151 }
Geremia 4:12ba0ecc2c1f 152 void TFT::window_pushpixelbuf(unsigned short* color, unsigned int lenght)
Geremia 2:713844a55c4e 153 {
Geremia 4:12ba0ecc2c1f 154 proto->wr_grambuf(color, lenght);
Geremia 2:713844a55c4e 155 }
Geremia 2:713844a55c4e 156 void TFT::hw_reset()
Geremia 2:713844a55c4e 157 {
Geremia 2:713844a55c4e 158 proto->hw_reset();
Geremia 20:14daa48ffd4c 159 BusEnable(true);
Geremia 2:713844a55c4e 160 }
Geremia 2:713844a55c4e 161 void TFT::BusEnable(bool enable)
Geremia 2:713844a55c4e 162 {
Geremia 2:713844a55c4e 163 proto->BusEnable(enable);
Geremia 2:713844a55c4e 164 }
Geremia 2:713844a55c4e 165 // color TFT can rotate in hw (swap raw<->columns) for landscape views
Geremia 2:713844a55c4e 166 void TFT::set_orientation(int o)
Geremia 2:713844a55c4e 167 {
Geremia 2:713844a55c4e 168 orientation = o;
Geremia 2:713844a55c4e 169 wr_cmd8(0x36);
Geremia 2:713844a55c4e 170 switch (orientation) {
Geremia 2:713844a55c4e 171 case 0:// default, portrait view 0°
Geremia 2:713844a55c4e 172 if(mipistd) wr_data8(0x0A); // this is in real a vertical flip enabled, seems most displays are vertical flipped
Geremia 3:48f3282c2be8 173 else wr_data8(0x48); //for some other ILIxxxx
Geremia 7:bb0383b91104 174 set_width(screensize_X);
Geremia 7:bb0383b91104 175 set_height(screensize_Y);
Geremia 2:713844a55c4e 176 break;
Geremia 2:713844a55c4e 177 case 1:// landscape view +90°
Geremia 2:713844a55c4e 178 if(mipistd) wr_data8(0x28);
Geremia 3:48f3282c2be8 179 else wr_data8(0x29);//for some other ILIxxxx
Geremia 7:bb0383b91104 180 set_width(screensize_Y);
Geremia 7:bb0383b91104 181 set_height(screensize_X);
Geremia 2:713844a55c4e 182 break;
Geremia 2:713844a55c4e 183 case 2:// portrait view +180°
Geremia 2:713844a55c4e 184 if(mipistd) wr_data8(0x09);
Geremia 3:48f3282c2be8 185 else wr_data8(0x99);//for some other ILIxxxx
Geremia 7:bb0383b91104 186 set_width(screensize_X);
Geremia 7:bb0383b91104 187 set_height(screensize_Y);
Geremia 2:713844a55c4e 188 break;
Geremia 2:713844a55c4e 189 case 3:// landscape view -90°
Geremia 2:713844a55c4e 190 if(mipistd) wr_data8(0x2B);
Geremia 3:48f3282c2be8 191 else wr_data8(0xF8);//for some other ILIxxxx
Geremia 7:bb0383b91104 192 set_width(screensize_Y);
Geremia 7:bb0383b91104 193 set_height(screensize_X);
Geremia 2:713844a55c4e 194 break;
Geremia 2:713844a55c4e 195 }
Geremia 2:713844a55c4e 196 }
Geremia 7:bb0383b91104 197 void TFT::invert(unsigned char o)
Geremia 7:bb0383b91104 198 {
Geremia 7:bb0383b91104 199 if(o == 0) wr_cmd8(0x20);
Geremia 7:bb0383b91104 200 else wr_cmd8(0x21);
Geremia 7:bb0383b91104 201 }
Geremia 10:668cf78ff93a 202 void TFT::FastWindow(bool enable)
Geremia 10:668cf78ff93a 203 {
Geremia 10:668cf78ff93a 204 usefastwindow=enable;
Geremia 10:668cf78ff93a 205 }
Geremia 2:713844a55c4e 206 // TFT have both column and raw autoincrement inside a window, with internal counters
Geremia 2:713844a55c4e 207 void TFT::window(int x, int y, int w, int h)
Geremia 2:713844a55c4e 208 {
Geremia 10:668cf78ff93a 209 fastwindowready=false; // end raw/column going to be set to lower value than bottom-right corner
Geremia 2:713844a55c4e 210 wr_cmd8(0x2A);
Geremia 2:713844a55c4e 211 wr_data16(x); //start column
Geremia 2:713844a55c4e 212 wr_data16(x+w-1);//end column
Geremia 2:713844a55c4e 213
Geremia 2:713844a55c4e 214 wr_cmd8(0x2B);
Geremia 2:713844a55c4e 215 wr_data16(y); //start page
Geremia 2:713844a55c4e 216 wr_data16(y+h-1);//end page
Geremia 2:713844a55c4e 217
Geremia 2:713844a55c4e 218 wr_cmd8(0x2C); //write mem, just send pixels color next
Geremia 2:713844a55c4e 219 }
Geremia 5:b222a9461d6b 220 void TFT::window4read(int x, int y, int w, int h)
Geremia 5:b222a9461d6b 221 {
Geremia 10:668cf78ff93a 222 fastwindowready=false;
Geremia 5:b222a9461d6b 223 wr_cmd8(0x2A);
Geremia 5:b222a9461d6b 224 wr_data16(x); //start column
Geremia 5:b222a9461d6b 225 wr_data16(x+w-1);//end column
Geremia 5:b222a9461d6b 226
Geremia 5:b222a9461d6b 227 wr_cmd8(0x2B);
Geremia 5:b222a9461d6b 228 wr_data16(y); //start page
Geremia 5:b222a9461d6b 229 wr_data16(y+h-1);//end page
Geremia 5:b222a9461d6b 230
Geremia 5:b222a9461d6b 231 wr_cmd8(0x2E); //read mem, just pixelread next
Geremia 5:b222a9461d6b 232 }
Geremia 2:713844a55c4e 233 void TFT::pixel(int x, int y, unsigned short color)
Geremia 2:713844a55c4e 234 {
Geremia 10:668cf78ff93a 235 if(usefastwindow) //ili9486 does not like truncated 2A/2B cmds, at least in par mode
Geremia 10:668cf78ff93a 236 {
Geremia 10:668cf78ff93a 237 if(fastwindowready) //setting only start column/page does speedup, but needs end raw/column previously set to bottom-right corner
Geremia 10:668cf78ff93a 238 {
Geremia 10:668cf78ff93a 239 wr_cmd8(0x2A);
Geremia 10:668cf78ff93a 240 wr_data16(x); //start column only
Geremia 10:668cf78ff93a 241 wr_cmd8(0x2B);
Geremia 10:668cf78ff93a 242 wr_data16(y); //start page only
Geremia 10:668cf78ff93a 243 wr_cmd8(0x2C); //write mem, just send pixels color next
Geremia 10:668cf78ff93a 244 }
Geremia 10:668cf78ff93a 245 else
Geremia 10:668cf78ff93a 246 {
Geremia 10:668cf78ff93a 247 window(x,y,width()-x,height()-y); // set also end raw/column to bottom-right corner
Geremia 10:668cf78ff93a 248 fastwindowready=true;
Geremia 10:668cf78ff93a 249 }
Geremia 10:668cf78ff93a 250 }
Geremia 10:668cf78ff93a 251 else window(x,y,1,1);
Geremia 4:12ba0ecc2c1f 252 // proto->wr_gram(color); // 2C expects 16bit parameters
Geremia 4:12ba0ecc2c1f 253 wr_gram(color);
Geremia 2:713844a55c4e 254 }
Geremia 5:b222a9461d6b 255 unsigned short TFT::pixelread(int x, int y)
Geremia 5:b222a9461d6b 256 {
Geremia 10:668cf78ff93a 257 if(usefastwindow) //ili9486 does not like truncated 2A/2B cmds, at least in par mode
Geremia 10:668cf78ff93a 258 {
Geremia 10:668cf78ff93a 259 if(fastwindowready) //setting only start column/page does speedup, but needs end raw/column previously set to bottom-right corner
Geremia 10:668cf78ff93a 260 {
Geremia 10:668cf78ff93a 261 wr_cmd8(0x2A);
Geremia 10:668cf78ff93a 262 wr_data16(x); //start column only
Geremia 10:668cf78ff93a 263 wr_cmd8(0x2B);
Geremia 10:668cf78ff93a 264 wr_data16(y); //start page only
Geremia 10:668cf78ff93a 265 wr_cmd8(0x2E); //read mem, just pixelread next
Geremia 10:668cf78ff93a 266 }
Geremia 10:668cf78ff93a 267 else
Geremia 10:668cf78ff93a 268 {
Geremia 10:668cf78ff93a 269 window4read(x,y,width()-x,height()-y); // set also end raw/column to bottom-right corner
Geremia 10:668cf78ff93a 270 fastwindowready=true;
Geremia 10:668cf78ff93a 271 }
Geremia 10:668cf78ff93a 272 }
Geremia 10:668cf78ff93a 273 else window4read(x,y,1,1);
Geremia 10:668cf78ff93a 274
Geremia 5:b222a9461d6b 275 unsigned short color;
Geremia 5:b222a9461d6b 276 // proto->wr_gram(color); // 2C expects 16bit parameters
Geremia 5:b222a9461d6b 277 color = rd_gram();
Geremia 11:b842b8e332cb 278 if(isBGR) color = BGR2RGB(color); // in case, convert BGR to RGB (should depend on cmd36 bit3) but maybe is device specific
Geremia 5:b222a9461d6b 279 return color;
Geremia 5:b222a9461d6b 280 }
Geremia 7:bb0383b91104 281 void TFT::setscrollarea (int startY, int areasize) // ie 0,480 for whole screen
Geremia 7:bb0383b91104 282 {
Geremia 7:bb0383b91104 283 unsigned int bfa;
Geremia 7:bb0383b91104 284 topfixedareasize=startY;
Geremia 7:bb0383b91104 285 scrollareasize=areasize;
Geremia 7:bb0383b91104 286 wr_cmd8(0x33);
Geremia 7:bb0383b91104 287 wr_data16(topfixedareasize); //num lines of top fixed area
Geremia 7:bb0383b91104 288 wr_data16(scrollareasize+scrollbugfix); //num lines of vertical scroll area, +1 for ILI9481 fix
Geremia 8:26757296c79d 289 if((areasize+startY)>screensize_Y) bfa=0;
Geremia 8:26757296c79d 290 else bfa = screensize_Y-(areasize+startY);
Geremia 7:bb0383b91104 291 wr_data16(bfa); //num lines of bottom fixed area
Geremia 7:bb0383b91104 292 }
Geremia 7:bb0383b91104 293 void TFT::scroll (int lines) // ie 1= scrollup 1, 479= scrolldown 1
Geremia 7:bb0383b91104 294 {
Geremia 7:bb0383b91104 295 wr_cmd8(0x37);
Geremia 8:26757296c79d 296 wr_data16(topfixedareasize+(lines%scrollareasize)); // select the (absolute)line which will be displayed as first scrollarea line
Geremia 7:bb0383b91104 297 }
Geremia 7:bb0383b91104 298 void TFT::scrollreset()
Geremia 7:bb0383b91104 299 {
Geremia 7:bb0383b91104 300 wr_cmd8(0x13); //normal display mode
Geremia 7:bb0383b91104 301 }
Geremia 2:713844a55c4e 302 void TFT::cls (void)
Geremia 2:713844a55c4e 303 {
Geremia 2:713844a55c4e 304 WindowMax();
Geremia 7:bb0383b91104 305 // proto->wr_gram(_background,screensize_X*screensize_Y);
Geremia 7:bb0383b91104 306 // proto->wr_gram(0,screensize_X*screensize_Y);
Geremia 7:bb0383b91104 307 wr_gram(_background,screensize_X*screensize_Y);
Geremia 7:bb0383b91104 308 }
Geremia 11:b842b8e332cb 309 // try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR
Geremia 11:b842b8e332cb 310 void TFT::auto_gram_read_format()
Geremia 11:b842b8e332cb 311 {
Geremia 11:b842b8e332cb 312 unsigned short px=0xCDB1;
Geremia 11:b842b8e332cb 313 unsigned short rback, rback18;
Geremia 11:b842b8e332cb 314 pixel(0,0,px);
Geremia 11:b842b8e332cb 315 window4read(0,0,1,1);
Geremia 11:b842b8e332cb 316 rback=proto->rd_gram(0); // try 16bit
Geremia 11:b842b8e332cb 317 window4read(0,0,1,1);
Geremia 11:b842b8e332cb 318 rback18=proto->rd_gram(1); // try 18bit converted to 16
Geremia 11:b842b8e332cb 319 if((rback18==px) || (BGR2RGB(rback18)==px))
Geremia 11:b842b8e332cb 320 {
Geremia 11:b842b8e332cb 321 is18bit=true;
Geremia 11:b842b8e332cb 322 if(BGR2RGB(rback18)==px) isBGR=true;
Geremia 11:b842b8e332cb 323 }
Geremia 11:b842b8e332cb 324 else if((rback==px) || (BGR2RGB(rback)==px))
Geremia 11:b842b8e332cb 325 {
Geremia 11:b842b8e332cb 326 if(BGR2RGB(rback)==px) isBGR=true;
Geremia 11:b842b8e332cb 327 }
Geremia 20:14daa48ffd4c 328 // 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 11:b842b8e332cb 329 }
Geremia 7:bb0383b91104 330 // try to identify display controller
Geremia 7:bb0383b91104 331 void TFT::identify()
Geremia 7:bb0383b91104 332 {
Geremia 7:bb0383b91104 333 // MIPI std read ID cmd
Geremia 7:bb0383b91104 334 tftID=rd_reg_data32(0xBF);
Geremia 7:bb0383b91104 335 mipistd=true;
Geremia 7:bb0383b91104 336 // debug("ID MIPI : 0x%8X\r\n",tftID);
Geremia 7:bb0383b91104 337 if(((tftID&0xFF)==((tftID>>8)&0xFF)) && ((tftID&0xFF)==((tftID>>16)&0xFF)))
Geremia 7:bb0383b91104 338 {
Geremia 7:bb0383b91104 339 mipistd=false;
Geremia 7:bb0383b91104 340 // ILI specfic read ID cmd
Geremia 7:bb0383b91104 341 tftID=rd_reg_data32(0xD3)>>8;
Geremia 7:bb0383b91104 342 // debug("ID ILI : 0x%8X\r\n",tftID);
Geremia 7:bb0383b91104 343 }
Geremia 7:bb0383b91104 344 if(((tftID&0xFF)==((tftID>>8)&0xFF)) && ((tftID&0xFF)==((tftID>>16)&0xFF)))
Geremia 7:bb0383b91104 345 {
Geremia 7:bb0383b91104 346 // ILI specfic read ID cmd with ili9341 specific spi read-in enable 0xD9 cmd
Geremia 7:bb0383b91104 347 tftID=rd_extcreg_data32(0xD3, 0xD9);
Geremia 7:bb0383b91104 348 // debug("ID D9 extc ILI : 0x%8X\r\n",tftID);
Geremia 7:bb0383b91104 349 }
Geremia 7:bb0383b91104 350 if(((tftID&0xFF)==((tftID>>8)&0xFF)) && ((tftID&0xFF)==((tftID>>16)&0xFF)))
Geremia 7:bb0383b91104 351 {
Geremia 7:bb0383b91104 352 // ILI specfic read ID cmd with ili9486/88 specific spi read-in enable 0xFB cmd
Geremia 7:bb0383b91104 353 tftID=rd_extcreg_data32(0xD3, 0xFB);
Geremia 7:bb0383b91104 354 // debug("ID D9 extc ILI : 0x%8X\r\n",tftID);
Geremia 7:bb0383b91104 355 }
Geremia 7:bb0383b91104 356 if(((tftID&0xFF)==((tftID>>8)&0xFF)) && ((tftID&0xFF)==((tftID>>16)&0xFF))) tftID=0xDEAD;
Geremia 7:bb0383b91104 357 if ((tftID&0xFFFF)==0x9481) scrollbugfix=1;
Geremia 7:bb0383b91104 358 else scrollbugfix=0;
Geremia 7:bb0383b91104 359 hw_reset(); // in case wrong cmds messed up important settings
Geremia 7:bb0383b91104 360 }
Geremia 7:bb0383b91104 361 int TFT::sizeX()
Geremia 7:bb0383b91104 362 {
Geremia 7:bb0383b91104 363 return screensize_X;
Geremia 7:bb0383b91104 364 }
Geremia 7:bb0383b91104 365 int TFT::sizeY()
Geremia 7:bb0383b91104 366 {
Geremia 7:bb0383b91104 367 return screensize_Y;
Geremia 2:713844a55c4e 368 }