Anuj Patel
/
uVGAII_with_printf
Wrappper for VGAII demo by Jim Hamblem that includes a printf function that can print infinitely.
Embed:
(wiki syntax)
Show/hide line numbers
TFT_4DGL_Text.cpp
00001 // 00002 // TFT_4DGL is a class to drive 4D Systems TFT touch screens 00003 // 00004 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> 00005 // 00006 // TFT_4DGL is free software: you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation, either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // TFT_4DGL is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. 00018 00019 #include "mbed.h" 00020 #include "TFT_4DGL.h" 00021 #include <stdarg.h> 00022 #include <stdio.h> 00023 00024 00025 //**************************************************************************************************** 00026 void TFT_4DGL :: set_font(char mode) { // set font size 00027 char command[2]= ""; 00028 00029 int w, h, fx = 8, fy = 8; 00030 00031 command[0] = SETFONT; 00032 command[1] = mode; 00033 00034 current_font = mode; 00035 00036 if (current_orientation == IS_PORTRAIT) { 00037 w = SIZE_X; 00038 h = SIZE_Y; 00039 } else { 00040 w = SIZE_Y; 00041 h = SIZE_X; 00042 } 00043 00044 switch (mode) { 00045 case FONT_5X7 : 00046 fx = 6; 00047 fy = 8; 00048 break; 00049 case FONT_8X8 : 00050 fx = 8; 00051 fy = 8; 00052 break; 00053 case FONT_8X12 : 00054 fx = 8; 00055 fy = 12; 00056 break; 00057 case FONT_12X16 : 00058 fx = 12; 00059 fy = 16; 00060 break; 00061 } 00062 00063 max_col = w / fx; 00064 max_row = h / fy; 00065 00066 writeCOMMAND(command, 2); 00067 } 00068 00069 //**************************************************************************************************** 00070 void TFT_4DGL :: text_mode(char mode) { // set text mode 00071 char command[2]= ""; 00072 00073 command[0] = TEXTMODE; 00074 command[1] = mode; 00075 00076 writeCOMMAND(command, 2); 00077 } 00078 00079 //**************************************************************************************************** 00080 void TFT_4DGL :: text_char(char c, char col, char row, int color) { // draw a text char 00081 char command[6]= ""; 00082 00083 command[0] = TEXTCHAR; 00084 00085 command[1] = c; 00086 command[2] = col; 00087 command[3] = row; 00088 00089 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits 00090 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits 00091 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00092 00093 command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00094 command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00095 00096 writeCOMMAND(command, 8); 00097 } 00098 00099 //**************************************************************************************************** 00100 void TFT_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height) { // draw a graphic char 00101 char command[10]= ""; 00102 00103 command[0] = GRAPHCHAR; 00104 00105 command[1] = c; 00106 00107 command[2] = (x >> 8) & 0xFF; 00108 command[3] = x & 0xFF; 00109 00110 command[4] = (y >> 8) & 0xFF; 00111 command[5] = y & 0xFF; 00112 00113 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits 00114 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits 00115 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00116 00117 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00118 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00119 00120 command[8] = width; 00121 00122 command[9] = height; 00123 00124 writeCOMMAND(command, 10); 00125 } 00126 00127 //**************************************************************************************************** 00128 void TFT_4DGL :: text_string(char *s, char col, char row, char font, int color) { // draw a text string 00129 00130 char command[1000]= ""; 00131 int size = strlen(s); 00132 int i = 0; 00133 00134 command[0] = TEXTSTRING; 00135 00136 command[1] = col; 00137 command[2] = row; 00138 00139 command[3] = font; 00140 00141 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits 00142 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits 00143 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00144 00145 command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00146 command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00147 00148 for (i=0; i<size; i++) command[6+i] = s[i]; 00149 00150 command[6+size] = 0; 00151 00152 writeCOMMAND(command, 7 + size); 00153 } 00154 00155 //**************************************************************************************************** 00156 void TFT_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height) { // draw a text string 00157 00158 char command[1000]= ""; 00159 int size = strlen(s); 00160 int i = 0; 00161 00162 command[0] = GRAPHSTRING; 00163 00164 command[1] = (x >> 8) & 0xFF; 00165 command[2] = x & 0xFF; 00166 00167 command[3] = (y >> 8) & 0xFF; 00168 command[4] = y & 0xFF; 00169 00170 command[5] = font; 00171 00172 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits 00173 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits 00174 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00175 00176 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00177 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00178 00179 command[8] = width; 00180 00181 command[9] = height; 00182 00183 for (i=0; i<size; i++) command[10+i] = s[i]; 00184 00185 command[10+size] = 0; 00186 00187 writeCOMMAND(command, 11 + size); 00188 } 00189 00190 //**************************************************************************************************** 00191 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 00192 00193 char command[1000]= ""; 00194 int size = strlen(s); 00195 int i = 0, red5, green6, blue5; 00196 00197 command[0] = TEXTBUTTON; 00198 00199 command[1] = mode; 00200 00201 command[2] = (x >> 8) & 0xFF; 00202 command[3] = x & 0xFF; 00203 00204 command[4] = (y >> 8) & 0xFF; 00205 command[5] = y & 0xFF; 00206 00207 red5 = (button_color >> (16 + 3)) & 0x1F; // get red on 5 bits 00208 green6 = (button_color >> (8 + 2)) & 0x3F; // get green on 6 bits 00209 blue5 = (button_color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00210 00211 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00212 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00213 00214 command[8] = font; 00215 00216 red5 = (text_color >> (16 + 3)) & 0x1F; // get red on 5 bits 00217 green6 = (text_color >> (8 + 2)) & 0x3F; // get green on 6 bits 00218 blue5 = (text_color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00219 00220 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00221 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00222 00223 command[11] = width; 00224 00225 command[12] = height; 00226 00227 for (i=0; i<size; i++) command[13+i] = s[i]; 00228 00229 command[13+size] = 0; 00230 00231 writeCOMMAND(command, 14 + size); 00232 } 00233 00234 //**************************************************************************************************** 00235 void TFT_4DGL :: locate(char col, char row) { // place text curssor at col, row 00236 current_col = col; 00237 current_row = row; 00238 } 00239 00240 //**************************************************************************************************** 00241 void TFT_4DGL :: color(int color) { // set text color 00242 current_color = color; 00243 } 00244 00245 //**************************************************************************************************** 00246 void TFT_4DGL :: putc(char c) { // place char at current cursor position 00247 00248 text_char(c, current_col++, current_row, current_color); 00249 00250 if (current_col == max_col) { 00251 current_col = 0; 00252 current_row++; 00253 } 00254 if (current_row == max_row) { 00255 current_row = 0; 00256 } 00257 } 00258 00259 //**************************************************************************************************** 00260 void TFT_4DGL :: puts(char *s) { // place string at current cursor position 00261 00262 text_string(s, current_col, current_row, current_font, current_color); 00263 00264 current_col += strlen(s); 00265 00266 if (current_col >= max_col) { 00267 current_row += current_col / max_col; 00268 current_col %= max_col; 00269 } 00270 if (current_row >= max_row) { 00271 current_row %= max_row; 00272 } 00273 }
Generated on Fri Jul 15 2022 06:03:34 by 1.7.2