Lib for the new LCD Display with ILI9341 controller supporting two displays
Dependents: CANary_9341_test CANary_9341 CANary
Fork of SPI_TFT_ILI9341 by
SPI_TFTx2_ILI9341.cpp@10:aca12a61d2b1, 2014-05-18 (annotated)
- Committer:
- TickTock
- Date:
- Sun May 18 12:45:24 2014 +0000
- Revision:
- 10:aca12a61d2b1
- Parent:
- 9:522e742e62eb
Works with both controllers using precompiler directive
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:da1bf437cbc1 | 1 | /* mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller |
dreschpe | 0:da1bf437cbc1 | 2 | * Copyright (c) 2013 Peter Drescher - DC2PD |
TickTock | 10:aca12a61d2b1 | 3 | * Updated by Yoong HM for maintaining SPI_TFTx2 and SPI_TFTx2_ILI9341 in the |
TickTock | 10:aca12a61d2b1 | 4 | * same code directory. |
dreschpe | 0:da1bf437cbc1 | 5 | * |
dreschpe | 0:da1bf437cbc1 | 6 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dreschpe | 0:da1bf437cbc1 | 7 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dreschpe | 0:da1bf437cbc1 | 8 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dreschpe | 0:da1bf437cbc1 | 9 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dreschpe | 0:da1bf437cbc1 | 10 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dreschpe | 0:da1bf437cbc1 | 11 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
dreschpe | 0:da1bf437cbc1 | 12 | * THE SOFTWARE. |
dreschpe | 0:da1bf437cbc1 | 13 | */ |
TickTock | 10:aca12a61d2b1 | 14 | |
TickTock | 8:66cf46ec1225 | 15 | // 12.06.13 fork from SPI_TFTx2 code because controller is different ... |
TickTock | 10:aca12a61d2b1 | 16 | // 14.07.13 Test with real display and bugfix |
dreschpe | 4:f018e272220b | 17 | // 18.10.13 Better Circle function from Michael Ammann |
dreschpe | 5:55aed13f2630 | 18 | // 22.10.13 Fixes for Kinetis Board - 8 bit spi |
dreschpe | 6:fe07ae8329f7 | 19 | // 26.01.14 Change interface for BMP_16 to also use SD-cards |
TickTock | 10:aca12a61d2b1 | 20 | // 13.05.14 Change the class name to SPI_TFTx2_ILI9341 |
dreschpe | 0:da1bf437cbc1 | 21 | |
TickTock | 8:66cf46ec1225 | 22 | #include "SPI_TFTx2_ILI9341.h" |
dreschpe | 0:da1bf437cbc1 | 23 | #include "mbed.h" |
dreschpe | 0:da1bf437cbc1 | 24 | |
TickTock | 10:aca12a61d2b1 | 25 | #define BPP 16 // Bits per pixel |
TickTock | 10:aca12a61d2b1 | 26 | |
dreschpe | 0:da1bf437cbc1 | 27 | //extern Serial pc; |
dreschpe | 0:da1bf437cbc1 | 28 | //extern DigitalOut xx; // debug !! |
dreschpe | 0:da1bf437cbc1 | 29 | |
TickTock | 10:aca12a61d2b1 | 30 | SPI_TFTx2_ILI9341::SPI_TFTx2_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs0, PinName cs1, PinName reset, PinName dc, const char *name) |
TickTock | 9:522e742e62eb | 31 | : _spi(mosi, miso, sclk), _cs0(cs0), _cs1(cs1), _reset(reset), _dc(dc), GraphicsDisplay(name) |
dreschpe | 0:da1bf437cbc1 | 32 | { |
dreschpe | 6:fe07ae8329f7 | 33 | clk = sclk; |
dreschpe | 0:da1bf437cbc1 | 34 | orientation = 0; |
dreschpe | 0:da1bf437cbc1 | 35 | char_x = 0; |
TickTock | 9:522e742e62eb | 36 | seldisp = 2; |
dreschpe | 0:da1bf437cbc1 | 37 | tft_reset(); |
dreschpe | 0:da1bf437cbc1 | 38 | } |
dreschpe | 0:da1bf437cbc1 | 39 | |
TickTock | 10:aca12a61d2b1 | 40 | int SPI_TFTx2_ILI9341::width() |
dreschpe | 0:da1bf437cbc1 | 41 | { |
dreschpe | 0:da1bf437cbc1 | 42 | if (orientation == 0 || orientation == 2) return 240; |
dreschpe | 0:da1bf437cbc1 | 43 | else return 320; |
dreschpe | 0:da1bf437cbc1 | 44 | } |
dreschpe | 0:da1bf437cbc1 | 45 | |
dreschpe | 0:da1bf437cbc1 | 46 | |
TickTock | 10:aca12a61d2b1 | 47 | int SPI_TFTx2_ILI9341::height() |
dreschpe | 0:da1bf437cbc1 | 48 | { |
dreschpe | 0:da1bf437cbc1 | 49 | if (orientation == 0 || orientation == 2) return 320; |
dreschpe | 0:da1bf437cbc1 | 50 | else return 240; |
dreschpe | 0:da1bf437cbc1 | 51 | } |
dreschpe | 0:da1bf437cbc1 | 52 | |
dreschpe | 0:da1bf437cbc1 | 53 | |
TickTock | 10:aca12a61d2b1 | 54 | void SPI_TFTx2_ILI9341::set_orientation(unsigned int o) |
dreschpe | 0:da1bf437cbc1 | 55 | { |
dreschpe | 0:da1bf437cbc1 | 56 | orientation = o; |
dreschpe | 2:0a16083193a4 | 57 | wr_cmd(0x36); // MEMORY_ACCESS_CONTROL |
dreschpe | 0:da1bf437cbc1 | 58 | switch (orientation) { |
dreschpe | 0:da1bf437cbc1 | 59 | case 0: |
dreschpe | 2:0a16083193a4 | 60 | _spi.write(0x48); |
dreschpe | 0:da1bf437cbc1 | 61 | break; |
dreschpe | 0:da1bf437cbc1 | 62 | case 1: |
dreschpe | 2:0a16083193a4 | 63 | _spi.write(0x28); |
dreschpe | 0:da1bf437cbc1 | 64 | break; |
dreschpe | 0:da1bf437cbc1 | 65 | case 2: |
dreschpe | 2:0a16083193a4 | 66 | _spi.write(0x88); |
dreschpe | 0:da1bf437cbc1 | 67 | break; |
dreschpe | 0:da1bf437cbc1 | 68 | case 3: |
dreschpe | 2:0a16083193a4 | 69 | _spi.write(0xE8); |
dreschpe | 0:da1bf437cbc1 | 70 | break; |
dreschpe | 0:da1bf437cbc1 | 71 | } |
TickTock | 10:aca12a61d2b1 | 72 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 73 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 74 | WindowMax(); |
TickTock | 10:aca12a61d2b1 | 75 | } |
dreschpe | 0:da1bf437cbc1 | 76 | |
TickTock | 10:aca12a61d2b1 | 77 | void SPI_TFTx2_ILI9341::set_display(unsigned int o) |
TickTock | 9:522e742e62eb | 78 | { |
TickTock | 9:522e742e62eb | 79 | seldisp = o; |
TickTock | 9:522e742e62eb | 80 | } |
dreschpe | 0:da1bf437cbc1 | 81 | |
dreschpe | 0:da1bf437cbc1 | 82 | // write command to tft register |
dreschpe | 0:da1bf437cbc1 | 83 | |
TickTock | 10:aca12a61d2b1 | 84 | void SPI_TFTx2_ILI9341::wr_cmd(unsigned char cmd) |
dreschpe | 0:da1bf437cbc1 | 85 | { |
dreschpe | 0:da1bf437cbc1 | 86 | _dc = 0; |
TickTock | 9:522e742e62eb | 87 | if (seldisp == 0) { |
TickTock | 9:522e742e62eb | 88 | _cs0 = 0; |
TickTock | 9:522e742e62eb | 89 | _cs1 = 1; |
TickTock | 9:522e742e62eb | 90 | } else if (seldisp == 1) { |
TickTock | 9:522e742e62eb | 91 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 92 | _cs1 = 0; |
TickTock | 9:522e742e62eb | 93 | } else { |
TickTock | 9:522e742e62eb | 94 | _cs0 = 0; |
TickTock | 9:522e742e62eb | 95 | _cs1 = 0; |
TickTock | 9:522e742e62eb | 96 | } |
dreschpe | 0:da1bf437cbc1 | 97 | _spi.write(cmd); // mbed lib |
dreschpe | 0:da1bf437cbc1 | 98 | _dc = 1; |
dreschpe | 0:da1bf437cbc1 | 99 | } |
dreschpe | 0:da1bf437cbc1 | 100 | |
dreschpe | 0:da1bf437cbc1 | 101 | |
dreschpe | 0:da1bf437cbc1 | 102 | |
TickTock | 10:aca12a61d2b1 | 103 | void SPI_TFTx2_ILI9341::wr_dat(unsigned char dat) |
dreschpe | 0:da1bf437cbc1 | 104 | { |
TickTock | 9:522e742e62eb | 105 | if (seldisp == 0) { |
TickTock | 9:522e742e62eb | 106 | _cs0 = 0; |
TickTock | 9:522e742e62eb | 107 | _cs1 = 1; |
TickTock | 9:522e742e62eb | 108 | } else if (seldisp == 1) { |
TickTock | 9:522e742e62eb | 109 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 110 | _cs1 = 0; |
TickTock | 9:522e742e62eb | 111 | } else { |
TickTock | 9:522e742e62eb | 112 | _cs0 = 0; |
TickTock | 9:522e742e62eb | 113 | _cs1 = 0; |
TickTock | 9:522e742e62eb | 114 | } |
TickTock | 9:522e742e62eb | 115 | _spi.write(dat); // mbed lib |
dreschpe | 0:da1bf437cbc1 | 116 | } |
dreschpe | 0:da1bf437cbc1 | 117 | |
dreschpe | 0:da1bf437cbc1 | 118 | |
dreschpe | 0:da1bf437cbc1 | 119 | |
TickTock | 10:aca12a61d2b1 | 120 | // the ILI9341 can read |
dreschpe | 6:fe07ae8329f7 | 121 | |
TickTock | 10:aca12a61d2b1 | 122 | char SPI_TFTx2_ILI9341::rd_byte(unsigned char cmd) |
dreschpe | 6:fe07ae8329f7 | 123 | { |
dreschpe | 6:fe07ae8329f7 | 124 | char r; |
dreschpe | 6:fe07ae8329f7 | 125 | _dc = 0; |
TickTock | 9:522e742e62eb | 126 | if (seldisp == 0) { |
TickTock | 9:522e742e62eb | 127 | _cs0 = 0; |
TickTock | 9:522e742e62eb | 128 | _cs1 = 1; |
TickTock | 9:522e742e62eb | 129 | } else if (seldisp == 1) { |
TickTock | 9:522e742e62eb | 130 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 131 | _cs1 = 0; |
TickTock | 9:522e742e62eb | 132 | } else { |
TickTock | 9:522e742e62eb | 133 | _cs0 = 0; |
TickTock | 9:522e742e62eb | 134 | _cs1 = 0; |
TickTock | 9:522e742e62eb | 135 | } |
dreschpe | 6:fe07ae8329f7 | 136 | _spi.write(cmd); // mbed lib |
TickTock | 9:522e742e62eb | 137 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 138 | _cs1 = 1; |
dreschpe | 6:fe07ae8329f7 | 139 | r = _spi.write(0xff); |
TickTock | 9:522e742e62eb | 140 | _cs0 = 1; |
TickTock | 10:aca12a61d2b1 | 141 | _cs1 = 1; |
dreschpe | 6:fe07ae8329f7 | 142 | return(r); |
dreschpe | 6:fe07ae8329f7 | 143 | } |
dreschpe | 0:da1bf437cbc1 | 144 | |
dreschpe | 6:fe07ae8329f7 | 145 | // read 32 bit |
TickTock | 10:aca12a61d2b1 | 146 | int SPI_TFTx2_ILI9341::rd_32(unsigned char cmd) |
dreschpe | 6:fe07ae8329f7 | 147 | { |
dreschpe | 6:fe07ae8329f7 | 148 | int d; |
dreschpe | 6:fe07ae8329f7 | 149 | char r; |
dreschpe | 6:fe07ae8329f7 | 150 | _dc = 0; |
TickTock | 9:522e742e62eb | 151 | if (seldisp == 0) { |
TickTock | 9:522e742e62eb | 152 | _cs0 = 0; |
TickTock | 9:522e742e62eb | 153 | _cs1 = 1; |
TickTock | 9:522e742e62eb | 154 | } else if (seldisp == 1) { |
TickTock | 9:522e742e62eb | 155 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 156 | _cs1 = 0; |
TickTock | 9:522e742e62eb | 157 | } else { |
TickTock | 9:522e742e62eb | 158 | _cs0 = 0; |
TickTock | 9:522e742e62eb | 159 | _cs1 = 0; |
TickTock | 9:522e742e62eb | 160 | } |
dreschpe | 6:fe07ae8329f7 | 161 | d = cmd; |
dreschpe | 6:fe07ae8329f7 | 162 | d = d << 1; |
dreschpe | 6:fe07ae8329f7 | 163 | _spi.format(9,3); // we have to add a dummy clock cycle |
dreschpe | 6:fe07ae8329f7 | 164 | _spi.write(d); |
TickTock | 10:aca12a61d2b1 | 165 | _spi.format(8,3); |
dreschpe | 6:fe07ae8329f7 | 166 | _dc = 1; |
dreschpe | 6:fe07ae8329f7 | 167 | r = _spi.write(0xff); |
dreschpe | 6:fe07ae8329f7 | 168 | d = r; |
dreschpe | 6:fe07ae8329f7 | 169 | r = _spi.write(0xff); |
dreschpe | 6:fe07ae8329f7 | 170 | d = (d << 8) | r; |
dreschpe | 6:fe07ae8329f7 | 171 | r = _spi.write(0xff); |
dreschpe | 6:fe07ae8329f7 | 172 | d = (d << 8) | r; |
dreschpe | 6:fe07ae8329f7 | 173 | r = _spi.write(0xff); |
dreschpe | 6:fe07ae8329f7 | 174 | d = (d << 8) | r; |
TickTock | 10:aca12a61d2b1 | 175 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 176 | _cs1 = 1; |
dreschpe | 6:fe07ae8329f7 | 177 | return(d); |
dreschpe | 6:fe07ae8329f7 | 178 | } |
dreschpe | 0:da1bf437cbc1 | 179 | |
TickTock | 10:aca12a61d2b1 | 180 | int SPI_TFTx2_ILI9341::Read_ID(void){ |
dreschpe | 6:fe07ae8329f7 | 181 | int r; |
dreschpe | 6:fe07ae8329f7 | 182 | r = rd_byte(0x0A); |
dreschpe | 6:fe07ae8329f7 | 183 | r = rd_byte(0x0A); |
dreschpe | 6:fe07ae8329f7 | 184 | r = rd_byte(0x0A); |
dreschpe | 6:fe07ae8329f7 | 185 | r = rd_byte(0x0A); |
dreschpe | 6:fe07ae8329f7 | 186 | return(r); |
dreschpe | 6:fe07ae8329f7 | 187 | } |
dreschpe | 0:da1bf437cbc1 | 188 | |
dreschpe | 0:da1bf437cbc1 | 189 | |
dreschpe | 1:6d6125e88de7 | 190 | // Init code based on MI0283QT datasheet |
dreschpe | 1:6d6125e88de7 | 191 | |
TickTock | 10:aca12a61d2b1 | 192 | void SPI_TFTx2_ILI9341::tft_reset() |
dreschpe | 0:da1bf437cbc1 | 193 | { |
dreschpe | 2:0a16083193a4 | 194 | _spi.format(8,3); // 8 bit spi mode 3 |
TickTock | 10:aca12a61d2b1 | 195 | _spi.frequency(48000000); // 48 Mhz SPI clock |
TickTock | 9:522e742e62eb | 196 | _cs0 = 1; // cs high |
TickTock | 9:522e742e62eb | 197 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 198 | _dc = 1; // dc high |
dreschpe | 0:da1bf437cbc1 | 199 | _reset = 0; // display reset |
dreschpe | 0:da1bf437cbc1 | 200 | |
dreschpe | 0:da1bf437cbc1 | 201 | wait_us(50); |
dreschpe | 1:6d6125e88de7 | 202 | _reset = 1; // end hardware reset |
dreschpe | 0:da1bf437cbc1 | 203 | wait_ms(5); |
TickTock | 10:aca12a61d2b1 | 204 | |
TickTock | 10:aca12a61d2b1 | 205 | wr_cmd(0x01); // SW reset |
dreschpe | 1:6d6125e88de7 | 206 | wait_ms(5); |
TickTock | 10:aca12a61d2b1 | 207 | wr_cmd(0x28); // display off |
dreschpe | 0:da1bf437cbc1 | 208 | |
dreschpe | 0:da1bf437cbc1 | 209 | /* Start Initial Sequence ----------------------------------------------------*/ |
TickTock | 10:aca12a61d2b1 | 210 | wr_cmd(0xCF); |
dreschpe | 1:6d6125e88de7 | 211 | _spi.write(0x00); |
dreschpe | 1:6d6125e88de7 | 212 | _spi.write(0x83); |
dreschpe | 1:6d6125e88de7 | 213 | _spi.write(0x30); |
TickTock | 9:522e742e62eb | 214 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 215 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 216 | |
TickTock | 10:aca12a61d2b1 | 217 | wr_cmd(0xED); |
dreschpe | 1:6d6125e88de7 | 218 | _spi.write(0x64); |
dreschpe | 1:6d6125e88de7 | 219 | _spi.write(0x03); |
dreschpe | 1:6d6125e88de7 | 220 | _spi.write(0x12); |
dreschpe | 1:6d6125e88de7 | 221 | _spi.write(0x81); |
TickTock | 9:522e742e62eb | 222 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 223 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 224 | |
TickTock | 10:aca12a61d2b1 | 225 | wr_cmd(0xE8); |
dreschpe | 1:6d6125e88de7 | 226 | _spi.write(0x85); |
dreschpe | 1:6d6125e88de7 | 227 | _spi.write(0x01); |
dreschpe | 1:6d6125e88de7 | 228 | _spi.write(0x79); |
TickTock | 9:522e742e62eb | 229 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 230 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 231 | |
TickTock | 10:aca12a61d2b1 | 232 | wr_cmd(0xCB); |
dreschpe | 0:da1bf437cbc1 | 233 | _spi.write(0x39); |
dreschpe | 0:da1bf437cbc1 | 234 | _spi.write(0x2C); |
dreschpe | 0:da1bf437cbc1 | 235 | _spi.write(0x00); |
dreschpe | 0:da1bf437cbc1 | 236 | _spi.write(0x34); |
dreschpe | 0:da1bf437cbc1 | 237 | _spi.write(0x02); |
TickTock | 9:522e742e62eb | 238 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 239 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 240 | |
TickTock | 10:aca12a61d2b1 | 241 | wr_cmd(0xF7); |
dreschpe | 1:6d6125e88de7 | 242 | _spi.write(0x20); |
TickTock | 9:522e742e62eb | 243 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 244 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 245 | |
TickTock | 10:aca12a61d2b1 | 246 | wr_cmd(0xEA); |
dreschpe | 1:6d6125e88de7 | 247 | _spi.write(0x00); |
dreschpe | 1:6d6125e88de7 | 248 | _spi.write(0x00); |
TickTock | 9:522e742e62eb | 249 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 250 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 251 | |
dreschpe | 0:da1bf437cbc1 | 252 | wr_cmd(0xC0); // POWER_CONTROL_1 |
dreschpe | 1:6d6125e88de7 | 253 | _spi.write(0x26); |
TickTock | 9:522e742e62eb | 254 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 255 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 256 | |
dreschpe | 0:da1bf437cbc1 | 257 | wr_cmd(0xC1); // POWER_CONTROL_2 |
dreschpe | 0:da1bf437cbc1 | 258 | _spi.write(0x11); |
TickTock | 9:522e742e62eb | 259 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 260 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 261 | |
dreschpe | 0:da1bf437cbc1 | 262 | wr_cmd(0xC5); // VCOM_CONTROL_1 |
dreschpe | 1:6d6125e88de7 | 263 | _spi.write(0x35); |
dreschpe | 1:6d6125e88de7 | 264 | _spi.write(0x3E); |
TickTock | 9:522e742e62eb | 265 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 266 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 267 | |
dreschpe | 0:da1bf437cbc1 | 268 | wr_cmd(0xC7); // VCOM_CONTROL_2 |
dreschpe | 1:6d6125e88de7 | 269 | _spi.write(0xBE); |
TickTock | 9:522e742e62eb | 270 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 271 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 272 | |
dreschpe | 0:da1bf437cbc1 | 273 | wr_cmd(0x36); // MEMORY_ACCESS_CONTROL |
dreschpe | 0:da1bf437cbc1 | 274 | _spi.write(0x48); |
TickTock | 9:522e742e62eb | 275 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 276 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 277 | |
dreschpe | 1:6d6125e88de7 | 278 | wr_cmd(0x3A); // COLMOD_PIXEL_FORMAT_SET |
TickTock | 10:aca12a61d2b1 | 279 | _spi.write(0x55); // 16 bit pixel |
TickTock | 9:522e742e62eb | 280 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 281 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 282 | |
dreschpe | 1:6d6125e88de7 | 283 | wr_cmd(0xB1); // Frame Rate |
dreschpe | 1:6d6125e88de7 | 284 | _spi.write(0x00); |
TickTock | 10:aca12a61d2b1 | 285 | _spi.write(0x1B); |
TickTock | 9:522e742e62eb | 286 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 287 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 288 | |
dreschpe | 1:6d6125e88de7 | 289 | wr_cmd(0xF2); // Gamma Function Disable |
dreschpe | 1:6d6125e88de7 | 290 | _spi.write(0x08); |
TickTock | 9:522e742e62eb | 291 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 292 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 293 | |
TickTock | 10:aca12a61d2b1 | 294 | wr_cmd(0x26); |
dreschpe | 1:6d6125e88de7 | 295 | _spi.write(0x01); // gamma set for curve 01/2/04/08 |
TickTock | 9:522e742e62eb | 296 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 297 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 298 | |
dreschpe | 1:6d6125e88de7 | 299 | wr_cmd(0xE0); // positive gamma correction |
TickTock | 10:aca12a61d2b1 | 300 | _spi.write(0x1F); |
TickTock | 10:aca12a61d2b1 | 301 | _spi.write(0x1A); |
TickTock | 10:aca12a61d2b1 | 302 | _spi.write(0x18); |
TickTock | 10:aca12a61d2b1 | 303 | _spi.write(0x0A); |
TickTock | 10:aca12a61d2b1 | 304 | _spi.write(0x0F); |
TickTock | 10:aca12a61d2b1 | 305 | _spi.write(0x06); |
TickTock | 10:aca12a61d2b1 | 306 | _spi.write(0x45); |
TickTock | 10:aca12a61d2b1 | 307 | _spi.write(0x87); |
TickTock | 10:aca12a61d2b1 | 308 | _spi.write(0x32); |
TickTock | 10:aca12a61d2b1 | 309 | _spi.write(0x0A); |
dreschpe | 1:6d6125e88de7 | 310 | _spi.write(0x07); |
TickTock | 10:aca12a61d2b1 | 311 | _spi.write(0x02); |
TickTock | 10:aca12a61d2b1 | 312 | _spi.write(0x07); |
TickTock | 10:aca12a61d2b1 | 313 | _spi.write(0x05); |
dreschpe | 1:6d6125e88de7 | 314 | _spi.write(0x00); |
TickTock | 9:522e742e62eb | 315 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 316 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 317 | |
dreschpe | 1:6d6125e88de7 | 318 | wr_cmd(0xE1); // negativ gamma correction |
TickTock | 10:aca12a61d2b1 | 319 | _spi.write(0x00); |
TickTock | 10:aca12a61d2b1 | 320 | _spi.write(0x25); |
TickTock | 10:aca12a61d2b1 | 321 | _spi.write(0x27); |
TickTock | 10:aca12a61d2b1 | 322 | _spi.write(0x05); |
TickTock | 10:aca12a61d2b1 | 323 | _spi.write(0x10); |
TickTock | 10:aca12a61d2b1 | 324 | _spi.write(0x09); |
TickTock | 10:aca12a61d2b1 | 325 | _spi.write(0x3A); |
TickTock | 10:aca12a61d2b1 | 326 | _spi.write(0x78); |
TickTock | 10:aca12a61d2b1 | 327 | _spi.write(0x4D); |
TickTock | 10:aca12a61d2b1 | 328 | _spi.write(0x05); |
TickTock | 10:aca12a61d2b1 | 329 | _spi.write(0x18); |
TickTock | 10:aca12a61d2b1 | 330 | _spi.write(0x0D); |
dreschpe | 1:6d6125e88de7 | 331 | _spi.write(0x38); |
TickTock | 10:aca12a61d2b1 | 332 | _spi.write(0x3A); |
dreschpe | 1:6d6125e88de7 | 333 | _spi.write(0x1F); |
TickTock | 9:522e742e62eb | 334 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 335 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 336 | |
dreschpe | 1:6d6125e88de7 | 337 | WindowMax (); |
TickTock | 10:aca12a61d2b1 | 338 | |
dreschpe | 1:6d6125e88de7 | 339 | //wr_cmd(0x34); // tearing effect off |
dreschpe | 1:6d6125e88de7 | 340 | //_cs = 1; |
TickTock | 10:aca12a61d2b1 | 341 | |
dreschpe | 1:6d6125e88de7 | 342 | //wr_cmd(0x35); // tearing effect on |
dreschpe | 1:6d6125e88de7 | 343 | //_cs = 1; |
TickTock | 10:aca12a61d2b1 | 344 | |
dreschpe | 1:6d6125e88de7 | 345 | wr_cmd(0xB7); // entry mode |
dreschpe | 1:6d6125e88de7 | 346 | _spi.write(0x07); |
TickTock | 9:522e742e62eb | 347 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 348 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 349 | |
dreschpe | 1:6d6125e88de7 | 350 | wr_cmd(0xB6); // display function control |
dreschpe | 1:6d6125e88de7 | 351 | _spi.write(0x0A); |
dreschpe | 1:6d6125e88de7 | 352 | _spi.write(0x82); |
dreschpe | 1:6d6125e88de7 | 353 | _spi.write(0x27); |
dreschpe | 1:6d6125e88de7 | 354 | _spi.write(0x00); |
TickTock | 9:522e742e62eb | 355 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 356 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 357 | |
dreschpe | 1:6d6125e88de7 | 358 | wr_cmd(0x11); // sleep out |
TickTock | 9:522e742e62eb | 359 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 360 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 361 | |
dreschpe | 1:6d6125e88de7 | 362 | wait_ms(100); |
TickTock | 10:aca12a61d2b1 | 363 | |
dreschpe | 1:6d6125e88de7 | 364 | wr_cmd(0x29); // display on |
TickTock | 9:522e742e62eb | 365 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 366 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 367 | |
dreschpe | 1:6d6125e88de7 | 368 | wait_ms(100); |
TickTock | 10:aca12a61d2b1 | 369 | |
dreschpe | 1:6d6125e88de7 | 370 | } |
dreschpe | 0:da1bf437cbc1 | 371 | |
dreschpe | 0:da1bf437cbc1 | 372 | |
TickTock | 10:aca12a61d2b1 | 373 | void SPI_TFTx2_ILI9341::pixel(int x, int y, int color) |
dreschpe | 0:da1bf437cbc1 | 374 | { |
dreschpe | 0:da1bf437cbc1 | 375 | wr_cmd(0x2A); |
dreschpe | 0:da1bf437cbc1 | 376 | _spi.write(x >> 8); |
dreschpe | 0:da1bf437cbc1 | 377 | _spi.write(x); |
TickTock | 9:522e742e62eb | 378 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 379 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 380 | wr_cmd(0x2B); |
dreschpe | 0:da1bf437cbc1 | 381 | _spi.write(y >> 8); |
dreschpe | 0:da1bf437cbc1 | 382 | _spi.write(y); |
TickTock | 9:522e742e62eb | 383 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 384 | _cs1 = 1; |
dreschpe | 5:55aed13f2630 | 385 | wr_cmd(0x2C); // send pixel |
dreschpe | 5:55aed13f2630 | 386 | #if defined TARGET_KL25Z // 8 Bit SPI |
dreschpe | 5:55aed13f2630 | 387 | _spi.write(color >> 8); |
dreschpe | 5:55aed13f2630 | 388 | _spi.write(color & 0xff); |
TickTock | 10:aca12a61d2b1 | 389 | #else |
dreschpe | 0:da1bf437cbc1 | 390 | _spi.format(16,3); // switch to 16 bit Mode 3 |
dreschpe | 0:da1bf437cbc1 | 391 | _spi.write(color); // Write D0..D15 |
dreschpe | 0:da1bf437cbc1 | 392 | _spi.format(8,3); |
dreschpe | 5:55aed13f2630 | 393 | #endif |
TickTock | 9:522e742e62eb | 394 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 395 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 396 | } |
dreschpe | 0:da1bf437cbc1 | 397 | |
dreschpe | 0:da1bf437cbc1 | 398 | |
TickTock | 10:aca12a61d2b1 | 399 | void SPI_TFTx2_ILI9341::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) |
dreschpe | 0:da1bf437cbc1 | 400 | { |
dreschpe | 0:da1bf437cbc1 | 401 | wr_cmd(0x2A); |
dreschpe | 0:da1bf437cbc1 | 402 | _spi.write(x >> 8); |
dreschpe | 0:da1bf437cbc1 | 403 | _spi.write(x); |
dreschpe | 0:da1bf437cbc1 | 404 | _spi.write((x+w-1) >> 8); |
dreschpe | 0:da1bf437cbc1 | 405 | _spi.write(x+w-1); |
TickTock | 10:aca12a61d2b1 | 406 | |
TickTock | 9:522e742e62eb | 407 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 408 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 409 | wr_cmd(0x2B); |
dreschpe | 0:da1bf437cbc1 | 410 | _spi.write(y >> 8); |
dreschpe | 0:da1bf437cbc1 | 411 | _spi.write(y); |
dreschpe | 0:da1bf437cbc1 | 412 | _spi.write((y+h-1) >> 8); |
dreschpe | 0:da1bf437cbc1 | 413 | _spi.write(y+h-1); |
TickTock | 9:522e742e62eb | 414 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 415 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 416 | } |
dreschpe | 0:da1bf437cbc1 | 417 | |
dreschpe | 0:da1bf437cbc1 | 418 | |
TickTock | 10:aca12a61d2b1 | 419 | void SPI_TFTx2_ILI9341::WindowMax (void) |
dreschpe | 0:da1bf437cbc1 | 420 | { |
dreschpe | 0:da1bf437cbc1 | 421 | window (0, 0, width(), height()); |
dreschpe | 0:da1bf437cbc1 | 422 | } |
dreschpe | 0:da1bf437cbc1 | 423 | |
dreschpe | 0:da1bf437cbc1 | 424 | |
dreschpe | 0:da1bf437cbc1 | 425 | |
TickTock | 10:aca12a61d2b1 | 426 | void SPI_TFTx2_ILI9341::cls (void) |
dreschpe | 0:da1bf437cbc1 | 427 | { |
dreschpe | 0:da1bf437cbc1 | 428 | int pixel = ( width() * height()); |
dreschpe | 0:da1bf437cbc1 | 429 | WindowMax(); |
dreschpe | 5:55aed13f2630 | 430 | wr_cmd(0x2C); // send pixel |
dreschpe | 5:55aed13f2630 | 431 | #if defined TARGET_KL25Z // 8 Bit SPI |
dreschpe | 5:55aed13f2630 | 432 | unsigned int i; |
dreschpe | 5:55aed13f2630 | 433 | for (i = 0; i < ( width() * height()); i++){ |
dreschpe | 5:55aed13f2630 | 434 | _spi.write(_background >> 8); |
dreschpe | 5:55aed13f2630 | 435 | _spi.write(_background & 0xff); |
dreschpe | 5:55aed13f2630 | 436 | } |
TickTock | 10:aca12a61d2b1 | 437 | |
TickTock | 10:aca12a61d2b1 | 438 | #else |
dreschpe | 0:da1bf437cbc1 | 439 | _spi.format(16,3); // switch to 16 bit Mode 3 |
dreschpe | 0:da1bf437cbc1 | 440 | unsigned int i; |
dreschpe | 0:da1bf437cbc1 | 441 | for (i = 0; i < ( width() * height()); i++) |
dreschpe | 5:55aed13f2630 | 442 | _spi.write(_background); |
TickTock | 10:aca12a61d2b1 | 443 | _spi.format(8,3); |
TickTock | 10:aca12a61d2b1 | 444 | #endif |
TickTock | 9:522e742e62eb | 445 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 446 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 447 | } |
dreschpe | 0:da1bf437cbc1 | 448 | |
dreschpe | 0:da1bf437cbc1 | 449 | |
TickTock | 10:aca12a61d2b1 | 450 | void SPI_TFTx2_ILI9341::circle(int x0, int y0, int r, int color) |
dreschpe | 0:da1bf437cbc1 | 451 | { |
dreschpe | 0:da1bf437cbc1 | 452 | |
mazgch | 3:3d7298360e45 | 453 | int x = -r, y = 0, err = 2-2*r, e2; |
mazgch | 3:3d7298360e45 | 454 | do { |
mazgch | 3:3d7298360e45 | 455 | pixel(x0-x, y0+y,color); |
mazgch | 3:3d7298360e45 | 456 | pixel(x0+x, y0+y,color); |
mazgch | 3:3d7298360e45 | 457 | pixel(x0+x, y0-y,color); |
mazgch | 3:3d7298360e45 | 458 | pixel(x0-x, y0-y,color); |
mazgch | 3:3d7298360e45 | 459 | e2 = err; |
mazgch | 3:3d7298360e45 | 460 | if (e2 <= y) { |
mazgch | 3:3d7298360e45 | 461 | err += ++y*2+1; |
mazgch | 3:3d7298360e45 | 462 | if (-x == y && e2 <= x) e2 = 0; |
mazgch | 3:3d7298360e45 | 463 | } |
mazgch | 3:3d7298360e45 | 464 | if (e2 > x) err += ++x*2+1; |
mazgch | 3:3d7298360e45 | 465 | } while (x <= 0); |
dreschpe | 4:f018e272220b | 466 | |
dreschpe | 0:da1bf437cbc1 | 467 | } |
dreschpe | 0:da1bf437cbc1 | 468 | |
TickTock | 10:aca12a61d2b1 | 469 | void SPI_TFTx2_ILI9341::fillcircle(int x0, int y0, int r, int color) |
dreschpe | 0:da1bf437cbc1 | 470 | { |
mazgch | 3:3d7298360e45 | 471 | int x = -r, y = 0, err = 2-2*r, e2; |
mazgch | 3:3d7298360e45 | 472 | do { |
mazgch | 3:3d7298360e45 | 473 | vline(x0-x, y0-y, y0+y, color); |
mazgch | 3:3d7298360e45 | 474 | vline(x0+x, y0-y, y0+y, color); |
mazgch | 3:3d7298360e45 | 475 | e2 = err; |
mazgch | 3:3d7298360e45 | 476 | if (e2 <= y) { |
mazgch | 3:3d7298360e45 | 477 | err += ++y*2+1; |
mazgch | 3:3d7298360e45 | 478 | if (-x == y && e2 <= x) e2 = 0; |
mazgch | 3:3d7298360e45 | 479 | } |
mazgch | 3:3d7298360e45 | 480 | if (e2 > x) err += ++x*2+1; |
mazgch | 3:3d7298360e45 | 481 | } while (x <= 0); |
dreschpe | 0:da1bf437cbc1 | 482 | } |
dreschpe | 0:da1bf437cbc1 | 483 | |
dreschpe | 0:da1bf437cbc1 | 484 | |
TickTock | 10:aca12a61d2b1 | 485 | void SPI_TFTx2_ILI9341::hline(int x0, int x1, int y, int color) |
dreschpe | 0:da1bf437cbc1 | 486 | { |
dreschpe | 0:da1bf437cbc1 | 487 | int w; |
dreschpe | 0:da1bf437cbc1 | 488 | w = x1 - x0 + 1; |
dreschpe | 0:da1bf437cbc1 | 489 | window(x0,y,w,1); |
dreschpe | 5:55aed13f2630 | 490 | wr_cmd(0x2C); // send pixel |
dreschpe | 5:55aed13f2630 | 491 | #if defined TARGET_KL25Z // 8 Bit SPI |
dreschpe | 5:55aed13f2630 | 492 | int j; |
dreschpe | 5:55aed13f2630 | 493 | for (j=0; j<w; j++) { |
dreschpe | 5:55aed13f2630 | 494 | _spi.write(color >> 8); |
dreschpe | 5:55aed13f2630 | 495 | _spi.write(color & 0xff); |
TickTock | 10:aca12a61d2b1 | 496 | } |
TickTock | 10:aca12a61d2b1 | 497 | #else |
dreschpe | 0:da1bf437cbc1 | 498 | _spi.format(16,3); // switch to 16 bit Mode 3 |
dreschpe | 0:da1bf437cbc1 | 499 | int j; |
dreschpe | 0:da1bf437cbc1 | 500 | for (j=0; j<w; j++) { |
dreschpe | 0:da1bf437cbc1 | 501 | _spi.write(color); |
dreschpe | 0:da1bf437cbc1 | 502 | } |
dreschpe | 5:55aed13f2630 | 503 | _spi.format(8,3); |
dreschpe | 5:55aed13f2630 | 504 | #endif |
TickTock | 9:522e742e62eb | 505 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 506 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 507 | WindowMax(); |
dreschpe | 0:da1bf437cbc1 | 508 | return; |
dreschpe | 0:da1bf437cbc1 | 509 | } |
dreschpe | 0:da1bf437cbc1 | 510 | |
TickTock | 10:aca12a61d2b1 | 511 | void SPI_TFTx2_ILI9341::vline(int x, int y0, int y1, int color) |
dreschpe | 0:da1bf437cbc1 | 512 | { |
dreschpe | 0:da1bf437cbc1 | 513 | int h; |
dreschpe | 0:da1bf437cbc1 | 514 | h = y1 - y0 + 1; |
dreschpe | 0:da1bf437cbc1 | 515 | window(x,y0,1,h); |
dreschpe | 5:55aed13f2630 | 516 | wr_cmd(0x2C); // send pixel |
dreschpe | 5:55aed13f2630 | 517 | #if defined TARGET_KL25Z // 8 Bit SPI |
dreschpe | 5:55aed13f2630 | 518 | for (int y=0; y<h; y++) { |
dreschpe | 5:55aed13f2630 | 519 | _spi.write(color >> 8); |
dreschpe | 5:55aed13f2630 | 520 | _spi.write(color & 0xff); |
TickTock | 10:aca12a61d2b1 | 521 | } |
TickTock | 10:aca12a61d2b1 | 522 | #else |
dreschpe | 0:da1bf437cbc1 | 523 | _spi.format(16,3); // switch to 16 bit Mode 3 |
dreschpe | 0:da1bf437cbc1 | 524 | for (int y=0; y<h; y++) { |
dreschpe | 0:da1bf437cbc1 | 525 | _spi.write(color); |
dreschpe | 0:da1bf437cbc1 | 526 | } |
dreschpe | 5:55aed13f2630 | 527 | _spi.format(8,3); |
dreschpe | 5:55aed13f2630 | 528 | #endif |
TickTock | 9:522e742e62eb | 529 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 530 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 531 | WindowMax(); |
dreschpe | 0:da1bf437cbc1 | 532 | return; |
dreschpe | 0:da1bf437cbc1 | 533 | } |
dreschpe | 0:da1bf437cbc1 | 534 | |
dreschpe | 0:da1bf437cbc1 | 535 | |
dreschpe | 0:da1bf437cbc1 | 536 | |
TickTock | 10:aca12a61d2b1 | 537 | void SPI_TFTx2_ILI9341::line(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:da1bf437cbc1 | 538 | { |
dreschpe | 0:da1bf437cbc1 | 539 | //WindowMax(); |
dreschpe | 0:da1bf437cbc1 | 540 | int dx = 0, dy = 0; |
dreschpe | 0:da1bf437cbc1 | 541 | int dx_sym = 0, dy_sym = 0; |
dreschpe | 0:da1bf437cbc1 | 542 | int dx_x2 = 0, dy_x2 = 0; |
dreschpe | 0:da1bf437cbc1 | 543 | int di = 0; |
dreschpe | 0:da1bf437cbc1 | 544 | |
dreschpe | 0:da1bf437cbc1 | 545 | dx = x1-x0; |
dreschpe | 0:da1bf437cbc1 | 546 | dy = y1-y0; |
dreschpe | 0:da1bf437cbc1 | 547 | |
dreschpe | 0:da1bf437cbc1 | 548 | if (dx == 0) { /* vertical line */ |
dreschpe | 0:da1bf437cbc1 | 549 | if (y1 > y0) vline(x0,y0,y1,color); |
dreschpe | 0:da1bf437cbc1 | 550 | else vline(x0,y1,y0,color); |
dreschpe | 0:da1bf437cbc1 | 551 | return; |
dreschpe | 0:da1bf437cbc1 | 552 | } |
dreschpe | 0:da1bf437cbc1 | 553 | |
dreschpe | 0:da1bf437cbc1 | 554 | if (dx > 0) { |
dreschpe | 0:da1bf437cbc1 | 555 | dx_sym = 1; |
dreschpe | 0:da1bf437cbc1 | 556 | } else { |
dreschpe | 0:da1bf437cbc1 | 557 | dx_sym = -1; |
dreschpe | 0:da1bf437cbc1 | 558 | } |
dreschpe | 0:da1bf437cbc1 | 559 | if (dy == 0) { /* horizontal line */ |
dreschpe | 0:da1bf437cbc1 | 560 | if (x1 > x0) hline(x0,x1,y0,color); |
dreschpe | 0:da1bf437cbc1 | 561 | else hline(x1,x0,y0,color); |
dreschpe | 0:da1bf437cbc1 | 562 | return; |
dreschpe | 0:da1bf437cbc1 | 563 | } |
dreschpe | 0:da1bf437cbc1 | 564 | |
dreschpe | 0:da1bf437cbc1 | 565 | if (dy > 0) { |
dreschpe | 0:da1bf437cbc1 | 566 | dy_sym = 1; |
dreschpe | 0:da1bf437cbc1 | 567 | } else { |
dreschpe | 0:da1bf437cbc1 | 568 | dy_sym = -1; |
dreschpe | 0:da1bf437cbc1 | 569 | } |
dreschpe | 0:da1bf437cbc1 | 570 | |
dreschpe | 0:da1bf437cbc1 | 571 | dx = dx_sym*dx; |
dreschpe | 0:da1bf437cbc1 | 572 | dy = dy_sym*dy; |
dreschpe | 0:da1bf437cbc1 | 573 | |
dreschpe | 0:da1bf437cbc1 | 574 | dx_x2 = dx*2; |
dreschpe | 0:da1bf437cbc1 | 575 | dy_x2 = dy*2; |
dreschpe | 0:da1bf437cbc1 | 576 | |
dreschpe | 0:da1bf437cbc1 | 577 | if (dx >= dy) { |
dreschpe | 0:da1bf437cbc1 | 578 | di = dy_x2 - dx; |
dreschpe | 0:da1bf437cbc1 | 579 | while (x0 != x1) { |
dreschpe | 0:da1bf437cbc1 | 580 | |
dreschpe | 0:da1bf437cbc1 | 581 | pixel(x0, y0, color); |
dreschpe | 0:da1bf437cbc1 | 582 | x0 += dx_sym; |
dreschpe | 0:da1bf437cbc1 | 583 | if (di<0) { |
dreschpe | 0:da1bf437cbc1 | 584 | di += dy_x2; |
dreschpe | 0:da1bf437cbc1 | 585 | } else { |
dreschpe | 0:da1bf437cbc1 | 586 | di += dy_x2 - dx_x2; |
dreschpe | 0:da1bf437cbc1 | 587 | y0 += dy_sym; |
dreschpe | 0:da1bf437cbc1 | 588 | } |
dreschpe | 0:da1bf437cbc1 | 589 | } |
dreschpe | 0:da1bf437cbc1 | 590 | pixel(x0, y0, color); |
dreschpe | 0:da1bf437cbc1 | 591 | } else { |
dreschpe | 0:da1bf437cbc1 | 592 | di = dx_x2 - dy; |
dreschpe | 0:da1bf437cbc1 | 593 | while (y0 != y1) { |
dreschpe | 0:da1bf437cbc1 | 594 | pixel(x0, y0, color); |
dreschpe | 0:da1bf437cbc1 | 595 | y0 += dy_sym; |
dreschpe | 0:da1bf437cbc1 | 596 | if (di < 0) { |
dreschpe | 0:da1bf437cbc1 | 597 | di += dx_x2; |
dreschpe | 0:da1bf437cbc1 | 598 | } else { |
dreschpe | 0:da1bf437cbc1 | 599 | di += dx_x2 - dy_x2; |
dreschpe | 0:da1bf437cbc1 | 600 | x0 += dx_sym; |
dreschpe | 0:da1bf437cbc1 | 601 | } |
dreschpe | 0:da1bf437cbc1 | 602 | } |
dreschpe | 0:da1bf437cbc1 | 603 | pixel(x0, y0, color); |
dreschpe | 0:da1bf437cbc1 | 604 | } |
dreschpe | 0:da1bf437cbc1 | 605 | return; |
dreschpe | 0:da1bf437cbc1 | 606 | } |
dreschpe | 0:da1bf437cbc1 | 607 | |
dreschpe | 0:da1bf437cbc1 | 608 | |
TickTock | 10:aca12a61d2b1 | 609 | void SPI_TFTx2_ILI9341::rect(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:da1bf437cbc1 | 610 | { |
dreschpe | 0:da1bf437cbc1 | 611 | |
dreschpe | 0:da1bf437cbc1 | 612 | if (x1 > x0) hline(x0,x1,y0,color); |
dreschpe | 0:da1bf437cbc1 | 613 | else hline(x1,x0,y0,color); |
dreschpe | 0:da1bf437cbc1 | 614 | |
dreschpe | 0:da1bf437cbc1 | 615 | if (y1 > y0) vline(x0,y0,y1,color); |
dreschpe | 0:da1bf437cbc1 | 616 | else vline(x0,y1,y0,color); |
dreschpe | 0:da1bf437cbc1 | 617 | |
dreschpe | 0:da1bf437cbc1 | 618 | if (x1 > x0) hline(x0,x1,y1,color); |
dreschpe | 0:da1bf437cbc1 | 619 | else hline(x1,x0,y1,color); |
dreschpe | 0:da1bf437cbc1 | 620 | |
dreschpe | 0:da1bf437cbc1 | 621 | if (y1 > y0) vline(x1,y0,y1,color); |
dreschpe | 0:da1bf437cbc1 | 622 | else vline(x1,y1,y0,color); |
dreschpe | 0:da1bf437cbc1 | 623 | |
dreschpe | 0:da1bf437cbc1 | 624 | return; |
dreschpe | 0:da1bf437cbc1 | 625 | } |
dreschpe | 0:da1bf437cbc1 | 626 | |
dreschpe | 0:da1bf437cbc1 | 627 | |
dreschpe | 0:da1bf437cbc1 | 628 | |
TickTock | 10:aca12a61d2b1 | 629 | void SPI_TFTx2_ILI9341::fillrect(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:da1bf437cbc1 | 630 | { |
dreschpe | 0:da1bf437cbc1 | 631 | |
dreschpe | 0:da1bf437cbc1 | 632 | int h = y1 - y0 + 1; |
dreschpe | 0:da1bf437cbc1 | 633 | int w = x1 - x0 + 1; |
dreschpe | 0:da1bf437cbc1 | 634 | int pixel = h * w; |
dreschpe | 0:da1bf437cbc1 | 635 | window(x0,y0,w,h); |
TickTock | 10:aca12a61d2b1 | 636 | wr_cmd(0x2C); // send pixel |
dreschpe | 5:55aed13f2630 | 637 | #if defined TARGET_KL25Z // 8 Bit SPI |
dreschpe | 5:55aed13f2630 | 638 | for (int p=0; p<pixel; p++) { |
dreschpe | 5:55aed13f2630 | 639 | _spi.write(color >> 8); |
dreschpe | 5:55aed13f2630 | 640 | _spi.write(color & 0xff); |
dreschpe | 5:55aed13f2630 | 641 | } |
dreschpe | 5:55aed13f2630 | 642 | #else |
dreschpe | 0:da1bf437cbc1 | 643 | _spi.format(16,3); // switch to 16 bit Mode 3 |
dreschpe | 0:da1bf437cbc1 | 644 | for (int p=0; p<pixel; p++) { |
dreschpe | 0:da1bf437cbc1 | 645 | _spi.write(color); |
dreschpe | 0:da1bf437cbc1 | 646 | } |
dreschpe | 5:55aed13f2630 | 647 | _spi.format(8,3); |
dreschpe | 5:55aed13f2630 | 648 | #endif |
TickTock | 9:522e742e62eb | 649 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 650 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 651 | WindowMax(); |
dreschpe | 0:da1bf437cbc1 | 652 | return; |
dreschpe | 0:da1bf437cbc1 | 653 | } |
dreschpe | 0:da1bf437cbc1 | 654 | |
dreschpe | 0:da1bf437cbc1 | 655 | |
TickTock | 10:aca12a61d2b1 | 656 | void SPI_TFTx2_ILI9341::locate(int x, int y) |
dreschpe | 0:da1bf437cbc1 | 657 | { |
dreschpe | 0:da1bf437cbc1 | 658 | char_x = x; |
dreschpe | 0:da1bf437cbc1 | 659 | char_y = y; |
dreschpe | 0:da1bf437cbc1 | 660 | } |
dreschpe | 0:da1bf437cbc1 | 661 | |
dreschpe | 0:da1bf437cbc1 | 662 | |
dreschpe | 0:da1bf437cbc1 | 663 | |
TickTock | 10:aca12a61d2b1 | 664 | int SPI_TFTx2_ILI9341::columns() |
dreschpe | 0:da1bf437cbc1 | 665 | { |
dreschpe | 0:da1bf437cbc1 | 666 | return width() / font[1]; |
dreschpe | 0:da1bf437cbc1 | 667 | } |
dreschpe | 0:da1bf437cbc1 | 668 | |
dreschpe | 0:da1bf437cbc1 | 669 | |
dreschpe | 0:da1bf437cbc1 | 670 | |
TickTock | 10:aca12a61d2b1 | 671 | int SPI_TFTx2_ILI9341::rows() |
dreschpe | 0:da1bf437cbc1 | 672 | { |
dreschpe | 0:da1bf437cbc1 | 673 | return height() / font[2]; |
dreschpe | 0:da1bf437cbc1 | 674 | } |
dreschpe | 0:da1bf437cbc1 | 675 | |
dreschpe | 0:da1bf437cbc1 | 676 | |
dreschpe | 0:da1bf437cbc1 | 677 | |
TickTock | 10:aca12a61d2b1 | 678 | int SPI_TFTx2_ILI9341::_putc(int value) |
dreschpe | 0:da1bf437cbc1 | 679 | { |
dreschpe | 0:da1bf437cbc1 | 680 | if (value == '\n') { // new line |
dreschpe | 0:da1bf437cbc1 | 681 | char_x = 0; |
dreschpe | 0:da1bf437cbc1 | 682 | char_y = char_y + font[2]; |
dreschpe | 0:da1bf437cbc1 | 683 | if (char_y >= height() - font[2]) { |
dreschpe | 0:da1bf437cbc1 | 684 | char_y = 0; |
dreschpe | 0:da1bf437cbc1 | 685 | } |
dreschpe | 0:da1bf437cbc1 | 686 | } else { |
dreschpe | 0:da1bf437cbc1 | 687 | character(char_x, char_y, value); |
dreschpe | 0:da1bf437cbc1 | 688 | } |
dreschpe | 0:da1bf437cbc1 | 689 | return value; |
dreschpe | 0:da1bf437cbc1 | 690 | } |
dreschpe | 0:da1bf437cbc1 | 691 | |
dreschpe | 0:da1bf437cbc1 | 692 | |
TickTock | 10:aca12a61d2b1 | 693 | void SPI_TFTx2_ILI9341::character(int x, int y, int c) |
dreschpe | 0:da1bf437cbc1 | 694 | { |
dreschpe | 0:da1bf437cbc1 | 695 | unsigned int hor,vert,offset,bpl,j,i,b; |
dreschpe | 0:da1bf437cbc1 | 696 | unsigned char* zeichen; |
dreschpe | 0:da1bf437cbc1 | 697 | unsigned char z,w; |
dreschpe | 0:da1bf437cbc1 | 698 | |
dreschpe | 0:da1bf437cbc1 | 699 | if ((c < 31) || (c > 127)) return; // test char range |
dreschpe | 0:da1bf437cbc1 | 700 | |
dreschpe | 0:da1bf437cbc1 | 701 | // read font parameter from start of array |
dreschpe | 0:da1bf437cbc1 | 702 | offset = font[0]; // bytes / char |
dreschpe | 0:da1bf437cbc1 | 703 | hor = font[1]; // get hor size of font |
dreschpe | 0:da1bf437cbc1 | 704 | vert = font[2]; // get vert size of font |
dreschpe | 0:da1bf437cbc1 | 705 | bpl = font[3]; // bytes per line |
dreschpe | 0:da1bf437cbc1 | 706 | |
dreschpe | 0:da1bf437cbc1 | 707 | if (char_x + hor > width()) { |
dreschpe | 0:da1bf437cbc1 | 708 | char_x = 0; |
dreschpe | 0:da1bf437cbc1 | 709 | char_y = char_y + vert; |
dreschpe | 0:da1bf437cbc1 | 710 | if (char_y >= height() - font[2]) { |
dreschpe | 0:da1bf437cbc1 | 711 | char_y = 0; |
dreschpe | 0:da1bf437cbc1 | 712 | } |
dreschpe | 0:da1bf437cbc1 | 713 | } |
dreschpe | 0:da1bf437cbc1 | 714 | window(char_x, char_y,hor,vert); // char box |
dreschpe | 5:55aed13f2630 | 715 | wr_cmd(0x2C); // send pixel |
TickTock | 10:aca12a61d2b1 | 716 | #ifndef TARGET_KL25Z // 16 Bit SPI |
TickTock | 10:aca12a61d2b1 | 717 | _spi.format(16,3); |
dreschpe | 5:55aed13f2630 | 718 | #endif // switch to 16 bit Mode 3 |
dreschpe | 0:da1bf437cbc1 | 719 | zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap |
dreschpe | 0:da1bf437cbc1 | 720 | w = zeichen[0]; // width of actual char |
dreschpe | 0:da1bf437cbc1 | 721 | for (j=0; j<vert; j++) { // vert line |
dreschpe | 0:da1bf437cbc1 | 722 | for (i=0; i<hor; i++) { // horz line |
dreschpe | 0:da1bf437cbc1 | 723 | z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; |
dreschpe | 0:da1bf437cbc1 | 724 | b = 1 << (j & 0x07); |
dreschpe | 0:da1bf437cbc1 | 725 | if (( z & b ) == 0x00) { |
TickTock | 10:aca12a61d2b1 | 726 | #ifndef TARGET_KL25Z // 16 Bit SPI |
dreschpe | 0:da1bf437cbc1 | 727 | _spi.write(_background); |
dreschpe | 5:55aed13f2630 | 728 | #else |
dreschpe | 5:55aed13f2630 | 729 | _spi.write(_background >> 8); |
dreschpe | 5:55aed13f2630 | 730 | _spi.write(_background & 0xff); |
dreschpe | 5:55aed13f2630 | 731 | #endif |
dreschpe | 0:da1bf437cbc1 | 732 | } else { |
dreschpe | 5:55aed13f2630 | 733 | #ifndef TARGET_KL25Z // 16 Bit SPI |
dreschpe | 0:da1bf437cbc1 | 734 | _spi.write(_foreground); |
dreschpe | 5:55aed13f2630 | 735 | #else |
dreschpe | 5:55aed13f2630 | 736 | _spi.write(_foreground >> 8); |
dreschpe | 5:55aed13f2630 | 737 | _spi.write(_foreground & 0xff); |
dreschpe | 5:55aed13f2630 | 738 | #endif |
dreschpe | 0:da1bf437cbc1 | 739 | } |
dreschpe | 0:da1bf437cbc1 | 740 | } |
dreschpe | 0:da1bf437cbc1 | 741 | } |
TickTock | 9:522e742e62eb | 742 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 743 | _cs1 = 1; |
dreschpe | 5:55aed13f2630 | 744 | #ifndef TARGET_KL25Z // 16 Bit SPI |
dreschpe | 0:da1bf437cbc1 | 745 | _spi.format(8,3); |
dreschpe | 5:55aed13f2630 | 746 | #endif |
dreschpe | 0:da1bf437cbc1 | 747 | WindowMax(); |
dreschpe | 0:da1bf437cbc1 | 748 | if ((w + 2) < hor) { // x offset to next char |
dreschpe | 0:da1bf437cbc1 | 749 | char_x += w + 2; |
dreschpe | 0:da1bf437cbc1 | 750 | } else char_x += hor; |
dreschpe | 0:da1bf437cbc1 | 751 | } |
dreschpe | 0:da1bf437cbc1 | 752 | |
dreschpe | 0:da1bf437cbc1 | 753 | |
TickTock | 10:aca12a61d2b1 | 754 | void SPI_TFTx2_ILI9341::set_font(unsigned char* f) |
dreschpe | 0:da1bf437cbc1 | 755 | { |
dreschpe | 0:da1bf437cbc1 | 756 | font = f; |
dreschpe | 0:da1bf437cbc1 | 757 | } |
dreschpe | 0:da1bf437cbc1 | 758 | |
dreschpe | 0:da1bf437cbc1 | 759 | |
dreschpe | 0:da1bf437cbc1 | 760 | |
TickTock | 10:aca12a61d2b1 | 761 | void SPI_TFTx2_ILI9341::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap) |
dreschpe | 0:da1bf437cbc1 | 762 | { |
dreschpe | 0:da1bf437cbc1 | 763 | unsigned int j; |
dreschpe | 0:da1bf437cbc1 | 764 | int padd; |
dreschpe | 0:da1bf437cbc1 | 765 | unsigned short *bitmap_ptr = (unsigned short *)bitmap; |
dreschpe | 5:55aed13f2630 | 766 | #if defined TARGET_KL25Z // 8 Bit SPI |
dreschpe | 5:55aed13f2630 | 767 | unsigned short pix_temp; |
dreschpe | 5:55aed13f2630 | 768 | #endif |
TickTock | 10:aca12a61d2b1 | 769 | |
dreschpe | 2:0a16083193a4 | 770 | unsigned int i; |
TickTock | 10:aca12a61d2b1 | 771 | |
dreschpe | 0:da1bf437cbc1 | 772 | // the lines are padded to multiple of 4 bytes in a bitmap |
dreschpe | 0:da1bf437cbc1 | 773 | padd = -1; |
dreschpe | 0:da1bf437cbc1 | 774 | do { |
dreschpe | 0:da1bf437cbc1 | 775 | padd ++; |
dreschpe | 0:da1bf437cbc1 | 776 | } while (2*(w + padd)%4 != 0); |
dreschpe | 0:da1bf437cbc1 | 777 | window(x, y, w, h); |
dreschpe | 2:0a16083193a4 | 778 | bitmap_ptr += ((h - 1)* (w + padd)); |
dreschpe | 5:55aed13f2630 | 779 | wr_cmd(0x2C); // send pixel |
TickTock | 10:aca12a61d2b1 | 780 | #ifndef TARGET_KL25Z // 16 Bit SPI |
dreschpe | 5:55aed13f2630 | 781 | _spi.format(16,3); |
dreschpe | 5:55aed13f2630 | 782 | #endif // switch to 16 bit Mode 3 |
dreschpe | 2:0a16083193a4 | 783 | for (j = 0; j < h; j++) { //Lines |
dreschpe | 2:0a16083193a4 | 784 | for (i = 0; i < w; i++) { // one line |
dreschpe | 5:55aed13f2630 | 785 | #if defined TARGET_KL25Z // 8 Bit SPI |
dreschpe | 5:55aed13f2630 | 786 | pix_temp = *bitmap_ptr; |
dreschpe | 5:55aed13f2630 | 787 | _spi.write(pix_temp >> 8); |
dreschpe | 5:55aed13f2630 | 788 | _spi.write(pix_temp); |
dreschpe | 5:55aed13f2630 | 789 | bitmap_ptr++; |
dreschpe | 5:55aed13f2630 | 790 | #else |
dreschpe | 5:55aed13f2630 | 791 | _spi.write(*bitmap_ptr); // one line |
dreschpe | 5:55aed13f2630 | 792 | bitmap_ptr++; |
dreschpe | 5:55aed13f2630 | 793 | #endif |
dreschpe | 0:da1bf437cbc1 | 794 | } |
dreschpe | 0:da1bf437cbc1 | 795 | bitmap_ptr -= 2*w; |
dreschpe | 0:da1bf437cbc1 | 796 | bitmap_ptr -= padd; |
dreschpe | 0:da1bf437cbc1 | 797 | } |
TickTock | 9:522e742e62eb | 798 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 799 | _cs1 = 1; |
TickTock | 10:aca12a61d2b1 | 800 | #ifndef TARGET_KL25Z // 16 Bit SPI |
dreschpe | 0:da1bf437cbc1 | 801 | _spi.format(8,3); |
dreschpe | 5:55aed13f2630 | 802 | #endif |
dreschpe | 0:da1bf437cbc1 | 803 | WindowMax(); |
dreschpe | 0:da1bf437cbc1 | 804 | } |
dreschpe | 0:da1bf437cbc1 | 805 | |
dreschpe | 0:da1bf437cbc1 | 806 | |
dreschpe | 6:fe07ae8329f7 | 807 | // local filesystem is not implemented in kinetis board , but you can add a SD card |
dreschpe | 5:55aed13f2630 | 808 | |
TickTock | 10:aca12a61d2b1 | 809 | int SPI_TFTx2_ILI9341::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP) |
dreschpe | 0:da1bf437cbc1 | 810 | { |
dreschpe | 0:da1bf437cbc1 | 811 | |
dreschpe | 0:da1bf437cbc1 | 812 | #define OffsetPixelWidth 18 |
dreschpe | 0:da1bf437cbc1 | 813 | #define OffsetPixelHeigh 22 |
dreschpe | 0:da1bf437cbc1 | 814 | #define OffsetFileSize 34 |
dreschpe | 0:da1bf437cbc1 | 815 | #define OffsetPixData 10 |
dreschpe | 0:da1bf437cbc1 | 816 | #define OffsetBPP 28 |
dreschpe | 0:da1bf437cbc1 | 817 | |
dreschpe | 0:da1bf437cbc1 | 818 | char filename[50]; |
dreschpe | 0:da1bf437cbc1 | 819 | unsigned char BMP_Header[54]; |
dreschpe | 0:da1bf437cbc1 | 820 | unsigned short BPP_t; |
dreschpe | 0:da1bf437cbc1 | 821 | unsigned int PixelWidth,PixelHeigh,start_data; |
dreschpe | 0:da1bf437cbc1 | 822 | unsigned int i,off; |
dreschpe | 0:da1bf437cbc1 | 823 | int padd,j; |
dreschpe | 0:da1bf437cbc1 | 824 | unsigned short *line; |
dreschpe | 0:da1bf437cbc1 | 825 | |
dreschpe | 0:da1bf437cbc1 | 826 | // get the filename |
dreschpe | 6:fe07ae8329f7 | 827 | i=0; |
dreschpe | 0:da1bf437cbc1 | 828 | while (*Name_BMP!='\0') { |
dreschpe | 0:da1bf437cbc1 | 829 | filename[i++]=*Name_BMP++; |
dreschpe | 0:da1bf437cbc1 | 830 | } |
TickTock | 10:aca12a61d2b1 | 831 | filename[i] = 0; |
TickTock | 10:aca12a61d2b1 | 832 | |
dreschpe | 0:da1bf437cbc1 | 833 | FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file |
dreschpe | 0:da1bf437cbc1 | 834 | if (!Image) { |
dreschpe | 0:da1bf437cbc1 | 835 | return(0); // error file not found ! |
dreschpe | 0:da1bf437cbc1 | 836 | } |
dreschpe | 0:da1bf437cbc1 | 837 | |
dreschpe | 0:da1bf437cbc1 | 838 | fread(&BMP_Header[0],1,54,Image); // get the BMP Header |
dreschpe | 0:da1bf437cbc1 | 839 | |
dreschpe | 0:da1bf437cbc1 | 840 | if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte |
dreschpe | 0:da1bf437cbc1 | 841 | fclose(Image); |
dreschpe | 0:da1bf437cbc1 | 842 | return(-1); // error no BMP file |
dreschpe | 0:da1bf437cbc1 | 843 | } |
dreschpe | 0:da1bf437cbc1 | 844 | |
dreschpe | 0:da1bf437cbc1 | 845 | BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8); |
dreschpe | 0:da1bf437cbc1 | 846 | if (BPP_t != 0x0010) { |
dreschpe | 0:da1bf437cbc1 | 847 | fclose(Image); |
dreschpe | 0:da1bf437cbc1 | 848 | return(-2); // error no 16 bit BMP |
dreschpe | 0:da1bf437cbc1 | 849 | } |
dreschpe | 0:da1bf437cbc1 | 850 | |
dreschpe | 0:da1bf437cbc1 | 851 | PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24); |
dreschpe | 0:da1bf437cbc1 | 852 | PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24); |
dreschpe | 0:da1bf437cbc1 | 853 | if (PixelHeigh > height() + y || PixelWidth > width() + x) { |
dreschpe | 0:da1bf437cbc1 | 854 | fclose(Image); |
dreschpe | 0:da1bf437cbc1 | 855 | return(-3); // to big |
dreschpe | 0:da1bf437cbc1 | 856 | } |
dreschpe | 0:da1bf437cbc1 | 857 | |
dreschpe | 0:da1bf437cbc1 | 858 | start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24); |
dreschpe | 0:da1bf437cbc1 | 859 | |
dreschpe | 0:da1bf437cbc1 | 860 | line = (unsigned short *) malloc (2 * PixelWidth); // we need a buffer for a line |
dreschpe | 0:da1bf437cbc1 | 861 | if (line == NULL) { |
dreschpe | 0:da1bf437cbc1 | 862 | return(-4); // error no memory |
dreschpe | 0:da1bf437cbc1 | 863 | } |
dreschpe | 0:da1bf437cbc1 | 864 | |
dreschpe | 0:da1bf437cbc1 | 865 | // the bmp lines are padded to multiple of 4 bytes |
dreschpe | 0:da1bf437cbc1 | 866 | padd = -1; |
dreschpe | 0:da1bf437cbc1 | 867 | do { |
dreschpe | 0:da1bf437cbc1 | 868 | padd ++; |
dreschpe | 0:da1bf437cbc1 | 869 | } while ((PixelWidth * 2 + padd)%4 != 0); |
dreschpe | 0:da1bf437cbc1 | 870 | |
dreschpe | 0:da1bf437cbc1 | 871 | window(x, y,PixelWidth ,PixelHeigh); |
dreschpe | 6:fe07ae8329f7 | 872 | wr_cmd(0x2C); // send pixel |
TickTock | 10:aca12a61d2b1 | 873 | #ifndef TARGET_KL25Z // only 8 Bit SPI |
TickTock | 10:aca12a61d2b1 | 874 | _spi.format(16,3); |
dreschpe | 6:fe07ae8329f7 | 875 | #endif // switch to 16 bit Mode 3 |
dreschpe | 0:da1bf437cbc1 | 876 | for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up |
dreschpe | 0:da1bf437cbc1 | 877 | off = j * (PixelWidth * 2 + padd) + start_data; // start of line |
dreschpe | 0:da1bf437cbc1 | 878 | fseek(Image, off ,SEEK_SET); |
TickTock | 10:aca12a61d2b1 | 879 | fread(line,1,PixelWidth * 2,Image); // read a line - slow |
dreschpe | 0:da1bf437cbc1 | 880 | for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT |
dreschpe | 6:fe07ae8329f7 | 881 | #ifndef TARGET_KL25Z // only 8 Bit SPI |
dreschpe | 0:da1bf437cbc1 | 882 | _spi.write(line[i]); // one 16 bit pixel |
TickTock | 10:aca12a61d2b1 | 883 | #else |
dreschpe | 6:fe07ae8329f7 | 884 | _spi.write(line[i] >> 8); |
dreschpe | 6:fe07ae8329f7 | 885 | _spi.write(line[i]); |
TickTock | 10:aca12a61d2b1 | 886 | #endif |
TickTock | 10:aca12a61d2b1 | 887 | } |
dreschpe | 0:da1bf437cbc1 | 888 | } |
TickTock | 9:522e742e62eb | 889 | _cs0 = 1; |
TickTock | 9:522e742e62eb | 890 | _cs1 = 1; |
dreschpe | 0:da1bf437cbc1 | 891 | _spi.format(8,3); |
dreschpe | 0:da1bf437cbc1 | 892 | free (line); |
dreschpe | 0:da1bf437cbc1 | 893 | fclose(Image); |
dreschpe | 0:da1bf437cbc1 | 894 | WindowMax(); |
dreschpe | 0:da1bf437cbc1 | 895 | return(1); |
dreschpe | 5:55aed13f2630 | 896 | } |