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