ajfja

Fork of 4DGL-uLCD-SE by Jonathan Austin

Committer:
anevil14
Date:
Fri May 01 16:49:27 2015 +0000
Revision:
1:df77db998389
No Changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anevil14 1:df77db998389 1 //
anevil14 1:df77db998389 2 // uLCD_4DGL is a class to drive 4D Systems LCD screens
anevil14 1:df77db998389 3 //
anevil14 1:df77db998389 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
anevil14 1:df77db998389 5 // Modifed for Goldelox processor <2013> Jim Hamblen
anevil14 1:df77db998389 6 //
anevil14 1:df77db998389 7 // uLCD_4DGL is free software: you can redistribute it and/or modify
anevil14 1:df77db998389 8 // it under the terms of the GNU General Public License as published by
anevil14 1:df77db998389 9 // the Free Software Foundation, either version 3 of the License, or
anevil14 1:df77db998389 10 // (at your option) any later version.
anevil14 1:df77db998389 11 //
anevil14 1:df77db998389 12 // uLCD_4DGL is distributed in the hope that it will be useful,
anevil14 1:df77db998389 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
anevil14 1:df77db998389 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
anevil14 1:df77db998389 15 // GNU General Public License for more details.
anevil14 1:df77db998389 16 //
anevil14 1:df77db998389 17 // You should have received a copy of the GNU General Public License
anevil14 1:df77db998389 18 // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>.
anevil14 1:df77db998389 19
anevil14 1:df77db998389 20 #include "mbed.h"
anevil14 1:df77db998389 21 #include "uLCD_4DGL.h"
anevil14 1:df77db998389 22
anevil14 1:df77db998389 23 #define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0])
anevil14 1:df77db998389 24
anevil14 1:df77db998389 25 //****************************************************************************************************
anevil14 1:df77db998389 26 void uLCD_4DGL :: circle(int x, int y , int radius, int color) // draw a circle in (x,y)
anevil14 1:df77db998389 27 {
anevil14 1:df77db998389 28 char command[9]= "";
anevil14 1:df77db998389 29
anevil14 1:df77db998389 30 command[0] = CIRCLE;
anevil14 1:df77db998389 31
anevil14 1:df77db998389 32 command[1] = (x >> 8) & 0xFF;
anevil14 1:df77db998389 33 command[2] = x & 0xFF;
anevil14 1:df77db998389 34
anevil14 1:df77db998389 35 command[3] = (y >> 8) & 0xFF;
anevil14 1:df77db998389 36 command[4] = y & 0xFF;
anevil14 1:df77db998389 37
anevil14 1:df77db998389 38 command[5] = (radius >> 8) & 0xFF;
anevil14 1:df77db998389 39 command[6] = radius & 0xFF;
anevil14 1:df77db998389 40
anevil14 1:df77db998389 41 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
anevil14 1:df77db998389 42 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
anevil14 1:df77db998389 43 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
anevil14 1:df77db998389 44
anevil14 1:df77db998389 45 command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
anevil14 1:df77db998389 46 command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
anevil14 1:df77db998389 47
anevil14 1:df77db998389 48 writeCOMMAND(command, 9);
anevil14 1:df77db998389 49 }
anevil14 1:df77db998389 50 //****************************************************************************************************
anevil14 1:df77db998389 51 void uLCD_4DGL :: filled_circle(int x, int y , int radius, int color) // draw a circle in (x,y)
anevil14 1:df77db998389 52 {
anevil14 1:df77db998389 53 char command[9]= "";
anevil14 1:df77db998389 54
anevil14 1:df77db998389 55 command[0] = FCIRCLE;
anevil14 1:df77db998389 56
anevil14 1:df77db998389 57 command[1] = (x >> 8) & 0xFF;
anevil14 1:df77db998389 58 command[2] = x & 0xFF;
anevil14 1:df77db998389 59
anevil14 1:df77db998389 60 command[3] = (y >> 8) & 0xFF;
anevil14 1:df77db998389 61 command[4] = y & 0xFF;
anevil14 1:df77db998389 62
anevil14 1:df77db998389 63 command[5] = (radius >> 8) & 0xFF;
anevil14 1:df77db998389 64 command[6] = radius & 0xFF;
anevil14 1:df77db998389 65
anevil14 1:df77db998389 66 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
anevil14 1:df77db998389 67 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
anevil14 1:df77db998389 68 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
anevil14 1:df77db998389 69
anevil14 1:df77db998389 70 command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
anevil14 1:df77db998389 71 command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
anevil14 1:df77db998389 72
anevil14 1:df77db998389 73 writeCOMMAND(command, 9);
anevil14 1:df77db998389 74 }
anevil14 1:df77db998389 75
anevil14 1:df77db998389 76 //****************************************************************************************************
anevil14 1:df77db998389 77 void uLCD_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) // draw a traingle
anevil14 1:df77db998389 78 {
anevil14 1:df77db998389 79 char command[15]= "";
anevil14 1:df77db998389 80
anevil14 1:df77db998389 81 command[0] = TRIANGLE;
anevil14 1:df77db998389 82
anevil14 1:df77db998389 83 command[1] = (x1 >> 8) & 0xFF;
anevil14 1:df77db998389 84 command[2] = x1 & 0xFF;
anevil14 1:df77db998389 85
anevil14 1:df77db998389 86 command[3] = (y1 >> 8) & 0xFF;
anevil14 1:df77db998389 87 command[4] = y1 & 0xFF;
anevil14 1:df77db998389 88
anevil14 1:df77db998389 89 command[5] = (x2 >> 8) & 0xFF;
anevil14 1:df77db998389 90 command[6] = x2 & 0xFF;
anevil14 1:df77db998389 91
anevil14 1:df77db998389 92 command[7] = (y2 >> 8) & 0xFF;
anevil14 1:df77db998389 93 command[8] = y2 & 0xFF;
anevil14 1:df77db998389 94
anevil14 1:df77db998389 95 command[9] = (x3 >> 8) & 0xFF;
anevil14 1:df77db998389 96 command[10] = x3 & 0xFF;
anevil14 1:df77db998389 97
anevil14 1:df77db998389 98 command[11] = (y3 >> 8) & 0xFF;
anevil14 1:df77db998389 99 command[12] = y3 & 0xFF;
anevil14 1:df77db998389 100
anevil14 1:df77db998389 101 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
anevil14 1:df77db998389 102 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
anevil14 1:df77db998389 103 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
anevil14 1:df77db998389 104
anevil14 1:df77db998389 105 command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
anevil14 1:df77db998389 106 command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
anevil14 1:df77db998389 107
anevil14 1:df77db998389 108 writeCOMMAND(command, 15);
anevil14 1:df77db998389 109 }
anevil14 1:df77db998389 110
anevil14 1:df77db998389 111 //****************************************************************************************************
anevil14 1:df77db998389 112 void uLCD_4DGL :: line(int x1, int y1 , int x2, int y2, int color) // draw a line
anevil14 1:df77db998389 113 {
anevil14 1:df77db998389 114 char command[11]= "";
anevil14 1:df77db998389 115
anevil14 1:df77db998389 116 command[0] = LINE;
anevil14 1:df77db998389 117
anevil14 1:df77db998389 118 command[1] = (x1 >> 8) & 0xFF;
anevil14 1:df77db998389 119 command[2] = x1 & 0xFF;
anevil14 1:df77db998389 120
anevil14 1:df77db998389 121 command[3] = (y1 >> 8) & 0xFF;
anevil14 1:df77db998389 122 command[4] = y1 & 0xFF;
anevil14 1:df77db998389 123
anevil14 1:df77db998389 124 command[5] = (x2 >> 8) & 0xFF;
anevil14 1:df77db998389 125 command[6] = x2 & 0xFF;
anevil14 1:df77db998389 126
anevil14 1:df77db998389 127 command[7] = (y2 >> 8) & 0xFF;
anevil14 1:df77db998389 128 command[8] = y2 & 0xFF;
anevil14 1:df77db998389 129
anevil14 1:df77db998389 130 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
anevil14 1:df77db998389 131 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
anevil14 1:df77db998389 132 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
anevil14 1:df77db998389 133
anevil14 1:df77db998389 134 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
anevil14 1:df77db998389 135 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
anevil14 1:df77db998389 136
anevil14 1:df77db998389 137 writeCOMMAND(command, 11);
anevil14 1:df77db998389 138 }
anevil14 1:df77db998389 139
anevil14 1:df77db998389 140 //****************************************************************************************************
anevil14 1:df77db998389 141 void uLCD_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle
anevil14 1:df77db998389 142 {
anevil14 1:df77db998389 143 char command[11]= "";
anevil14 1:df77db998389 144
anevil14 1:df77db998389 145 command[0] = RECTANGLE;
anevil14 1:df77db998389 146
anevil14 1:df77db998389 147 command[1] = (x1 >> 8) & 0xFF;
anevil14 1:df77db998389 148 command[2] = x1 & 0xFF;
anevil14 1:df77db998389 149
anevil14 1:df77db998389 150 command[3] = (y1 >> 8) & 0xFF;
anevil14 1:df77db998389 151 command[4] = y1 & 0xFF;
anevil14 1:df77db998389 152
anevil14 1:df77db998389 153 command[5] = (x2 >> 8) & 0xFF;
anevil14 1:df77db998389 154 command[6] = x2 & 0xFF;
anevil14 1:df77db998389 155
anevil14 1:df77db998389 156 command[7] = (y2 >> 8) & 0xFF;
anevil14 1:df77db998389 157 command[8] = y2 & 0xFF;
anevil14 1:df77db998389 158
anevil14 1:df77db998389 159 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
anevil14 1:df77db998389 160 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
anevil14 1:df77db998389 161 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
anevil14 1:df77db998389 162
anevil14 1:df77db998389 163 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
anevil14 1:df77db998389 164 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
anevil14 1:df77db998389 165
anevil14 1:df77db998389 166 writeCOMMAND(command, 11);
anevil14 1:df77db998389 167 }
anevil14 1:df77db998389 168
anevil14 1:df77db998389 169 //****************************************************************************************************
anevil14 1:df77db998389 170 void uLCD_4DGL :: filled_rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle
anevil14 1:df77db998389 171 {
anevil14 1:df77db998389 172 char command[11]= "";
anevil14 1:df77db998389 173
anevil14 1:df77db998389 174 command[0] = FRECTANGLE;
anevil14 1:df77db998389 175
anevil14 1:df77db998389 176 command[1] = (x1 >> 8) & 0xFF;
anevil14 1:df77db998389 177 command[2] = x1 & 0xFF;
anevil14 1:df77db998389 178
anevil14 1:df77db998389 179 command[3] = (y1 >> 8) & 0xFF;
anevil14 1:df77db998389 180 command[4] = y1 & 0xFF;
anevil14 1:df77db998389 181
anevil14 1:df77db998389 182 command[5] = (x2 >> 8) & 0xFF;
anevil14 1:df77db998389 183 command[6] = x2 & 0xFF;
anevil14 1:df77db998389 184
anevil14 1:df77db998389 185 command[7] = (y2 >> 8) & 0xFF;
anevil14 1:df77db998389 186 command[8] = y2 & 0xFF;
anevil14 1:df77db998389 187
anevil14 1:df77db998389 188 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
anevil14 1:df77db998389 189 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
anevil14 1:df77db998389 190 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
anevil14 1:df77db998389 191
anevil14 1:df77db998389 192 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
anevil14 1:df77db998389 193 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
anevil14 1:df77db998389 194
anevil14 1:df77db998389 195 writeCOMMAND(command, 11);
anevil14 1:df77db998389 196 }
anevil14 1:df77db998389 197
anevil14 1:df77db998389 198
anevil14 1:df77db998389 199
anevil14 1:df77db998389 200 //****************************************************************************************************
anevil14 1:df77db998389 201 void uLCD_4DGL :: pixel(int x, int y, int color) // draw a pixel
anevil14 1:df77db998389 202 {
anevil14 1:df77db998389 203 char command[7]= "";
anevil14 1:df77db998389 204
anevil14 1:df77db998389 205 command[0] = PIXEL;
anevil14 1:df77db998389 206
anevil14 1:df77db998389 207 command[1] = (x >> 8) & 0xFF;
anevil14 1:df77db998389 208 command[2] = x & 0xFF;
anevil14 1:df77db998389 209
anevil14 1:df77db998389 210 command[3] = (y >> 8) & 0xFF;
anevil14 1:df77db998389 211 command[4] = y & 0xFF;
anevil14 1:df77db998389 212
anevil14 1:df77db998389 213 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
anevil14 1:df77db998389 214 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
anevil14 1:df77db998389 215 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
anevil14 1:df77db998389 216
anevil14 1:df77db998389 217 command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
anevil14 1:df77db998389 218 command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
anevil14 1:df77db998389 219
anevil14 1:df77db998389 220 writeCOMMAND(command, 7);
anevil14 1:df77db998389 221 }
anevil14 1:df77db998389 222 //****************************************************************************************************
anevil14 1:df77db998389 223 void uLCD_4DGL :: BLIT(int x, int y, int w, int h, int *colors) // draw a block of pixels
anevil14 1:df77db998389 224 {
anevil14 1:df77db998389 225 int red5, green6, blue5;
anevil14 1:df77db998389 226 writeBYTEfast('\x00');
anevil14 1:df77db998389 227 writeBYTEfast(BLITCOM);
anevil14 1:df77db998389 228 writeBYTEfast((x >> 8) & 0xFF);
anevil14 1:df77db998389 229 writeBYTEfast(x & 0xFF);
anevil14 1:df77db998389 230 writeBYTEfast((y >> 8) & 0xFF);
anevil14 1:df77db998389 231 writeBYTEfast(y & 0xFF);
anevil14 1:df77db998389 232 writeBYTEfast((w >> 8) & 0xFF);
anevil14 1:df77db998389 233 writeBYTE(w & 0xFF);
anevil14 1:df77db998389 234 writeBYTE((h >> 8) & 0xFF);
anevil14 1:df77db998389 235 writeBYTE(h & 0xFF);
anevil14 1:df77db998389 236 wait_ms(1);
anevil14 1:df77db998389 237 for (int i=0; i<w*h; i++) {
anevil14 1:df77db998389 238 red5 = (colors[i] >> (16 + 3)) & 0x1F; // get red on 5 bits
anevil14 1:df77db998389 239 green6 = (colors[i] >> (8 + 2)) & 0x3F; // get green on 6 bits
anevil14 1:df77db998389 240 blue5 = (colors[i] >> (0 + 3)) & 0x1F; // get blue on 5 bits
anevil14 1:df77db998389 241 writeBYTEfast(((red5 << 3) + (green6 >> 3)) & 0xFF); // first part of 16 bits color
anevil14 1:df77db998389 242 writeBYTEfast(((green6 << 5) + (blue5 >> 0)) & 0xFF); // second part of 16 bits color
anevil14 1:df77db998389 243 }
anevil14 1:df77db998389 244 int resp=0;
anevil14 1:df77db998389 245 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
anevil14 1:df77db998389 246 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
anevil14 1:df77db998389 247 switch (resp) {
anevil14 1:df77db998389 248 case ACK : // if OK return 1
anevil14 1:df77db998389 249 resp = 1;
anevil14 1:df77db998389 250 break;
anevil14 1:df77db998389 251 case NAK : // if NOK return -1
anevil14 1:df77db998389 252 resp = -1;
anevil14 1:df77db998389 253 break;
anevil14 1:df77db998389 254 default :
anevil14 1:df77db998389 255 resp = 0; // else return 0
anevil14 1:df77db998389 256 break;
anevil14 1:df77db998389 257 }
anevil14 1:df77db998389 258 #if DEBUGMODE
anevil14 1:df77db998389 259 pc.printf(" Answer received : %d\n",resp);
anevil14 1:df77db998389 260 #endif
anevil14 1:df77db998389 261
anevil14 1:df77db998389 262 }
anevil14 1:df77db998389 263 //******************************************************************************************************
anevil14 1:df77db998389 264 int uLCD_4DGL :: read_pixel(int x, int y) // read screen info and populate data
anevil14 1:df77db998389 265 {
anevil14 1:df77db998389 266
anevil14 1:df77db998389 267 char command[6]= "";
anevil14 1:df77db998389 268 command[0] = 0xFF;
anevil14 1:df77db998389 269 command[1] = READPIXEL;
anevil14 1:df77db998389 270
anevil14 1:df77db998389 271 command[2] = (x >> 8) & 0xFF;
anevil14 1:df77db998389 272 command[3] = x & 0xFF;
anevil14 1:df77db998389 273
anevil14 1:df77db998389 274 command[4] = (y >> 8) & 0xFF;
anevil14 1:df77db998389 275 command[5] = y & 0xFF;
anevil14 1:df77db998389 276
anevil14 1:df77db998389 277 int i, temp = 0, color = 0, resp = 0;
anevil14 1:df77db998389 278 char response[2] = "";
anevil14 1:df77db998389 279
anevil14 1:df77db998389 280 freeBUFFER();
anevil14 1:df77db998389 281
anevil14 1:df77db998389 282 for (i = 0; i < 6; i++) { // send all chars to serial port
anevil14 1:df77db998389 283 writeBYTE(command[i]);
anevil14 1:df77db998389 284 }
anevil14 1:df77db998389 285
anevil14 1:df77db998389 286 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
anevil14 1:df77db998389 287
anevil14 1:df77db998389 288 while (_cmd.readable() && resp < ARRAY_SIZE(response)) {
anevil14 1:df77db998389 289 temp = _cmd.getc();
anevil14 1:df77db998389 290 response[resp++] = (char)temp;
anevil14 1:df77db998389 291 }
anevil14 1:df77db998389 292
anevil14 1:df77db998389 293 color = ((response[0] << 8) + response[1]);
anevil14 1:df77db998389 294
anevil14 1:df77db998389 295 return color; // WARNING : this is 16bits color, not 24bits... need to be fixed
anevil14 1:df77db998389 296 }
anevil14 1:df77db998389 297
anevil14 1:df77db998389 298
anevil14 1:df77db998389 299 //****************************************************************************************************
anevil14 1:df77db998389 300 void uLCD_4DGL :: pen_size(char mode) // set pen to SOLID or WIREFRAME
anevil14 1:df77db998389 301 {
anevil14 1:df77db998389 302 char command[2]= "";
anevil14 1:df77db998389 303
anevil14 1:df77db998389 304 command[0] = PENSIZE;
anevil14 1:df77db998389 305 command[1] = mode;
anevil14 1:df77db998389 306 writeCOMMAND(command, 2);
anevil14 1:df77db998389 307 }
anevil14 1:df77db998389 308
anevil14 1:df77db998389 309
anevil14 1:df77db998389 310