a version of 4DGL with a minor change for the uVGAII 640 by 480 res

Committer:
4180_1
Date:
Thu Feb 24 15:14:36 2011 +0000
Revision:
0:e25ba425dc7b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:e25ba425dc7b 1 //
4180_1 0:e25ba425dc7b 2 // TFT_4DGL is a class to drive 4D Systems TFT touch screens
4180_1 0:e25ba425dc7b 3 //
4180_1 0:e25ba425dc7b 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
4180_1 0:e25ba425dc7b 5 //
4180_1 0:e25ba425dc7b 6 // TFT_4DGL is free software: you can redistribute it and/or modify
4180_1 0:e25ba425dc7b 7 // it under the terms of the GNU General Public License as published by
4180_1 0:e25ba425dc7b 8 // the Free Software Foundation, either version 3 of the License, or
4180_1 0:e25ba425dc7b 9 // (at your option) any later version.
4180_1 0:e25ba425dc7b 10 //
4180_1 0:e25ba425dc7b 11 // TFT_4DGL is distributed in the hope that it will be useful,
4180_1 0:e25ba425dc7b 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
4180_1 0:e25ba425dc7b 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4180_1 0:e25ba425dc7b 14 // GNU General Public License for more details.
4180_1 0:e25ba425dc7b 15 //
4180_1 0:e25ba425dc7b 16 // You should have received a copy of the GNU General Public License
4180_1 0:e25ba425dc7b 17 // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
4180_1 0:e25ba425dc7b 18
4180_1 0:e25ba425dc7b 19 #include "mbed.h"
4180_1 0:e25ba425dc7b 20 #include "TFT_4DGL.h"
4180_1 0:e25ba425dc7b 21
4180_1 0:e25ba425dc7b 22
4180_1 0:e25ba425dc7b 23 //****************************************************************************************************
4180_1 0:e25ba425dc7b 24 void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y)
4180_1 0:e25ba425dc7b 25 char command[9]= "";
4180_1 0:e25ba425dc7b 26
4180_1 0:e25ba425dc7b 27 command[0] = CIRCLE;
4180_1 0:e25ba425dc7b 28
4180_1 0:e25ba425dc7b 29 command[1] = (x >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 30 command[2] = x & 0xFF;
4180_1 0:e25ba425dc7b 31
4180_1 0:e25ba425dc7b 32 command[3] = (y >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 33 command[4] = y & 0xFF;
4180_1 0:e25ba425dc7b 34
4180_1 0:e25ba425dc7b 35 command[5] = (radius >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 36 command[6] = radius & 0xFF;
4180_1 0:e25ba425dc7b 37
4180_1 0:e25ba425dc7b 38 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 39 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 40 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 41
4180_1 0:e25ba425dc7b 42 command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 43 command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 44
4180_1 0:e25ba425dc7b 45 writeCOMMAND(command, 9);
4180_1 0:e25ba425dc7b 46 }
4180_1 0:e25ba425dc7b 47
4180_1 0:e25ba425dc7b 48 //****************************************************************************************************
4180_1 0:e25ba425dc7b 49 void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle
4180_1 0:e25ba425dc7b 50 char command[15]= "";
4180_1 0:e25ba425dc7b 51
4180_1 0:e25ba425dc7b 52 command[0] = TRIANGLE;
4180_1 0:e25ba425dc7b 53
4180_1 0:e25ba425dc7b 54 command[1] = (x1 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 55 command[2] = x1 & 0xFF;
4180_1 0:e25ba425dc7b 56
4180_1 0:e25ba425dc7b 57 command[3] = (y1 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 58 command[4] = y1 & 0xFF;
4180_1 0:e25ba425dc7b 59
4180_1 0:e25ba425dc7b 60 command[5] = (x2 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 61 command[6] = x2 & 0xFF;
4180_1 0:e25ba425dc7b 62
4180_1 0:e25ba425dc7b 63 command[7] = (y2 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 64 command[8] = y2 & 0xFF;
4180_1 0:e25ba425dc7b 65
4180_1 0:e25ba425dc7b 66 command[9] = (x3 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 67 command[10] = x3 & 0xFF;
4180_1 0:e25ba425dc7b 68
4180_1 0:e25ba425dc7b 69 command[11] = (y3 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 70 command[12] = y3 & 0xFF;
4180_1 0:e25ba425dc7b 71
4180_1 0:e25ba425dc7b 72 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 73 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 74 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 75
4180_1 0:e25ba425dc7b 76 command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 77 command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 78
4180_1 0:e25ba425dc7b 79 writeCOMMAND(command, 15);
4180_1 0:e25ba425dc7b 80 }
4180_1 0:e25ba425dc7b 81
4180_1 0:e25ba425dc7b 82 //****************************************************************************************************
4180_1 0:e25ba425dc7b 83 void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line
4180_1 0:e25ba425dc7b 84 char command[11]= "";
4180_1 0:e25ba425dc7b 85
4180_1 0:e25ba425dc7b 86 command[0] = LINE;
4180_1 0:e25ba425dc7b 87
4180_1 0:e25ba425dc7b 88 command[1] = (x1 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 89 command[2] = x1 & 0xFF;
4180_1 0:e25ba425dc7b 90
4180_1 0:e25ba425dc7b 91 command[3] = (y1 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 92 command[4] = y1 & 0xFF;
4180_1 0:e25ba425dc7b 93
4180_1 0:e25ba425dc7b 94 command[5] = (x2 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 95 command[6] = x2 & 0xFF;
4180_1 0:e25ba425dc7b 96
4180_1 0:e25ba425dc7b 97 command[7] = (y2 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 98 command[8] = y2 & 0xFF;
4180_1 0:e25ba425dc7b 99
4180_1 0:e25ba425dc7b 100 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 101 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 102 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 103
4180_1 0:e25ba425dc7b 104 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 105 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 106
4180_1 0:e25ba425dc7b 107 writeCOMMAND(command, 11);
4180_1 0:e25ba425dc7b 108 }
4180_1 0:e25ba425dc7b 109
4180_1 0:e25ba425dc7b 110 //****************************************************************************************************
4180_1 0:e25ba425dc7b 111 void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle
4180_1 0:e25ba425dc7b 112 char command[11]= "";
4180_1 0:e25ba425dc7b 113
4180_1 0:e25ba425dc7b 114 command[0] = RECTANGLE;
4180_1 0:e25ba425dc7b 115
4180_1 0:e25ba425dc7b 116 command[1] = (x1 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 117 command[2] = x1 & 0xFF;
4180_1 0:e25ba425dc7b 118
4180_1 0:e25ba425dc7b 119 command[3] = (y1 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 120 command[4] = y1 & 0xFF;
4180_1 0:e25ba425dc7b 121
4180_1 0:e25ba425dc7b 122 command[5] = (x2 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 123 command[6] = x2 & 0xFF;
4180_1 0:e25ba425dc7b 124
4180_1 0:e25ba425dc7b 125 command[7] = (y2 >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 126 command[8] = y2 & 0xFF;
4180_1 0:e25ba425dc7b 127
4180_1 0:e25ba425dc7b 128 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 129 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 130 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 131
4180_1 0:e25ba425dc7b 132 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 133 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 134
4180_1 0:e25ba425dc7b 135 writeCOMMAND(command, 11);
4180_1 0:e25ba425dc7b 136 }
4180_1 0:e25ba425dc7b 137
4180_1 0:e25ba425dc7b 138 //****************************************************************************************************
4180_1 0:e25ba425dc7b 139 void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse
4180_1 0:e25ba425dc7b 140 char command[11]= "";
4180_1 0:e25ba425dc7b 141
4180_1 0:e25ba425dc7b 142 command[0] = ELLIPSE;
4180_1 0:e25ba425dc7b 143
4180_1 0:e25ba425dc7b 144 command[1] = (x >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 145 command[2] = x & 0xFF;
4180_1 0:e25ba425dc7b 146
4180_1 0:e25ba425dc7b 147 command[3] = (y >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 148 command[4] = y & 0xFF;
4180_1 0:e25ba425dc7b 149
4180_1 0:e25ba425dc7b 150 command[5] = (radius_x >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 151 command[6] = radius_x & 0xFF;
4180_1 0:e25ba425dc7b 152
4180_1 0:e25ba425dc7b 153 command[7] = (radius_y >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 154 command[8] = radius_y & 0xFF;
4180_1 0:e25ba425dc7b 155
4180_1 0:e25ba425dc7b 156 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 157 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 158 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 159
4180_1 0:e25ba425dc7b 160 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 161 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 162
4180_1 0:e25ba425dc7b 163 writeCOMMAND(command, 11);
4180_1 0:e25ba425dc7b 164 }
4180_1 0:e25ba425dc7b 165
4180_1 0:e25ba425dc7b 166 //****************************************************************************************************
4180_1 0:e25ba425dc7b 167 void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel
4180_1 0:e25ba425dc7b 168 char command[7]= "";
4180_1 0:e25ba425dc7b 169
4180_1 0:e25ba425dc7b 170 command[0] = PIXEL;
4180_1 0:e25ba425dc7b 171
4180_1 0:e25ba425dc7b 172 command[1] = (x >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 173 command[2] = x & 0xFF;
4180_1 0:e25ba425dc7b 174
4180_1 0:e25ba425dc7b 175 command[3] = (y >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 176 command[4] = y & 0xFF;
4180_1 0:e25ba425dc7b 177
4180_1 0:e25ba425dc7b 178 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 179 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 180 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 181
4180_1 0:e25ba425dc7b 182 command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 183 command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 184
4180_1 0:e25ba425dc7b 185 writeCOMMAND(command, 7);
4180_1 0:e25ba425dc7b 186 }
4180_1 0:e25ba425dc7b 187
4180_1 0:e25ba425dc7b 188 //******************************************************************************************************
4180_1 0:e25ba425dc7b 189 int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data
4180_1 0:e25ba425dc7b 190
4180_1 0:e25ba425dc7b 191 char command[5]= "";
4180_1 0:e25ba425dc7b 192
4180_1 0:e25ba425dc7b 193 command[0] = READPIXEL;
4180_1 0:e25ba425dc7b 194
4180_1 0:e25ba425dc7b 195 command[1] = (x >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 196 command[2] = x & 0xFF;
4180_1 0:e25ba425dc7b 197
4180_1 0:e25ba425dc7b 198 command[3] = (y >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 199 command[4] = y & 0xFF;
4180_1 0:e25ba425dc7b 200
4180_1 0:e25ba425dc7b 201 int i, temp = 0, color = 0, resp = 0;
4180_1 0:e25ba425dc7b 202 char response[2] = "";
4180_1 0:e25ba425dc7b 203
4180_1 0:e25ba425dc7b 204 freeBUFFER();
4180_1 0:e25ba425dc7b 205
4180_1 0:e25ba425dc7b 206 for (i = 0; i < 5; i++) { // send all chars to serial port
4180_1 0:e25ba425dc7b 207 writeBYTE(command[i]);
4180_1 0:e25ba425dc7b 208 }
4180_1 0:e25ba425dc7b 209
4180_1 0:e25ba425dc7b 210 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 0:e25ba425dc7b 211
4180_1 0:e25ba425dc7b 212 while (_cmd.readable()) {
4180_1 0:e25ba425dc7b 213 temp = _cmd.getc();
4180_1 0:e25ba425dc7b 214 response[resp++] = (char)temp;
4180_1 0:e25ba425dc7b 215 }
4180_1 0:e25ba425dc7b 216
4180_1 0:e25ba425dc7b 217 color = ((response[0] << 8) + response[1]);
4180_1 0:e25ba425dc7b 218
4180_1 0:e25ba425dc7b 219 return color; // WARNING : this is 16bits color, not 24bits... need to be fixed
4180_1 0:e25ba425dc7b 220 }
4180_1 0:e25ba425dc7b 221
4180_1 0:e25ba425dc7b 222 //******************************************************************************************************
4180_1 0:e25ba425dc7b 223 void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) {
4180_1 0:e25ba425dc7b 224
4180_1 0:e25ba425dc7b 225 char command[13]= "";
4180_1 0:e25ba425dc7b 226
4180_1 0:e25ba425dc7b 227 command[0] = SCREENCOPY;
4180_1 0:e25ba425dc7b 228
4180_1 0:e25ba425dc7b 229 command[1] = (xs >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 230 command[2] = xs & 0xFF;
4180_1 0:e25ba425dc7b 231
4180_1 0:e25ba425dc7b 232 command[3] = (ys >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 233 command[4] = ys & 0xFF;
4180_1 0:e25ba425dc7b 234
4180_1 0:e25ba425dc7b 235 command[5] = (xd >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 236 command[6] = xd & 0xFF;
4180_1 0:e25ba425dc7b 237
4180_1 0:e25ba425dc7b 238 command[7] = (yd >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 239 command[8] = yd & 0xFF;
4180_1 0:e25ba425dc7b 240
4180_1 0:e25ba425dc7b 241 command[9] = (width >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 242 command[10] = width & 0xFF;
4180_1 0:e25ba425dc7b 243
4180_1 0:e25ba425dc7b 244 command[11] = (height >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 245 command[12] = height & 0xFF;
4180_1 0:e25ba425dc7b 246
4180_1 0:e25ba425dc7b 247 writeCOMMAND(command, 13);
4180_1 0:e25ba425dc7b 248 }
4180_1 0:e25ba425dc7b 249
4180_1 0:e25ba425dc7b 250 //****************************************************************************************************
4180_1 0:e25ba425dc7b 251 void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME
4180_1 0:e25ba425dc7b 252 char command[2]= "";
4180_1 0:e25ba425dc7b 253
4180_1 0:e25ba425dc7b 254 command[0] = PENSIZE;
4180_1 0:e25ba425dc7b 255 command[1] = mode;
4180_1 0:e25ba425dc7b 256
4180_1 0:e25ba425dc7b 257 writeCOMMAND(command, 2);
4180_1 0:e25ba425dc7b 258 }