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: afero_poc15_180216 afero_poc15_180223 afero_poc15_180302 afero_poc15_180403R ... more
Fork of UniGraphic by
UniGraphic for La Suno Version.
To go with La Suno, WatchDog Reset functions were added in ILI9341.
Display/TFT.cpp@4:12ba0ecc2c1f, 2015-02-15 (annotated)
- Committer:
- Geremia
- Date:
- Sun Feb 15 20:06:07 2015 +0000
- Revision:
- 4:12ba0ecc2c1f
- Parent:
- 3:48f3282c2be8
- Child:
- 5:b222a9461d6b
Added PAR16, separated 16bit writes for cmd parameters and pixeldata
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 | 2:713844a55c4e | 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 | 2:713844a55c4e | 26 | : GraphicsDisplay(name), LCDSIZE_X(lcdsize_x), LCDSIZE_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 | 2:713844a55c4e | 37 | // cls(); |
Geremia | 2:713844a55c4e | 38 | // locate(0,0); |
Geremia | 2:713844a55c4e | 39 | } |
Geremia | 2:713844a55c4e | 40 | 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 | 2:713844a55c4e | 41 | : GraphicsDisplay(name), LCDSIZE_X(lcdsize_x), LCDSIZE_Y(lcdsize_y) |
Geremia | 2:713844a55c4e | 42 | { |
Geremia | 2:713844a55c4e | 43 | if(displayproto==SPI_8) |
Geremia | 2:713844a55c4e | 44 | { |
Geremia | 2:713844a55c4e | 45 | proto = new SPI8(Hz, mosi, miso, sclk, CS, reset, DC); |
Geremia | 2:713844a55c4e | 46 | useNOP=false; |
Geremia | 2:713844a55c4e | 47 | } |
Geremia | 2:713844a55c4e | 48 | else if(displayproto==SPI_16) |
Geremia | 2:713844a55c4e | 49 | { |
Geremia | 2:713844a55c4e | 50 | proto = new SPI16(Hz, mosi, miso, sclk, CS, reset, DC); |
Geremia | 2:713844a55c4e | 51 | useNOP=true; |
Geremia | 2:713844a55c4e | 52 | } |
Geremia | 4:12ba0ecc2c1f | 53 | scrollbugfix=0; |
Geremia | 4:12ba0ecc2c1f | 54 | mipistd=false; |
Geremia | 2:713844a55c4e | 55 | set_orientation(0); |
Geremia | 2:713844a55c4e | 56 | foreground(White); |
Geremia | 2:713844a55c4e | 57 | background(Black); |
Geremia | 2:713844a55c4e | 58 | set_auto_up(false); |
Geremia | 2:713844a55c4e | 59 | // locate(0,0); |
Geremia | 2:713844a55c4e | 60 | } |
Geremia | 2:713844a55c4e | 61 | void TFT::wr_cmd8(unsigned char cmd) |
Geremia | 2:713844a55c4e | 62 | { |
Geremia | 2:713844a55c4e | 63 | if(useNOP) proto->wr_cmd16(cmd); // 0x0000|cmd, 00 is NOP cmd for TFT |
Geremia | 2:713844a55c4e | 64 | else proto->wr_cmd8(cmd); |
Geremia | 2:713844a55c4e | 65 | } |
Geremia | 2:713844a55c4e | 66 | void TFT::wr_data8(unsigned char data) |
Geremia | 2:713844a55c4e | 67 | { |
Geremia | 2:713844a55c4e | 68 | proto->wr_data8(data); |
Geremia | 2:713844a55c4e | 69 | } |
Geremia | 2:713844a55c4e | 70 | void TFT::wr_data16(unsigned short data) |
Geremia | 2:713844a55c4e | 71 | { |
Geremia | 2:713844a55c4e | 72 | proto->wr_data16(data); |
Geremia | 2:713844a55c4e | 73 | } |
Geremia | 4:12ba0ecc2c1f | 74 | void TFT::wr_gram(unsigned short data) |
Geremia | 4:12ba0ecc2c1f | 75 | { |
Geremia | 4:12ba0ecc2c1f | 76 | proto->wr_gram(data); |
Geremia | 4:12ba0ecc2c1f | 77 | } |
Geremia | 4:12ba0ecc2c1f | 78 | void TFT::wr_gram(unsigned short data, unsigned int count) |
Geremia | 2:713844a55c4e | 79 | { |
Geremia | 4:12ba0ecc2c1f | 80 | proto->wr_gram(data, count); |
Geremia | 4:12ba0ecc2c1f | 81 | } |
Geremia | 4:12ba0ecc2c1f | 82 | void TFT::wr_grambuf(unsigned short* data, unsigned int lenght) |
Geremia | 4:12ba0ecc2c1f | 83 | { |
Geremia | 4:12ba0ecc2c1f | 84 | proto->wr_grambuf(data, lenght); |
Geremia | 2:713844a55c4e | 85 | } |
Geremia | 4:12ba0ecc2c1f | 86 | //for TFT, just send data, position counters are in hw |
Geremia | 4:12ba0ecc2c1f | 87 | void TFT::window_pushpixel(unsigned short color) |
Geremia | 4:12ba0ecc2c1f | 88 | { |
Geremia | 4:12ba0ecc2c1f | 89 | proto->wr_gram(color); |
Geremia | 4:12ba0ecc2c1f | 90 | } |
Geremia | 4:12ba0ecc2c1f | 91 | void TFT::window_pushpixel(unsigned short color, unsigned int count) |
Geremia | 4:12ba0ecc2c1f | 92 | { |
Geremia | 4:12ba0ecc2c1f | 93 | proto->wr_gram(color, count); |
Geremia | 4:12ba0ecc2c1f | 94 | } |
Geremia | 4:12ba0ecc2c1f | 95 | void TFT::window_pushpixelbuf(unsigned short* color, unsigned int lenght) |
Geremia | 2:713844a55c4e | 96 | { |
Geremia | 4:12ba0ecc2c1f | 97 | proto->wr_grambuf(color, lenght); |
Geremia | 2:713844a55c4e | 98 | } |
Geremia | 2:713844a55c4e | 99 | void TFT::hw_reset() |
Geremia | 2:713844a55c4e | 100 | { |
Geremia | 2:713844a55c4e | 101 | proto->hw_reset(); |
Geremia | 2:713844a55c4e | 102 | } |
Geremia | 2:713844a55c4e | 103 | void TFT::BusEnable(bool enable) |
Geremia | 2:713844a55c4e | 104 | { |
Geremia | 2:713844a55c4e | 105 | proto->BusEnable(enable); |
Geremia | 2:713844a55c4e | 106 | } |
Geremia | 2:713844a55c4e | 107 | // color TFT can rotate in hw (swap raw<->columns) for landscape views |
Geremia | 2:713844a55c4e | 108 | void TFT::set_orientation(int o) |
Geremia | 2:713844a55c4e | 109 | { |
Geremia | 2:713844a55c4e | 110 | orientation = o; |
Geremia | 2:713844a55c4e | 111 | wr_cmd8(0x36); |
Geremia | 2:713844a55c4e | 112 | switch (orientation) { |
Geremia | 2:713844a55c4e | 113 | case 0:// default, portrait view 0° |
Geremia | 2:713844a55c4e | 114 | if(mipistd) wr_data8(0x0A); // this is in real a vertical flip enabled, seems most displays are vertical flipped |
Geremia | 3:48f3282c2be8 | 115 | else wr_data8(0x48); //for some other ILIxxxx |
Geremia | 2:713844a55c4e | 116 | set_width(LCDSIZE_X); |
Geremia | 2:713844a55c4e | 117 | set_height(LCDSIZE_Y); |
Geremia | 2:713844a55c4e | 118 | break; |
Geremia | 2:713844a55c4e | 119 | case 1:// landscape view +90° |
Geremia | 2:713844a55c4e | 120 | if(mipistd) wr_data8(0x28); |
Geremia | 3:48f3282c2be8 | 121 | else wr_data8(0x29);//for some other ILIxxxx |
Geremia | 2:713844a55c4e | 122 | set_width(LCDSIZE_Y); |
Geremia | 2:713844a55c4e | 123 | set_height(LCDSIZE_X); |
Geremia | 2:713844a55c4e | 124 | break; |
Geremia | 2:713844a55c4e | 125 | case 2:// portrait view +180° |
Geremia | 2:713844a55c4e | 126 | if(mipistd) wr_data8(0x09); |
Geremia | 3:48f3282c2be8 | 127 | else wr_data8(0x99);//for some other ILIxxxx |
Geremia | 2:713844a55c4e | 128 | set_width(LCDSIZE_X); |
Geremia | 2:713844a55c4e | 129 | set_height(LCDSIZE_Y); |
Geremia | 2:713844a55c4e | 130 | break; |
Geremia | 2:713844a55c4e | 131 | case 3:// landscape view -90° |
Geremia | 2:713844a55c4e | 132 | if(mipistd) wr_data8(0x2B); |
Geremia | 3:48f3282c2be8 | 133 | else wr_data8(0xF8);//for some other ILIxxxx |
Geremia | 2:713844a55c4e | 134 | set_width(LCDSIZE_Y); |
Geremia | 2:713844a55c4e | 135 | set_height(LCDSIZE_X); |
Geremia | 2:713844a55c4e | 136 | break; |
Geremia | 2:713844a55c4e | 137 | } |
Geremia | 2:713844a55c4e | 138 | } |
Geremia | 2:713844a55c4e | 139 | // TFT have both column and raw autoincrement inside a window, with internal counters |
Geremia | 2:713844a55c4e | 140 | void TFT::window(int x, int y, int w, int h) |
Geremia | 2:713844a55c4e | 141 | { |
Geremia | 2:713844a55c4e | 142 | //ili9486 does not like truncated 2A/2B cmds, at least in par mode |
Geremia | 2:713844a55c4e | 143 | //setting only start column/page would speedup, but needs a windowmax() before, maybe implement later |
Geremia | 3:48f3282c2be8 | 144 | //fixme for PAR_16: // cmd 2A/2B expects 8bit parameters |
Geremia | 2:713844a55c4e | 145 | wr_cmd8(0x2A); |
Geremia | 2:713844a55c4e | 146 | wr_data16(x); //start column |
Geremia | 2:713844a55c4e | 147 | wr_data16(x+w-1);//end column |
Geremia | 2:713844a55c4e | 148 | |
Geremia | 2:713844a55c4e | 149 | wr_cmd8(0x2B); |
Geremia | 2:713844a55c4e | 150 | wr_data16(y); //start page |
Geremia | 2:713844a55c4e | 151 | wr_data16(y+h-1);//end page |
Geremia | 2:713844a55c4e | 152 | |
Geremia | 2:713844a55c4e | 153 | wr_cmd8(0x2C); //write mem, just send pixels color next |
Geremia | 2:713844a55c4e | 154 | } |
Geremia | 2:713844a55c4e | 155 | void TFT::pixel(int x, int y, unsigned short color) |
Geremia | 2:713844a55c4e | 156 | { |
Geremia | 2:713844a55c4e | 157 | window(x,y,1,1); |
Geremia | 4:12ba0ecc2c1f | 158 | // proto->wr_gram(color); // 2C expects 16bit parameters |
Geremia | 4:12ba0ecc2c1f | 159 | wr_gram(color); |
Geremia | 2:713844a55c4e | 160 | } |
Geremia | 2:713844a55c4e | 161 | void TFT::cls (void) |
Geremia | 2:713844a55c4e | 162 | { |
Geremia | 2:713844a55c4e | 163 | WindowMax(); |
Geremia | 4:12ba0ecc2c1f | 164 | // proto->wr_gram(_background,LCDSIZE_X*LCDSIZE_Y); |
Geremia | 4:12ba0ecc2c1f | 165 | // proto->wr_gram(0,LCDSIZE_X*LCDSIZE_Y); |
Geremia | 4:12ba0ecc2c1f | 166 | wr_gram(_background,LCDSIZE_X*LCDSIZE_Y); |
Geremia | 2:713844a55c4e | 167 | } |