Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 4DGL-uLCD-SE by
uLCD_4DGL_main.cpp@6:b759b69cbaf9, 2013-11-25 (annotated)
- Committer:
- 4180_1
- Date:
- Mon Nov 25 04:24:22 2013 +0000
- Revision:
- 6:b759b69cbaf9
- Parent:
- 5:8936798c19a3
- Child:
- 7:e39a44de229a
ver1.4
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:8b656995301f | 5 | // |
4180_1 | 1:8b656995301f | 6 | // uLCD_4DGL is free software: you can redistribute it and/or modify |
4180_1 | 1:8b656995301f | 7 | // it under the terms of the GNU General Public License as published by |
4180_1 | 1:8b656995301f | 8 | // the Free Software Foundation, either version 3 of the License, or |
4180_1 | 1:8b656995301f | 9 | // (at your option) any later version. |
4180_1 | 1:8b656995301f | 10 | // |
4180_1 | 1:8b656995301f | 11 | // uLCD_4DGL is distributed in the hope that it will be useful, |
4180_1 | 1:8b656995301f | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
4180_1 | 1:8b656995301f | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4180_1 | 1:8b656995301f | 14 | // GNU General Public License for more details. |
4180_1 | 1:8b656995301f | 15 | // |
4180_1 | 1:8b656995301f | 16 | // You should have received a copy of the GNU General Public License |
4180_1 | 1:8b656995301f | 17 | // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. |
4180_1 | 1:8b656995301f | 18 | |
4180_1 | 1:8b656995301f | 19 | #include "mbed.h" |
4180_1 | 1:8b656995301f | 20 | #include "uLCD_4DGL.h" |
4180_1 | 1:8b656995301f | 21 | |
4180_1 | 1:8b656995301f | 22 | #define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0]) |
4180_1 | 1:8b656995301f | 23 | |
4180_1 | 1:8b656995301f | 24 | //Serial pc(USBTX,USBRX); |
4180_1 | 1:8b656995301f | 25 | |
4180_1 | 5:8936798c19a3 | 26 | |
4180_1 | 1:8b656995301f | 27 | //****************************************************************************************************** |
4180_1 | 1:8b656995301f | 28 | uLCD_4DGL :: uLCD_4DGL(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx), |
4180_1 | 1:8b656995301f | 29 | _rst(rst) |
4180_1 | 1:8b656995301f | 30 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 31 | ,pc(USBTX, USBRX) |
4180_1 | 1:8b656995301f | 32 | #endif // DEBUGMODE |
4180_1 | 1:8b656995301f | 33 | { |
4180_1 | 1:8b656995301f | 34 | // Constructor |
4180_1 | 1:8b656995301f | 35 | _cmd.baud(9600); |
4180_1 | 1:8b656995301f | 36 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 37 | pc.baud(115200); |
4180_1 | 1:8b656995301f | 38 | |
4180_1 | 1:8b656995301f | 39 | pc.printf("\n\n\n"); |
4180_1 | 1:8b656995301f | 40 | pc.printf("*********************\n"); |
4180_1 | 1:8b656995301f | 41 | pc.printf("uLCD_4DGL CONSTRUCTOR\n"); |
4180_1 | 1:8b656995301f | 42 | pc.printf("*********************\n"); |
4180_1 | 1:8b656995301f | 43 | #endif |
4180_1 | 1:8b656995301f | 44 | |
4180_1 | 1:8b656995301f | 45 | _rst = 1; // put RESET pin to high to start TFT screen |
4180_1 | 1:8b656995301f | 46 | reset(); |
4180_1 | 1:8b656995301f | 47 | |
4180_1 | 1:8b656995301f | 48 | // autobaud(); // send autobaud command |
4180_1 | 1:8b656995301f | 49 | // version(); // get version information |
4180_1 | 1:8b656995301f | 50 | cls(); // clear screen |
4180_1 | 1:8b656995301f | 51 | |
4180_1 | 1:8b656995301f | 52 | current_col = 0; // initial cursor col |
4180_1 | 1:8b656995301f | 53 | current_row = 0; // initial cursor row |
4180_1 | 1:8b656995301f | 54 | current_color = WHITE; // initial text color |
4180_1 | 1:8b656995301f | 55 | current_orientation = IS_PORTRAIT; // initial screen orientation |
4180_1 | 2:edae99e4abe7 | 56 | current_hf = 1; |
4180_1 | 2:edae99e4abe7 | 57 | current_wf = 1; |
4180_1 | 2:edae99e4abe7 | 58 | set_font(FONT_7X8); // initial font |
4180_1 | 1:8b656995301f | 59 | // text_mode(OPAQUE); // initial texr mode |
4180_1 | 1:8b656995301f | 60 | } |
4180_1 | 1:8b656995301f | 61 | |
4180_1 | 1:8b656995301f | 62 | //****************************************************************************************************** |
4180_1 | 1:8b656995301f | 63 | void uLCD_4DGL :: writeBYTE(char c) // send a BYTE command to screen |
4180_1 | 1:8b656995301f | 64 | { |
4180_1 | 1:8b656995301f | 65 | |
4180_1 | 1:8b656995301f | 66 | _cmd.putc(c); |
4180_1 | 4:74df7fc26fef | 67 | wait_ms(1); //mbed is too fast for LCD at high baud rates in long commands |
4180_1 | 1:8b656995301f | 68 | |
4180_1 | 1:8b656995301f | 69 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 70 | pc.printf(" Char sent : 0x%02X\n",c); |
4180_1 | 1:8b656995301f | 71 | #endif |
4180_1 | 1:8b656995301f | 72 | |
4180_1 | 1:8b656995301f | 73 | } |
4180_1 | 1:8b656995301f | 74 | |
4180_1 | 1:8b656995301f | 75 | //****************************************************************************************************** |
4180_1 | 4:74df7fc26fef | 76 | void uLCD_4DGL :: writeBYTEfast(char c) // send a BYTE command to screen |
4180_1 | 4:74df7fc26fef | 77 | { |
4180_1 | 4:74df7fc26fef | 78 | |
4180_1 | 4:74df7fc26fef | 79 | _cmd.putc(c); |
4180_1 | 4:74df7fc26fef | 80 | //wait_ms(0.0); //mbed is too fast for LCD at high baud rates - but not in some commands |
4180_1 | 4:74df7fc26fef | 81 | |
4180_1 | 4:74df7fc26fef | 82 | #if DEBUGMODE |
4180_1 | 4:74df7fc26fef | 83 | pc.printf(" Char sent : 0x%02X\n",c); |
4180_1 | 4:74df7fc26fef | 84 | #endif |
4180_1 | 4:74df7fc26fef | 85 | |
4180_1 | 4:74df7fc26fef | 86 | } |
4180_1 | 4:74df7fc26fef | 87 | //****************************************************************************************************** |
4180_1 | 1:8b656995301f | 88 | void uLCD_4DGL :: freeBUFFER(void) // Clear serial buffer before writing command |
4180_1 | 1:8b656995301f | 89 | { |
4180_1 | 1:8b656995301f | 90 | |
4180_1 | 1:8b656995301f | 91 | while (_cmd.readable()) _cmd.getc(); // clear buffer garbage |
4180_1 | 1:8b656995301f | 92 | } |
4180_1 | 1:8b656995301f | 93 | |
4180_1 | 1:8b656995301f | 94 | //****************************************************************************************************** |
4180_1 | 1:8b656995301f | 95 | int uLCD_4DGL :: writeCOMMAND(char *command, int number) // send several BYTES making a command and return an answer |
4180_1 | 1:8b656995301f | 96 | { |
4180_1 | 1:8b656995301f | 97 | |
4180_1 | 1:8b656995301f | 98 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 99 | pc.printf("\n"); |
4180_1 | 1:8b656995301f | 100 | pc.printf("New COMMAND : 0x%02X\n", command[0]); |
4180_1 | 1:8b656995301f | 101 | #endif |
4180_1 | 1:8b656995301f | 102 | int i, resp = 0; |
4180_1 | 1:8b656995301f | 103 | freeBUFFER(); |
4180_1 | 1:8b656995301f | 104 | writeBYTE(0xFF); |
4180_1 | 4:74df7fc26fef | 105 | for (i = 0; i < number; i++) { |
4180_1 | 4:74df7fc26fef | 106 | if (i<16) |
4180_1 | 4:74df7fc26fef | 107 | writeBYTEfast(command[i]); // send command to serial port |
4180_1 | 4:74df7fc26fef | 108 | else |
4180_1 | 4:74df7fc26fef | 109 | writeBYTE(command[i]); // send command to serial port but slower |
4180_1 | 4:74df7fc26fef | 110 | } |
4180_1 | 1:8b656995301f | 111 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
4180_1 | 1:8b656995301f | 112 | if (_cmd.readable()) resp = _cmd.getc(); // read response if any |
4180_1 | 1:8b656995301f | 113 | switch (resp) { |
4180_1 | 1:8b656995301f | 114 | case ACK : // if OK return 1 |
4180_1 | 1:8b656995301f | 115 | resp = 1; |
4180_1 | 1:8b656995301f | 116 | break; |
4180_1 | 1:8b656995301f | 117 | case NAK : // if NOK return -1 |
4180_1 | 1:8b656995301f | 118 | resp = -1; |
4180_1 | 1:8b656995301f | 119 | break; |
4180_1 | 1:8b656995301f | 120 | default : |
4180_1 | 1:8b656995301f | 121 | resp = 0; // else return 0 |
4180_1 | 1:8b656995301f | 122 | break; |
4180_1 | 1:8b656995301f | 123 | } |
4180_1 | 1:8b656995301f | 124 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 125 | pc.printf(" Answer received : %d\n",resp); |
4180_1 | 1:8b656995301f | 126 | #endif |
4180_1 | 1:8b656995301f | 127 | |
4180_1 | 1:8b656995301f | 128 | return resp; |
4180_1 | 1:8b656995301f | 129 | } |
4180_1 | 1:8b656995301f | 130 | |
4180_1 | 1:8b656995301f | 131 | //************************************************************************** |
4180_1 | 1:8b656995301f | 132 | void uLCD_4DGL :: reset() // Reset Screen |
4180_1 | 1:8b656995301f | 133 | { |
4180_1 | 5:8936798c19a3 | 134 | wait_ms(5); |
4180_1 | 1:8b656995301f | 135 | _rst = 0; // put RESET pin to low |
4180_1 | 5:8936798c19a3 | 136 | wait_ms(5); // wait a few milliseconds for command reception |
4180_1 | 1:8b656995301f | 137 | _rst = 1; // put RESET back to high |
4180_1 | 1:8b656995301f | 138 | wait(3); // wait 3s for screen to restart |
4180_1 | 1:8b656995301f | 139 | |
4180_1 | 1:8b656995301f | 140 | freeBUFFER(); // clean buffer from possible garbage |
4180_1 | 1:8b656995301f | 141 | } |
4180_1 | 1:8b656995301f | 142 | //****************************************************************************************************** |
4180_1 | 1:8b656995301f | 143 | int uLCD_4DGL :: writeCOMMANDnull(char *command, int number) // send several BYTES making a command and return an answer |
4180_1 | 1:8b656995301f | 144 | { |
4180_1 | 1:8b656995301f | 145 | |
4180_1 | 1:8b656995301f | 146 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 147 | pc.printf("\n"); |
4180_1 | 1:8b656995301f | 148 | pc.printf("New COMMAND : 0x%02X\n", command[0]); |
4180_1 | 1:8b656995301f | 149 | #endif |
4180_1 | 1:8b656995301f | 150 | int i, resp = 0; |
4180_1 | 1:8b656995301f | 151 | freeBUFFER(); |
4180_1 | 2:edae99e4abe7 | 152 | writeBYTE(0x00); //command has a null prefix byte |
4180_1 | 4:74df7fc26fef | 153 | for (i = 0; i < number; i++) { |
4180_1 | 4:74df7fc26fef | 154 | if (i<16) |
4180_1 | 4:74df7fc26fef | 155 | writeBYTEfast(command[i]); // send command to serial port |
4180_1 | 4:74df7fc26fef | 156 | else |
4180_1 | 4:74df7fc26fef | 157 | writeBYTE(command[i]); // send command to serial port |
4180_1 | 4:74df7fc26fef | 158 | } |
4180_1 | 1:8b656995301f | 159 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
4180_1 | 1:8b656995301f | 160 | if (_cmd.readable()) resp = _cmd.getc(); // read response if any |
4180_1 | 1:8b656995301f | 161 | switch (resp) { |
4180_1 | 1:8b656995301f | 162 | case ACK : // if OK return 1 |
4180_1 | 1:8b656995301f | 163 | resp = 1; |
4180_1 | 1:8b656995301f | 164 | break; |
4180_1 | 1:8b656995301f | 165 | case NAK : // if NOK return -1 |
4180_1 | 1:8b656995301f | 166 | resp = -1; |
4180_1 | 1:8b656995301f | 167 | break; |
4180_1 | 1:8b656995301f | 168 | default : |
4180_1 | 1:8b656995301f | 169 | resp = 0; // else return 0 |
4180_1 | 1:8b656995301f | 170 | break; |
4180_1 | 1:8b656995301f | 171 | } |
4180_1 | 1:8b656995301f | 172 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 173 | pc.printf(" Answer received : %d\n",resp); |
4180_1 | 1:8b656995301f | 174 | #endif |
4180_1 | 1:8b656995301f | 175 | |
4180_1 | 1:8b656995301f | 176 | return resp; |
4180_1 | 1:8b656995301f | 177 | } |
4180_1 | 1:8b656995301f | 178 | |
4180_1 | 1:8b656995301f | 179 | |
4180_1 | 1:8b656995301f | 180 | //************************************************************************** |
4180_1 | 1:8b656995301f | 181 | void uLCD_4DGL :: autobaud() // send AutoBaud command (9600) |
4180_1 | 1:8b656995301f | 182 | { |
4180_1 | 1:8b656995301f | 183 | writeBYTE(AUTOBAUD); |
4180_1 | 1:8b656995301f | 184 | char command[1] = ""; |
4180_1 | 1:8b656995301f | 185 | command[0] = AUTOBAUD; |
4180_1 | 1:8b656995301f | 186 | writeCOMMAND(command, 1); |
4180_1 | 1:8b656995301f | 187 | } |
4180_1 | 1:8b656995301f | 188 | |
4180_1 | 1:8b656995301f | 189 | //************************************************************************** |
4180_1 | 1:8b656995301f | 190 | void uLCD_4DGL :: cls() // clear screen |
4180_1 | 1:8b656995301f | 191 | { |
4180_1 | 1:8b656995301f | 192 | char command[1] = ""; |
4180_1 | 1:8b656995301f | 193 | |
4180_1 | 1:8b656995301f | 194 | command[0] = CLS; |
4180_1 | 1:8b656995301f | 195 | writeCOMMAND(command, 1); |
4180_1 | 2:edae99e4abe7 | 196 | current_hf = 1; |
4180_1 | 2:edae99e4abe7 | 197 | current_wf = 1; |
4180_1 | 2:edae99e4abe7 | 198 | set_font(FONT_7X8); // initial font |
4180_1 | 1:8b656995301f | 199 | } |
4180_1 | 1:8b656995301f | 200 | |
4180_1 | 1:8b656995301f | 201 | //************************************************************************** |
4180_1 | 1:8b656995301f | 202 | void uLCD_4DGL :: version() // get API version |
4180_1 | 1:8b656995301f | 203 | { |
4180_1 | 1:8b656995301f | 204 | char command[2] = ""; |
4180_1 | 1:8b656995301f | 205 | command[0] = VERSION; |
4180_1 | 1:8b656995301f | 206 | command[1] = OFF; |
4180_1 | 1:8b656995301f | 207 | readVERSION(command, 2); |
4180_1 | 1:8b656995301f | 208 | } |
4180_1 | 1:8b656995301f | 209 | |
4180_1 | 1:8b656995301f | 210 | //************************************************************************** |
4180_1 | 1:8b656995301f | 211 | void uLCD_4DGL :: baudrate(int speed) // set screen baud rate |
4180_1 | 1:8b656995301f | 212 | { |
4180_1 | 1:8b656995301f | 213 | char command[3]= ""; |
4180_1 | 1:8b656995301f | 214 | writeBYTE(0x00); |
4180_1 | 1:8b656995301f | 215 | command[0] = BAUDRATE; |
4180_1 | 1:8b656995301f | 216 | command[1] = 0; |
4180_1 | 1:8b656995301f | 217 | int newbaud = BAUD_9600; |
4180_1 | 1:8b656995301f | 218 | switch (speed) { |
4180_1 | 1:8b656995301f | 219 | case 110 : |
4180_1 | 1:8b656995301f | 220 | newbaud = BAUD_110; |
4180_1 | 1:8b656995301f | 221 | break; |
4180_1 | 1:8b656995301f | 222 | case 300 : |
4180_1 | 1:8b656995301f | 223 | newbaud = BAUD_300; |
4180_1 | 1:8b656995301f | 224 | break; |
4180_1 | 1:8b656995301f | 225 | case 600 : |
4180_1 | 1:8b656995301f | 226 | newbaud = BAUD_600; |
4180_1 | 1:8b656995301f | 227 | break; |
4180_1 | 1:8b656995301f | 228 | case 1200 : |
4180_1 | 1:8b656995301f | 229 | newbaud = BAUD_1200; |
4180_1 | 1:8b656995301f | 230 | break; |
4180_1 | 1:8b656995301f | 231 | case 2400 : |
4180_1 | 1:8b656995301f | 232 | newbaud = BAUD_2400; |
4180_1 | 1:8b656995301f | 233 | break; |
4180_1 | 1:8b656995301f | 234 | case 4800 : |
4180_1 | 1:8b656995301f | 235 | newbaud = BAUD_4800; |
4180_1 | 1:8b656995301f | 236 | break; |
4180_1 | 1:8b656995301f | 237 | case 9600 : |
4180_1 | 4:74df7fc26fef | 238 | newbaud = BAUD_9600; |
4180_1 | 1:8b656995301f | 239 | break; |
4180_1 | 1:8b656995301f | 240 | case 14400 : |
4180_1 | 1:8b656995301f | 241 | newbaud = BAUD_14400; |
4180_1 | 1:8b656995301f | 242 | break; |
4180_1 | 1:8b656995301f | 243 | case 19200 : |
4180_1 | 1:8b656995301f | 244 | newbaud = BAUD_19200; |
4180_1 | 1:8b656995301f | 245 | break; |
4180_1 | 1:8b656995301f | 246 | case 31250 : |
4180_1 | 1:8b656995301f | 247 | newbaud = BAUD_31250; |
4180_1 | 1:8b656995301f | 248 | break; |
4180_1 | 1:8b656995301f | 249 | case 38400 : |
4180_1 | 1:8b656995301f | 250 | newbaud = BAUD_38400; |
4180_1 | 1:8b656995301f | 251 | break; |
4180_1 | 1:8b656995301f | 252 | case 56000 : |
4180_1 | 1:8b656995301f | 253 | newbaud = BAUD_56000; |
4180_1 | 1:8b656995301f | 254 | break; |
4180_1 | 1:8b656995301f | 255 | case 57600 : |
4180_1 | 1:8b656995301f | 256 | newbaud = BAUD_57600; |
4180_1 | 1:8b656995301f | 257 | break; |
4180_1 | 1:8b656995301f | 258 | case 115200 : |
4180_1 | 1:8b656995301f | 259 | newbaud = BAUD_115200; |
4180_1 | 1:8b656995301f | 260 | break; |
4180_1 | 1:8b656995301f | 261 | case 128000 : |
4180_1 | 1:8b656995301f | 262 | newbaud = BAUD_128000; |
4180_1 | 1:8b656995301f | 263 | break; |
4180_1 | 1:8b656995301f | 264 | case 256000 : |
4180_1 | 1:8b656995301f | 265 | newbaud = BAUD_256000; |
4180_1 | 1:8b656995301f | 266 | break; |
4180_1 | 5:8936798c19a3 | 267 | case 300000 : |
4180_1 | 5:8936798c19a3 | 268 | newbaud = BAUD_300000; |
4180_1 | 5:8936798c19a3 | 269 | speed = 272727; |
4180_1 | 5:8936798c19a3 | 270 | break; |
4180_1 | 5:8936798c19a3 | 271 | case 375000 : |
4180_1 | 5:8936798c19a3 | 272 | newbaud = BAUD_375000; |
4180_1 | 5:8936798c19a3 | 273 | speed = 333333; |
4180_1 | 5:8936798c19a3 | 274 | break; |
4180_1 | 5:8936798c19a3 | 275 | case 500000 : |
4180_1 | 5:8936798c19a3 | 276 | newbaud = BAUD_500000; |
4180_1 | 5:8936798c19a3 | 277 | speed = 428571; |
4180_1 | 5:8936798c19a3 | 278 | break; |
4180_1 | 5:8936798c19a3 | 279 | case 600000 : |
4180_1 | 5:8936798c19a3 | 280 | newbaud = BAUD_600000; |
4180_1 | 5:8936798c19a3 | 281 | break; |
4180_1 | 1:8b656995301f | 282 | default : |
4180_1 | 1:8b656995301f | 283 | newbaud = BAUD_9600; |
4180_1 | 1:8b656995301f | 284 | speed = 9600; |
4180_1 | 1:8b656995301f | 285 | break; |
4180_1 | 1:8b656995301f | 286 | } |
4180_1 | 1:8b656995301f | 287 | |
4180_1 | 1:8b656995301f | 288 | int i, resp = 0; |
4180_1 | 1:8b656995301f | 289 | |
4180_1 | 1:8b656995301f | 290 | freeBUFFER(); |
4180_1 | 1:8b656995301f | 291 | command[1] = char(newbaud >>8); |
4180_1 | 1:8b656995301f | 292 | command[2] = char(newbaud % 256); |
4180_1 | 5:8936798c19a3 | 293 | wait_ms(1); |
4180_1 | 5:8936798c19a3 | 294 | for (i = 0; i <3; i++) writeBYTEfast(command[i]); // send command to serial port |
4180_1 | 5:8936798c19a3 | 295 | wait_ms(10); //dont change baud until all characters get sent out |
4180_1 | 1:8b656995301f | 296 | _cmd.baud(speed); // set mbed to same speed |
4180_1 | 5:8936798c19a3 | 297 | i=0; |
4180_1 | 5:8936798c19a3 | 298 | while ((!_cmd.readable()) && (i<25000)) { |
4180_1 | 5:8936798c19a3 | 299 | wait_ms(TEMPO); // wait for screen answer - comes 100ms after change |
4180_1 | 5:8936798c19a3 | 300 | i++; //timeout if ack character missed by baud change |
4180_1 | 5:8936798c19a3 | 301 | } |
4180_1 | 1:8b656995301f | 302 | if (_cmd.readable()) resp = _cmd.getc(); // read response if any |
4180_1 | 1:8b656995301f | 303 | switch (resp) { |
4180_1 | 1:8b656995301f | 304 | case ACK : // if OK return 1 |
4180_1 | 1:8b656995301f | 305 | resp = 1; |
4180_1 | 1:8b656995301f | 306 | break; |
4180_1 | 1:8b656995301f | 307 | case NAK : // if NOK return -1 |
4180_1 | 1:8b656995301f | 308 | resp = -1; |
4180_1 | 1:8b656995301f | 309 | break; |
4180_1 | 1:8b656995301f | 310 | default : |
4180_1 | 1:8b656995301f | 311 | resp = 0; // else return 0 |
4180_1 | 1:8b656995301f | 312 | break; |
4180_1 | 1:8b656995301f | 313 | } |
4180_1 | 1:8b656995301f | 314 | } |
4180_1 | 1:8b656995301f | 315 | |
4180_1 | 1:8b656995301f | 316 | //****************************************************************************************************** |
4180_1 | 1:8b656995301f | 317 | int uLCD_4DGL :: readVERSION(char *command, int number) // read screen info and populate data |
4180_1 | 1:8b656995301f | 318 | { |
4180_1 | 1:8b656995301f | 319 | |
4180_1 | 1:8b656995301f | 320 | int i, temp = 0, resp = 0; |
4180_1 | 1:8b656995301f | 321 | char response[5] = ""; |
4180_1 | 1:8b656995301f | 322 | |
4180_1 | 1:8b656995301f | 323 | freeBUFFER(); |
4180_1 | 1:8b656995301f | 324 | |
4180_1 | 1:8b656995301f | 325 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
4180_1 | 1:8b656995301f | 326 | |
4180_1 | 1:8b656995301f | 327 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
4180_1 | 1:8b656995301f | 328 | |
4180_1 | 1:8b656995301f | 329 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
4180_1 | 1:8b656995301f | 330 | temp = _cmd.getc(); |
4180_1 | 1:8b656995301f | 331 | response[resp++] = (char)temp; |
4180_1 | 1:8b656995301f | 332 | } |
4180_1 | 1:8b656995301f | 333 | switch (resp) { |
4180_1 | 6:b759b69cbaf9 | 334 | case 2 : // if OK populate data and return 1 |
4180_1 | 6:b759b69cbaf9 | 335 | revision = response[0]<<8 + response[1]; |
4180_1 | 1:8b656995301f | 336 | resp = 1; |
4180_1 | 1:8b656995301f | 337 | break; |
4180_1 | 1:8b656995301f | 338 | default : |
4180_1 | 1:8b656995301f | 339 | resp = 0; // else return 0 |
4180_1 | 1:8b656995301f | 340 | break; |
4180_1 | 1:8b656995301f | 341 | } |
4180_1 | 1:8b656995301f | 342 | return resp; |
4180_1 | 1:8b656995301f | 343 | } |
4180_1 | 1:8b656995301f | 344 | |
4180_1 | 1:8b656995301f | 345 | //**************************************************************************************************** |
4180_1 | 1:8b656995301f | 346 | void uLCD_4DGL :: background_color(int color) // set screen background color |
4180_1 | 1:8b656995301f | 347 | { |
4180_1 | 1:8b656995301f | 348 | char command[3]= ""; // input color is in 24bits like 0xRRGGBB |
4180_1 | 1:8b656995301f | 349 | |
4180_1 | 1:8b656995301f | 350 | command[0] = BCKGDCOLOR; |
4180_1 | 1:8b656995301f | 351 | |
4180_1 | 1:8b656995301f | 352 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
4180_1 | 1:8b656995301f | 353 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
4180_1 | 1:8b656995301f | 354 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
4180_1 | 1:8b656995301f | 355 | |
4180_1 | 1:8b656995301f | 356 | command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
4180_1 | 1:8b656995301f | 357 | command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
4180_1 | 1:8b656995301f | 358 | |
4180_1 | 1:8b656995301f | 359 | writeCOMMAND(command, 3); |
4180_1 | 1:8b656995301f | 360 | } |
4180_1 | 1:8b656995301f | 361 | |
4180_1 | 1:8b656995301f | 362 | //**************************************************************************************************** |
4180_1 | 2:edae99e4abe7 | 363 | void uLCD_4DGL :: textbackground_color(int color) // set screen background color |
4180_1 | 2:edae99e4abe7 | 364 | { |
4180_1 | 2:edae99e4abe7 | 365 | char command[3]= ""; // input color is in 24bits like 0xRRGGBB |
4180_1 | 2:edae99e4abe7 | 366 | |
4180_1 | 2:edae99e4abe7 | 367 | command[0] = TXTBCKGDCOLOR; |
4180_1 | 2:edae99e4abe7 | 368 | |
4180_1 | 2:edae99e4abe7 | 369 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
4180_1 | 2:edae99e4abe7 | 370 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
4180_1 | 2:edae99e4abe7 | 371 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
4180_1 | 2:edae99e4abe7 | 372 | |
4180_1 | 2:edae99e4abe7 | 373 | command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
4180_1 | 2:edae99e4abe7 | 374 | command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
4180_1 | 2:edae99e4abe7 | 375 | |
4180_1 | 2:edae99e4abe7 | 376 | writeCOMMAND(command, 3); |
4180_1 | 2:edae99e4abe7 | 377 | } |
4180_1 | 2:edae99e4abe7 | 378 | |
4180_1 | 2:edae99e4abe7 | 379 | //**************************************************************************************************** |
4180_1 | 1:8b656995301f | 380 | void uLCD_4DGL :: display_control(char mode, char value) // set screen mode to value |
4180_1 | 1:8b656995301f | 381 | { |
4180_1 | 1:8b656995301f | 382 | char command[3]= ""; |
4180_1 | 1:8b656995301f | 383 | |
4180_1 | 1:8b656995301f | 384 | command[0] = DISPCONTROL; |
4180_1 | 1:8b656995301f | 385 | command[1] = mode; |
4180_1 | 1:8b656995301f | 386 | command[2] = value; |
4180_1 | 1:8b656995301f | 387 | |
4180_1 | 1:8b656995301f | 388 | if (mode == ORIENTATION) { |
4180_1 | 1:8b656995301f | 389 | switch (value) { |
4180_1 | 1:8b656995301f | 390 | case LANDSCAPE : |
4180_1 | 1:8b656995301f | 391 | current_orientation = IS_LANDSCAPE; |
4180_1 | 1:8b656995301f | 392 | break; |
4180_1 | 1:8b656995301f | 393 | case LANDSCAPE_R : |
4180_1 | 1:8b656995301f | 394 | current_orientation = IS_LANDSCAPE; |
4180_1 | 1:8b656995301f | 395 | break; |
4180_1 | 1:8b656995301f | 396 | case PORTRAIT : |
4180_1 | 1:8b656995301f | 397 | current_orientation = IS_PORTRAIT; |
4180_1 | 1:8b656995301f | 398 | break; |
4180_1 | 1:8b656995301f | 399 | case PORTRAIT_R : |
4180_1 | 1:8b656995301f | 400 | current_orientation = IS_PORTRAIT; |
4180_1 | 1:8b656995301f | 401 | break; |
4180_1 | 1:8b656995301f | 402 | } |
4180_1 | 1:8b656995301f | 403 | } |
4180_1 | 1:8b656995301f | 404 | writeCOMMAND(command, 3); |
4180_1 | 1:8b656995301f | 405 | set_font(current_font); |
4180_1 | 1:8b656995301f | 406 | } |
4180_1 | 1:8b656995301f | 407 | |
4180_1 | 1:8b656995301f | 408 | //**************************************************************************************************** |
4180_1 | 1:8b656995301f | 409 | void uLCD_4DGL :: set_volume(char value) // set sound volume to value |
4180_1 | 1:8b656995301f | 410 | { |
4180_1 | 1:8b656995301f | 411 | char command[2]= ""; |
4180_1 | 1:8b656995301f | 412 | |
4180_1 | 1:8b656995301f | 413 | command[0] = SETVOLUME; |
4180_1 | 1:8b656995301f | 414 | command[1] = value; |
4180_1 | 1:8b656995301f | 415 | |
4180_1 | 1:8b656995301f | 416 | writeCOMMAND(command, 2); |
4180_1 | 1:8b656995301f | 417 | } |
4180_1 | 1:8b656995301f | 418 | |
4180_1 | 1:8b656995301f | 419 | |
4180_1 | 1:8b656995301f | 420 | //****************************************************************************************************** |
4180_1 | 1:8b656995301f | 421 | void uLCD_4DGL :: getTOUCH(char *command, int number, int *x, int *y) // read screen info and populate data |
4180_1 | 1:8b656995301f | 422 | { |
4180_1 | 1:8b656995301f | 423 | |
4180_1 | 1:8b656995301f | 424 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 425 | pc.printf("\n"); |
4180_1 | 1:8b656995301f | 426 | pc.printf("New COMMAND : 0x%02X\n", command[0]); |
4180_1 | 1:8b656995301f | 427 | #endif |
4180_1 | 1:8b656995301f | 428 | int i, temp = 0, resp = 0; |
4180_1 | 1:8b656995301f | 429 | char response[5] = ""; |
4180_1 | 1:8b656995301f | 430 | |
4180_1 | 1:8b656995301f | 431 | freeBUFFER(); |
4180_1 | 1:8b656995301f | 432 | |
4180_1 | 1:8b656995301f | 433 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
4180_1 | 1:8b656995301f | 434 | |
4180_1 | 1:8b656995301f | 435 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
4180_1 | 1:8b656995301f | 436 | |
4180_1 | 1:8b656995301f | 437 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
4180_1 | 1:8b656995301f | 438 | temp = _cmd.getc(); |
4180_1 | 1:8b656995301f | 439 | response[resp++] = (char)temp; |
4180_1 | 1:8b656995301f | 440 | } |
4180_1 | 1:8b656995301f | 441 | |
4180_1 | 1:8b656995301f | 442 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 443 | pc.printf(" Answer received %d : 0x%02X 0x%02X 0x%02X 0x%02X\n", resp, response[0], response[1], response[2], response[3]); |
4180_1 | 1:8b656995301f | 444 | #endif |
4180_1 | 1:8b656995301f | 445 | |
4180_1 | 1:8b656995301f | 446 | switch (resp) { |
4180_1 | 1:8b656995301f | 447 | case 4 : // if OK populate data |
4180_1 | 1:8b656995301f | 448 | *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF); |
4180_1 | 1:8b656995301f | 449 | *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF); |
4180_1 | 1:8b656995301f | 450 | break; |
4180_1 | 1:8b656995301f | 451 | default : |
4180_1 | 1:8b656995301f | 452 | *x = -1; |
4180_1 | 1:8b656995301f | 453 | *y = -1; |
4180_1 | 1:8b656995301f | 454 | break; |
4180_1 | 1:8b656995301f | 455 | } |
4180_1 | 1:8b656995301f | 456 | |
4180_1 | 1:8b656995301f | 457 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 458 | pc.printf(" X,Y : %03d,%03d\n", *x, *y); |
4180_1 | 1:8b656995301f | 459 | #endif |
4180_1 | 1:8b656995301f | 460 | } |
4180_1 | 1:8b656995301f | 461 | |
4180_1 | 1:8b656995301f | 462 | //****************************************************************************************************** |
4180_1 | 1:8b656995301f | 463 | int uLCD_4DGL :: getSTATUS(char *command, int number) // read screen info and populate data |
4180_1 | 1:8b656995301f | 464 | { |
4180_1 | 1:8b656995301f | 465 | |
4180_1 | 1:8b656995301f | 466 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 467 | pc.printf("\n"); |
4180_1 | 1:8b656995301f | 468 | pc.printf("New COMMAND : 0x%02X\n", command[0]); |
4180_1 | 1:8b656995301f | 469 | #endif |
4180_1 | 1:8b656995301f | 470 | |
4180_1 | 1:8b656995301f | 471 | int i, temp = 0, resp = 0; |
4180_1 | 1:8b656995301f | 472 | char response[5] = ""; |
4180_1 | 1:8b656995301f | 473 | |
4180_1 | 1:8b656995301f | 474 | freeBUFFER(); |
4180_1 | 1:8b656995301f | 475 | |
4180_1 | 1:8b656995301f | 476 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
4180_1 | 1:8b656995301f | 477 | |
4180_1 | 1:8b656995301f | 478 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
4180_1 | 1:8b656995301f | 479 | |
4180_1 | 1:8b656995301f | 480 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
4180_1 | 1:8b656995301f | 481 | temp = _cmd.getc(); |
4180_1 | 1:8b656995301f | 482 | response[resp++] = (char)temp; |
4180_1 | 1:8b656995301f | 483 | } |
4180_1 | 1:8b656995301f | 484 | switch (resp) { |
4180_1 | 1:8b656995301f | 485 | case 4 : |
4180_1 | 1:8b656995301f | 486 | resp = (int)response[1]; // if OK populate data |
4180_1 | 1:8b656995301f | 487 | break; |
4180_1 | 1:8b656995301f | 488 | default : |
4180_1 | 1:8b656995301f | 489 | resp = -1; // else return 0 |
4180_1 | 1:8b656995301f | 490 | break; |
4180_1 | 1:8b656995301f | 491 | } |
4180_1 | 1:8b656995301f | 492 | |
4180_1 | 1:8b656995301f | 493 | #if DEBUGMODE |
4180_1 | 1:8b656995301f | 494 | pc.printf(" Answer received : %d\n", resp); |
4180_1 | 1:8b656995301f | 495 | #endif |
4180_1 | 1:8b656995301f | 496 | |
4180_1 | 1:8b656995301f | 497 | return resp; |
4180_1 | 2:edae99e4abe7 | 498 | } |