Allow user to connect multiple screen.

Dependencies:   mbed-rtos mbed

Committer:
Ratchapong
Date:
Wed Mar 11 05:00:37 2015 +0000
Revision:
0:052d0f82433e
Working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ratchapong 0:052d0f82433e 1 //
Ratchapong 0:052d0f82433e 2 // uLCD_4DGL is a class to drive 4D Systems LCD screens
Ratchapong 0:052d0f82433e 3 //
Ratchapong 0:052d0f82433e 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
Ratchapong 0:052d0f82433e 5 // Modifed for Goldelox processor <2013> Jim Hamblen
Ratchapong 0:052d0f82433e 6 //
Ratchapong 0:052d0f82433e 7 // uLCD_4DGL is free software: you can redistribute it and/or modify
Ratchapong 0:052d0f82433e 8 // it under the terms of the GNU General Public License as published by
Ratchapong 0:052d0f82433e 9 // the Free Software Foundation, either version 3 of the License, or
Ratchapong 0:052d0f82433e 10 // (at your option) any later version.
Ratchapong 0:052d0f82433e 11 //
Ratchapong 0:052d0f82433e 12 // uLCD_4DGL is distributed in the hope that it will be useful,
Ratchapong 0:052d0f82433e 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
Ratchapong 0:052d0f82433e 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Ratchapong 0:052d0f82433e 15 // GNU General Public License for more details.
Ratchapong 0:052d0f82433e 16 //
Ratchapong 0:052d0f82433e 17 // You should have received a copy of the GNU General Public License
Ratchapong 0:052d0f82433e 18 // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>.
Ratchapong 0:052d0f82433e 19
Ratchapong 0:052d0f82433e 20 #include "mbed.h"
Ratchapong 0:052d0f82433e 21 #include "uLCD_4DGL.h"
Ratchapong 0:052d0f82433e 22
Ratchapong 0:052d0f82433e 23
Ratchapong 0:052d0f82433e 24 //Media Commands
Ratchapong 0:052d0f82433e 25
Ratchapong 0:052d0f82433e 26 //******************************************************************************************************
Ratchapong 0:052d0f82433e 27 int uLCD_4DGL :: media_init()
Ratchapong 0:052d0f82433e 28 {
Ratchapong 0:052d0f82433e 29 int resp = 0;
Ratchapong 0:052d0f82433e 30 char command[1] = "";
Ratchapong 0:052d0f82433e 31 command[0] = MINIT;
Ratchapong 0:052d0f82433e 32 writeCOMMAND(command, 1);
Ratchapong 0:052d0f82433e 33 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
Ratchapong 0:052d0f82433e 34 if (_cmd.readable()) {
Ratchapong 0:052d0f82433e 35 resp = _cmd.getc(); // read response
Ratchapong 0:052d0f82433e 36 resp = resp << 8 + _cmd.getc();
Ratchapong 0:052d0f82433e 37 }
Ratchapong 0:052d0f82433e 38 return resp;
Ratchapong 0:052d0f82433e 39 }
Ratchapong 0:052d0f82433e 40
Ratchapong 0:052d0f82433e 41 //******************************************************************************************************
Ratchapong 0:052d0f82433e 42 void uLCD_4DGL :: set_byte_address(int hi, int lo)
Ratchapong 0:052d0f82433e 43 {
Ratchapong 0:052d0f82433e 44 char command[5]= "";
Ratchapong 0:052d0f82433e 45 command[0] = SBADDRESS;
Ratchapong 0:052d0f82433e 46
Ratchapong 0:052d0f82433e 47 command[1] = (hi >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 48 command[2] = hi & 0xFF;
Ratchapong 0:052d0f82433e 49
Ratchapong 0:052d0f82433e 50 command[3] = (lo >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 51 command[4] = lo & 0xFF;
Ratchapong 0:052d0f82433e 52 writeCOMMAND(command, 5);
Ratchapong 0:052d0f82433e 53 }
Ratchapong 0:052d0f82433e 54
Ratchapong 0:052d0f82433e 55 //******************************************************************************************************
Ratchapong 0:052d0f82433e 56 void uLCD_4DGL :: set_sector_address(int hi, int lo)
Ratchapong 0:052d0f82433e 57 {
Ratchapong 0:052d0f82433e 58
Ratchapong 0:052d0f82433e 59 char command[5]= "";
Ratchapong 0:052d0f82433e 60 command[0] = SSADDRESS;
Ratchapong 0:052d0f82433e 61
Ratchapong 0:052d0f82433e 62 command[1] = (hi >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 63 command[2] = hi & 0xFF;
Ratchapong 0:052d0f82433e 64
Ratchapong 0:052d0f82433e 65 command[3] = (lo >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 66 command[4] = lo & 0xFF;
Ratchapong 0:052d0f82433e 67 writeCOMMAND(command, 5);
Ratchapong 0:052d0f82433e 68 }
Ratchapong 0:052d0f82433e 69
Ratchapong 0:052d0f82433e 70 //******************************************************************************************************
Ratchapong 0:052d0f82433e 71 char uLCD_4DGL :: read_byte()
Ratchapong 0:052d0f82433e 72 {
Ratchapong 0:052d0f82433e 73 char resp = 0;
Ratchapong 0:052d0f82433e 74 char command[1] = "";
Ratchapong 0:052d0f82433e 75 command[0] = READBYTE;
Ratchapong 0:052d0f82433e 76 writeCOMMAND(command, 1);
Ratchapong 0:052d0f82433e 77 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
Ratchapong 0:052d0f82433e 78 if (_cmd.readable()) {
Ratchapong 0:052d0f82433e 79 resp = _cmd.getc(); // read response
Ratchapong 0:052d0f82433e 80 resp = _cmd.getc();
Ratchapong 0:052d0f82433e 81 }
Ratchapong 0:052d0f82433e 82 return resp;
Ratchapong 0:052d0f82433e 83 }
Ratchapong 0:052d0f82433e 84
Ratchapong 0:052d0f82433e 85 //******************************************************************************************************
Ratchapong 0:052d0f82433e 86 int uLCD_4DGL :: read_word()
Ratchapong 0:052d0f82433e 87 {
Ratchapong 0:052d0f82433e 88 int resp=0;
Ratchapong 0:052d0f82433e 89 char command[1] = "";
Ratchapong 0:052d0f82433e 90 command[0] = READWORD;
Ratchapong 0:052d0f82433e 91 writeCOMMAND(command, 1);
Ratchapong 0:052d0f82433e 92 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
Ratchapong 0:052d0f82433e 93 if (_cmd.readable()) {
Ratchapong 0:052d0f82433e 94 resp = _cmd.getc(); // read response
Ratchapong 0:052d0f82433e 95 resp = resp << 8 + _cmd.getc();
Ratchapong 0:052d0f82433e 96 }
Ratchapong 0:052d0f82433e 97 return resp;
Ratchapong 0:052d0f82433e 98 }
Ratchapong 0:052d0f82433e 99
Ratchapong 0:052d0f82433e 100 //******************************************************************************************************
Ratchapong 0:052d0f82433e 101 void uLCD_4DGL :: write_byte(int value)
Ratchapong 0:052d0f82433e 102 {
Ratchapong 0:052d0f82433e 103 char command[3]= "";
Ratchapong 0:052d0f82433e 104
Ratchapong 0:052d0f82433e 105 command[0] = WRITEBYTE;
Ratchapong 0:052d0f82433e 106
Ratchapong 0:052d0f82433e 107 command[1] = (value >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 108 command[2] = value & 0xFF;
Ratchapong 0:052d0f82433e 109 writeCOMMAND(command,3);
Ratchapong 0:052d0f82433e 110 }
Ratchapong 0:052d0f82433e 111
Ratchapong 0:052d0f82433e 112 //******************************************************************************************************
Ratchapong 0:052d0f82433e 113 void uLCD_4DGL :: write_word(int value)
Ratchapong 0:052d0f82433e 114 {
Ratchapong 0:052d0f82433e 115 char command[3]= "";
Ratchapong 0:052d0f82433e 116
Ratchapong 0:052d0f82433e 117 command[0] = WRITEWORD;
Ratchapong 0:052d0f82433e 118
Ratchapong 0:052d0f82433e 119 command[1] = (value >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 120 command[2] = value & 0xFF;
Ratchapong 0:052d0f82433e 121 writeCOMMAND(command,3);
Ratchapong 0:052d0f82433e 122 }
Ratchapong 0:052d0f82433e 123
Ratchapong 0:052d0f82433e 124 //******************************************************************************************************
Ratchapong 0:052d0f82433e 125 void uLCD_4DGL :: flush_media()
Ratchapong 0:052d0f82433e 126 {
Ratchapong 0:052d0f82433e 127 char command[1] = "";
Ratchapong 0:052d0f82433e 128 command[0] = FLUSHMEDIA;
Ratchapong 0:052d0f82433e 129 writeCOMMAND(command, 1);
Ratchapong 0:052d0f82433e 130 }
Ratchapong 0:052d0f82433e 131
Ratchapong 0:052d0f82433e 132 //******************************************************************************************************
Ratchapong 0:052d0f82433e 133 void uLCD_4DGL :: display_image(int x, int y)
Ratchapong 0:052d0f82433e 134 {
Ratchapong 0:052d0f82433e 135 char command[6]= "";
Ratchapong 0:052d0f82433e 136 command[0] = DISPLAYIMAGE;
Ratchapong 0:052d0f82433e 137
Ratchapong 0:052d0f82433e 138 command[1] = (x >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 139 command[2] = x & 0xFF;
Ratchapong 0:052d0f82433e 140
Ratchapong 0:052d0f82433e 141 command[3] = (y >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 142 command[4] = y & 0xFF;
Ratchapong 0:052d0f82433e 143 writeCOMMAND(command, 5);
Ratchapong 0:052d0f82433e 144 }
Ratchapong 0:052d0f82433e 145
Ratchapong 0:052d0f82433e 146 //******************************************************************************************************
Ratchapong 0:052d0f82433e 147 void uLCD_4DGL :: display_video(int x, int y)
Ratchapong 0:052d0f82433e 148 {
Ratchapong 0:052d0f82433e 149 char command[5]= "";
Ratchapong 0:052d0f82433e 150 command[0] = DISPLAYVIDEO;
Ratchapong 0:052d0f82433e 151
Ratchapong 0:052d0f82433e 152 command[1] = (x >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 153 command[2] = x & 0xFF;
Ratchapong 0:052d0f82433e 154
Ratchapong 0:052d0f82433e 155 command[3] = (y >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 156 command[4] = y & 0xFF;
Ratchapong 0:052d0f82433e 157 writeCOMMAND(command, 5);
Ratchapong 0:052d0f82433e 158 }
Ratchapong 0:052d0f82433e 159
Ratchapong 0:052d0f82433e 160 //******************************************************************************************************
Ratchapong 0:052d0f82433e 161 void uLCD_4DGL :: display_frame(int x, int y, int w)
Ratchapong 0:052d0f82433e 162 {
Ratchapong 0:052d0f82433e 163 char command[7]= "";
Ratchapong 0:052d0f82433e 164
Ratchapong 0:052d0f82433e 165 command[0] = DISPLAYFRAME;
Ratchapong 0:052d0f82433e 166
Ratchapong 0:052d0f82433e 167 command[1] = (x >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 168 command[2] = x & 0xFF;
Ratchapong 0:052d0f82433e 169
Ratchapong 0:052d0f82433e 170 command[3] = (y >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 171 command[4] = y & 0xFF;
Ratchapong 0:052d0f82433e 172
Ratchapong 0:052d0f82433e 173 command[5] = (w >> 8) & 0xFF;
Ratchapong 0:052d0f82433e 174 command[6] = w & 0xFF;
Ratchapong 0:052d0f82433e 175 writeCOMMAND(command,7);
Ratchapong 0:052d0f82433e 176 }
Ratchapong 0:052d0f82433e 177