uVGA III library
Dependents: CDUFinal CDU_Mbed_21 CDU_Mbed_26 CDU_Mbed_30
Fork of 4DGL by
TFT_4DGL_main.cpp@2:aa719945d0e4, 2014-07-01 (annotated)
- Committer:
- WillemBraat
- Date:
- Tue Jul 01 13:20:11 2014 +0000
- Revision:
- 2:aa719945d0e4
- Parent:
- 1:ebc67b51c225
- Child:
- 3:f34ce48346bc
CDU_CSS() added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AdamGreen | 0:d6e186427f3e | 1 | // |
AdamGreen | 0:d6e186427f3e | 2 | // TFT_4DGL is a class to drive 4D Systems TFT touch screens |
AdamGreen | 0:d6e186427f3e | 3 | // |
AdamGreen | 0:d6e186427f3e | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
AdamGreen | 0:d6e186427f3e | 5 | // |
AdamGreen | 0:d6e186427f3e | 6 | // TFT_4DGL is free software: you can redistribute it and/or modify |
AdamGreen | 0:d6e186427f3e | 7 | // it under the terms of the GNU General Public License as published by |
AdamGreen | 0:d6e186427f3e | 8 | // the Free Software Foundation, either version 3 of the License, or |
AdamGreen | 0:d6e186427f3e | 9 | // (at your option) any later version. |
AdamGreen | 0:d6e186427f3e | 10 | // |
AdamGreen | 0:d6e186427f3e | 11 | // TFT_4DGL is distributed in the hope that it will be useful, |
AdamGreen | 0:d6e186427f3e | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
AdamGreen | 0:d6e186427f3e | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
AdamGreen | 0:d6e186427f3e | 14 | // GNU General Public License for more details. |
AdamGreen | 0:d6e186427f3e | 15 | // |
AdamGreen | 0:d6e186427f3e | 16 | // You should have received a copy of the GNU General Public License |
AdamGreen | 0:d6e186427f3e | 17 | // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. |
AdamGreen | 0:d6e186427f3e | 18 | |
AdamGreen | 0:d6e186427f3e | 19 | #include "mbed.h" |
AdamGreen | 0:d6e186427f3e | 20 | #include "TFT_4DGL.h" |
AdamGreen | 0:d6e186427f3e | 21 | |
AdamGreen | 0:d6e186427f3e | 22 | #define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0]) |
AdamGreen | 0:d6e186427f3e | 23 | |
WillemBraat | 1:ebc67b51c225 | 24 | |
WillemBraat | 1:ebc67b51c225 | 25 | |
AdamGreen | 0:d6e186427f3e | 26 | //Serial pc(USBTX,USBRX); |
AdamGreen | 0:d6e186427f3e | 27 | |
AdamGreen | 0:d6e186427f3e | 28 | //****************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 29 | TFT_4DGL :: TFT_4DGL(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx), |
AdamGreen | 0:d6e186427f3e | 30 | _rst(rst) |
AdamGreen | 0:d6e186427f3e | 31 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 32 | ,pc(USBTX, USBRX) |
AdamGreen | 0:d6e186427f3e | 33 | #endif // DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 34 | { // Constructor |
AdamGreen | 0:d6e186427f3e | 35 | |
AdamGreen | 0:d6e186427f3e | 36 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 37 | pc.baud(115200); |
AdamGreen | 0:d6e186427f3e | 38 | |
AdamGreen | 0:d6e186427f3e | 39 | pc.printf("\n\n\n"); |
AdamGreen | 0:d6e186427f3e | 40 | pc.printf("********************\n"); |
AdamGreen | 0:d6e186427f3e | 41 | pc.printf("TFT_4DGL CONSTRUCTOR\n"); |
AdamGreen | 0:d6e186427f3e | 42 | pc.printf("********************\n"); |
AdamGreen | 0:d6e186427f3e | 43 | #endif |
AdamGreen | 0:d6e186427f3e | 44 | |
AdamGreen | 0:d6e186427f3e | 45 | _rst = 1; // put RESET pin to high to start TFT screen |
WillemBraat | 1:ebc67b51c225 | 46 | reset(); // will toggle led1 |
AdamGreen | 0:d6e186427f3e | 47 | autobaud(); // send autobaud command |
AdamGreen | 0:d6e186427f3e | 48 | version(); // get version information |
AdamGreen | 0:d6e186427f3e | 49 | cls(); // clear screen |
AdamGreen | 0:d6e186427f3e | 50 | |
AdamGreen | 0:d6e186427f3e | 51 | current_col = 0; // initial cursor col |
AdamGreen | 0:d6e186427f3e | 52 | current_row = 0; // initial cursor row |
AdamGreen | 0:d6e186427f3e | 53 | current_color = WHITE; // initial text color |
AdamGreen | 0:d6e186427f3e | 54 | current_orientation = IS_PORTRAIT; // initial screen orientation |
AdamGreen | 0:d6e186427f3e | 55 | |
WillemBraat | 1:ebc67b51c225 | 56 | set_font(FONT_15X17); // initial font |
AdamGreen | 0:d6e186427f3e | 57 | text_mode(OPAQUE); // initial texr mode |
AdamGreen | 0:d6e186427f3e | 58 | } |
AdamGreen | 0:d6e186427f3e | 59 | |
AdamGreen | 0:d6e186427f3e | 60 | //****************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 61 | void TFT_4DGL :: writeBYTE(char c) { // send a BYTE command to screen |
AdamGreen | 0:d6e186427f3e | 62 | |
AdamGreen | 0:d6e186427f3e | 63 | _cmd.putc(c); |
AdamGreen | 0:d6e186427f3e | 64 | wait_ms(1); |
AdamGreen | 0:d6e186427f3e | 65 | |
AdamGreen | 0:d6e186427f3e | 66 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 67 | pc.printf(" Char sent : 0x%02X\n",c); |
AdamGreen | 0:d6e186427f3e | 68 | #endif |
AdamGreen | 0:d6e186427f3e | 69 | |
AdamGreen | 0:d6e186427f3e | 70 | } |
AdamGreen | 0:d6e186427f3e | 71 | |
AdamGreen | 0:d6e186427f3e | 72 | //****************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 73 | void TFT_4DGL :: freeBUFFER(void) { // Clear serial buffer before writing command |
AdamGreen | 0:d6e186427f3e | 74 | |
AdamGreen | 0:d6e186427f3e | 75 | while (_cmd.readable()) _cmd.getc(); // clear buffer garbage |
AdamGreen | 0:d6e186427f3e | 76 | } |
AdamGreen | 0:d6e186427f3e | 77 | |
AdamGreen | 0:d6e186427f3e | 78 | //****************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 79 | int TFT_4DGL :: writeCOMMAND(char *command, int number) { // send several BYTES making a command and return an answer |
AdamGreen | 0:d6e186427f3e | 80 | |
AdamGreen | 0:d6e186427f3e | 81 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 82 | pc.printf("\n"); |
AdamGreen | 0:d6e186427f3e | 83 | pc.printf("New COMMAND : 0x%02X\n", command[0]); |
AdamGreen | 0:d6e186427f3e | 84 | #endif |
AdamGreen | 0:d6e186427f3e | 85 | int i, resp = 0; |
AdamGreen | 0:d6e186427f3e | 86 | freeBUFFER(); |
AdamGreen | 0:d6e186427f3e | 87 | |
AdamGreen | 0:d6e186427f3e | 88 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send command to serial port |
AdamGreen | 0:d6e186427f3e | 89 | |
AdamGreen | 0:d6e186427f3e | 90 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
AdamGreen | 0:d6e186427f3e | 91 | if (_cmd.readable()) resp = _cmd.getc(); // read response if any |
AdamGreen | 0:d6e186427f3e | 92 | switch (resp) { |
AdamGreen | 0:d6e186427f3e | 93 | case ACK : // if OK return 1 |
AdamGreen | 0:d6e186427f3e | 94 | resp = 1; |
AdamGreen | 0:d6e186427f3e | 95 | break; |
AdamGreen | 0:d6e186427f3e | 96 | case NAK : // if NOK return -1 |
AdamGreen | 0:d6e186427f3e | 97 | resp = -1; |
AdamGreen | 0:d6e186427f3e | 98 | break; |
AdamGreen | 0:d6e186427f3e | 99 | default : |
AdamGreen | 0:d6e186427f3e | 100 | resp = 0; // else return 0 |
AdamGreen | 0:d6e186427f3e | 101 | break; |
AdamGreen | 0:d6e186427f3e | 102 | } |
AdamGreen | 0:d6e186427f3e | 103 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 104 | pc.printf(" Answer received : %d\n",resp); |
AdamGreen | 0:d6e186427f3e | 105 | #endif |
AdamGreen | 0:d6e186427f3e | 106 | |
AdamGreen | 0:d6e186427f3e | 107 | return resp; |
AdamGreen | 0:d6e186427f3e | 108 | } |
AdamGreen | 0:d6e186427f3e | 109 | |
AdamGreen | 0:d6e186427f3e | 110 | //************************************************************************** |
AdamGreen | 0:d6e186427f3e | 111 | void TFT_4DGL :: reset() { // Reset Screen |
WillemBraat | 2:aa719945d0e4 | 112 | //DigitalOut led(LED1); |
AdamGreen | 0:d6e186427f3e | 113 | _rst = 0; // put RESET pin to low |
AdamGreen | 0:d6e186427f3e | 114 | wait_ms(TEMPO); // wait a few milliseconds for command reception |
WillemBraat | 1:ebc67b51c225 | 115 | wait_ms(TEMPO); |
AdamGreen | 0:d6e186427f3e | 116 | _rst = 1; // put RESET back to high |
WillemBraat | 2:aa719945d0e4 | 117 | //led=1; |
AdamGreen | 0:d6e186427f3e | 118 | wait(3); // wait 3s for screen to restart |
WillemBraat | 2:aa719945d0e4 | 119 | //led=0; |
WillemBraat | 1:ebc67b51c225 | 120 | |
AdamGreen | 0:d6e186427f3e | 121 | freeBUFFER(); // clean buffer from possible garbage |
AdamGreen | 0:d6e186427f3e | 122 | } |
AdamGreen | 0:d6e186427f3e | 123 | |
WillemBraat | 1:ebc67b51c225 | 124 | |
AdamGreen | 0:d6e186427f3e | 125 | //************************************************************************** |
AdamGreen | 0:d6e186427f3e | 126 | void TFT_4DGL :: autobaud() { // send AutoBaud command (9600) |
AdamGreen | 0:d6e186427f3e | 127 | char command[1] = ""; |
AdamGreen | 0:d6e186427f3e | 128 | command[0] = AUTOBAUD; |
AdamGreen | 0:d6e186427f3e | 129 | writeCOMMAND(command, 1); |
AdamGreen | 0:d6e186427f3e | 130 | } |
AdamGreen | 0:d6e186427f3e | 131 | |
AdamGreen | 0:d6e186427f3e | 132 | //************************************************************************** |
AdamGreen | 0:d6e186427f3e | 133 | void TFT_4DGL :: cls() { // clear screen |
AdamGreen | 0:d6e186427f3e | 134 | char command[1] = ""; |
AdamGreen | 0:d6e186427f3e | 135 | command[0] = CLS; |
AdamGreen | 0:d6e186427f3e | 136 | writeCOMMAND(command, 1); |
AdamGreen | 0:d6e186427f3e | 137 | } |
AdamGreen | 0:d6e186427f3e | 138 | |
AdamGreen | 0:d6e186427f3e | 139 | //************************************************************************** |
AdamGreen | 0:d6e186427f3e | 140 | void TFT_4DGL :: version() { // get API version |
AdamGreen | 0:d6e186427f3e | 141 | char command[2] = ""; |
AdamGreen | 0:d6e186427f3e | 142 | command[0] = VERSION; |
AdamGreen | 0:d6e186427f3e | 143 | command[1] = OFF; |
AdamGreen | 0:d6e186427f3e | 144 | readVERSION(command, 2); |
AdamGreen | 0:d6e186427f3e | 145 | } |
AdamGreen | 0:d6e186427f3e | 146 | |
AdamGreen | 0:d6e186427f3e | 147 | //************************************************************************** |
AdamGreen | 0:d6e186427f3e | 148 | void TFT_4DGL :: baudrate(int speed) { // set screen baud rate |
AdamGreen | 0:d6e186427f3e | 149 | char command[2]= ""; |
AdamGreen | 0:d6e186427f3e | 150 | command[0] = BAUDRATE; |
AdamGreen | 0:d6e186427f3e | 151 | switch (speed) { |
AdamGreen | 0:d6e186427f3e | 152 | case 110 : |
AdamGreen | 0:d6e186427f3e | 153 | command[1] = BAUD_110; |
AdamGreen | 0:d6e186427f3e | 154 | break; |
AdamGreen | 0:d6e186427f3e | 155 | case 300 : |
AdamGreen | 0:d6e186427f3e | 156 | command[1] = BAUD_300; |
AdamGreen | 0:d6e186427f3e | 157 | break; |
AdamGreen | 0:d6e186427f3e | 158 | case 600 : |
AdamGreen | 0:d6e186427f3e | 159 | command[1] = BAUD_600; |
AdamGreen | 0:d6e186427f3e | 160 | break; |
AdamGreen | 0:d6e186427f3e | 161 | case 1200 : |
AdamGreen | 0:d6e186427f3e | 162 | command[1] = BAUD_1200; |
AdamGreen | 0:d6e186427f3e | 163 | break; |
AdamGreen | 0:d6e186427f3e | 164 | case 2400 : |
AdamGreen | 0:d6e186427f3e | 165 | command[1] = BAUD_2400; |
AdamGreen | 0:d6e186427f3e | 166 | break; |
AdamGreen | 0:d6e186427f3e | 167 | case 4800 : |
AdamGreen | 0:d6e186427f3e | 168 | command[1] = BAUD_4800; |
AdamGreen | 0:d6e186427f3e | 169 | break; |
AdamGreen | 0:d6e186427f3e | 170 | case 9600 : |
AdamGreen | 0:d6e186427f3e | 171 | command[1] = BAUD_9600; |
AdamGreen | 0:d6e186427f3e | 172 | break; |
AdamGreen | 0:d6e186427f3e | 173 | case 14400 : |
AdamGreen | 0:d6e186427f3e | 174 | command[1] = BAUD_14400; |
AdamGreen | 0:d6e186427f3e | 175 | break; |
AdamGreen | 0:d6e186427f3e | 176 | case 19200 : |
AdamGreen | 0:d6e186427f3e | 177 | command[1] = BAUD_19200; |
AdamGreen | 0:d6e186427f3e | 178 | break; |
AdamGreen | 0:d6e186427f3e | 179 | case 31250 : |
AdamGreen | 0:d6e186427f3e | 180 | command[1] = BAUD_31250; |
AdamGreen | 0:d6e186427f3e | 181 | break; |
AdamGreen | 0:d6e186427f3e | 182 | case 38400 : |
AdamGreen | 0:d6e186427f3e | 183 | command[1] = BAUD_38400; |
AdamGreen | 0:d6e186427f3e | 184 | break; |
AdamGreen | 0:d6e186427f3e | 185 | case 56000 : |
AdamGreen | 0:d6e186427f3e | 186 | command[1] = BAUD_56000; |
AdamGreen | 0:d6e186427f3e | 187 | break; |
AdamGreen | 0:d6e186427f3e | 188 | case 57600 : |
AdamGreen | 0:d6e186427f3e | 189 | command[1] = BAUD_57600; |
AdamGreen | 0:d6e186427f3e | 190 | break; |
AdamGreen | 0:d6e186427f3e | 191 | case 115200 : |
AdamGreen | 0:d6e186427f3e | 192 | command[1] = BAUD_115200; |
AdamGreen | 0:d6e186427f3e | 193 | break; |
AdamGreen | 0:d6e186427f3e | 194 | case 128000 : |
AdamGreen | 0:d6e186427f3e | 195 | command[1] = BAUD_128000; |
AdamGreen | 0:d6e186427f3e | 196 | break; |
AdamGreen | 0:d6e186427f3e | 197 | case 256000 : |
AdamGreen | 0:d6e186427f3e | 198 | command[1] = BAUD_256000; |
AdamGreen | 0:d6e186427f3e | 199 | break; |
AdamGreen | 0:d6e186427f3e | 200 | default : |
AdamGreen | 0:d6e186427f3e | 201 | command[1] = BAUD_9600; |
AdamGreen | 0:d6e186427f3e | 202 | speed = 9600; |
AdamGreen | 0:d6e186427f3e | 203 | break; |
AdamGreen | 0:d6e186427f3e | 204 | } |
AdamGreen | 0:d6e186427f3e | 205 | |
AdamGreen | 0:d6e186427f3e | 206 | int i, resp = 0; |
AdamGreen | 0:d6e186427f3e | 207 | |
AdamGreen | 0:d6e186427f3e | 208 | freeBUFFER(); |
AdamGreen | 0:d6e186427f3e | 209 | |
AdamGreen | 0:d6e186427f3e | 210 | for (i = 0; i <2; i++) writeBYTE(command[i]); // send command to serial port |
AdamGreen | 0:d6e186427f3e | 211 | _cmd.baud(speed); // set mbed to same speed |
AdamGreen | 0:d6e186427f3e | 212 | |
AdamGreen | 0:d6e186427f3e | 213 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
AdamGreen | 0:d6e186427f3e | 214 | |
AdamGreen | 0:d6e186427f3e | 215 | if (_cmd.readable()) resp = _cmd.getc(); // read response if any |
AdamGreen | 0:d6e186427f3e | 216 | switch (resp) { |
AdamGreen | 0:d6e186427f3e | 217 | case ACK : // if OK return 1 |
AdamGreen | 0:d6e186427f3e | 218 | resp = 1; |
AdamGreen | 0:d6e186427f3e | 219 | break; |
AdamGreen | 0:d6e186427f3e | 220 | case NAK : // if NOK return -1 |
AdamGreen | 0:d6e186427f3e | 221 | resp = -1; |
AdamGreen | 0:d6e186427f3e | 222 | break; |
AdamGreen | 0:d6e186427f3e | 223 | default : |
AdamGreen | 0:d6e186427f3e | 224 | resp = 0; // else return 0 |
AdamGreen | 0:d6e186427f3e | 225 | break; |
AdamGreen | 0:d6e186427f3e | 226 | } |
AdamGreen | 0:d6e186427f3e | 227 | } |
AdamGreen | 0:d6e186427f3e | 228 | |
AdamGreen | 0:d6e186427f3e | 229 | //****************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 230 | int TFT_4DGL :: readVERSION(char *command, int number) { // read screen info and populate data |
AdamGreen | 0:d6e186427f3e | 231 | |
AdamGreen | 0:d6e186427f3e | 232 | int i, temp = 0, resp = 0; |
AdamGreen | 0:d6e186427f3e | 233 | char response[5] = ""; |
AdamGreen | 0:d6e186427f3e | 234 | |
AdamGreen | 0:d6e186427f3e | 235 | freeBUFFER(); |
AdamGreen | 0:d6e186427f3e | 236 | |
AdamGreen | 0:d6e186427f3e | 237 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
AdamGreen | 0:d6e186427f3e | 238 | |
AdamGreen | 0:d6e186427f3e | 239 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
AdamGreen | 0:d6e186427f3e | 240 | |
AdamGreen | 0:d6e186427f3e | 241 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
AdamGreen | 0:d6e186427f3e | 242 | temp = _cmd.getc(); |
AdamGreen | 0:d6e186427f3e | 243 | response[resp++] = (char)temp; |
AdamGreen | 0:d6e186427f3e | 244 | } |
AdamGreen | 0:d6e186427f3e | 245 | switch (resp) { |
AdamGreen | 0:d6e186427f3e | 246 | case 5 : // if OK populate data and return 1 |
AdamGreen | 0:d6e186427f3e | 247 | type = response[0]; |
AdamGreen | 0:d6e186427f3e | 248 | revision = response[1]; |
AdamGreen | 0:d6e186427f3e | 249 | firmware = response[2]; |
AdamGreen | 0:d6e186427f3e | 250 | reserved1 = response[3]; |
AdamGreen | 0:d6e186427f3e | 251 | reserved2 = response[4]; |
AdamGreen | 0:d6e186427f3e | 252 | resp = 1; |
AdamGreen | 0:d6e186427f3e | 253 | break; |
AdamGreen | 0:d6e186427f3e | 254 | default : |
AdamGreen | 0:d6e186427f3e | 255 | resp = 0; // else return 0 |
AdamGreen | 0:d6e186427f3e | 256 | break; |
AdamGreen | 0:d6e186427f3e | 257 | } |
AdamGreen | 0:d6e186427f3e | 258 | return resp; |
AdamGreen | 0:d6e186427f3e | 259 | } |
AdamGreen | 0:d6e186427f3e | 260 | |
AdamGreen | 0:d6e186427f3e | 261 | //**************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 262 | void TFT_4DGL :: background_color(int color) { // set screen background color |
AdamGreen | 0:d6e186427f3e | 263 | char command[3]= ""; // input color is in 24bits like 0xRRGGBB |
AdamGreen | 0:d6e186427f3e | 264 | |
AdamGreen | 0:d6e186427f3e | 265 | command[0] = BCKGDCOLOR; |
AdamGreen | 0:d6e186427f3e | 266 | |
AdamGreen | 0:d6e186427f3e | 267 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
AdamGreen | 0:d6e186427f3e | 268 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
AdamGreen | 0:d6e186427f3e | 269 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
AdamGreen | 0:d6e186427f3e | 270 | |
AdamGreen | 0:d6e186427f3e | 271 | command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
AdamGreen | 0:d6e186427f3e | 272 | command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
AdamGreen | 0:d6e186427f3e | 273 | |
AdamGreen | 0:d6e186427f3e | 274 | writeCOMMAND(command, 3); |
AdamGreen | 0:d6e186427f3e | 275 | } |
AdamGreen | 0:d6e186427f3e | 276 | |
AdamGreen | 0:d6e186427f3e | 277 | //**************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 278 | void TFT_4DGL :: display_control(char mode, char value) { // set screen mode to value |
AdamGreen | 0:d6e186427f3e | 279 | char command[3]= ""; |
AdamGreen | 0:d6e186427f3e | 280 | |
AdamGreen | 0:d6e186427f3e | 281 | command[0] = DISPCONTROL; |
AdamGreen | 0:d6e186427f3e | 282 | command[1] = mode; |
AdamGreen | 0:d6e186427f3e | 283 | command[2] = value; |
AdamGreen | 0:d6e186427f3e | 284 | |
AdamGreen | 0:d6e186427f3e | 285 | if (mode == ORIENTATION) { |
AdamGreen | 0:d6e186427f3e | 286 | switch (value) { |
AdamGreen | 0:d6e186427f3e | 287 | case LANDSCAPE : |
AdamGreen | 0:d6e186427f3e | 288 | current_orientation = IS_LANDSCAPE; |
AdamGreen | 0:d6e186427f3e | 289 | break; |
AdamGreen | 0:d6e186427f3e | 290 | case LANDSCAPE_R : |
AdamGreen | 0:d6e186427f3e | 291 | current_orientation = IS_LANDSCAPE; |
AdamGreen | 0:d6e186427f3e | 292 | break; |
AdamGreen | 0:d6e186427f3e | 293 | case PORTRAIT : |
AdamGreen | 0:d6e186427f3e | 294 | current_orientation = IS_PORTRAIT; |
AdamGreen | 0:d6e186427f3e | 295 | break; |
AdamGreen | 0:d6e186427f3e | 296 | case PORTRAIT_R : |
AdamGreen | 0:d6e186427f3e | 297 | current_orientation = IS_PORTRAIT; |
AdamGreen | 0:d6e186427f3e | 298 | break; |
AdamGreen | 0:d6e186427f3e | 299 | } |
AdamGreen | 0:d6e186427f3e | 300 | } |
AdamGreen | 0:d6e186427f3e | 301 | writeCOMMAND(command, 3); |
AdamGreen | 0:d6e186427f3e | 302 | set_font(current_font); |
AdamGreen | 0:d6e186427f3e | 303 | } |
AdamGreen | 0:d6e186427f3e | 304 | |
AdamGreen | 0:d6e186427f3e | 305 | //**************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 306 | void TFT_4DGL :: set_volume(char value) { // set sound volume to value |
AdamGreen | 0:d6e186427f3e | 307 | char command[2]= ""; |
AdamGreen | 0:d6e186427f3e | 308 | |
AdamGreen | 0:d6e186427f3e | 309 | command[0] = SETVOLUME; |
AdamGreen | 0:d6e186427f3e | 310 | command[1] = value; |
AdamGreen | 0:d6e186427f3e | 311 | |
AdamGreen | 0:d6e186427f3e | 312 | writeCOMMAND(command, 2); |
AdamGreen | 0:d6e186427f3e | 313 | } |
AdamGreen | 0:d6e186427f3e | 314 | |
AdamGreen | 0:d6e186427f3e | 315 | |
AdamGreen | 0:d6e186427f3e | 316 | //****************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 317 | void TFT_4DGL :: getTOUCH(char *command, int number, int *x, int *y) { // read screen info and populate data |
AdamGreen | 0:d6e186427f3e | 318 | |
AdamGreen | 0:d6e186427f3e | 319 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 320 | pc.printf("\n"); |
AdamGreen | 0:d6e186427f3e | 321 | pc.printf("New COMMAND : 0x%02X\n", command[0]); |
AdamGreen | 0:d6e186427f3e | 322 | #endif |
AdamGreen | 0:d6e186427f3e | 323 | int i, temp = 0, resp = 0; |
AdamGreen | 0:d6e186427f3e | 324 | char response[5] = ""; |
AdamGreen | 0:d6e186427f3e | 325 | |
AdamGreen | 0:d6e186427f3e | 326 | freeBUFFER(); |
AdamGreen | 0:d6e186427f3e | 327 | |
AdamGreen | 0:d6e186427f3e | 328 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
AdamGreen | 0:d6e186427f3e | 329 | |
AdamGreen | 0:d6e186427f3e | 330 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
AdamGreen | 0:d6e186427f3e | 331 | |
AdamGreen | 0:d6e186427f3e | 332 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
AdamGreen | 0:d6e186427f3e | 333 | temp = _cmd.getc(); |
AdamGreen | 0:d6e186427f3e | 334 | response[resp++] = (char)temp; |
AdamGreen | 0:d6e186427f3e | 335 | } |
AdamGreen | 0:d6e186427f3e | 336 | |
AdamGreen | 0:d6e186427f3e | 337 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 338 | pc.printf(" Answer received %d : 0x%02X 0x%02X 0x%02X 0x%02X\n", resp, response[0], response[1], response[2], response[3]); |
AdamGreen | 0:d6e186427f3e | 339 | #endif |
AdamGreen | 0:d6e186427f3e | 340 | |
AdamGreen | 0:d6e186427f3e | 341 | switch (resp) { |
AdamGreen | 0:d6e186427f3e | 342 | case 4 : // if OK populate data |
AdamGreen | 0:d6e186427f3e | 343 | *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF); |
AdamGreen | 0:d6e186427f3e | 344 | *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF); |
AdamGreen | 0:d6e186427f3e | 345 | break; |
AdamGreen | 0:d6e186427f3e | 346 | default : |
AdamGreen | 0:d6e186427f3e | 347 | *x = -1; |
AdamGreen | 0:d6e186427f3e | 348 | *y = -1; |
AdamGreen | 0:d6e186427f3e | 349 | break; |
AdamGreen | 0:d6e186427f3e | 350 | } |
AdamGreen | 0:d6e186427f3e | 351 | |
AdamGreen | 0:d6e186427f3e | 352 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 353 | pc.printf(" X,Y : %03d,%03d\n", *x, *y); |
AdamGreen | 0:d6e186427f3e | 354 | #endif |
AdamGreen | 0:d6e186427f3e | 355 | } |
AdamGreen | 0:d6e186427f3e | 356 | |
AdamGreen | 0:d6e186427f3e | 357 | //****************************************************************************************************** |
AdamGreen | 0:d6e186427f3e | 358 | int TFT_4DGL :: getSTATUS(char *command, int number) { // read screen info and populate data |
AdamGreen | 0:d6e186427f3e | 359 | |
AdamGreen | 0:d6e186427f3e | 360 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 361 | pc.printf("\n"); |
AdamGreen | 0:d6e186427f3e | 362 | pc.printf("New COMMAND : 0x%02X\n", command[0]); |
AdamGreen | 0:d6e186427f3e | 363 | #endif |
AdamGreen | 0:d6e186427f3e | 364 | |
AdamGreen | 0:d6e186427f3e | 365 | int i, temp = 0, resp = 0; |
AdamGreen | 0:d6e186427f3e | 366 | char response[5] = ""; |
AdamGreen | 0:d6e186427f3e | 367 | |
AdamGreen | 0:d6e186427f3e | 368 | freeBUFFER(); |
AdamGreen | 0:d6e186427f3e | 369 | |
AdamGreen | 0:d6e186427f3e | 370 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
AdamGreen | 0:d6e186427f3e | 371 | |
AdamGreen | 0:d6e186427f3e | 372 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
AdamGreen | 0:d6e186427f3e | 373 | |
AdamGreen | 0:d6e186427f3e | 374 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
AdamGreen | 0:d6e186427f3e | 375 | temp = _cmd.getc(); |
AdamGreen | 0:d6e186427f3e | 376 | response[resp++] = (char)temp; |
AdamGreen | 0:d6e186427f3e | 377 | } |
AdamGreen | 0:d6e186427f3e | 378 | switch (resp) { |
AdamGreen | 0:d6e186427f3e | 379 | case 4 : |
AdamGreen | 0:d6e186427f3e | 380 | resp = (int)response[1]; // if OK populate data |
AdamGreen | 0:d6e186427f3e | 381 | break; |
AdamGreen | 0:d6e186427f3e | 382 | default : |
AdamGreen | 0:d6e186427f3e | 383 | resp = -1; // else return 0 |
AdamGreen | 0:d6e186427f3e | 384 | break; |
AdamGreen | 0:d6e186427f3e | 385 | } |
AdamGreen | 0:d6e186427f3e | 386 | |
AdamGreen | 0:d6e186427f3e | 387 | #if DEBUGMODE |
AdamGreen | 0:d6e186427f3e | 388 | pc.printf(" Answer received : %d\n", resp); |
AdamGreen | 0:d6e186427f3e | 389 | #endif |
AdamGreen | 0:d6e186427f3e | 390 | |
AdamGreen | 0:d6e186427f3e | 391 | return resp; |
AdamGreen | 0:d6e186427f3e | 392 | } |