Dependents:   Telecommande_prologue

Committer:
projetremote
Date:
Tue May 03 13:36:08 2011 +0000
Revision:
0:277186c9dd25

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
projetremote 0:277186c9dd25 1 //
projetremote 0:277186c9dd25 2 // TFT_4DGL is a class to drive 4D Systems TFT touch screens
projetremote 0:277186c9dd25 3 //
projetremote 0:277186c9dd25 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
projetremote 0:277186c9dd25 5 //
projetremote 0:277186c9dd25 6 // TFT_4DGL is free software: you can redistribute it and/or modify
projetremote 0:277186c9dd25 7 // it under the terms of the GNU General Public License as published by
projetremote 0:277186c9dd25 8 // the Free Software Foundation, either version 3 of the License, or
projetremote 0:277186c9dd25 9 // (at your option) any later version.
projetremote 0:277186c9dd25 10 //
projetremote 0:277186c9dd25 11 // TFT_4DGL is distributed in the hope that it will be useful,
projetremote 0:277186c9dd25 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
projetremote 0:277186c9dd25 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
projetremote 0:277186c9dd25 14 // GNU General Public License for more details.
projetremote 0:277186c9dd25 15 //
projetremote 0:277186c9dd25 16 // You should have received a copy of the GNU General Public License
projetremote 0:277186c9dd25 17 // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
projetremote 0:277186c9dd25 18
projetremote 0:277186c9dd25 19 #include "mbed.h"
projetremote 0:277186c9dd25 20 #include "TFT_4DGL.h"
projetremote 0:277186c9dd25 21
projetremote 0:277186c9dd25 22 //****************************************************************************************************
projetremote 0:277186c9dd25 23 void TFT_4DGL :: set_font(char mode) { // set font size
projetremote 0:277186c9dd25 24 char command[2]= "";
projetremote 0:277186c9dd25 25
projetremote 0:277186c9dd25 26 int w, h, fx = 8, fy = 8;
projetremote 0:277186c9dd25 27
projetremote 0:277186c9dd25 28 command[0] = SETFONT;
projetremote 0:277186c9dd25 29 command[1] = mode;
projetremote 0:277186c9dd25 30
projetremote 0:277186c9dd25 31 current_font = mode;
projetremote 0:277186c9dd25 32
projetremote 0:277186c9dd25 33 if (current_orientation == IS_PORTRAIT) {
projetremote 0:277186c9dd25 34 w = SIZE_X;
projetremote 0:277186c9dd25 35 h = SIZE_Y;
projetremote 0:277186c9dd25 36 } else {
projetremote 0:277186c9dd25 37 w = SIZE_Y;
projetremote 0:277186c9dd25 38 h = SIZE_X;
projetremote 0:277186c9dd25 39 }
projetremote 0:277186c9dd25 40
projetremote 0:277186c9dd25 41 switch (mode) {
projetremote 0:277186c9dd25 42 case FONT_5X7 :
projetremote 0:277186c9dd25 43 fx = 6;
projetremote 0:277186c9dd25 44 fy = 8;
projetremote 0:277186c9dd25 45 break;
projetremote 0:277186c9dd25 46 case FONT_8X8 :
projetremote 0:277186c9dd25 47 fx = 8;
projetremote 0:277186c9dd25 48 fy = 8;
projetremote 0:277186c9dd25 49 break;
projetremote 0:277186c9dd25 50 case FONT_8X12 :
projetremote 0:277186c9dd25 51 fx = 8;
projetremote 0:277186c9dd25 52 fy = 12;
projetremote 0:277186c9dd25 53 break;
projetremote 0:277186c9dd25 54 case FONT_12X16 :
projetremote 0:277186c9dd25 55 fx = 12;
projetremote 0:277186c9dd25 56 fy = 16;
projetremote 0:277186c9dd25 57 break;
projetremote 0:277186c9dd25 58 }
projetremote 0:277186c9dd25 59
projetremote 0:277186c9dd25 60 max_col = w / fx;
projetremote 0:277186c9dd25 61 max_row = h / fy;
projetremote 0:277186c9dd25 62
projetremote 0:277186c9dd25 63 writeCOMMAND(command, 2);
projetremote 0:277186c9dd25 64 }
projetremote 0:277186c9dd25 65
projetremote 0:277186c9dd25 66 //****************************************************************************************************
projetremote 0:277186c9dd25 67 void TFT_4DGL :: text_mode(char mode) { // set text mode
projetremote 0:277186c9dd25 68 char command[2]= "";
projetremote 0:277186c9dd25 69
projetremote 0:277186c9dd25 70 command[0] = TEXTMODE;
projetremote 0:277186c9dd25 71 command[1] = mode;
projetremote 0:277186c9dd25 72
projetremote 0:277186c9dd25 73 writeCOMMAND(command, 2);
projetremote 0:277186c9dd25 74 }
projetremote 0:277186c9dd25 75
projetremote 0:277186c9dd25 76 //****************************************************************************************************
projetremote 0:277186c9dd25 77 void TFT_4DGL :: text_char(char c, char col, char row, int color) { // draw a text char
projetremote 0:277186c9dd25 78 char command[6]= "";
projetremote 0:277186c9dd25 79
projetremote 0:277186c9dd25 80 command[0] = TEXTCHAR;
projetremote 0:277186c9dd25 81
projetremote 0:277186c9dd25 82 command[1] = c;
projetremote 0:277186c9dd25 83 command[2] = col;
projetremote 0:277186c9dd25 84 command[3] = row;
projetremote 0:277186c9dd25 85
projetremote 0:277186c9dd25 86 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
projetremote 0:277186c9dd25 87 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
projetremote 0:277186c9dd25 88 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
projetremote 0:277186c9dd25 89
projetremote 0:277186c9dd25 90 command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
projetremote 0:277186c9dd25 91 command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
projetremote 0:277186c9dd25 92
projetremote 0:277186c9dd25 93 writeCOMMAND(command, 8);
projetremote 0:277186c9dd25 94 }
projetremote 0:277186c9dd25 95
projetremote 0:277186c9dd25 96 //****************************************************************************************************
projetremote 0:277186c9dd25 97 void TFT_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height) { // draw a graphic char
projetremote 0:277186c9dd25 98 char command[10]= "";
projetremote 0:277186c9dd25 99
projetremote 0:277186c9dd25 100 command[0] = GRAPHCHAR;
projetremote 0:277186c9dd25 101
projetremote 0:277186c9dd25 102 command[1] = c;
projetremote 0:277186c9dd25 103
projetremote 0:277186c9dd25 104 command[2] = (x >> 8) & 0xFF;
projetremote 0:277186c9dd25 105 command[3] = x & 0xFF;
projetremote 0:277186c9dd25 106
projetremote 0:277186c9dd25 107 command[4] = (y >> 8) & 0xFF;
projetremote 0:277186c9dd25 108 command[5] = y & 0xFF;
projetremote 0:277186c9dd25 109
projetremote 0:277186c9dd25 110 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
projetremote 0:277186c9dd25 111 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
projetremote 0:277186c9dd25 112 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
projetremote 0:277186c9dd25 113
projetremote 0:277186c9dd25 114 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
projetremote 0:277186c9dd25 115 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
projetremote 0:277186c9dd25 116
projetremote 0:277186c9dd25 117 command[8] = width;
projetremote 0:277186c9dd25 118
projetremote 0:277186c9dd25 119 command[9] = height;
projetremote 0:277186c9dd25 120
projetremote 0:277186c9dd25 121 writeCOMMAND(command, 10);
projetremote 0:277186c9dd25 122 }
projetremote 0:277186c9dd25 123
projetremote 0:277186c9dd25 124 //****************************************************************************************************
projetremote 0:277186c9dd25 125 void TFT_4DGL :: text_string(char *s, char col, char row, char font, int color) { // draw a text string
projetremote 0:277186c9dd25 126
projetremote 0:277186c9dd25 127 char command[1000]= "";
projetremote 0:277186c9dd25 128 int size = strlen(s);
projetremote 0:277186c9dd25 129 int i = 0;
projetremote 0:277186c9dd25 130
projetremote 0:277186c9dd25 131 command[0] = TEXTSTRING;
projetremote 0:277186c9dd25 132
projetremote 0:277186c9dd25 133 command[1] = col;
projetremote 0:277186c9dd25 134 command[2] = row;
projetremote 0:277186c9dd25 135
projetremote 0:277186c9dd25 136 command[3] = font;
projetremote 0:277186c9dd25 137
projetremote 0:277186c9dd25 138 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
projetremote 0:277186c9dd25 139 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
projetremote 0:277186c9dd25 140 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
projetremote 0:277186c9dd25 141
projetremote 0:277186c9dd25 142 command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
projetremote 0:277186c9dd25 143 command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
projetremote 0:277186c9dd25 144
projetremote 0:277186c9dd25 145 for (i=0; i<size; i++) command[6+i] = s[i];
projetremote 0:277186c9dd25 146
projetremote 0:277186c9dd25 147 command[6+size] = 0;
projetremote 0:277186c9dd25 148
projetremote 0:277186c9dd25 149 writeCOMMAND(command, 7 + size);
projetremote 0:277186c9dd25 150 }
projetremote 0:277186c9dd25 151
projetremote 0:277186c9dd25 152 //****************************************************************************************************
projetremote 0:277186c9dd25 153 void TFT_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height) { // draw a text string
projetremote 0:277186c9dd25 154
projetremote 0:277186c9dd25 155 char command[1000]= "";
projetremote 0:277186c9dd25 156 int size = strlen(s);
projetremote 0:277186c9dd25 157 int i = 0;
projetremote 0:277186c9dd25 158
projetremote 0:277186c9dd25 159 command[0] = GRAPHSTRING;
projetremote 0:277186c9dd25 160
projetremote 0:277186c9dd25 161 command[1] = (x >> 8) & 0xFF;
projetremote 0:277186c9dd25 162 command[2] = x & 0xFF;
projetremote 0:277186c9dd25 163
projetremote 0:277186c9dd25 164 command[3] = (y >> 8) & 0xFF;
projetremote 0:277186c9dd25 165 command[4] = y & 0xFF;
projetremote 0:277186c9dd25 166
projetremote 0:277186c9dd25 167 command[5] = font;
projetremote 0:277186c9dd25 168
projetremote 0:277186c9dd25 169 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
projetremote 0:277186c9dd25 170 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
projetremote 0:277186c9dd25 171 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
projetremote 0:277186c9dd25 172
projetremote 0:277186c9dd25 173 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
projetremote 0:277186c9dd25 174 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
projetremote 0:277186c9dd25 175
projetremote 0:277186c9dd25 176 command[8] = width;
projetremote 0:277186c9dd25 177
projetremote 0:277186c9dd25 178 command[9] = height;
projetremote 0:277186c9dd25 179
projetremote 0:277186c9dd25 180 for (i=0; i<size; i++) command[10+i] = s[i];
projetremote 0:277186c9dd25 181
projetremote 0:277186c9dd25 182 command[10+size] = 0;
projetremote 0:277186c9dd25 183
projetremote 0:277186c9dd25 184 writeCOMMAND(command, 11 + size);
projetremote 0:277186c9dd25 185 }
projetremote 0:277186c9dd25 186
projetremote 0:277186c9dd25 187 //****************************************************************************************************
projetremote 0:277186c9dd25 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
projetremote 0:277186c9dd25 189
projetremote 0:277186c9dd25 190 char command[1000]= "";
projetremote 0:277186c9dd25 191 int size = strlen(s);
projetremote 0:277186c9dd25 192 int i = 0, red5, green6, blue5;
projetremote 0:277186c9dd25 193
projetremote 0:277186c9dd25 194 command[0] = TEXTBUTTON;
projetremote 0:277186c9dd25 195
projetremote 0:277186c9dd25 196 command[1] = mode;
projetremote 0:277186c9dd25 197
projetremote 0:277186c9dd25 198 command[2] = (x >> 8) & 0xFF;
projetremote 0:277186c9dd25 199 command[3] = x & 0xFF;
projetremote 0:277186c9dd25 200
projetremote 0:277186c9dd25 201 command[4] = (y >> 8) & 0xFF;
projetremote 0:277186c9dd25 202 command[5] = y & 0xFF;
projetremote 0:277186c9dd25 203
projetremote 0:277186c9dd25 204 red5 = (button_color >> (16 + 3)) & 0x1F; // get red on 5 bits
projetremote 0:277186c9dd25 205 green6 = (button_color >> (8 + 2)) & 0x3F; // get green on 6 bits
projetremote 0:277186c9dd25 206 blue5 = (button_color >> (0 + 3)) & 0x1F; // get blue on 5 bits
projetremote 0:277186c9dd25 207
projetremote 0:277186c9dd25 208 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
projetremote 0:277186c9dd25 209 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
projetremote 0:277186c9dd25 210
projetremote 0:277186c9dd25 211 command[8] = font;
projetremote 0:277186c9dd25 212
projetremote 0:277186c9dd25 213 red5 = (text_color >> (16 + 3)) & 0x1F; // get red on 5 bits
projetremote 0:277186c9dd25 214 green6 = (text_color >> (8 + 2)) & 0x3F; // get green on 6 bits
projetremote 0:277186c9dd25 215 blue5 = (text_color >> (0 + 3)) & 0x1F; // get blue on 5 bits
projetremote 0:277186c9dd25 216
projetremote 0:277186c9dd25 217 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
projetremote 0:277186c9dd25 218 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
projetremote 0:277186c9dd25 219
projetremote 0:277186c9dd25 220 command[11] = width;
projetremote 0:277186c9dd25 221
projetremote 0:277186c9dd25 222 command[12] = height;
projetremote 0:277186c9dd25 223
projetremote 0:277186c9dd25 224 for (i=0; i<size; i++) command[13+i] = s[i];
projetremote 0:277186c9dd25 225
projetremote 0:277186c9dd25 226 command[13+size] = 0;
projetremote 0:277186c9dd25 227
projetremote 0:277186c9dd25 228 writeCOMMAND(command, 14 + size);
projetremote 0:277186c9dd25 229 }
projetremote 0:277186c9dd25 230
projetremote 0:277186c9dd25 231 //****************************************************************************************************
projetremote 0:277186c9dd25 232 void TFT_4DGL :: locate(char col, char row) { // place text curssor at col, row
projetremote 0:277186c9dd25 233 current_col = col;
projetremote 0:277186c9dd25 234 current_row = row;
projetremote 0:277186c9dd25 235 }
projetremote 0:277186c9dd25 236
projetremote 0:277186c9dd25 237 //****************************************************************************************************
projetremote 0:277186c9dd25 238 void TFT_4DGL :: color(int color) { // set text color
projetremote 0:277186c9dd25 239 current_color = color;
projetremote 0:277186c9dd25 240 }
projetremote 0:277186c9dd25 241
projetremote 0:277186c9dd25 242 //****************************************************************************************************
projetremote 0:277186c9dd25 243 void TFT_4DGL :: putc(char c) { // place char at current cursor position
projetremote 0:277186c9dd25 244
projetremote 0:277186c9dd25 245 text_char(c, current_col++, current_row, current_color);
projetremote 0:277186c9dd25 246
projetremote 0:277186c9dd25 247 if (current_col == max_col) {
projetremote 0:277186c9dd25 248 current_col = 0;
projetremote 0:277186c9dd25 249 current_row++;
projetremote 0:277186c9dd25 250 }
projetremote 0:277186c9dd25 251 if (current_row == max_row) {
projetremote 0:277186c9dd25 252 current_row = 0;
projetremote 0:277186c9dd25 253 }
projetremote 0:277186c9dd25 254 }
projetremote 0:277186c9dd25 255
projetremote 0:277186c9dd25 256 //****************************************************************************************************
projetremote 0:277186c9dd25 257 void TFT_4DGL :: puts(char *s) { // place string at current cursor position
projetremote 0:277186c9dd25 258
projetremote 0:277186c9dd25 259 text_string(s, current_col, current_row, current_font, current_color);
projetremote 0:277186c9dd25 260
projetremote 0:277186c9dd25 261 current_col += strlen(s);
projetremote 0:277186c9dd25 262
projetremote 0:277186c9dd25 263 if (current_col >= max_col) {
projetremote 0:277186c9dd25 264 current_row += current_col / max_col;
projetremote 0:277186c9dd25 265 current_col %= max_col;
projetremote 0:277186c9dd25 266 }
projetremote 0:277186c9dd25 267 if (current_row >= max_row) {
projetremote 0:277186c9dd25 268 current_row %= max_row;
projetremote 0:277186c9dd25 269 }
projetremote 0:277186c9dd25 270 }