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