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