Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SPI_TFT_ILI9341 by
SPI_TFT_ILI9341.cpp@9:6d30a225a5c7, 2014-04-07 (annotated)
- Committer:
- wim
- Date:
- Mon Apr 07 20:25:09 2014 +0000
- Revision:
- 9:6d30a225a5c7
- Parent:
- 8:8593d3668153
- Child:
- 10:2d505d14b7eb
Test version 2, LCD functions, I2C lib
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 | 
| dreschpe | 0:da1bf437cbc1 | 3 | * | 
| dreschpe | 0:da1bf437cbc1 | 4 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
| dreschpe | 0:da1bf437cbc1 | 5 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
| dreschpe | 0:da1bf437cbc1 | 6 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
| dreschpe | 0:da1bf437cbc1 | 7 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
| dreschpe | 0:da1bf437cbc1 | 8 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| dreschpe | 0:da1bf437cbc1 | 9 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
| dreschpe | 0:da1bf437cbc1 | 10 | * THE SOFTWARE. | 
| dreschpe | 0:da1bf437cbc1 | 11 | */ | 
| dreschpe | 0:da1bf437cbc1 | 12 | |
| dreschpe | 0:da1bf437cbc1 | 13 | // 12.06.13 fork from SPI_TFT code because controller is different ... | 
| dreschpe | 2:0a16083193a4 | 14 | // 14.07.13 Test with real display and bugfix | 
| dreschpe | 4:f018e272220b | 15 | // 18.10.13 Better Circle function from Michael Ammann | 
| dreschpe | 5:55aed13f2630 | 16 | // 22.10.13 Fixes for Kinetis Board - 8 bit spi | 
| dreschpe | 6:fe07ae8329f7 | 17 | // 26.01.14 Change interface for BMP_16 to also use SD-cards | 
| wim | 9:6d30a225a5c7 | 18 | // 30.03.14 WH Added some methods & defines, Fixed typos & warnings, General define for SPI_16 selection | 
| dreschpe | 0:da1bf437cbc1 | 19 | |
| dreschpe | 0:da1bf437cbc1 | 20 | #include "mbed.h" | 
| wim | 9:6d30a225a5c7 | 21 | #include "SPI_TFT_ILI9341.h" | 
| dreschpe | 0:da1bf437cbc1 | 22 | |
| dreschpe | 0:da1bf437cbc1 | 23 | //extern Serial pc; | 
| dreschpe | 0:da1bf437cbc1 | 24 | //extern DigitalOut xx; // debug !! | 
| dreschpe | 0:da1bf437cbc1 | 25 | |
| dreschpe | 0:da1bf437cbc1 | 26 | SPI_TFT_ILI9341::SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char *name) | 
| wim | 8:8593d3668153 | 27 | //WH : _spi(mosi, miso, sclk), _cs(cs), _reset(reset), _dc(dc), GraphicsDisplay(name) | 
| wim | 8:8593d3668153 | 28 | : GraphicsDisplay(name), _spi(mosi, miso, sclk), _cs(cs), _reset(reset), _dc(dc) | 
| dreschpe | 0:da1bf437cbc1 | 29 | { | 
| wim | 8:8593d3668153 | 30 | //WH clk = sclk; | 
| wim | 8:8593d3668153 | 31 | //WH orientation = 0; | 
| wim | 8:8593d3668153 | 32 | _origin = Origin_LeftTop; | 
| wim | 9:6d30a225a5c7 | 33 | _char_x = 0; | 
| wim | 9:6d30a225a5c7 | 34 | _char_y = 0; | 
| wim | 9:6d30a225a5c7 | 35 | _transparancy = false; | 
| wim | 9:6d30a225a5c7 | 36 | // set_font(Arial12x12); //Default font | 
| wim | 9:6d30a225a5c7 | 37 | // set_font(FONT8x8); //Default font, shame it doesnt fit format.. waste of flash space at moment | 
| wim | 9:6d30a225a5c7 | 38 | |
| dreschpe | 0:da1bf437cbc1 | 39 | tft_reset(); | 
| dreschpe | 0:da1bf437cbc1 | 40 | } | 
| dreschpe | 0:da1bf437cbc1 | 41 | |
| dreschpe | 0:da1bf437cbc1 | 42 | int SPI_TFT_ILI9341::width() | 
| dreschpe | 0:da1bf437cbc1 | 43 | { | 
| wim | 8:8593d3668153 | 44 | // if (orientation == 0 || orientation == 2) return 240; | 
| wim | 8:8593d3668153 | 45 | // else return 320; | 
| wim | 8:8593d3668153 | 46 | |
| wim | 8:8593d3668153 | 47 | if (_origin == Origin_LeftTop || _origin == Origin_RightBot) return TFT_WIDTH; | 
| wim | 8:8593d3668153 | 48 | else return TFT_HEIGHT; | 
| dreschpe | 0:da1bf437cbc1 | 49 | } | 
| dreschpe | 0:da1bf437cbc1 | 50 | |
| dreschpe | 0:da1bf437cbc1 | 51 | |
| dreschpe | 0:da1bf437cbc1 | 52 | int SPI_TFT_ILI9341::height() | 
| dreschpe | 0:da1bf437cbc1 | 53 | { | 
| wim | 8:8593d3668153 | 54 | // if (orientation == 0 || orientation == 2) return 320; | 
| wim | 8:8593d3668153 | 55 | // else return 240; | 
| wim | 8:8593d3668153 | 56 | |
| wim | 8:8593d3668153 | 57 | if (_origin == Origin_LeftTop || _origin == Origin_RightBot) return TFT_HEIGHT; | 
| wim | 8:8593d3668153 | 58 | else return TFT_WIDTH; | 
| dreschpe | 0:da1bf437cbc1 | 59 | } | 
| dreschpe | 0:da1bf437cbc1 | 60 | |
| wim | 8:8593d3668153 | 61 | //WH | 
| wim | 8:8593d3668153 | 62 | #if(0) | 
| dreschpe | 2:0a16083193a4 | 63 | void SPI_TFT_ILI9341::set_orientation(unsigned int o) | 
| dreschpe | 0:da1bf437cbc1 | 64 | { | 
| dreschpe | 0:da1bf437cbc1 | 65 | orientation = o; | 
| dreschpe | 2:0a16083193a4 | 66 | wr_cmd(0x36); // MEMORY_ACCESS_CONTROL | 
| dreschpe | 0:da1bf437cbc1 | 67 | switch (orientation) { | 
| dreschpe | 0:da1bf437cbc1 | 68 | case 0: | 
| dreschpe | 2:0a16083193a4 | 69 | _spi.write(0x48); | 
| dreschpe | 0:da1bf437cbc1 | 70 | break; | 
| dreschpe | 0:da1bf437cbc1 | 71 | case 1: | 
| dreschpe | 2:0a16083193a4 | 72 | _spi.write(0x28); | 
| dreschpe | 0:da1bf437cbc1 | 73 | break; | 
| dreschpe | 0:da1bf437cbc1 | 74 | case 2: | 
| dreschpe | 2:0a16083193a4 | 75 | _spi.write(0x88); | 
| dreschpe | 0:da1bf437cbc1 | 76 | break; | 
| dreschpe | 0:da1bf437cbc1 | 77 | case 3: | 
| dreschpe | 2:0a16083193a4 | 78 | _spi.write(0xE8); | 
| dreschpe | 0:da1bf437cbc1 | 79 | break; | 
| dreschpe | 0:da1bf437cbc1 | 80 | } | 
| dreschpe | 2:0a16083193a4 | 81 | _cs = 1; | 
| wim | 8:8593d3668153 | 82 | window_max(); | 
| dreschpe | 2:0a16083193a4 | 83 | } | 
| wim | 8:8593d3668153 | 84 | #else | 
| wim | 8:8593d3668153 | 85 | void SPI_TFT_ILI9341::set_origin(Origin origin) { | 
| wim | 8:8593d3668153 | 86 | _origin = origin; | 
| wim | 8:8593d3668153 | 87 | wr_cmd(ILI9341_MAC); // MEMORY_ACCESS_CONTROL | 
| wim | 8:8593d3668153 | 88 | switch (_origin) { | 
| wim | 8:8593d3668153 | 89 | case Origin_LeftTop: /* Left Top of panel is origin */ | 
| wim | 8:8593d3668153 | 90 | _spi.write(0x48); | 
| wim | 8:8593d3668153 | 91 | break; | 
| wim | 9:6d30a225a5c7 | 92 | case Origin_RightTop: /* ok */ | 
| wim | 8:8593d3668153 | 93 | _spi.write(0x28); | 
| wim | 8:8593d3668153 | 94 | break; | 
| wim | 9:6d30a225a5c7 | 95 | case Origin_RightBot: /* ok */ | 
| wim | 8:8593d3668153 | 96 | _spi.write(0x88); | 
| wim | 8:8593d3668153 | 97 | break; | 
| wim | 9:6d30a225a5c7 | 98 | case Origin_LeftBot: /* ok */ | 
| wim | 8:8593d3668153 | 99 | _spi.write(0xE8); | 
| wim | 8:8593d3668153 | 100 | break; | 
| wim | 8:8593d3668153 | 101 | } | 
| wim | 8:8593d3668153 | 102 | _cs = 1; | 
| wim | 8:8593d3668153 | 103 | window_max(); | 
| wim | 8:8593d3668153 | 104 | } | 
| wim | 8:8593d3668153 | 105 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 106 | |
| dreschpe | 0:da1bf437cbc1 | 107 | |
| wim | 9:6d30a225a5c7 | 108 | // background transparancy for characters | 
| wim | 9:6d30a225a5c7 | 109 | void SPI_TFT_ILI9341::set_transparancy(bool state) { | 
| wim | 9:6d30a225a5c7 | 110 | _transparancy = state; | 
| wim | 9:6d30a225a5c7 | 111 | } | 
| wim | 9:6d30a225a5c7 | 112 | |
| wim | 9:6d30a225a5c7 | 113 | |
| dreschpe | 0:da1bf437cbc1 | 114 | // write command to tft register | 
| dreschpe | 0:da1bf437cbc1 | 115 | void SPI_TFT_ILI9341::wr_cmd(unsigned char cmd) | 
| dreschpe | 0:da1bf437cbc1 | 116 | { | 
| dreschpe | 0:da1bf437cbc1 | 117 | _dc = 0; | 
| dreschpe | 0:da1bf437cbc1 | 118 | _cs = 0; | 
| dreschpe | 0:da1bf437cbc1 | 119 | _spi.write(cmd); // mbed lib | 
| dreschpe | 0:da1bf437cbc1 | 120 | _dc = 1; | 
| dreschpe | 0:da1bf437cbc1 | 121 | } | 
| dreschpe | 0:da1bf437cbc1 | 122 | |
| dreschpe | 0:da1bf437cbc1 | 123 | |
| wim | 9:6d30a225a5c7 | 124 | // write data to tft | 
| dreschpe | 0:da1bf437cbc1 | 125 | void SPI_TFT_ILI9341::wr_dat(unsigned char dat) | 
| dreschpe | 0:da1bf437cbc1 | 126 | { | 
| dreschpe | 0:da1bf437cbc1 | 127 | _spi.write(dat); // mbed lib | 
| dreschpe | 0:da1bf437cbc1 | 128 | } | 
| dreschpe | 0:da1bf437cbc1 | 129 | |
| wim | 9:6d30a225a5c7 | 130 | //WH | 
| wim | 9:6d30a225a5c7 | 131 | // The ILI9341 can be read | 
| wim | 9:6d30a225a5c7 | 132 | // Read not supported in M24SR | 
| dreschpe | 0:da1bf437cbc1 | 133 | |
| dreschpe | 6:fe07ae8329f7 | 134 | |
| wim | 9:6d30a225a5c7 | 135 | // Read byte | 
| dreschpe | 6:fe07ae8329f7 | 136 | char SPI_TFT_ILI9341::rd_byte(unsigned char cmd) | 
| dreschpe | 6:fe07ae8329f7 | 137 | { | 
| dreschpe | 6:fe07ae8329f7 | 138 | char r; | 
| dreschpe | 6:fe07ae8329f7 | 139 | _dc = 0; | 
| dreschpe | 6:fe07ae8329f7 | 140 | _cs = 0; | 
| dreschpe | 6:fe07ae8329f7 | 141 | _spi.write(cmd); // mbed lib | 
| dreschpe | 6:fe07ae8329f7 | 142 | _cs = 1; | 
| dreschpe | 6:fe07ae8329f7 | 143 | r = _spi.write(0xff); | 
| dreschpe | 6:fe07ae8329f7 | 144 | _cs = 1; | 
| dreschpe | 6:fe07ae8329f7 | 145 | return(r); | 
| dreschpe | 6:fe07ae8329f7 | 146 | } | 
| dreschpe | 0:da1bf437cbc1 | 147 | |
| wim | 9:6d30a225a5c7 | 148 | // Read 32 bit | 
| dreschpe | 6:fe07ae8329f7 | 149 | int SPI_TFT_ILI9341::rd_32(unsigned char cmd) | 
| dreschpe | 6:fe07ae8329f7 | 150 | { | 
| dreschpe | 6:fe07ae8329f7 | 151 | int d; | 
| dreschpe | 6:fe07ae8329f7 | 152 | char r; | 
| dreschpe | 6:fe07ae8329f7 | 153 | _dc = 0; | 
| dreschpe | 6:fe07ae8329f7 | 154 | _cs = 0; | 
| dreschpe | 6:fe07ae8329f7 | 155 | d = cmd; | 
| dreschpe | 6:fe07ae8329f7 | 156 | d = d << 1; | 
| wim | 8:8593d3668153 | 157 | _spi.format(9,0); // we have to add a dummy clock cycle | 
| dreschpe | 6:fe07ae8329f7 | 158 | _spi.write(d); | 
| wim | 8:8593d3668153 | 159 | _spi.format(8,0); | 
| dreschpe | 6:fe07ae8329f7 | 160 | _dc = 1; | 
| dreschpe | 6:fe07ae8329f7 | 161 | r = _spi.write(0xff); | 
| dreschpe | 6:fe07ae8329f7 | 162 | d = r; | 
| dreschpe | 6:fe07ae8329f7 | 163 | r = _spi.write(0xff); | 
| dreschpe | 6:fe07ae8329f7 | 164 | d = (d << 8) | r; | 
| dreschpe | 6:fe07ae8329f7 | 165 | r = _spi.write(0xff); | 
| dreschpe | 6:fe07ae8329f7 | 166 | d = (d << 8) | r; | 
| dreschpe | 6:fe07ae8329f7 | 167 | r = _spi.write(0xff); | 
| dreschpe | 6:fe07ae8329f7 | 168 | d = (d << 8) | r; | 
| dreschpe | 6:fe07ae8329f7 | 169 | _cs = 1; | 
| dreschpe | 6:fe07ae8329f7 | 170 | return(d); | 
| dreschpe | 6:fe07ae8329f7 | 171 | } | 
| dreschpe | 0:da1bf437cbc1 | 172 | |
| wim | 9:6d30a225a5c7 | 173 | //This may be not supported on some revisions of IL9341 | 
| dreschpe | 6:fe07ae8329f7 | 174 | int SPI_TFT_ILI9341::Read_ID(void){ | 
| dreschpe | 6:fe07ae8329f7 | 175 | int r; | 
| dreschpe | 6:fe07ae8329f7 | 176 | r = rd_byte(0x0A); | 
| dreschpe | 6:fe07ae8329f7 | 177 | r = rd_byte(0x0A); | 
| dreschpe | 6:fe07ae8329f7 | 178 | r = rd_byte(0x0A); | 
| dreschpe | 6:fe07ae8329f7 | 179 | r = rd_byte(0x0A); | 
| dreschpe | 6:fe07ae8329f7 | 180 | return(r); | 
| dreschpe | 6:fe07ae8329f7 | 181 | } | 
| dreschpe | 0:da1bf437cbc1 | 182 | |
| dreschpe | 0:da1bf437cbc1 | 183 | |
| dreschpe | 1:6d6125e88de7 | 184 | // Init code based on MI0283QT datasheet | 
| dreschpe | 0:da1bf437cbc1 | 185 | void SPI_TFT_ILI9341::tft_reset() | 
| dreschpe | 0:da1bf437cbc1 | 186 | { | 
| wim | 9:6d30a225a5c7 | 187 | //WH _spi.format(8,3); // 8 bit spi Mode 3 | 
| wim | 8:8593d3668153 | 188 | _spi.format(8,0); // 8 bit spi mode 0 | 
| wim | 8:8593d3668153 | 189 | |
| wim | 9:6d30a225a5c7 | 190 | _spi.frequency(10000000); // 10 Mhz SPI ... should work on current version of mbed F103 lib after fix for HSI/HSE... | 
| wim | 9:6d30a225a5c7 | 191 | // _spi.frequency(4000000); // 4 Mhz SPI clock | 
| wim | 9:6d30a225a5c7 | 192 | // _spi.frequency(8000000); // 8 Mhz SPI clock | 
| wim | 8:8593d3668153 | 193 | |
| dreschpe | 0:da1bf437cbc1 | 194 | _cs = 1; // cs high | 
| dreschpe | 0:da1bf437cbc1 | 195 | _dc = 1; // dc high | 
| wim | 9:6d30a225a5c7 | 196 | |
| dreschpe | 0:da1bf437cbc1 | 197 | _reset = 0; // display reset | 
| dreschpe | 0:da1bf437cbc1 | 198 | wait_us(50); | 
| wim | 9:6d30a225a5c7 | 199 | _reset = 1; // end hardware reset | 
| dreschpe | 0:da1bf437cbc1 | 200 | wait_ms(5); | 
| dreschpe | 1:6d6125e88de7 | 201 | |
| wim | 8:8593d3668153 | 202 | //WH wr_cmd(0x01); // SW reset | 
| wim | 8:8593d3668153 | 203 | wr_cmd(ILI9341_DISPLAY_RST); // SW reset | 
| dreschpe | 1:6d6125e88de7 | 204 | wait_ms(5); | 
| wim | 9:6d30a225a5c7 | 205 | |
| wim | 8:8593d3668153 | 206 | //WH wr_cmd(0x28); // display off | 
| wim | 8:8593d3668153 | 207 | wr_cmd(ILI9341_DISPLAY_OFF); // display off | 
| dreschpe | 0:da1bf437cbc1 | 208 | |
| dreschpe | 0:da1bf437cbc1 | 209 | /* Start Initial Sequence ----------------------------------------------------*/ | 
| wim | 8:8593d3668153 | 210 | // wr_cmd(0xCF); | 
| wim | 8:8593d3668153 | 211 | wr_cmd(ILI9341_POWERB); /* Power control B register */ | 
| dreschpe | 1:6d6125e88de7 | 212 | _spi.write(0x00); | 
| dreschpe | 1:6d6125e88de7 | 213 | _spi.write(0x83); | 
| dreschpe | 1:6d6125e88de7 | 214 | _spi.write(0x30); | 
| dreschpe | 1:6d6125e88de7 | 215 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 216 | |
| wim | 8:8593d3668153 | 217 | // wr_cmd(0xED); | 
| wim | 8:8593d3668153 | 218 | wr_cmd(ILI9341_POWER_SEQ); /* Power on sequence register */ | 
| dreschpe | 1:6d6125e88de7 | 219 | _spi.write(0x64); | 
| dreschpe | 1:6d6125e88de7 | 220 | _spi.write(0x03); | 
| dreschpe | 1:6d6125e88de7 | 221 | _spi.write(0x12); | 
| dreschpe | 1:6d6125e88de7 | 222 | _spi.write(0x81); | 
| dreschpe | 1:6d6125e88de7 | 223 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 224 | |
| wim | 8:8593d3668153 | 225 | // wr_cmd(0xE8); | 
| wim | 8:8593d3668153 | 226 | wr_cmd(ILI9341_DTCA); /* Driver timing control A */ | 
| dreschpe | 1:6d6125e88de7 | 227 | _spi.write(0x85); | 
| dreschpe | 1:6d6125e88de7 | 228 | _spi.write(0x01); | 
| dreschpe | 1:6d6125e88de7 | 229 | _spi.write(0x79); | 
| dreschpe | 1:6d6125e88de7 | 230 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 231 | |
| wim | 8:8593d3668153 | 232 | // wr_cmd(0xCB); | 
| wim | 8:8593d3668153 | 233 | wr_cmd(ILI9341_POWERA); /* Power control A register */ | 
| dreschpe | 0:da1bf437cbc1 | 234 | _spi.write(0x39); | 
| dreschpe | 0:da1bf437cbc1 | 235 | _spi.write(0x2C); | 
| dreschpe | 0:da1bf437cbc1 | 236 | _spi.write(0x00); | 
| dreschpe | 0:da1bf437cbc1 | 237 | _spi.write(0x34); | 
| dreschpe | 0:da1bf437cbc1 | 238 | _spi.write(0x02); | 
| dreschpe | 0:da1bf437cbc1 | 239 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 240 | |
| wim | 8:8593d3668153 | 241 | // wr_cmd(0xF7); | 
| wim | 8:8593d3668153 | 242 | wr_cmd(ILI9341_PRC); /* Pump ratio control register */ | 
| dreschpe | 1:6d6125e88de7 | 243 | _spi.write(0x20); | 
| dreschpe | 0:da1bf437cbc1 | 244 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 245 | |
| wim | 8:8593d3668153 | 246 | // wr_cmd(0xEA); | 
| wim | 8:8593d3668153 | 247 | wr_cmd(ILI9341_DTCB); /* Driver timing control B */ | 
| dreschpe | 1:6d6125e88de7 | 248 | _spi.write(0x00); | 
| dreschpe | 1:6d6125e88de7 | 249 | _spi.write(0x00); | 
| dreschpe | 0:da1bf437cbc1 | 250 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 251 | |
| wim | 8:8593d3668153 | 252 | // wr_cmd(0xC0); // POWER_CONTROL_1 | 
| wim | 8:8593d3668153 | 253 | wr_cmd(ILI9341_POWER1); // POWER_CONTROL_1 | 
| dreschpe | 1:6d6125e88de7 | 254 | _spi.write(0x26); | 
| dreschpe | 0:da1bf437cbc1 | 255 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 256 | |
| wim | 8:8593d3668153 | 257 | // wr_cmd(0xC1); // POWER_CONTROL_2 | 
| wim | 8:8593d3668153 | 258 | wr_cmd(ILI9341_POWER2); // POWER_CONTROL_2 | 
| dreschpe | 0:da1bf437cbc1 | 259 | _spi.write(0x11); | 
| dreschpe | 0:da1bf437cbc1 | 260 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 261 | |
| wim | 8:8593d3668153 | 262 | // wr_cmd(0xC5); // VCOM_CONTROL_1 | 
| wim | 8:8593d3668153 | 263 | wr_cmd(ILI9341_VCOM1); // VCOM_CONTROL_1 | 
| dreschpe | 1:6d6125e88de7 | 264 | _spi.write(0x35); | 
| dreschpe | 1:6d6125e88de7 | 265 | _spi.write(0x3E); | 
| dreschpe | 0:da1bf437cbc1 | 266 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 267 | |
| wim | 8:8593d3668153 | 268 | // wr_cmd(0xC7); // VCOM_CONTROL_2 | 
| wim | 8:8593d3668153 | 269 | wr_cmd(ILI9341_VCOM2); // VCOM_CONTROL_2 | 
| dreschpe | 1:6d6125e88de7 | 270 | _spi.write(0xBE); | 
| dreschpe | 0:da1bf437cbc1 | 271 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 272 | |
| wim | 8:8593d3668153 | 273 | // wr_cmd(0x36); // MEMORY_ACCESS_CONTROL | 
| wim | 8:8593d3668153 | 274 | wr_cmd(ILI9341_MAC); // MEMORY_ACCESS_CONTROL | 
| wim | 9:6d30a225a5c7 | 275 | _spi.write(0x48); // my,mx,mv,ml,BGR,mh,0,0 | 
| dreschpe | 0:da1bf437cbc1 | 276 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 277 | |
| wim | 8:8593d3668153 | 278 | // wr_cmd(0x3A); // COLMOD_PIXEL_FORMAT_SET | 
| wim | 8:8593d3668153 | 279 | wr_cmd(ILI9341_PIXEL_FORMAT); /* Pixel Format register */ | 
| dreschpe | 1:6d6125e88de7 | 280 | _spi.write(0x55); // 16 bit pixel | 
| dreschpe | 1:6d6125e88de7 | 281 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 282 | |
| wim | 8:8593d3668153 | 283 | // wr_cmd(0xB1); // Frame Rate | 
| wim | 8:8593d3668153 | 284 | wr_cmd(ILI9341_FRC); /* Frame Rate Control register */ | 
| dreschpe | 1:6d6125e88de7 | 285 | _spi.write(0x00); | 
| dreschpe | 1:6d6125e88de7 | 286 | _spi.write(0x1B); | 
| dreschpe | 1:6d6125e88de7 | 287 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 288 | |
| wim | 8:8593d3668153 | 289 | // wr_cmd(0xF2); // Gamma Function Disable | 
| wim | 8:8593d3668153 | 290 | wr_cmd(ILI9341_3GAMMA_EN); /* 3 Gamma enable register */ | 
| wim | 8:8593d3668153 | 291 | _spi.write(0x08); // Gamma Function Disable | 
| dreschpe | 1:6d6125e88de7 | 292 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 293 | |
| wim | 8:8593d3668153 | 294 | // wr_cmd(0x26); | 
| wim | 8:8593d3668153 | 295 | wr_cmd(ILI9341_GAMMA); /* Gamma register */ | 
| dreschpe | 1:6d6125e88de7 | 296 | _spi.write(0x01); // gamma set for curve 01/2/04/08 | 
| dreschpe | 1:6d6125e88de7 | 297 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 298 | |
| wim | 8:8593d3668153 | 299 | // wr_cmd(0xE0); // positive gamma correction | 
| wim | 8:8593d3668153 | 300 | wr_cmd(ILI9341_PGAMMA); /* Positive Gamma Correction register*/ | 
| dreschpe | 1:6d6125e88de7 | 301 | _spi.write(0x1F); | 
| dreschpe | 1:6d6125e88de7 | 302 | _spi.write(0x1A); | 
| dreschpe | 1:6d6125e88de7 | 303 | _spi.write(0x18); | 
| dreschpe | 1:6d6125e88de7 | 304 | _spi.write(0x0A); | 
| dreschpe | 1:6d6125e88de7 | 305 | _spi.write(0x0F); | 
| dreschpe | 1:6d6125e88de7 | 306 | _spi.write(0x06); | 
| dreschpe | 1:6d6125e88de7 | 307 | _spi.write(0x45); | 
| dreschpe | 1:6d6125e88de7 | 308 | _spi.write(0x87); | 
| dreschpe | 1:6d6125e88de7 | 309 | _spi.write(0x32); | 
| dreschpe | 1:6d6125e88de7 | 310 | _spi.write(0x0A); | 
| dreschpe | 1:6d6125e88de7 | 311 | _spi.write(0x07); | 
| dreschpe | 1:6d6125e88de7 | 312 | _spi.write(0x02); | 
| dreschpe | 1:6d6125e88de7 | 313 | _spi.write(0x07); | 
| dreschpe | 1:6d6125e88de7 | 314 | _spi.write(0x05); | 
| dreschpe | 1:6d6125e88de7 | 315 | _spi.write(0x00); | 
| dreschpe | 1:6d6125e88de7 | 316 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 317 | |
| wim | 8:8593d3668153 | 318 | // wr_cmd(0xE1); // negativ gamma correction | 
| wim | 8:8593d3668153 | 319 | wr_cmd(ILI9341_NGAMMA); /* Negative Gamma Correction register*/ | 
| dreschpe | 1:6d6125e88de7 | 320 | _spi.write(0x00); | 
| dreschpe | 1:6d6125e88de7 | 321 | _spi.write(0x25); | 
| dreschpe | 1:6d6125e88de7 | 322 | _spi.write(0x27); | 
| dreschpe | 1:6d6125e88de7 | 323 | _spi.write(0x05); | 
| dreschpe | 1:6d6125e88de7 | 324 | _spi.write(0x10); | 
| dreschpe | 1:6d6125e88de7 | 325 | _spi.write(0x09); | 
| dreschpe | 1:6d6125e88de7 | 326 | _spi.write(0x3A); | 
| dreschpe | 1:6d6125e88de7 | 327 | _spi.write(0x78); | 
| dreschpe | 1:6d6125e88de7 | 328 | _spi.write(0x4D); | 
| dreschpe | 1:6d6125e88de7 | 329 | _spi.write(0x05); | 
| dreschpe | 1:6d6125e88de7 | 330 | _spi.write(0x18); | 
| dreschpe | 1:6d6125e88de7 | 331 | _spi.write(0x0D); | 
| dreschpe | 1:6d6125e88de7 | 332 | _spi.write(0x38); | 
| dreschpe | 1:6d6125e88de7 | 333 | _spi.write(0x3A); | 
| dreschpe | 1:6d6125e88de7 | 334 | _spi.write(0x1F); | 
| dreschpe | 1:6d6125e88de7 | 335 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 336 | |
| wim | 8:8593d3668153 | 337 | window_max(); | 
| wim | 8:8593d3668153 | 338 | |
| wim | 8:8593d3668153 | 339 | //wr_cmd(ILI9341_TEAR_OFF); // tearing effect off | 
| dreschpe | 1:6d6125e88de7 | 340 | //_cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 341 | |
| wim | 8:8593d3668153 | 342 | //wr_cmd(ILI9341_TEAR_ON); // tearing effect on | 
| dreschpe | 1:6d6125e88de7 | 343 | //_cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 344 | |
| wim | 8:8593d3668153 | 345 | //WH wr_cmd(0xB7); // entry mode | 
| wim | 8:8593d3668153 | 346 | wr_cmd(ILI9341_ENTRY_MODE); // entry mode | 
| dreschpe | 1:6d6125e88de7 | 347 | _spi.write(0x07); | 
| dreschpe | 1:6d6125e88de7 | 348 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 349 | |
| wim | 8:8593d3668153 | 350 | // wr_cmd(0xB6); // display function control | 
| wim | 8:8593d3668153 | 351 | wr_cmd(ILI9341_DFC); /* Display Function Control register*/ | 
| dreschpe | 1:6d6125e88de7 | 352 | _spi.write(0x0A); | 
| dreschpe | 1:6d6125e88de7 | 353 | _spi.write(0x82); | 
| dreschpe | 1:6d6125e88de7 | 354 | _spi.write(0x27); | 
| dreschpe | 1:6d6125e88de7 | 355 | _spi.write(0x00); | 
| dreschpe | 1:6d6125e88de7 | 356 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 357 | |
| wim | 8:8593d3668153 | 358 | // wr_cmd(0x11); // sleep out | 
| wim | 8:8593d3668153 | 359 | wr_cmd(ILI9341_SLEEP_OUT); // sleep out | 
| dreschpe | 1:6d6125e88de7 | 360 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 361 | |
| dreschpe | 1:6d6125e88de7 | 362 | wait_ms(100); | 
| dreschpe | 1:6d6125e88de7 | 363 | |
| wim | 8:8593d3668153 | 364 | // wr_cmd(0x29); // display on | 
| wim | 8:8593d3668153 | 365 | wr_cmd(ILI9341_DISPLAY_ON); | 
| dreschpe | 1:6d6125e88de7 | 366 | _cs = 1; | 
| dreschpe | 1:6d6125e88de7 | 367 | |
| dreschpe | 1:6d6125e88de7 | 368 | wait_ms(100); | 
| dreschpe | 1:6d6125e88de7 | 369 | |
| dreschpe | 1:6d6125e88de7 | 370 | } | 
| dreschpe | 0:da1bf437cbc1 | 371 | |
| dreschpe | 0:da1bf437cbc1 | 372 | |
| wim | 9:6d30a225a5c7 | 373 | void SPI_TFT_ILI9341::tft_on(bool on) | 
| wim | 9:6d30a225a5c7 | 374 | { | 
| wim | 9:6d30a225a5c7 | 375 | if (on) { | 
| wim | 9:6d30a225a5c7 | 376 | wr_cmd(ILI9341_DISPLAY_ON); | 
| wim | 9:6d30a225a5c7 | 377 | } | 
| wim | 9:6d30a225a5c7 | 378 | else { | 
| wim | 9:6d30a225a5c7 | 379 | wr_cmd(ILI9341_DISPLAY_OFF); | 
| wim | 9:6d30a225a5c7 | 380 | } | 
| wim | 9:6d30a225a5c7 | 381 | _cs = 1; | 
| wim | 9:6d30a225a5c7 | 382 | } | 
| wim | 9:6d30a225a5c7 | 383 | |
| dreschpe | 0:da1bf437cbc1 | 384 | void SPI_TFT_ILI9341::pixel(int x, int y, int color) | 
| dreschpe | 0:da1bf437cbc1 | 385 | { | 
| wim | 8:8593d3668153 | 386 | // wr_cmd(0x2A); | 
| wim | 8:8593d3668153 | 387 | wr_cmd(ILI9341_COLUMN_ADDR); | 
| dreschpe | 0:da1bf437cbc1 | 388 | _spi.write(x >> 8); | 
| dreschpe | 0:da1bf437cbc1 | 389 | _spi.write(x); | 
| wim | 9:6d30a225a5c7 | 390 | _spi.write((x+1) >> 8); //WH | 
| wim | 9:6d30a225a5c7 | 391 | _spi.write(x+1); | 
| wim | 9:6d30a225a5c7 | 392 | |
| dreschpe | 0:da1bf437cbc1 | 393 | _cs = 1; | 
| wim | 8:8593d3668153 | 394 | |
| wim | 8:8593d3668153 | 395 | // wr_cmd(0x2B); | 
| wim | 8:8593d3668153 | 396 | wr_cmd(ILI9341_PAGE_ADDR); | 
| dreschpe | 0:da1bf437cbc1 | 397 | _spi.write(y >> 8); | 
| dreschpe | 0:da1bf437cbc1 | 398 | _spi.write(y); | 
| wim | 9:6d30a225a5c7 | 399 | _spi.write((y+1) >> 8); //WH | 
| wim | 9:6d30a225a5c7 | 400 | _spi.write(y+1); | 
| wim | 9:6d30a225a5c7 | 401 | |
| dreschpe | 0:da1bf437cbc1 | 402 | _cs = 1; | 
| wim | 8:8593d3668153 | 403 | |
| wim | 8:8593d3668153 | 404 | // wr_cmd(0x2C); // send pixel | 
| wim | 8:8593d3668153 | 405 | wr_cmd(ILI9341_GRAM); // send pixel | 
| wim | 8:8593d3668153 | 406 | |
| wim | 8:8593d3668153 | 407 | //WH | 
| wim | 8:8593d3668153 | 408 | #if(0) | 
| dreschpe | 5:55aed13f2630 | 409 | #if defined TARGET_KL25Z // 8 Bit SPI | 
| dreschpe | 5:55aed13f2630 | 410 | _spi.write(color >> 8); | 
| dreschpe | 5:55aed13f2630 | 411 | _spi.write(color & 0xff); | 
| dreschpe | 5:55aed13f2630 | 412 | #else | 
| wim | 8:8593d3668153 | 413 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| dreschpe | 0:da1bf437cbc1 | 414 | _spi.write(color); // Write D0..D15 | 
| wim | 8:8593d3668153 | 415 | _spi.format(8,0); | 
| dreschpe | 5:55aed13f2630 | 416 | #endif | 
| wim | 8:8593d3668153 | 417 | #endif | 
| wim | 8:8593d3668153 | 418 | |
| wim | 9:6d30a225a5c7 | 419 | // #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 420 | #if(0) // dont bother switching for only one pixel | 
| wim | 8:8593d3668153 | 421 | // 16 Bit SPI | 
| wim | 8:8593d3668153 | 422 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| wim | 8:8593d3668153 | 423 | _spi.write(color); // Write D0..D15 | 
| wim | 8:8593d3668153 | 424 | _spi.format(8,0); // switch back to 8 bit Mode 0 | 
| wim | 8:8593d3668153 | 425 | #else | 
| wim | 8:8593d3668153 | 426 | // 8 Bit SPI | 
| wim | 8:8593d3668153 | 427 | _spi.write(color >> 8); | 
| wim | 8:8593d3668153 | 428 | _spi.write(color & 0xff); | 
| wim | 8:8593d3668153 | 429 | #endif | 
| wim | 8:8593d3668153 | 430 | |
| dreschpe | 0:da1bf437cbc1 | 431 | _cs = 1; | 
| dreschpe | 0:da1bf437cbc1 | 432 | } | 
| dreschpe | 0:da1bf437cbc1 | 433 | |
| dreschpe | 0:da1bf437cbc1 | 434 | |
| dreschpe | 0:da1bf437cbc1 | 435 | void SPI_TFT_ILI9341::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) | 
| dreschpe | 0:da1bf437cbc1 | 436 | { | 
| wim | 8:8593d3668153 | 437 | |
| wim | 8:8593d3668153 | 438 | // wr_cmd(0x2A); | 
| wim | 8:8593d3668153 | 439 | wr_cmd(ILI9341_COLUMN_ADDR); | 
| dreschpe | 0:da1bf437cbc1 | 440 | _spi.write(x >> 8); | 
| dreschpe | 0:da1bf437cbc1 | 441 | _spi.write(x); | 
| dreschpe | 0:da1bf437cbc1 | 442 | _spi.write((x+w-1) >> 8); | 
| wim | 8:8593d3668153 | 443 | _spi.write(x+w-1); | 
| dreschpe | 0:da1bf437cbc1 | 444 | _cs = 1; | 
| wim | 8:8593d3668153 | 445 | |
| wim | 8:8593d3668153 | 446 | // wr_cmd(0x2B); | 
| wim | 8:8593d3668153 | 447 | wr_cmd(ILI9341_PAGE_ADDR); | 
| dreschpe | 0:da1bf437cbc1 | 448 | _spi.write(y >> 8); | 
| dreschpe | 0:da1bf437cbc1 | 449 | _spi.write(y); | 
| dreschpe | 0:da1bf437cbc1 | 450 | _spi.write((y+h-1) >> 8); | 
| dreschpe | 0:da1bf437cbc1 | 451 | _spi.write(y+h-1); | 
| dreschpe | 0:da1bf437cbc1 | 452 | _cs = 1; | 
| dreschpe | 0:da1bf437cbc1 | 453 | } | 
| dreschpe | 0:da1bf437cbc1 | 454 | |
| dreschpe | 0:da1bf437cbc1 | 455 | |
| wim | 8:8593d3668153 | 456 | void SPI_TFT_ILI9341::window_max (void) | 
| dreschpe | 0:da1bf437cbc1 | 457 | { | 
| wim | 8:8593d3668153 | 458 | window (0, 0, width(), height()); | 
| dreschpe | 0:da1bf437cbc1 | 459 | } | 
| dreschpe | 0:da1bf437cbc1 | 460 | |
| dreschpe | 0:da1bf437cbc1 | 461 | |
| wim | 8:8593d3668153 | 462 | //WH | 
| wim | 8:8593d3668153 | 463 | #if(0) | 
| dreschpe | 0:da1bf437cbc1 | 464 | void SPI_TFT_ILI9341::cls (void) | 
| dreschpe | 0:da1bf437cbc1 | 465 | { | 
| dreschpe | 0:da1bf437cbc1 | 466 | int pixel = ( width() * height()); | 
| wim | 8:8593d3668153 | 467 | window_max(); | 
| dreschpe | 5:55aed13f2630 | 468 | wr_cmd(0x2C); // send pixel | 
| dreschpe | 5:55aed13f2630 | 469 | #if defined TARGET_KL25Z // 8 Bit SPI | 
| dreschpe | 5:55aed13f2630 | 470 | unsigned int i; | 
| dreschpe | 5:55aed13f2630 | 471 | for (i = 0; i < ( width() * height()); i++){ | 
| dreschpe | 5:55aed13f2630 | 472 | _spi.write(_background >> 8); | 
| dreschpe | 5:55aed13f2630 | 473 | _spi.write(_background & 0xff); | 
| dreschpe | 5:55aed13f2630 | 474 | } | 
| dreschpe | 5:55aed13f2630 | 475 | |
| dreschpe | 5:55aed13f2630 | 476 | #else | 
| wim | 8:8593d3668153 | 477 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| dreschpe | 0:da1bf437cbc1 | 478 | unsigned int i; | 
| dreschpe | 0:da1bf437cbc1 | 479 | for (i = 0; i < ( width() * height()); i++) | 
| dreschpe | 5:55aed13f2630 | 480 | _spi.write(_background); | 
| wim | 8:8593d3668153 | 481 | _spi.format(8,0); | 
| dreschpe | 5:55aed13f2630 | 482 | #endif | 
| dreschpe | 5:55aed13f2630 | 483 | _cs = 1; | 
| dreschpe | 0:da1bf437cbc1 | 484 | } | 
| wim | 8:8593d3668153 | 485 | #else | 
| dreschpe | 0:da1bf437cbc1 | 486 | |
| wim | 8:8593d3668153 | 487 | /** Fill the screen with _background color | 
| wim | 8:8593d3668153 | 488 | * @param none | 
| wim | 8:8593d3668153 | 489 | * @return none | 
| wim | 8:8593d3668153 | 490 | */ | 
| wim | 8:8593d3668153 | 491 | void SPI_TFT_ILI9341::cls() | 
| wim | 8:8593d3668153 | 492 | { | 
| wim | 8:8593d3668153 | 493 | fillrect(0, 0, width()-1, height()-1, _background); | 
| wim | 8:8593d3668153 | 494 | } | 
| wim | 8:8593d3668153 | 495 | |
| wim | 8:8593d3668153 | 496 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 497 | |
| dreschpe | 0:da1bf437cbc1 | 498 | void SPI_TFT_ILI9341::circle(int x0, int y0, int r, int color) | 
| dreschpe | 0:da1bf437cbc1 | 499 | { | 
| dreschpe | 0:da1bf437cbc1 | 500 | |
| mazgch | 3:3d7298360e45 | 501 | int x = -r, y = 0, err = 2-2*r, e2; | 
| mazgch | 3:3d7298360e45 | 502 | do { | 
| mazgch | 3:3d7298360e45 | 503 | pixel(x0-x, y0+y,color); | 
| mazgch | 3:3d7298360e45 | 504 | pixel(x0+x, y0+y,color); | 
| mazgch | 3:3d7298360e45 | 505 | pixel(x0+x, y0-y,color); | 
| mazgch | 3:3d7298360e45 | 506 | pixel(x0-x, y0-y,color); | 
| mazgch | 3:3d7298360e45 | 507 | e2 = err; | 
| mazgch | 3:3d7298360e45 | 508 | if (e2 <= y) { | 
| mazgch | 3:3d7298360e45 | 509 | err += ++y*2+1; | 
| mazgch | 3:3d7298360e45 | 510 | if (-x == y && e2 <= x) e2 = 0; | 
| mazgch | 3:3d7298360e45 | 511 | } | 
| mazgch | 3:3d7298360e45 | 512 | if (e2 > x) err += ++x*2+1; | 
| mazgch | 3:3d7298360e45 | 513 | } while (x <= 0); | 
| dreschpe | 4:f018e272220b | 514 | |
| dreschpe | 0:da1bf437cbc1 | 515 | } | 
| dreschpe | 0:da1bf437cbc1 | 516 | |
| mazgch | 3:3d7298360e45 | 517 | void SPI_TFT_ILI9341::fillcircle(int x0, int y0, int r, int color) | 
| dreschpe | 0:da1bf437cbc1 | 518 | { | 
| mazgch | 3:3d7298360e45 | 519 | int x = -r, y = 0, err = 2-2*r, e2; | 
| mazgch | 3:3d7298360e45 | 520 | do { | 
| mazgch | 3:3d7298360e45 | 521 | vline(x0-x, y0-y, y0+y, color); | 
| mazgch | 3:3d7298360e45 | 522 | vline(x0+x, y0-y, y0+y, color); | 
| mazgch | 3:3d7298360e45 | 523 | e2 = err; | 
| mazgch | 3:3d7298360e45 | 524 | if (e2 <= y) { | 
| mazgch | 3:3d7298360e45 | 525 | err += ++y*2+1; | 
| mazgch | 3:3d7298360e45 | 526 | if (-x == y && e2 <= x) e2 = 0; | 
| mazgch | 3:3d7298360e45 | 527 | } | 
| mazgch | 3:3d7298360e45 | 528 | if (e2 > x) err += ++x*2+1; | 
| mazgch | 3:3d7298360e45 | 529 | } while (x <= 0); | 
| dreschpe | 0:da1bf437cbc1 | 530 | } | 
| dreschpe | 0:da1bf437cbc1 | 531 | |
| wim | 9:6d30a225a5c7 | 532 | |
| wim | 9:6d30a225a5c7 | 533 | void SPI_TFT_ILI9341::oval ( int x, int y, int b, int color, float aspect ) | 
| wim | 9:6d30a225a5c7 | 534 | { | 
| wim | 9:6d30a225a5c7 | 535 | /* local variables */ | 
| wim | 9:6d30a225a5c7 | 536 | int col; /* Column. */ | 
| wim | 9:6d30a225a5c7 | 537 | int row; /* Row. */ | 
| wim | 9:6d30a225a5c7 | 538 | float aspect_square; | 
| wim | 9:6d30a225a5c7 | 539 | int a_square; | 
| wim | 9:6d30a225a5c7 | 540 | int b_square; | 
| wim | 9:6d30a225a5c7 | 541 | int two_a_square; | 
| wim | 9:6d30a225a5c7 | 542 | int two_b_square; | 
| wim | 9:6d30a225a5c7 | 543 | int four_a_square; | 
| wim | 9:6d30a225a5c7 | 544 | int four_b_square; | 
| wim | 9:6d30a225a5c7 | 545 | int d; | 
| wim | 9:6d30a225a5c7 | 546 | |
| wim | 9:6d30a225a5c7 | 547 | aspect_square = aspect * aspect; | 
| wim | 9:6d30a225a5c7 | 548 | |
| wim | 9:6d30a225a5c7 | 549 | b_square = b * b; | 
| wim | 9:6d30a225a5c7 | 550 | a_square = b_square / aspect_square; | 
| wim | 9:6d30a225a5c7 | 551 | row = b; | 
| wim | 9:6d30a225a5c7 | 552 | col = 0; | 
| wim | 9:6d30a225a5c7 | 553 | two_a_square = a_square << 1; | 
| wim | 9:6d30a225a5c7 | 554 | four_a_square = a_square << 2; | 
| wim | 9:6d30a225a5c7 | 555 | four_b_square = b_square << 2; | 
| wim | 9:6d30a225a5c7 | 556 | two_b_square = b_square << 1; | 
| wim | 9:6d30a225a5c7 | 557 | d = two_a_square * ((row - 1) * (row)) + a_square + two_b_square * (1 - a_square); | 
| wim | 9:6d30a225a5c7 | 558 | |
| wim | 9:6d30a225a5c7 | 559 | while (a_square * (row) > b_square * col ) { | 
| wim | 9:6d30a225a5c7 | 560 | pixel( x + col, y + row, color ); | 
| wim | 9:6d30a225a5c7 | 561 | pixel( x + col, y - row, color ); | 
| wim | 9:6d30a225a5c7 | 562 | pixel( x - col, y + row, color ); | 
| wim | 9:6d30a225a5c7 | 563 | pixel( x - col, y - row, color ); | 
| wim | 9:6d30a225a5c7 | 564 | if ( d >= 0 ) { | 
| wim | 9:6d30a225a5c7 | 565 | row--; | 
| wim | 9:6d30a225a5c7 | 566 | d -= four_a_square * row; | 
| wim | 9:6d30a225a5c7 | 567 | } | 
| wim | 9:6d30a225a5c7 | 568 | d += two_b_square * (3 + (col << 1)); | 
| wim | 9:6d30a225a5c7 | 569 | col++; | 
| wim | 9:6d30a225a5c7 | 570 | } | 
| wim | 9:6d30a225a5c7 | 571 | |
| wim | 9:6d30a225a5c7 | 572 | d = two_b_square * (col + 1) * col + two_a_square * (row * (row - 2) + 1) + (1 - two_a_square) * b_square; | 
| wim | 9:6d30a225a5c7 | 573 | |
| wim | 9:6d30a225a5c7 | 574 | while ( row + 1 ) { | 
| wim | 9:6d30a225a5c7 | 575 | pixel( x + col, y + row, color ); | 
| wim | 9:6d30a225a5c7 | 576 | pixel( x + col, y - row, color ); | 
| wim | 9:6d30a225a5c7 | 577 | pixel( x - col, y + row, color ); | 
| wim | 9:6d30a225a5c7 | 578 | pixel( x - col, y - row, color ); | 
| wim | 9:6d30a225a5c7 | 579 | if ( d <= 0 ) { | 
| wim | 9:6d30a225a5c7 | 580 | col++; | 
| wim | 9:6d30a225a5c7 | 581 | d += four_b_square * col; | 
| wim | 9:6d30a225a5c7 | 582 | } | 
| wim | 9:6d30a225a5c7 | 583 | row--; | 
| wim | 9:6d30a225a5c7 | 584 | d += two_a_square * (3 - (row << 1)); | 
| wim | 9:6d30a225a5c7 | 585 | } | 
| wim | 9:6d30a225a5c7 | 586 | |
| wim | 9:6d30a225a5c7 | 587 | } /* End oval */ | 
| wim | 9:6d30a225a5c7 | 588 | |
| wim | 9:6d30a225a5c7 | 589 | |
| wim | 9:6d30a225a5c7 | 590 | void SPI_TFT_ILI9341::filloval ( int x, int y, int b, int color, float aspect ) | 
| wim | 9:6d30a225a5c7 | 591 | { | 
| wim | 9:6d30a225a5c7 | 592 | /* local variables */ | 
| wim | 9:6d30a225a5c7 | 593 | int col; /* Column. */ | 
| wim | 9:6d30a225a5c7 | 594 | int row; /* Row. */ | 
| wim | 9:6d30a225a5c7 | 595 | float aspect_square; | 
| wim | 9:6d30a225a5c7 | 596 | int a_square; | 
| wim | 9:6d30a225a5c7 | 597 | int b_square; | 
| wim | 9:6d30a225a5c7 | 598 | int two_a_square; | 
| wim | 9:6d30a225a5c7 | 599 | int two_b_square; | 
| wim | 9:6d30a225a5c7 | 600 | int four_a_square; | 
| wim | 9:6d30a225a5c7 | 601 | int four_b_square; | 
| wim | 9:6d30a225a5c7 | 602 | int d; | 
| wim | 9:6d30a225a5c7 | 603 | |
| wim | 9:6d30a225a5c7 | 604 | aspect_square = aspect * aspect; | 
| wim | 9:6d30a225a5c7 | 605 | |
| wim | 9:6d30a225a5c7 | 606 | b_square = b * b; | 
| wim | 9:6d30a225a5c7 | 607 | a_square = b_square / aspect_square; | 
| wim | 9:6d30a225a5c7 | 608 | row = b; | 
| wim | 9:6d30a225a5c7 | 609 | col = 0; | 
| wim | 9:6d30a225a5c7 | 610 | two_a_square = a_square << 1; | 
| wim | 9:6d30a225a5c7 | 611 | four_a_square = a_square << 2; | 
| wim | 9:6d30a225a5c7 | 612 | four_b_square = b_square << 2; | 
| wim | 9:6d30a225a5c7 | 613 | two_b_square = b_square << 1; | 
| wim | 9:6d30a225a5c7 | 614 | d = two_a_square * ((row - 1) * (row)) + a_square + two_b_square * (1 - a_square); | 
| wim | 9:6d30a225a5c7 | 615 | |
| wim | 9:6d30a225a5c7 | 616 | while (a_square * (row) > b_square * col ) { | 
| wim | 9:6d30a225a5c7 | 617 | vline(x - col, y - row, y + row, color); | 
| wim | 9:6d30a225a5c7 | 618 | vline(x + col, y - row, y + row, color); | 
| wim | 9:6d30a225a5c7 | 619 | |
| wim | 9:6d30a225a5c7 | 620 | if ( d >= 0 ) { | 
| wim | 9:6d30a225a5c7 | 621 | row--; | 
| wim | 9:6d30a225a5c7 | 622 | d -= four_a_square * row; | 
| wim | 9:6d30a225a5c7 | 623 | } | 
| wim | 9:6d30a225a5c7 | 624 | d += two_b_square * (3 + (col << 1)); | 
| wim | 9:6d30a225a5c7 | 625 | col++; | 
| wim | 9:6d30a225a5c7 | 626 | } | 
| wim | 9:6d30a225a5c7 | 627 | |
| wim | 9:6d30a225a5c7 | 628 | d = two_b_square * (col + 1) * col + two_a_square * (row * (row - 2) + 1) + (1 - two_a_square) * b_square; | 
| wim | 9:6d30a225a5c7 | 629 | |
| wim | 9:6d30a225a5c7 | 630 | while ( row + 1 ) { | 
| wim | 9:6d30a225a5c7 | 631 | vline(x - col, y - row, y + row, color); | 
| wim | 9:6d30a225a5c7 | 632 | vline(x + col, y - row, y + row, color); | 
| wim | 9:6d30a225a5c7 | 633 | |
| wim | 9:6d30a225a5c7 | 634 | if ( d <= 0 ) { | 
| wim | 9:6d30a225a5c7 | 635 | col++; | 
| wim | 9:6d30a225a5c7 | 636 | d += four_b_square * col; | 
| wim | 9:6d30a225a5c7 | 637 | } | 
| wim | 9:6d30a225a5c7 | 638 | row--; | 
| wim | 9:6d30a225a5c7 | 639 | d += two_a_square * (3 - (row << 1)); | 
| wim | 9:6d30a225a5c7 | 640 | } | 
| wim | 9:6d30a225a5c7 | 641 | |
| wim | 9:6d30a225a5c7 | 642 | } /* End filloval */ | 
| wim | 9:6d30a225a5c7 | 643 | |
| wim | 9:6d30a225a5c7 | 644 | |
| wim | 9:6d30a225a5c7 | 645 | |
| wim | 8:8593d3668153 | 646 | //WH | 
| wim | 8:8593d3668153 | 647 | #if(0) | 
| dreschpe | 0:da1bf437cbc1 | 648 | void SPI_TFT_ILI9341::hline(int x0, int x1, int y, int color) | 
| dreschpe | 0:da1bf437cbc1 | 649 | { | 
| dreschpe | 0:da1bf437cbc1 | 650 | int w; | 
| dreschpe | 0:da1bf437cbc1 | 651 | w = x1 - x0 + 1; | 
| dreschpe | 0:da1bf437cbc1 | 652 | window(x0,y,w,1); | 
| dreschpe | 5:55aed13f2630 | 653 | wr_cmd(0x2C); // send pixel | 
| dreschpe | 5:55aed13f2630 | 654 | #if defined TARGET_KL25Z // 8 Bit SPI | 
| dreschpe | 5:55aed13f2630 | 655 | int j; | 
| dreschpe | 5:55aed13f2630 | 656 | for (j=0; j<w; j++) { | 
| dreschpe | 5:55aed13f2630 | 657 | _spi.write(color >> 8); | 
| dreschpe | 5:55aed13f2630 | 658 | _spi.write(color & 0xff); | 
| dreschpe | 5:55aed13f2630 | 659 | } | 
| dreschpe | 5:55aed13f2630 | 660 | #else | 
| wim | 8:8593d3668153 | 661 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| dreschpe | 0:da1bf437cbc1 | 662 | int j; | 
| dreschpe | 0:da1bf437cbc1 | 663 | for (j=0; j<w; j++) { | 
| dreschpe | 0:da1bf437cbc1 | 664 | _spi.write(color); | 
| dreschpe | 0:da1bf437cbc1 | 665 | } | 
| wim | 8:8593d3668153 | 666 | _spi.format(8,0); | 
| dreschpe | 5:55aed13f2630 | 667 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 668 | _cs = 1; | 
| wim | 8:8593d3668153 | 669 | window_max(); | 
| dreschpe | 0:da1bf437cbc1 | 670 | return; | 
| dreschpe | 0:da1bf437cbc1 | 671 | } | 
| wim | 8:8593d3668153 | 672 | #else | 
| wim | 8:8593d3668153 | 673 | void SPI_TFT_ILI9341::hline(int x0, int x1, int y, int color) | 
| wim | 8:8593d3668153 | 674 | { | 
| wim | 8:8593d3668153 | 675 | int i, w; | 
| wim | 8:8593d3668153 | 676 | int msb, lsb; | 
| wim | 8:8593d3668153 | 677 | w = x1 - x0 + 1; | 
| wim | 8:8593d3668153 | 678 | window(x0,y,w,1); | 
| wim | 8:8593d3668153 | 679 | // wr_cmd(0x2C); // send pixel | 
| wim | 8:8593d3668153 | 680 | wr_cmd(ILI9341_GRAM); // send pixel | 
| wim | 8:8593d3668153 | 681 | |
| wim | 8:8593d3668153 | 682 | #if (SPI_16 == 1) | 
| wim | 8:8593d3668153 | 683 | // 16 Bit SPI | 
| wim | 8:8593d3668153 | 684 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| wim | 8:8593d3668153 | 685 | for (i = 0; i < w; i++) | 
| wim | 8:8593d3668153 | 686 | _spi.write(color); | 
| wim | 8:8593d3668153 | 687 | _spi.format(8,0); // switch back to 8 bit Mode 0 | 
| wim | 8:8593d3668153 | 688 | #else | 
| wim | 8:8593d3668153 | 689 | // 8 Bit SPI | 
| wim | 8:8593d3668153 | 690 | msb = color >> 8; | 
| wim | 8:8593d3668153 | 691 | lsb = color & 0xff; | 
| wim | 8:8593d3668153 | 692 | for (i = 0; i < w; i++){ | 
| wim | 8:8593d3668153 | 693 | _spi.write(msb); | 
| wim | 8:8593d3668153 | 694 | _spi.write(lsb); | 
| wim | 8:8593d3668153 | 695 | } | 
| wim | 8:8593d3668153 | 696 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 697 | |
| wim | 8:8593d3668153 | 698 | _cs = 1; | 
| wim | 8:8593d3668153 | 699 | window_max(); | 
| wim | 8:8593d3668153 | 700 | } | 
| wim | 8:8593d3668153 | 701 | #endif | 
| wim | 8:8593d3668153 | 702 | |
| wim | 8:8593d3668153 | 703 | |
| wim | 8:8593d3668153 | 704 | |
| wim | 8:8593d3668153 | 705 | //WH | 
| wim | 8:8593d3668153 | 706 | #if(0) | 
| dreschpe | 0:da1bf437cbc1 | 707 | void SPI_TFT_ILI9341::vline(int x, int y0, int y1, int color) | 
| dreschpe | 0:da1bf437cbc1 | 708 | { | 
| dreschpe | 0:da1bf437cbc1 | 709 | int h; | 
| dreschpe | 0:da1bf437cbc1 | 710 | h = y1 - y0 + 1; | 
| dreschpe | 0:da1bf437cbc1 | 711 | window(x,y0,1,h); | 
| dreschpe | 5:55aed13f2630 | 712 | wr_cmd(0x2C); // send pixel | 
| dreschpe | 5:55aed13f2630 | 713 | #if defined TARGET_KL25Z // 8 Bit SPI | 
| dreschpe | 5:55aed13f2630 | 714 | for (int y=0; y<h; y++) { | 
| dreschpe | 5:55aed13f2630 | 715 | _spi.write(color >> 8); | 
| dreschpe | 5:55aed13f2630 | 716 | _spi.write(color & 0xff); | 
| dreschpe | 5:55aed13f2630 | 717 | } | 
| dreschpe | 5:55aed13f2630 | 718 | #else | 
| wim | 8:8593d3668153 | 719 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| dreschpe | 0:da1bf437cbc1 | 720 | for (int y=0; y<h; y++) { | 
| dreschpe | 0:da1bf437cbc1 | 721 | _spi.write(color); | 
| dreschpe | 0:da1bf437cbc1 | 722 | } | 
| wim | 8:8593d3668153 | 723 | _spi.format(8,0); | 
| dreschpe | 5:55aed13f2630 | 724 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 725 | _cs = 1; | 
| wim | 8:8593d3668153 | 726 | window_max(); | 
| dreschpe | 0:da1bf437cbc1 | 727 | return; | 
| dreschpe | 0:da1bf437cbc1 | 728 | } | 
| wim | 8:8593d3668153 | 729 | #else | 
| wim | 8:8593d3668153 | 730 | void SPI_TFT_ILI9341::vline(int x, int y0, int y1, int color) | 
| wim | 8:8593d3668153 | 731 | { | 
| wim | 8:8593d3668153 | 732 | int i, h; | 
| wim | 8:8593d3668153 | 733 | int msb, lsb; | 
| wim | 8:8593d3668153 | 734 | |
| wim | 8:8593d3668153 | 735 | h = y1 - y0 + 1; | 
| wim | 8:8593d3668153 | 736 | window(x,y0,1,h); | 
| wim | 8:8593d3668153 | 737 | // wr_cmd(0x2C); // send pixel | 
| wim | 8:8593d3668153 | 738 | wr_cmd(ILI9341_GRAM); // send pixel | 
| dreschpe | 0:da1bf437cbc1 | 739 | |
| wim | 8:8593d3668153 | 740 | #if (SPI_16 == 1) | 
| wim | 8:8593d3668153 | 741 | // 16 Bit SPI | 
| wim | 8:8593d3668153 | 742 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| wim | 8:8593d3668153 | 743 | for (i = 0; i < h; i++) | 
| wim | 8:8593d3668153 | 744 | _spi.write(color); | 
| wim | 8:8593d3668153 | 745 | _spi.format(8,0); // switch back to 8 bit Mode 0 | 
| wim | 8:8593d3668153 | 746 | #else | 
| wim | 8:8593d3668153 | 747 | // 8 Bit SPI | 
| wim | 8:8593d3668153 | 748 | msb = color >> 8; | 
| wim | 8:8593d3668153 | 749 | lsb = color & 0xff; | 
| wim | 8:8593d3668153 | 750 | for (i = 0; i < h; i++){ | 
| wim | 8:8593d3668153 | 751 | _spi.write(msb); | 
| wim | 8:8593d3668153 | 752 | _spi.write(lsb); | 
| wim | 8:8593d3668153 | 753 | } | 
| wim | 8:8593d3668153 | 754 | #endif | 
| wim | 8:8593d3668153 | 755 | |
| wim | 8:8593d3668153 | 756 | _cs = 1; | 
| wim | 8:8593d3668153 | 757 | window_max(); | 
| wim | 8:8593d3668153 | 758 | } | 
| wim | 8:8593d3668153 | 759 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 760 | |
| dreschpe | 0:da1bf437cbc1 | 761 | void SPI_TFT_ILI9341::line(int x0, int y0, int x1, int y1, int color) | 
| dreschpe | 0:da1bf437cbc1 | 762 | { | 
| wim | 8:8593d3668153 | 763 | //window_max(); | 
| dreschpe | 0:da1bf437cbc1 | 764 | int dx = 0, dy = 0; | 
| dreschpe | 0:da1bf437cbc1 | 765 | int dx_sym = 0, dy_sym = 0; | 
| dreschpe | 0:da1bf437cbc1 | 766 | int dx_x2 = 0, dy_x2 = 0; | 
| dreschpe | 0:da1bf437cbc1 | 767 | int di = 0; | 
| dreschpe | 0:da1bf437cbc1 | 768 | |
| dreschpe | 0:da1bf437cbc1 | 769 | dx = x1-x0; | 
| dreschpe | 0:da1bf437cbc1 | 770 | dy = y1-y0; | 
| dreschpe | 0:da1bf437cbc1 | 771 | |
| dreschpe | 0:da1bf437cbc1 | 772 | if (dx == 0) { /* vertical line */ | 
| dreschpe | 0:da1bf437cbc1 | 773 | if (y1 > y0) vline(x0,y0,y1,color); | 
| dreschpe | 0:da1bf437cbc1 | 774 | else vline(x0,y1,y0,color); | 
| dreschpe | 0:da1bf437cbc1 | 775 | return; | 
| dreschpe | 0:da1bf437cbc1 | 776 | } | 
| dreschpe | 0:da1bf437cbc1 | 777 | |
| dreschpe | 0:da1bf437cbc1 | 778 | if (dx > 0) { | 
| dreschpe | 0:da1bf437cbc1 | 779 | dx_sym = 1; | 
| dreschpe | 0:da1bf437cbc1 | 780 | } else { | 
| dreschpe | 0:da1bf437cbc1 | 781 | dx_sym = -1; | 
| dreschpe | 0:da1bf437cbc1 | 782 | } | 
| dreschpe | 0:da1bf437cbc1 | 783 | if (dy == 0) { /* horizontal line */ | 
| dreschpe | 0:da1bf437cbc1 | 784 | if (x1 > x0) hline(x0,x1,y0,color); | 
| dreschpe | 0:da1bf437cbc1 | 785 | else hline(x1,x0,y0,color); | 
| dreschpe | 0:da1bf437cbc1 | 786 | return; | 
| dreschpe | 0:da1bf437cbc1 | 787 | } | 
| dreschpe | 0:da1bf437cbc1 | 788 | |
| dreschpe | 0:da1bf437cbc1 | 789 | if (dy > 0) { | 
| dreschpe | 0:da1bf437cbc1 | 790 | dy_sym = 1; | 
| dreschpe | 0:da1bf437cbc1 | 791 | } else { | 
| dreschpe | 0:da1bf437cbc1 | 792 | dy_sym = -1; | 
| dreschpe | 0:da1bf437cbc1 | 793 | } | 
| dreschpe | 0:da1bf437cbc1 | 794 | |
| dreschpe | 0:da1bf437cbc1 | 795 | dx = dx_sym*dx; | 
| dreschpe | 0:da1bf437cbc1 | 796 | dy = dy_sym*dy; | 
| dreschpe | 0:da1bf437cbc1 | 797 | |
| dreschpe | 0:da1bf437cbc1 | 798 | dx_x2 = dx*2; | 
| dreschpe | 0:da1bf437cbc1 | 799 | dy_x2 = dy*2; | 
| dreschpe | 0:da1bf437cbc1 | 800 | |
| dreschpe | 0:da1bf437cbc1 | 801 | if (dx >= dy) { | 
| dreschpe | 0:da1bf437cbc1 | 802 | di = dy_x2 - dx; | 
| dreschpe | 0:da1bf437cbc1 | 803 | while (x0 != x1) { | 
| dreschpe | 0:da1bf437cbc1 | 804 | |
| dreschpe | 0:da1bf437cbc1 | 805 | pixel(x0, y0, color); | 
| dreschpe | 0:da1bf437cbc1 | 806 | x0 += dx_sym; | 
| dreschpe | 0:da1bf437cbc1 | 807 | if (di<0) { | 
| dreschpe | 0:da1bf437cbc1 | 808 | di += dy_x2; | 
| dreschpe | 0:da1bf437cbc1 | 809 | } else { | 
| dreschpe | 0:da1bf437cbc1 | 810 | di += dy_x2 - dx_x2; | 
| dreschpe | 0:da1bf437cbc1 | 811 | y0 += dy_sym; | 
| dreschpe | 0:da1bf437cbc1 | 812 | } | 
| dreschpe | 0:da1bf437cbc1 | 813 | } | 
| dreschpe | 0:da1bf437cbc1 | 814 | pixel(x0, y0, color); | 
| dreschpe | 0:da1bf437cbc1 | 815 | } else { | 
| dreschpe | 0:da1bf437cbc1 | 816 | di = dx_x2 - dy; | 
| dreschpe | 0:da1bf437cbc1 | 817 | while (y0 != y1) { | 
| dreschpe | 0:da1bf437cbc1 | 818 | pixel(x0, y0, color); | 
| dreschpe | 0:da1bf437cbc1 | 819 | y0 += dy_sym; | 
| dreschpe | 0:da1bf437cbc1 | 820 | if (di < 0) { | 
| dreschpe | 0:da1bf437cbc1 | 821 | di += dx_x2; | 
| dreschpe | 0:da1bf437cbc1 | 822 | } else { | 
| dreschpe | 0:da1bf437cbc1 | 823 | di += dx_x2 - dy_x2; | 
| dreschpe | 0:da1bf437cbc1 | 824 | x0 += dx_sym; | 
| dreschpe | 0:da1bf437cbc1 | 825 | } | 
| dreschpe | 0:da1bf437cbc1 | 826 | } | 
| dreschpe | 0:da1bf437cbc1 | 827 | pixel(x0, y0, color); | 
| dreschpe | 0:da1bf437cbc1 | 828 | } | 
| wim | 8:8593d3668153 | 829 | //WH return; | 
| dreschpe | 0:da1bf437cbc1 | 830 | } | 
| dreschpe | 0:da1bf437cbc1 | 831 | |
| dreschpe | 0:da1bf437cbc1 | 832 | |
| dreschpe | 0:da1bf437cbc1 | 833 | void SPI_TFT_ILI9341::rect(int x0, int y0, int x1, int y1, int color) | 
| dreschpe | 0:da1bf437cbc1 | 834 | { | 
| dreschpe | 0:da1bf437cbc1 | 835 | |
| dreschpe | 0:da1bf437cbc1 | 836 | if (x1 > x0) hline(x0,x1,y0,color); | 
| dreschpe | 0:da1bf437cbc1 | 837 | else hline(x1,x0,y0,color); | 
| dreschpe | 0:da1bf437cbc1 | 838 | |
| dreschpe | 0:da1bf437cbc1 | 839 | if (y1 > y0) vline(x0,y0,y1,color); | 
| dreschpe | 0:da1bf437cbc1 | 840 | else vline(x0,y1,y0,color); | 
| dreschpe | 0:da1bf437cbc1 | 841 | |
| dreschpe | 0:da1bf437cbc1 | 842 | if (x1 > x0) hline(x0,x1,y1,color); | 
| dreschpe | 0:da1bf437cbc1 | 843 | else hline(x1,x0,y1,color); | 
| dreschpe | 0:da1bf437cbc1 | 844 | |
| dreschpe | 0:da1bf437cbc1 | 845 | if (y1 > y0) vline(x1,y0,y1,color); | 
| dreschpe | 0:da1bf437cbc1 | 846 | else vline(x1,y1,y0,color); | 
| dreschpe | 0:da1bf437cbc1 | 847 | |
| wim | 8:8593d3668153 | 848 | //WH return; | 
| dreschpe | 0:da1bf437cbc1 | 849 | } | 
| dreschpe | 0:da1bf437cbc1 | 850 | |
| dreschpe | 0:da1bf437cbc1 | 851 | |
| wim | 8:8593d3668153 | 852 | //WH | 
| wim | 8:8593d3668153 | 853 | #if(0) | 
| dreschpe | 0:da1bf437cbc1 | 854 | void SPI_TFT_ILI9341::fillrect(int x0, int y0, int x1, int y1, int color) | 
| dreschpe | 0:da1bf437cbc1 | 855 | { | 
| dreschpe | 0:da1bf437cbc1 | 856 | int h = y1 - y0 + 1; | 
| dreschpe | 0:da1bf437cbc1 | 857 | int w = x1 - x0 + 1; | 
| dreschpe | 0:da1bf437cbc1 | 858 | int pixel = h * w; | 
| dreschpe | 0:da1bf437cbc1 | 859 | window(x0,y0,w,h); | 
| dreschpe | 0:da1bf437cbc1 | 860 | wr_cmd(0x2C); // send pixel | 
| dreschpe | 5:55aed13f2630 | 861 | #if defined TARGET_KL25Z // 8 Bit SPI | 
| dreschpe | 5:55aed13f2630 | 862 | for (int p=0; p<pixel; p++) { | 
| dreschpe | 5:55aed13f2630 | 863 | _spi.write(color >> 8); | 
| dreschpe | 5:55aed13f2630 | 864 | _spi.write(color & 0xff); | 
| dreschpe | 5:55aed13f2630 | 865 | } | 
| dreschpe | 5:55aed13f2630 | 866 | #else | 
| wim | 8:8593d3668153 | 867 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| dreschpe | 0:da1bf437cbc1 | 868 | for (int p=0; p<pixel; p++) { | 
| dreschpe | 0:da1bf437cbc1 | 869 | _spi.write(color); | 
| dreschpe | 0:da1bf437cbc1 | 870 | } | 
| wim | 8:8593d3668153 | 871 | _spi.format(8,0); | 
| dreschpe | 5:55aed13f2630 | 872 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 873 | _cs = 1; | 
| wim | 8:8593d3668153 | 874 | window_max(); | 
| dreschpe | 0:da1bf437cbc1 | 875 | return; | 
| dreschpe | 0:da1bf437cbc1 | 876 | } | 
| dreschpe | 0:da1bf437cbc1 | 877 | |
| wim | 8:8593d3668153 | 878 | #else | 
| wim | 8:8593d3668153 | 879 | |
| wim | 8:8593d3668153 | 880 | void SPI_TFT_ILI9341::fillrect(int x0, int y0, int x1, int y1, int color) | 
| wim | 8:8593d3668153 | 881 | { | 
| wim | 9:6d30a225a5c7 | 882 | //sanity check | 
| wim | 9:6d30a225a5c7 | 883 | if ( x0 > x1 ) swap( int, x0, x1 ) | 
| wim | 9:6d30a225a5c7 | 884 | if ( y0 > y1 ) swap( int, y0, y1 ) | 
| wim | 9:6d30a225a5c7 | 885 | |
| wim | 9:6d30a225a5c7 | 886 | int h = y1 - y0 + 1; | 
| wim | 9:6d30a225a5c7 | 887 | int w = x1 - x0 + 1; | 
| wim | 8:8593d3668153 | 888 | int pixels = h * w; | 
| wim | 8:8593d3668153 | 889 | int i, msb, lsb; | 
| wim | 8:8593d3668153 | 890 | |
| wim | 8:8593d3668153 | 891 | window(x0,y0,w,h); | 
| wim | 8:8593d3668153 | 892 | // wr_cmd(0x2C); // send pixel | 
| wim | 8:8593d3668153 | 893 | wr_cmd(ILI9341_GRAM); // send pixel | 
| wim | 8:8593d3668153 | 894 | |
| wim | 8:8593d3668153 | 895 | #if (SPI_16 == 1) | 
| wim | 8:8593d3668153 | 896 | // 16 Bit SPI | 
| wim | 8:8593d3668153 | 897 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| wim | 8:8593d3668153 | 898 | for (i = 0; i < pixels; i++) | 
| wim | 8:8593d3668153 | 899 | _spi.write(color); | 
| wim | 8:8593d3668153 | 900 | _spi.format(8,0); // switch back to 8 bit Mode 0 | 
| wim | 8:8593d3668153 | 901 | #else | 
| wim | 8:8593d3668153 | 902 | // 8 Bit SPI | 
| wim | 8:8593d3668153 | 903 | msb = color >> 8; | 
| wim | 8:8593d3668153 | 904 | lsb = color & 0xff; | 
| wim | 8:8593d3668153 | 905 | for (i = 0; i < pixels; i++){ | 
| wim | 8:8593d3668153 | 906 | _spi.write(msb); | 
| wim | 8:8593d3668153 | 907 | _spi.write(lsb); | 
| wim | 8:8593d3668153 | 908 | } | 
| wim | 8:8593d3668153 | 909 | #endif | 
| wim | 8:8593d3668153 | 910 | |
| wim | 8:8593d3668153 | 911 | _cs = 1; | 
| wim | 8:8593d3668153 | 912 | } | 
| wim | 8:8593d3668153 | 913 | #endif | 
| wim | 8:8593d3668153 | 914 | |
| wim | 9:6d30a225a5c7 | 915 | void SPI_TFT_ILI9341::roundrect( int x1, int y1, int x2, int y2, int color ) | 
| wim | 9:6d30a225a5c7 | 916 | { | 
| wim | 9:6d30a225a5c7 | 917 | //sanity check | 
| wim | 9:6d30a225a5c7 | 918 | if ( x1 > x2 ) swap( int, x1, x2 ) | 
| wim | 9:6d30a225a5c7 | 919 | if ( y1 > y2 ) swap( int, y1, y2 ) | 
| wim | 9:6d30a225a5c7 | 920 | |
| wim | 9:6d30a225a5c7 | 921 | if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 ) | 
| wim | 9:6d30a225a5c7 | 922 | { | 
| wim | 9:6d30a225a5c7 | 923 | pixel( x1 + 1, y1 + 1, color ); | 
| wim | 9:6d30a225a5c7 | 924 | pixel( x2 - 1, y1 + 1, color ); | 
| wim | 9:6d30a225a5c7 | 925 | pixel( x1 + 1, y2 - 1, color ); | 
| wim | 9:6d30a225a5c7 | 926 | pixel( x2 - 1, y2 - 1, color ); | 
| wim | 9:6d30a225a5c7 | 927 | //x0, x1, y | 
| wim | 9:6d30a225a5c7 | 928 | hline( x1 + 2, x2 - 2 ,y1, color ); | 
| wim | 9:6d30a225a5c7 | 929 | hline( x1 + 2, x2 - 2, y2, color ); | 
| wim | 9:6d30a225a5c7 | 930 | //y0, y1, x | 
| wim | 9:6d30a225a5c7 | 931 | vline( y1 + 2, y2 - 2, x1, color ); | 
| wim | 9:6d30a225a5c7 | 932 | vline( y1 + 2, y2 - 2, x2, color ); | 
| wim | 9:6d30a225a5c7 | 933 | } | 
| wim | 9:6d30a225a5c7 | 934 | } | 
| wim | 9:6d30a225a5c7 | 935 | |
| wim | 9:6d30a225a5c7 | 936 | |
| wim | 9:6d30a225a5c7 | 937 | void SPI_TFT_ILI9341::fillroundrect( int x1, int y1, int x2, int y2, int color ) | 
| wim | 9:6d30a225a5c7 | 938 | { | 
| wim | 9:6d30a225a5c7 | 939 | //sanity check | 
| wim | 9:6d30a225a5c7 | 940 | if ( x1 > x2 ) swap( int, x1, x2 ) | 
| wim | 9:6d30a225a5c7 | 941 | if ( y1 > y2 ) swap( int, y1, y2 ) | 
| wim | 9:6d30a225a5c7 | 942 | |
| wim | 9:6d30a225a5c7 | 943 | if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 ) | 
| wim | 9:6d30a225a5c7 | 944 | { | 
| wim | 9:6d30a225a5c7 | 945 | for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ ) | 
| wim | 9:6d30a225a5c7 | 946 | { | 
| wim | 9:6d30a225a5c7 | 947 | switch ( i ) | 
| wim | 9:6d30a225a5c7 | 948 | { | 
| wim | 9:6d30a225a5c7 | 949 | case 0: | 
| wim | 9:6d30a225a5c7 | 950 | hline( x1 + 2, x2 - 2, y1 + i, color ); | 
| wim | 9:6d30a225a5c7 | 951 | hline( x1 + 2, x2 - 2, y2 - i, color ); | 
| wim | 9:6d30a225a5c7 | 952 | break; | 
| wim | 9:6d30a225a5c7 | 953 | |
| wim | 9:6d30a225a5c7 | 954 | case 1: | 
| wim | 9:6d30a225a5c7 | 955 | hline( x1 + 1, x2 - 1, y1 + i, color ); | 
| wim | 9:6d30a225a5c7 | 956 | hline( x1 + 1, x2 - 1, y2 - i, color ); | 
| wim | 9:6d30a225a5c7 | 957 | break; | 
| wim | 9:6d30a225a5c7 | 958 | |
| wim | 9:6d30a225a5c7 | 959 | default: | 
| wim | 9:6d30a225a5c7 | 960 | hline( x1, x2, y1 + i, color ); | 
| wim | 9:6d30a225a5c7 | 961 | hline( x1, x2, y2 - i, color ); | 
| wim | 9:6d30a225a5c7 | 962 | break; | 
| wim | 9:6d30a225a5c7 | 963 | } | 
| wim | 9:6d30a225a5c7 | 964 | } | 
| wim | 9:6d30a225a5c7 | 965 | } | 
| wim | 9:6d30a225a5c7 | 966 | } | 
| wim | 9:6d30a225a5c7 | 967 | |
| wim | 8:8593d3668153 | 968 | |
| dreschpe | 0:da1bf437cbc1 | 969 | |
| dreschpe | 0:da1bf437cbc1 | 970 | void SPI_TFT_ILI9341::locate(int x, int y) | 
| dreschpe | 0:da1bf437cbc1 | 971 | { | 
| wim | 9:6d30a225a5c7 | 972 | _char_x = x; | 
| wim | 9:6d30a225a5c7 | 973 | _char_y = y; | 
| dreschpe | 0:da1bf437cbc1 | 974 | } | 
| dreschpe | 0:da1bf437cbc1 | 975 | |
| dreschpe | 0:da1bf437cbc1 | 976 | |
| dreschpe | 0:da1bf437cbc1 | 977 | |
| dreschpe | 0:da1bf437cbc1 | 978 | int SPI_TFT_ILI9341::columns() | 
| dreschpe | 0:da1bf437cbc1 | 979 | { | 
| wim | 8:8593d3668153 | 980 | return width() / _font[1]; | 
| dreschpe | 0:da1bf437cbc1 | 981 | } | 
| dreschpe | 0:da1bf437cbc1 | 982 | |
| dreschpe | 0:da1bf437cbc1 | 983 | |
| dreschpe | 0:da1bf437cbc1 | 984 | |
| dreschpe | 0:da1bf437cbc1 | 985 | int SPI_TFT_ILI9341::rows() | 
| dreschpe | 0:da1bf437cbc1 | 986 | { | 
| wim | 8:8593d3668153 | 987 | return height() / _font[2]; | 
| dreschpe | 0:da1bf437cbc1 | 988 | } | 
| dreschpe | 0:da1bf437cbc1 | 989 | |
| dreschpe | 0:da1bf437cbc1 | 990 | |
| dreschpe | 0:da1bf437cbc1 | 991 | |
| dreschpe | 0:da1bf437cbc1 | 992 | int SPI_TFT_ILI9341::_putc(int value) | 
| dreschpe | 0:da1bf437cbc1 | 993 | { | 
| dreschpe | 0:da1bf437cbc1 | 994 | if (value == '\n') { // new line | 
| wim | 9:6d30a225a5c7 | 995 | _char_x = 0; | 
| wim | 9:6d30a225a5c7 | 996 | _char_y = _char_y + _font[2]; | 
| wim | 9:6d30a225a5c7 | 997 | if (_char_y >= height() - _font[2]) { | 
| wim | 9:6d30a225a5c7 | 998 | _char_y = 0; | 
| dreschpe | 0:da1bf437cbc1 | 999 | } | 
| dreschpe | 0:da1bf437cbc1 | 1000 | } else { | 
| wim | 9:6d30a225a5c7 | 1001 | character(_char_x, _char_y, value); | 
| dreschpe | 0:da1bf437cbc1 | 1002 | } | 
| dreschpe | 0:da1bf437cbc1 | 1003 | return value; | 
| dreschpe | 0:da1bf437cbc1 | 1004 | } | 
| dreschpe | 0:da1bf437cbc1 | 1005 | |
| wim | 8:8593d3668153 | 1006 | //WH | 
| wim | 8:8593d3668153 | 1007 | #if(0) | 
| dreschpe | 0:da1bf437cbc1 | 1008 | void SPI_TFT_ILI9341::character(int x, int y, int c) | 
| dreschpe | 0:da1bf437cbc1 | 1009 | { | 
| dreschpe | 0:da1bf437cbc1 | 1010 | unsigned int hor,vert,offset,bpl,j,i,b; | 
| dreschpe | 0:da1bf437cbc1 | 1011 | unsigned char* zeichen; | 
| dreschpe | 0:da1bf437cbc1 | 1012 | unsigned char z,w; | 
| dreschpe | 0:da1bf437cbc1 | 1013 | |
| dreschpe | 0:da1bf437cbc1 | 1014 | if ((c < 31) || (c > 127)) return; // test char range | 
| dreschpe | 0:da1bf437cbc1 | 1015 | |
| dreschpe | 0:da1bf437cbc1 | 1016 | // read font parameter from start of array | 
| wim | 8:8593d3668153 | 1017 | offset = _font[0]; // bytes / char | 
| wim | 8:8593d3668153 | 1018 | hor = _font[1]; // get hor size of font | 
| wim | 8:8593d3668153 | 1019 | vert = _font[2]; // get vert size of font | 
| wim | 8:8593d3668153 | 1020 | bpl = _font[3]; // bytes per line | 
| dreschpe | 0:da1bf437cbc1 | 1021 | |
| wim | 9:6d30a225a5c7 | 1022 | if (_char_x + hor > width()) { | 
| wim | 9:6d30a225a5c7 | 1023 | _char_x = 0; | 
| wim | 9:6d30a225a5c7 | 1024 | _char_y = _char_y + vert; | 
| wim | 9:6d30a225a5c7 | 1025 | if (_char_y >= height() - _font[2]) { | 
| wim | 9:6d30a225a5c7 | 1026 | _char_y = 0; | 
| dreschpe | 0:da1bf437cbc1 | 1027 | } | 
| dreschpe | 0:da1bf437cbc1 | 1028 | } | 
| wim | 9:6d30a225a5c7 | 1029 | window(_char_x, _char_y,hor,vert); // char box | 
| dreschpe | 5:55aed13f2630 | 1030 | wr_cmd(0x2C); // send pixel | 
| dreschpe | 5:55aed13f2630 | 1031 | #ifndef TARGET_KL25Z // 16 Bit SPI | 
| wim | 8:8593d3668153 | 1032 | _spi.format(16,0); | 
| wim | 8:8593d3668153 | 1033 | #endif // switch to 16 bit Mode 0 | 
| wim | 8:8593d3668153 | 1034 | zeichen = &_font[((c -32) * offset) + 4]; // start of char bitmap | 
| dreschpe | 0:da1bf437cbc1 | 1035 | w = zeichen[0]; // width of actual char | 
| dreschpe | 0:da1bf437cbc1 | 1036 | for (j=0; j<vert; j++) { // vert line | 
| dreschpe | 0:da1bf437cbc1 | 1037 | for (i=0; i<hor; i++) { // horz line | 
| dreschpe | 0:da1bf437cbc1 | 1038 | z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; | 
| dreschpe | 0:da1bf437cbc1 | 1039 | b = 1 << (j & 0x07); | 
| dreschpe | 0:da1bf437cbc1 | 1040 | if (( z & b ) == 0x00) { | 
| dreschpe | 5:55aed13f2630 | 1041 | #ifndef TARGET_KL25Z // 16 Bit SPI | 
| dreschpe | 0:da1bf437cbc1 | 1042 | _spi.write(_background); | 
| dreschpe | 5:55aed13f2630 | 1043 | #else | 
| dreschpe | 5:55aed13f2630 | 1044 | _spi.write(_background >> 8); | 
| dreschpe | 5:55aed13f2630 | 1045 | _spi.write(_background & 0xff); | 
| dreschpe | 5:55aed13f2630 | 1046 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 1047 | } else { | 
| dreschpe | 5:55aed13f2630 | 1048 | #ifndef TARGET_KL25Z // 16 Bit SPI | 
| dreschpe | 0:da1bf437cbc1 | 1049 | _spi.write(_foreground); | 
| dreschpe | 5:55aed13f2630 | 1050 | #else | 
| dreschpe | 5:55aed13f2630 | 1051 | _spi.write(_foreground >> 8); | 
| dreschpe | 5:55aed13f2630 | 1052 | _spi.write(_foreground & 0xff); | 
| dreschpe | 5:55aed13f2630 | 1053 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 1054 | } | 
| dreschpe | 0:da1bf437cbc1 | 1055 | } | 
| dreschpe | 0:da1bf437cbc1 | 1056 | } | 
| dreschpe | 0:da1bf437cbc1 | 1057 | _cs = 1; | 
| dreschpe | 5:55aed13f2630 | 1058 | #ifndef TARGET_KL25Z // 16 Bit SPI | 
| wim | 8:8593d3668153 | 1059 | _spi.format(8,0); | 
| dreschpe | 5:55aed13f2630 | 1060 | #endif | 
| wim | 8:8593d3668153 | 1061 | window_max(); | 
| wim | 8:8593d3668153 | 1062 | if ((w + 2) < hor) { // x offset to next char | 
| wim | 9:6d30a225a5c7 | 1063 | __char_x += w + 2; | 
| wim | 9:6d30a225a5c7 | 1064 | } else __char_x += hor; | 
| wim | 8:8593d3668153 | 1065 | } | 
| wim | 8:8593d3668153 | 1066 | #else | 
| wim | 9:6d30a225a5c7 | 1067 | |
| wim | 9:6d30a225a5c7 | 1068 | #if (TRANSPARANCY == 1) | 
| wim | 9:6d30a225a5c7 | 1069 | //WH write foreground, write background only when not transparant mode | 
| wim | 8:8593d3668153 | 1070 | void SPI_TFT_ILI9341::character(int x, int y, int c) | 
| wim | 8:8593d3668153 | 1071 | { | 
| wim | 8:8593d3668153 | 1072 | unsigned int hor,vert,offset,bpl,j,i,b; | 
| wim | 8:8593d3668153 | 1073 | unsigned char* symbol; | 
| wim | 8:8593d3668153 | 1074 | unsigned char z,w; | 
| wim | 8:8593d3668153 | 1075 | |
| wim | 8:8593d3668153 | 1076 | if ((c < 31) || (c > 127)) return; // test char range | 
| wim | 8:8593d3668153 | 1077 | |
| wim | 8:8593d3668153 | 1078 | // read font parameter from start of array | 
| wim | 8:8593d3668153 | 1079 | offset = _font[0]; // bytes / char | 
| wim | 8:8593d3668153 | 1080 | hor = _font[1]; // get hor size of font | 
| wim | 8:8593d3668153 | 1081 | vert = _font[2]; // get vert size of font | 
| wim | 8:8593d3668153 | 1082 | bpl = _font[3]; // bytes per line | 
| wim | 8:8593d3668153 | 1083 | |
| wim | 9:6d30a225a5c7 | 1084 | if (_char_x + hor > width()) { | 
| wim | 9:6d30a225a5c7 | 1085 | _char_x = 0; | 
| wim | 9:6d30a225a5c7 | 1086 | _char_y = _char_y + vert; | 
| wim | 9:6d30a225a5c7 | 1087 | if (_char_y >= height() - vert) { | 
| wim | 9:6d30a225a5c7 | 1088 | _char_y = 0; | 
| wim | 8:8593d3668153 | 1089 | } | 
| wim | 8:8593d3668153 | 1090 | } | 
| wim | 9:6d30a225a5c7 | 1091 | |
| wim | 9:6d30a225a5c7 | 1092 | symbol = &_font[((c - 32) * offset) + 4]; // start of char bitmap | 
| wim | 9:6d30a225a5c7 | 1093 | w = symbol[0]; // width of actual char (proportional font) | 
| wim | 9:6d30a225a5c7 | 1094 | for (j=0; j<vert; j++) { // vert line | 
| wim | 9:6d30a225a5c7 | 1095 | for (i=0; i<hor; i++) { // horz line | 
| wim | 9:6d30a225a5c7 | 1096 | z = symbol[bpl * i + ((j & 0xF8) >> 3) + 1]; | 
| wim | 9:6d30a225a5c7 | 1097 | b = 1 << (j & 0x07); | 
| wim | 9:6d30a225a5c7 | 1098 | |
| wim | 9:6d30a225a5c7 | 1099 | // Test bit in character bitmap to write either _foreground or _background color | 
| wim | 9:6d30a225a5c7 | 1100 | if (( z & b ) == 0x00) { | 
| wim | 9:6d30a225a5c7 | 1101 | // bit is 0, write _background color | 
| wim | 9:6d30a225a5c7 | 1102 | if (!_transparancy) { // write background color only when transparancy is 'off' | 
| wim | 9:6d30a225a5c7 | 1103 | pixel(_char_x+i, _char_y+j, _background); | 
| wim | 9:6d30a225a5c7 | 1104 | } | 
| wim | 9:6d30a225a5c7 | 1105 | } | 
| wim | 9:6d30a225a5c7 | 1106 | else { | 
| wim | 9:6d30a225a5c7 | 1107 | // bit is 1, write _foreground color | 
| wim | 9:6d30a225a5c7 | 1108 | pixel(_char_x+i, _char_y+j, _foreground); | 
| wim | 9:6d30a225a5c7 | 1109 | } // if bit | 
| wim | 9:6d30a225a5c7 | 1110 | } // for i | 
| wim | 9:6d30a225a5c7 | 1111 | } // for j | 
| wim | 9:6d30a225a5c7 | 1112 | |
| wim | 9:6d30a225a5c7 | 1113 | window_max(); | 
| wim | 9:6d30a225a5c7 | 1114 | |
| wim | 9:6d30a225a5c7 | 1115 | if ((w + 2) < hor) { // x offset to next char | 
| wim | 9:6d30a225a5c7 | 1116 | _char_x += w + 2; | 
| wim | 9:6d30a225a5c7 | 1117 | } else _char_x += hor; | 
| wim | 9:6d30a225a5c7 | 1118 | } | 
| wim | 9:6d30a225a5c7 | 1119 | |
| wim | 9:6d30a225a5c7 | 1120 | #else | 
| wim | 9:6d30a225a5c7 | 1121 | |
| wim | 9:6d30a225a5c7 | 1122 | //WH write foreground and background | 
| wim | 9:6d30a225a5c7 | 1123 | void SPI_TFT_ILI9341::character(int x, int y, int c) | 
| wim | 9:6d30a225a5c7 | 1124 | { | 
| wim | 9:6d30a225a5c7 | 1125 | unsigned int hor,vert,offset,bpl,j,i,b; | 
| wim | 9:6d30a225a5c7 | 1126 | unsigned char* symbol; | 
| wim | 9:6d30a225a5c7 | 1127 | unsigned char z,w; | 
| wim | 9:6d30a225a5c7 | 1128 | |
| wim | 9:6d30a225a5c7 | 1129 | if ((c < 31) || (c > 127)) return; // test char range | 
| wim | 9:6d30a225a5c7 | 1130 | |
| wim | 9:6d30a225a5c7 | 1131 | // read font parameter from start of array | 
| wim | 9:6d30a225a5c7 | 1132 | offset = _font[0]; // bytes / char | 
| wim | 9:6d30a225a5c7 | 1133 | hor = _font[1]; // get hor size of font | 
| wim | 9:6d30a225a5c7 | 1134 | vert = _font[2]; // get vert size of font | 
| wim | 9:6d30a225a5c7 | 1135 | bpl = _font[3]; // bytes per line | 
| wim | 9:6d30a225a5c7 | 1136 | |
| wim | 9:6d30a225a5c7 | 1137 | if (_char_x + hor > width()) { | 
| wim | 9:6d30a225a5c7 | 1138 | _char_x = 0; | 
| wim | 9:6d30a225a5c7 | 1139 | _char_y = _char_y + vert; | 
| wim | 9:6d30a225a5c7 | 1140 | if (_char_y >= height() - vert) { | 
| wim | 9:6d30a225a5c7 | 1141 | _char_y = 0; | 
| wim | 9:6d30a225a5c7 | 1142 | } | 
| wim | 9:6d30a225a5c7 | 1143 | } | 
| wim | 9:6d30a225a5c7 | 1144 | window(_char_x, _char_y, hor, vert); // char box | 
| wim | 8:8593d3668153 | 1145 | // wr_cmd(0x2C); // send pixel | 
| wim | 8:8593d3668153 | 1146 | wr_cmd(ILI9341_GRAM); // send pixel | 
| wim | 8:8593d3668153 | 1147 | |
| wim | 8:8593d3668153 | 1148 | #if (SPI_16 == 1) | 
| wim | 8:8593d3668153 | 1149 | // 16 Bit SPI | 
| wim | 8:8593d3668153 | 1150 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| wim | 8:8593d3668153 | 1151 | #endif | 
| wim | 8:8593d3668153 | 1152 | symbol = &_font[((c - 32) * offset) + 4]; // start of char bitmap | 
| wim | 9:6d30a225a5c7 | 1153 | w = symbol[0]; // width of actual char (proportional font) | 
| wim | 8:8593d3668153 | 1154 | for (j=0; j<vert; j++) { // vert line | 
| wim | 8:8593d3668153 | 1155 | for (i=0; i<hor; i++) { // horz line | 
| wim | 9:6d30a225a5c7 | 1156 | z = symbol[bpl * i + ((j & 0xF8) >> 3) + 1]; | 
| wim | 8:8593d3668153 | 1157 | b = 1 << (j & 0x07); | 
| wim | 9:6d30a225a5c7 | 1158 | |
| wim | 9:6d30a225a5c7 | 1159 | // Test bit in character bitmap to write either _foreground or _background color | 
| wim | 8:8593d3668153 | 1160 | if (( z & b ) == 0x00) { | 
| wim | 9:6d30a225a5c7 | 1161 | // bit is 0, write _background color | 
| wim | 8:8593d3668153 | 1162 | #if (SPI_16 == 1) | 
| wim | 8:8593d3668153 | 1163 | // 16 Bit SPI | 
| wim | 8:8593d3668153 | 1164 | _spi.write(_background); | 
| wim | 8:8593d3668153 | 1165 | #else | 
| wim | 8:8593d3668153 | 1166 | // 8 Bit SPI | 
| wim | 8:8593d3668153 | 1167 | _spi.write(_background >> 8); | 
| wim | 8:8593d3668153 | 1168 | _spi.write(_background & 0xff); | 
| wim | 8:8593d3668153 | 1169 | #endif | 
| wim | 8:8593d3668153 | 1170 | } | 
| wim | 8:8593d3668153 | 1171 | else { | 
| wim | 9:6d30a225a5c7 | 1172 | // bit is 1, write _foreground color | 
| wim | 8:8593d3668153 | 1173 | #if (SPI_16 == 1) | 
| wim | 8:8593d3668153 | 1174 | // 16 Bit SPI | 
| wim | 8:8593d3668153 | 1175 | _spi.write(_foreground); | 
| wim | 8:8593d3668153 | 1176 | #else | 
| wim | 8:8593d3668153 | 1177 | // 8 Bit SPI | 
| wim | 8:8593d3668153 | 1178 | _spi.write(_foreground >> 8); | 
| wim | 8:8593d3668153 | 1179 | _spi.write(_foreground & 0xff); | 
| wim | 8:8593d3668153 | 1180 | #endif | 
| wim | 9:6d30a225a5c7 | 1181 | } // if bit | 
| wim | 8:8593d3668153 | 1182 | } // for i | 
| wim | 8:8593d3668153 | 1183 | } // for j | 
| wim | 8:8593d3668153 | 1184 | |
| wim | 8:8593d3668153 | 1185 | _cs = 1; | 
| wim | 8:8593d3668153 | 1186 | #if (SPI_16 == 1) // 16 Bit SPI | 
| wim | 8:8593d3668153 | 1187 | _spi.format(8,0); // switch back to 8 bit Mode 0 | 
| wim | 8:8593d3668153 | 1188 | #endif | 
| wim | 8:8593d3668153 | 1189 | window_max(); | 
| wim | 8:8593d3668153 | 1190 | |
| dreschpe | 0:da1bf437cbc1 | 1191 | if ((w + 2) < hor) { // x offset to next char | 
| wim | 9:6d30a225a5c7 | 1192 | _char_x += w + 2; | 
| wim | 9:6d30a225a5c7 | 1193 | } else _char_x += hor; | 
| dreschpe | 0:da1bf437cbc1 | 1194 | } | 
| wim | 9:6d30a225a5c7 | 1195 | #endif | 
| wim | 9:6d30a225a5c7 | 1196 | |
| wim | 9:6d30a225a5c7 | 1197 | |
| dreschpe | 0:da1bf437cbc1 | 1198 | |
| wim | 8:8593d3668153 | 1199 | #endif | 
| wim | 8:8593d3668153 | 1200 | |
| dreschpe | 0:da1bf437cbc1 | 1201 | |
| dreschpe | 0:da1bf437cbc1 | 1202 | void SPI_TFT_ILI9341::set_font(unsigned char* f) | 
| dreschpe | 0:da1bf437cbc1 | 1203 | { | 
| wim | 8:8593d3668153 | 1204 | _font = f; | 
| dreschpe | 0:da1bf437cbc1 | 1205 | } | 
| dreschpe | 0:da1bf437cbc1 | 1206 | |
| dreschpe | 0:da1bf437cbc1 | 1207 | |
| dreschpe | 0:da1bf437cbc1 | 1208 | |
| dreschpe | 0:da1bf437cbc1 | 1209 | void SPI_TFT_ILI9341::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap) | 
| dreschpe | 0:da1bf437cbc1 | 1210 | { | 
| dreschpe | 0:da1bf437cbc1 | 1211 | unsigned int j; | 
| dreschpe | 0:da1bf437cbc1 | 1212 | int padd; | 
| dreschpe | 0:da1bf437cbc1 | 1213 | unsigned short *bitmap_ptr = (unsigned short *)bitmap; | 
| wim | 9:6d30a225a5c7 | 1214 | #if (SPI_16 != 1) // 16 Bit SPI | 
| wim | 9:6d30a225a5c7 | 1215 | unsigned short pix_temp; | 
| dreschpe | 5:55aed13f2630 | 1216 | #endif | 
| dreschpe | 5:55aed13f2630 | 1217 | |
| dreschpe | 2:0a16083193a4 | 1218 | unsigned int i; | 
| dreschpe | 2:0a16083193a4 | 1219 | |
| dreschpe | 0:da1bf437cbc1 | 1220 | // the lines are padded to multiple of 4 bytes in a bitmap | 
| dreschpe | 0:da1bf437cbc1 | 1221 | padd = -1; | 
| dreschpe | 0:da1bf437cbc1 | 1222 | do { | 
| dreschpe | 0:da1bf437cbc1 | 1223 | padd ++; | 
| dreschpe | 0:da1bf437cbc1 | 1224 | } while (2*(w + padd)%4 != 0); | 
| dreschpe | 0:da1bf437cbc1 | 1225 | window(x, y, w, h); | 
| dreschpe | 2:0a16083193a4 | 1226 | bitmap_ptr += ((h - 1)* (w + padd)); | 
| wim | 8:8593d3668153 | 1227 | // wr_cmd(0x2C); // send pixel | 
| wim | 8:8593d3668153 | 1228 | wr_cmd(ILI9341_GRAM); // send pixel | 
| wim | 8:8593d3668153 | 1229 | |
| wim | 9:6d30a225a5c7 | 1230 | #if (SPI_16 == 1) // 16 Bit SPI | 
| wim | 9:6d30a225a5c7 | 1231 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| wim | 9:6d30a225a5c7 | 1232 | #endif | 
| dreschpe | 2:0a16083193a4 | 1233 | for (j = 0; j < h; j++) { //Lines | 
| dreschpe | 2:0a16083193a4 | 1234 | for (i = 0; i < w; i++) { // one line | 
| wim | 9:6d30a225a5c7 | 1235 | #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 1236 | // 16 Bit SPI | 
| wim | 9:6d30a225a5c7 | 1237 | _spi.write(*bitmap_ptr); // one line | 
| wim | 9:6d30a225a5c7 | 1238 | bitmap_ptr++; | 
| wim | 9:6d30a225a5c7 | 1239 | #else | 
| wim | 9:6d30a225a5c7 | 1240 | // 8 Bit SPI | 
| dreschpe | 5:55aed13f2630 | 1241 | pix_temp = *bitmap_ptr; | 
| dreschpe | 5:55aed13f2630 | 1242 | _spi.write(pix_temp >> 8); | 
| dreschpe | 5:55aed13f2630 | 1243 | _spi.write(pix_temp); | 
| dreschpe | 5:55aed13f2630 | 1244 | bitmap_ptr++; | 
| dreschpe | 5:55aed13f2630 | 1245 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 1246 | } | 
| dreschpe | 0:da1bf437cbc1 | 1247 | bitmap_ptr -= 2*w; | 
| dreschpe | 0:da1bf437cbc1 | 1248 | bitmap_ptr -= padd; | 
| dreschpe | 0:da1bf437cbc1 | 1249 | } | 
| dreschpe | 0:da1bf437cbc1 | 1250 | _cs = 1; | 
| wim | 9:6d30a225a5c7 | 1251 | |
| wim | 9:6d30a225a5c7 | 1252 | #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 1253 | _spi.format(8,0); // switch back to 8 bit Mode 0 | 
| dreschpe | 5:55aed13f2630 | 1254 | #endif | 
| wim | 8:8593d3668153 | 1255 | window_max(); | 
| dreschpe | 0:da1bf437cbc1 | 1256 | } | 
| dreschpe | 0:da1bf437cbc1 | 1257 | |
| dreschpe | 0:da1bf437cbc1 | 1258 | |
| wim | 9:6d30a225a5c7 | 1259 | // local filesystem is not implemented in kinetis board, but you can add an SD card | 
| dreschpe | 5:55aed13f2630 | 1260 | |
| dreschpe | 0:da1bf437cbc1 | 1261 | int SPI_TFT_ILI9341::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP) | 
| dreschpe | 0:da1bf437cbc1 | 1262 | { | 
| dreschpe | 0:da1bf437cbc1 | 1263 | |
| dreschpe | 0:da1bf437cbc1 | 1264 | #define OffsetPixelWidth 18 | 
| dreschpe | 0:da1bf437cbc1 | 1265 | #define OffsetPixelHeigh 22 | 
| dreschpe | 0:da1bf437cbc1 | 1266 | #define OffsetFileSize 34 | 
| dreschpe | 0:da1bf437cbc1 | 1267 | #define OffsetPixData 10 | 
| dreschpe | 0:da1bf437cbc1 | 1268 | #define OffsetBPP 28 | 
| dreschpe | 0:da1bf437cbc1 | 1269 | |
| dreschpe | 0:da1bf437cbc1 | 1270 | char filename[50]; | 
| dreschpe | 0:da1bf437cbc1 | 1271 | unsigned char BMP_Header[54]; | 
| dreschpe | 0:da1bf437cbc1 | 1272 | unsigned short BPP_t; | 
| dreschpe | 0:da1bf437cbc1 | 1273 | unsigned int PixelWidth,PixelHeigh,start_data; | 
| dreschpe | 0:da1bf437cbc1 | 1274 | unsigned int i,off; | 
| dreschpe | 0:da1bf437cbc1 | 1275 | int padd,j; | 
| dreschpe | 0:da1bf437cbc1 | 1276 | unsigned short *line; | 
| dreschpe | 0:da1bf437cbc1 | 1277 | |
| dreschpe | 0:da1bf437cbc1 | 1278 | // get the filename | 
| dreschpe | 6:fe07ae8329f7 | 1279 | i=0; | 
| dreschpe | 0:da1bf437cbc1 | 1280 | while (*Name_BMP!='\0') { | 
| dreschpe | 0:da1bf437cbc1 | 1281 | filename[i++]=*Name_BMP++; | 
| dreschpe | 0:da1bf437cbc1 | 1282 | } | 
| dreschpe | 6:fe07ae8329f7 | 1283 | filename[i] = 0; | 
| dreschpe | 6:fe07ae8329f7 | 1284 | |
| dreschpe | 0:da1bf437cbc1 | 1285 | FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file | 
| dreschpe | 0:da1bf437cbc1 | 1286 | if (!Image) { | 
| dreschpe | 0:da1bf437cbc1 | 1287 | return(0); // error file not found ! | 
| dreschpe | 0:da1bf437cbc1 | 1288 | } | 
| dreschpe | 0:da1bf437cbc1 | 1289 | |
| dreschpe | 0:da1bf437cbc1 | 1290 | fread(&BMP_Header[0],1,54,Image); // get the BMP Header | 
| dreschpe | 0:da1bf437cbc1 | 1291 | |
| dreschpe | 0:da1bf437cbc1 | 1292 | if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte | 
| dreschpe | 0:da1bf437cbc1 | 1293 | fclose(Image); | 
| dreschpe | 0:da1bf437cbc1 | 1294 | return(-1); // error no BMP file | 
| dreschpe | 0:da1bf437cbc1 | 1295 | } | 
| dreschpe | 0:da1bf437cbc1 | 1296 | |
| dreschpe | 0:da1bf437cbc1 | 1297 | BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8); | 
| dreschpe | 0:da1bf437cbc1 | 1298 | if (BPP_t != 0x0010) { | 
| dreschpe | 0:da1bf437cbc1 | 1299 | fclose(Image); | 
| dreschpe | 0:da1bf437cbc1 | 1300 | return(-2); // error no 16 bit BMP | 
| dreschpe | 0:da1bf437cbc1 | 1301 | } | 
| dreschpe | 0:da1bf437cbc1 | 1302 | |
| dreschpe | 0:da1bf437cbc1 | 1303 | PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24); | 
| dreschpe | 0:da1bf437cbc1 | 1304 | PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24); | 
| dreschpe | 0:da1bf437cbc1 | 1305 | if (PixelHeigh > height() + y || PixelWidth > width() + x) { | 
| dreschpe | 0:da1bf437cbc1 | 1306 | fclose(Image); | 
| dreschpe | 0:da1bf437cbc1 | 1307 | return(-3); // to big | 
| dreschpe | 0:da1bf437cbc1 | 1308 | } | 
| dreschpe | 0:da1bf437cbc1 | 1309 | |
| dreschpe | 0:da1bf437cbc1 | 1310 | start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24); | 
| dreschpe | 0:da1bf437cbc1 | 1311 | |
| dreschpe | 0:da1bf437cbc1 | 1312 | line = (unsigned short *) malloc (2 * PixelWidth); // we need a buffer for a line | 
| dreschpe | 0:da1bf437cbc1 | 1313 | if (line == NULL) { | 
| dreschpe | 0:da1bf437cbc1 | 1314 | return(-4); // error no memory | 
| dreschpe | 0:da1bf437cbc1 | 1315 | } | 
| dreschpe | 0:da1bf437cbc1 | 1316 | |
| dreschpe | 0:da1bf437cbc1 | 1317 | // the bmp lines are padded to multiple of 4 bytes | 
| dreschpe | 0:da1bf437cbc1 | 1318 | padd = -1; | 
| dreschpe | 0:da1bf437cbc1 | 1319 | do { | 
| dreschpe | 0:da1bf437cbc1 | 1320 | padd ++; | 
| dreschpe | 0:da1bf437cbc1 | 1321 | } while ((PixelWidth * 2 + padd)%4 != 0); | 
| dreschpe | 0:da1bf437cbc1 | 1322 | |
| dreschpe | 0:da1bf437cbc1 | 1323 | window(x, y,PixelWidth ,PixelHeigh); | 
| wim | 8:8593d3668153 | 1324 | // wr_cmd(0x2C); // send pixel | 
| wim | 8:8593d3668153 | 1325 | wr_cmd(ILI9341_GRAM); // send pixel | 
| wim | 8:8593d3668153 | 1326 | |
| wim | 9:6d30a225a5c7 | 1327 | #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 1328 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| wim | 9:6d30a225a5c7 | 1329 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 1330 | for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up | 
| dreschpe | 0:da1bf437cbc1 | 1331 | off = j * (PixelWidth * 2 + padd) + start_data; // start of line | 
| dreschpe | 0:da1bf437cbc1 | 1332 | fseek(Image, off ,SEEK_SET); | 
| dreschpe | 6:fe07ae8329f7 | 1333 | fread(line,1,PixelWidth * 2,Image); // read a line - slow | 
| dreschpe | 0:da1bf437cbc1 | 1334 | for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT | 
| wim | 9:6d30a225a5c7 | 1335 | #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 1336 | // one 16 bit pixel | 
| wim | 9:6d30a225a5c7 | 1337 | _spi.write(line[i]); | 
| wim | 9:6d30a225a5c7 | 1338 | #else | 
| wim | 9:6d30a225a5c7 | 1339 | // only 8 Bit SPI | 
| wim | 9:6d30a225a5c7 | 1340 | _spi.write(line[i] >> 8); | 
| wim | 9:6d30a225a5c7 | 1341 | _spi.write(line[i]); | 
| dreschpe | 6:fe07ae8329f7 | 1342 | #endif | 
| dreschpe | 0:da1bf437cbc1 | 1343 | } | 
| dreschpe | 0:da1bf437cbc1 | 1344 | } | 
| dreschpe | 0:da1bf437cbc1 | 1345 | _cs = 1; | 
| wim | 9:6d30a225a5c7 | 1346 | |
| wim | 9:6d30a225a5c7 | 1347 | #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 1348 | _spi.format(8,0); // switch back to 8 bit Mode 0 | 
| wim | 9:6d30a225a5c7 | 1349 | #endif | 
| wim | 9:6d30a225a5c7 | 1350 | |
| dreschpe | 0:da1bf437cbc1 | 1351 | free (line); | 
| dreschpe | 0:da1bf437cbc1 | 1352 | fclose(Image); | 
| wim | 8:8593d3668153 | 1353 | window_max(); | 
| dreschpe | 0:da1bf437cbc1 | 1354 | return(1); | 
| dreschpe | 5:55aed13f2630 | 1355 | } | 
| wim | 8:8593d3668153 | 1356 | |
| wim | 8:8593d3668153 | 1357 | |
| wim | 8:8593d3668153 | 1358 | /******************************************************************************* | 
| wim | 8:8593d3668153 | 1359 | * Function Name : WriteBMP_FAT | 
| wim | 8:8593d3668153 | 1360 | * @brief Displays a bitmap picture loaded in Flash. | 
| wim | 8:8593d3668153 | 1361 | * @param Xpos: specifies the X position. | 
| wim | 8:8593d3668153 | 1362 | * @param Ypos: specifies the Y position. | 
| wim | 8:8593d3668153 | 1363 | * @param BmpAddress: Bmp picture address in Flash. | 
| wim | 8:8593d3668153 | 1364 | * @return None | 
| wim | 8:8593d3668153 | 1365 | *******************************************************************************/ | 
| wim | 8:8593d3668153 | 1366 | void SPI_TFT_ILI9341::WriteBMP_FAT(uint16_t Xpos, uint16_t Ypos, const char* BmpName) | 
| wim | 8:8593d3668153 | 1367 | { | 
| wim | 8:8593d3668153 | 1368 | uint32_t index = 0, size = 0, width=0, height=0; | 
| wim | 8:8593d3668153 | 1369 | uint16_t *pBmpWord=0; | 
| wim | 9:6d30a225a5c7 | 1370 | // uint16_t data; | 
| wim | 8:8593d3668153 | 1371 | |
| wim | 8:8593d3668153 | 1372 | /* Read bitmap width*/ | 
| wim | 8:8593d3668153 | 1373 | width = BmpName[0]+1; | 
| wim | 8:8593d3668153 | 1374 | /* Read bitmap height*/ | 
| wim | 8:8593d3668153 | 1375 | height = BmpName[1]+1; | 
| wim | 8:8593d3668153 | 1376 | /* Read bitmap size */ | 
| wim | 8:8593d3668153 | 1377 | size = width * height; /* nb of 16 bits */ | 
| wim | 8:8593d3668153 | 1378 | |
| wim | 8:8593d3668153 | 1379 | window(Xpos, Ypos, width , height); | 
| wim | 8:8593d3668153 | 1380 | |
| wim | 8:8593d3668153 | 1381 | // wr_cmd(0x2C); // send pixel | 
| wim | 8:8593d3668153 | 1382 | wr_cmd(ILI9341_GRAM); // send pixel | 
| wim | 8:8593d3668153 | 1383 | |
| wim | 8:8593d3668153 | 1384 | /* Set WRX to send data */ | 
| wim | 9:6d30a225a5c7 | 1385 | //WH _dc = 1; | 
| wim | 9:6d30a225a5c7 | 1386 | |
| wim | 9:6d30a225a5c7 | 1387 | #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 1388 | _spi.format(16,0); // switch to 16 bit Mode 0 | 
| wim | 9:6d30a225a5c7 | 1389 | #endif | 
| wim | 8:8593d3668153 | 1390 | |
| wim | 8:8593d3668153 | 1391 | pBmpWord = (uint16_t *) (&BmpName[5]); | 
| wim | 9:6d30a225a5c7 | 1392 | /* Send to the screen */ | 
| wim | 8:8593d3668153 | 1393 | for(index = 0; index < size; index++) | 
| wim | 8:8593d3668153 | 1394 | { | 
| wim | 9:6d30a225a5c7 | 1395 | #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 1396 | // one 16 bit pixel | 
| wim | 9:6d30a225a5c7 | 1397 | _spi.write(*pBmpWord); | 
| wim | 9:6d30a225a5c7 | 1398 | #else | 
| wim | 9:6d30a225a5c7 | 1399 | // only 8 Bit SPI | 
| wim | 9:6d30a225a5c7 | 1400 | _spi.write(*pBmpWord & 0xFF); | 
| wim | 9:6d30a225a5c7 | 1401 | _spi.write((*pBmpWord>>8) & 0xFF); | 
| wim | 9:6d30a225a5c7 | 1402 | #endif | 
| wim | 9:6d30a225a5c7 | 1403 | |
| wim | 8:8593d3668153 | 1404 | pBmpWord++; | 
| wim | 8:8593d3668153 | 1405 | } | 
| wim | 8:8593d3668153 | 1406 | |
| wim | 8:8593d3668153 | 1407 | /* Set LCD control line(/CS) */ | 
| wim | 8:8593d3668153 | 1408 | _cs = 1; | 
| wim | 9:6d30a225a5c7 | 1409 | |
| wim | 9:6d30a225a5c7 | 1410 | #if (SPI_16 == 1) | 
| wim | 9:6d30a225a5c7 | 1411 | _spi.format(8,0); // switch back to 8 bit Mode 0 | 
| wim | 9:6d30a225a5c7 | 1412 | #endif | 
| wim | 8:8593d3668153 | 1413 | |
| wim | 8:8593d3668153 | 1414 | window_max(); | 
| wim | 8:8593d3668153 | 1415 | } | 
| wim | 8:8593d3668153 | 1416 | |
| wim | 8:8593d3668153 | 1417 | 
