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