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.
TFT_4DGL_Graphics.cpp@0:26bcd4640f94, 2010-12-27 (annotated)
- Committer:
- JLS
- Date:
- Mon Dec 27 21:32:10 2010 +0000
- Revision:
- 0:26bcd4640f94
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| JLS | 0:26bcd4640f94 | 1 | // | 
| JLS | 0:26bcd4640f94 | 2 | // TFT_4DGL is a class to drive 4D Systems TFT touch screens | 
| JLS | 0:26bcd4640f94 | 3 | // | 
| JLS | 0:26bcd4640f94 | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> | 
| JLS | 0:26bcd4640f94 | 5 | // | 
| JLS | 0:26bcd4640f94 | 6 | // TFT_4DGL is free software: you can redistribute it and/or modify | 
| JLS | 0:26bcd4640f94 | 7 | // it under the terms of the GNU General Public License as published by | 
| JLS | 0:26bcd4640f94 | 8 | // the Free Software Foundation, either version 3 of the License, or | 
| JLS | 0:26bcd4640f94 | 9 | // (at your option) any later version. | 
| JLS | 0:26bcd4640f94 | 10 | // | 
| JLS | 0:26bcd4640f94 | 11 | // TFT_4DGL is distributed in the hope that it will be useful, | 
| JLS | 0:26bcd4640f94 | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| JLS | 0:26bcd4640f94 | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| JLS | 0:26bcd4640f94 | 14 | // GNU General Public License for more details. | 
| JLS | 0:26bcd4640f94 | 15 | // | 
| JLS | 0:26bcd4640f94 | 16 | // You should have received a copy of the GNU General Public License | 
| JLS | 0:26bcd4640f94 | 17 | // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. | 
| JLS | 0:26bcd4640f94 | 18 | |
| JLS | 0:26bcd4640f94 | 19 | #include "mbed.h" | 
| JLS | 0:26bcd4640f94 | 20 | #include "TFT_4DGL.h" | 
| JLS | 0:26bcd4640f94 | 21 | |
| JLS | 0:26bcd4640f94 | 22 | |
| JLS | 0:26bcd4640f94 | 23 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 24 | void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y) | 
| JLS | 0:26bcd4640f94 | 25 | char command[9]= ""; | 
| JLS | 0:26bcd4640f94 | 26 | |
| JLS | 0:26bcd4640f94 | 27 | command[0] = CIRCLE; | 
| JLS | 0:26bcd4640f94 | 28 | |
| JLS | 0:26bcd4640f94 | 29 | command[1] = (x >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 30 | command[2] = x & 0xFF; | 
| JLS | 0:26bcd4640f94 | 31 | |
| JLS | 0:26bcd4640f94 | 32 | command[3] = (y >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 33 | command[4] = y & 0xFF; | 
| JLS | 0:26bcd4640f94 | 34 | |
| JLS | 0:26bcd4640f94 | 35 | command[5] = (radius >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 36 | command[6] = radius & 0xFF; | 
| JLS | 0:26bcd4640f94 | 37 | |
| JLS | 0:26bcd4640f94 | 38 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits | 
| JLS | 0:26bcd4640f94 | 39 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits | 
| JLS | 0:26bcd4640f94 | 40 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits | 
| JLS | 0:26bcd4640f94 | 41 | |
| JLS | 0:26bcd4640f94 | 42 | command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 43 | command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 44 | |
| JLS | 0:26bcd4640f94 | 45 | writeCOMMAND(command, 9); | 
| JLS | 0:26bcd4640f94 | 46 | } | 
| JLS | 0:26bcd4640f94 | 47 | |
| JLS | 0:26bcd4640f94 | 48 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 49 | void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle | 
| JLS | 0:26bcd4640f94 | 50 | char command[15]= ""; | 
| JLS | 0:26bcd4640f94 | 51 | |
| JLS | 0:26bcd4640f94 | 52 | command[0] = TRIANGLE; | 
| JLS | 0:26bcd4640f94 | 53 | |
| JLS | 0:26bcd4640f94 | 54 | command[1] = (x1 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 55 | command[2] = x1 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 56 | |
| JLS | 0:26bcd4640f94 | 57 | command[3] = (y1 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 58 | command[4] = y1 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 59 | |
| JLS | 0:26bcd4640f94 | 60 | command[5] = (x2 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 61 | command[6] = x2 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 62 | |
| JLS | 0:26bcd4640f94 | 63 | command[7] = (y2 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 64 | command[8] = y2 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 65 | |
| JLS | 0:26bcd4640f94 | 66 | command[9] = (x3 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 67 | command[10] = x3 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 68 | |
| JLS | 0:26bcd4640f94 | 69 | command[11] = (y3 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 70 | command[12] = y3 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 71 | |
| JLS | 0:26bcd4640f94 | 72 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits | 
| JLS | 0:26bcd4640f94 | 73 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits | 
| JLS | 0:26bcd4640f94 | 74 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits | 
| JLS | 0:26bcd4640f94 | 75 | |
| JLS | 0:26bcd4640f94 | 76 | command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 77 | command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 78 | |
| JLS | 0:26bcd4640f94 | 79 | writeCOMMAND(command, 15); | 
| JLS | 0:26bcd4640f94 | 80 | } | 
| JLS | 0:26bcd4640f94 | 81 | |
| JLS | 0:26bcd4640f94 | 82 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 83 | void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line | 
| JLS | 0:26bcd4640f94 | 84 | char command[11]= ""; | 
| JLS | 0:26bcd4640f94 | 85 | |
| JLS | 0:26bcd4640f94 | 86 | command[0] = LINE; | 
| JLS | 0:26bcd4640f94 | 87 | |
| JLS | 0:26bcd4640f94 | 88 | command[1] = (x1 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 89 | command[2] = x1 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 90 | |
| JLS | 0:26bcd4640f94 | 91 | command[3] = (y1 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 92 | command[4] = y1 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 93 | |
| JLS | 0:26bcd4640f94 | 94 | command[5] = (x2 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 95 | command[6] = x2 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 96 | |
| JLS | 0:26bcd4640f94 | 97 | command[7] = (y2 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 98 | command[8] = y2 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 99 | |
| JLS | 0:26bcd4640f94 | 100 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits | 
| JLS | 0:26bcd4640f94 | 101 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits | 
| JLS | 0:26bcd4640f94 | 102 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits | 
| JLS | 0:26bcd4640f94 | 103 | |
| JLS | 0:26bcd4640f94 | 104 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 105 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 106 | |
| JLS | 0:26bcd4640f94 | 107 | writeCOMMAND(command, 11); | 
| JLS | 0:26bcd4640f94 | 108 | } | 
| JLS | 0:26bcd4640f94 | 109 | |
| JLS | 0:26bcd4640f94 | 110 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 111 | void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle | 
| JLS | 0:26bcd4640f94 | 112 | char command[11]= ""; | 
| JLS | 0:26bcd4640f94 | 113 | |
| JLS | 0:26bcd4640f94 | 114 | command[0] = RECTANGLE; | 
| JLS | 0:26bcd4640f94 | 115 | |
| JLS | 0:26bcd4640f94 | 116 | command[1] = (x1 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 117 | command[2] = x1 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 118 | |
| JLS | 0:26bcd4640f94 | 119 | command[3] = (y1 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 120 | command[4] = y1 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 121 | |
| JLS | 0:26bcd4640f94 | 122 | command[5] = (x2 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 123 | command[6] = x2 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 124 | |
| JLS | 0:26bcd4640f94 | 125 | command[7] = (y2 >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 126 | command[8] = y2 & 0xFF; | 
| JLS | 0:26bcd4640f94 | 127 | |
| JLS | 0:26bcd4640f94 | 128 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits | 
| JLS | 0:26bcd4640f94 | 129 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits | 
| JLS | 0:26bcd4640f94 | 130 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits | 
| JLS | 0:26bcd4640f94 | 131 | |
| JLS | 0:26bcd4640f94 | 132 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 133 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 134 | |
| JLS | 0:26bcd4640f94 | 135 | writeCOMMAND(command, 11); | 
| JLS | 0:26bcd4640f94 | 136 | } | 
| JLS | 0:26bcd4640f94 | 137 | |
| JLS | 0:26bcd4640f94 | 138 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 139 | void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse | 
| JLS | 0:26bcd4640f94 | 140 | char command[11]= ""; | 
| JLS | 0:26bcd4640f94 | 141 | |
| JLS | 0:26bcd4640f94 | 142 | command[0] = ELLIPSE; | 
| JLS | 0:26bcd4640f94 | 143 | |
| JLS | 0:26bcd4640f94 | 144 | command[1] = (x >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 145 | command[2] = x & 0xFF; | 
| JLS | 0:26bcd4640f94 | 146 | |
| JLS | 0:26bcd4640f94 | 147 | command[3] = (y >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 148 | command[4] = y & 0xFF; | 
| JLS | 0:26bcd4640f94 | 149 | |
| JLS | 0:26bcd4640f94 | 150 | command[5] = (radius_x >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 151 | command[6] = radius_x & 0xFF; | 
| JLS | 0:26bcd4640f94 | 152 | |
| JLS | 0:26bcd4640f94 | 153 | command[7] = (radius_y >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 154 | command[8] = radius_y & 0xFF; | 
| JLS | 0:26bcd4640f94 | 155 | |
| JLS | 0:26bcd4640f94 | 156 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits | 
| JLS | 0:26bcd4640f94 | 157 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits | 
| JLS | 0:26bcd4640f94 | 158 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits | 
| JLS | 0:26bcd4640f94 | 159 | |
| JLS | 0:26bcd4640f94 | 160 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 161 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 162 | |
| JLS | 0:26bcd4640f94 | 163 | writeCOMMAND(command, 11); | 
| JLS | 0:26bcd4640f94 | 164 | } | 
| JLS | 0:26bcd4640f94 | 165 | |
| JLS | 0:26bcd4640f94 | 166 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 167 | void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel | 
| JLS | 0:26bcd4640f94 | 168 | char command[7]= ""; | 
| JLS | 0:26bcd4640f94 | 169 | |
| JLS | 0:26bcd4640f94 | 170 | command[0] = PIXEL; | 
| JLS | 0:26bcd4640f94 | 171 | |
| JLS | 0:26bcd4640f94 | 172 | command[1] = (x >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 173 | command[2] = x & 0xFF; | 
| JLS | 0:26bcd4640f94 | 174 | |
| JLS | 0:26bcd4640f94 | 175 | command[3] = (y >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 176 | command[4] = y & 0xFF; | 
| JLS | 0:26bcd4640f94 | 177 | |
| JLS | 0:26bcd4640f94 | 178 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits | 
| JLS | 0:26bcd4640f94 | 179 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits | 
| JLS | 0:26bcd4640f94 | 180 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits | 
| JLS | 0:26bcd4640f94 | 181 | |
| JLS | 0:26bcd4640f94 | 182 | command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 183 | command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color | 
| JLS | 0:26bcd4640f94 | 184 | |
| JLS | 0:26bcd4640f94 | 185 | writeCOMMAND(command, 7); | 
| JLS | 0:26bcd4640f94 | 186 | } | 
| JLS | 0:26bcd4640f94 | 187 | |
| JLS | 0:26bcd4640f94 | 188 | //****************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 189 | int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data | 
| JLS | 0:26bcd4640f94 | 190 | |
| JLS | 0:26bcd4640f94 | 191 | char command[5]= ""; | 
| JLS | 0:26bcd4640f94 | 192 | |
| JLS | 0:26bcd4640f94 | 193 | command[0] = READPIXEL; | 
| JLS | 0:26bcd4640f94 | 194 | |
| JLS | 0:26bcd4640f94 | 195 | command[1] = (x >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 196 | command[2] = x & 0xFF; | 
| JLS | 0:26bcd4640f94 | 197 | |
| JLS | 0:26bcd4640f94 | 198 | command[3] = (y >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 199 | command[4] = y & 0xFF; | 
| JLS | 0:26bcd4640f94 | 200 | |
| JLS | 0:26bcd4640f94 | 201 | int i, temp = 0, color = 0, resp = 0; | 
| JLS | 0:26bcd4640f94 | 202 | char response[2] = ""; | 
| JLS | 0:26bcd4640f94 | 203 | |
| JLS | 0:26bcd4640f94 | 204 | freeBUFFER(); | 
| JLS | 0:26bcd4640f94 | 205 | |
| JLS | 0:26bcd4640f94 | 206 | for (i = 0; i < 5; i++) { // send all chars to serial port | 
| JLS | 0:26bcd4640f94 | 207 | writeBYTE(command[i]); | 
| JLS | 0:26bcd4640f94 | 208 | } | 
| JLS | 0:26bcd4640f94 | 209 | |
| JLS | 0:26bcd4640f94 | 210 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer | 
| JLS | 0:26bcd4640f94 | 211 | |
| JLS | 0:26bcd4640f94 | 212 | while (_cmd.readable()) { | 
| JLS | 0:26bcd4640f94 | 213 | temp = _cmd.getc(); | 
| JLS | 0:26bcd4640f94 | 214 | response[resp++] = (char)temp; | 
| JLS | 0:26bcd4640f94 | 215 | } | 
| JLS | 0:26bcd4640f94 | 216 | |
| JLS | 0:26bcd4640f94 | 217 | color = ((response[0] << 8) + response[1]); | 
| JLS | 0:26bcd4640f94 | 218 | |
| JLS | 0:26bcd4640f94 | 219 | return color; // WARNING : this is 16bits color, not 24bits... need to be fixed | 
| JLS | 0:26bcd4640f94 | 220 | } | 
| JLS | 0:26bcd4640f94 | 221 | |
| JLS | 0:26bcd4640f94 | 222 | //****************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 223 | void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) { | 
| JLS | 0:26bcd4640f94 | 224 | |
| JLS | 0:26bcd4640f94 | 225 | char command[13]= ""; | 
| JLS | 0:26bcd4640f94 | 226 | |
| JLS | 0:26bcd4640f94 | 227 | command[0] = SCREENCOPY; | 
| JLS | 0:26bcd4640f94 | 228 | |
| JLS | 0:26bcd4640f94 | 229 | command[1] = (xs >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 230 | command[2] = xs & 0xFF; | 
| JLS | 0:26bcd4640f94 | 231 | |
| JLS | 0:26bcd4640f94 | 232 | command[3] = (ys >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 233 | command[4] = ys & 0xFF; | 
| JLS | 0:26bcd4640f94 | 234 | |
| JLS | 0:26bcd4640f94 | 235 | command[5] = (xd >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 236 | command[6] = xd & 0xFF; | 
| JLS | 0:26bcd4640f94 | 237 | |
| JLS | 0:26bcd4640f94 | 238 | command[7] = (yd >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 239 | command[8] = yd & 0xFF; | 
| JLS | 0:26bcd4640f94 | 240 | |
| JLS | 0:26bcd4640f94 | 241 | command[9] = (width >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 242 | command[10] = width & 0xFF; | 
| JLS | 0:26bcd4640f94 | 243 | |
| JLS | 0:26bcd4640f94 | 244 | command[11] = (height >> 8) & 0xFF; | 
| JLS | 0:26bcd4640f94 | 245 | command[12] = height & 0xFF; | 
| JLS | 0:26bcd4640f94 | 246 | |
| JLS | 0:26bcd4640f94 | 247 | writeCOMMAND(command, 13); | 
| JLS | 0:26bcd4640f94 | 248 | } | 
| JLS | 0:26bcd4640f94 | 249 | |
| JLS | 0:26bcd4640f94 | 250 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 251 | void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME | 
| JLS | 0:26bcd4640f94 | 252 | char command[2]= ""; | 
| JLS | 0:26bcd4640f94 | 253 | |
| JLS | 0:26bcd4640f94 | 254 | command[0] = PENSIZE; | 
| JLS | 0:26bcd4640f94 | 255 | command[1] = mode; | 
| JLS | 0:26bcd4640f94 | 256 | |
| JLS | 0:26bcd4640f94 | 257 | writeCOMMAND(command, 2); | 
| JLS | 0:26bcd4640f94 | 258 | } | 
| JLS | 0:26bcd4640f94 | 259 | |
| JLS | 0:26bcd4640f94 | 260 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 261 | // This plays a .wav file from the FAT partition of an uSD Card | 
| JLS | 0:26bcd4640f94 | 262 | // Not really recommended as the speaker on the uLCD-32PT is really bad! | 
| JLS | 0:26bcd4640f94 | 263 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 264 | void TFT_4DGL :: SD_Card_Wav(char *Filename) { | 
| JLS | 0:26bcd4640f94 | 265 | char command[21]= ""; | 
| JLS | 0:26bcd4640f94 | 266 | int Lgt=0; | 
| JLS | 0:26bcd4640f94 | 267 | |
| JLS | 0:26bcd4640f94 | 268 | command[0] = 0x40; //ext_cmd | 
| JLS | 0:26bcd4640f94 | 269 | command[1] = 0x6C; //Play Audio | 
| JLS | 0:26bcd4640f94 | 270 | command[2] = 0x01; //Option 0x00=Return at end, 0x01=Return now, 0x02=Stop, 0x03=Pause, 0x04=Resume, 0x05=Loop. | 
| JLS | 0:26bcd4640f94 | 271 | for(int i=0;Filename[i]!=0x00;i++){ | 
| JLS | 0:26bcd4640f94 | 272 | command[i+3] = Filename[i]; | 
| JLS | 0:26bcd4640f94 | 273 | Lgt = i; | 
| JLS | 0:26bcd4640f94 | 274 | } | 
| JLS | 0:26bcd4640f94 | 275 | command[Lgt+4] = 0x2E; //. | 
| JLS | 0:26bcd4640f94 | 276 | command[Lgt+5] = 0x77; //w | 
| JLS | 0:26bcd4640f94 | 277 | command[Lgt+6] = 0x61; //a | 
| JLS | 0:26bcd4640f94 | 278 | command[Lgt+7] = 0x76; //v | 
| JLS | 0:26bcd4640f94 | 279 | command[Lgt+8] = 0x00; //terminator | 
| JLS | 0:26bcd4640f94 | 280 | |
| JLS | 0:26bcd4640f94 | 281 | writeCOMMAND(command, Lgt+9); | 
| JLS | 0:26bcd4640f94 | 282 | } | 
| JLS | 0:26bcd4640f94 | 283 | |
| JLS | 0:26bcd4640f94 | 284 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 285 | // This sets the volume for the speaker on the uLCD-32PT | 
| JLS | 0:26bcd4640f94 | 286 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 287 | void TFT_4DGL :: Set_Volume(char vol) { | 
| JLS | 0:26bcd4640f94 | 288 | |
| JLS | 0:26bcd4640f94 | 289 | char command[2]= ""; | 
| JLS | 0:26bcd4640f94 | 290 | |
| JLS | 0:26bcd4640f94 | 291 | command[0] = 0x76; //cmd | 
| JLS | 0:26bcd4640f94 | 292 | command[1] = vol; //set volume | 
| JLS | 0:26bcd4640f94 | 293 | |
| JLS | 0:26bcd4640f94 | 294 | writeCOMMAND(command, 2); | 
| JLS | 0:26bcd4640f94 | 295 | } | 
| JLS | 0:26bcd4640f94 | 296 | |
| JLS | 0:26bcd4640f94 | 297 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 298 | // This displays an image on the screen that is stored on the FAT partition of an uSD Card | 
| JLS | 0:26bcd4640f94 | 299 | // Sent Filename, X-pos, Y-pos, Sector Address - Display from the RAW partition is quicker | 
| JLS | 0:26bcd4640f94 | 300 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 301 | void TFT_4DGL :: uSD_FAT_Image(char *Filename, int x, int y, long s) { | 
| JLS | 0:26bcd4640f94 | 302 | char X_MSB, X_LSB, Y_MSB, Y_LSB, S0, S1, S2, S3; | 
| JLS | 0:26bcd4640f94 | 303 | char command[25]= ""; | 
| JLS | 0:26bcd4640f94 | 304 | int Lgt=0; | 
| JLS | 0:26bcd4640f94 | 305 | |
| JLS | 0:26bcd4640f94 | 306 | X_LSB = x&0x00FF; | 
| JLS | 0:26bcd4640f94 | 307 | X_MSB = (x >> 8); | 
| JLS | 0:26bcd4640f94 | 308 | Y_LSB = y&0x00FF; | 
| JLS | 0:26bcd4640f94 | 309 | Y_MSB = (y >> 8); | 
| JLS | 0:26bcd4640f94 | 310 | |
| JLS | 0:26bcd4640f94 | 311 | S0 = (s >> 20)&0x000000FF; | 
| JLS | 0:26bcd4640f94 | 312 | S1 = (s >> 16)&0x0000FF; | 
| JLS | 0:26bcd4640f94 | 313 | S2 = (s >> 8)&0x0000FF; | 
| JLS | 0:26bcd4640f94 | 314 | S3 = s&0x0000FF;; | 
| JLS | 0:26bcd4640f94 | 315 | |
| JLS | 0:26bcd4640f94 | 316 | command[0] = '@'; //ext_cmd | 
| JLS | 0:26bcd4640f94 | 317 | command[1] = 'm'; //FAT Image | 
| JLS | 0:26bcd4640f94 | 318 | for(int i=0;Filename[i]!=0x00;i++){ | 
| JLS | 0:26bcd4640f94 | 319 | command[i+2] = Filename[i]; | 
| JLS | 0:26bcd4640f94 | 320 | Lgt = i; | 
| JLS | 0:26bcd4640f94 | 321 | } | 
| JLS | 0:26bcd4640f94 | 322 | command[Lgt+3] = '.'; //. | 
| JLS | 0:26bcd4640f94 | 323 | command[Lgt+4] = 'G'; //G | 
| JLS | 0:26bcd4640f94 | 324 | command[Lgt+5] = 'C'; //C | 
| JLS | 0:26bcd4640f94 | 325 | command[Lgt+6] = 'I'; //I | 
| JLS | 0:26bcd4640f94 | 326 | command[Lgt+7] = 0x00; //Terminator | 
| JLS | 0:26bcd4640f94 | 327 | command[Lgt+8] = X_MSB; //X-Position MSB | 
| JLS | 0:26bcd4640f94 | 328 | command[Lgt+9] = X_LSB; //X-Position LSB | 
| JLS | 0:26bcd4640f94 | 329 | command[Lgt+10] = Y_MSB; //Y-Position MSB | 
| JLS | 0:26bcd4640f94 | 330 | command[Lgt+11] = Y_LSB; //Y-Position LSB | 
| JLS | 0:26bcd4640f94 | 331 | command[Lgt+12] = S0; //Sector Address 4 bytes | 
| JLS | 0:26bcd4640f94 | 332 | command[Lgt+13] = S1; | 
| JLS | 0:26bcd4640f94 | 333 | command[Lgt+14] = S2; | 
| JLS | 0:26bcd4640f94 | 334 | command[Lgt+15] = S3; | 
| JLS | 0:26bcd4640f94 | 335 | |
| JLS | 0:26bcd4640f94 | 336 | writeCOMMAND(command, Lgt+16); | 
| JLS | 0:26bcd4640f94 | 337 | } | 
| JLS | 0:26bcd4640f94 | 338 | |
| JLS | 0:26bcd4640f94 | 339 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 340 | // This displays an image on the screen in the NEW FORMAT | 
| JLS | 0:26bcd4640f94 | 341 | // Sent X-pos, Y-pos, Sector Address - This is the recommended way to display images | 
| JLS | 0:26bcd4640f94 | 342 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 343 | void TFT_4DGL :: uSD_Image(int x, int y, long s) { | 
| JLS | 0:26bcd4640f94 | 344 | char S1, S2, S3; | 
| JLS | 0:26bcd4640f94 | 345 | char X_MSB, X_LSB, Y_MSB, Y_LSB; | 
| JLS | 0:26bcd4640f94 | 346 | char command[9]= ""; | 
| JLS | 0:26bcd4640f94 | 347 | |
| JLS | 0:26bcd4640f94 | 348 | X_LSB = x&0x00FF; //Work out the x position | 
| JLS | 0:26bcd4640f94 | 349 | X_MSB = (x >> 8); | 
| JLS | 0:26bcd4640f94 | 350 | Y_LSB = y&0x00FF; //Work out the y position | 
| JLS | 0:26bcd4640f94 | 351 | Y_MSB = (y >> 8); | 
| JLS | 0:26bcd4640f94 | 352 | |
| JLS | 0:26bcd4640f94 | 353 | S1 = (s >> 16)&0x0000FF; //Work out the sector address | 
| JLS | 0:26bcd4640f94 | 354 | S2 = (s >> 8)&0x0000FF; | 
| JLS | 0:26bcd4640f94 | 355 | S3 = s&0x0000FF; | 
| JLS | 0:26bcd4640f94 | 356 | |
| JLS | 0:26bcd4640f94 | 357 | command[0] = 0x40; //ext_cmd | 
| JLS | 0:26bcd4640f94 | 358 | command[1] = 0x49; //Display image | 
| JLS | 0:26bcd4640f94 | 359 | command[2] = X_MSB; //X position - 2 bytes | 
| JLS | 0:26bcd4640f94 | 360 | command[3] = X_LSB; | 
| JLS | 0:26bcd4640f94 | 361 | command[4] = Y_MSB; //Y position - 2 bytes | 
| JLS | 0:26bcd4640f94 | 362 | command[5] = Y_LSB; | 
| JLS | 0:26bcd4640f94 | 363 | command[6] = S1; //Sector address - 3 bytes | 
| JLS | 0:26bcd4640f94 | 364 | command[7] = S2; | 
| JLS | 0:26bcd4640f94 | 365 | command[8] = S3; | 
| JLS | 0:26bcd4640f94 | 366 | |
| JLS | 0:26bcd4640f94 | 367 | writeCOMMAND(command, 9); | 
| JLS | 0:26bcd4640f94 | 368 | } | 
| JLS | 0:26bcd4640f94 | 369 | |
| JLS | 0:26bcd4640f94 | 370 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 371 | // This displays an video on the screen in the NEW FORMAT | 
| JLS | 0:26bcd4640f94 | 372 | // Sent X-pos, Y-pos, Sector Address - This is the recommended way to display video | 
| JLS | 0:26bcd4640f94 | 373 | //**************************************************************************************************** | 
| JLS | 0:26bcd4640f94 | 374 | void TFT_4DGL :: uSD_Video(int x, int y, long s) { | 
| JLS | 0:26bcd4640f94 | 375 | char S1, S2, S3; | 
| JLS | 0:26bcd4640f94 | 376 | char X_MSB, X_LSB, Y_MSB, Y_LSB; | 
| JLS | 0:26bcd4640f94 | 377 | char command[10]= ""; | 
| JLS | 0:26bcd4640f94 | 378 | |
| JLS | 0:26bcd4640f94 | 379 | X_LSB = x&0x00FF; | 
| JLS | 0:26bcd4640f94 | 380 | X_MSB = (x >> 8); | 
| JLS | 0:26bcd4640f94 | 381 | Y_LSB = y&0x00FF; | 
| JLS | 0:26bcd4640f94 | 382 | Y_MSB = (y >> 8); | 
| JLS | 0:26bcd4640f94 | 383 | |
| JLS | 0:26bcd4640f94 | 384 | S1 = (s >> 16)&0x0000FF; | 
| JLS | 0:26bcd4640f94 | 385 | S2 = (s >> 8)&0x0000FF; | 
| JLS | 0:26bcd4640f94 | 386 | S3 = s&0x0000FF; | 
| JLS | 0:26bcd4640f94 | 387 | |
| JLS | 0:26bcd4640f94 | 388 | command[0] = 0x40; //ext_cmd | 
| JLS | 0:26bcd4640f94 | 389 | command[1] = 0x56; //Display video | 
| JLS | 0:26bcd4640f94 | 390 | command[2] = X_MSB; //X position - 2 bytes | 
| JLS | 0:26bcd4640f94 | 391 | command[3] = X_LSB; | 
| JLS | 0:26bcd4640f94 | 392 | command[4] = Y_MSB; //Y position - 2 bytes | 
| JLS | 0:26bcd4640f94 | 393 | command[5] = Y_LSB; | 
| JLS | 0:26bcd4640f94 | 394 | command[6] = 0x00; //delay between frames | 
| JLS | 0:26bcd4640f94 | 395 | command[7] = S1; //Sector address - 3 bytes | 
| JLS | 0:26bcd4640f94 | 396 | command[8] = S2; | 
| JLS | 0:26bcd4640f94 | 397 | command[9] = S3; | 
| JLS | 0:26bcd4640f94 | 398 | |
| JLS | 0:26bcd4640f94 | 399 | writeCOMMAND(command, 10); | 
| JLS | 0:26bcd4640f94 | 400 | } |