Lib for the new LCD Display with ILI9341 controller

Committer:
dreschpe
Date:
Wed Jun 12 22:54:38 2013 +0000
Revision:
0:da1bf437cbc1
Child:
1:6d6125e88de7
Test Version,

Who changed what in which revision?

UserRevisionLine numberNew 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 0:da1bf437cbc1 14
dreschpe 0:da1bf437cbc1 15 #include "SPI_TFT_ILI9341.h"
dreschpe 0:da1bf437cbc1 16 #include "mbed.h"
dreschpe 0:da1bf437cbc1 17
dreschpe 0:da1bf437cbc1 18 #define BPP 16 // Bits per pixel
dreschpe 0:da1bf437cbc1 19
dreschpe 0:da1bf437cbc1 20
dreschpe 0:da1bf437cbc1 21 //extern Serial pc;
dreschpe 0:da1bf437cbc1 22 //extern DigitalOut xx; // debug !!
dreschpe 0:da1bf437cbc1 23
dreschpe 0:da1bf437cbc1 24 SPI_TFT_ILI9341::SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char *name)
dreschpe 0:da1bf437cbc1 25 : _spi(mosi, miso, sclk), _cs(cs), _reset(reset), _dc(dc), GraphicsDisplay(name)
dreschpe 0:da1bf437cbc1 26 {
dreschpe 0:da1bf437cbc1 27 orientation = 0;
dreschpe 0:da1bf437cbc1 28 char_x = 0;
dreschpe 0:da1bf437cbc1 29 tft_reset();
dreschpe 0:da1bf437cbc1 30 }
dreschpe 0:da1bf437cbc1 31
dreschpe 0:da1bf437cbc1 32 int SPI_TFT_ILI9341::width()
dreschpe 0:da1bf437cbc1 33 {
dreschpe 0:da1bf437cbc1 34 if (orientation == 0 || orientation == 2) return 240;
dreschpe 0:da1bf437cbc1 35 else return 320;
dreschpe 0:da1bf437cbc1 36 }
dreschpe 0:da1bf437cbc1 37
dreschpe 0:da1bf437cbc1 38
dreschpe 0:da1bf437cbc1 39 int SPI_TFT_ILI9341::height()
dreschpe 0:da1bf437cbc1 40 {
dreschpe 0:da1bf437cbc1 41 if (orientation == 0 || orientation == 2) return 320;
dreschpe 0:da1bf437cbc1 42 else return 240;
dreschpe 0:da1bf437cbc1 43 }
dreschpe 0:da1bf437cbc1 44
dreschpe 0:da1bf437cbc1 45
dreschpe 0:da1bf437cbc1 46 /*void SPI_TFT_ILI9341::set_orientation(unsigned int o)
dreschpe 0:da1bf437cbc1 47 {
dreschpe 0:da1bf437cbc1 48 orientation = o;
dreschpe 0:da1bf437cbc1 49 switch (orientation) {
dreschpe 0:da1bf437cbc1 50 case 0:
dreschpe 0:da1bf437cbc1 51 wr_reg(0x16, 0x08);
dreschpe 0:da1bf437cbc1 52 break;
dreschpe 0:da1bf437cbc1 53 case 1:
dreschpe 0:da1bf437cbc1 54 wr_reg(0x16, 0x68);
dreschpe 0:da1bf437cbc1 55 break;
dreschpe 0:da1bf437cbc1 56 case 2:
dreschpe 0:da1bf437cbc1 57 wr_reg(0x16, 0xC8);
dreschpe 0:da1bf437cbc1 58 break;
dreschpe 0:da1bf437cbc1 59 case 3:
dreschpe 0:da1bf437cbc1 60 wr_reg(0x16, 0xA8);
dreschpe 0:da1bf437cbc1 61 break;
dreschpe 0:da1bf437cbc1 62 }
dreschpe 0:da1bf437cbc1 63 WindowMax();
dreschpe 0:da1bf437cbc1 64 } */
dreschpe 0:da1bf437cbc1 65
dreschpe 0:da1bf437cbc1 66
dreschpe 0:da1bf437cbc1 67 // write command to tft register
dreschpe 0:da1bf437cbc1 68
dreschpe 0:da1bf437cbc1 69 void SPI_TFT_ILI9341::wr_cmd(unsigned char cmd)
dreschpe 0:da1bf437cbc1 70 {
dreschpe 0:da1bf437cbc1 71 _dc = 0;
dreschpe 0:da1bf437cbc1 72 _cs = 0;
dreschpe 0:da1bf437cbc1 73 _spi.write(cmd); // mbed lib
dreschpe 0:da1bf437cbc1 74 _dc = 1;
dreschpe 0:da1bf437cbc1 75 }
dreschpe 0:da1bf437cbc1 76
dreschpe 0:da1bf437cbc1 77
dreschpe 0:da1bf437cbc1 78
dreschpe 0:da1bf437cbc1 79 void SPI_TFT_ILI9341::wr_dat(unsigned char dat)
dreschpe 0:da1bf437cbc1 80 {
dreschpe 0:da1bf437cbc1 81 _spi.write(dat); // mbed lib
dreschpe 0:da1bf437cbc1 82 // _cs = 1;
dreschpe 0:da1bf437cbc1 83 }
dreschpe 0:da1bf437cbc1 84
dreschpe 0:da1bf437cbc1 85
dreschpe 0:da1bf437cbc1 86
dreschpe 0:da1bf437cbc1 87 // the ILI9341 can read - has to be implemented later
dreschpe 0:da1bf437cbc1 88 // A read will return 0 at the moment
dreschpe 0:da1bf437cbc1 89
dreschpe 0:da1bf437cbc1 90 //unsigned short SPI_TFT_ILI9341::rd_dat (void)
dreschpe 0:da1bf437cbc1 91 //{
dreschpe 0:da1bf437cbc1 92 // unsigned short val = 0;
dreschpe 0:da1bf437cbc1 93
dreschpe 0:da1bf437cbc1 94 //val = _spi.write(0x73ff); /* Dummy read 1 */
dreschpe 0:da1bf437cbc1 95 //val = _spi.write(0x0000); /* Read D8..D15 */
dreschpe 0:da1bf437cbc1 96 // return (val);
dreschpe 0:da1bf437cbc1 97 //}
dreschpe 0:da1bf437cbc1 98
dreschpe 0:da1bf437cbc1 99
dreschpe 0:da1bf437cbc1 100
dreschpe 0:da1bf437cbc1 101 void SPI_TFT_ILI9341::tft_reset()
dreschpe 0:da1bf437cbc1 102 {
dreschpe 0:da1bf437cbc1 103 //static unsigned short driverCode;
dreschpe 0:da1bf437cbc1 104 _spi.format(8,3); // 8 bit spi mode 3
dreschpe 0:da1bf437cbc1 105 _spi.frequency(12000000); // 12 Mhz SPI clock
dreschpe 0:da1bf437cbc1 106 _cs = 1; // cs high
dreschpe 0:da1bf437cbc1 107 _dc = 1; // dc high
dreschpe 0:da1bf437cbc1 108 _reset = 0; // display reset
dreschpe 0:da1bf437cbc1 109
dreschpe 0:da1bf437cbc1 110 wait_us(50);
dreschpe 0:da1bf437cbc1 111 _reset = 1; // end reset
dreschpe 0:da1bf437cbc1 112 wait_ms(5);
dreschpe 0:da1bf437cbc1 113
dreschpe 0:da1bf437cbc1 114 /* Start Initial Sequence ----------------------------------------------------*/
dreschpe 0:da1bf437cbc1 115 wr_cmd(0xCD); // Power Control A
dreschpe 0:da1bf437cbc1 116 _spi.write(0x39);
dreschpe 0:da1bf437cbc1 117 _spi.write(0x2C);
dreschpe 0:da1bf437cbc1 118 _spi.write(0x00);
dreschpe 0:da1bf437cbc1 119 _spi.write(0x34);
dreschpe 0:da1bf437cbc1 120 _spi.write(0x02);
dreschpe 0:da1bf437cbc1 121 _cs = 1;
dreschpe 0:da1bf437cbc1 122
dreschpe 0:da1bf437cbc1 123 wr_cmd(0xCF); // Power Control B
dreschpe 0:da1bf437cbc1 124 _spi.write(0x00);
dreschpe 0:da1bf437cbc1 125 _spi.write(0xAA);
dreschpe 0:da1bf437cbc1 126 _spi.write(0xB0);
dreschpe 0:da1bf437cbc1 127 _cs = 1;
dreschpe 0:da1bf437cbc1 128 wr_cmd(0xF7); // CMD_PUMP_RATIO_CONTROL
dreschpe 0:da1bf437cbc1 129 _spi.write(0x30);
dreschpe 0:da1bf437cbc1 130 _cs = 1;
dreschpe 0:da1bf437cbc1 131 wr_cmd(0xC0); // POWER_CONTROL_1
dreschpe 0:da1bf437cbc1 132 _spi.write(0x25);
dreschpe 0:da1bf437cbc1 133 _cs = 1;
dreschpe 0:da1bf437cbc1 134 wr_cmd(0xC1); // POWER_CONTROL_2
dreschpe 0:da1bf437cbc1 135 _spi.write(0x11);
dreschpe 0:da1bf437cbc1 136 _cs = 1;
dreschpe 0:da1bf437cbc1 137 wr_cmd(0xC5); // VCOM_CONTROL_1
dreschpe 0:da1bf437cbc1 138 _spi.write(0x5C);
dreschpe 0:da1bf437cbc1 139 _spi.write(0x4C);
dreschpe 0:da1bf437cbc1 140 _cs = 1;
dreschpe 0:da1bf437cbc1 141 wr_cmd(0xC7); // VCOM_CONTROL_2
dreschpe 0:da1bf437cbc1 142 _spi.write(0x94);
dreschpe 0:da1bf437cbc1 143 _cs = 1;
dreschpe 0:da1bf437cbc1 144 wr_cmd(0xE8); // DRIVER_TIMING_CONTROL_A
dreschpe 0:da1bf437cbc1 145 _spi.write(0x85);
dreschpe 0:da1bf437cbc1 146 _spi.write(0x01);
dreschpe 0:da1bf437cbc1 147 _spi.write(0x78);
dreschpe 0:da1bf437cbc1 148 _cs = 1;
dreschpe 0:da1bf437cbc1 149 wr_cmd(0xEA); // DRIVER_TIMING_CONTROL_B
dreschpe 0:da1bf437cbc1 150 _spi.write(0x00);
dreschpe 0:da1bf437cbc1 151 _spi.write(0x00);
dreschpe 0:da1bf437cbc1 152 _cs = 1;
dreschpe 0:da1bf437cbc1 153 wr_cmd(0x3A); // COLMOD_PIXEL_FORMAT_SET
dreschpe 0:da1bf437cbc1 154 _spi.write(0x05);
dreschpe 0:da1bf437cbc1 155 _cs = 1;
dreschpe 0:da1bf437cbc1 156 wr_cmd(0x36); // MEMORY_ACCESS_CONTROL
dreschpe 0:da1bf437cbc1 157 _spi.write(0x48);
dreschpe 0:da1bf437cbc1 158 _cs = 1;
dreschpe 0:da1bf437cbc1 159 WindowMax ();
dreschpe 0:da1bf437cbc1 160 }
dreschpe 0:da1bf437cbc1 161
dreschpe 0:da1bf437cbc1 162
dreschpe 0:da1bf437cbc1 163 void SPI_TFT_ILI9341::pixel(int x, int y, int color)
dreschpe 0:da1bf437cbc1 164 {
dreschpe 0:da1bf437cbc1 165 wr_cmd(0x2A);
dreschpe 0:da1bf437cbc1 166 _spi.write(x >> 8);
dreschpe 0:da1bf437cbc1 167 _spi.write(x);
dreschpe 0:da1bf437cbc1 168 _cs = 1;
dreschpe 0:da1bf437cbc1 169 wr_cmd(0x2B);
dreschpe 0:da1bf437cbc1 170 _spi.write(y >> 8);
dreschpe 0:da1bf437cbc1 171 _spi.write(y);
dreschpe 0:da1bf437cbc1 172 _cs = 1;
dreschpe 0:da1bf437cbc1 173 wr_cmd(0x2C); // send pixel
dreschpe 0:da1bf437cbc1 174 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:da1bf437cbc1 175 _spi.write(color); // Write D0..D15
dreschpe 0:da1bf437cbc1 176 _spi.format(8,3);
dreschpe 0:da1bf437cbc1 177 _cs = 1;
dreschpe 0:da1bf437cbc1 178 }
dreschpe 0:da1bf437cbc1 179
dreschpe 0:da1bf437cbc1 180
dreschpe 0:da1bf437cbc1 181 void SPI_TFT_ILI9341::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h)
dreschpe 0:da1bf437cbc1 182 {
dreschpe 0:da1bf437cbc1 183 wr_cmd(0x2A);
dreschpe 0:da1bf437cbc1 184 _spi.write(x >> 8);
dreschpe 0:da1bf437cbc1 185 _spi.write(x);
dreschpe 0:da1bf437cbc1 186 _spi.write((x+w-1) >> 8);
dreschpe 0:da1bf437cbc1 187 _spi.write(x+w-1);
dreschpe 0:da1bf437cbc1 188
dreschpe 0:da1bf437cbc1 189 _cs = 1;
dreschpe 0:da1bf437cbc1 190 wr_cmd(0x2B);
dreschpe 0:da1bf437cbc1 191 _spi.write(y >> 8);
dreschpe 0:da1bf437cbc1 192 _spi.write(y);
dreschpe 0:da1bf437cbc1 193 _spi.write((y+h-1) >> 8);
dreschpe 0:da1bf437cbc1 194 _spi.write(y+h-1);
dreschpe 0:da1bf437cbc1 195 _cs = 1;
dreschpe 0:da1bf437cbc1 196 }
dreschpe 0:da1bf437cbc1 197
dreschpe 0:da1bf437cbc1 198
dreschpe 0:da1bf437cbc1 199 void SPI_TFT_ILI9341::WindowMax (void)
dreschpe 0:da1bf437cbc1 200 {
dreschpe 0:da1bf437cbc1 201 window (0, 0, width(), height());
dreschpe 0:da1bf437cbc1 202 }
dreschpe 0:da1bf437cbc1 203
dreschpe 0:da1bf437cbc1 204
dreschpe 0:da1bf437cbc1 205
dreschpe 0:da1bf437cbc1 206 void SPI_TFT_ILI9341::cls (void)
dreschpe 0:da1bf437cbc1 207 {
dreschpe 0:da1bf437cbc1 208 int pixel = ( width() * height());
dreschpe 0:da1bf437cbc1 209 WindowMax();
dreschpe 0:da1bf437cbc1 210 wr_cmd(0x2C); // send pixel
dreschpe 0:da1bf437cbc1 211 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:da1bf437cbc1 212 unsigned int i;
dreschpe 0:da1bf437cbc1 213 for (i = 0; i < ( width() * height()); i++)
dreschpe 0:da1bf437cbc1 214 _spi.write(_background);
dreschpe 0:da1bf437cbc1 215 _cs = 1;
dreschpe 0:da1bf437cbc1 216 _spi.format(8,3);
dreschpe 0:da1bf437cbc1 217 }
dreschpe 0:da1bf437cbc1 218
dreschpe 0:da1bf437cbc1 219
dreschpe 0:da1bf437cbc1 220 void SPI_TFT_ILI9341::circle(int x0, int y0, int r, int color)
dreschpe 0:da1bf437cbc1 221 {
dreschpe 0:da1bf437cbc1 222
dreschpe 0:da1bf437cbc1 223 int draw_x0, draw_y0;
dreschpe 0:da1bf437cbc1 224 int draw_x1, draw_y1;
dreschpe 0:da1bf437cbc1 225 int draw_x2, draw_y2;
dreschpe 0:da1bf437cbc1 226 int draw_x3, draw_y3;
dreschpe 0:da1bf437cbc1 227 int draw_x4, draw_y4;
dreschpe 0:da1bf437cbc1 228 int draw_x5, draw_y5;
dreschpe 0:da1bf437cbc1 229 int draw_x6, draw_y6;
dreschpe 0:da1bf437cbc1 230 int draw_x7, draw_y7;
dreschpe 0:da1bf437cbc1 231 int xx, yy;
dreschpe 0:da1bf437cbc1 232 int di;
dreschpe 0:da1bf437cbc1 233 //WindowMax();
dreschpe 0:da1bf437cbc1 234 if (r == 0) { /* no radius */
dreschpe 0:da1bf437cbc1 235 return;
dreschpe 0:da1bf437cbc1 236 }
dreschpe 0:da1bf437cbc1 237
dreschpe 0:da1bf437cbc1 238 draw_x0 = draw_x1 = x0;
dreschpe 0:da1bf437cbc1 239 draw_y0 = draw_y1 = y0 + r;
dreschpe 0:da1bf437cbc1 240 if (draw_y0 < height()) {
dreschpe 0:da1bf437cbc1 241 pixel(draw_x0, draw_y0, color); /* 90 degree */
dreschpe 0:da1bf437cbc1 242 }
dreschpe 0:da1bf437cbc1 243
dreschpe 0:da1bf437cbc1 244 draw_x2 = draw_x3 = x0;
dreschpe 0:da1bf437cbc1 245 draw_y2 = draw_y3 = y0 - r;
dreschpe 0:da1bf437cbc1 246 if (draw_y2 >= 0) {
dreschpe 0:da1bf437cbc1 247 pixel(draw_x2, draw_y2, color); /* 270 degree */
dreschpe 0:da1bf437cbc1 248 }
dreschpe 0:da1bf437cbc1 249
dreschpe 0:da1bf437cbc1 250 draw_x4 = draw_x6 = x0 + r;
dreschpe 0:da1bf437cbc1 251 draw_y4 = draw_y6 = y0;
dreschpe 0:da1bf437cbc1 252 if (draw_x4 < width()) {
dreschpe 0:da1bf437cbc1 253 pixel(draw_x4, draw_y4, color); /* 0 degree */
dreschpe 0:da1bf437cbc1 254 }
dreschpe 0:da1bf437cbc1 255
dreschpe 0:da1bf437cbc1 256 draw_x5 = draw_x7 = x0 - r;
dreschpe 0:da1bf437cbc1 257 draw_y5 = draw_y7 = y0;
dreschpe 0:da1bf437cbc1 258 if (draw_x5>=0) {
dreschpe 0:da1bf437cbc1 259 pixel(draw_x5, draw_y5, color); /* 180 degree */
dreschpe 0:da1bf437cbc1 260 }
dreschpe 0:da1bf437cbc1 261
dreschpe 0:da1bf437cbc1 262 if (r == 1) {
dreschpe 0:da1bf437cbc1 263 return;
dreschpe 0:da1bf437cbc1 264 }
dreschpe 0:da1bf437cbc1 265
dreschpe 0:da1bf437cbc1 266 di = 3 - 2*r;
dreschpe 0:da1bf437cbc1 267 xx = 0;
dreschpe 0:da1bf437cbc1 268 yy = r;
dreschpe 0:da1bf437cbc1 269 while (xx < yy) {
dreschpe 0:da1bf437cbc1 270
dreschpe 0:da1bf437cbc1 271 if (di < 0) {
dreschpe 0:da1bf437cbc1 272 di += 4*xx + 6;
dreschpe 0:da1bf437cbc1 273 } else {
dreschpe 0:da1bf437cbc1 274 di += 4*(xx - yy) + 10;
dreschpe 0:da1bf437cbc1 275 yy--;
dreschpe 0:da1bf437cbc1 276 draw_y0--;
dreschpe 0:da1bf437cbc1 277 draw_y1--;
dreschpe 0:da1bf437cbc1 278 draw_y2++;
dreschpe 0:da1bf437cbc1 279 draw_y3++;
dreschpe 0:da1bf437cbc1 280 draw_x4--;
dreschpe 0:da1bf437cbc1 281 draw_x5++;
dreschpe 0:da1bf437cbc1 282 draw_x6--;
dreschpe 0:da1bf437cbc1 283 draw_x7++;
dreschpe 0:da1bf437cbc1 284 }
dreschpe 0:da1bf437cbc1 285 xx++;
dreschpe 0:da1bf437cbc1 286 draw_x0++;
dreschpe 0:da1bf437cbc1 287 draw_x1--;
dreschpe 0:da1bf437cbc1 288 draw_x2++;
dreschpe 0:da1bf437cbc1 289 draw_x3--;
dreschpe 0:da1bf437cbc1 290 draw_y4++;
dreschpe 0:da1bf437cbc1 291 draw_y5++;
dreschpe 0:da1bf437cbc1 292 draw_y6--;
dreschpe 0:da1bf437cbc1 293 draw_y7--;
dreschpe 0:da1bf437cbc1 294
dreschpe 0:da1bf437cbc1 295 if ( (draw_x0 <= width()) && (draw_y0>=0) ) {
dreschpe 0:da1bf437cbc1 296 pixel(draw_x0, draw_y0, color);
dreschpe 0:da1bf437cbc1 297 }
dreschpe 0:da1bf437cbc1 298
dreschpe 0:da1bf437cbc1 299 if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) {
dreschpe 0:da1bf437cbc1 300 pixel(draw_x1, draw_y1, color);
dreschpe 0:da1bf437cbc1 301 }
dreschpe 0:da1bf437cbc1 302
dreschpe 0:da1bf437cbc1 303 if ( (draw_x2 <= width()) && (draw_y2 <= height()) ) {
dreschpe 0:da1bf437cbc1 304 pixel(draw_x2, draw_y2, color);
dreschpe 0:da1bf437cbc1 305 }
dreschpe 0:da1bf437cbc1 306
dreschpe 0:da1bf437cbc1 307 if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) {
dreschpe 0:da1bf437cbc1 308 pixel(draw_x3, draw_y3, color);
dreschpe 0:da1bf437cbc1 309 }
dreschpe 0:da1bf437cbc1 310
dreschpe 0:da1bf437cbc1 311 if ( (draw_x4 <= width()) && (draw_y4 >= 0) ) {
dreschpe 0:da1bf437cbc1 312 pixel(draw_x4, draw_y4, color);
dreschpe 0:da1bf437cbc1 313 }
dreschpe 0:da1bf437cbc1 314
dreschpe 0:da1bf437cbc1 315 if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) {
dreschpe 0:da1bf437cbc1 316 pixel(draw_x5, draw_y5, color);
dreschpe 0:da1bf437cbc1 317 }
dreschpe 0:da1bf437cbc1 318 if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) {
dreschpe 0:da1bf437cbc1 319 pixel(draw_x6, draw_y6, color);
dreschpe 0:da1bf437cbc1 320 }
dreschpe 0:da1bf437cbc1 321 if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) {
dreschpe 0:da1bf437cbc1 322 pixel(draw_x7, draw_y7, color);
dreschpe 0:da1bf437cbc1 323 }
dreschpe 0:da1bf437cbc1 324 }
dreschpe 0:da1bf437cbc1 325 return;
dreschpe 0:da1bf437cbc1 326 }
dreschpe 0:da1bf437cbc1 327
dreschpe 0:da1bf437cbc1 328 void SPI_TFT_ILI9341::fillcircle(int x, int y, int r, int color)
dreschpe 0:da1bf437cbc1 329 {
dreschpe 0:da1bf437cbc1 330 int i;
dreschpe 0:da1bf437cbc1 331 for (i = 0; i <= r; i++)
dreschpe 0:da1bf437cbc1 332 circle(x,y,i,color);
dreschpe 0:da1bf437cbc1 333 }
dreschpe 0:da1bf437cbc1 334
dreschpe 0:da1bf437cbc1 335
dreschpe 0:da1bf437cbc1 336
dreschpe 0:da1bf437cbc1 337 void SPI_TFT_ILI9341::hline(int x0, int x1, int y, int color)
dreschpe 0:da1bf437cbc1 338 {
dreschpe 0:da1bf437cbc1 339 int w;
dreschpe 0:da1bf437cbc1 340 w = x1 - x0 + 1;
dreschpe 0:da1bf437cbc1 341 window(x0,y,w,1);
dreschpe 0:da1bf437cbc1 342 wr_cmd(0x2C); // send pixel
dreschpe 0:da1bf437cbc1 343 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:da1bf437cbc1 344 int j;
dreschpe 0:da1bf437cbc1 345 for (j=0; j<w; j++) {
dreschpe 0:da1bf437cbc1 346 _spi.write(color);
dreschpe 0:da1bf437cbc1 347 }
dreschpe 0:da1bf437cbc1 348 _cs = 1;
dreschpe 0:da1bf437cbc1 349 _spi.format(8,3);
dreschpe 0:da1bf437cbc1 350 WindowMax();
dreschpe 0:da1bf437cbc1 351 return;
dreschpe 0:da1bf437cbc1 352 }
dreschpe 0:da1bf437cbc1 353
dreschpe 0:da1bf437cbc1 354 void SPI_TFT_ILI9341::vline(int x, int y0, int y1, int color)
dreschpe 0:da1bf437cbc1 355 {
dreschpe 0:da1bf437cbc1 356 int h;
dreschpe 0:da1bf437cbc1 357 h = y1 - y0 + 1;
dreschpe 0:da1bf437cbc1 358 window(x,y0,1,h);
dreschpe 0:da1bf437cbc1 359 wr_cmd(0x2C); // send pixel
dreschpe 0:da1bf437cbc1 360 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:da1bf437cbc1 361 for (int y=0; y<h; y++) {
dreschpe 0:da1bf437cbc1 362 _spi.write(color);
dreschpe 0:da1bf437cbc1 363 }
dreschpe 0:da1bf437cbc1 364 _cs = 1;
dreschpe 0:da1bf437cbc1 365 _spi.format(8,3);
dreschpe 0:da1bf437cbc1 366 WindowMax();
dreschpe 0:da1bf437cbc1 367 return;
dreschpe 0:da1bf437cbc1 368 }
dreschpe 0:da1bf437cbc1 369
dreschpe 0:da1bf437cbc1 370
dreschpe 0:da1bf437cbc1 371
dreschpe 0:da1bf437cbc1 372 void SPI_TFT_ILI9341::line(int x0, int y0, int x1, int y1, int color)
dreschpe 0:da1bf437cbc1 373 {
dreschpe 0:da1bf437cbc1 374 //WindowMax();
dreschpe 0:da1bf437cbc1 375 int dx = 0, dy = 0;
dreschpe 0:da1bf437cbc1 376 int dx_sym = 0, dy_sym = 0;
dreschpe 0:da1bf437cbc1 377 int dx_x2 = 0, dy_x2 = 0;
dreschpe 0:da1bf437cbc1 378 int di = 0;
dreschpe 0:da1bf437cbc1 379
dreschpe 0:da1bf437cbc1 380 dx = x1-x0;
dreschpe 0:da1bf437cbc1 381 dy = y1-y0;
dreschpe 0:da1bf437cbc1 382
dreschpe 0:da1bf437cbc1 383 if (dx == 0) { /* vertical line */
dreschpe 0:da1bf437cbc1 384 if (y1 > y0) vline(x0,y0,y1,color);
dreschpe 0:da1bf437cbc1 385 else vline(x0,y1,y0,color);
dreschpe 0:da1bf437cbc1 386 return;
dreschpe 0:da1bf437cbc1 387 }
dreschpe 0:da1bf437cbc1 388
dreschpe 0:da1bf437cbc1 389 if (dx > 0) {
dreschpe 0:da1bf437cbc1 390 dx_sym = 1;
dreschpe 0:da1bf437cbc1 391 } else {
dreschpe 0:da1bf437cbc1 392 dx_sym = -1;
dreschpe 0:da1bf437cbc1 393 }
dreschpe 0:da1bf437cbc1 394 if (dy == 0) { /* horizontal line */
dreschpe 0:da1bf437cbc1 395 if (x1 > x0) hline(x0,x1,y0,color);
dreschpe 0:da1bf437cbc1 396 else hline(x1,x0,y0,color);
dreschpe 0:da1bf437cbc1 397 return;
dreschpe 0:da1bf437cbc1 398 }
dreschpe 0:da1bf437cbc1 399
dreschpe 0:da1bf437cbc1 400 if (dy > 0) {
dreschpe 0:da1bf437cbc1 401 dy_sym = 1;
dreschpe 0:da1bf437cbc1 402 } else {
dreschpe 0:da1bf437cbc1 403 dy_sym = -1;
dreschpe 0:da1bf437cbc1 404 }
dreschpe 0:da1bf437cbc1 405
dreschpe 0:da1bf437cbc1 406 dx = dx_sym*dx;
dreschpe 0:da1bf437cbc1 407 dy = dy_sym*dy;
dreschpe 0:da1bf437cbc1 408
dreschpe 0:da1bf437cbc1 409 dx_x2 = dx*2;
dreschpe 0:da1bf437cbc1 410 dy_x2 = dy*2;
dreschpe 0:da1bf437cbc1 411
dreschpe 0:da1bf437cbc1 412 if (dx >= dy) {
dreschpe 0:da1bf437cbc1 413 di = dy_x2 - dx;
dreschpe 0:da1bf437cbc1 414 while (x0 != x1) {
dreschpe 0:da1bf437cbc1 415
dreschpe 0:da1bf437cbc1 416 pixel(x0, y0, color);
dreschpe 0:da1bf437cbc1 417 x0 += dx_sym;
dreschpe 0:da1bf437cbc1 418 if (di<0) {
dreschpe 0:da1bf437cbc1 419 di += dy_x2;
dreschpe 0:da1bf437cbc1 420 } else {
dreschpe 0:da1bf437cbc1 421 di += dy_x2 - dx_x2;
dreschpe 0:da1bf437cbc1 422 y0 += dy_sym;
dreschpe 0:da1bf437cbc1 423 }
dreschpe 0:da1bf437cbc1 424 }
dreschpe 0:da1bf437cbc1 425 pixel(x0, y0, color);
dreschpe 0:da1bf437cbc1 426 } else {
dreschpe 0:da1bf437cbc1 427 di = dx_x2 - dy;
dreschpe 0:da1bf437cbc1 428 while (y0 != y1) {
dreschpe 0:da1bf437cbc1 429 pixel(x0, y0, color);
dreschpe 0:da1bf437cbc1 430 y0 += dy_sym;
dreschpe 0:da1bf437cbc1 431 if (di < 0) {
dreschpe 0:da1bf437cbc1 432 di += dx_x2;
dreschpe 0:da1bf437cbc1 433 } else {
dreschpe 0:da1bf437cbc1 434 di += dx_x2 - dy_x2;
dreschpe 0:da1bf437cbc1 435 x0 += dx_sym;
dreschpe 0:da1bf437cbc1 436 }
dreschpe 0:da1bf437cbc1 437 }
dreschpe 0:da1bf437cbc1 438 pixel(x0, y0, color);
dreschpe 0:da1bf437cbc1 439 }
dreschpe 0:da1bf437cbc1 440 return;
dreschpe 0:da1bf437cbc1 441 }
dreschpe 0:da1bf437cbc1 442
dreschpe 0:da1bf437cbc1 443
dreschpe 0:da1bf437cbc1 444 void SPI_TFT_ILI9341::rect(int x0, int y0, int x1, int y1, int color)
dreschpe 0:da1bf437cbc1 445 {
dreschpe 0:da1bf437cbc1 446
dreschpe 0:da1bf437cbc1 447 if (x1 > x0) hline(x0,x1,y0,color);
dreschpe 0:da1bf437cbc1 448 else hline(x1,x0,y0,color);
dreschpe 0:da1bf437cbc1 449
dreschpe 0:da1bf437cbc1 450 if (y1 > y0) vline(x0,y0,y1,color);
dreschpe 0:da1bf437cbc1 451 else vline(x0,y1,y0,color);
dreschpe 0:da1bf437cbc1 452
dreschpe 0:da1bf437cbc1 453 if (x1 > x0) hline(x0,x1,y1,color);
dreschpe 0:da1bf437cbc1 454 else hline(x1,x0,y1,color);
dreschpe 0:da1bf437cbc1 455
dreschpe 0:da1bf437cbc1 456 if (y1 > y0) vline(x1,y0,y1,color);
dreschpe 0:da1bf437cbc1 457 else vline(x1,y1,y0,color);
dreschpe 0:da1bf437cbc1 458
dreschpe 0:da1bf437cbc1 459 return;
dreschpe 0:da1bf437cbc1 460 }
dreschpe 0:da1bf437cbc1 461
dreschpe 0:da1bf437cbc1 462
dreschpe 0:da1bf437cbc1 463
dreschpe 0:da1bf437cbc1 464 void SPI_TFT_ILI9341::fillrect(int x0, int y0, int x1, int y1, int color)
dreschpe 0:da1bf437cbc1 465 {
dreschpe 0:da1bf437cbc1 466
dreschpe 0:da1bf437cbc1 467 int h = y1 - y0 + 1;
dreschpe 0:da1bf437cbc1 468 int w = x1 - x0 + 1;
dreschpe 0:da1bf437cbc1 469 int pixel = h * w;
dreschpe 0:da1bf437cbc1 470 window(x0,y0,w,h);
dreschpe 0:da1bf437cbc1 471 wr_cmd(0x2C); // send pixel
dreschpe 0:da1bf437cbc1 472 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:da1bf437cbc1 473 for (int p=0; p<pixel; p++) {
dreschpe 0:da1bf437cbc1 474 _spi.write(color);
dreschpe 0:da1bf437cbc1 475 }
dreschpe 0:da1bf437cbc1 476 _cs = 1;
dreschpe 0:da1bf437cbc1 477 _spi.format(8,3);
dreschpe 0:da1bf437cbc1 478 WindowMax();
dreschpe 0:da1bf437cbc1 479 return;
dreschpe 0:da1bf437cbc1 480 }
dreschpe 0:da1bf437cbc1 481
dreschpe 0:da1bf437cbc1 482
dreschpe 0:da1bf437cbc1 483 void SPI_TFT_ILI9341::locate(int x, int y)
dreschpe 0:da1bf437cbc1 484 {
dreschpe 0:da1bf437cbc1 485 char_x = x;
dreschpe 0:da1bf437cbc1 486 char_y = y;
dreschpe 0:da1bf437cbc1 487 }
dreschpe 0:da1bf437cbc1 488
dreschpe 0:da1bf437cbc1 489
dreschpe 0:da1bf437cbc1 490
dreschpe 0:da1bf437cbc1 491 int SPI_TFT_ILI9341::columns()
dreschpe 0:da1bf437cbc1 492 {
dreschpe 0:da1bf437cbc1 493 return width() / font[1];
dreschpe 0:da1bf437cbc1 494 }
dreschpe 0:da1bf437cbc1 495
dreschpe 0:da1bf437cbc1 496
dreschpe 0:da1bf437cbc1 497
dreschpe 0:da1bf437cbc1 498 int SPI_TFT_ILI9341::rows()
dreschpe 0:da1bf437cbc1 499 {
dreschpe 0:da1bf437cbc1 500 return height() / font[2];
dreschpe 0:da1bf437cbc1 501 }
dreschpe 0:da1bf437cbc1 502
dreschpe 0:da1bf437cbc1 503
dreschpe 0:da1bf437cbc1 504
dreschpe 0:da1bf437cbc1 505 int SPI_TFT_ILI9341::_putc(int value)
dreschpe 0:da1bf437cbc1 506 {
dreschpe 0:da1bf437cbc1 507 if (value == '\n') { // new line
dreschpe 0:da1bf437cbc1 508 char_x = 0;
dreschpe 0:da1bf437cbc1 509 char_y = char_y + font[2];
dreschpe 0:da1bf437cbc1 510 if (char_y >= height() - font[2]) {
dreschpe 0:da1bf437cbc1 511 char_y = 0;
dreschpe 0:da1bf437cbc1 512 }
dreschpe 0:da1bf437cbc1 513 } else {
dreschpe 0:da1bf437cbc1 514 character(char_x, char_y, value);
dreschpe 0:da1bf437cbc1 515 }
dreschpe 0:da1bf437cbc1 516 return value;
dreschpe 0:da1bf437cbc1 517 }
dreschpe 0:da1bf437cbc1 518
dreschpe 0:da1bf437cbc1 519
dreschpe 0:da1bf437cbc1 520 void SPI_TFT_ILI9341::character(int x, int y, int c)
dreschpe 0:da1bf437cbc1 521 {
dreschpe 0:da1bf437cbc1 522 unsigned int hor,vert,offset,bpl,j,i,b;
dreschpe 0:da1bf437cbc1 523 unsigned char* zeichen;
dreschpe 0:da1bf437cbc1 524 unsigned char z,w;
dreschpe 0:da1bf437cbc1 525
dreschpe 0:da1bf437cbc1 526 if ((c < 31) || (c > 127)) return; // test char range
dreschpe 0:da1bf437cbc1 527
dreschpe 0:da1bf437cbc1 528 // read font parameter from start of array
dreschpe 0:da1bf437cbc1 529 offset = font[0]; // bytes / char
dreschpe 0:da1bf437cbc1 530 hor = font[1]; // get hor size of font
dreschpe 0:da1bf437cbc1 531 vert = font[2]; // get vert size of font
dreschpe 0:da1bf437cbc1 532 bpl = font[3]; // bytes per line
dreschpe 0:da1bf437cbc1 533
dreschpe 0:da1bf437cbc1 534 if (char_x + hor > width()) {
dreschpe 0:da1bf437cbc1 535 char_x = 0;
dreschpe 0:da1bf437cbc1 536 char_y = char_y + vert;
dreschpe 0:da1bf437cbc1 537 if (char_y >= height() - font[2]) {
dreschpe 0:da1bf437cbc1 538 char_y = 0;
dreschpe 0:da1bf437cbc1 539 }
dreschpe 0:da1bf437cbc1 540 }
dreschpe 0:da1bf437cbc1 541 window(char_x, char_y,hor,vert); // char box
dreschpe 0:da1bf437cbc1 542 wr_cmd(0x2C); // send pixel
dreschpe 0:da1bf437cbc1 543 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:da1bf437cbc1 544 zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
dreschpe 0:da1bf437cbc1 545 w = zeichen[0]; // width of actual char
dreschpe 0:da1bf437cbc1 546 for (j=0; j<vert; j++) { // vert line
dreschpe 0:da1bf437cbc1 547 for (i=0; i<hor; i++) { // horz line
dreschpe 0:da1bf437cbc1 548 z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
dreschpe 0:da1bf437cbc1 549 b = 1 << (j & 0x07);
dreschpe 0:da1bf437cbc1 550 if (( z & b ) == 0x00) {
dreschpe 0:da1bf437cbc1 551 _spi.write(_background);
dreschpe 0:da1bf437cbc1 552 } else {
dreschpe 0:da1bf437cbc1 553 _spi.write(_foreground);
dreschpe 0:da1bf437cbc1 554 }
dreschpe 0:da1bf437cbc1 555 }
dreschpe 0:da1bf437cbc1 556 }
dreschpe 0:da1bf437cbc1 557 _cs = 1;
dreschpe 0:da1bf437cbc1 558 _spi.format(8,3);
dreschpe 0:da1bf437cbc1 559 WindowMax();
dreschpe 0:da1bf437cbc1 560 if ((w + 2) < hor) { // x offset to next char
dreschpe 0:da1bf437cbc1 561 char_x += w + 2;
dreschpe 0:da1bf437cbc1 562 } else char_x += hor;
dreschpe 0:da1bf437cbc1 563 }
dreschpe 0:da1bf437cbc1 564
dreschpe 0:da1bf437cbc1 565
dreschpe 0:da1bf437cbc1 566 void SPI_TFT_ILI9341::set_font(unsigned char* f)
dreschpe 0:da1bf437cbc1 567 {
dreschpe 0:da1bf437cbc1 568 font = f;
dreschpe 0:da1bf437cbc1 569 }
dreschpe 0:da1bf437cbc1 570
dreschpe 0:da1bf437cbc1 571
dreschpe 0:da1bf437cbc1 572
dreschpe 0:da1bf437cbc1 573 void SPI_TFT_ILI9341::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap)
dreschpe 0:da1bf437cbc1 574 {
dreschpe 0:da1bf437cbc1 575 unsigned int j;
dreschpe 0:da1bf437cbc1 576 int padd;
dreschpe 0:da1bf437cbc1 577 unsigned short *bitmap_ptr = (unsigned short *)bitmap;
dreschpe 0:da1bf437cbc1 578 // the lines are padded to multiple of 4 bytes in a bitmap
dreschpe 0:da1bf437cbc1 579 padd = -1;
dreschpe 0:da1bf437cbc1 580 do {
dreschpe 0:da1bf437cbc1 581 padd ++;
dreschpe 0:da1bf437cbc1 582 } while (2*(w + padd)%4 != 0);
dreschpe 0:da1bf437cbc1 583 window(x, y, w, h);
dreschpe 0:da1bf437cbc1 584 wr_cmd(0x2C); // send pixel
dreschpe 0:da1bf437cbc1 585 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:da1bf437cbc1 586 unsigned int i;
dreschpe 0:da1bf437cbc1 587 for (j = 0; j < h; j++) { //Lines
dreschpe 0:da1bf437cbc1 588 for (i = 0; i < w; i++) { // copy pixel data to TFT
dreschpe 0:da1bf437cbc1 589 _spi.write(*bitmap_ptr); // one line
dreschpe 0:da1bf437cbc1 590 bitmap_ptr++;
dreschpe 0:da1bf437cbc1 591 }
dreschpe 0:da1bf437cbc1 592 bitmap_ptr -= 2*w;
dreschpe 0:da1bf437cbc1 593 bitmap_ptr -= padd;
dreschpe 0:da1bf437cbc1 594 }
dreschpe 0:da1bf437cbc1 595 _cs = 1;
dreschpe 0:da1bf437cbc1 596 _spi.format(8,3);
dreschpe 0:da1bf437cbc1 597 WindowMax();
dreschpe 0:da1bf437cbc1 598 }
dreschpe 0:da1bf437cbc1 599
dreschpe 0:da1bf437cbc1 600
dreschpe 0:da1bf437cbc1 601 int SPI_TFT_ILI9341::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP)
dreschpe 0:da1bf437cbc1 602 {
dreschpe 0:da1bf437cbc1 603
dreschpe 0:da1bf437cbc1 604 #define OffsetPixelWidth 18
dreschpe 0:da1bf437cbc1 605 #define OffsetPixelHeigh 22
dreschpe 0:da1bf437cbc1 606 #define OffsetFileSize 34
dreschpe 0:da1bf437cbc1 607 #define OffsetPixData 10
dreschpe 0:da1bf437cbc1 608 #define OffsetBPP 28
dreschpe 0:da1bf437cbc1 609
dreschpe 0:da1bf437cbc1 610 char filename[50];
dreschpe 0:da1bf437cbc1 611 unsigned char BMP_Header[54];
dreschpe 0:da1bf437cbc1 612 unsigned short BPP_t;
dreschpe 0:da1bf437cbc1 613 unsigned int PixelWidth,PixelHeigh,start_data;
dreschpe 0:da1bf437cbc1 614 unsigned int i,off;
dreschpe 0:da1bf437cbc1 615 int padd,j;
dreschpe 0:da1bf437cbc1 616 unsigned short *line;
dreschpe 0:da1bf437cbc1 617
dreschpe 0:da1bf437cbc1 618 // get the filename
dreschpe 0:da1bf437cbc1 619 LocalFileSystem local("local");
dreschpe 0:da1bf437cbc1 620 sprintf(&filename[0],"/local/");
dreschpe 0:da1bf437cbc1 621 i=7;
dreschpe 0:da1bf437cbc1 622 while (*Name_BMP!='\0') {
dreschpe 0:da1bf437cbc1 623 filename[i++]=*Name_BMP++;
dreschpe 0:da1bf437cbc1 624 }
dreschpe 0:da1bf437cbc1 625
dreschpe 0:da1bf437cbc1 626 fprintf(stderr, "filename : %s \n\r",filename);
dreschpe 0:da1bf437cbc1 627
dreschpe 0:da1bf437cbc1 628 FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file
dreschpe 0:da1bf437cbc1 629 if (!Image) {
dreschpe 0:da1bf437cbc1 630 return(0); // error file not found !
dreschpe 0:da1bf437cbc1 631 }
dreschpe 0:da1bf437cbc1 632
dreschpe 0:da1bf437cbc1 633 fread(&BMP_Header[0],1,54,Image); // get the BMP Header
dreschpe 0:da1bf437cbc1 634
dreschpe 0:da1bf437cbc1 635 if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte
dreschpe 0:da1bf437cbc1 636 fclose(Image);
dreschpe 0:da1bf437cbc1 637 return(-1); // error no BMP file
dreschpe 0:da1bf437cbc1 638 }
dreschpe 0:da1bf437cbc1 639
dreschpe 0:da1bf437cbc1 640 BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8);
dreschpe 0:da1bf437cbc1 641 if (BPP_t != 0x0010) {
dreschpe 0:da1bf437cbc1 642 fclose(Image);
dreschpe 0:da1bf437cbc1 643 return(-2); // error no 16 bit BMP
dreschpe 0:da1bf437cbc1 644 }
dreschpe 0:da1bf437cbc1 645
dreschpe 0:da1bf437cbc1 646 PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24);
dreschpe 0:da1bf437cbc1 647 PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24);
dreschpe 0:da1bf437cbc1 648 if (PixelHeigh > height() + y || PixelWidth > width() + x) {
dreschpe 0:da1bf437cbc1 649 fclose(Image);
dreschpe 0:da1bf437cbc1 650 return(-3); // to big
dreschpe 0:da1bf437cbc1 651 }
dreschpe 0:da1bf437cbc1 652
dreschpe 0:da1bf437cbc1 653 start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24);
dreschpe 0:da1bf437cbc1 654
dreschpe 0:da1bf437cbc1 655 line = (unsigned short *) malloc (2 * PixelWidth); // we need a buffer for a line
dreschpe 0:da1bf437cbc1 656 if (line == NULL) {
dreschpe 0:da1bf437cbc1 657 return(-4); // error no memory
dreschpe 0:da1bf437cbc1 658 }
dreschpe 0:da1bf437cbc1 659
dreschpe 0:da1bf437cbc1 660 // the bmp lines are padded to multiple of 4 bytes
dreschpe 0:da1bf437cbc1 661 padd = -1;
dreschpe 0:da1bf437cbc1 662 do {
dreschpe 0:da1bf437cbc1 663 padd ++;
dreschpe 0:da1bf437cbc1 664 } while ((PixelWidth * 2 + padd)%4 != 0);
dreschpe 0:da1bf437cbc1 665
dreschpe 0:da1bf437cbc1 666
dreschpe 0:da1bf437cbc1 667 //fseek(Image, 70 ,SEEK_SET);
dreschpe 0:da1bf437cbc1 668 window(x, y,PixelWidth ,PixelHeigh);
dreschpe 0:da1bf437cbc1 669 wr_cmd(0x2C); // send pixel
dreschpe 0:da1bf437cbc1 670 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:da1bf437cbc1 671 for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up
dreschpe 0:da1bf437cbc1 672 off = j * (PixelWidth * 2 + padd) + start_data; // start of line
dreschpe 0:da1bf437cbc1 673 fseek(Image, off ,SEEK_SET);
dreschpe 0:da1bf437cbc1 674 fread(line,1,PixelWidth * 2,Image); // read a line - slow !
dreschpe 0:da1bf437cbc1 675 for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT
dreschpe 0:da1bf437cbc1 676 _spi.write(line[i]); // one 16 bit pixel
dreschpe 0:da1bf437cbc1 677 }
dreschpe 0:da1bf437cbc1 678 }
dreschpe 0:da1bf437cbc1 679 _cs = 1;
dreschpe 0:da1bf437cbc1 680 _spi.format(8,3);
dreschpe 0:da1bf437cbc1 681 free (line);
dreschpe 0:da1bf437cbc1 682 fclose(Image);
dreschpe 0:da1bf437cbc1 683 WindowMax();
dreschpe 0:da1bf437cbc1 684 return(1);
dreschpe 0:da1bf437cbc1 685 }