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