ajfja
Fork of 4DGL-uLCD-SE by
uLCD_4DGL_Media.cpp@1:df77db998389, 2015-05-01 (annotated)
- Committer:
- anevil14
- Date:
- Fri May 01 16:49:27 2015 +0000
- Revision:
- 1:df77db998389
No Changes
Who changed what in which revision?
User | Revision | Line number | New 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 | |
anevil14 | 1:df77db998389 | 24 | //Media Commands |
anevil14 | 1:df77db998389 | 25 | |
anevil14 | 1:df77db998389 | 26 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 27 | int uLCD_4DGL :: media_init() |
anevil14 | 1:df77db998389 | 28 | { |
anevil14 | 1:df77db998389 | 29 | int resp = 0; |
anevil14 | 1:df77db998389 | 30 | char command[1] = ""; |
anevil14 | 1:df77db998389 | 31 | command[0] = MINIT; |
anevil14 | 1:df77db998389 | 32 | writeCOMMAND(command, 1); |
anevil14 | 1:df77db998389 | 33 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
anevil14 | 1:df77db998389 | 34 | if (_cmd.readable()) { |
anevil14 | 1:df77db998389 | 35 | resp = _cmd.getc(); // read response |
anevil14 | 1:df77db998389 | 36 | resp = resp << 8 + _cmd.getc(); |
anevil14 | 1:df77db998389 | 37 | } |
anevil14 | 1:df77db998389 | 38 | return resp; |
anevil14 | 1:df77db998389 | 39 | } |
anevil14 | 1:df77db998389 | 40 | |
anevil14 | 1:df77db998389 | 41 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 42 | void uLCD_4DGL :: set_byte_address(int hi, int lo) |
anevil14 | 1:df77db998389 | 43 | { |
anevil14 | 1:df77db998389 | 44 | char command[5]= ""; |
anevil14 | 1:df77db998389 | 45 | command[0] = SBADDRESS; |
anevil14 | 1:df77db998389 | 46 | |
anevil14 | 1:df77db998389 | 47 | command[1] = (hi >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 48 | command[2] = hi & 0xFF; |
anevil14 | 1:df77db998389 | 49 | |
anevil14 | 1:df77db998389 | 50 | command[3] = (lo >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 51 | command[4] = lo & 0xFF; |
anevil14 | 1:df77db998389 | 52 | writeCOMMAND(command, 5); |
anevil14 | 1:df77db998389 | 53 | } |
anevil14 | 1:df77db998389 | 54 | |
anevil14 | 1:df77db998389 | 55 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 56 | void uLCD_4DGL :: set_sector_address(int hi, int lo) |
anevil14 | 1:df77db998389 | 57 | { |
anevil14 | 1:df77db998389 | 58 | |
anevil14 | 1:df77db998389 | 59 | char command[5]= ""; |
anevil14 | 1:df77db998389 | 60 | command[0] = SSADDRESS; |
anevil14 | 1:df77db998389 | 61 | |
anevil14 | 1:df77db998389 | 62 | command[1] = (hi >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 63 | command[2] = hi & 0xFF; |
anevil14 | 1:df77db998389 | 64 | |
anevil14 | 1:df77db998389 | 65 | command[3] = (lo >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 66 | command[4] = lo & 0xFF; |
anevil14 | 1:df77db998389 | 67 | writeCOMMAND(command, 5); |
anevil14 | 1:df77db998389 | 68 | } |
anevil14 | 1:df77db998389 | 69 | |
anevil14 | 1:df77db998389 | 70 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 71 | char uLCD_4DGL :: read_byte() |
anevil14 | 1:df77db998389 | 72 | { |
anevil14 | 1:df77db998389 | 73 | char resp = 0; |
anevil14 | 1:df77db998389 | 74 | char command[1] = ""; |
anevil14 | 1:df77db998389 | 75 | command[0] = READBYTE; |
anevil14 | 1:df77db998389 | 76 | writeCOMMAND(command, 1); |
anevil14 | 1:df77db998389 | 77 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
anevil14 | 1:df77db998389 | 78 | if (_cmd.readable()) { |
anevil14 | 1:df77db998389 | 79 | resp = _cmd.getc(); // read response |
anevil14 | 1:df77db998389 | 80 | resp = _cmd.getc(); |
anevil14 | 1:df77db998389 | 81 | } |
anevil14 | 1:df77db998389 | 82 | return resp; |
anevil14 | 1:df77db998389 | 83 | } |
anevil14 | 1:df77db998389 | 84 | |
anevil14 | 1:df77db998389 | 85 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 86 | int uLCD_4DGL :: read_word() |
anevil14 | 1:df77db998389 | 87 | { |
anevil14 | 1:df77db998389 | 88 | int resp=0; |
anevil14 | 1:df77db998389 | 89 | char command[1] = ""; |
anevil14 | 1:df77db998389 | 90 | command[0] = READWORD; |
anevil14 | 1:df77db998389 | 91 | writeCOMMAND(command, 1); |
anevil14 | 1:df77db998389 | 92 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
anevil14 | 1:df77db998389 | 93 | if (_cmd.readable()) { |
anevil14 | 1:df77db998389 | 94 | resp = _cmd.getc(); // read response |
anevil14 | 1:df77db998389 | 95 | resp = resp << 8 + _cmd.getc(); |
anevil14 | 1:df77db998389 | 96 | } |
anevil14 | 1:df77db998389 | 97 | return resp; |
anevil14 | 1:df77db998389 | 98 | } |
anevil14 | 1:df77db998389 | 99 | |
anevil14 | 1:df77db998389 | 100 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 101 | void uLCD_4DGL :: write_byte(int value) |
anevil14 | 1:df77db998389 | 102 | { |
anevil14 | 1:df77db998389 | 103 | char command[3]= ""; |
anevil14 | 1:df77db998389 | 104 | |
anevil14 | 1:df77db998389 | 105 | command[0] = WRITEBYTE; |
anevil14 | 1:df77db998389 | 106 | |
anevil14 | 1:df77db998389 | 107 | command[1] = (value >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 108 | command[2] = value & 0xFF; |
anevil14 | 1:df77db998389 | 109 | writeCOMMAND(command,3); |
anevil14 | 1:df77db998389 | 110 | } |
anevil14 | 1:df77db998389 | 111 | |
anevil14 | 1:df77db998389 | 112 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 113 | void uLCD_4DGL :: write_word(int value) |
anevil14 | 1:df77db998389 | 114 | { |
anevil14 | 1:df77db998389 | 115 | char command[3]= ""; |
anevil14 | 1:df77db998389 | 116 | |
anevil14 | 1:df77db998389 | 117 | command[0] = WRITEWORD; |
anevil14 | 1:df77db998389 | 118 | |
anevil14 | 1:df77db998389 | 119 | command[1] = (value >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 120 | command[2] = value & 0xFF; |
anevil14 | 1:df77db998389 | 121 | writeCOMMAND(command,3); |
anevil14 | 1:df77db998389 | 122 | } |
anevil14 | 1:df77db998389 | 123 | |
anevil14 | 1:df77db998389 | 124 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 125 | void uLCD_4DGL :: flush_media() |
anevil14 | 1:df77db998389 | 126 | { |
anevil14 | 1:df77db998389 | 127 | char command[1] = ""; |
anevil14 | 1:df77db998389 | 128 | command[0] = FLUSHMEDIA; |
anevil14 | 1:df77db998389 | 129 | writeCOMMAND(command, 1); |
anevil14 | 1:df77db998389 | 130 | } |
anevil14 | 1:df77db998389 | 131 | |
anevil14 | 1:df77db998389 | 132 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 133 | void uLCD_4DGL :: display_image(int x, int y) |
anevil14 | 1:df77db998389 | 134 | { |
anevil14 | 1:df77db998389 | 135 | char command[6]= ""; |
anevil14 | 1:df77db998389 | 136 | command[0] = DISPLAYIMAGE; |
anevil14 | 1:df77db998389 | 137 | |
anevil14 | 1:df77db998389 | 138 | command[1] = (x >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 139 | command[2] = x & 0xFF; |
anevil14 | 1:df77db998389 | 140 | |
anevil14 | 1:df77db998389 | 141 | command[3] = (y >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 142 | command[4] = y & 0xFF; |
anevil14 | 1:df77db998389 | 143 | writeCOMMAND(command, 5); |
anevil14 | 1:df77db998389 | 144 | } |
anevil14 | 1:df77db998389 | 145 | |
anevil14 | 1:df77db998389 | 146 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 147 | void uLCD_4DGL :: display_video(int x, int y) |
anevil14 | 1:df77db998389 | 148 | { |
anevil14 | 1:df77db998389 | 149 | char command[5]= ""; |
anevil14 | 1:df77db998389 | 150 | command[0] = DISPLAYVIDEO; |
anevil14 | 1:df77db998389 | 151 | |
anevil14 | 1:df77db998389 | 152 | command[1] = (x >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 153 | command[2] = x & 0xFF; |
anevil14 | 1:df77db998389 | 154 | |
anevil14 | 1:df77db998389 | 155 | command[3] = (y >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 156 | command[4] = y & 0xFF; |
anevil14 | 1:df77db998389 | 157 | writeCOMMAND(command, 5); |
anevil14 | 1:df77db998389 | 158 | } |
anevil14 | 1:df77db998389 | 159 | |
anevil14 | 1:df77db998389 | 160 | //****************************************************************************************************** |
anevil14 | 1:df77db998389 | 161 | void uLCD_4DGL :: display_frame(int x, int y, int w) |
anevil14 | 1:df77db998389 | 162 | { |
anevil14 | 1:df77db998389 | 163 | char command[7]= ""; |
anevil14 | 1:df77db998389 | 164 | |
anevil14 | 1:df77db998389 | 165 | command[0] = DISPLAYFRAME; |
anevil14 | 1:df77db998389 | 166 | |
anevil14 | 1:df77db998389 | 167 | command[1] = (x >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 168 | command[2] = x & 0xFF; |
anevil14 | 1:df77db998389 | 169 | |
anevil14 | 1:df77db998389 | 170 | command[3] = (y >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 171 | command[4] = y & 0xFF; |
anevil14 | 1:df77db998389 | 172 | |
anevil14 | 1:df77db998389 | 173 | command[5] = (w >> 8) & 0xFF; |
anevil14 | 1:df77db998389 | 174 | command[6] = w & 0xFF; |
anevil14 | 1:df77db998389 | 175 | writeCOMMAND(command,7); |
anevil14 | 1:df77db998389 | 176 | } |
anevil14 | 1:df77db998389 | 177 |