With added colors.

Dependents:   Arcade_RedX

Fork of 4DGL-uLCD-SE by jim hamblen

Committer:
4180_1
Date:
Mon Nov 25 04:24:22 2013 +0000
Revision:
6:b759b69cbaf9
Parent:
1:8b656995301f
ver1.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AdamGreen 0:d6e186427f3e 1 //
4180_1 6:b759b69cbaf9 2 // uLCD_4DGL is a class to drive 4D Systems LCD screens
AdamGreen 0:d6e186427f3e 3 //
AdamGreen 0:d6e186427f3e 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
AdamGreen 0:d6e186427f3e 5 //
4180_1 1:8b656995301f 6 // uLCD_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 //
4180_1 1:8b656995301f 11 // uLCD_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
4180_1 1:8b656995301f 17 // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>.
AdamGreen 0:d6e186427f3e 18
AdamGreen 0:d6e186427f3e 19 #include "mbed.h"
4180_1 1:8b656995301f 20 #include "uLCD_4DGL.h"
AdamGreen 0:d6e186427f3e 21
AdamGreen 0:d6e186427f3e 22 //******************************************************************************************************
4180_1 6:b759b69cbaf9 23 void uLCD_4DGL :: touch_mode(char mode) // Send touch mode (WAIT, PRESS, RELEASE or MOVE)
4180_1 6:b759b69cbaf9 24 {
AdamGreen 0:d6e186427f3e 25
AdamGreen 0:d6e186427f3e 26 char command[2]= "";
AdamGreen 0:d6e186427f3e 27
AdamGreen 0:d6e186427f3e 28 command[0] = GETTOUCH;
AdamGreen 0:d6e186427f3e 29 command[1] = mode;
AdamGreen 0:d6e186427f3e 30
AdamGreen 0:d6e186427f3e 31 writeCOMMAND(command, 2);
AdamGreen 0:d6e186427f3e 32 }
AdamGreen 0:d6e186427f3e 33
AdamGreen 0:d6e186427f3e 34 //******************************************************************************************************
4180_1 6:b759b69cbaf9 35 void uLCD_4DGL :: get_touch(int *x, int *y) // Get the touch coordinates
4180_1 6:b759b69cbaf9 36 {
AdamGreen 0:d6e186427f3e 37
AdamGreen 0:d6e186427f3e 38 char command[2] = "";
4180_1 6:b759b69cbaf9 39
AdamGreen 0:d6e186427f3e 40 command[0] = GETTOUCH;
AdamGreen 0:d6e186427f3e 41 command[1] = GETPOSITION;
4180_1 6:b759b69cbaf9 42
AdamGreen 0:d6e186427f3e 43 getTOUCH(command, 2, x, y);
AdamGreen 0:d6e186427f3e 44 }
AdamGreen 0:d6e186427f3e 45
AdamGreen 0:d6e186427f3e 46 //******************************************************************************************************
4180_1 6:b759b69cbaf9 47 int uLCD_4DGL :: touch_status(void) // Get the touch screen status
4180_1 6:b759b69cbaf9 48 {
AdamGreen 0:d6e186427f3e 49
AdamGreen 0:d6e186427f3e 50 char command[2] = "";
4180_1 6:b759b69cbaf9 51
AdamGreen 0:d6e186427f3e 52 command[0] = GETTOUCH;
AdamGreen 0:d6e186427f3e 53 command[1] = STATUS;
4180_1 6:b759b69cbaf9 54
AdamGreen 0:d6e186427f3e 55 return getSTATUS(command, 2);
AdamGreen 0:d6e186427f3e 56 }
AdamGreen 0:d6e186427f3e 57
AdamGreen 0:d6e186427f3e 58
AdamGreen 0:d6e186427f3e 59 //******************************************************************************************************
4180_1 6:b759b69cbaf9 60 void uLCD_4DGL :: wait_touch(int delay) // wait until touch within a delay in milliseconds
4180_1 6:b759b69cbaf9 61 {
AdamGreen 0:d6e186427f3e 62
AdamGreen 0:d6e186427f3e 63 char command[3]= "";
AdamGreen 0:d6e186427f3e 64
AdamGreen 0:d6e186427f3e 65 command[0] = WAITTOUCH;
AdamGreen 0:d6e186427f3e 66
AdamGreen 0:d6e186427f3e 67 command[1] = (delay >> 8) & 0xFF;
AdamGreen 0:d6e186427f3e 68 command[2] = delay & 0xFF;
AdamGreen 0:d6e186427f3e 69
AdamGreen 0:d6e186427f3e 70 writeCOMMAND(command, 3);
AdamGreen 0:d6e186427f3e 71 }
AdamGreen 0:d6e186427f3e 72
AdamGreen 0:d6e186427f3e 73 //******************************************************************************************************
4180_1 6:b759b69cbaf9 74 void uLCD_4DGL :: set_touch(int x1, int y1 , int x2, int y2) // define touch area
4180_1 6:b759b69cbaf9 75 {
AdamGreen 0:d6e186427f3e 76
AdamGreen 0:d6e186427f3e 77 char command[9]= "";
AdamGreen 0:d6e186427f3e 78
AdamGreen 0:d6e186427f3e 79 command[0] = SETTOUCH;
AdamGreen 0:d6e186427f3e 80
AdamGreen 0:d6e186427f3e 81 command[1] = (x1 >> 8) & 0xFF;
AdamGreen 0:d6e186427f3e 82 command[2] = x1 & 0xFF;
AdamGreen 0:d6e186427f3e 83
AdamGreen 0:d6e186427f3e 84 command[3] = (y1 >> 8) & 0xFF;
AdamGreen 0:d6e186427f3e 85 command[4] = y1 & 0xFF;
AdamGreen 0:d6e186427f3e 86
AdamGreen 0:d6e186427f3e 87 command[5] = (x2 >> 8) & 0xFF;
AdamGreen 0:d6e186427f3e 88 command[6] = x2 & 0xFF;
AdamGreen 0:d6e186427f3e 89
AdamGreen 0:d6e186427f3e 90 command[7] = (y2 >> 8) & 0xFF;
AdamGreen 0:d6e186427f3e 91 command[8] = y2 & 0xFF;
AdamGreen 0:d6e186427f3e 92
AdamGreen 0:d6e186427f3e 93 writeCOMMAND(command, 9);
4180_1 6:b759b69cbaf9 94 }
4180_1 6:b759b69cbaf9 95 //Media Commands
4180_1 6:b759b69cbaf9 96
4180_1 6:b759b69cbaf9 97 //******************************************************************************************************
4180_1 6:b759b69cbaf9 98 int uLCD_4DGL :: media_init()
4180_1 6:b759b69cbaf9 99 {
4180_1 6:b759b69cbaf9 100 int resp = 0;
4180_1 6:b759b69cbaf9 101 char command[1] = "";
4180_1 6:b759b69cbaf9 102 command[0] = MINIT;
4180_1 6:b759b69cbaf9 103 writeCOMMAND(command, 1);
4180_1 6:b759b69cbaf9 104 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 6:b759b69cbaf9 105 if (_cmd.readable()) {
4180_1 6:b759b69cbaf9 106 resp = _cmd.getc(); // read response
4180_1 6:b759b69cbaf9 107 resp = resp << 8 + _cmd.getc();
4180_1 6:b759b69cbaf9 108 }
4180_1 6:b759b69cbaf9 109 return resp;
4180_1 6:b759b69cbaf9 110 }
4180_1 6:b759b69cbaf9 111
4180_1 6:b759b69cbaf9 112 //******************************************************************************************************
4180_1 6:b759b69cbaf9 113 void uLCD_4DGL :: set_byte_address(int hi, int lo)
4180_1 6:b759b69cbaf9 114 {
4180_1 6:b759b69cbaf9 115 char command[5]= "";
4180_1 6:b759b69cbaf9 116 command[0] = SBADDRESS;
4180_1 6:b759b69cbaf9 117
4180_1 6:b759b69cbaf9 118 command[1] = (hi >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 119 command[2] = hi & 0xFF;
4180_1 6:b759b69cbaf9 120
4180_1 6:b759b69cbaf9 121 command[3] = (lo >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 122 command[4] = lo & 0xFF;
4180_1 6:b759b69cbaf9 123 writeCOMMAND(command, 5);
4180_1 6:b759b69cbaf9 124 }
4180_1 6:b759b69cbaf9 125
4180_1 6:b759b69cbaf9 126 //******************************************************************************************************
4180_1 6:b759b69cbaf9 127 void uLCD_4DGL :: set_sector_address(int hi, int lo)
4180_1 6:b759b69cbaf9 128 {
4180_1 6:b759b69cbaf9 129
4180_1 6:b759b69cbaf9 130 char command[5]= "";
4180_1 6:b759b69cbaf9 131 command[0] = SSADDRESS;
4180_1 6:b759b69cbaf9 132
4180_1 6:b759b69cbaf9 133 command[1] = (hi >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 134 command[2] = hi & 0xFF;
4180_1 6:b759b69cbaf9 135
4180_1 6:b759b69cbaf9 136 command[3] = (lo >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 137 command[4] = lo & 0xFF;
4180_1 6:b759b69cbaf9 138 writeCOMMAND(command, 5);
4180_1 6:b759b69cbaf9 139 }
4180_1 6:b759b69cbaf9 140
4180_1 6:b759b69cbaf9 141 //******************************************************************************************************
4180_1 6:b759b69cbaf9 142 char uLCD_4DGL :: read_byte()
4180_1 6:b759b69cbaf9 143 {
4180_1 6:b759b69cbaf9 144 char resp = 0;
4180_1 6:b759b69cbaf9 145 char command[1] = "";
4180_1 6:b759b69cbaf9 146 command[0] = READBYTE;
4180_1 6:b759b69cbaf9 147 writeCOMMAND(command, 1);
4180_1 6:b759b69cbaf9 148 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 6:b759b69cbaf9 149 if (_cmd.readable()) {
4180_1 6:b759b69cbaf9 150 resp = _cmd.getc(); // read response
4180_1 6:b759b69cbaf9 151 resp = _cmd.getc();
4180_1 6:b759b69cbaf9 152 }
4180_1 6:b759b69cbaf9 153 return resp;
4180_1 6:b759b69cbaf9 154 }
4180_1 6:b759b69cbaf9 155
4180_1 6:b759b69cbaf9 156 //******************************************************************************************************
4180_1 6:b759b69cbaf9 157 int uLCD_4DGL :: read_word()
4180_1 6:b759b69cbaf9 158 {
4180_1 6:b759b69cbaf9 159 int resp=0;
4180_1 6:b759b69cbaf9 160 char command[1] = "";
4180_1 6:b759b69cbaf9 161 command[0] = READWORD;
4180_1 6:b759b69cbaf9 162 writeCOMMAND(command, 1);
4180_1 6:b759b69cbaf9 163 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 6:b759b69cbaf9 164 if (_cmd.readable()) {
4180_1 6:b759b69cbaf9 165 resp = _cmd.getc(); // read response
4180_1 6:b759b69cbaf9 166 resp = resp << 8 + _cmd.getc();
4180_1 6:b759b69cbaf9 167 }
4180_1 6:b759b69cbaf9 168 return resp;
4180_1 6:b759b69cbaf9 169 }
4180_1 6:b759b69cbaf9 170
4180_1 6:b759b69cbaf9 171 //******************************************************************************************************
4180_1 6:b759b69cbaf9 172 void uLCD_4DGL :: write_byte(int value)
4180_1 6:b759b69cbaf9 173 {
4180_1 6:b759b69cbaf9 174 char command[3]= "";
4180_1 6:b759b69cbaf9 175
4180_1 6:b759b69cbaf9 176 command[0] = WRITEBYTE;
4180_1 6:b759b69cbaf9 177
4180_1 6:b759b69cbaf9 178 command[1] = (value >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 179 command[2] = value & 0xFF;
4180_1 6:b759b69cbaf9 180 writeCOMMAND(command,3);
4180_1 6:b759b69cbaf9 181 }
4180_1 6:b759b69cbaf9 182
4180_1 6:b759b69cbaf9 183 //******************************************************************************************************
4180_1 6:b759b69cbaf9 184 void uLCD_4DGL :: write_word(int value)
4180_1 6:b759b69cbaf9 185 {
4180_1 6:b759b69cbaf9 186 char command[3]= "";
4180_1 6:b759b69cbaf9 187
4180_1 6:b759b69cbaf9 188 command[0] = WRITEWORD;
4180_1 6:b759b69cbaf9 189
4180_1 6:b759b69cbaf9 190 command[1] = (value >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 191 command[2] = value & 0xFF;
4180_1 6:b759b69cbaf9 192 writeCOMMAND(command,3);
4180_1 6:b759b69cbaf9 193 }
4180_1 6:b759b69cbaf9 194
4180_1 6:b759b69cbaf9 195 //******************************************************************************************************
4180_1 6:b759b69cbaf9 196 void uLCD_4DGL :: flush_media()
4180_1 6:b759b69cbaf9 197 {
4180_1 6:b759b69cbaf9 198 char command[1] = "";
4180_1 6:b759b69cbaf9 199 command[0] = FLUSHMEDIA;
4180_1 6:b759b69cbaf9 200 writeCOMMAND(command, 1);
4180_1 6:b759b69cbaf9 201 }
4180_1 6:b759b69cbaf9 202
4180_1 6:b759b69cbaf9 203 //******************************************************************************************************
4180_1 6:b759b69cbaf9 204 void uLCD_4DGL :: display_image(int x, int y)
4180_1 6:b759b69cbaf9 205 {
4180_1 6:b759b69cbaf9 206 char command[6]= "";
4180_1 6:b759b69cbaf9 207 command[0] = DISPLAYIMAGE;
4180_1 6:b759b69cbaf9 208
4180_1 6:b759b69cbaf9 209 command[1] = (x >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 210 command[2] = x & 0xFF;
4180_1 6:b759b69cbaf9 211
4180_1 6:b759b69cbaf9 212 command[3] = (y >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 213 command[4] = y & 0xFF;
4180_1 6:b759b69cbaf9 214 writeCOMMAND(command, 5);
4180_1 6:b759b69cbaf9 215 }
4180_1 6:b759b69cbaf9 216
4180_1 6:b759b69cbaf9 217 //******************************************************************************************************
4180_1 6:b759b69cbaf9 218 void uLCD_4DGL :: display_video(int x, int y)
4180_1 6:b759b69cbaf9 219 {
4180_1 6:b759b69cbaf9 220 char command[5]= "";
4180_1 6:b759b69cbaf9 221 command[0] = DISPLAYVIDEO;
4180_1 6:b759b69cbaf9 222
4180_1 6:b759b69cbaf9 223 command[1] = (x >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 224 command[2] = x & 0xFF;
4180_1 6:b759b69cbaf9 225
4180_1 6:b759b69cbaf9 226 command[3] = (y >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 227 command[4] = y & 0xFF;
4180_1 6:b759b69cbaf9 228 writeCOMMAND(command, 5);
4180_1 6:b759b69cbaf9 229 }
4180_1 6:b759b69cbaf9 230
4180_1 6:b759b69cbaf9 231 //******************************************************************************************************
4180_1 6:b759b69cbaf9 232 void uLCD_4DGL :: display_frame(int x, int y, int w)
4180_1 6:b759b69cbaf9 233 {
4180_1 6:b759b69cbaf9 234 char command[7]= "";
4180_1 6:b759b69cbaf9 235
4180_1 6:b759b69cbaf9 236 command[0] = DISPLAYFRAME;
4180_1 6:b759b69cbaf9 237
4180_1 6:b759b69cbaf9 238 command[1] = (x >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 239 command[2] = x & 0xFF;
4180_1 6:b759b69cbaf9 240
4180_1 6:b759b69cbaf9 241 command[3] = (y >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 242 command[4] = y & 0xFF;
4180_1 6:b759b69cbaf9 243
4180_1 6:b759b69cbaf9 244 command[5] = (w >> 8) & 0xFF;
4180_1 6:b759b69cbaf9 245 command[6] = w & 0xFF;
4180_1 6:b759b69cbaf9 246 writeCOMMAND(command,7);
4180_1 6:b759b69cbaf9 247 }