Kamil Ondrousek / Mbed 2 deprecated Chua

Dependencies:   mbed

Committer:
JLS
Date:
Sun Dec 26 19:18:09 2010 +0000
Revision:
1:2dcd2355ae5e
updated

Who changed what in which revision?

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