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