Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.
Dependents: afero_poc15_180216 afero_poc15_180223 afero_poc15_180302 afero_poc15_180403R ... more
Fork of UniGraphic by
UniGraphic for La Suno Version.
To go with La Suno, WatchDog Reset functions were added in ILI9341.
Graphics/GraphicsDisplay.cpp@34:1a148973febe, 2017-12-25 (annotated)
- Committer:
- Rhyme
- Date:
- Mon Dec 25 08:33:03 2017 +0000
- Revision:
- 34:1a148973febe
- Parent:
- 32:9cd6227dc7a6
watch dog resets were added in ILI9341
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 4:12ba0ecc2c1f | 1 | /* mbed UniGraphic library - Graphics class |
Geremia | 4:12ba0ecc2c1f | 2 | * Copyright (c) 2015 Giuliano Dianda |
Geremia | 4:12ba0ecc2c1f | 3 | * Released under the MIT License: http://mbed.org/license/mit |
Geremia | 4:12ba0ecc2c1f | 4 | * |
Geremia | 4:12ba0ecc2c1f | 5 | * Derived work of: |
Geremia | 4:12ba0ecc2c1f | 6 | * |
Geremia | 4:12ba0ecc2c1f | 7 | * mbed GraphicsDisplay Display Library Base Class |
Geremia | 4:12ba0ecc2c1f | 8 | * Copyright (c) 2007-2009 sford |
Geremia | 4:12ba0ecc2c1f | 9 | * Released under the MIT License: http://mbed.org/license/mit |
Geremia | 4:12ba0ecc2c1f | 10 | * |
Geremia | 4:12ba0ecc2c1f | 11 | * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller |
Geremia | 3:48f3282c2be8 | 12 | * Copyright (c) 2013 Peter Drescher - DC2PD |
Geremia | 3:48f3282c2be8 | 13 | * |
Geremia | 3:48f3282c2be8 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Geremia | 3:48f3282c2be8 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Geremia | 3:48f3282c2be8 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Geremia | 3:48f3282c2be8 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Geremia | 3:48f3282c2be8 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Geremia | 3:48f3282c2be8 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Geremia | 3:48f3282c2be8 | 20 | * THE SOFTWARE. |
Geremia | 3:48f3282c2be8 | 21 | */ |
Geremia | 3:48f3282c2be8 | 22 | |
Geremia | 4:12ba0ecc2c1f | 23 | |
Geremia | 0:75ec1b3cde17 | 24 | |
Geremia | 0:75ec1b3cde17 | 25 | #include "GraphicsDisplay.h" |
Geremia | 0:75ec1b3cde17 | 26 | #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; } |
Geremia | 0:75ec1b3cde17 | 27 | GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) { |
Geremia | 8:26757296c79d | 28 | set_font((unsigned char*)Terminal6x8,32,127,true); |
Geremia | 2:713844a55c4e | 29 | // foreground(0xFFFF); |
Geremia | 2:713844a55c4e | 30 | // background(0x0000); |
Geremia | 0:75ec1b3cde17 | 31 | char_x = 0; |
Geremia | 0:75ec1b3cde17 | 32 | char_y = 0; |
Geremia | 0:75ec1b3cde17 | 33 | oriented_width=0; |
Geremia | 0:75ec1b3cde17 | 34 | oriented_height=0; |
Geremia | 22:f9a37f22b9cb | 35 | fontzoomver=1; |
Geremia | 22:f9a37f22b9cb | 36 | fontzoomhor=1; |
Geremia | 0:75ec1b3cde17 | 37 | auto_up = true; |
Geremia | 0:75ec1b3cde17 | 38 | } |
Geremia | 0:75ec1b3cde17 | 39 | |
Geremia | 0:75ec1b3cde17 | 40 | void GraphicsDisplay::WindowMax (void) |
Geremia | 0:75ec1b3cde17 | 41 | { |
Geremia | 0:75ec1b3cde17 | 42 | window (0, 0, oriented_width, oriented_height); |
Geremia | 0:75ec1b3cde17 | 43 | } |
Geremia | 0:75ec1b3cde17 | 44 | void GraphicsDisplay::set_width(int width) |
Geremia | 0:75ec1b3cde17 | 45 | { |
Geremia | 0:75ec1b3cde17 | 46 | oriented_width = width; |
Geremia | 0:75ec1b3cde17 | 47 | } |
Geremia | 0:75ec1b3cde17 | 48 | void GraphicsDisplay::set_height(int height) |
Geremia | 0:75ec1b3cde17 | 49 | { |
Geremia | 0:75ec1b3cde17 | 50 | oriented_height = height; |
Geremia | 0:75ec1b3cde17 | 51 | } |
Geremia | 0:75ec1b3cde17 | 52 | int GraphicsDisplay::width() |
Geremia | 0:75ec1b3cde17 | 53 | { |
Geremia | 0:75ec1b3cde17 | 54 | return oriented_width; |
Geremia | 0:75ec1b3cde17 | 55 | } |
Geremia | 0:75ec1b3cde17 | 56 | int GraphicsDisplay::height() |
Geremia | 0:75ec1b3cde17 | 57 | { |
Geremia | 0:75ec1b3cde17 | 58 | return oriented_height; |
Geremia | 0:75ec1b3cde17 | 59 | } |
Geremia | 0:75ec1b3cde17 | 60 | void GraphicsDisplay::circle(int x0, int y0, int r, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 61 | { |
Geremia | 0:75ec1b3cde17 | 62 | int x = -r, y = 0, err = 2-2*r, e2; |
Geremia | 0:75ec1b3cde17 | 63 | do { |
Geremia | 0:75ec1b3cde17 | 64 | pixel(x0-x, y0+y,color); |
Geremia | 0:75ec1b3cde17 | 65 | pixel(x0+x, y0+y,color); |
Geremia | 0:75ec1b3cde17 | 66 | pixel(x0+x, y0-y,color); |
Geremia | 0:75ec1b3cde17 | 67 | pixel(x0-x, y0-y,color); |
Geremia | 0:75ec1b3cde17 | 68 | e2 = err; |
Geremia | 0:75ec1b3cde17 | 69 | if (e2 <= y) { |
Geremia | 0:75ec1b3cde17 | 70 | err += ++y*2+1; |
Geremia | 0:75ec1b3cde17 | 71 | if (-x == y && e2 <= x) e2 = 0; |
Geremia | 0:75ec1b3cde17 | 72 | } |
Geremia | 0:75ec1b3cde17 | 73 | if (e2 > x) err += ++x*2+1; |
Geremia | 0:75ec1b3cde17 | 74 | } while (x <= 0); |
Geremia | 0:75ec1b3cde17 | 75 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 76 | } |
Geremia | 0:75ec1b3cde17 | 77 | void GraphicsDisplay::fillcircle(int x0, int y0, int r, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 78 | { |
Geremia | 0:75ec1b3cde17 | 79 | bool old_auto_up=auto_up; |
Geremia | 0:75ec1b3cde17 | 80 | if(auto_up) auto_up=false; |
Geremia | 0:75ec1b3cde17 | 81 | int x = -r, y = 0, err = 2-2*r, e2; |
Geremia | 0:75ec1b3cde17 | 82 | do { |
Geremia | 0:75ec1b3cde17 | 83 | vline(x0-x, y0-y, y0+y, color); |
Geremia | 0:75ec1b3cde17 | 84 | vline(x0+x, y0-y, y0+y, color); |
Geremia | 0:75ec1b3cde17 | 85 | e2 = err; |
Geremia | 0:75ec1b3cde17 | 86 | if (e2 <= y) { |
Geremia | 0:75ec1b3cde17 | 87 | err += ++y*2+1; |
Geremia | 0:75ec1b3cde17 | 88 | if (-x == y && e2 <= x) e2 = 0; |
Geremia | 0:75ec1b3cde17 | 89 | } |
Geremia | 0:75ec1b3cde17 | 90 | if (e2 > x) err += ++x*2+1; |
Geremia | 0:75ec1b3cde17 | 91 | } while (x <= 0); |
Geremia | 0:75ec1b3cde17 | 92 | if(old_auto_up) |
Geremia | 0:75ec1b3cde17 | 93 | { |
Geremia | 0:75ec1b3cde17 | 94 | auto_up=true; |
Geremia | 0:75ec1b3cde17 | 95 | copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 96 | } |
Geremia | 0:75ec1b3cde17 | 97 | } |
Geremia | 0:75ec1b3cde17 | 98 | void GraphicsDisplay::hline(int x0, int x1, int y, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 99 | { |
Geremia | 2:713844a55c4e | 100 | int len = x1 - x0 + 1; |
Geremia | 0:75ec1b3cde17 | 101 | window(x0,y,len,1); |
Geremia | 2:713844a55c4e | 102 | // for (int j=0; j<len; j++) window_pushpixel(color); |
Geremia | 2:713844a55c4e | 103 | window_pushpixel(color, len); |
Geremia | 0:75ec1b3cde17 | 104 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 105 | return; |
Geremia | 0:75ec1b3cde17 | 106 | } |
Geremia | 0:75ec1b3cde17 | 107 | void GraphicsDisplay::vline(int x, int y0, int y1, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 108 | { |
Geremia | 2:713844a55c4e | 109 | int len = y1 - y0 + 1; |
Geremia | 0:75ec1b3cde17 | 110 | window(x,y0,1,len); |
Geremia | 2:713844a55c4e | 111 | // for (int y=0; y<len; y++) window_pushpixel(color); |
Geremia | 2:713844a55c4e | 112 | window_pushpixel(color, len); |
Geremia | 0:75ec1b3cde17 | 113 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 114 | return; |
Geremia | 0:75ec1b3cde17 | 115 | } |
Geremia | 0:75ec1b3cde17 | 116 | void GraphicsDisplay::line(int x0, int y0, int x1, int y1, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 117 | { |
Geremia | 0:75ec1b3cde17 | 118 | //WindowMax(); |
Geremia | 0:75ec1b3cde17 | 119 | int dx = 0, dy = 0; |
Geremia | 0:75ec1b3cde17 | 120 | int dx_sym = 0, dy_sym = 0; |
Geremia | 0:75ec1b3cde17 | 121 | int dx_x2 = 0, dy_x2 = 0; |
Geremia | 0:75ec1b3cde17 | 122 | int di = 0; |
Geremia | 0:75ec1b3cde17 | 123 | |
Geremia | 0:75ec1b3cde17 | 124 | dx = x1-x0; |
Geremia | 0:75ec1b3cde17 | 125 | dy = y1-y0; |
Geremia | 0:75ec1b3cde17 | 126 | |
Geremia | 0:75ec1b3cde17 | 127 | if (dx == 0) { /* vertical line */ |
Geremia | 0:75ec1b3cde17 | 128 | if (y1 < y0) SWAP(y0,y1); |
Geremia | 0:75ec1b3cde17 | 129 | vline(x0,y0,y1,color); |
Geremia | 0:75ec1b3cde17 | 130 | return; |
Geremia | 0:75ec1b3cde17 | 131 | } |
Geremia | 0:75ec1b3cde17 | 132 | |
Geremia | 0:75ec1b3cde17 | 133 | if (dx > 0) { |
Geremia | 0:75ec1b3cde17 | 134 | dx_sym = 1; |
Geremia | 0:75ec1b3cde17 | 135 | } else { |
Geremia | 0:75ec1b3cde17 | 136 | dx_sym = -1; |
Geremia | 0:75ec1b3cde17 | 137 | } |
Geremia | 0:75ec1b3cde17 | 138 | if (dy == 0) { /* horizontal line */ |
Geremia | 0:75ec1b3cde17 | 139 | if (x1 < x0) SWAP(x1,x0); |
Geremia | 0:75ec1b3cde17 | 140 | hline(x0,x1,y0,color); |
Geremia | 0:75ec1b3cde17 | 141 | return; |
Geremia | 0:75ec1b3cde17 | 142 | } |
Geremia | 0:75ec1b3cde17 | 143 | |
Geremia | 0:75ec1b3cde17 | 144 | if (dy > 0) { |
Geremia | 0:75ec1b3cde17 | 145 | dy_sym = 1; |
Geremia | 0:75ec1b3cde17 | 146 | } else { |
Geremia | 0:75ec1b3cde17 | 147 | dy_sym = -1; |
Geremia | 0:75ec1b3cde17 | 148 | } |
Geremia | 0:75ec1b3cde17 | 149 | |
Geremia | 0:75ec1b3cde17 | 150 | dx = dx_sym*dx; |
Geremia | 0:75ec1b3cde17 | 151 | dy = dy_sym*dy; |
Geremia | 0:75ec1b3cde17 | 152 | |
Geremia | 0:75ec1b3cde17 | 153 | dx_x2 = dx*2; |
Geremia | 0:75ec1b3cde17 | 154 | dy_x2 = dy*2; |
Geremia | 0:75ec1b3cde17 | 155 | |
Geremia | 0:75ec1b3cde17 | 156 | if (dx >= dy) { |
Geremia | 0:75ec1b3cde17 | 157 | di = dy_x2 - dx; |
Geremia | 0:75ec1b3cde17 | 158 | while (x0 != x1) { |
Geremia | 0:75ec1b3cde17 | 159 | |
Geremia | 0:75ec1b3cde17 | 160 | pixel(x0, y0, color); |
Geremia | 0:75ec1b3cde17 | 161 | x0 += dx_sym; |
Geremia | 0:75ec1b3cde17 | 162 | if (di<0) { |
Geremia | 0:75ec1b3cde17 | 163 | di += dy_x2; |
Geremia | 0:75ec1b3cde17 | 164 | } else { |
Geremia | 0:75ec1b3cde17 | 165 | di += dy_x2 - dx_x2; |
Geremia | 0:75ec1b3cde17 | 166 | y0 += dy_sym; |
Geremia | 0:75ec1b3cde17 | 167 | } |
Geremia | 0:75ec1b3cde17 | 168 | } |
Geremia | 0:75ec1b3cde17 | 169 | pixel(x0, y0, color); |
Geremia | 0:75ec1b3cde17 | 170 | } else { |
Geremia | 0:75ec1b3cde17 | 171 | di = dx_x2 - dy; |
Geremia | 0:75ec1b3cde17 | 172 | while (y0 != y1) { |
Geremia | 0:75ec1b3cde17 | 173 | pixel(x0, y0, color); |
Geremia | 0:75ec1b3cde17 | 174 | y0 += dy_sym; |
Geremia | 0:75ec1b3cde17 | 175 | if (di < 0) { |
Geremia | 0:75ec1b3cde17 | 176 | di += dx_x2; |
Geremia | 0:75ec1b3cde17 | 177 | } else { |
Geremia | 0:75ec1b3cde17 | 178 | di += dx_x2 - dy_x2; |
Geremia | 0:75ec1b3cde17 | 179 | x0 += dx_sym; |
Geremia | 0:75ec1b3cde17 | 180 | } |
Geremia | 0:75ec1b3cde17 | 181 | } |
Geremia | 0:75ec1b3cde17 | 182 | pixel(x0, y0, color); |
Geremia | 0:75ec1b3cde17 | 183 | } |
Geremia | 0:75ec1b3cde17 | 184 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 185 | return; |
Geremia | 0:75ec1b3cde17 | 186 | } |
Geremia | 0:75ec1b3cde17 | 187 | void GraphicsDisplay::rect(int x0, int y0, int x1, int y1, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 188 | { |
Geremia | 0:75ec1b3cde17 | 189 | bool old_auto_up=auto_up; |
Geremia | 0:75ec1b3cde17 | 190 | if(auto_up) auto_up=0; |
Geremia | 0:75ec1b3cde17 | 191 | if (x1 > x0) hline(x0,x1,y0,color); |
Geremia | 0:75ec1b3cde17 | 192 | else hline(x1,x0,y0,color); |
Geremia | 0:75ec1b3cde17 | 193 | |
Geremia | 0:75ec1b3cde17 | 194 | if (y1 > y0) vline(x0,y0,y1,color); |
Geremia | 0:75ec1b3cde17 | 195 | else vline(x0,y1,y0,color); |
Geremia | 0:75ec1b3cde17 | 196 | |
Geremia | 0:75ec1b3cde17 | 197 | if (x1 > x0) hline(x0,x1,y1,color); |
Geremia | 0:75ec1b3cde17 | 198 | else hline(x1,x0,y1,color); |
Geremia | 0:75ec1b3cde17 | 199 | |
Geremia | 0:75ec1b3cde17 | 200 | if (y1 > y0) vline(x1,y0,y1,color); |
Geremia | 0:75ec1b3cde17 | 201 | else vline(x1,y1,y0,color); |
Geremia | 0:75ec1b3cde17 | 202 | if(old_auto_up) |
Geremia | 0:75ec1b3cde17 | 203 | { |
Geremia | 0:75ec1b3cde17 | 204 | auto_up=true; |
Geremia | 0:75ec1b3cde17 | 205 | copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 206 | } |
Geremia | 0:75ec1b3cde17 | 207 | return; |
Geremia | 0:75ec1b3cde17 | 208 | } |
Geremia | 0:75ec1b3cde17 | 209 | void GraphicsDisplay::fillrect(int x0, int y0, int x1, int y1, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 210 | { |
Geremia | 0:75ec1b3cde17 | 211 | if(x0 > x1) SWAP(x0,x1); |
Geremia | 0:75ec1b3cde17 | 212 | if(y0 > y1) SWAP(y0,y1); |
Geremia | 0:75ec1b3cde17 | 213 | |
Geremia | 0:75ec1b3cde17 | 214 | int h = y1 - y0 + 1; |
Geremia | 0:75ec1b3cde17 | 215 | int w = x1 - x0 + 1; |
Geremia | 0:75ec1b3cde17 | 216 | unsigned int pixels = h * w; |
Geremia | 0:75ec1b3cde17 | 217 | window(x0,y0,w,h); |
Geremia | 2:713844a55c4e | 218 | // for (unsigned int p=0; p<pixels; p++) window_pushpixel(color); |
Geremia | 2:713844a55c4e | 219 | window_pushpixel(color, pixels); |
Geremia | 0:75ec1b3cde17 | 220 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 221 | return; |
Geremia | 0:75ec1b3cde17 | 222 | } |
Geremia | 0:75ec1b3cde17 | 223 | void GraphicsDisplay::locate(int x, int y) |
Geremia | 0:75ec1b3cde17 | 224 | { |
Geremia | 0:75ec1b3cde17 | 225 | char_x = x; |
Geremia | 0:75ec1b3cde17 | 226 | char_y = y; |
Geremia | 0:75ec1b3cde17 | 227 | } |
Geremia | 0:75ec1b3cde17 | 228 | int GraphicsDisplay::columns() |
Geremia | 0:75ec1b3cde17 | 229 | { |
Geremia | 0:75ec1b3cde17 | 230 | return oriented_width / fonthor; |
Geremia | 0:75ec1b3cde17 | 231 | } |
Geremia | 0:75ec1b3cde17 | 232 | int GraphicsDisplay::rows() |
Geremia | 0:75ec1b3cde17 | 233 | { |
Geremia | 0:75ec1b3cde17 | 234 | return oriented_height / fontvert; |
Geremia | 0:75ec1b3cde17 | 235 | } |
Geremia | 3:48f3282c2be8 | 236 | void GraphicsDisplay::set_font(unsigned char* f, unsigned char firstascii, unsigned char lastascii, bool proportional) |
Geremia | 0:75ec1b3cde17 | 237 | { |
Geremia | 0:75ec1b3cde17 | 238 | font = f; |
Geremia | 0:75ec1b3cde17 | 239 | // read font parameter from start of array |
Geremia | 0:75ec1b3cde17 | 240 | //fontoffset = font[0]; // bytes / char |
Geremia | 0:75ec1b3cde17 | 241 | fonthor = font[1]; // get hor size of font |
Geremia | 0:75ec1b3cde17 | 242 | fontvert = font[2]; // get vert size of font |
Geremia | 0:75ec1b3cde17 | 243 | //fontbpl = font[3]; // bytes per line |
Geremia | 0:75ec1b3cde17 | 244 | fontbpl = (fontvert+7)>>3; //bytes per line, rounded up to multiple of 8 |
Geremia | 0:75ec1b3cde17 | 245 | fontoffset = (fonthor*fontbpl)+1; |
Geremia | 0:75ec1b3cde17 | 246 | firstch = firstascii; // first ascii code present in font array (usually 32) |
Geremia | 0:75ec1b3cde17 | 247 | lastch = lastascii; // last ascii code present in font array (usually 127) |
Geremia | 3:48f3282c2be8 | 248 | fontprop=proportional; |
Geremia | 22:f9a37f22b9cb | 249 | set_font_zoom(1,1); |
Geremia | 22:f9a37f22b9cb | 250 | } |
Geremia | 22:f9a37f22b9cb | 251 | void GraphicsDisplay::set_font_zoom(unsigned char x_mul, unsigned char y_mul) |
Geremia | 22:f9a37f22b9cb | 252 | { |
Geremia | 22:f9a37f22b9cb | 253 | fontzoomhor=((x_mul==0) ? 1:x_mul); |
Geremia | 22:f9a37f22b9cb | 254 | fontzoomver=((y_mul==0) ? 1:y_mul); |
Geremia | 0:75ec1b3cde17 | 255 | } |
Geremia | 0:75ec1b3cde17 | 256 | int GraphicsDisplay::_putc(int value) |
Geremia | 0:75ec1b3cde17 | 257 | { |
Geremia | 0:75ec1b3cde17 | 258 | if (value == '\n') { // new line |
Geremia | 0:75ec1b3cde17 | 259 | char_x = 0; |
Geremia | 22:f9a37f22b9cb | 260 | char_y = char_y + fontvert*fontzoomver; |
Geremia | 22:f9a37f22b9cb | 261 | if (char_y >= oriented_height - fontvert*fontzoomver) { |
Geremia | 0:75ec1b3cde17 | 262 | char_y = 0; |
Geremia | 0:75ec1b3cde17 | 263 | } |
Geremia | 0:75ec1b3cde17 | 264 | } else { |
Geremia | 0:75ec1b3cde17 | 265 | character(char_x, char_y, value); |
Geremia | 0:75ec1b3cde17 | 266 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 267 | } |
Geremia | 0:75ec1b3cde17 | 268 | return value; |
Geremia | 0:75ec1b3cde17 | 269 | } |
Geremia | 0:75ec1b3cde17 | 270 | void GraphicsDisplay::character(int x, int y, int c) |
Geremia | 0:75ec1b3cde17 | 271 | { |
Geremia | 0:75ec1b3cde17 | 272 | char_x=x; |
Geremia | 0:75ec1b3cde17 | 273 | char_y=y; |
Geremia | 0:75ec1b3cde17 | 274 | int j,i,b; |
Geremia | 0:75ec1b3cde17 | 275 | unsigned char* zeichen; |
Geremia | 22:f9a37f22b9cb | 276 | unsigned char z,w,v; |
Geremia | 0:75ec1b3cde17 | 277 | |
Geremia | 0:75ec1b3cde17 | 278 | /* // read font parameter from start of array |
Geremia | 0:75ec1b3cde17 | 279 | offset = font[0]; // bytes / char |
Geremia | 0:75ec1b3cde17 | 280 | hor = font[1]; // get hor size of font |
Geremia | 0:75ec1b3cde17 | 281 | vert = font[2]; // get vert size of font |
Geremia | 0:75ec1b3cde17 | 282 | bpl = font[3]; // bytes per line |
Geremia | 0:75ec1b3cde17 | 283 | */ |
Geremia | 22:f9a37f22b9cb | 284 | if (char_x + fonthor*fontzoomhor > oriented_width) { |
Geremia | 0:75ec1b3cde17 | 285 | char_x = 0; |
Geremia | 22:f9a37f22b9cb | 286 | char_y = char_y + fontvert*fontzoomver; |
Geremia | 22:f9a37f22b9cb | 287 | if (char_y > oriented_height - fontvert*fontzoomver) { |
Geremia | 0:75ec1b3cde17 | 288 | char_y = 0; |
Geremia | 0:75ec1b3cde17 | 289 | } |
Geremia | 0:75ec1b3cde17 | 290 | } |
Geremia | 22:f9a37f22b9cb | 291 | window(char_x, char_y,fonthor*fontzoomhor,fontvert*fontzoomver); // char box |
dreschpe | 32:9cd6227dc7a6 | 292 | if ((c < firstch) || (c > lastch)) { // test char range - if not exist fill with blank |
dreschpe | 32:9cd6227dc7a6 | 293 | for (i = 0; i < fonthor*fontvert*fontzoomver;i++){ |
dreschpe | 32:9cd6227dc7a6 | 294 | window_pushpixel(_background, fontzoomhor); //(color, howmany) |
dreschpe | 32:9cd6227dc7a6 | 295 | } |
dreschpe | 32:9cd6227dc7a6 | 296 | } |
dreschpe | 32:9cd6227dc7a6 | 297 | else{ |
dreschpe | 32:9cd6227dc7a6 | 298 | zeichen = &font[((c-firstch) * fontoffset) + 4]; // start of char bitmap |
dreschpe | 32:9cd6227dc7a6 | 299 | w = zeichen[0]; // width of actual char |
dreschpe | 32:9cd6227dc7a6 | 300 | // construct the char into the buffer |
dreschpe | 32:9cd6227dc7a6 | 301 | for (j=0; j<fontvert; j++) { // vert line |
dreschpe | 32:9cd6227dc7a6 | 302 | for (v=0; v<fontzoomver; v++) { // repeat horiz line for vertical zooming |
dreschpe | 32:9cd6227dc7a6 | 303 | for (i=0; i<fonthor; i++) { // horz line |
dreschpe | 32:9cd6227dc7a6 | 304 | z = zeichen[(fontbpl * i) + ((j & 0xF8) >> 3)+1]; |
dreschpe | 32:9cd6227dc7a6 | 305 | b = 1 << (j & 0x07); |
dreschpe | 32:9cd6227dc7a6 | 306 | if (( z & b ) == 0x00) { |
dreschpe | 32:9cd6227dc7a6 | 307 | // pixel(char_x+i,char_y+j,0); |
dreschpe | 32:9cd6227dc7a6 | 308 | window_pushpixel(_background, fontzoomhor); //(color, howmany) |
dreschpe | 32:9cd6227dc7a6 | 309 | } else { |
dreschpe | 32:9cd6227dc7a6 | 310 | // pixel(char_x+i,char_y+j,1); |
dreschpe | 32:9cd6227dc7a6 | 311 | window_pushpixel(_foreground, fontzoomhor); |
dreschpe | 32:9cd6227dc7a6 | 312 | } |
dreschpe | 32:9cd6227dc7a6 | 313 | } |
dreschpe | 32:9cd6227dc7a6 | 314 | } //for each zoomed vert |
dreschpe | 32:9cd6227dc7a6 | 315 | } |
Geremia | 0:75ec1b3cde17 | 316 | } |
Geremia | 8:26757296c79d | 317 | if(fontprop) |
Geremia | 8:26757296c79d | 318 | { |
Geremia | 22:f9a37f22b9cb | 319 | if((w+1)<fonthor) char_x += (w*fontzoomhor)+1; // put at least 1 blank after variable-width characters, except characters that occupy whole fonthor space like "_" |
Geremia | 22:f9a37f22b9cb | 320 | else char_x += fonthor*fontzoomhor; |
Geremia | 8:26757296c79d | 321 | } |
Geremia | 22:f9a37f22b9cb | 322 | else char_x += fonthor*fontzoomhor; // fixed width |
Geremia | 0:75ec1b3cde17 | 323 | } |
Geremia | 0:75ec1b3cde17 | 324 | void GraphicsDisplay::Bitmap_BW(Bitmap_s bm, int x, int y) |
Geremia | 0:75ec1b3cde17 | 325 | { |
Geremia | 0:75ec1b3cde17 | 326 | int h,v,b; |
Geremia | 0:75ec1b3cde17 | 327 | // int cropX; |
Geremia | 0:75ec1b3cde17 | 328 | char d; |
Geremia | 0:75ec1b3cde17 | 329 | if(x<0) x=0; |
Geremia | 0:75ec1b3cde17 | 330 | if(y<0) y=0; |
Geremia | 0:75ec1b3cde17 | 331 | int cropX = (x+bm.xSize)-oriented_width; |
Geremia | 0:75ec1b3cde17 | 332 | if(cropX<0) cropX=0; |
Geremia | 0:75ec1b3cde17 | 333 | window(x, y, bm.xSize-cropX, bm.ySize); |
Geremia | 0:75ec1b3cde17 | 334 | for(v=0; v < bm.ySize; v++) { // lines |
Geremia | 0:75ec1b3cde17 | 335 | if((v + y) >= oriented_height) break; // no need to crop Y |
Geremia | 0:75ec1b3cde17 | 336 | for(h=0; h < bm.xSize; h++) { // pixel |
Geremia | 0:75ec1b3cde17 | 337 | if((h + x) >= oriented_width) break; |
Geremia | 0:75ec1b3cde17 | 338 | d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)]; |
Geremia | 0:75ec1b3cde17 | 339 | b = 0x80 >> (h & 0x07); |
Geremia | 0:75ec1b3cde17 | 340 | if((d & b) == 0) { |
Geremia | 0:75ec1b3cde17 | 341 | window_pushpixel(_background); |
Geremia | 0:75ec1b3cde17 | 342 | } else { |
Geremia | 0:75ec1b3cde17 | 343 | window_pushpixel(_foreground); |
Geremia | 0:75ec1b3cde17 | 344 | } |
Geremia | 0:75ec1b3cde17 | 345 | } |
Geremia | 0:75ec1b3cde17 | 346 | } |
Geremia | 0:75ec1b3cde17 | 347 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 348 | } |
Geremia | 0:75ec1b3cde17 | 349 | void GraphicsDisplay::Bitmap(int x, int y, int w, int h,unsigned char *bitmap) |
Geremia | 0:75ec1b3cde17 | 350 | { |
Geremia | 16:244f9563ebc1 | 351 | int j; |
Geremia | 16:244f9563ebc1 | 352 | unsigned char padd; |
Geremia | 0:75ec1b3cde17 | 353 | unsigned short *bitmap_ptr = (unsigned short *)bitmap; |
Geremia | 16:244f9563ebc1 | 354 | |
Geremia | 16:244f9563ebc1 | 355 | padd = w%2; // the lines are padded to multiple of 4 bytes in a bitmap |
Geremia | 0:75ec1b3cde17 | 356 | if(x<0) x=0; |
Geremia | 16:244f9563ebc1 | 357 | else if(x>=oriented_width) return; |
Geremia | 0:75ec1b3cde17 | 358 | if(y<0) y=0; |
Geremia | 16:244f9563ebc1 | 359 | else if(y>=oriented_height) return; |
Geremia | 0:75ec1b3cde17 | 360 | int cropX = (x+w)-oriented_width; |
Geremia | 0:75ec1b3cde17 | 361 | if(cropX<0) cropX=0; |
Geremia | 16:244f9563ebc1 | 362 | int cropY = (y+h)-oriented_height; |
Geremia | 16:244f9563ebc1 | 363 | if(cropY<0) cropY=0; |
Geremia | 16:244f9563ebc1 | 364 | window(x, y, w-cropX, h-cropY); |
Geremia | 16:244f9563ebc1 | 365 | bitmap_ptr += ((h - 1)* (w + padd)); // begin of last line in array (first line of image)(standard bmp scan direction is left->right bottom->top) |
Geremia | 16:244f9563ebc1 | 366 | for (j = 0; j < h-cropY; j++) { //Lines |
Geremia | 16:244f9563ebc1 | 367 | window_pushpixelbuf(bitmap_ptr, w-cropX); |
Geremia | 16:244f9563ebc1 | 368 | bitmap_ptr -= w+padd; |
Geremia | 0:75ec1b3cde17 | 369 | } |
Geremia | 0:75ec1b3cde17 | 370 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 371 | } |
Geremia | 16:244f9563ebc1 | 372 | |
Geremia | 0:75ec1b3cde17 | 373 | // local filesystem is not implemented in kinetis board , but you can add a SD card |
Geremia | 16:244f9563ebc1 | 374 | // fixme this whole functions needs testing and speedup |
Geremia | 0:75ec1b3cde17 | 375 | int GraphicsDisplay::BMP_16(int x, int y, const char *Name_BMP) |
Geremia | 0:75ec1b3cde17 | 376 | { |
Geremia | 0:75ec1b3cde17 | 377 | |
Geremia | 0:75ec1b3cde17 | 378 | #define OffsetPixelWidth 18 |
Geremia | 0:75ec1b3cde17 | 379 | #define OffsetPixelHeigh 22 |
Geremia | 0:75ec1b3cde17 | 380 | #define OffsetFileSize 34 |
Geremia | 0:75ec1b3cde17 | 381 | #define OffsetPixData 10 |
Geremia | 0:75ec1b3cde17 | 382 | #define OffsetBPP 28 |
Geremia | 0:75ec1b3cde17 | 383 | |
Geremia | 0:75ec1b3cde17 | 384 | char filename[50]; |
Geremia | 0:75ec1b3cde17 | 385 | unsigned char BMP_Header[54]; |
Geremia | 0:75ec1b3cde17 | 386 | unsigned short BPP_t; |
Geremia | 0:75ec1b3cde17 | 387 | unsigned int PixelWidth,PixelHeigh,start_data; |
Geremia | 0:75ec1b3cde17 | 388 | unsigned int i,off; |
Geremia | 0:75ec1b3cde17 | 389 | int padd,j; |
Geremia | 0:75ec1b3cde17 | 390 | unsigned short *line; |
Geremia | 0:75ec1b3cde17 | 391 | |
Geremia | 0:75ec1b3cde17 | 392 | // get the filename |
Geremia | 0:75ec1b3cde17 | 393 | i=0; |
Geremia | 0:75ec1b3cde17 | 394 | while (*Name_BMP!='\0') { |
Geremia | 0:75ec1b3cde17 | 395 | filename[i++]=*Name_BMP++; |
Geremia | 0:75ec1b3cde17 | 396 | } |
Geremia | 0:75ec1b3cde17 | 397 | filename[i] = 0; |
Geremia | 0:75ec1b3cde17 | 398 | |
Geremia | 0:75ec1b3cde17 | 399 | FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file |
Geremia | 0:75ec1b3cde17 | 400 | if (!Image) { |
Geremia | 0:75ec1b3cde17 | 401 | return(0); // error file not found ! |
Geremia | 0:75ec1b3cde17 | 402 | } |
Geremia | 0:75ec1b3cde17 | 403 | |
Geremia | 0:75ec1b3cde17 | 404 | fread(&BMP_Header[0],1,54,Image); // get the BMP Header |
Geremia | 0:75ec1b3cde17 | 405 | |
Geremia | 0:75ec1b3cde17 | 406 | if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte |
Geremia | 0:75ec1b3cde17 | 407 | fclose(Image); |
Geremia | 0:75ec1b3cde17 | 408 | return(-1); // error no BMP file |
Geremia | 0:75ec1b3cde17 | 409 | } |
Geremia | 0:75ec1b3cde17 | 410 | |
Geremia | 0:75ec1b3cde17 | 411 | BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8); |
Geremia | 0:75ec1b3cde17 | 412 | if (BPP_t != 0x0010) { |
Geremia | 0:75ec1b3cde17 | 413 | fclose(Image); |
Geremia | 0:75ec1b3cde17 | 414 | return(-2); // error no 16 bit BMP |
Geremia | 0:75ec1b3cde17 | 415 | } |
Geremia | 0:75ec1b3cde17 | 416 | |
Geremia | 0:75ec1b3cde17 | 417 | PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24); |
Geremia | 0:75ec1b3cde17 | 418 | PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24); |
Geremia | 0:75ec1b3cde17 | 419 | if (PixelHeigh > oriented_height + y || PixelWidth > oriented_width + x) { |
Geremia | 0:75ec1b3cde17 | 420 | fclose(Image); |
Geremia | 0:75ec1b3cde17 | 421 | return(-3); // to big |
Geremia | 0:75ec1b3cde17 | 422 | } |
Geremia | 0:75ec1b3cde17 | 423 | |
Geremia | 0:75ec1b3cde17 | 424 | start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24); |
Geremia | 0:75ec1b3cde17 | 425 | |
Geremia | 0:75ec1b3cde17 | 426 | line = (unsigned short *) malloc (2 * PixelWidth); // we need a buffer for a line |
Geremia | 0:75ec1b3cde17 | 427 | if (line == NULL) { |
Geremia | 0:75ec1b3cde17 | 428 | return(-4); // error no memory |
Geremia | 0:75ec1b3cde17 | 429 | } |
Geremia | 0:75ec1b3cde17 | 430 | |
Geremia | 0:75ec1b3cde17 | 431 | // the bmp lines are padded to multiple of 4 bytes |
Geremia | 0:75ec1b3cde17 | 432 | padd = -1; |
Geremia | 0:75ec1b3cde17 | 433 | do { |
Geremia | 0:75ec1b3cde17 | 434 | padd ++; |
Geremia | 0:75ec1b3cde17 | 435 | } while ((PixelWidth * 2 + padd)%4 != 0); |
Geremia | 0:75ec1b3cde17 | 436 | |
Geremia | 0:75ec1b3cde17 | 437 | window(x, y,PixelWidth ,PixelHeigh); |
Geremia | 0:75ec1b3cde17 | 438 | // wr_cmd(0x2C); // send pixel |
Geremia | 0:75ec1b3cde17 | 439 | for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up |
Geremia | 0:75ec1b3cde17 | 440 | off = j * (PixelWidth * 2 + padd) + start_data; // start of line |
Geremia | 0:75ec1b3cde17 | 441 | fseek(Image, off ,SEEK_SET); |
Geremia | 0:75ec1b3cde17 | 442 | fread(line,1,PixelWidth * 2,Image); // read a line - slow |
Geremia | 2:713844a55c4e | 443 | /* for (i = 0; i < PixelWidth; i++) |
Geremia | 2:713844a55c4e | 444 | { // copy pixel data to TFT |
Geremia | 0:75ec1b3cde17 | 445 | // wr_16(line[i]); // one 16 bit pixel |
Geremia | 0:75ec1b3cde17 | 446 | window_pushpixel(line[i]); |
Geremia | 2:713844a55c4e | 447 | |
Geremia | 2:713844a55c4e | 448 | } */ |
Geremia | 2:713844a55c4e | 449 | window_pushpixelbuf(line, PixelWidth); |
Geremia | 0:75ec1b3cde17 | 450 | } |
Geremia | 0:75ec1b3cde17 | 451 | free (line); |
Geremia | 0:75ec1b3cde17 | 452 | fclose(Image); |
Geremia | 0:75ec1b3cde17 | 453 | if(auto_up) copy_to_lcd(); |
Geremia | 0:75ec1b3cde17 | 454 | return(1); |
Geremia | 0:75ec1b3cde17 | 455 | } |
Geremia | 0:75ec1b3cde17 | 456 | |
Geremia | 0:75ec1b3cde17 | 457 | void GraphicsDisplay::cls (void) |
Geremia | 0:75ec1b3cde17 | 458 | { |
Geremia | 0:75ec1b3cde17 | 459 | unsigned int pixels = ( oriented_width * oriented_height); |
Geremia | 0:75ec1b3cde17 | 460 | WindowMax(); |
Geremia | 0:75ec1b3cde17 | 461 | for (unsigned int i = 0; i < pixels; i++) |
Geremia | 0:75ec1b3cde17 | 462 | { |
Geremia | 0:75ec1b3cde17 | 463 | window_pushpixel(_background); |
Geremia | 0:75ec1b3cde17 | 464 | } |
Geremia | 0:75ec1b3cde17 | 465 | } |
Geremia | 2:713844a55c4e | 466 | void GraphicsDisplay::set_auto_up(bool up) |
Geremia | 2:713844a55c4e | 467 | { |
Geremia | 2:713844a55c4e | 468 | if(up) auto_up = true; |
Geremia | 2:713844a55c4e | 469 | else auto_up = false; |
Geremia | 2:713844a55c4e | 470 | } |
Geremia | 2:713844a55c4e | 471 | bool GraphicsDisplay::get_auto_up(void) |
Geremia | 2:713844a55c4e | 472 | { |
Geremia | 2:713844a55c4e | 473 | return (auto_up); |
Geremia | 2:713844a55c4e | 474 | } |
Geremia | 0:75ec1b3cde17 | 475 | |
Geremia | 0:75ec1b3cde17 | 476 |