Fork of 4DGL lib for uLCD-144-G2. Different command values needed. See https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ for instructions and demo code.

Dependents:   mythermostat MorseCode SuperMbedBall frogger_G ... more

Fork of 4DGL by Adam Green

Committer:
4180_1
Date:
Sat Nov 30 02:05:15 2013 +0000
Revision:
7:e39a44de229a
Parent:
5:8936798c19a3
ver1.5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 1:8b656995301f 1 //
4180_1 1:8b656995301f 2 // uLCD_4DGL is a class to drive 4D Systems TFT touch screens
4180_1 1:8b656995301f 3 //
4180_1 1:8b656995301f 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
4180_1 7:e39a44de229a 5 // Modifed for Goldelox processor <2013> Jim Hamblen
4180_1 1:8b656995301f 6 //
4180_1 1:8b656995301f 7 // uLCD_4DGL is free software: you can redistribute it and/or modify
4180_1 1:8b656995301f 8 // it under the terms of the GNU General Public License as published by
4180_1 1:8b656995301f 9 // the Free Software Foundation, either version 3 of the License, or
4180_1 1:8b656995301f 10 // (at your option) any later version.
4180_1 1:8b656995301f 11 //
4180_1 1:8b656995301f 12 // uLCD_4DGL is distributed in the hope that it will be useful,
4180_1 1:8b656995301f 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
4180_1 1:8b656995301f 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4180_1 1:8b656995301f 15 // GNU General Public License for more details.
4180_1 1:8b656995301f 16 //
4180_1 1:8b656995301f 17 // You should have received a copy of the GNU General Public License
4180_1 1:8b656995301f 18 // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>.
4180_1 1:8b656995301f 19
4180_1 1:8b656995301f 20 #include "mbed.h"
4180_1 1:8b656995301f 21 #include "uLCD_4DGL.h"
4180_1 1:8b656995301f 22
4180_1 1:8b656995301f 23 //****************************************************************************************************
4180_1 7:e39a44de229a 24 void uLCD_4DGL :: set_font_size(char width, char height) // set font size
4180_1 7:e39a44de229a 25 {
4180_1 7:e39a44de229a 26 if (current_orientation == IS_PORTRAIT) {
4180_1 7:e39a44de229a 27 current_fx = width;
4180_1 7:e39a44de229a 28 current_fy = height;
4180_1 7:e39a44de229a 29 } else {
4180_1 7:e39a44de229a 30 current_fy = height;
4180_1 7:e39a44de229a 31 current_fx = width;
4180_1 7:e39a44de229a 32 }
4180_1 7:e39a44de229a 33 max_col = current_w / (current_fx*current_wf);
4180_1 7:e39a44de229a 34 max_row = current_h / (current_fy*current_hf);
4180_1 7:e39a44de229a 35 }
4180_1 7:e39a44de229a 36
4180_1 7:e39a44de229a 37 //****************************************************************************************************
4180_1 7:e39a44de229a 38 void uLCD_4DGL :: set_font(char mode) // set font - system or SD media
4180_1 1:8b656995301f 39 {
4180_1 1:8b656995301f 40 char command[3]= "";
4180_1 1:8b656995301f 41
4180_1 1:8b656995301f 42 command[0] = SETFONT;
4180_1 1:8b656995301f 43 command[1] = 0;
4180_1 1:8b656995301f 44 command[2] = mode;
4180_1 1:8b656995301f 45
4180_1 1:8b656995301f 46 current_font = mode;
4180_1 1:8b656995301f 47
4180_1 1:8b656995301f 48 if (current_orientation == IS_PORTRAIT) {
4180_1 2:edae99e4abe7 49 current_w = SIZE_X;
4180_1 2:edae99e4abe7 50 current_h = SIZE_Y;
4180_1 1:8b656995301f 51 } else {
4180_1 2:edae99e4abe7 52 current_w = SIZE_Y;
4180_1 2:edae99e4abe7 53 current_h = SIZE_X;
4180_1 1:8b656995301f 54 }
4180_1 1:8b656995301f 55
4180_1 1:8b656995301f 56 switch (mode) {
4180_1 1:8b656995301f 57 case FONT_5X7 :
4180_1 7:e39a44de229a 58
4180_1 2:edae99e4abe7 59 current_fx = 6;
4180_1 2:edae99e4abe7 60 current_fy = 8;
4180_1 2:edae99e4abe7 61 break;
4180_1 2:edae99e4abe7 62 case FONT_7X8 :
4180_1 2:edae99e4abe7 63 current_fx = 7;
4180_1 2:edae99e4abe7 64 current_fy = 8;
4180_1 1:8b656995301f 65 break;
4180_1 1:8b656995301f 66 case FONT_8X8 :
4180_1 2:edae99e4abe7 67 current_fx = 8;
4180_1 2:edae99e4abe7 68 current_fy = 8;
4180_1 1:8b656995301f 69 break;
4180_1 1:8b656995301f 70 case FONT_8X12 :
4180_1 2:edae99e4abe7 71 current_fx = 8;
4180_1 2:edae99e4abe7 72 current_fy = 12;
4180_1 1:8b656995301f 73 break;
4180_1 1:8b656995301f 74 case FONT_12X16 :
4180_1 2:edae99e4abe7 75 current_fx = 12;
4180_1 2:edae99e4abe7 76 current_fy = 16;
4180_1 1:8b656995301f 77 break;
4180_1 7:e39a44de229a 78 default:
4180_1 7:e39a44de229a 79 current_fx = 8;
4180_1 7:e39a44de229a 80 current_fy = 8;
4180_1 1:8b656995301f 81 }
4180_1 1:8b656995301f 82
4180_1 2:edae99e4abe7 83 max_col = current_w / (current_fx*current_wf);
4180_1 2:edae99e4abe7 84 max_row = current_h / (current_fy*current_hf);
4180_1 1:8b656995301f 85
4180_1 1:8b656995301f 86 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 87 }
4180_1 1:8b656995301f 88
4180_1 5:8936798c19a3 89
4180_1 5:8936798c19a3 90
4180_1 1:8b656995301f 91 //****************************************************************************************************
4180_1 1:8b656995301f 92 void uLCD_4DGL :: text_mode(char mode) // set text mode
4180_1 1:8b656995301f 93 {
4180_1 1:8b656995301f 94 char command[3]= "";
4180_1 1:8b656995301f 95
4180_1 1:8b656995301f 96 command[0] = TEXTMODE;
4180_1 1:8b656995301f 97 command[1] = 0;
4180_1 1:8b656995301f 98 command[2] = mode;
4180_1 1:8b656995301f 99
4180_1 1:8b656995301f 100 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 101 }
4180_1 1:8b656995301f 102
4180_1 1:8b656995301f 103 //****************************************************************************************************
4180_1 5:8936798c19a3 104 void uLCD_4DGL :: text_bold(char mode) // set text mode
4180_1 5:8936798c19a3 105 {
4180_1 5:8936798c19a3 106 char command[3]= "";
4180_1 5:8936798c19a3 107
4180_1 5:8936798c19a3 108 command[0] = TEXTBOLD;
4180_1 5:8936798c19a3 109 command[1] = 0;
4180_1 5:8936798c19a3 110 command[2] = mode;
4180_1 5:8936798c19a3 111
4180_1 5:8936798c19a3 112 writeCOMMAND(command, 3);
4180_1 5:8936798c19a3 113 }
4180_1 5:8936798c19a3 114
4180_1 5:8936798c19a3 115 //****************************************************************************************************
4180_1 5:8936798c19a3 116 void uLCD_4DGL :: text_italic(char mode) // set text mode
4180_1 5:8936798c19a3 117 {
4180_1 5:8936798c19a3 118 char command[3]= "";
4180_1 5:8936798c19a3 119
4180_1 5:8936798c19a3 120 command[0] = TEXTITALIC;
4180_1 5:8936798c19a3 121 command[1] = 0;
4180_1 5:8936798c19a3 122 command[2] = mode;
4180_1 5:8936798c19a3 123
4180_1 5:8936798c19a3 124 writeCOMMAND(command, 3);
4180_1 5:8936798c19a3 125 }
4180_1 5:8936798c19a3 126
4180_1 5:8936798c19a3 127 //****************************************************************************************************
4180_1 5:8936798c19a3 128 void uLCD_4DGL :: text_inverse(char mode) // set text mode
4180_1 5:8936798c19a3 129 {
4180_1 5:8936798c19a3 130 char command[3]= "";
4180_1 5:8936798c19a3 131
4180_1 5:8936798c19a3 132 command[0] = TEXTINVERSE;
4180_1 5:8936798c19a3 133 command[1] = 0;
4180_1 5:8936798c19a3 134 command[2] = mode;
4180_1 5:8936798c19a3 135
4180_1 5:8936798c19a3 136 writeCOMMAND(command, 3);
4180_1 5:8936798c19a3 137 }
4180_1 5:8936798c19a3 138
4180_1 5:8936798c19a3 139 //****************************************************************************************************
4180_1 7:e39a44de229a 140 void uLCD_4DGL :: text_underline(char mode) // set text mode
4180_1 7:e39a44de229a 141 {
4180_1 7:e39a44de229a 142 char command[3]= "";
4180_1 7:e39a44de229a 143
4180_1 7:e39a44de229a 144 command[0] = TEXTUNDERLINE;
4180_1 7:e39a44de229a 145 command[1] = 0;
4180_1 7:e39a44de229a 146 command[2] = mode;
4180_1 7:e39a44de229a 147
4180_1 7:e39a44de229a 148 writeCOMMAND(command, 3);
4180_1 7:e39a44de229a 149 }
4180_1 7:e39a44de229a 150
4180_1 7:e39a44de229a 151 //****************************************************************************************************
4180_1 2:edae99e4abe7 152 void uLCD_4DGL :: text_width(char width) // set text width
4180_1 2:edae99e4abe7 153 {
4180_1 2:edae99e4abe7 154 char command[3]= "";
4180_1 2:edae99e4abe7 155
4180_1 2:edae99e4abe7 156 command[0] = TEXTWIDTH;
4180_1 2:edae99e4abe7 157 command[1] = 0;
4180_1 2:edae99e4abe7 158 command[2] = width;
4180_1 2:edae99e4abe7 159 current_wf = width;
4180_1 2:edae99e4abe7 160 max_col = current_w / (current_fx*current_wf);
4180_1 2:edae99e4abe7 161 writeCOMMAND(command, 3);
4180_1 2:edae99e4abe7 162 }
4180_1 2:edae99e4abe7 163
4180_1 2:edae99e4abe7 164 //****************************************************************************************************
4180_1 2:edae99e4abe7 165 void uLCD_4DGL :: text_height(char height) // set text height
4180_1 2:edae99e4abe7 166 {
4180_1 2:edae99e4abe7 167 char command[3]= "";
4180_1 2:edae99e4abe7 168
4180_1 2:edae99e4abe7 169 command[0] = TEXTHEIGHT;
4180_1 2:edae99e4abe7 170 command[1] = 0;
4180_1 2:edae99e4abe7 171 command[2] = height;
4180_1 2:edae99e4abe7 172 current_hf = height;
4180_1 2:edae99e4abe7 173 max_row = current_h / (current_fy*current_hf);
4180_1 2:edae99e4abe7 174 writeCOMMAND(command, 3);
4180_1 2:edae99e4abe7 175 }
4180_1 2:edae99e4abe7 176
4180_1 2:edae99e4abe7 177
4180_1 2:edae99e4abe7 178 //****************************************************************************************************
4180_1 1:8b656995301f 179 void uLCD_4DGL :: text_char(char c, char col, char row, int color) // draw a text char
4180_1 1:8b656995301f 180 {
4180_1 1:8b656995301f 181 char command[6]= "";
4180_1 1:8b656995301f 182 command[0] = 0xE4; //move cursor
4180_1 1:8b656995301f 183 command[1] = 0;
4180_1 1:8b656995301f 184 command[2] = row;
4180_1 1:8b656995301f 185 command[3] = 0;
4180_1 1:8b656995301f 186 command[4] = col;
4180_1 1:8b656995301f 187 writeCOMMAND(command, 5);
4180_1 1:8b656995301f 188
4180_1 1:8b656995301f 189 command[0] = 0x7F; //set color
4180_1 1:8b656995301f 190
4180_1 1:8b656995301f 191 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 1:8b656995301f 192 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 1:8b656995301f 193 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 1:8b656995301f 194
4180_1 1:8b656995301f 195 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 1:8b656995301f 196 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 1:8b656995301f 197 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 198
4180_1 1:8b656995301f 199 command[0] = TEXTCHAR; //print char
4180_1 1:8b656995301f 200 command[1] = 0;
4180_1 1:8b656995301f 201 command[2] = c;
4180_1 1:8b656995301f 202 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 203
4180_1 1:8b656995301f 204 }
4180_1 1:8b656995301f 205
4180_1 1:8b656995301f 206
4180_1 1:8b656995301f 207 //****************************************************************************************************
4180_1 1:8b656995301f 208 void uLCD_4DGL :: text_string(char *s, char col, char row, char font, int color) // draw a text string
4180_1 1:8b656995301f 209 {
4180_1 1:8b656995301f 210
4180_1 1:8b656995301f 211 char command[1000]= "";
4180_1 1:8b656995301f 212 int size = strlen(s);
4180_1 1:8b656995301f 213 int i = 0;
4180_1 1:8b656995301f 214
4180_1 1:8b656995301f 215 set_font(font);
4180_1 1:8b656995301f 216
4180_1 1:8b656995301f 217 command[0] = 0xE4; //move cursor
4180_1 1:8b656995301f 218 command[1] = 0;
4180_1 1:8b656995301f 219 command[2] = row;
4180_1 1:8b656995301f 220 command[3] = 0;
4180_1 1:8b656995301f 221 command[4] = col;
4180_1 1:8b656995301f 222 writeCOMMAND(command, 5);
4180_1 1:8b656995301f 223
4180_1 1:8b656995301f 224 command[0] = 0x7F; //set color
4180_1 1:8b656995301f 225 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 1:8b656995301f 226 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 1:8b656995301f 227 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 1:8b656995301f 228
4180_1 1:8b656995301f 229 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 1:8b656995301f 230 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 1:8b656995301f 231 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 232
4180_1 1:8b656995301f 233 command[0] = TEXTSTRING;
4180_1 1:8b656995301f 234 for (i=0; i<size; i++) command[1+i] = s[i];
4180_1 1:8b656995301f 235 command[1+size] = 0;
4180_1 1:8b656995301f 236 writeCOMMANDnull(command, 2 + size);
4180_1 1:8b656995301f 237 }
4180_1 1:8b656995301f 238
4180_1 1:8b656995301f 239
4180_1 1:8b656995301f 240
4180_1 1:8b656995301f 241 //****************************************************************************************************
4180_1 1:8b656995301f 242 void uLCD_4DGL :: locate(char col, char row) // place text curssor at col, row
4180_1 1:8b656995301f 243 {
4180_1 2:edae99e4abe7 244 char command[5] = "";
4180_1 1:8b656995301f 245 current_col = col;
4180_1 1:8b656995301f 246 current_row = row;
4180_1 7:e39a44de229a 247 command[0] = MOVECURSOR; //move cursor
4180_1 2:edae99e4abe7 248 command[1] = 0;
4180_1 2:edae99e4abe7 249 command[2] = current_row;
4180_1 2:edae99e4abe7 250 command[3] = 0;
4180_1 2:edae99e4abe7 251 command[4] = current_col;
4180_1 2:edae99e4abe7 252 writeCOMMAND(command, 5);
4180_1 1:8b656995301f 253 }
4180_1 1:8b656995301f 254
4180_1 1:8b656995301f 255 //****************************************************************************************************
4180_1 1:8b656995301f 256 void uLCD_4DGL :: color(int color) // set text color
4180_1 1:8b656995301f 257 {
4180_1 2:edae99e4abe7 258 char command[5] = "";
4180_1 1:8b656995301f 259 current_color = color;
4180_1 2:edae99e4abe7 260 command[0] = 0x7F; //set color
4180_1 2:edae99e4abe7 261
4180_1 2:edae99e4abe7 262 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 2:edae99e4abe7 263 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 2:edae99e4abe7 264 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 2:edae99e4abe7 265
4180_1 2:edae99e4abe7 266 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 2:edae99e4abe7 267 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 2:edae99e4abe7 268 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 269 }
4180_1 1:8b656995301f 270
4180_1 1:8b656995301f 271 //****************************************************************************************************
4180_1 2:edae99e4abe7 272 void uLCD_4DGL :: putc(char c) // place char at current cursor position
4180_1 2:edae99e4abe7 273 //used by virtual printf function _putc
4180_1 1:8b656995301f 274 {
4180_1 2:edae99e4abe7 275 char command[6] ="";
4180_1 7:e39a44de229a 276 if(c<0x20) {
4180_1 7:e39a44de229a 277 if(c=='\n') {
4180_1 7:e39a44de229a 278 current_col = 0;
4180_1 7:e39a44de229a 279 current_row++;
4180_1 7:e39a44de229a 280 command[0] = MOVECURSOR; //move cursor to start of next line
4180_1 7:e39a44de229a 281 command[1] = 0;
4180_1 7:e39a44de229a 282 command[2] = current_row;
4180_1 7:e39a44de229a 283 command[3] = 0;
4180_1 7:e39a44de229a 284 command[4] = current_col;
4180_1 7:e39a44de229a 285 writeCOMMAND(command, 5);
4180_1 7:e39a44de229a 286 }
4180_1 7:e39a44de229a 287 if(c=='\r') {
4180_1 7:e39a44de229a 288 current_col = 0;
4180_1 7:e39a44de229a 289 command[0] = MOVECURSOR; //move cursor to start of line
4180_1 7:e39a44de229a 290 command[1] = 0;
4180_1 7:e39a44de229a 291 command[2] = current_row;
4180_1 7:e39a44de229a 292 command[3] = 0;
4180_1 7:e39a44de229a 293 command[4] = current_col;
4180_1 7:e39a44de229a 294 writeCOMMAND(command, 5);
4180_1 7:e39a44de229a 295 }
4180_1 7:e39a44de229a 296 if(c=='\f') {
4180_1 7:e39a44de229a 297 uLCD_4DGL::cls(); //clear screen on form feed
4180_1 7:e39a44de229a 298 }
4180_1 2:edae99e4abe7 299 } else {
4180_1 2:edae99e4abe7 300 command[0] = PUTCHAR;
4180_1 2:edae99e4abe7 301 command[1] = 0x00;
4180_1 2:edae99e4abe7 302 command[2] = c;
4180_1 2:edae99e4abe7 303 writeCOMMAND(command,3);
4180_1 7:e39a44de229a 304 current_col++;
4180_1 2:edae99e4abe7 305 }
4180_1 1:8b656995301f 306 if (current_col == max_col) {
4180_1 1:8b656995301f 307 current_col = 0;
4180_1 1:8b656995301f 308 current_row++;
4180_1 7:e39a44de229a 309 command[0] = MOVECURSOR; //move cursor to next line
4180_1 2:edae99e4abe7 310 command[1] = 0;
4180_1 2:edae99e4abe7 311 command[2] = current_row;
4180_1 2:edae99e4abe7 312 command[3] = 0;
4180_1 2:edae99e4abe7 313 command[4] = current_col;
4180_1 2:edae99e4abe7 314 writeCOMMAND(command, 5);
4180_1 1:8b656995301f 315 }
4180_1 1:8b656995301f 316 if (current_row == max_row) {
4180_1 1:8b656995301f 317 current_row = 0;
4180_1 7:e39a44de229a 318 command[0] = MOVECURSOR; //move cursor back to start
4180_1 2:edae99e4abe7 319 command[1] = 0;
4180_1 2:edae99e4abe7 320 command[2] = current_row;
4180_1 2:edae99e4abe7 321 command[3] = 0;
4180_1 2:edae99e4abe7 322 command[4] = current_col;
4180_1 2:edae99e4abe7 323 writeCOMMAND(command, 5);
4180_1 1:8b656995301f 324 }
4180_1 1:8b656995301f 325 }
4180_1 1:8b656995301f 326
4180_1 2:edae99e4abe7 327
4180_1 1:8b656995301f 328 //****************************************************************************************************
4180_1 1:8b656995301f 329 void uLCD_4DGL :: puts(char *s) // place string at current cursor position
4180_1 1:8b656995301f 330 {
4180_1 1:8b656995301f 331
4180_1 1:8b656995301f 332 text_string(s, current_col, current_row, current_font, current_color);
4180_1 1:8b656995301f 333
4180_1 1:8b656995301f 334 current_col += strlen(s);
4180_1 1:8b656995301f 335
4180_1 1:8b656995301f 336 if (current_col >= max_col) {
4180_1 1:8b656995301f 337 current_row += current_col / max_col;
4180_1 1:8b656995301f 338 current_col %= max_col;
4180_1 1:8b656995301f 339 }
4180_1 1:8b656995301f 340 if (current_row >= max_row) {
4180_1 1:8b656995301f 341 current_row %= max_row;
4180_1 1:8b656995301f 342 }
4180_1 1:8b656995301f 343 }