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