for 4180 final project

Fork of 4DGL-uLCD-SE by jim hamblen

Committer:
bkf34
Date:
Wed Apr 22 03:16:54 2015 +0000
Revision:
8:9a943cbbad5b
Parent:
7:e39a44de229a
final;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 1:8b656995301f 1 //
4180_1 2:edae99e4abe7 2 // uLCD_4DGL is a class to drive 4D Systems uLCD 144 G2
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 #define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0])
4180_1 1:8b656995301f 24
4180_1 1:8b656995301f 25 //Serial pc(USBTX,USBRX);
4180_1 1:8b656995301f 26
4180_1 5:8936798c19a3 27
4180_1 1:8b656995301f 28 //******************************************************************************************************
4180_1 1:8b656995301f 29 uLCD_4DGL :: uLCD_4DGL(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx),
4180_1 1:8b656995301f 30 _rst(rst)
4180_1 1:8b656995301f 31 #if DEBUGMODE
4180_1 1:8b656995301f 32 ,pc(USBTX, USBRX)
4180_1 1:8b656995301f 33 #endif // DEBUGMODE
4180_1 1:8b656995301f 34 {
4180_1 1:8b656995301f 35 // Constructor
4180_1 1:8b656995301f 36 _cmd.baud(9600);
4180_1 1:8b656995301f 37 #if DEBUGMODE
4180_1 1:8b656995301f 38 pc.baud(115200);
4180_1 1:8b656995301f 39
4180_1 1:8b656995301f 40 pc.printf("\n\n\n");
4180_1 1:8b656995301f 41 pc.printf("*********************\n");
4180_1 1:8b656995301f 42 pc.printf("uLCD_4DGL CONSTRUCTOR\n");
4180_1 1:8b656995301f 43 pc.printf("*********************\n");
4180_1 1:8b656995301f 44 #endif
4180_1 1:8b656995301f 45
4180_1 1:8b656995301f 46 _rst = 1; // put RESET pin to high to start TFT screen
4180_1 1:8b656995301f 47 reset();
4180_1 1:8b656995301f 48 cls(); // clear screen
4180_1 1:8b656995301f 49 current_col = 0; // initial cursor col
4180_1 1:8b656995301f 50 current_row = 0; // initial cursor row
4180_1 1:8b656995301f 51 current_color = WHITE; // initial text color
4180_1 1:8b656995301f 52 current_orientation = IS_PORTRAIT; // initial screen orientation
4180_1 2:edae99e4abe7 53 current_hf = 1;
4180_1 2:edae99e4abe7 54 current_wf = 1;
4180_1 2:edae99e4abe7 55 set_font(FONT_7X8); // initial font
4180_1 1:8b656995301f 56 // text_mode(OPAQUE); // initial texr mode
4180_1 1:8b656995301f 57 }
4180_1 1:8b656995301f 58
4180_1 1:8b656995301f 59 //******************************************************************************************************
4180_1 1:8b656995301f 60 void uLCD_4DGL :: writeBYTE(char c) // send a BYTE command to screen
4180_1 1:8b656995301f 61 {
4180_1 1:8b656995301f 62
4180_1 1:8b656995301f 63 _cmd.putc(c);
4180_1 7:e39a44de229a 64 wait_us(500); //mbed is too fast for LCD at high baud rates in some long commands
4180_1 1:8b656995301f 65
4180_1 1:8b656995301f 66 #if DEBUGMODE
4180_1 1:8b656995301f 67 pc.printf(" Char sent : 0x%02X\n",c);
4180_1 1:8b656995301f 68 #endif
4180_1 1:8b656995301f 69
4180_1 1:8b656995301f 70 }
4180_1 1:8b656995301f 71
4180_1 1:8b656995301f 72 //******************************************************************************************************
4180_1 4:74df7fc26fef 73 void uLCD_4DGL :: writeBYTEfast(char c) // send a BYTE command to screen
4180_1 4:74df7fc26fef 74 {
4180_1 4:74df7fc26fef 75
4180_1 4:74df7fc26fef 76 _cmd.putc(c);
4180_1 7:e39a44de229a 77 //wait_ms(0.0); //mbed is too fast for LCD at high baud rates - but not in short commands
4180_1 4:74df7fc26fef 78
4180_1 4:74df7fc26fef 79 #if DEBUGMODE
4180_1 4:74df7fc26fef 80 pc.printf(" Char sent : 0x%02X\n",c);
4180_1 4:74df7fc26fef 81 #endif
4180_1 4:74df7fc26fef 82
4180_1 4:74df7fc26fef 83 }
4180_1 4:74df7fc26fef 84 //******************************************************************************************************
4180_1 1:8b656995301f 85 void uLCD_4DGL :: freeBUFFER(void) // Clear serial buffer before writing command
4180_1 1:8b656995301f 86 {
4180_1 1:8b656995301f 87
4180_1 1:8b656995301f 88 while (_cmd.readable()) _cmd.getc(); // clear buffer garbage
4180_1 1:8b656995301f 89 }
4180_1 1:8b656995301f 90
4180_1 1:8b656995301f 91 //******************************************************************************************************
4180_1 1:8b656995301f 92 int uLCD_4DGL :: writeCOMMAND(char *command, int number) // send several BYTES making a command and return an answer
4180_1 1:8b656995301f 93 {
4180_1 1:8b656995301f 94
4180_1 1:8b656995301f 95 #if DEBUGMODE
4180_1 1:8b656995301f 96 pc.printf("\n");
4180_1 1:8b656995301f 97 pc.printf("New COMMAND : 0x%02X\n", command[0]);
4180_1 1:8b656995301f 98 #endif
4180_1 1:8b656995301f 99 int i, resp = 0;
4180_1 1:8b656995301f 100 freeBUFFER();
4180_1 1:8b656995301f 101 writeBYTE(0xFF);
4180_1 4:74df7fc26fef 102 for (i = 0; i < number; i++) {
4180_1 4:74df7fc26fef 103 if (i<16)
4180_1 4:74df7fc26fef 104 writeBYTEfast(command[i]); // send command to serial port
4180_1 4:74df7fc26fef 105 else
4180_1 4:74df7fc26fef 106 writeBYTE(command[i]); // send command to serial port but slower
4180_1 4:74df7fc26fef 107 }
4180_1 1:8b656995301f 108 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 109 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
4180_1 1:8b656995301f 110 switch (resp) {
4180_1 1:8b656995301f 111 case ACK : // if OK return 1
4180_1 1:8b656995301f 112 resp = 1;
4180_1 1:8b656995301f 113 break;
4180_1 1:8b656995301f 114 case NAK : // if NOK return -1
4180_1 1:8b656995301f 115 resp = -1;
4180_1 1:8b656995301f 116 break;
4180_1 1:8b656995301f 117 default :
4180_1 1:8b656995301f 118 resp = 0; // else return 0
4180_1 1:8b656995301f 119 break;
4180_1 1:8b656995301f 120 }
4180_1 1:8b656995301f 121 #if DEBUGMODE
4180_1 1:8b656995301f 122 pc.printf(" Answer received : %d\n",resp);
4180_1 1:8b656995301f 123 #endif
4180_1 1:8b656995301f 124
4180_1 1:8b656995301f 125 return resp;
4180_1 1:8b656995301f 126 }
4180_1 1:8b656995301f 127
4180_1 1:8b656995301f 128 //**************************************************************************
4180_1 1:8b656995301f 129 void uLCD_4DGL :: reset() // Reset Screen
4180_1 1:8b656995301f 130 {
4180_1 5:8936798c19a3 131 wait_ms(5);
4180_1 1:8b656995301f 132 _rst = 0; // put RESET pin to low
4180_1 5:8936798c19a3 133 wait_ms(5); // wait a few milliseconds for command reception
4180_1 1:8b656995301f 134 _rst = 1; // put RESET back to high
4180_1 1:8b656995301f 135 wait(3); // wait 3s for screen to restart
4180_1 1:8b656995301f 136
4180_1 1:8b656995301f 137 freeBUFFER(); // clean buffer from possible garbage
4180_1 1:8b656995301f 138 }
4180_1 1:8b656995301f 139 //******************************************************************************************************
4180_1 1:8b656995301f 140 int uLCD_4DGL :: writeCOMMANDnull(char *command, int number) // send several BYTES making a command and return an answer
4180_1 1:8b656995301f 141 {
4180_1 1:8b656995301f 142
4180_1 1:8b656995301f 143 #if DEBUGMODE
4180_1 1:8b656995301f 144 pc.printf("\n");
4180_1 1:8b656995301f 145 pc.printf("New COMMAND : 0x%02X\n", command[0]);
4180_1 1:8b656995301f 146 #endif
4180_1 1:8b656995301f 147 int i, resp = 0;
4180_1 1:8b656995301f 148 freeBUFFER();
4180_1 2:edae99e4abe7 149 writeBYTE(0x00); //command has a null prefix byte
4180_1 4:74df7fc26fef 150 for (i = 0; i < number; i++) {
4180_1 7:e39a44de229a 151 if (i<16) //don't overflow LCD UART buffer
4180_1 4:74df7fc26fef 152 writeBYTEfast(command[i]); // send command to serial port
4180_1 4:74df7fc26fef 153 else
4180_1 7:e39a44de229a 154 writeBYTE(command[i]); // send command to serial port with delay
4180_1 4:74df7fc26fef 155 }
4180_1 1:8b656995301f 156 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 157 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
4180_1 1:8b656995301f 158 switch (resp) {
4180_1 1:8b656995301f 159 case ACK : // if OK return 1
4180_1 1:8b656995301f 160 resp = 1;
4180_1 1:8b656995301f 161 break;
4180_1 1:8b656995301f 162 case NAK : // if NOK return -1
4180_1 1:8b656995301f 163 resp = -1;
4180_1 1:8b656995301f 164 break;
4180_1 1:8b656995301f 165 default :
4180_1 1:8b656995301f 166 resp = 0; // else return 0
4180_1 1:8b656995301f 167 break;
4180_1 1:8b656995301f 168 }
4180_1 1:8b656995301f 169 #if DEBUGMODE
4180_1 1:8b656995301f 170 pc.printf(" Answer received : %d\n",resp);
4180_1 1:8b656995301f 171 #endif
4180_1 1:8b656995301f 172
4180_1 1:8b656995301f 173 return resp;
4180_1 1:8b656995301f 174 }
4180_1 1:8b656995301f 175
4180_1 1:8b656995301f 176 //**************************************************************************
4180_1 1:8b656995301f 177 void uLCD_4DGL :: cls() // clear screen
4180_1 1:8b656995301f 178 {
4180_1 1:8b656995301f 179 char command[1] = "";
4180_1 1:8b656995301f 180
4180_1 1:8b656995301f 181 command[0] = CLS;
4180_1 1:8b656995301f 182 writeCOMMAND(command, 1);
4180_1 7:e39a44de229a 183 current_row=0;
4180_1 7:e39a44de229a 184 current_col=0;
4180_1 2:edae99e4abe7 185 current_hf = 1;
4180_1 2:edae99e4abe7 186 current_wf = 1;
4180_1 2:edae99e4abe7 187 set_font(FONT_7X8); // initial font
4180_1 1:8b656995301f 188 }
4180_1 1:8b656995301f 189
4180_1 1:8b656995301f 190 //**************************************************************************
4180_1 7:e39a44de229a 191 int uLCD_4DGL :: version() // get API version
4180_1 1:8b656995301f 192 {
4180_1 7:e39a44de229a 193
4180_1 1:8b656995301f 194 char command[2] = "";
4180_1 7:e39a44de229a 195 command[0] = '\x00';
4180_1 7:e39a44de229a 196 command[1] = VERSION;
4180_1 7:e39a44de229a 197 return readVERSION(command, 2);
4180_1 1:8b656995301f 198 }
4180_1 1:8b656995301f 199
4180_1 1:8b656995301f 200 //**************************************************************************
4180_1 1:8b656995301f 201 void uLCD_4DGL :: baudrate(int speed) // set screen baud rate
4180_1 1:8b656995301f 202 {
4180_1 1:8b656995301f 203 char command[3]= "";
4180_1 1:8b656995301f 204 writeBYTE(0x00);
4180_1 1:8b656995301f 205 command[0] = BAUDRATE;
4180_1 1:8b656995301f 206 command[1] = 0;
4180_1 1:8b656995301f 207 int newbaud = BAUD_9600;
4180_1 1:8b656995301f 208 switch (speed) {
4180_1 1:8b656995301f 209 case 110 :
4180_1 1:8b656995301f 210 newbaud = BAUD_110;
4180_1 1:8b656995301f 211 break;
4180_1 1:8b656995301f 212 case 300 :
4180_1 1:8b656995301f 213 newbaud = BAUD_300;
4180_1 1:8b656995301f 214 break;
4180_1 1:8b656995301f 215 case 600 :
4180_1 1:8b656995301f 216 newbaud = BAUD_600;
4180_1 1:8b656995301f 217 break;
4180_1 1:8b656995301f 218 case 1200 :
4180_1 1:8b656995301f 219 newbaud = BAUD_1200;
4180_1 1:8b656995301f 220 break;
4180_1 1:8b656995301f 221 case 2400 :
4180_1 1:8b656995301f 222 newbaud = BAUD_2400;
4180_1 1:8b656995301f 223 break;
4180_1 1:8b656995301f 224 case 4800 :
4180_1 1:8b656995301f 225 newbaud = BAUD_4800;
4180_1 1:8b656995301f 226 break;
4180_1 1:8b656995301f 227 case 9600 :
4180_1 4:74df7fc26fef 228 newbaud = BAUD_9600;
4180_1 1:8b656995301f 229 break;
4180_1 1:8b656995301f 230 case 14400 :
4180_1 1:8b656995301f 231 newbaud = BAUD_14400;
4180_1 1:8b656995301f 232 break;
4180_1 1:8b656995301f 233 case 19200 :
4180_1 1:8b656995301f 234 newbaud = BAUD_19200;
4180_1 1:8b656995301f 235 break;
4180_1 1:8b656995301f 236 case 31250 :
4180_1 1:8b656995301f 237 newbaud = BAUD_31250;
4180_1 1:8b656995301f 238 break;
4180_1 1:8b656995301f 239 case 38400 :
4180_1 1:8b656995301f 240 newbaud = BAUD_38400;
4180_1 1:8b656995301f 241 break;
4180_1 1:8b656995301f 242 case 56000 :
4180_1 1:8b656995301f 243 newbaud = BAUD_56000;
4180_1 1:8b656995301f 244 break;
4180_1 1:8b656995301f 245 case 57600 :
4180_1 1:8b656995301f 246 newbaud = BAUD_57600;
4180_1 1:8b656995301f 247 break;
4180_1 1:8b656995301f 248 case 115200 :
4180_1 1:8b656995301f 249 newbaud = BAUD_115200;
4180_1 1:8b656995301f 250 break;
4180_1 1:8b656995301f 251 case 128000 :
4180_1 1:8b656995301f 252 newbaud = BAUD_128000;
4180_1 1:8b656995301f 253 break;
4180_1 1:8b656995301f 254 case 256000 :
4180_1 1:8b656995301f 255 newbaud = BAUD_256000;
4180_1 1:8b656995301f 256 break;
4180_1 5:8936798c19a3 257 case 300000 :
4180_1 5:8936798c19a3 258 newbaud = BAUD_300000;
4180_1 5:8936798c19a3 259 speed = 272727;
4180_1 5:8936798c19a3 260 break;
4180_1 5:8936798c19a3 261 case 375000 :
4180_1 5:8936798c19a3 262 newbaud = BAUD_375000;
4180_1 5:8936798c19a3 263 speed = 333333;
4180_1 5:8936798c19a3 264 break;
4180_1 5:8936798c19a3 265 case 500000 :
4180_1 5:8936798c19a3 266 newbaud = BAUD_500000;
4180_1 5:8936798c19a3 267 speed = 428571;
4180_1 5:8936798c19a3 268 break;
4180_1 5:8936798c19a3 269 case 600000 :
4180_1 5:8936798c19a3 270 newbaud = BAUD_600000;
4180_1 5:8936798c19a3 271 break;
4180_1 7:e39a44de229a 272 case 750000 : //rates over 600000 are not documented, but seem to work
4180_1 7:e39a44de229a 273 newbaud = BAUD_750000;
4180_1 7:e39a44de229a 274 break;
4180_1 7:e39a44de229a 275 case 1000000 :
4180_1 7:e39a44de229a 276 newbaud = BAUD_1000000;
4180_1 7:e39a44de229a 277 break;
4180_1 7:e39a44de229a 278 case 1500000 :
4180_1 7:e39a44de229a 279 newbaud = BAUD_1500000;
4180_1 7:e39a44de229a 280 break;
4180_1 7:e39a44de229a 281 case 3000000 :
4180_1 7:e39a44de229a 282 newbaud = BAUD_3000000;
4180_1 7:e39a44de229a 283 break;
4180_1 1:8b656995301f 284 default :
4180_1 1:8b656995301f 285 newbaud = BAUD_9600;
4180_1 1:8b656995301f 286 speed = 9600;
4180_1 1:8b656995301f 287 break;
4180_1 1:8b656995301f 288 }
4180_1 1:8b656995301f 289
4180_1 1:8b656995301f 290 int i, resp = 0;
4180_1 1:8b656995301f 291
4180_1 1:8b656995301f 292 freeBUFFER();
4180_1 1:8b656995301f 293 command[1] = char(newbaud >>8);
4180_1 1:8b656995301f 294 command[2] = char(newbaud % 256);
4180_1 5:8936798c19a3 295 wait_ms(1);
4180_1 5:8936798c19a3 296 for (i = 0; i <3; i++) writeBYTEfast(command[i]); // send command to serial port
4180_1 7:e39a44de229a 297 for (i = 0; i<10; i++) wait_ms(1);
4180_1 7:e39a44de229a 298 //dont change baud until all characters get sent out
4180_1 1:8b656995301f 299 _cmd.baud(speed); // set mbed to same speed
4180_1 5:8936798c19a3 300 i=0;
4180_1 5:8936798c19a3 301 while ((!_cmd.readable()) && (i<25000)) {
4180_1 5:8936798c19a3 302 wait_ms(TEMPO); // wait for screen answer - comes 100ms after change
4180_1 5:8936798c19a3 303 i++; //timeout if ack character missed by baud change
4180_1 5:8936798c19a3 304 }
4180_1 1:8b656995301f 305 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
4180_1 1:8b656995301f 306 switch (resp) {
4180_1 1:8b656995301f 307 case ACK : // if OK return 1
4180_1 1:8b656995301f 308 resp = 1;
4180_1 1:8b656995301f 309 break;
4180_1 1:8b656995301f 310 case NAK : // if NOK return -1
4180_1 1:8b656995301f 311 resp = -1;
4180_1 1:8b656995301f 312 break;
4180_1 1:8b656995301f 313 default :
4180_1 1:8b656995301f 314 resp = 0; // else return 0
4180_1 1:8b656995301f 315 break;
4180_1 1:8b656995301f 316 }
4180_1 1:8b656995301f 317 }
4180_1 1:8b656995301f 318
4180_1 1:8b656995301f 319 //******************************************************************************************************
4180_1 1:8b656995301f 320 int uLCD_4DGL :: readVERSION(char *command, int number) // read screen info and populate data
4180_1 1:8b656995301f 321 {
4180_1 1:8b656995301f 322
4180_1 1:8b656995301f 323 int i, temp = 0, resp = 0;
4180_1 1:8b656995301f 324 char response[5] = "";
4180_1 1:8b656995301f 325
4180_1 1:8b656995301f 326 freeBUFFER();
4180_1 1:8b656995301f 327
4180_1 1:8b656995301f 328 for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
4180_1 1:8b656995301f 329
4180_1 1:8b656995301f 330 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 331
4180_1 1:8b656995301f 332 while (_cmd.readable() && resp < ARRAY_SIZE(response)) {
4180_1 1:8b656995301f 333 temp = _cmd.getc();
4180_1 1:8b656995301f 334 response[resp++] = (char)temp;
4180_1 1:8b656995301f 335 }
4180_1 1:8b656995301f 336 switch (resp) {
4180_1 6:b759b69cbaf9 337 case 2 : // if OK populate data and return 1
4180_1 6:b759b69cbaf9 338 revision = response[0]<<8 + response[1];
4180_1 1:8b656995301f 339 resp = 1;
4180_1 1:8b656995301f 340 break;
4180_1 1:8b656995301f 341 default :
4180_1 1:8b656995301f 342 resp = 0; // else return 0
4180_1 1:8b656995301f 343 break;
4180_1 1:8b656995301f 344 }
4180_1 1:8b656995301f 345 return resp;
4180_1 1:8b656995301f 346 }
4180_1 1:8b656995301f 347
4180_1 1:8b656995301f 348 //****************************************************************************************************
4180_1 1:8b656995301f 349 void uLCD_4DGL :: background_color(int color) // set screen background color
4180_1 1:8b656995301f 350 {
4180_1 1:8b656995301f 351 char command[3]= ""; // input color is in 24bits like 0xRRGGBB
4180_1 1:8b656995301f 352
4180_1 1:8b656995301f 353 command[0] = BCKGDCOLOR;
4180_1 1:8b656995301f 354
4180_1 1:8b656995301f 355 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 1:8b656995301f 356 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 1:8b656995301f 357 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 1:8b656995301f 358
4180_1 1:8b656995301f 359 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 1:8b656995301f 360 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 1:8b656995301f 361
4180_1 1:8b656995301f 362 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 363 }
4180_1 1:8b656995301f 364
4180_1 1:8b656995301f 365 //****************************************************************************************************
4180_1 2:edae99e4abe7 366 void uLCD_4DGL :: textbackground_color(int color) // set screen background color
4180_1 2:edae99e4abe7 367 {
4180_1 2:edae99e4abe7 368 char command[3]= ""; // input color is in 24bits like 0xRRGGBB
4180_1 2:edae99e4abe7 369
4180_1 2:edae99e4abe7 370 command[0] = TXTBCKGDCOLOR;
4180_1 2:edae99e4abe7 371
4180_1 2:edae99e4abe7 372 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 2:edae99e4abe7 373 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 2:edae99e4abe7 374 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 2:edae99e4abe7 375
4180_1 2:edae99e4abe7 376 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 2:edae99e4abe7 377 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 2:edae99e4abe7 378
4180_1 2:edae99e4abe7 379 writeCOMMAND(command, 3);
4180_1 2:edae99e4abe7 380 }
4180_1 2:edae99e4abe7 381
4180_1 2:edae99e4abe7 382 //****************************************************************************************************
4180_1 7:e39a44de229a 383 void uLCD_4DGL :: display_control(char mode) // set screen mode to value
4180_1 1:8b656995301f 384 {
4180_1 1:8b656995301f 385 char command[3]= "";
4180_1 1:8b656995301f 386
4180_1 1:8b656995301f 387 command[0] = DISPCONTROL;
4180_1 7:e39a44de229a 388 command[1] = 0;
4180_1 7:e39a44de229a 389 command[2] = mode;
4180_1 1:8b656995301f 390
4180_1 1:8b656995301f 391 if (mode == ORIENTATION) {
4180_1 7:e39a44de229a 392 switch (mode) {
4180_1 1:8b656995301f 393 case LANDSCAPE :
4180_1 1:8b656995301f 394 current_orientation = IS_LANDSCAPE;
4180_1 1:8b656995301f 395 break;
4180_1 1:8b656995301f 396 case LANDSCAPE_R :
4180_1 1:8b656995301f 397 current_orientation = IS_LANDSCAPE;
4180_1 1:8b656995301f 398 break;
4180_1 1:8b656995301f 399 case PORTRAIT :
4180_1 1:8b656995301f 400 current_orientation = IS_PORTRAIT;
4180_1 1:8b656995301f 401 break;
4180_1 1:8b656995301f 402 case PORTRAIT_R :
4180_1 1:8b656995301f 403 current_orientation = IS_PORTRAIT;
4180_1 1:8b656995301f 404 break;
4180_1 1:8b656995301f 405 }
4180_1 1:8b656995301f 406 }
4180_1 1:8b656995301f 407 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 408 set_font(current_font);
4180_1 1:8b656995301f 409 }
4180_1 7:e39a44de229a 410 //****************************************************************************************************
4180_1 7:e39a44de229a 411 void uLCD_4DGL :: display_power(char mode) // set screen mode to value
4180_1 7:e39a44de229a 412 {
4180_1 7:e39a44de229a 413 char command[3]= "";
4180_1 1:8b656995301f 414
4180_1 7:e39a44de229a 415 command[0] = DISPPOWER;
4180_1 7:e39a44de229a 416 command[1] = 0;
4180_1 7:e39a44de229a 417 command[2] = mode;
4180_1 7:e39a44de229a 418 writeCOMMAND(command, 3);
4180_1 7:e39a44de229a 419 }
4180_1 1:8b656995301f 420 //****************************************************************************************************
4180_1 1:8b656995301f 421 void uLCD_4DGL :: set_volume(char value) // set sound volume to value
4180_1 1:8b656995301f 422 {
4180_1 1:8b656995301f 423 char command[2]= "";
4180_1 1:8b656995301f 424
4180_1 1:8b656995301f 425 command[0] = SETVOLUME;
4180_1 1:8b656995301f 426 command[1] = value;
4180_1 1:8b656995301f 427
4180_1 1:8b656995301f 428 writeCOMMAND(command, 2);
4180_1 1:8b656995301f 429 }
4180_1 1:8b656995301f 430
4180_1 1:8b656995301f 431
4180_1 1:8b656995301f 432 //******************************************************************************************************
4180_1 1:8b656995301f 433 int uLCD_4DGL :: getSTATUS(char *command, int number) // read screen info and populate data
4180_1 1:8b656995301f 434 {
4180_1 1:8b656995301f 435
4180_1 1:8b656995301f 436 #if DEBUGMODE
4180_1 1:8b656995301f 437 pc.printf("\n");
4180_1 1:8b656995301f 438 pc.printf("New COMMAND : 0x%02X\n", command[0]);
4180_1 1:8b656995301f 439 #endif
4180_1 1:8b656995301f 440
4180_1 1:8b656995301f 441 int i, temp = 0, resp = 0;
4180_1 1:8b656995301f 442 char response[5] = "";
4180_1 1:8b656995301f 443
4180_1 1:8b656995301f 444 freeBUFFER();
4180_1 1:8b656995301f 445
4180_1 1:8b656995301f 446 for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
4180_1 1:8b656995301f 447
4180_1 1:8b656995301f 448 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 449
4180_1 1:8b656995301f 450 while (_cmd.readable() && resp < ARRAY_SIZE(response)) {
4180_1 1:8b656995301f 451 temp = _cmd.getc();
4180_1 1:8b656995301f 452 response[resp++] = (char)temp;
4180_1 1:8b656995301f 453 }
4180_1 1:8b656995301f 454 switch (resp) {
4180_1 1:8b656995301f 455 case 4 :
4180_1 1:8b656995301f 456 resp = (int)response[1]; // if OK populate data
4180_1 1:8b656995301f 457 break;
4180_1 1:8b656995301f 458 default :
4180_1 1:8b656995301f 459 resp = -1; // else return 0
4180_1 1:8b656995301f 460 break;
4180_1 1:8b656995301f 461 }
4180_1 1:8b656995301f 462
4180_1 1:8b656995301f 463 #if DEBUGMODE
4180_1 1:8b656995301f 464 pc.printf(" Answer received : %d\n", resp);
4180_1 1:8b656995301f 465 #endif
4180_1 1:8b656995301f 466
4180_1 1:8b656995301f 467 return resp;
4180_1 2:edae99e4abe7 468 }
4180_1 7:e39a44de229a 469