Library to control a QVGA TFT connected to SPI. You can use printf to print text The lib can handle different fonts, draw lines, circles, rect and bmp

Committer:
dreschpe
Date:
Wed Jul 13 08:25:10 2011 +0000
Revision:
1:aa3356b16080
Parent:
0:cccc5726bdf3
Add Docu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:cccc5726bdf3 1 /* mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller
dreschpe 0:cccc5726bdf3 2 * Copyright (c) 2011 Peter Drescher - DC2PD
dreschpe 0:cccc5726bdf3 3 *
dreschpe 0:cccc5726bdf3 4 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dreschpe 0:cccc5726bdf3 5 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dreschpe 0:cccc5726bdf3 6 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dreschpe 0:cccc5726bdf3 7 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dreschpe 0:cccc5726bdf3 8 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dreschpe 0:cccc5726bdf3 9 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
dreschpe 0:cccc5726bdf3 10 * THE SOFTWARE.
dreschpe 0:cccc5726bdf3 11 */
dreschpe 0:cccc5726bdf3 12
dreschpe 0:cccc5726bdf3 13 #include "SPI_TFT.h"
dreschpe 0:cccc5726bdf3 14 #include "mbed.h"
dreschpe 0:cccc5726bdf3 15
dreschpe 0:cccc5726bdf3 16
dreschpe 0:cccc5726bdf3 17
dreschpe 1:aa3356b16080 18 #define BPP 16 // Bits per pixel
dreschpe 1:aa3356b16080 19
dreschpe 1:aa3356b16080 20
dreschpe 1:aa3356b16080 21
dreschpe 0:cccc5726bdf3 22 SPI_TFT::SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, const char *name)
dreschpe 0:cccc5726bdf3 23 : _spi(mosi, miso, sclk), _cs(cs), _reset(reset),GraphicsDisplay(name) {
dreschpe 0:cccc5726bdf3 24 tft_reset();
dreschpe 0:cccc5726bdf3 25 orientation = 0;
dreschpe 0:cccc5726bdf3 26 char_x = 0;
dreschpe 0:cccc5726bdf3 27 }
dreschpe 0:cccc5726bdf3 28
dreschpe 0:cccc5726bdf3 29 int SPI_TFT::width() {
dreschpe 0:cccc5726bdf3 30 if(orientation == 0 || orientation == 2) return 240;
dreschpe 0:cccc5726bdf3 31 else return 320;
dreschpe 0:cccc5726bdf3 32 }
dreschpe 0:cccc5726bdf3 33
dreschpe 0:cccc5726bdf3 34
dreschpe 0:cccc5726bdf3 35 int SPI_TFT::height() {
dreschpe 0:cccc5726bdf3 36 if(orientation == 0 || orientation == 2) return 320;
dreschpe 0:cccc5726bdf3 37 else return 240;
dreschpe 0:cccc5726bdf3 38 }
dreschpe 0:cccc5726bdf3 39
dreschpe 1:aa3356b16080 40
dreschpe 0:cccc5726bdf3 41
dreschpe 0:cccc5726bdf3 42 void SPI_TFT::set_orientation(unsigned int o){
dreschpe 0:cccc5726bdf3 43 orientation = o;
dreschpe 0:cccc5726bdf3 44 switch(orientation){
dreschpe 0:cccc5726bdf3 45 case 0:
dreschpe 0:cccc5726bdf3 46 wr_reg(0x16, 0x0008);
dreschpe 0:cccc5726bdf3 47 break;
dreschpe 0:cccc5726bdf3 48 case 1:
dreschpe 0:cccc5726bdf3 49 wr_reg(0x16, 0x0068);
dreschpe 0:cccc5726bdf3 50 break;
dreschpe 0:cccc5726bdf3 51 case 2:
dreschpe 0:cccc5726bdf3 52 wr_reg(0x16, 0x00C8);
dreschpe 0:cccc5726bdf3 53 break;
dreschpe 0:cccc5726bdf3 54 case 3:
dreschpe 0:cccc5726bdf3 55 wr_reg(0x16, 0x00A8);
dreschpe 0:cccc5726bdf3 56 break;
dreschpe 0:cccc5726bdf3 57 }
dreschpe 0:cccc5726bdf3 58 }
dreschpe 0:cccc5726bdf3 59
dreschpe 1:aa3356b16080 60
dreschpe 0:cccc5726bdf3 61
dreschpe 0:cccc5726bdf3 62 void SPI_TFT::wr_cmd(int cmd) {
dreschpe 0:cccc5726bdf3 63 _cs = 0;
dreschpe 0:cccc5726bdf3 64 _spi.write(SPI_START | SPI_WR | SPI_INDEX); /* Write : RS = 0, RW = 0 */
dreschpe 0:cccc5726bdf3 65 _spi.write(cmd);
dreschpe 0:cccc5726bdf3 66 _cs = 1;
dreschpe 0:cccc5726bdf3 67 }
dreschpe 0:cccc5726bdf3 68
dreschpe 1:aa3356b16080 69
dreschpe 0:cccc5726bdf3 70
dreschpe 0:cccc5726bdf3 71 void SPI_TFT::wr_dat(int dat) {
dreschpe 0:cccc5726bdf3 72 _cs = 0;
dreschpe 0:cccc5726bdf3 73 _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0
dreschpe 0:cccc5726bdf3 74 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:cccc5726bdf3 75 _spi.write(dat); // Write D0..D15
dreschpe 0:cccc5726bdf3 76 _spi.format(8,3); // 8 bit Mode 3
dreschpe 0:cccc5726bdf3 77 _cs = 1;
dreschpe 0:cccc5726bdf3 78 }
dreschpe 0:cccc5726bdf3 79
dreschpe 1:aa3356b16080 80
dreschpe 0:cccc5726bdf3 81
dreschpe 0:cccc5726bdf3 82 void SPI_TFT::wr_dat_start(void){
dreschpe 0:cccc5726bdf3 83 _cs = 0;
dreschpe 0:cccc5726bdf3 84 _spi.write(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */
dreschpe 0:cccc5726bdf3 85 }
dreschpe 0:cccc5726bdf3 86
dreschpe 1:aa3356b16080 87
dreschpe 0:cccc5726bdf3 88
dreschpe 0:cccc5726bdf3 89 void SPI_TFT::wr_dat_stop (void){
dreschpe 0:cccc5726bdf3 90 _cs = 1;
dreschpe 0:cccc5726bdf3 91 }
dreschpe 0:cccc5726bdf3 92
dreschpe 1:aa3356b16080 93
dreschpe 0:cccc5726bdf3 94
dreschpe 0:cccc5726bdf3 95 void SPI_TFT::wr_dat_only (unsigned short dat) {
dreschpe 0:cccc5726bdf3 96
dreschpe 0:cccc5726bdf3 97 _spi.format(16,3); // switch to 16 bit Mode 3
dreschpe 0:cccc5726bdf3 98 _spi.write(dat); // Write D0..D15
dreschpe 0:cccc5726bdf3 99 _spi.format(8,3); // 8 bit Mode 3
dreschpe 0:cccc5726bdf3 100 }
dreschpe 0:cccc5726bdf3 101
dreschpe 1:aa3356b16080 102
dreschpe 0:cccc5726bdf3 103
dreschpe 0:cccc5726bdf3 104 unsigned short SPI_TFT::rd_dat (void) {
dreschpe 0:cccc5726bdf3 105 unsigned short val = 0;
dreschpe 0:cccc5726bdf3 106
dreschpe 0:cccc5726bdf3 107 _cs = 0;
dreschpe 0:cccc5726bdf3 108 _spi.write(SPI_START | SPI_RD | SPI_DATA); /* Read: RS = 1, RW = 1 */
dreschpe 0:cccc5726bdf3 109 _spi.write(0); /* Dummy read 1 */
dreschpe 0:cccc5726bdf3 110 val = _spi.write(0); /* Read D8..D15 */
dreschpe 0:cccc5726bdf3 111 val <<= 8;
dreschpe 0:cccc5726bdf3 112 val |= _spi.write(0); /* Read D0..D7 */
dreschpe 0:cccc5726bdf3 113 _cs = 1;
dreschpe 0:cccc5726bdf3 114 return (val);
dreschpe 0:cccc5726bdf3 115 }
dreschpe 0:cccc5726bdf3 116
dreschpe 1:aa3356b16080 117
dreschpe 0:cccc5726bdf3 118
dreschpe 0:cccc5726bdf3 119 void SPI_TFT::wr_reg (unsigned char reg, unsigned short val) {
dreschpe 0:cccc5726bdf3 120
dreschpe 0:cccc5726bdf3 121 wr_cmd(reg);
dreschpe 0:cccc5726bdf3 122 wr_dat(val);
dreschpe 0:cccc5726bdf3 123 }
dreschpe 0:cccc5726bdf3 124
dreschpe 1:aa3356b16080 125
dreschpe 0:cccc5726bdf3 126
dreschpe 0:cccc5726bdf3 127 unsigned short SPI_TFT::rd_reg (unsigned char reg) {
dreschpe 0:cccc5726bdf3 128
dreschpe 0:cccc5726bdf3 129 wr_cmd(reg);
dreschpe 0:cccc5726bdf3 130 return(rd_dat());
dreschpe 0:cccc5726bdf3 131 }
dreschpe 0:cccc5726bdf3 132
dreschpe 1:aa3356b16080 133
dreschpe 0:cccc5726bdf3 134
dreschpe 0:cccc5726bdf3 135 void SPI_TFT::tft_reset() {
dreschpe 0:cccc5726bdf3 136 static unsigned short driverCode;
dreschpe 0:cccc5726bdf3 137 _spi.format(8,3); // 8 bit spi mode 3
dreschpe 0:cccc5726bdf3 138 _spi.frequency(48000000); // 48Mhz SPI clock
dreschpe 0:cccc5726bdf3 139 _reset = 0; // reset
dreschpe 0:cccc5726bdf3 140 _cs = 1;
dreschpe 0:cccc5726bdf3 141 wait_us(50);
dreschpe 0:cccc5726bdf3 142 _reset = 1; // end reset
dreschpe 0:cccc5726bdf3 143 wait_ms(5);
dreschpe 0:cccc5726bdf3 144
dreschpe 0:cccc5726bdf3 145 driverCode = rd_reg(0x00); // read controller ID
dreschpe 0:cccc5726bdf3 146 //printf("Disp_ID = %x",driverCode);
dreschpe 0:cccc5726bdf3 147
dreschpe 0:cccc5726bdf3 148 /* Start Initial Sequence ----------------------------------------------------*/
dreschpe 0:cccc5726bdf3 149 wr_reg(0xEA, 0x0000); /* Reset Power Control 1 */
dreschpe 0:cccc5726bdf3 150 wr_reg(0xEB, 0x0020); /* Power Control 2 */
dreschpe 0:cccc5726bdf3 151 wr_reg(0xEC, 0x000C); /* Power Control 3 */
dreschpe 0:cccc5726bdf3 152 wr_reg(0xED, 0x00C4); /* Power Control 4 */
dreschpe 0:cccc5726bdf3 153 wr_reg(0xE8, 0x0040); /* Source OPON_N */
dreschpe 0:cccc5726bdf3 154 wr_reg(0xE9, 0x0038); /* Source OPON_I */
dreschpe 0:cccc5726bdf3 155 wr_reg(0xF1, 0x0001); /* */
dreschpe 0:cccc5726bdf3 156 wr_reg(0xF2, 0x0010); /* */
dreschpe 0:cccc5726bdf3 157 wr_reg(0x27, 0x00A3); /* Display Control 2 */
dreschpe 0:cccc5726bdf3 158
dreschpe 0:cccc5726bdf3 159 /* Power On sequence ---------------------------------------------------------*/
dreschpe 0:cccc5726bdf3 160 wr_reg(0x1B, 0x001B); /* Power Control 2 */
dreschpe 0:cccc5726bdf3 161 wr_reg(0x1A, 0x0001); /* Power Control 1 */
dreschpe 0:cccc5726bdf3 162 wr_reg(0x24, 0x002F); /* Vcom Control 2 */
dreschpe 0:cccc5726bdf3 163 wr_reg(0x25, 0x0057); /* Vcom Control 3 */
dreschpe 0:cccc5726bdf3 164 wr_reg(0x23, 0x008D); /* Vcom Control 1 */
dreschpe 0:cccc5726bdf3 165
dreschpe 0:cccc5726bdf3 166 /* Gamma settings -----------------------------------------------------------*/
dreschpe 0:cccc5726bdf3 167 wr_reg(0x40,0x00); //
dreschpe 0:cccc5726bdf3 168 wr_reg(0x41,0x00); //
dreschpe 0:cccc5726bdf3 169 wr_reg(0x42,0x01); //
dreschpe 0:cccc5726bdf3 170 wr_reg(0x43,0x13); //
dreschpe 0:cccc5726bdf3 171 wr_reg(0x44,0x10); //
dreschpe 0:cccc5726bdf3 172 wr_reg(0x45,0x26); //
dreschpe 0:cccc5726bdf3 173 wr_reg(0x46,0x08); //
dreschpe 0:cccc5726bdf3 174 wr_reg(0x47,0x51); //
dreschpe 0:cccc5726bdf3 175 wr_reg(0x48,0x02); //
dreschpe 0:cccc5726bdf3 176 wr_reg(0x49,0x12); //
dreschpe 0:cccc5726bdf3 177 wr_reg(0x4A,0x18); //
dreschpe 0:cccc5726bdf3 178 wr_reg(0x4B,0x19); //
dreschpe 0:cccc5726bdf3 179 wr_reg(0x4C,0x14); //
dreschpe 0:cccc5726bdf3 180 wr_reg(0x50,0x19); //
dreschpe 0:cccc5726bdf3 181 wr_reg(0x51,0x2F); //
dreschpe 0:cccc5726bdf3 182 wr_reg(0x52,0x2C); //
dreschpe 0:cccc5726bdf3 183 wr_reg(0x53,0x3E); //
dreschpe 0:cccc5726bdf3 184 wr_reg(0x54,0x3F); //
dreschpe 0:cccc5726bdf3 185 wr_reg(0x55,0x3F); //
dreschpe 0:cccc5726bdf3 186 wr_reg(0x56,0x2E); //
dreschpe 0:cccc5726bdf3 187 wr_reg(0x57,0x77); //
dreschpe 0:cccc5726bdf3 188 wr_reg(0x58,0x0B); //
dreschpe 0:cccc5726bdf3 189 wr_reg(0x59,0x06); //
dreschpe 0:cccc5726bdf3 190 wr_reg(0x5A,0x07); //
dreschpe 0:cccc5726bdf3 191 wr_reg(0x5B,0x0D); //
dreschpe 0:cccc5726bdf3 192 wr_reg(0x5C,0x1D); //
dreschpe 0:cccc5726bdf3 193 wr_reg(0x5D,0xCC); //
dreschpe 0:cccc5726bdf3 194
dreschpe 0:cccc5726bdf3 195 /* Power + Osc ---------------------------------------------------------------*/
dreschpe 0:cccc5726bdf3 196 wr_reg(0x18, 0x0036); /* OSC Control 1 */
dreschpe 0:cccc5726bdf3 197 wr_reg(0x19, 0x0001); /* OSC Control 2 */
dreschpe 0:cccc5726bdf3 198 wr_reg(0x01, 0x0000); /* Display Mode Control */
dreschpe 0:cccc5726bdf3 199 wr_reg(0x1F, 0x0088); /* Power Control 6 */
dreschpe 0:cccc5726bdf3 200 wait_ms(5); /* Delay 5 ms */
dreschpe 0:cccc5726bdf3 201 wr_reg(0x1F, 0x0080); /* Power Control 6 */
dreschpe 0:cccc5726bdf3 202 wait_ms(5); /* Delay 5 ms */
dreschpe 0:cccc5726bdf3 203 wr_reg(0x1F, 0x0090); /* Power Control 6 */
dreschpe 0:cccc5726bdf3 204 wait_ms(5); /* Delay 5 ms */
dreschpe 0:cccc5726bdf3 205 wr_reg(0x1F, 0x00D0); /* Power Control 6 */
dreschpe 0:cccc5726bdf3 206 wait_ms(5); /* Delay 5 ms */
dreschpe 0:cccc5726bdf3 207
dreschpe 0:cccc5726bdf3 208 wr_reg(0x17, 0x0005); /* Colmod 16Bit/Pixel */
dreschpe 0:cccc5726bdf3 209
dreschpe 0:cccc5726bdf3 210 wr_reg(0x36, 0x0000); /* Panel Characteristic */
dreschpe 0:cccc5726bdf3 211 wr_reg(0x28, 0x0038); /* Display Control 3 */
dreschpe 0:cccc5726bdf3 212 wait_ms(40);
dreschpe 0:cccc5726bdf3 213 wr_reg(0x28, 0x003C); /* Display Control 3 */
dreschpe 0:cccc5726bdf3 214 switch(orientation){
dreschpe 0:cccc5726bdf3 215 case 0:
dreschpe 0:cccc5726bdf3 216 wr_reg(0x16, 0x0008);
dreschpe 0:cccc5726bdf3 217 break;
dreschpe 0:cccc5726bdf3 218 case 1:
dreschpe 0:cccc5726bdf3 219 wr_reg(0x16, 0x0068);
dreschpe 0:cccc5726bdf3 220 break;
dreschpe 0:cccc5726bdf3 221 case 2:
dreschpe 0:cccc5726bdf3 222 wr_reg(0x16, 0x00C8);
dreschpe 0:cccc5726bdf3 223 break;
dreschpe 0:cccc5726bdf3 224 case 3:
dreschpe 0:cccc5726bdf3 225 wr_reg(0x16, 0x00A8);
dreschpe 0:cccc5726bdf3 226 break;
dreschpe 0:cccc5726bdf3 227 }
dreschpe 0:cccc5726bdf3 228
dreschpe 0:cccc5726bdf3 229 WindowMax ();
dreschpe 0:cccc5726bdf3 230 }
dreschpe 0:cccc5726bdf3 231
dreschpe 0:cccc5726bdf3 232
dreschpe 1:aa3356b16080 233
dreschpe 0:cccc5726bdf3 234
dreschpe 0:cccc5726bdf3 235 void SPI_TFT::pixel(int x, int y, int color) {
dreschpe 0:cccc5726bdf3 236 wr_reg(0x03, (x >> 0));
dreschpe 0:cccc5726bdf3 237 wr_reg(0x02, (x >> 8));
dreschpe 0:cccc5726bdf3 238 wr_reg(0x07, (y >> 0));
dreschpe 0:cccc5726bdf3 239 wr_reg(0x06, (y >> 8));
dreschpe 0:cccc5726bdf3 240 wr_cmd(0x22);
dreschpe 0:cccc5726bdf3 241 wr_dat(color);
dreschpe 0:cccc5726bdf3 242 }
dreschpe 0:cccc5726bdf3 243
dreschpe 0:cccc5726bdf3 244
dreschpe 1:aa3356b16080 245
dreschpe 0:cccc5726bdf3 246
dreschpe 0:cccc5726bdf3 247 void SPI_TFT::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
dreschpe 0:cccc5726bdf3 248 wr_reg(0x03, (x >> 0));
dreschpe 0:cccc5726bdf3 249 wr_reg(0x02, (x >> 8));
dreschpe 0:cccc5726bdf3 250 wr_reg(0x05, (x+w-1 >> 0));
dreschpe 0:cccc5726bdf3 251 wr_reg(0x04, (x+w-1 >> 8));
dreschpe 0:cccc5726bdf3 252 wr_reg(0x07, ( y >> 0));
dreschpe 0:cccc5726bdf3 253 wr_reg(0x06, ( y >> 8));
dreschpe 0:cccc5726bdf3 254 wr_reg(0x09, ( y+h-1 >> 0));
dreschpe 0:cccc5726bdf3 255 wr_reg(0x08, ( y+h-1 >> 8));
dreschpe 0:cccc5726bdf3 256 //wr_cmd(0x22);
dreschpe 0:cccc5726bdf3 257 }
dreschpe 0:cccc5726bdf3 258
dreschpe 0:cccc5726bdf3 259
dreschpe 0:cccc5726bdf3 260
dreschpe 1:aa3356b16080 261
dreschpe 0:cccc5726bdf3 262
dreschpe 0:cccc5726bdf3 263 void SPI_TFT::WindowMax (void) {
dreschpe 0:cccc5726bdf3 264 window (0, 0, width(), height());
dreschpe 0:cccc5726bdf3 265 }
dreschpe 0:cccc5726bdf3 266
dreschpe 0:cccc5726bdf3 267
dreschpe 1:aa3356b16080 268
dreschpe 0:cccc5726bdf3 269 void SPI_TFT::cls (void) {
dreschpe 0:cccc5726bdf3 270 unsigned int i;
dreschpe 0:cccc5726bdf3 271 WindowMax();
dreschpe 0:cccc5726bdf3 272 wr_cmd(0x22);
dreschpe 0:cccc5726bdf3 273 wr_dat_start();
dreschpe 0:cccc5726bdf3 274 _spi.format(16,3); // 16 bit Mode 3
dreschpe 0:cccc5726bdf3 275 for(i = 0; i < ( width() * height()); i++)
dreschpe 0:cccc5726bdf3 276 _spi.write(_background);
dreschpe 0:cccc5726bdf3 277 _spi.format(8,3); // 8 bit Mode 3
dreschpe 0:cccc5726bdf3 278 wr_dat_stop();
dreschpe 0:cccc5726bdf3 279 }
dreschpe 0:cccc5726bdf3 280
dreschpe 0:cccc5726bdf3 281
dreschpe 1:aa3356b16080 282
dreschpe 0:cccc5726bdf3 283 void SPI_TFT::circle(int x0, int y0, int r, int color) {
dreschpe 0:cccc5726bdf3 284
dreschpe 0:cccc5726bdf3 285 int draw_x0, draw_y0;
dreschpe 0:cccc5726bdf3 286 int draw_x1, draw_y1;
dreschpe 0:cccc5726bdf3 287 int draw_x2, draw_y2;
dreschpe 0:cccc5726bdf3 288 int draw_x3, draw_y3;
dreschpe 0:cccc5726bdf3 289 int draw_x4, draw_y4;
dreschpe 0:cccc5726bdf3 290 int draw_x5, draw_y5;
dreschpe 0:cccc5726bdf3 291 int draw_x6, draw_y6;
dreschpe 0:cccc5726bdf3 292 int draw_x7, draw_y7;
dreschpe 0:cccc5726bdf3 293 int xx, yy;
dreschpe 0:cccc5726bdf3 294 int di;
dreschpe 0:cccc5726bdf3 295 WindowMax();
dreschpe 0:cccc5726bdf3 296 if(r == 0) /* no radius */
dreschpe 0:cccc5726bdf3 297 {
dreschpe 0:cccc5726bdf3 298 return;
dreschpe 0:cccc5726bdf3 299 }
dreschpe 0:cccc5726bdf3 300
dreschpe 0:cccc5726bdf3 301 draw_x0 = draw_x1 = x0;
dreschpe 0:cccc5726bdf3 302 draw_y0 = draw_y1 = y0 + r;
dreschpe 0:cccc5726bdf3 303 if(draw_y0 < height())
dreschpe 0:cccc5726bdf3 304 {
dreschpe 0:cccc5726bdf3 305 pixel(draw_x0, draw_y0, color); /* 90 degree */
dreschpe 0:cccc5726bdf3 306 }
dreschpe 0:cccc5726bdf3 307
dreschpe 0:cccc5726bdf3 308 draw_x2 = draw_x3 = x0;
dreschpe 0:cccc5726bdf3 309 draw_y2 = draw_y3 = y0 - r;
dreschpe 0:cccc5726bdf3 310 if(draw_y2 >= 0)
dreschpe 0:cccc5726bdf3 311 {
dreschpe 0:cccc5726bdf3 312 pixel(draw_x2, draw_y2, color); /* 270 degree */
dreschpe 0:cccc5726bdf3 313 }
dreschpe 0:cccc5726bdf3 314
dreschpe 0:cccc5726bdf3 315 draw_x4 = draw_x6 = x0 + r;
dreschpe 0:cccc5726bdf3 316 draw_y4 = draw_y6 = y0;
dreschpe 0:cccc5726bdf3 317 if(draw_x4 < width())
dreschpe 0:cccc5726bdf3 318 {
dreschpe 0:cccc5726bdf3 319 pixel(draw_x4, draw_y4, color); /* 0 degree */
dreschpe 0:cccc5726bdf3 320 }
dreschpe 0:cccc5726bdf3 321
dreschpe 0:cccc5726bdf3 322 draw_x5 = draw_x7 = x0 - r;
dreschpe 0:cccc5726bdf3 323 draw_y5 = draw_y7 = y0;
dreschpe 0:cccc5726bdf3 324 if(draw_x5>=0)
dreschpe 0:cccc5726bdf3 325 {
dreschpe 0:cccc5726bdf3 326 pixel(draw_x5, draw_y5, color); /* 180 degree */
dreschpe 0:cccc5726bdf3 327 }
dreschpe 0:cccc5726bdf3 328
dreschpe 0:cccc5726bdf3 329 if(r == 1)
dreschpe 0:cccc5726bdf3 330 {
dreschpe 0:cccc5726bdf3 331 return;
dreschpe 0:cccc5726bdf3 332 }
dreschpe 0:cccc5726bdf3 333
dreschpe 0:cccc5726bdf3 334 di = 3 - 2*r;
dreschpe 0:cccc5726bdf3 335 xx = 0;
dreschpe 0:cccc5726bdf3 336 yy = r;
dreschpe 0:cccc5726bdf3 337 while(xx < yy)
dreschpe 0:cccc5726bdf3 338 {
dreschpe 0:cccc5726bdf3 339
dreschpe 0:cccc5726bdf3 340 if(di < 0)
dreschpe 0:cccc5726bdf3 341 {
dreschpe 0:cccc5726bdf3 342 di += 4*xx + 6;
dreschpe 0:cccc5726bdf3 343 }
dreschpe 0:cccc5726bdf3 344 else
dreschpe 0:cccc5726bdf3 345 {
dreschpe 0:cccc5726bdf3 346 di += 4*(xx - yy) + 10;
dreschpe 0:cccc5726bdf3 347 yy--;
dreschpe 0:cccc5726bdf3 348 draw_y0--;
dreschpe 0:cccc5726bdf3 349 draw_y1--;
dreschpe 0:cccc5726bdf3 350 draw_y2++;
dreschpe 0:cccc5726bdf3 351 draw_y3++;
dreschpe 0:cccc5726bdf3 352 draw_x4--;
dreschpe 0:cccc5726bdf3 353 draw_x5++;
dreschpe 0:cccc5726bdf3 354 draw_x6--;
dreschpe 0:cccc5726bdf3 355 draw_x7++;
dreschpe 0:cccc5726bdf3 356 }
dreschpe 0:cccc5726bdf3 357 xx++;
dreschpe 0:cccc5726bdf3 358 draw_x0++;
dreschpe 0:cccc5726bdf3 359 draw_x1--;
dreschpe 0:cccc5726bdf3 360 draw_x2++;
dreschpe 0:cccc5726bdf3 361 draw_x3--;
dreschpe 0:cccc5726bdf3 362 draw_y4++;
dreschpe 0:cccc5726bdf3 363 draw_y5++;
dreschpe 0:cccc5726bdf3 364 draw_y6--;
dreschpe 0:cccc5726bdf3 365 draw_y7--;
dreschpe 0:cccc5726bdf3 366
dreschpe 0:cccc5726bdf3 367 if( (draw_x0 <= width()) && (draw_y0>=0) )
dreschpe 0:cccc5726bdf3 368 {
dreschpe 0:cccc5726bdf3 369 pixel(draw_x0, draw_y0, color);
dreschpe 0:cccc5726bdf3 370 }
dreschpe 0:cccc5726bdf3 371
dreschpe 0:cccc5726bdf3 372 if( (draw_x1 >= 0) && (draw_y1 >= 0) )
dreschpe 0:cccc5726bdf3 373 {
dreschpe 0:cccc5726bdf3 374 pixel(draw_x1, draw_y1, color);
dreschpe 0:cccc5726bdf3 375 }
dreschpe 0:cccc5726bdf3 376
dreschpe 0:cccc5726bdf3 377 if( (draw_x2 <= width()) && (draw_y2 <= height()) )
dreschpe 0:cccc5726bdf3 378 {
dreschpe 0:cccc5726bdf3 379 pixel(draw_x2, draw_y2, color);
dreschpe 0:cccc5726bdf3 380 }
dreschpe 0:cccc5726bdf3 381
dreschpe 0:cccc5726bdf3 382 if( (draw_x3 >=0 ) && (draw_y3 <= height()) )
dreschpe 0:cccc5726bdf3 383 {
dreschpe 0:cccc5726bdf3 384 pixel(draw_x3, draw_y3, color);
dreschpe 0:cccc5726bdf3 385 }
dreschpe 0:cccc5726bdf3 386
dreschpe 0:cccc5726bdf3 387 if( (draw_x4 <= width()) && (draw_y4 >= 0) )
dreschpe 0:cccc5726bdf3 388 {
dreschpe 0:cccc5726bdf3 389 pixel(draw_x4, draw_y4, color);
dreschpe 0:cccc5726bdf3 390 }
dreschpe 0:cccc5726bdf3 391
dreschpe 0:cccc5726bdf3 392 if( (draw_x5 >= 0) && (draw_y5 >= 0) )
dreschpe 0:cccc5726bdf3 393 {
dreschpe 0:cccc5726bdf3 394 pixel(draw_x5, draw_y5, color);
dreschpe 0:cccc5726bdf3 395 }
dreschpe 0:cccc5726bdf3 396 if( (draw_x6 <=width()) && (draw_y6 <= height()) )
dreschpe 0:cccc5726bdf3 397 {
dreschpe 0:cccc5726bdf3 398 pixel(draw_x6, draw_y6, color);
dreschpe 0:cccc5726bdf3 399 }
dreschpe 0:cccc5726bdf3 400 if( (draw_x7 >= 0) && (draw_y7 <= height()) )
dreschpe 0:cccc5726bdf3 401 {
dreschpe 0:cccc5726bdf3 402 pixel(draw_x7, draw_y7, color);
dreschpe 0:cccc5726bdf3 403 }
dreschpe 0:cccc5726bdf3 404 }
dreschpe 0:cccc5726bdf3 405 return;
dreschpe 0:cccc5726bdf3 406 }
dreschpe 0:cccc5726bdf3 407
dreschpe 1:aa3356b16080 408
dreschpe 0:cccc5726bdf3 409 void SPI_TFT::hline(int x0, int x1, int y, int color) {
dreschpe 0:cccc5726bdf3 410 int w;
dreschpe 0:cccc5726bdf3 411 w = x1 - x0 + 1;
dreschpe 0:cccc5726bdf3 412 window(x0,y,w,1);
dreschpe 0:cccc5726bdf3 413 wr_cmd(0x22);
dreschpe 0:cccc5726bdf3 414 wr_dat_start();
dreschpe 0:cccc5726bdf3 415 _spi.format(16,3); // pixel are send in 16 bit mode to speed up
dreschpe 0:cccc5726bdf3 416 for(int x=0; x<w; x++){
dreschpe 0:cccc5726bdf3 417 _spi.write(color);
dreschpe 0:cccc5726bdf3 418 }
dreschpe 0:cccc5726bdf3 419 _spi.format(8,3);
dreschpe 0:cccc5726bdf3 420 wr_dat_stop();
dreschpe 0:cccc5726bdf3 421 return;
dreschpe 0:cccc5726bdf3 422 }
dreschpe 0:cccc5726bdf3 423
dreschpe 1:aa3356b16080 424
dreschpe 0:cccc5726bdf3 425
dreschpe 0:cccc5726bdf3 426 void SPI_TFT::vline(int x, int y0, int y1, int color) {
dreschpe 0:cccc5726bdf3 427 int h;
dreschpe 0:cccc5726bdf3 428 h = y1 - y0 + 1;
dreschpe 0:cccc5726bdf3 429 window(x,y0,1,h);
dreschpe 0:cccc5726bdf3 430 wr_cmd(0x22);
dreschpe 0:cccc5726bdf3 431 wr_dat_start();
dreschpe 0:cccc5726bdf3 432 _spi.format(16,3); // pixel are send in 16 bit mode to speed up
dreschpe 0:cccc5726bdf3 433 for(int y=0; y<h; y++){
dreschpe 0:cccc5726bdf3 434 _spi.write(color);
dreschpe 0:cccc5726bdf3 435 }
dreschpe 0:cccc5726bdf3 436 _spi.format(8,3);
dreschpe 0:cccc5726bdf3 437 wr_dat_stop();
dreschpe 0:cccc5726bdf3 438 return;
dreschpe 0:cccc5726bdf3 439 }
dreschpe 0:cccc5726bdf3 440
dreschpe 1:aa3356b16080 441
dreschpe 0:cccc5726bdf3 442
dreschpe 0:cccc5726bdf3 443 void SPI_TFT::line(int x0, int y0, int x1, int y1, int color) {
dreschpe 0:cccc5726bdf3 444 WindowMax();
dreschpe 0:cccc5726bdf3 445 int dx = 0, dy = 0;
dreschpe 0:cccc5726bdf3 446 int dx_sym = 0, dy_sym = 0;
dreschpe 0:cccc5726bdf3 447 int dx_x2 = 0, dy_x2 = 0;
dreschpe 0:cccc5726bdf3 448 int di = 0;
dreschpe 0:cccc5726bdf3 449
dreschpe 0:cccc5726bdf3 450 dx = x1-x0;
dreschpe 0:cccc5726bdf3 451 dy = y1-y0;
dreschpe 0:cccc5726bdf3 452
dreschpe 0:cccc5726bdf3 453 if(dx == 0) /* vertical line */
dreschpe 0:cccc5726bdf3 454 {
dreschpe 0:cccc5726bdf3 455 if(y1 > y0) vline(x0,y0,y1,color);
dreschpe 0:cccc5726bdf3 456 else vline(x0,y1,y0,color);
dreschpe 0:cccc5726bdf3 457 return;
dreschpe 0:cccc5726bdf3 458 }
dreschpe 0:cccc5726bdf3 459
dreschpe 0:cccc5726bdf3 460 if(dx > 0)
dreschpe 0:cccc5726bdf3 461 {
dreschpe 0:cccc5726bdf3 462 dx_sym = 1;
dreschpe 0:cccc5726bdf3 463 }
dreschpe 0:cccc5726bdf3 464 else
dreschpe 0:cccc5726bdf3 465 {
dreschpe 0:cccc5726bdf3 466 dx_sym = -1;
dreschpe 0:cccc5726bdf3 467 }
dreschpe 0:cccc5726bdf3 468 if(dy == 0) /* horizontal line */
dreschpe 0:cccc5726bdf3 469 {
dreschpe 0:cccc5726bdf3 470 if(x1 > x0) hline(x0,x1,y0,color);
dreschpe 0:cccc5726bdf3 471 else hline(x1,x0,y0,color);
dreschpe 0:cccc5726bdf3 472 return;
dreschpe 0:cccc5726bdf3 473 }
dreschpe 0:cccc5726bdf3 474
dreschpe 0:cccc5726bdf3 475 if(dy > 0)
dreschpe 0:cccc5726bdf3 476 {
dreschpe 0:cccc5726bdf3 477 dy_sym = 1;
dreschpe 0:cccc5726bdf3 478 }
dreschpe 0:cccc5726bdf3 479 else
dreschpe 0:cccc5726bdf3 480 {
dreschpe 0:cccc5726bdf3 481 dy_sym = -1;
dreschpe 0:cccc5726bdf3 482 }
dreschpe 0:cccc5726bdf3 483
dreschpe 0:cccc5726bdf3 484 dx = dx_sym*dx;
dreschpe 0:cccc5726bdf3 485 dy = dy_sym*dy;
dreschpe 0:cccc5726bdf3 486
dreschpe 0:cccc5726bdf3 487 dx_x2 = dx*2;
dreschpe 0:cccc5726bdf3 488 dy_x2 = dy*2;
dreschpe 0:cccc5726bdf3 489
dreschpe 0:cccc5726bdf3 490 if(dx >= dy)
dreschpe 0:cccc5726bdf3 491 {
dreschpe 0:cccc5726bdf3 492 di = dy_x2 - dx;
dreschpe 0:cccc5726bdf3 493 while(x0 != x1)
dreschpe 0:cccc5726bdf3 494 {
dreschpe 0:cccc5726bdf3 495
dreschpe 0:cccc5726bdf3 496 pixel(x0, y0, color);
dreschpe 0:cccc5726bdf3 497 x0 += dx_sym;
dreschpe 0:cccc5726bdf3 498 if(di<0)
dreschpe 0:cccc5726bdf3 499 {
dreschpe 0:cccc5726bdf3 500 di += dy_x2;
dreschpe 0:cccc5726bdf3 501 }
dreschpe 0:cccc5726bdf3 502 else
dreschpe 0:cccc5726bdf3 503 {
dreschpe 0:cccc5726bdf3 504 di += dy_x2 - dx_x2;
dreschpe 0:cccc5726bdf3 505 y0 += dy_sym;
dreschpe 0:cccc5726bdf3 506 }
dreschpe 0:cccc5726bdf3 507 }
dreschpe 0:cccc5726bdf3 508 pixel(x0, y0, color);
dreschpe 0:cccc5726bdf3 509 }
dreschpe 0:cccc5726bdf3 510 else
dreschpe 0:cccc5726bdf3 511 {
dreschpe 0:cccc5726bdf3 512 di = dx_x2 - dy;
dreschpe 0:cccc5726bdf3 513 while(y0 != y1)
dreschpe 0:cccc5726bdf3 514 {
dreschpe 0:cccc5726bdf3 515 pixel(x0, y0, color);
dreschpe 0:cccc5726bdf3 516 y0 += dy_sym;
dreschpe 0:cccc5726bdf3 517 if(di < 0)
dreschpe 0:cccc5726bdf3 518 {
dreschpe 0:cccc5726bdf3 519 di += dx_x2;
dreschpe 0:cccc5726bdf3 520 }
dreschpe 0:cccc5726bdf3 521 else
dreschpe 0:cccc5726bdf3 522 {
dreschpe 0:cccc5726bdf3 523 di += dx_x2 - dy_x2;
dreschpe 0:cccc5726bdf3 524 x0 += dx_sym;
dreschpe 0:cccc5726bdf3 525 }
dreschpe 0:cccc5726bdf3 526 }
dreschpe 0:cccc5726bdf3 527 pixel(x0, y0, color);
dreschpe 0:cccc5726bdf3 528 }
dreschpe 0:cccc5726bdf3 529 return;
dreschpe 0:cccc5726bdf3 530 }
dreschpe 0:cccc5726bdf3 531
dreschpe 0:cccc5726bdf3 532
dreschpe 1:aa3356b16080 533
dreschpe 0:cccc5726bdf3 534
dreschpe 0:cccc5726bdf3 535 void SPI_TFT::rect(int x0, int y0, int x1, int y1, int color) {
dreschpe 0:cccc5726bdf3 536
dreschpe 0:cccc5726bdf3 537 if(x1 > x0) hline(x0,x1,y0,color);
dreschpe 0:cccc5726bdf3 538 else hline(x1,x0,y0,color);
dreschpe 0:cccc5726bdf3 539
dreschpe 0:cccc5726bdf3 540 if(y1 > y0) vline(x0,y0,y1,color);
dreschpe 0:cccc5726bdf3 541 else vline(x0,y1,y0,color);
dreschpe 0:cccc5726bdf3 542
dreschpe 0:cccc5726bdf3 543 if(x1 > x0) hline(x0,x1,y1,color);
dreschpe 0:cccc5726bdf3 544 else hline(x1,x0,y1,color);
dreschpe 0:cccc5726bdf3 545
dreschpe 0:cccc5726bdf3 546 if(y1 > y0) vline(x1,y0,y1,color);
dreschpe 0:cccc5726bdf3 547 else vline(x1,y1,y0,color);
dreschpe 0:cccc5726bdf3 548
dreschpe 0:cccc5726bdf3 549 return;
dreschpe 0:cccc5726bdf3 550 }
dreschpe 0:cccc5726bdf3 551
dreschpe 1:aa3356b16080 552
dreschpe 0:cccc5726bdf3 553
dreschpe 0:cccc5726bdf3 554 void SPI_TFT::fillrect(int x0, int y0, int x1, int y1, int color) {
dreschpe 0:cccc5726bdf3 555
dreschpe 0:cccc5726bdf3 556 int h = y1 - y0 + 1;
dreschpe 0:cccc5726bdf3 557 int w = x1 - x0 + 1;
dreschpe 0:cccc5726bdf3 558 int pixel = h * w;
dreschpe 0:cccc5726bdf3 559 window(x0,y0,w,h);
dreschpe 0:cccc5726bdf3 560 wr_cmd(0x22);
dreschpe 0:cccc5726bdf3 561 wr_dat_start();
dreschpe 0:cccc5726bdf3 562 _spi.format(16,3); // pixel are send in 16 bit mode to speed up
dreschpe 0:cccc5726bdf3 563 for(int p=0; p<pixel; p++){
dreschpe 0:cccc5726bdf3 564 _spi.write(color);
dreschpe 0:cccc5726bdf3 565 }
dreschpe 0:cccc5726bdf3 566 _spi.format(8,3);
dreschpe 0:cccc5726bdf3 567 wr_dat_stop();
dreschpe 0:cccc5726bdf3 568 return;
dreschpe 0:cccc5726bdf3 569 }
dreschpe 0:cccc5726bdf3 570
dreschpe 0:cccc5726bdf3 571
dreschpe 1:aa3356b16080 572
dreschpe 0:cccc5726bdf3 573 void SPI_TFT::locate(int column, int row) {
dreschpe 0:cccc5726bdf3 574 _column = column;
dreschpe 0:cccc5726bdf3 575 char_x = font[1] * column; // get the horz. size of the actual font
dreschpe 0:cccc5726bdf3 576 _row = row;
dreschpe 0:cccc5726bdf3 577 }
dreschpe 0:cccc5726bdf3 578
dreschpe 1:aa3356b16080 579
dreschpe 0:cccc5726bdf3 580
dreschpe 0:cccc5726bdf3 581 int SPI_TFT::columns() {
dreschpe 0:cccc5726bdf3 582 return width() / font[1];
dreschpe 0:cccc5726bdf3 583 }
dreschpe 0:cccc5726bdf3 584
dreschpe 1:aa3356b16080 585
dreschpe 0:cccc5726bdf3 586
dreschpe 0:cccc5726bdf3 587 int SPI_TFT::rows() {
dreschpe 0:cccc5726bdf3 588 return height() / font[2];
dreschpe 0:cccc5726bdf3 589 }
dreschpe 0:cccc5726bdf3 590
dreschpe 1:aa3356b16080 591
dreschpe 0:cccc5726bdf3 592
dreschpe 0:cccc5726bdf3 593 int SPI_TFT::_putc(int value) {
dreschpe 0:cccc5726bdf3 594 if(value == '\n') {
dreschpe 0:cccc5726bdf3 595 _column = 0;
dreschpe 0:cccc5726bdf3 596 char_x = 0;
dreschpe 0:cccc5726bdf3 597 _row++;
dreschpe 0:cccc5726bdf3 598 if(_row >= rows()) {
dreschpe 0:cccc5726bdf3 599 _row = 0;
dreschpe 0:cccc5726bdf3 600 }
dreschpe 0:cccc5726bdf3 601 } else {
dreschpe 0:cccc5726bdf3 602 character(_column, _row, value);
dreschpe 0:cccc5726bdf3 603 _column++;
dreschpe 0:cccc5726bdf3 604 }
dreschpe 0:cccc5726bdf3 605 return value;
dreschpe 0:cccc5726bdf3 606 }
dreschpe 0:cccc5726bdf3 607
dreschpe 0:cccc5726bdf3 608
dreschpe 1:aa3356b16080 609
dreschpe 0:cccc5726bdf3 610
dreschpe 0:cccc5726bdf3 611 void SPI_TFT::character(int col, int row, int c){
dreschpe 0:cccc5726bdf3 612 unsigned int hor,vert,offset,bpl,j,i,b;
dreschpe 0:cccc5726bdf3 613 unsigned char* zeichen;
dreschpe 0:cccc5726bdf3 614 unsigned char z,w;
dreschpe 0:cccc5726bdf3 615
dreschpe 0:cccc5726bdf3 616 if((c < 31) || (c > 127)) return; // test char range
dreschpe 0:cccc5726bdf3 617
dreschpe 0:cccc5726bdf3 618 // read font parameter from start of array
dreschpe 0:cccc5726bdf3 619 offset = font[0]; // bytes / char
dreschpe 0:cccc5726bdf3 620 hor = font[1]; // get hor size of font
dreschpe 0:cccc5726bdf3 621 vert = font[2]; // get vert size of font
dreschpe 0:cccc5726bdf3 622 bpl = font[3]; // bytes per line
dreschpe 0:cccc5726bdf3 623
dreschpe 0:cccc5726bdf3 624 if(char_x + hor > width()){
dreschpe 0:cccc5726bdf3 625 char_x = 0;
dreschpe 0:cccc5726bdf3 626 _column = 0;
dreschpe 0:cccc5726bdf3 627 _row ++;
dreschpe 0:cccc5726bdf3 628 row++;
dreschpe 0:cccc5726bdf3 629 if(_row >= rows()) {
dreschpe 0:cccc5726bdf3 630 _row = 0;
dreschpe 0:cccc5726bdf3 631 row=0;
dreschpe 0:cccc5726bdf3 632 }
dreschpe 0:cccc5726bdf3 633 }
dreschpe 0:cccc5726bdf3 634
dreschpe 0:cccc5726bdf3 635 window(char_x, row * vert,hor,vert); // char box
dreschpe 0:cccc5726bdf3 636 wr_cmd(0x22);
dreschpe 0:cccc5726bdf3 637 wr_dat_start();
dreschpe 0:cccc5726bdf3 638 zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
dreschpe 0:cccc5726bdf3 639 w = zeichen[0]; // width of actual char
dreschpe 0:cccc5726bdf3 640 _spi.format(16,3); // pixel are 16 bit
dreschpe 0:cccc5726bdf3 641
dreschpe 0:cccc5726bdf3 642 for(j=0;j<vert;j++){ // vert line
dreschpe 0:cccc5726bdf3 643 for(i=0;i<hor;i++){ // horz line
dreschpe 0:cccc5726bdf3 644 z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
dreschpe 0:cccc5726bdf3 645 b = 1 << (j & 0x07);
dreschpe 0:cccc5726bdf3 646 if (( z & b ) == 0x00){
dreschpe 0:cccc5726bdf3 647 _spi.write(_background);
dreschpe 0:cccc5726bdf3 648 }
dreschpe 0:cccc5726bdf3 649 else {
dreschpe 0:cccc5726bdf3 650 _spi.write(_foreground);
dreschpe 0:cccc5726bdf3 651 }
dreschpe 0:cccc5726bdf3 652 }
dreschpe 0:cccc5726bdf3 653 }
dreschpe 0:cccc5726bdf3 654 _spi.format(8,3); // 8 bit
dreschpe 0:cccc5726bdf3 655 wr_dat_stop();
dreschpe 0:cccc5726bdf3 656 if ((w + 2) < hor) { // x offset to next char
dreschpe 0:cccc5726bdf3 657 char_x += w + 2;
dreschpe 0:cccc5726bdf3 658 }
dreschpe 0:cccc5726bdf3 659 else char_x += hor;
dreschpe 0:cccc5726bdf3 660 }
dreschpe 0:cccc5726bdf3 661
dreschpe 0:cccc5726bdf3 662
dreschpe 1:aa3356b16080 663
dreschpe 0:cccc5726bdf3 664
dreschpe 0:cccc5726bdf3 665
dreschpe 0:cccc5726bdf3 666 void SPI_TFT::set_font(unsigned char* f){
dreschpe 0:cccc5726bdf3 667 font = f;
dreschpe 0:cccc5726bdf3 668 }
dreschpe 0:cccc5726bdf3 669
dreschpe 1:aa3356b16080 670
dreschpe 0:cccc5726bdf3 671
dreschpe 0:cccc5726bdf3 672 void SPI_TFT::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap){
dreschpe 0:cccc5726bdf3 673 unsigned int i,j;
dreschpe 0:cccc5726bdf3 674 unsigned short *bitmap_ptr = (unsigned short *)bitmap;
dreschpe 0:cccc5726bdf3 675 window(x, y, w, h);
dreschpe 0:cccc5726bdf3 676 wr_cmd(0x22);
dreschpe 0:cccc5726bdf3 677 wr_dat_start();
dreschpe 0:cccc5726bdf3 678 _spi.format(16,3);
dreschpe 0:cccc5726bdf3 679 bitmap_ptr += ((h - 1)*w);
dreschpe 0:cccc5726bdf3 680 for (j = 0; j < h; j++){ //Lines
dreschpe 0:cccc5726bdf3 681 for (i = 0; i < w; i++) { // copy pixel data to TFT
dreschpe 0:cccc5726bdf3 682 _spi.write(*bitmap_ptr); // one line
dreschpe 0:cccc5726bdf3 683 bitmap_ptr++;
dreschpe 0:cccc5726bdf3 684 }
dreschpe 0:cccc5726bdf3 685 bitmap_ptr -= 2*w;
dreschpe 0:cccc5726bdf3 686 }
dreschpe 0:cccc5726bdf3 687 _spi.format(8,3);
dreschpe 0:cccc5726bdf3 688 wr_dat_stop();
dreschpe 0:cccc5726bdf3 689 }