Dependencies:   mbed

Committer:
Wizo
Date:
Thu Nov 15 17:18:25 2018 +0000
Revision:
0:700173727727
STMSchalter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wizo 0:700173727727 1 /* mbed library for the mbed Lab Board 128*32 pixel LCD
Wizo 0:700173727727 2 * use C12832 controller
Wizo 0:700173727727 3 * Copyright (c) 2012 Peter Drescher - DC2PD
Wizo 0:700173727727 4 * Released under the MIT License: http://mbed.org/license/mit
Wizo 0:700173727727 5 *
Wizo 0:700173727727 6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Wizo 0:700173727727 7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Wizo 0:700173727727 8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Wizo 0:700173727727 9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Wizo 0:700173727727 10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Wizo 0:700173727727 11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Wizo 0:700173727727 12 * THE SOFTWARE.
Wizo 0:700173727727 13 */
Wizo 0:700173727727 14
Wizo 0:700173727727 15 // 13.10.12 initial design
Wizo 0:700173727727 16 // 25.10.12 add autorefresh of screen
Wizo 0:700173727727 17 // 25.10.12 add standart font
Wizo 0:700173727727 18 // 20.12.12 add bitmap graphics
Wizo 0:700173727727 19
Wizo 0:700173727727 20 // optional defines :
Wizo 0:700173727727 21 // #define debug_lcd 1
Wizo 0:700173727727 22
Wizo 0:700173727727 23 #include "C12832.h"
Wizo 0:700173727727 24 #include "mbed.h"
Wizo 0:700173727727 25 #include "stdio.h"
Wizo 0:700173727727 26 #include "Small_7.h"
Wizo 0:700173727727 27
Wizo 0:700173727727 28 #define BPP 1 // Bits per pixel
Wizo 0:700173727727 29
Wizo 0:700173727727 30
Wizo 0:700173727727 31 C12832::C12832(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs, const char* name)
Wizo 0:700173727727 32 : _spi(mosi,NC,sck),_reset(reset),_A0(a0),_CS(ncs),GraphicsDisplay(name)
Wizo 0:700173727727 33 {
Wizo 0:700173727727 34 orientation = 1;
Wizo 0:700173727727 35 draw_mode = NORMAL;
Wizo 0:700173727727 36 char_x = 0;
Wizo 0:700173727727 37 lcd_reset();
Wizo 0:700173727727 38 }
Wizo 0:700173727727 39
Wizo 0:700173727727 40
Wizo 0:700173727727 41 int C12832::width()
Wizo 0:700173727727 42 {
Wizo 0:700173727727 43 if (orientation == 0 || orientation == 2) return 32;
Wizo 0:700173727727 44 else return 128;
Wizo 0:700173727727 45 }
Wizo 0:700173727727 46
Wizo 0:700173727727 47 int C12832::height()
Wizo 0:700173727727 48 {
Wizo 0:700173727727 49 if (orientation == 0 || orientation == 2) return 128;
Wizo 0:700173727727 50 else return 32;
Wizo 0:700173727727 51 }
Wizo 0:700173727727 52
Wizo 0:700173727727 53
Wizo 0:700173727727 54 void C12832::invert(unsigned int o)
Wizo 0:700173727727 55 {
Wizo 0:700173727727 56 if(o == 0) wr_cmd(0xA6);
Wizo 0:700173727727 57 else wr_cmd(0xA7);
Wizo 0:700173727727 58 }
Wizo 0:700173727727 59
Wizo 0:700173727727 60
Wizo 0:700173727727 61 void C12832::set_contrast(unsigned int o)
Wizo 0:700173727727 62 {
Wizo 0:700173727727 63 contrast = o;
Wizo 0:700173727727 64 wr_cmd(0x81); // set volume
Wizo 0:700173727727 65 wr_cmd(o & 0x3F);
Wizo 0:700173727727 66 }
Wizo 0:700173727727 67
Wizo 0:700173727727 68 unsigned int C12832::get_contrast(void)
Wizo 0:700173727727 69 {
Wizo 0:700173727727 70 return(contrast);
Wizo 0:700173727727 71 }
Wizo 0:700173727727 72
Wizo 0:700173727727 73
Wizo 0:700173727727 74 // write command to lcd controller
Wizo 0:700173727727 75
Wizo 0:700173727727 76 void C12832::wr_cmd(unsigned char cmd)
Wizo 0:700173727727 77 {
Wizo 0:700173727727 78 _A0 = 0;
Wizo 0:700173727727 79 _CS = 0;
Wizo 0:700173727727 80 _spi.write(cmd);
Wizo 0:700173727727 81 _CS = 1;
Wizo 0:700173727727 82 }
Wizo 0:700173727727 83
Wizo 0:700173727727 84 // write data to lcd controller
Wizo 0:700173727727 85
Wizo 0:700173727727 86 void C12832::wr_dat(unsigned char dat)
Wizo 0:700173727727 87 {
Wizo 0:700173727727 88 _A0 = 1;
Wizo 0:700173727727 89 _CS = 0;
Wizo 0:700173727727 90 _spi.write(dat);
Wizo 0:700173727727 91 _CS = 1;
Wizo 0:700173727727 92 }
Wizo 0:700173727727 93
Wizo 0:700173727727 94 // reset and init the lcd controller
Wizo 0:700173727727 95
Wizo 0:700173727727 96 void C12832::lcd_reset()
Wizo 0:700173727727 97 {
Wizo 0:700173727727 98
Wizo 0:700173727727 99 _spi.format(8,3); // 8 bit spi mode 3
Wizo 0:700173727727 100 _spi.frequency(20000000); // 19,2 Mhz SPI clock
Wizo 0:700173727727 101 _A0 = 0;
Wizo 0:700173727727 102 _CS = 1;
Wizo 0:700173727727 103 _reset = 0; // display reset
Wizo 0:700173727727 104 wait_us(50);
Wizo 0:700173727727 105 _reset = 1; // end reset
Wizo 0:700173727727 106 wait_ms(5);
Wizo 0:700173727727 107
Wizo 0:700173727727 108 /* Start Initial Sequence ----------------------------------------------------*/
Wizo 0:700173727727 109
Wizo 0:700173727727 110 wr_cmd(0xAE); // display off
Wizo 0:700173727727 111 wr_cmd(0xA2); // bias voltage
Wizo 0:700173727727 112
Wizo 0:700173727727 113 wr_cmd(0xA0);
Wizo 0:700173727727 114 wr_cmd(0xC8); // colum normal
Wizo 0:700173727727 115
Wizo 0:700173727727 116 wr_cmd(0x22); // voltage resistor ratio
Wizo 0:700173727727 117 wr_cmd(0x2F); // power on
Wizo 0:700173727727 118 //wr_cmd(0xA4); // LCD display ram
Wizo 0:700173727727 119 wr_cmd(0x40); // start line = 0
Wizo 0:700173727727 120 wr_cmd(0xAF); // display ON
Wizo 0:700173727727 121
Wizo 0:700173727727 122 wr_cmd(0x81); // set contrast
Wizo 0:700173727727 123 wr_cmd(0x17); // set contrast
Wizo 0:700173727727 124
Wizo 0:700173727727 125 wr_cmd(0xA6); // display normal
Wizo 0:700173727727 126
Wizo 0:700173727727 127
Wizo 0:700173727727 128 // clear and update LCD
Wizo 0:700173727727 129 memset(buffer,0x00,512); // clear display buffer
Wizo 0:700173727727 130 copy_to_lcd();
Wizo 0:700173727727 131 auto_up = 1; // switch on auto update
Wizo 0:700173727727 132 // dont do this by default. Make the user call
Wizo 0:700173727727 133 //claim(stdout); // redirekt printf to lcd
Wizo 0:700173727727 134 locate(0,0);
Wizo 0:700173727727 135 set_font((unsigned char*)Small_7); // standart font
Wizo 0:700173727727 136 }
Wizo 0:700173727727 137
Wizo 0:700173727727 138 // set one pixel in buffer
Wizo 0:700173727727 139
Wizo 0:700173727727 140 void C12832::pixel(int x, int y, int color)
Wizo 0:700173727727 141 {
Wizo 0:700173727727 142 // first check parameter
Wizo 0:700173727727 143 if(x > 128 || y > 32 || x < 0 || y < 0) return;
Wizo 0:700173727727 144
Wizo 0:700173727727 145 if(draw_mode == NORMAL) {
Wizo 0:700173727727 146 if(color == 0)
Wizo 0:700173727727 147 buffer[x + ((y/8) * 128)] &= ~(1 << (y%8)); // erase pixel
Wizo 0:700173727727 148 else
Wizo 0:700173727727 149 buffer[x + ((y/8) * 128)] |= (1 << (y%8)); // set pixel
Wizo 0:700173727727 150 } else { // XOR mode
Wizo 0:700173727727 151 if(color == 1)
Wizo 0:700173727727 152 buffer[x + ((y/8) * 128)] ^= (1 << (y%8)); // xor pixel
Wizo 0:700173727727 153 }
Wizo 0:700173727727 154 }
Wizo 0:700173727727 155
Wizo 0:700173727727 156 // update lcd
Wizo 0:700173727727 157
Wizo 0:700173727727 158 void C12832::copy_to_lcd(void)
Wizo 0:700173727727 159 {
Wizo 0:700173727727 160
Wizo 0:700173727727 161 int i=0;
Wizo 0:700173727727 162
Wizo 0:700173727727 163 //page 0
Wizo 0:700173727727 164 wr_cmd(0x00); // set column low nibble 0
Wizo 0:700173727727 165 wr_cmd(0x10); // set column hi nibble 0
Wizo 0:700173727727 166 wr_cmd(0xB0); // set page address 0
Wizo 0:700173727727 167 _A0 = 1;
Wizo 0:700173727727 168 for(i=0; i<128; i++) {
Wizo 0:700173727727 169 wr_dat(buffer[i]);
Wizo 0:700173727727 170 }
Wizo 0:700173727727 171
Wizo 0:700173727727 172 // page 1
Wizo 0:700173727727 173 wr_cmd(0x00); // set column low nibble 0
Wizo 0:700173727727 174 wr_cmd(0x10); // set column hi nibble 0
Wizo 0:700173727727 175 wr_cmd(0xB1); // set page address 1
Wizo 0:700173727727 176 _A0 = 1;
Wizo 0:700173727727 177 for(i=128; i<256; i++) {
Wizo 0:700173727727 178 wr_dat(buffer[i]);
Wizo 0:700173727727 179 }
Wizo 0:700173727727 180
Wizo 0:700173727727 181 //page 2
Wizo 0:700173727727 182 wr_cmd(0x00); // set column low nibble 0
Wizo 0:700173727727 183 wr_cmd(0x10); // set column hi nibble 0
Wizo 0:700173727727 184 wr_cmd(0xB2); // set page address 2
Wizo 0:700173727727 185 _A0 = 1;
Wizo 0:700173727727 186 for(i=256; i<384; i++) {
Wizo 0:700173727727 187 wr_dat(buffer[i]);
Wizo 0:700173727727 188 }
Wizo 0:700173727727 189
Wizo 0:700173727727 190 //page 3
Wizo 0:700173727727 191 wr_cmd(0x00); // set column low nibble 0
Wizo 0:700173727727 192 wr_cmd(0x10); // set column hi nibble 0
Wizo 0:700173727727 193 wr_cmd(0xB3); // set page address 3
Wizo 0:700173727727 194 _A0 = 1;
Wizo 0:700173727727 195
Wizo 0:700173727727 196 _CS = 0;
Wizo 0:700173727727 197
Wizo 0:700173727727 198 for(i=384; i<512; i++) {
Wizo 0:700173727727 199 wr_dat(buffer[i]);
Wizo 0:700173727727 200 }
Wizo 0:700173727727 201
Wizo 0:700173727727 202 }
Wizo 0:700173727727 203
Wizo 0:700173727727 204 void C12832::cls(void)
Wizo 0:700173727727 205 {
Wizo 0:700173727727 206 memset(buffer,0x00,512); // clear display buffer
Wizo 0:700173727727 207 copy_to_lcd();
Wizo 0:700173727727 208 }
Wizo 0:700173727727 209
Wizo 0:700173727727 210
Wizo 0:700173727727 211 void C12832::line(int x0, int y0, int x1, int y1, int color)
Wizo 0:700173727727 212 {
Wizo 0:700173727727 213 int dx = 0, dy = 0;
Wizo 0:700173727727 214 int dx_sym = 0, dy_sym = 0;
Wizo 0:700173727727 215 int dx_x2 = 0, dy_x2 = 0;
Wizo 0:700173727727 216 int di = 0;
Wizo 0:700173727727 217
Wizo 0:700173727727 218 dx = x1-x0;
Wizo 0:700173727727 219 dy = y1-y0;
Wizo 0:700173727727 220
Wizo 0:700173727727 221 // if (dx == 0) { /* vertical line */
Wizo 0:700173727727 222 // if (y1 > y0) vline(x0,y0,y1,color);
Wizo 0:700173727727 223 // else vline(x0,y1,y0,color);
Wizo 0:700173727727 224 // return;
Wizo 0:700173727727 225 // }
Wizo 0:700173727727 226
Wizo 0:700173727727 227 if (dx > 0) {
Wizo 0:700173727727 228 dx_sym = 1;
Wizo 0:700173727727 229 } else {
Wizo 0:700173727727 230 dx_sym = -1;
Wizo 0:700173727727 231 }
Wizo 0:700173727727 232 // if (dy == 0) { /* horizontal line */
Wizo 0:700173727727 233 // if (x1 > x0) hline(x0,x1,y0,color);
Wizo 0:700173727727 234 // else hline(x1,x0,y0,color);
Wizo 0:700173727727 235 // return;
Wizo 0:700173727727 236 // }
Wizo 0:700173727727 237
Wizo 0:700173727727 238 if (dy > 0) {
Wizo 0:700173727727 239 dy_sym = 1;
Wizo 0:700173727727 240 } else {
Wizo 0:700173727727 241 dy_sym = -1;
Wizo 0:700173727727 242 }
Wizo 0:700173727727 243
Wizo 0:700173727727 244 dx = dx_sym*dx;
Wizo 0:700173727727 245 dy = dy_sym*dy;
Wizo 0:700173727727 246
Wizo 0:700173727727 247 dx_x2 = dx*2;
Wizo 0:700173727727 248 dy_x2 = dy*2;
Wizo 0:700173727727 249
Wizo 0:700173727727 250 if (dx >= dy) {
Wizo 0:700173727727 251 di = dy_x2 - dx;
Wizo 0:700173727727 252 while (x0 != x1) {
Wizo 0:700173727727 253
Wizo 0:700173727727 254 pixel(x0, y0, color);
Wizo 0:700173727727 255 x0 += dx_sym;
Wizo 0:700173727727 256 if (di<0) {
Wizo 0:700173727727 257 di += dy_x2;
Wizo 0:700173727727 258 } else {
Wizo 0:700173727727 259 di += dy_x2 - dx_x2;
Wizo 0:700173727727 260 y0 += dy_sym;
Wizo 0:700173727727 261 }
Wizo 0:700173727727 262 }
Wizo 0:700173727727 263 pixel(x0, y0, color);
Wizo 0:700173727727 264 } else {
Wizo 0:700173727727 265 di = dx_x2 - dy;
Wizo 0:700173727727 266 while (y0 != y1) {
Wizo 0:700173727727 267 pixel(x0, y0, color);
Wizo 0:700173727727 268 y0 += dy_sym;
Wizo 0:700173727727 269 if (di < 0) {
Wizo 0:700173727727 270 di += dx_x2;
Wizo 0:700173727727 271 } else {
Wizo 0:700173727727 272 di += dx_x2 - dy_x2;
Wizo 0:700173727727 273 x0 += dx_sym;
Wizo 0:700173727727 274 }
Wizo 0:700173727727 275 }
Wizo 0:700173727727 276 pixel(x0, y0, color);
Wizo 0:700173727727 277 }
Wizo 0:700173727727 278 if(auto_up) copy_to_lcd();
Wizo 0:700173727727 279 }
Wizo 0:700173727727 280
Wizo 0:700173727727 281 void C12832::rect(int x0, int y0, int x1, int y1, int color)
Wizo 0:700173727727 282 {
Wizo 0:700173727727 283
Wizo 0:700173727727 284 if (x1 > x0) line(x0,y0,x1,y0,color);
Wizo 0:700173727727 285 else line(x1,y0,x0,y0,color);
Wizo 0:700173727727 286
Wizo 0:700173727727 287 if (y1 > y0) line(x0,y0,x0,y1,color);
Wizo 0:700173727727 288 else line(x0,y1,x0,y0,color);
Wizo 0:700173727727 289
Wizo 0:700173727727 290 if (x1 > x0) line(x0,y1,x1,y1,color);
Wizo 0:700173727727 291 else line(x1,y1,x0,y1,color);
Wizo 0:700173727727 292
Wizo 0:700173727727 293 if (y1 > y0) line(x1,y0,x1,y1,color);
Wizo 0:700173727727 294 else line(x1,y1,x1,y0,color);
Wizo 0:700173727727 295
Wizo 0:700173727727 296 if(auto_up) copy_to_lcd();
Wizo 0:700173727727 297 }
Wizo 0:700173727727 298
Wizo 0:700173727727 299 void C12832::fillrect(int x0, int y0, int x1, int y1, int color)
Wizo 0:700173727727 300 {
Wizo 0:700173727727 301 int l,c,i;
Wizo 0:700173727727 302 if(x0 > x1) {
Wizo 0:700173727727 303 i = x0;
Wizo 0:700173727727 304 x0 = x1;
Wizo 0:700173727727 305 x1 = i;
Wizo 0:700173727727 306 }
Wizo 0:700173727727 307
Wizo 0:700173727727 308 if(y0 > y1) {
Wizo 0:700173727727 309 i = y0;
Wizo 0:700173727727 310 y0 = y1;
Wizo 0:700173727727 311 y1 = i;
Wizo 0:700173727727 312 }
Wizo 0:700173727727 313
Wizo 0:700173727727 314 for(l = x0; l<= x1; l ++) {
Wizo 0:700173727727 315 for(c = y0; c<= y1; c++) {
Wizo 0:700173727727 316 pixel(l,c,color);
Wizo 0:700173727727 317 }
Wizo 0:700173727727 318 }
Wizo 0:700173727727 319 if(auto_up) copy_to_lcd();
Wizo 0:700173727727 320 }
Wizo 0:700173727727 321
Wizo 0:700173727727 322
Wizo 0:700173727727 323
Wizo 0:700173727727 324 void C12832::circle(int x0, int y0, int r, int color)
Wizo 0:700173727727 325 {
Wizo 0:700173727727 326
Wizo 0:700173727727 327 int draw_x0, draw_y0;
Wizo 0:700173727727 328 int draw_x1, draw_y1;
Wizo 0:700173727727 329 int draw_x2, draw_y2;
Wizo 0:700173727727 330 int draw_x3, draw_y3;
Wizo 0:700173727727 331 int draw_x4, draw_y4;
Wizo 0:700173727727 332 int draw_x5, draw_y5;
Wizo 0:700173727727 333 int draw_x6, draw_y6;
Wizo 0:700173727727 334 int draw_x7, draw_y7;
Wizo 0:700173727727 335 int xx, yy;
Wizo 0:700173727727 336 int di;
Wizo 0:700173727727 337 //WindowMax();
Wizo 0:700173727727 338 if (r == 0) { /* no radius */
Wizo 0:700173727727 339 return;
Wizo 0:700173727727 340 }
Wizo 0:700173727727 341
Wizo 0:700173727727 342 draw_x0 = draw_x1 = x0;
Wizo 0:700173727727 343 draw_y0 = draw_y1 = y0 + r;
Wizo 0:700173727727 344 if (draw_y0 < height()) {
Wizo 0:700173727727 345 pixel(draw_x0, draw_y0, color); /* 90 degree */
Wizo 0:700173727727 346 }
Wizo 0:700173727727 347
Wizo 0:700173727727 348 draw_x2 = draw_x3 = x0;
Wizo 0:700173727727 349 draw_y2 = draw_y3 = y0 - r;
Wizo 0:700173727727 350 if (draw_y2 >= 0) {
Wizo 0:700173727727 351 pixel(draw_x2, draw_y2, color); /* 270 degree */
Wizo 0:700173727727 352 }
Wizo 0:700173727727 353
Wizo 0:700173727727 354 draw_x4 = draw_x6 = x0 + r;
Wizo 0:700173727727 355 draw_y4 = draw_y6 = y0;
Wizo 0:700173727727 356 if (draw_x4 < width()) {
Wizo 0:700173727727 357 pixel(draw_x4, draw_y4, color); /* 0 degree */
Wizo 0:700173727727 358 }
Wizo 0:700173727727 359
Wizo 0:700173727727 360 draw_x5 = draw_x7 = x0 - r;
Wizo 0:700173727727 361 draw_y5 = draw_y7 = y0;
Wizo 0:700173727727 362 if (draw_x5>=0) {
Wizo 0:700173727727 363 pixel(draw_x5, draw_y5, color); /* 180 degree */
Wizo 0:700173727727 364 }
Wizo 0:700173727727 365
Wizo 0:700173727727 366 if (r == 1) {
Wizo 0:700173727727 367 return;
Wizo 0:700173727727 368 }
Wizo 0:700173727727 369
Wizo 0:700173727727 370 di = 3 - 2*r;
Wizo 0:700173727727 371 xx = 0;
Wizo 0:700173727727 372 yy = r;
Wizo 0:700173727727 373 while (xx < yy) {
Wizo 0:700173727727 374
Wizo 0:700173727727 375 if (di < 0) {
Wizo 0:700173727727 376 di += 4*xx + 6;
Wizo 0:700173727727 377 } else {
Wizo 0:700173727727 378 di += 4*(xx - yy) + 10;
Wizo 0:700173727727 379 yy--;
Wizo 0:700173727727 380 draw_y0--;
Wizo 0:700173727727 381 draw_y1--;
Wizo 0:700173727727 382 draw_y2++;
Wizo 0:700173727727 383 draw_y3++;
Wizo 0:700173727727 384 draw_x4--;
Wizo 0:700173727727 385 draw_x5++;
Wizo 0:700173727727 386 draw_x6--;
Wizo 0:700173727727 387 draw_x7++;
Wizo 0:700173727727 388 }
Wizo 0:700173727727 389 xx++;
Wizo 0:700173727727 390 draw_x0++;
Wizo 0:700173727727 391 draw_x1--;
Wizo 0:700173727727 392 draw_x2++;
Wizo 0:700173727727 393 draw_x3--;
Wizo 0:700173727727 394 draw_y4++;
Wizo 0:700173727727 395 draw_y5++;
Wizo 0:700173727727 396 draw_y6--;
Wizo 0:700173727727 397 draw_y7--;
Wizo 0:700173727727 398
Wizo 0:700173727727 399 if ( (draw_x0 <= width()) && (draw_y0>=0) ) {
Wizo 0:700173727727 400 pixel(draw_x0, draw_y0, color);
Wizo 0:700173727727 401 }
Wizo 0:700173727727 402
Wizo 0:700173727727 403 if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) {
Wizo 0:700173727727 404 pixel(draw_x1, draw_y1, color);
Wizo 0:700173727727 405 }
Wizo 0:700173727727 406
Wizo 0:700173727727 407 if ( (draw_x2 <= width()) && (draw_y2 <= height()) ) {
Wizo 0:700173727727 408 pixel(draw_x2, draw_y2, color);
Wizo 0:700173727727 409 }
Wizo 0:700173727727 410
Wizo 0:700173727727 411 if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) {
Wizo 0:700173727727 412 pixel(draw_x3, draw_y3, color);
Wizo 0:700173727727 413 }
Wizo 0:700173727727 414
Wizo 0:700173727727 415 if ( (draw_x4 <= width()) && (draw_y4 >= 0) ) {
Wizo 0:700173727727 416 pixel(draw_x4, draw_y4, color);
Wizo 0:700173727727 417 }
Wizo 0:700173727727 418
Wizo 0:700173727727 419 if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) {
Wizo 0:700173727727 420 pixel(draw_x5, draw_y5, color);
Wizo 0:700173727727 421 }
Wizo 0:700173727727 422 if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) {
Wizo 0:700173727727 423 pixel(draw_x6, draw_y6, color);
Wizo 0:700173727727 424 }
Wizo 0:700173727727 425 if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) {
Wizo 0:700173727727 426 pixel(draw_x7, draw_y7, color);
Wizo 0:700173727727 427 }
Wizo 0:700173727727 428 }
Wizo 0:700173727727 429 if(auto_up) copy_to_lcd();
Wizo 0:700173727727 430 }
Wizo 0:700173727727 431
Wizo 0:700173727727 432 void C12832::fillcircle(int x, int y, int r, int color)
Wizo 0:700173727727 433 {
Wizo 0:700173727727 434 int i,up;
Wizo 0:700173727727 435 up = auto_up;
Wizo 0:700173727727 436 auto_up = 0; // off
Wizo 0:700173727727 437 for (i = 0; i <= r; i++)
Wizo 0:700173727727 438 circle(x,y,i,color);
Wizo 0:700173727727 439 auto_up = up;
Wizo 0:700173727727 440 if(auto_up) copy_to_lcd();
Wizo 0:700173727727 441 }
Wizo 0:700173727727 442
Wizo 0:700173727727 443 void C12832::setmode(int mode)
Wizo 0:700173727727 444 {
Wizo 0:700173727727 445 draw_mode = mode;
Wizo 0:700173727727 446 }
Wizo 0:700173727727 447
Wizo 0:700173727727 448 void C12832::locate(int x, int y)
Wizo 0:700173727727 449 {
Wizo 0:700173727727 450 char_x = x;
Wizo 0:700173727727 451 char_y = y;
Wizo 0:700173727727 452 }
Wizo 0:700173727727 453
Wizo 0:700173727727 454
Wizo 0:700173727727 455
Wizo 0:700173727727 456 int C12832::columns()
Wizo 0:700173727727 457 {
Wizo 0:700173727727 458 return width() / font[1];
Wizo 0:700173727727 459 }
Wizo 0:700173727727 460
Wizo 0:700173727727 461
Wizo 0:700173727727 462
Wizo 0:700173727727 463 int C12832::rows()
Wizo 0:700173727727 464 {
Wizo 0:700173727727 465 return height() / font[2];
Wizo 0:700173727727 466 }
Wizo 0:700173727727 467
Wizo 0:700173727727 468
Wizo 0:700173727727 469
Wizo 0:700173727727 470 int C12832::_putc(int value)
Wizo 0:700173727727 471 {
Wizo 0:700173727727 472 if (value == '\n') { // new line
Wizo 0:700173727727 473 char_x = 0;
Wizo 0:700173727727 474 char_y = char_y + font[2];
Wizo 0:700173727727 475 if (char_y >= height() - font[2]) {
Wizo 0:700173727727 476 char_y = 0;
Wizo 0:700173727727 477 }
Wizo 0:700173727727 478 } else {
Wizo 0:700173727727 479 character(char_x, char_y, value);
Wizo 0:700173727727 480 if(auto_up) copy_to_lcd();
Wizo 0:700173727727 481 }
Wizo 0:700173727727 482 return value;
Wizo 0:700173727727 483 }
Wizo 0:700173727727 484
Wizo 0:700173727727 485 void C12832::character(int x, int y, int c)
Wizo 0:700173727727 486 {
Wizo 0:700173727727 487 unsigned int hor,vert,offset,bpl,j,i,b;
Wizo 0:700173727727 488 unsigned char* zeichen;
Wizo 0:700173727727 489 unsigned char z,w;
Wizo 0:700173727727 490
Wizo 0:700173727727 491 if ((c < 31) || (c > 127)) return; // test char range
Wizo 0:700173727727 492
Wizo 0:700173727727 493 // read font parameter from start of array
Wizo 0:700173727727 494 offset = font[0]; // bytes / char
Wizo 0:700173727727 495 hor = font[1]; // get hor size of font
Wizo 0:700173727727 496 vert = font[2]; // get vert size of font
Wizo 0:700173727727 497 bpl = font[3]; // bytes per line
Wizo 0:700173727727 498
Wizo 0:700173727727 499 if (char_x + hor > width()) {
Wizo 0:700173727727 500 char_x = 0;
Wizo 0:700173727727 501 char_y = char_y + vert;
Wizo 0:700173727727 502 if (char_y >= height() - font[2]) {
Wizo 0:700173727727 503 char_y = 0;
Wizo 0:700173727727 504 }
Wizo 0:700173727727 505 }
Wizo 0:700173727727 506
Wizo 0:700173727727 507 zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
Wizo 0:700173727727 508 w = zeichen[0]; // width of actual char
Wizo 0:700173727727 509 // construct the char into the buffer
Wizo 0:700173727727 510 for (j=0; j<vert; j++) { // vert line
Wizo 0:700173727727 511 for (i=0; i<hor; i++) { // horz line
Wizo 0:700173727727 512 z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
Wizo 0:700173727727 513 b = 1 << (j & 0x07);
Wizo 0:700173727727 514 if (( z & b ) == 0x00) {
Wizo 0:700173727727 515 pixel(x+i,y+j,0);
Wizo 0:700173727727 516 } else {
Wizo 0:700173727727 517 pixel(x+i,y+j,1);
Wizo 0:700173727727 518 }
Wizo 0:700173727727 519
Wizo 0:700173727727 520 }
Wizo 0:700173727727 521 }
Wizo 0:700173727727 522
Wizo 0:700173727727 523 char_x += w;
Wizo 0:700173727727 524 }
Wizo 0:700173727727 525
Wizo 0:700173727727 526
Wizo 0:700173727727 527 void C12832::set_font(unsigned char* f)
Wizo 0:700173727727 528 {
Wizo 0:700173727727 529 font = f;
Wizo 0:700173727727 530 }
Wizo 0:700173727727 531
Wizo 0:700173727727 532 void C12832::set_auto_up(unsigned int up)
Wizo 0:700173727727 533 {
Wizo 0:700173727727 534 if(up ) auto_up = 1;
Wizo 0:700173727727 535 else auto_up = 0;
Wizo 0:700173727727 536 }
Wizo 0:700173727727 537
Wizo 0:700173727727 538 unsigned int C12832::get_auto_up(void)
Wizo 0:700173727727 539 {
Wizo 0:700173727727 540 return (auto_up);
Wizo 0:700173727727 541 }
Wizo 0:700173727727 542
Wizo 0:700173727727 543 void C12832::print_bm(Bitmap bm, int x, int y)
Wizo 0:700173727727 544 {
Wizo 0:700173727727 545 int h,v,b;
Wizo 0:700173727727 546 char d;
Wizo 0:700173727727 547
Wizo 0:700173727727 548 for(v=0; v < bm.ySize; v++) { // lines
Wizo 0:700173727727 549 for(h=0; h < bm.xSize; h++) { // pixel
Wizo 0:700173727727 550 if(h + x > 127) break;
Wizo 0:700173727727 551 if(v + y > 31) break;
Wizo 0:700173727727 552 d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)];
Wizo 0:700173727727 553 b = 0x80 >> (h & 0x07);
Wizo 0:700173727727 554 if((d & b) == 0) {
Wizo 0:700173727727 555 pixel(x+h,y+v,0);
Wizo 0:700173727727 556 } else {
Wizo 0:700173727727 557 pixel(x+h,y+v,1);
Wizo 0:700173727727 558 }
Wizo 0:700173727727 559 }
Wizo 0:700173727727 560 }
Wizo 0:700173727727 561
Wizo 0:700173727727 562 }
Wizo 0:700173727727 563
Wizo 0:700173727727 564