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