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