Wrappper for VGAII demo by Jim Hamblem that includes a printf function that can print infinitely.

Dependencies:   mbed

Committer:
apatel43
Date:
Thu Oct 13 19:21:27 2011 +0000
Revision:
0:10b753bd635e
Version 1

Who changed what in which revision?

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