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