Fork of 4DGL-uLCD-SE by
uLCD_4DGL_Graphics.cpp@1:932d76a5b290, 2014-10-21 (annotated)
- Committer:
- hotwheelharry
- Date:
- Tue Oct 21 16:12:49 2014 +0000
- Revision:
- 1:932d76a5b290
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hotwheelharry | 1:932d76a5b290 | 1 | // |
hotwheelharry | 1:932d76a5b290 | 2 | // uLCD_4DGL is a class to drive 4D Systems LCD screens |
hotwheelharry | 1:932d76a5b290 | 3 | // |
hotwheelharry | 1:932d76a5b290 | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
hotwheelharry | 1:932d76a5b290 | 5 | // Modifed for Goldelox processor <2013> Jim Hamblen |
hotwheelharry | 1:932d76a5b290 | 6 | // |
hotwheelharry | 1:932d76a5b290 | 7 | // uLCD_4DGL is free software: you can redistribute it and/or modify |
hotwheelharry | 1:932d76a5b290 | 8 | // it under the terms of the GNU General Public License as published by |
hotwheelharry | 1:932d76a5b290 | 9 | // the Free Software Foundation, either version 3 of the License, or |
hotwheelharry | 1:932d76a5b290 | 10 | // (at your option) any later version. |
hotwheelharry | 1:932d76a5b290 | 11 | // |
hotwheelharry | 1:932d76a5b290 | 12 | // uLCD_4DGL is distributed in the hope that it will be useful, |
hotwheelharry | 1:932d76a5b290 | 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
hotwheelharry | 1:932d76a5b290 | 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
hotwheelharry | 1:932d76a5b290 | 15 | // GNU General Public License for more details. |
hotwheelharry | 1:932d76a5b290 | 16 | // |
hotwheelharry | 1:932d76a5b290 | 17 | // You should have received a copy of the GNU General Public License |
hotwheelharry | 1:932d76a5b290 | 18 | // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. |
hotwheelharry | 1:932d76a5b290 | 19 | |
hotwheelharry | 1:932d76a5b290 | 20 | #include "mbed.h" |
hotwheelharry | 1:932d76a5b290 | 21 | #include "uLCD_4DGL.h" |
hotwheelharry | 1:932d76a5b290 | 22 | |
hotwheelharry | 1:932d76a5b290 | 23 | #define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0]) |
hotwheelharry | 1:932d76a5b290 | 24 | |
hotwheelharry | 1:932d76a5b290 | 25 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 26 | void uLCD_4DGL :: circle(int x, int y , int radius, int color) // draw a circle in (x,y) |
hotwheelharry | 1:932d76a5b290 | 27 | { |
hotwheelharry | 1:932d76a5b290 | 28 | char command[9]= ""; |
hotwheelharry | 1:932d76a5b290 | 29 | |
hotwheelharry | 1:932d76a5b290 | 30 | command[0] = CIRCLE; |
hotwheelharry | 1:932d76a5b290 | 31 | |
hotwheelharry | 1:932d76a5b290 | 32 | command[1] = (x >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 33 | command[2] = x & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 34 | |
hotwheelharry | 1:932d76a5b290 | 35 | command[3] = (y >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 36 | command[4] = y & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 37 | |
hotwheelharry | 1:932d76a5b290 | 38 | command[5] = (radius >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 39 | command[6] = radius & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 40 | |
hotwheelharry | 1:932d76a5b290 | 41 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
hotwheelharry | 1:932d76a5b290 | 42 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
hotwheelharry | 1:932d76a5b290 | 43 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
hotwheelharry | 1:932d76a5b290 | 44 | |
hotwheelharry | 1:932d76a5b290 | 45 | command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 46 | command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 47 | |
hotwheelharry | 1:932d76a5b290 | 48 | writeCOMMAND(command, 9); |
hotwheelharry | 1:932d76a5b290 | 49 | } |
hotwheelharry | 1:932d76a5b290 | 50 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 51 | void uLCD_4DGL :: filled_circle(int x, int y , int radius, int color) // draw a circle in (x,y) |
hotwheelharry | 1:932d76a5b290 | 52 | { |
hotwheelharry | 1:932d76a5b290 | 53 | char command[9]= ""; |
hotwheelharry | 1:932d76a5b290 | 54 | |
hotwheelharry | 1:932d76a5b290 | 55 | command[0] = FCIRCLE; |
hotwheelharry | 1:932d76a5b290 | 56 | |
hotwheelharry | 1:932d76a5b290 | 57 | command[1] = (x >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 58 | command[2] = x & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 59 | |
hotwheelharry | 1:932d76a5b290 | 60 | command[3] = (y >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 61 | command[4] = y & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 62 | |
hotwheelharry | 1:932d76a5b290 | 63 | command[5] = (radius >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 64 | command[6] = radius & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 65 | |
hotwheelharry | 1:932d76a5b290 | 66 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
hotwheelharry | 1:932d76a5b290 | 67 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
hotwheelharry | 1:932d76a5b290 | 68 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
hotwheelharry | 1:932d76a5b290 | 69 | |
hotwheelharry | 1:932d76a5b290 | 70 | command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 71 | command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 72 | |
hotwheelharry | 1:932d76a5b290 | 73 | writeCOMMAND(command, 9); |
hotwheelharry | 1:932d76a5b290 | 74 | } |
hotwheelharry | 1:932d76a5b290 | 75 | |
hotwheelharry | 1:932d76a5b290 | 76 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 77 | void uLCD_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) // draw a traingle |
hotwheelharry | 1:932d76a5b290 | 78 | { |
hotwheelharry | 1:932d76a5b290 | 79 | char command[15]= ""; |
hotwheelharry | 1:932d76a5b290 | 80 | |
hotwheelharry | 1:932d76a5b290 | 81 | command[0] = TRIANGLE; |
hotwheelharry | 1:932d76a5b290 | 82 | |
hotwheelharry | 1:932d76a5b290 | 83 | command[1] = (x1 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 84 | command[2] = x1 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 85 | |
hotwheelharry | 1:932d76a5b290 | 86 | command[3] = (y1 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 87 | command[4] = y1 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 88 | |
hotwheelharry | 1:932d76a5b290 | 89 | command[5] = (x2 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 90 | command[6] = x2 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 91 | |
hotwheelharry | 1:932d76a5b290 | 92 | command[7] = (y2 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 93 | command[8] = y2 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 94 | |
hotwheelharry | 1:932d76a5b290 | 95 | command[9] = (x3 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 96 | command[10] = x3 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 97 | |
hotwheelharry | 1:932d76a5b290 | 98 | command[11] = (y3 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 99 | command[12] = y3 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 100 | |
hotwheelharry | 1:932d76a5b290 | 101 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
hotwheelharry | 1:932d76a5b290 | 102 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
hotwheelharry | 1:932d76a5b290 | 103 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
hotwheelharry | 1:932d76a5b290 | 104 | |
hotwheelharry | 1:932d76a5b290 | 105 | command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 106 | command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 107 | |
hotwheelharry | 1:932d76a5b290 | 108 | writeCOMMAND(command, 15); |
hotwheelharry | 1:932d76a5b290 | 109 | } |
hotwheelharry | 1:932d76a5b290 | 110 | |
hotwheelharry | 1:932d76a5b290 | 111 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 112 | void uLCD_4DGL :: line(int x1, int y1 , int x2, int y2, int color) // draw a line |
hotwheelharry | 1:932d76a5b290 | 113 | { |
hotwheelharry | 1:932d76a5b290 | 114 | char command[11]= ""; |
hotwheelharry | 1:932d76a5b290 | 115 | |
hotwheelharry | 1:932d76a5b290 | 116 | command[0] = LINE; |
hotwheelharry | 1:932d76a5b290 | 117 | |
hotwheelharry | 1:932d76a5b290 | 118 | command[1] = (x1 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 119 | command[2] = x1 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 120 | |
hotwheelharry | 1:932d76a5b290 | 121 | command[3] = (y1 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 122 | command[4] = y1 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 123 | |
hotwheelharry | 1:932d76a5b290 | 124 | command[5] = (x2 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 125 | command[6] = x2 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 126 | |
hotwheelharry | 1:932d76a5b290 | 127 | command[7] = (y2 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 128 | command[8] = y2 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 129 | |
hotwheelharry | 1:932d76a5b290 | 130 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
hotwheelharry | 1:932d76a5b290 | 131 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
hotwheelharry | 1:932d76a5b290 | 132 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
hotwheelharry | 1:932d76a5b290 | 133 | |
hotwheelharry | 1:932d76a5b290 | 134 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 135 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 136 | |
hotwheelharry | 1:932d76a5b290 | 137 | writeCOMMAND(command, 11); |
hotwheelharry | 1:932d76a5b290 | 138 | } |
hotwheelharry | 1:932d76a5b290 | 139 | |
hotwheelharry | 1:932d76a5b290 | 140 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 141 | void uLCD_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle |
hotwheelharry | 1:932d76a5b290 | 142 | { |
hotwheelharry | 1:932d76a5b290 | 143 | char command[11]= ""; |
hotwheelharry | 1:932d76a5b290 | 144 | |
hotwheelharry | 1:932d76a5b290 | 145 | command[0] = RECTANGLE; |
hotwheelharry | 1:932d76a5b290 | 146 | |
hotwheelharry | 1:932d76a5b290 | 147 | command[1] = (x1 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 148 | command[2] = x1 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 149 | |
hotwheelharry | 1:932d76a5b290 | 150 | command[3] = (y1 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 151 | command[4] = y1 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 152 | |
hotwheelharry | 1:932d76a5b290 | 153 | command[5] = (x2 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 154 | command[6] = x2 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 155 | |
hotwheelharry | 1:932d76a5b290 | 156 | command[7] = (y2 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 157 | command[8] = y2 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 158 | |
hotwheelharry | 1:932d76a5b290 | 159 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
hotwheelharry | 1:932d76a5b290 | 160 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
hotwheelharry | 1:932d76a5b290 | 161 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
hotwheelharry | 1:932d76a5b290 | 162 | |
hotwheelharry | 1:932d76a5b290 | 163 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 164 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 165 | |
hotwheelharry | 1:932d76a5b290 | 166 | writeCOMMAND(command, 11); |
hotwheelharry | 1:932d76a5b290 | 167 | } |
hotwheelharry | 1:932d76a5b290 | 168 | |
hotwheelharry | 1:932d76a5b290 | 169 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 170 | void uLCD_4DGL :: filled_rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle |
hotwheelharry | 1:932d76a5b290 | 171 | { |
hotwheelharry | 1:932d76a5b290 | 172 | char command[11]= ""; |
hotwheelharry | 1:932d76a5b290 | 173 | |
hotwheelharry | 1:932d76a5b290 | 174 | command[0] = FRECTANGLE; |
hotwheelharry | 1:932d76a5b290 | 175 | |
hotwheelharry | 1:932d76a5b290 | 176 | command[1] = (x1 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 177 | command[2] = x1 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 178 | |
hotwheelharry | 1:932d76a5b290 | 179 | command[3] = (y1 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 180 | command[4] = y1 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 181 | |
hotwheelharry | 1:932d76a5b290 | 182 | command[5] = (x2 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 183 | command[6] = x2 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 184 | |
hotwheelharry | 1:932d76a5b290 | 185 | command[7] = (y2 >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 186 | command[8] = y2 & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 187 | |
hotwheelharry | 1:932d76a5b290 | 188 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
hotwheelharry | 1:932d76a5b290 | 189 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
hotwheelharry | 1:932d76a5b290 | 190 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
hotwheelharry | 1:932d76a5b290 | 191 | |
hotwheelharry | 1:932d76a5b290 | 192 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 193 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 194 | |
hotwheelharry | 1:932d76a5b290 | 195 | writeCOMMAND(command, 11); |
hotwheelharry | 1:932d76a5b290 | 196 | } |
hotwheelharry | 1:932d76a5b290 | 197 | |
hotwheelharry | 1:932d76a5b290 | 198 | |
hotwheelharry | 1:932d76a5b290 | 199 | |
hotwheelharry | 1:932d76a5b290 | 200 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 201 | void uLCD_4DGL :: pixel(int x, int y, int color) // draw a pixel |
hotwheelharry | 1:932d76a5b290 | 202 | { |
hotwheelharry | 1:932d76a5b290 | 203 | char command[7]= ""; |
hotwheelharry | 1:932d76a5b290 | 204 | |
hotwheelharry | 1:932d76a5b290 | 205 | command[0] = PIXEL; |
hotwheelharry | 1:932d76a5b290 | 206 | |
hotwheelharry | 1:932d76a5b290 | 207 | command[1] = (x >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 208 | command[2] = x & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 209 | |
hotwheelharry | 1:932d76a5b290 | 210 | command[3] = (y >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 211 | command[4] = y & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 212 | |
hotwheelharry | 1:932d76a5b290 | 213 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
hotwheelharry | 1:932d76a5b290 | 214 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
hotwheelharry | 1:932d76a5b290 | 215 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
hotwheelharry | 1:932d76a5b290 | 216 | |
hotwheelharry | 1:932d76a5b290 | 217 | command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 218 | command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 219 | |
hotwheelharry | 1:932d76a5b290 | 220 | writeCOMMAND(command, 7); |
hotwheelharry | 1:932d76a5b290 | 221 | } |
hotwheelharry | 1:932d76a5b290 | 222 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 223 | void uLCD_4DGL :: BLIT(int x, int y, int w, int h, int *colors) // draw a block of pixels |
hotwheelharry | 1:932d76a5b290 | 224 | { |
hotwheelharry | 1:932d76a5b290 | 225 | int red5, green6, blue5; |
hotwheelharry | 1:932d76a5b290 | 226 | writeBYTEfast('\x00'); |
hotwheelharry | 1:932d76a5b290 | 227 | writeBYTEfast(BLITCOM); |
hotwheelharry | 1:932d76a5b290 | 228 | writeBYTEfast((x >> 8) & 0xFF); |
hotwheelharry | 1:932d76a5b290 | 229 | writeBYTEfast(x & 0xFF); |
hotwheelharry | 1:932d76a5b290 | 230 | writeBYTEfast((y >> 8) & 0xFF); |
hotwheelharry | 1:932d76a5b290 | 231 | writeBYTEfast(y & 0xFF); |
hotwheelharry | 1:932d76a5b290 | 232 | writeBYTEfast((w >> 8) & 0xFF); |
hotwheelharry | 1:932d76a5b290 | 233 | writeBYTE(w & 0xFF); |
hotwheelharry | 1:932d76a5b290 | 234 | writeBYTE((h >> 8) & 0xFF); |
hotwheelharry | 1:932d76a5b290 | 235 | writeBYTE(h & 0xFF); |
hotwheelharry | 1:932d76a5b290 | 236 | wait_ms(1); |
hotwheelharry | 1:932d76a5b290 | 237 | for (int i=0; i<w*h; i++) { |
hotwheelharry | 1:932d76a5b290 | 238 | red5 = (colors[i] >> (16 + 3)) & 0x1F; // get red on 5 bits |
hotwheelharry | 1:932d76a5b290 | 239 | green6 = (colors[i] >> (8 + 2)) & 0x3F; // get green on 6 bits |
hotwheelharry | 1:932d76a5b290 | 240 | blue5 = (colors[i] >> (0 + 3)) & 0x1F; // get blue on 5 bits |
hotwheelharry | 1:932d76a5b290 | 241 | writeBYTEfast(((red5 << 3) + (green6 >> 3)) & 0xFF); // first part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 242 | writeBYTEfast(((green6 << 5) + (blue5 >> 0)) & 0xFF); // second part of 16 bits color |
hotwheelharry | 1:932d76a5b290 | 243 | } |
hotwheelharry | 1:932d76a5b290 | 244 | int resp=0; |
hotwheelharry | 1:932d76a5b290 | 245 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
hotwheelharry | 1:932d76a5b290 | 246 | if (_cmd.readable()) resp = _cmd.getc(); // read response if any |
hotwheelharry | 1:932d76a5b290 | 247 | switch (resp) { |
hotwheelharry | 1:932d76a5b290 | 248 | case ACK : // if OK return 1 |
hotwheelharry | 1:932d76a5b290 | 249 | resp = 1; |
hotwheelharry | 1:932d76a5b290 | 250 | break; |
hotwheelharry | 1:932d76a5b290 | 251 | case NAK : // if NOK return -1 |
hotwheelharry | 1:932d76a5b290 | 252 | resp = -1; |
hotwheelharry | 1:932d76a5b290 | 253 | break; |
hotwheelharry | 1:932d76a5b290 | 254 | default : |
hotwheelharry | 1:932d76a5b290 | 255 | resp = 0; // else return 0 |
hotwheelharry | 1:932d76a5b290 | 256 | break; |
hotwheelharry | 1:932d76a5b290 | 257 | } |
hotwheelharry | 1:932d76a5b290 | 258 | #if DEBUGMODE |
hotwheelharry | 1:932d76a5b290 | 259 | pc.printf(" Answer received : %d\n",resp); |
hotwheelharry | 1:932d76a5b290 | 260 | #endif |
hotwheelharry | 1:932d76a5b290 | 261 | |
hotwheelharry | 1:932d76a5b290 | 262 | } |
hotwheelharry | 1:932d76a5b290 | 263 | //****************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 264 | int uLCD_4DGL :: read_pixel(int x, int y) // read screen info and populate data |
hotwheelharry | 1:932d76a5b290 | 265 | { |
hotwheelharry | 1:932d76a5b290 | 266 | |
hotwheelharry | 1:932d76a5b290 | 267 | char command[6]= ""; |
hotwheelharry | 1:932d76a5b290 | 268 | command[0] = 0xFF; |
hotwheelharry | 1:932d76a5b290 | 269 | command[1] = READPIXEL; |
hotwheelharry | 1:932d76a5b290 | 270 | |
hotwheelharry | 1:932d76a5b290 | 271 | command[2] = (x >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 272 | command[3] = x & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 273 | |
hotwheelharry | 1:932d76a5b290 | 274 | command[4] = (y >> 8) & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 275 | command[5] = y & 0xFF; |
hotwheelharry | 1:932d76a5b290 | 276 | |
hotwheelharry | 1:932d76a5b290 | 277 | int i, temp = 0, color = 0, resp = 0; |
hotwheelharry | 1:932d76a5b290 | 278 | char response[2] = ""; |
hotwheelharry | 1:932d76a5b290 | 279 | |
hotwheelharry | 1:932d76a5b290 | 280 | freeBUFFER(); |
hotwheelharry | 1:932d76a5b290 | 281 | |
hotwheelharry | 1:932d76a5b290 | 282 | for (i = 0; i < 6; i++) { // send all chars to serial port |
hotwheelharry | 1:932d76a5b290 | 283 | writeBYTE(command[i]); |
hotwheelharry | 1:932d76a5b290 | 284 | } |
hotwheelharry | 1:932d76a5b290 | 285 | |
hotwheelharry | 1:932d76a5b290 | 286 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
hotwheelharry | 1:932d76a5b290 | 287 | |
hotwheelharry | 1:932d76a5b290 | 288 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
hotwheelharry | 1:932d76a5b290 | 289 | temp = _cmd.getc(); |
hotwheelharry | 1:932d76a5b290 | 290 | response[resp++] = (char)temp; |
hotwheelharry | 1:932d76a5b290 | 291 | } |
hotwheelharry | 1:932d76a5b290 | 292 | |
hotwheelharry | 1:932d76a5b290 | 293 | color = ((response[0] << 8) + response[1]); |
hotwheelharry | 1:932d76a5b290 | 294 | |
hotwheelharry | 1:932d76a5b290 | 295 | return color; // WARNING : this is 16bits color, not 24bits... need to be fixed |
hotwheelharry | 1:932d76a5b290 | 296 | } |
hotwheelharry | 1:932d76a5b290 | 297 | |
hotwheelharry | 1:932d76a5b290 | 298 | |
hotwheelharry | 1:932d76a5b290 | 299 | //**************************************************************************************************** |
hotwheelharry | 1:932d76a5b290 | 300 | void uLCD_4DGL :: pen_size(char mode) // set pen to SOLID or WIREFRAME |
hotwheelharry | 1:932d76a5b290 | 301 | { |
hotwheelharry | 1:932d76a5b290 | 302 | char command[2]= ""; |
hotwheelharry | 1:932d76a5b290 | 303 | |
hotwheelharry | 1:932d76a5b290 | 304 | command[0] = PENSIZE; |
hotwheelharry | 1:932d76a5b290 | 305 | command[1] = mode; |
hotwheelharry | 1:932d76a5b290 | 306 | writeCOMMAND(command, 2); |
hotwheelharry | 1:932d76a5b290 | 307 | } |
hotwheelharry | 1:932d76a5b290 | 308 | |
hotwheelharry | 1:932d76a5b290 | 309 | |
hotwheelharry | 1:932d76a5b290 | 310 |