Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Dependents:   testUniGraphic_150217 maze_TFT_MMA8451Q TFT_test_frdm-kl25z TFT_test_NUCLEO-F411RE ... more

Committer:
dreschpe
Date:
Sun Oct 18 13:53:20 2015 +0000
Revision:
25:daacdcf34e52
Parent:
21:ae0a4eedfc90
Child:
27:acb2594b8aa4
Add check if platform supports par port mode

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