Finished Lab 4 Pt 1

Dependencies:   mbed Sounds PinDetect

Committer:
trmontgomery
Date:
Fri Apr 05 19:46:26 2019 +0000
Revision:
0:daf9e2f8e1a1
Finished Lab 4 pt 1

Who changed what in which revision?

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