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