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 void TFT_4DGL :: set_font(char mode) { // set font size
4180_1 0:e25ba425dc7b 24 char command[2]= "";
4180_1 0:e25ba425dc7b 25
4180_1 0:e25ba425dc7b 26 int w, h, fx = 8, fy = 8;
4180_1 0:e25ba425dc7b 27
4180_1 0:e25ba425dc7b 28 command[0] = SETFONT;
4180_1 0:e25ba425dc7b 29 command[1] = mode;
4180_1 0:e25ba425dc7b 30
4180_1 0:e25ba425dc7b 31 current_font = mode;
4180_1 0:e25ba425dc7b 32
4180_1 0:e25ba425dc7b 33 if (current_orientation == IS_PORTRAIT) {
4180_1 0:e25ba425dc7b 34 w = SIZE_X;
4180_1 0:e25ba425dc7b 35 h = SIZE_Y;
4180_1 0:e25ba425dc7b 36 } else {
4180_1 0:e25ba425dc7b 37 w = SIZE_Y;
4180_1 0:e25ba425dc7b 38 h = SIZE_X;
4180_1 0:e25ba425dc7b 39 }
4180_1 0:e25ba425dc7b 40
4180_1 0:e25ba425dc7b 41 switch (mode) {
4180_1 0:e25ba425dc7b 42 case FONT_5X7 :
4180_1 0:e25ba425dc7b 43 fx = 6;
4180_1 0:e25ba425dc7b 44 fy = 8;
4180_1 0:e25ba425dc7b 45 break;
4180_1 0:e25ba425dc7b 46 case FONT_8X8 :
4180_1 0:e25ba425dc7b 47 fx = 8;
4180_1 0:e25ba425dc7b 48 fy = 8;
4180_1 0:e25ba425dc7b 49 break;
4180_1 0:e25ba425dc7b 50 case FONT_8X12 :
4180_1 0:e25ba425dc7b 51 fx = 8;
4180_1 0:e25ba425dc7b 52 fy = 12;
4180_1 0:e25ba425dc7b 53 break;
4180_1 0:e25ba425dc7b 54 case FONT_12X16 :
4180_1 0:e25ba425dc7b 55 fx = 12;
4180_1 0:e25ba425dc7b 56 fy = 16;
4180_1 0:e25ba425dc7b 57 break;
4180_1 0:e25ba425dc7b 58 }
4180_1 0:e25ba425dc7b 59
4180_1 0:e25ba425dc7b 60 max_col = w / fx;
4180_1 0:e25ba425dc7b 61 max_row = h / fy;
4180_1 0:e25ba425dc7b 62
4180_1 0:e25ba425dc7b 63 writeCOMMAND(command, 2);
4180_1 0:e25ba425dc7b 64 }
4180_1 0:e25ba425dc7b 65
4180_1 0:e25ba425dc7b 66 //****************************************************************************************************
4180_1 0:e25ba425dc7b 67 void TFT_4DGL :: text_mode(char mode) { // set text mode
4180_1 0:e25ba425dc7b 68 char command[2]= "";
4180_1 0:e25ba425dc7b 69
4180_1 0:e25ba425dc7b 70 command[0] = TEXTMODE;
4180_1 0:e25ba425dc7b 71 command[1] = mode;
4180_1 0:e25ba425dc7b 72
4180_1 0:e25ba425dc7b 73 writeCOMMAND(command, 2);
4180_1 0:e25ba425dc7b 74 }
4180_1 0:e25ba425dc7b 75
4180_1 0:e25ba425dc7b 76 //****************************************************************************************************
4180_1 0:e25ba425dc7b 77 void TFT_4DGL :: text_char(char c, char col, char row, int color) { // draw a text char
4180_1 0:e25ba425dc7b 78 char command[6]= "";
4180_1 0:e25ba425dc7b 79
4180_1 0:e25ba425dc7b 80 command[0] = TEXTCHAR;
4180_1 0:e25ba425dc7b 81
4180_1 0:e25ba425dc7b 82 command[1] = c;
4180_1 0:e25ba425dc7b 83 command[2] = col;
4180_1 0:e25ba425dc7b 84 command[3] = row;
4180_1 0:e25ba425dc7b 85
4180_1 0:e25ba425dc7b 86 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 87 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 88 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 89
4180_1 0:e25ba425dc7b 90 command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 91 command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 92
4180_1 0:e25ba425dc7b 93 writeCOMMAND(command, 8);
4180_1 0:e25ba425dc7b 94 }
4180_1 0:e25ba425dc7b 95
4180_1 0:e25ba425dc7b 96 //****************************************************************************************************
4180_1 0:e25ba425dc7b 97 void TFT_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height) { // draw a graphic char
4180_1 0:e25ba425dc7b 98 char command[10]= "";
4180_1 0:e25ba425dc7b 99
4180_1 0:e25ba425dc7b 100 command[0] = GRAPHCHAR;
4180_1 0:e25ba425dc7b 101
4180_1 0:e25ba425dc7b 102 command[1] = c;
4180_1 0:e25ba425dc7b 103
4180_1 0:e25ba425dc7b 104 command[2] = (x >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 105 command[3] = x & 0xFF;
4180_1 0:e25ba425dc7b 106
4180_1 0:e25ba425dc7b 107 command[4] = (y >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 108 command[5] = y & 0xFF;
4180_1 0:e25ba425dc7b 109
4180_1 0:e25ba425dc7b 110 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 111 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 112 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 113
4180_1 0:e25ba425dc7b 114 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 115 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 116
4180_1 0:e25ba425dc7b 117 command[8] = width;
4180_1 0:e25ba425dc7b 118
4180_1 0:e25ba425dc7b 119 command[9] = height;
4180_1 0:e25ba425dc7b 120
4180_1 0:e25ba425dc7b 121 writeCOMMAND(command, 10);
4180_1 0:e25ba425dc7b 122 }
4180_1 0:e25ba425dc7b 123
4180_1 0:e25ba425dc7b 124 //****************************************************************************************************
4180_1 0:e25ba425dc7b 125 void TFT_4DGL :: text_string(char *s, char col, char row, char font, int color) { // draw a text string
4180_1 0:e25ba425dc7b 126
4180_1 0:e25ba425dc7b 127 char command[1000]= "";
4180_1 0:e25ba425dc7b 128 int size = strlen(s);
4180_1 0:e25ba425dc7b 129 int i = 0;
4180_1 0:e25ba425dc7b 130
4180_1 0:e25ba425dc7b 131 command[0] = TEXTSTRING;
4180_1 0:e25ba425dc7b 132
4180_1 0:e25ba425dc7b 133 command[1] = col;
4180_1 0:e25ba425dc7b 134 command[2] = row;
4180_1 0:e25ba425dc7b 135
4180_1 0:e25ba425dc7b 136 command[3] = font;
4180_1 0:e25ba425dc7b 137
4180_1 0:e25ba425dc7b 138 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 139 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 140 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 141
4180_1 0:e25ba425dc7b 142 command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 143 command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 144
4180_1 0:e25ba425dc7b 145 for (i=0; i<size; i++) command[6+i] = s[i];
4180_1 0:e25ba425dc7b 146
4180_1 0:e25ba425dc7b 147 command[6+size] = 0;
4180_1 0:e25ba425dc7b 148
4180_1 0:e25ba425dc7b 149 writeCOMMAND(command, 7 + size);
4180_1 0:e25ba425dc7b 150 }
4180_1 0:e25ba425dc7b 151
4180_1 0:e25ba425dc7b 152 //****************************************************************************************************
4180_1 0:e25ba425dc7b 153 void TFT_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height) { // draw a text string
4180_1 0:e25ba425dc7b 154
4180_1 0:e25ba425dc7b 155 char command[1000]= "";
4180_1 0:e25ba425dc7b 156 int size = strlen(s);
4180_1 0:e25ba425dc7b 157 int i = 0;
4180_1 0:e25ba425dc7b 158
4180_1 0:e25ba425dc7b 159 command[0] = GRAPHSTRING;
4180_1 0:e25ba425dc7b 160
4180_1 0:e25ba425dc7b 161 command[1] = (x >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 162 command[2] = x & 0xFF;
4180_1 0:e25ba425dc7b 163
4180_1 0:e25ba425dc7b 164 command[3] = (y >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 165 command[4] = y & 0xFF;
4180_1 0:e25ba425dc7b 166
4180_1 0:e25ba425dc7b 167 command[5] = font;
4180_1 0:e25ba425dc7b 168
4180_1 0:e25ba425dc7b 169 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 170 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 171 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 172
4180_1 0:e25ba425dc7b 173 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 174 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 175
4180_1 0:e25ba425dc7b 176 command[8] = width;
4180_1 0:e25ba425dc7b 177
4180_1 0:e25ba425dc7b 178 command[9] = height;
4180_1 0:e25ba425dc7b 179
4180_1 0:e25ba425dc7b 180 for (i=0; i<size; i++) command[10+i] = s[i];
4180_1 0:e25ba425dc7b 181
4180_1 0:e25ba425dc7b 182 command[10+size] = 0;
4180_1 0:e25ba425dc7b 183
4180_1 0:e25ba425dc7b 184 writeCOMMAND(command, 11 + size);
4180_1 0:e25ba425dc7b 185 }
4180_1 0:e25ba425dc7b 186
4180_1 0:e25ba425dc7b 187 //****************************************************************************************************
4180_1 0:e25ba425dc7b 188 void TFT_4DGL :: text_button(char *s, char mode, int x, int y, int button_color, char font, int text_color, char width, char height) { // draw a text string
4180_1 0:e25ba425dc7b 189
4180_1 0:e25ba425dc7b 190 char command[1000]= "";
4180_1 0:e25ba425dc7b 191 int size = strlen(s);
4180_1 0:e25ba425dc7b 192 int i = 0, red5, green6, blue5;
4180_1 0:e25ba425dc7b 193
4180_1 0:e25ba425dc7b 194 command[0] = TEXTBUTTON;
4180_1 0:e25ba425dc7b 195
4180_1 0:e25ba425dc7b 196 command[1] = mode;
4180_1 0:e25ba425dc7b 197
4180_1 0:e25ba425dc7b 198 command[2] = (x >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 199 command[3] = x & 0xFF;
4180_1 0:e25ba425dc7b 200
4180_1 0:e25ba425dc7b 201 command[4] = (y >> 8) & 0xFF;
4180_1 0:e25ba425dc7b 202 command[5] = y & 0xFF;
4180_1 0:e25ba425dc7b 203
4180_1 0:e25ba425dc7b 204 red5 = (button_color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 205 green6 = (button_color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 206 blue5 = (button_color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 207
4180_1 0:e25ba425dc7b 208 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 209 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 210
4180_1 0:e25ba425dc7b 211 command[8] = font;
4180_1 0:e25ba425dc7b 212
4180_1 0:e25ba425dc7b 213 red5 = (text_color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 0:e25ba425dc7b 214 green6 = (text_color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 0:e25ba425dc7b 215 blue5 = (text_color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 0:e25ba425dc7b 216
4180_1 0:e25ba425dc7b 217 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 0:e25ba425dc7b 218 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 0:e25ba425dc7b 219
4180_1 0:e25ba425dc7b 220 command[11] = width;
4180_1 0:e25ba425dc7b 221
4180_1 0:e25ba425dc7b 222 command[12] = height;
4180_1 0:e25ba425dc7b 223
4180_1 0:e25ba425dc7b 224 for (i=0; i<size; i++) command[13+i] = s[i];
4180_1 0:e25ba425dc7b 225
4180_1 0:e25ba425dc7b 226 command[13+size] = 0;
4180_1 0:e25ba425dc7b 227
4180_1 0:e25ba425dc7b 228 writeCOMMAND(command, 14 + size);
4180_1 0:e25ba425dc7b 229 }
4180_1 0:e25ba425dc7b 230
4180_1 0:e25ba425dc7b 231 //****************************************************************************************************
4180_1 0:e25ba425dc7b 232 void TFT_4DGL :: locate(char col, char row) { // place text curssor at col, row
4180_1 0:e25ba425dc7b 233 current_col = col;
4180_1 0:e25ba425dc7b 234 current_row = row;
4180_1 0:e25ba425dc7b 235 }
4180_1 0:e25ba425dc7b 236
4180_1 0:e25ba425dc7b 237 //****************************************************************************************************
4180_1 0:e25ba425dc7b 238 void TFT_4DGL :: color(int color) { // set text color
4180_1 0:e25ba425dc7b 239 current_color = color;
4180_1 0:e25ba425dc7b 240 }
4180_1 0:e25ba425dc7b 241
4180_1 0:e25ba425dc7b 242 //****************************************************************************************************
4180_1 0:e25ba425dc7b 243 void TFT_4DGL :: putc(char c) { // place char at current cursor position
4180_1 0:e25ba425dc7b 244
4180_1 0:e25ba425dc7b 245 text_char(c, current_col++, current_row, current_color);
4180_1 0:e25ba425dc7b 246
4180_1 0:e25ba425dc7b 247 if (current_col == max_col) {
4180_1 0:e25ba425dc7b 248 current_col = 0;
4180_1 0:e25ba425dc7b 249 current_row++;
4180_1 0:e25ba425dc7b 250 }
4180_1 0:e25ba425dc7b 251 if (current_row == max_row) {
4180_1 0:e25ba425dc7b 252 current_row = 0;
4180_1 0:e25ba425dc7b 253 }
4180_1 0:e25ba425dc7b 254 }
4180_1 0:e25ba425dc7b 255
4180_1 0:e25ba425dc7b 256 //****************************************************************************************************
4180_1 0:e25ba425dc7b 257 void TFT_4DGL :: puts(char *s) { // place string at current cursor position
4180_1 0:e25ba425dc7b 258
4180_1 0:e25ba425dc7b 259 text_string(s, current_col, current_row, current_font, current_color);
4180_1 0:e25ba425dc7b 260
4180_1 0:e25ba425dc7b 261 current_col += strlen(s);
4180_1 0:e25ba425dc7b 262
4180_1 0:e25ba425dc7b 263 if (current_col >= max_col) {
4180_1 0:e25ba425dc7b 264 current_row += current_col / max_col;
4180_1 0:e25ba425dc7b 265 current_col %= max_col;
4180_1 0:e25ba425dc7b 266 }
4180_1 0:e25ba425dc7b 267 if (current_row >= max_row) {
4180_1 0:e25ba425dc7b 268 current_row %= max_row;
4180_1 0:e25ba425dc7b 269 }
4180_1 0:e25ba425dc7b 270 }