A program to display an image on the uLCD-32PT display by 4D Systems

Dependencies:   mbed

Committer:
ms523
Date:
Sun Oct 03 15:47:25 2010 +0000
Revision:
0:fc4f3879f0e1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ms523 0:fc4f3879f0e1 1 //
ms523 0:fc4f3879f0e1 2 // TFT_4DGL is a class to drive 4D Systems TFT touch screens
ms523 0:fc4f3879f0e1 3 //
ms523 0:fc4f3879f0e1 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
ms523 0:fc4f3879f0e1 5 //
ms523 0:fc4f3879f0e1 6 // TFT_4DGL is free software: you can redistribute it and/or modify
ms523 0:fc4f3879f0e1 7 // it under the terms of the GNU General Public License as published by
ms523 0:fc4f3879f0e1 8 // the Free Software Foundation, either version 3 of the License, or
ms523 0:fc4f3879f0e1 9 // (at your option) any later version.
ms523 0:fc4f3879f0e1 10 //
ms523 0:fc4f3879f0e1 11 // TFT_4DGL is distributed in the hope that it will be useful,
ms523 0:fc4f3879f0e1 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
ms523 0:fc4f3879f0e1 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ms523 0:fc4f3879f0e1 14 // GNU General Public License for more details.
ms523 0:fc4f3879f0e1 15 //
ms523 0:fc4f3879f0e1 16 // You should have received a copy of the GNU General Public License
ms523 0:fc4f3879f0e1 17 // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
ms523 0:fc4f3879f0e1 18
ms523 0:fc4f3879f0e1 19 #include "mbed.h"
ms523 0:fc4f3879f0e1 20 #include "TFT_4DGL.h"
ms523 0:fc4f3879f0e1 21
ms523 0:fc4f3879f0e1 22
ms523 0:fc4f3879f0e1 23 //****************************************************************************************************
ms523 0:fc4f3879f0e1 24 void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y)
ms523 0:fc4f3879f0e1 25 char command[9]= "";
ms523 0:fc4f3879f0e1 26
ms523 0:fc4f3879f0e1 27 command[0] = CIRCLE;
ms523 0:fc4f3879f0e1 28
ms523 0:fc4f3879f0e1 29 command[1] = (x >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 30 command[2] = x & 0xFF;
ms523 0:fc4f3879f0e1 31
ms523 0:fc4f3879f0e1 32 command[3] = (y >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 33 command[4] = y & 0xFF;
ms523 0:fc4f3879f0e1 34
ms523 0:fc4f3879f0e1 35 command[5] = (radius >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 36 command[6] = radius & 0xFF;
ms523 0:fc4f3879f0e1 37
ms523 0:fc4f3879f0e1 38 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ms523 0:fc4f3879f0e1 39 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ms523 0:fc4f3879f0e1 40 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ms523 0:fc4f3879f0e1 41
ms523 0:fc4f3879f0e1 42 command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ms523 0:fc4f3879f0e1 43 command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ms523 0:fc4f3879f0e1 44
ms523 0:fc4f3879f0e1 45 writeCOMMAND(command, 9);
ms523 0:fc4f3879f0e1 46 }
ms523 0:fc4f3879f0e1 47
ms523 0:fc4f3879f0e1 48 //****************************************************************************************************
ms523 0:fc4f3879f0e1 49 void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle
ms523 0:fc4f3879f0e1 50 char command[15]= "";
ms523 0:fc4f3879f0e1 51
ms523 0:fc4f3879f0e1 52 command[0] = TRIANGLE;
ms523 0:fc4f3879f0e1 53
ms523 0:fc4f3879f0e1 54 command[1] = (x1 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 55 command[2] = x1 & 0xFF;
ms523 0:fc4f3879f0e1 56
ms523 0:fc4f3879f0e1 57 command[3] = (y1 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 58 command[4] = y1 & 0xFF;
ms523 0:fc4f3879f0e1 59
ms523 0:fc4f3879f0e1 60 command[5] = (x2 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 61 command[6] = x2 & 0xFF;
ms523 0:fc4f3879f0e1 62
ms523 0:fc4f3879f0e1 63 command[7] = (y2 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 64 command[8] = y2 & 0xFF;
ms523 0:fc4f3879f0e1 65
ms523 0:fc4f3879f0e1 66 command[9] = (x3 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 67 command[10] = x3 & 0xFF;
ms523 0:fc4f3879f0e1 68
ms523 0:fc4f3879f0e1 69 command[11] = (y3 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 70 command[12] = y3 & 0xFF;
ms523 0:fc4f3879f0e1 71
ms523 0:fc4f3879f0e1 72 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ms523 0:fc4f3879f0e1 73 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ms523 0:fc4f3879f0e1 74 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ms523 0:fc4f3879f0e1 75
ms523 0:fc4f3879f0e1 76 command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ms523 0:fc4f3879f0e1 77 command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ms523 0:fc4f3879f0e1 78
ms523 0:fc4f3879f0e1 79 writeCOMMAND(command, 15);
ms523 0:fc4f3879f0e1 80 }
ms523 0:fc4f3879f0e1 81
ms523 0:fc4f3879f0e1 82 //****************************************************************************************************
ms523 0:fc4f3879f0e1 83 void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line
ms523 0:fc4f3879f0e1 84 char command[11]= "";
ms523 0:fc4f3879f0e1 85
ms523 0:fc4f3879f0e1 86 command[0] = LINE;
ms523 0:fc4f3879f0e1 87
ms523 0:fc4f3879f0e1 88 command[1] = (x1 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 89 command[2] = x1 & 0xFF;
ms523 0:fc4f3879f0e1 90
ms523 0:fc4f3879f0e1 91 command[3] = (y1 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 92 command[4] = y1 & 0xFF;
ms523 0:fc4f3879f0e1 93
ms523 0:fc4f3879f0e1 94 command[5] = (x2 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 95 command[6] = x2 & 0xFF;
ms523 0:fc4f3879f0e1 96
ms523 0:fc4f3879f0e1 97 command[7] = (y2 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 98 command[8] = y2 & 0xFF;
ms523 0:fc4f3879f0e1 99
ms523 0:fc4f3879f0e1 100 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ms523 0:fc4f3879f0e1 101 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ms523 0:fc4f3879f0e1 102 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ms523 0:fc4f3879f0e1 103
ms523 0:fc4f3879f0e1 104 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ms523 0:fc4f3879f0e1 105 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ms523 0:fc4f3879f0e1 106
ms523 0:fc4f3879f0e1 107 writeCOMMAND(command, 11);
ms523 0:fc4f3879f0e1 108 }
ms523 0:fc4f3879f0e1 109
ms523 0:fc4f3879f0e1 110 //****************************************************************************************************
ms523 0:fc4f3879f0e1 111 void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle
ms523 0:fc4f3879f0e1 112 char command[11]= "";
ms523 0:fc4f3879f0e1 113
ms523 0:fc4f3879f0e1 114 command[0] = RECTANGLE;
ms523 0:fc4f3879f0e1 115
ms523 0:fc4f3879f0e1 116 command[1] = (x1 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 117 command[2] = x1 & 0xFF;
ms523 0:fc4f3879f0e1 118
ms523 0:fc4f3879f0e1 119 command[3] = (y1 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 120 command[4] = y1 & 0xFF;
ms523 0:fc4f3879f0e1 121
ms523 0:fc4f3879f0e1 122 command[5] = (x2 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 123 command[6] = x2 & 0xFF;
ms523 0:fc4f3879f0e1 124
ms523 0:fc4f3879f0e1 125 command[7] = (y2 >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 126 command[8] = y2 & 0xFF;
ms523 0:fc4f3879f0e1 127
ms523 0:fc4f3879f0e1 128 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ms523 0:fc4f3879f0e1 129 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ms523 0:fc4f3879f0e1 130 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ms523 0:fc4f3879f0e1 131
ms523 0:fc4f3879f0e1 132 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ms523 0:fc4f3879f0e1 133 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ms523 0:fc4f3879f0e1 134
ms523 0:fc4f3879f0e1 135 writeCOMMAND(command, 11);
ms523 0:fc4f3879f0e1 136 }
ms523 0:fc4f3879f0e1 137
ms523 0:fc4f3879f0e1 138 //****************************************************************************************************
ms523 0:fc4f3879f0e1 139 void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse
ms523 0:fc4f3879f0e1 140 char command[11]= "";
ms523 0:fc4f3879f0e1 141
ms523 0:fc4f3879f0e1 142 command[0] = ELLIPSE;
ms523 0:fc4f3879f0e1 143
ms523 0:fc4f3879f0e1 144 command[1] = (x >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 145 command[2] = x & 0xFF;
ms523 0:fc4f3879f0e1 146
ms523 0:fc4f3879f0e1 147 command[3] = (y >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 148 command[4] = y & 0xFF;
ms523 0:fc4f3879f0e1 149
ms523 0:fc4f3879f0e1 150 command[5] = (radius_x >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 151 command[6] = radius_x & 0xFF;
ms523 0:fc4f3879f0e1 152
ms523 0:fc4f3879f0e1 153 command[7] = (radius_y >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 154 command[8] = radius_y & 0xFF;
ms523 0:fc4f3879f0e1 155
ms523 0:fc4f3879f0e1 156 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ms523 0:fc4f3879f0e1 157 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ms523 0:fc4f3879f0e1 158 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ms523 0:fc4f3879f0e1 159
ms523 0:fc4f3879f0e1 160 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ms523 0:fc4f3879f0e1 161 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ms523 0:fc4f3879f0e1 162
ms523 0:fc4f3879f0e1 163 writeCOMMAND(command, 11);
ms523 0:fc4f3879f0e1 164 }
ms523 0:fc4f3879f0e1 165
ms523 0:fc4f3879f0e1 166 //****************************************************************************************************
ms523 0:fc4f3879f0e1 167 void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel
ms523 0:fc4f3879f0e1 168 char command[7]= "";
ms523 0:fc4f3879f0e1 169
ms523 0:fc4f3879f0e1 170 command[0] = PIXEL;
ms523 0:fc4f3879f0e1 171
ms523 0:fc4f3879f0e1 172 command[1] = (x >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 173 command[2] = x & 0xFF;
ms523 0:fc4f3879f0e1 174
ms523 0:fc4f3879f0e1 175 command[3] = (y >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 176 command[4] = y & 0xFF;
ms523 0:fc4f3879f0e1 177
ms523 0:fc4f3879f0e1 178 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ms523 0:fc4f3879f0e1 179 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ms523 0:fc4f3879f0e1 180 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ms523 0:fc4f3879f0e1 181
ms523 0:fc4f3879f0e1 182 command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ms523 0:fc4f3879f0e1 183 command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ms523 0:fc4f3879f0e1 184
ms523 0:fc4f3879f0e1 185 writeCOMMAND(command, 7);
ms523 0:fc4f3879f0e1 186 }
ms523 0:fc4f3879f0e1 187
ms523 0:fc4f3879f0e1 188 //******************************************************************************************************
ms523 0:fc4f3879f0e1 189 int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data
ms523 0:fc4f3879f0e1 190
ms523 0:fc4f3879f0e1 191 char command[5]= "";
ms523 0:fc4f3879f0e1 192
ms523 0:fc4f3879f0e1 193 command[0] = READPIXEL;
ms523 0:fc4f3879f0e1 194
ms523 0:fc4f3879f0e1 195 command[1] = (x >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 196 command[2] = x & 0xFF;
ms523 0:fc4f3879f0e1 197
ms523 0:fc4f3879f0e1 198 command[3] = (y >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 199 command[4] = y & 0xFF;
ms523 0:fc4f3879f0e1 200
ms523 0:fc4f3879f0e1 201 int i, temp = 0, color = 0, resp = 0;
ms523 0:fc4f3879f0e1 202 char response[2] = "";
ms523 0:fc4f3879f0e1 203
ms523 0:fc4f3879f0e1 204 freeBUFFER();
ms523 0:fc4f3879f0e1 205
ms523 0:fc4f3879f0e1 206 for (i = 0; i < 5; i++) { // send all chars to serial port
ms523 0:fc4f3879f0e1 207 writeBYTE(command[i]);
ms523 0:fc4f3879f0e1 208 }
ms523 0:fc4f3879f0e1 209
ms523 0:fc4f3879f0e1 210 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
ms523 0:fc4f3879f0e1 211
ms523 0:fc4f3879f0e1 212 while (_cmd.readable()) {
ms523 0:fc4f3879f0e1 213 temp = _cmd.getc();
ms523 0:fc4f3879f0e1 214 response[resp++] = (char)temp;
ms523 0:fc4f3879f0e1 215 }
ms523 0:fc4f3879f0e1 216
ms523 0:fc4f3879f0e1 217 color = ((response[0] << 8) + response[1]);
ms523 0:fc4f3879f0e1 218
ms523 0:fc4f3879f0e1 219 return color; // WARNING : this is 16bits color, not 24bits... need to be fixed
ms523 0:fc4f3879f0e1 220 }
ms523 0:fc4f3879f0e1 221
ms523 0:fc4f3879f0e1 222 //******************************************************************************************************
ms523 0:fc4f3879f0e1 223 void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) {
ms523 0:fc4f3879f0e1 224
ms523 0:fc4f3879f0e1 225 char command[13]= "";
ms523 0:fc4f3879f0e1 226
ms523 0:fc4f3879f0e1 227 command[0] = SCREENCOPY;
ms523 0:fc4f3879f0e1 228
ms523 0:fc4f3879f0e1 229 command[1] = (xs >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 230 command[2] = xs & 0xFF;
ms523 0:fc4f3879f0e1 231
ms523 0:fc4f3879f0e1 232 command[3] = (ys >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 233 command[4] = ys & 0xFF;
ms523 0:fc4f3879f0e1 234
ms523 0:fc4f3879f0e1 235 command[5] = (xd >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 236 command[6] = xd & 0xFF;
ms523 0:fc4f3879f0e1 237
ms523 0:fc4f3879f0e1 238 command[7] = (yd >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 239 command[8] = yd & 0xFF;
ms523 0:fc4f3879f0e1 240
ms523 0:fc4f3879f0e1 241 command[9] = (width >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 242 command[10] = width & 0xFF;
ms523 0:fc4f3879f0e1 243
ms523 0:fc4f3879f0e1 244 command[11] = (height >> 8) & 0xFF;
ms523 0:fc4f3879f0e1 245 command[12] = height & 0xFF;
ms523 0:fc4f3879f0e1 246
ms523 0:fc4f3879f0e1 247 writeCOMMAND(command, 13);
ms523 0:fc4f3879f0e1 248 }
ms523 0:fc4f3879f0e1 249
ms523 0:fc4f3879f0e1 250 //****************************************************************************************************
ms523 0:fc4f3879f0e1 251 void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME
ms523 0:fc4f3879f0e1 252 char command[2]= "";
ms523 0:fc4f3879f0e1 253
ms523 0:fc4f3879f0e1 254 command[0] = PENSIZE;
ms523 0:fc4f3879f0e1 255 command[1] = mode;
ms523 0:fc4f3879f0e1 256
ms523 0:fc4f3879f0e1 257 writeCOMMAND(command, 2);
ms523 0:fc4f3879f0e1 258 }
ms523 0:fc4f3879f0e1 259
ms523 0:fc4f3879f0e1 260 //****************************************************************************************************
ms523 0:fc4f3879f0e1 261 // This plays a .wav file from the FAT partition of an uSD Card
ms523 0:fc4f3879f0e1 262 // Not really recommended as the speaker on the uLCD-32PT is really bad!
ms523 0:fc4f3879f0e1 263 //****************************************************************************************************
ms523 0:fc4f3879f0e1 264 void TFT_4DGL :: SD_Card_Wav(char *Filename) {
ms523 0:fc4f3879f0e1 265 char command[21]= "";
ms523 0:fc4f3879f0e1 266 int Lgt=0;
ms523 0:fc4f3879f0e1 267
ms523 0:fc4f3879f0e1 268 command[0] = 0x40; //ext_cmd
ms523 0:fc4f3879f0e1 269 command[1] = 0x6C; //Play Audio
ms523 0:fc4f3879f0e1 270 command[2] = 0x01; //Option 0x00=Return at end, 0x01=Return now, 0x02=Stop, 0x03=Pause, 0x04=Resume, 0x05=Loop.
ms523 0:fc4f3879f0e1 271 for(int i=0;Filename[i]!=0x00;i++){
ms523 0:fc4f3879f0e1 272 command[i+3] = Filename[i];
ms523 0:fc4f3879f0e1 273 Lgt = i;
ms523 0:fc4f3879f0e1 274 }
ms523 0:fc4f3879f0e1 275 command[Lgt+4] = 0x2E; //.
ms523 0:fc4f3879f0e1 276 command[Lgt+5] = 0x77; //w
ms523 0:fc4f3879f0e1 277 command[Lgt+6] = 0x61; //a
ms523 0:fc4f3879f0e1 278 command[Lgt+7] = 0x76; //v
ms523 0:fc4f3879f0e1 279 command[Lgt+8] = 0x00; //terminator
ms523 0:fc4f3879f0e1 280
ms523 0:fc4f3879f0e1 281 writeCOMMAND(command, Lgt+9);
ms523 0:fc4f3879f0e1 282 }
ms523 0:fc4f3879f0e1 283
ms523 0:fc4f3879f0e1 284 //****************************************************************************************************
ms523 0:fc4f3879f0e1 285 // This sets the volume for the speaker on the uLCD-32PT
ms523 0:fc4f3879f0e1 286 //****************************************************************************************************
ms523 0:fc4f3879f0e1 287 void TFT_4DGL :: Set_Volume(char vol) {
ms523 0:fc4f3879f0e1 288
ms523 0:fc4f3879f0e1 289 char command[2]= "";
ms523 0:fc4f3879f0e1 290
ms523 0:fc4f3879f0e1 291 command[0] = 0x76; //cmd
ms523 0:fc4f3879f0e1 292 command[1] = vol; //set volume
ms523 0:fc4f3879f0e1 293
ms523 0:fc4f3879f0e1 294 writeCOMMAND(command, 2);
ms523 0:fc4f3879f0e1 295 }
ms523 0:fc4f3879f0e1 296
ms523 0:fc4f3879f0e1 297 //****************************************************************************************************
ms523 0:fc4f3879f0e1 298 // This displays an image on the screen that is stored on the FAT partition of an uSD Card
ms523 0:fc4f3879f0e1 299 // Sent Filename, X-pos, Y-pos, Sector Address - Display from the RAW partition is quicker
ms523 0:fc4f3879f0e1 300 //****************************************************************************************************
ms523 0:fc4f3879f0e1 301 void TFT_4DGL :: uSD_FAT_Image(char *Filename, int x, int y, long s) {
ms523 0:fc4f3879f0e1 302 char X_MSB, X_LSB, Y_MSB, Y_LSB, S0, S1, S2, S3;
ms523 0:fc4f3879f0e1 303 char command[25]= "";
ms523 0:fc4f3879f0e1 304 int Lgt=0;
ms523 0:fc4f3879f0e1 305
ms523 0:fc4f3879f0e1 306 X_LSB = x&0x00FF;
ms523 0:fc4f3879f0e1 307 X_MSB = (x >> 8);
ms523 0:fc4f3879f0e1 308 Y_LSB = y&0x00FF;
ms523 0:fc4f3879f0e1 309 Y_MSB = (y >> 8);
ms523 0:fc4f3879f0e1 310
ms523 0:fc4f3879f0e1 311 S0 = (s >> 20)&0x000000FF;
ms523 0:fc4f3879f0e1 312 S1 = (s >> 16)&0x0000FF;
ms523 0:fc4f3879f0e1 313 S2 = (s >> 8)&0x0000FF;
ms523 0:fc4f3879f0e1 314 S3 = s&0x0000FF;;
ms523 0:fc4f3879f0e1 315
ms523 0:fc4f3879f0e1 316 command[0] = '@'; //ext_cmd
ms523 0:fc4f3879f0e1 317 command[1] = 'm'; //FAT Image
ms523 0:fc4f3879f0e1 318 for(int i=0;Filename[i]!=0x00;i++){
ms523 0:fc4f3879f0e1 319 command[i+2] = Filename[i];
ms523 0:fc4f3879f0e1 320 Lgt = i;
ms523 0:fc4f3879f0e1 321 }
ms523 0:fc4f3879f0e1 322 command[Lgt+3] = '.'; //.
ms523 0:fc4f3879f0e1 323 command[Lgt+4] = 'G'; //G
ms523 0:fc4f3879f0e1 324 command[Lgt+5] = 'C'; //C
ms523 0:fc4f3879f0e1 325 command[Lgt+6] = 'I'; //I
ms523 0:fc4f3879f0e1 326 command[Lgt+7] = 0x00; //Terminator
ms523 0:fc4f3879f0e1 327 command[Lgt+8] = X_MSB; //X-Position MSB
ms523 0:fc4f3879f0e1 328 command[Lgt+9] = X_LSB; //X-Position LSB
ms523 0:fc4f3879f0e1 329 command[Lgt+10] = Y_MSB; //Y-Position MSB
ms523 0:fc4f3879f0e1 330 command[Lgt+11] = Y_LSB; //Y-Position LSB
ms523 0:fc4f3879f0e1 331 command[Lgt+12] = S0; //Sector Address 4 bytes
ms523 0:fc4f3879f0e1 332 command[Lgt+13] = S1;
ms523 0:fc4f3879f0e1 333 command[Lgt+14] = S2;
ms523 0:fc4f3879f0e1 334 command[Lgt+15] = S3;
ms523 0:fc4f3879f0e1 335
ms523 0:fc4f3879f0e1 336 writeCOMMAND(command, Lgt+16);
ms523 0:fc4f3879f0e1 337 }
ms523 0:fc4f3879f0e1 338
ms523 0:fc4f3879f0e1 339 //****************************************************************************************************
ms523 0:fc4f3879f0e1 340 // This displays an image on the screen in the NEW FORMAT
ms523 0:fc4f3879f0e1 341 // Sent X-pos, Y-pos, Sector Address - This is the recommended way to display images
ms523 0:fc4f3879f0e1 342 //****************************************************************************************************
ms523 0:fc4f3879f0e1 343 void TFT_4DGL :: uSD_Image(int x, int y, long s) {
ms523 0:fc4f3879f0e1 344 char S1, S2, S3;
ms523 0:fc4f3879f0e1 345 char X_MSB, X_LSB, Y_MSB, Y_LSB;
ms523 0:fc4f3879f0e1 346 char command[9]= "";
ms523 0:fc4f3879f0e1 347
ms523 0:fc4f3879f0e1 348 X_LSB = x&0x00FF; //Work out the x position
ms523 0:fc4f3879f0e1 349 X_MSB = (x >> 8);
ms523 0:fc4f3879f0e1 350 Y_LSB = y&0x00FF; //Work out the y position
ms523 0:fc4f3879f0e1 351 Y_MSB = (y >> 8);
ms523 0:fc4f3879f0e1 352
ms523 0:fc4f3879f0e1 353 S1 = (s >> 16)&0x0000FF; //Work out the sector address
ms523 0:fc4f3879f0e1 354 S2 = (s >> 8)&0x0000FF;
ms523 0:fc4f3879f0e1 355 S3 = s&0x0000FF;
ms523 0:fc4f3879f0e1 356
ms523 0:fc4f3879f0e1 357 command[0] = 0x40; //ext_cmd
ms523 0:fc4f3879f0e1 358 command[1] = 0x49; //Display image
ms523 0:fc4f3879f0e1 359 command[2] = X_MSB; //X position - 2 bytes
ms523 0:fc4f3879f0e1 360 command[3] = X_LSB;
ms523 0:fc4f3879f0e1 361 command[4] = Y_MSB; //Y position - 2 bytes
ms523 0:fc4f3879f0e1 362 command[5] = Y_LSB;
ms523 0:fc4f3879f0e1 363 command[6] = S1; //Sector address - 3 bytes
ms523 0:fc4f3879f0e1 364 command[7] = S2;
ms523 0:fc4f3879f0e1 365 command[8] = S3;
ms523 0:fc4f3879f0e1 366
ms523 0:fc4f3879f0e1 367 writeCOMMAND(command, 9);
ms523 0:fc4f3879f0e1 368 }
ms523 0:fc4f3879f0e1 369
ms523 0:fc4f3879f0e1 370 //****************************************************************************************************
ms523 0:fc4f3879f0e1 371 // This displays an video on the screen in the NEW FORMAT
ms523 0:fc4f3879f0e1 372 // Sent X-pos, Y-pos, Sector Address - This is the recommended way to display video
ms523 0:fc4f3879f0e1 373 //****************************************************************************************************
ms523 0:fc4f3879f0e1 374 void TFT_4DGL :: uSD_Video(int x, int y, long s) {
ms523 0:fc4f3879f0e1 375 char S1, S2, S3;
ms523 0:fc4f3879f0e1 376 char X_MSB, X_LSB, Y_MSB, Y_LSB;
ms523 0:fc4f3879f0e1 377 char command[10]= "";
ms523 0:fc4f3879f0e1 378
ms523 0:fc4f3879f0e1 379 X_LSB = x&0x00FF;
ms523 0:fc4f3879f0e1 380 X_MSB = (x >> 8);
ms523 0:fc4f3879f0e1 381 Y_LSB = y&0x00FF;
ms523 0:fc4f3879f0e1 382 Y_MSB = (y >> 8);
ms523 0:fc4f3879f0e1 383
ms523 0:fc4f3879f0e1 384 S1 = (s >> 16)&0x0000FF;
ms523 0:fc4f3879f0e1 385 S2 = (s >> 8)&0x0000FF;
ms523 0:fc4f3879f0e1 386 S3 = s&0x0000FF;
ms523 0:fc4f3879f0e1 387
ms523 0:fc4f3879f0e1 388 command[0] = 0x40; //ext_cmd
ms523 0:fc4f3879f0e1 389 command[1] = 0x56; //Display video
ms523 0:fc4f3879f0e1 390 command[2] = X_MSB; //X position - 2 bytes
ms523 0:fc4f3879f0e1 391 command[3] = X_LSB;
ms523 0:fc4f3879f0e1 392 command[4] = Y_MSB; //Y position - 2 bytes
ms523 0:fc4f3879f0e1 393 command[5] = Y_LSB;
ms523 0:fc4f3879f0e1 394 command[6] = 0x00; //delay between frames
ms523 0:fc4f3879f0e1 395 command[7] = S1; //Sector address - 3 bytes
ms523 0:fc4f3879f0e1 396 command[8] = S2;
ms523 0:fc4f3879f0e1 397 command[9] = S3;
ms523 0:fc4f3879f0e1 398
ms523 0:fc4f3879f0e1 399 writeCOMMAND(command, 10);
ms523 0:fc4f3879f0e1 400 }