for alanteam

Dependents:   termometro

Committer:
alanchip
Date:
Wed Oct 28 00:50:10 2020 +0000
Revision:
17:d3785b67760a
Parent:
16:7de323fa46fe
Child:
18:8d7e54330c0b
for alan

Who changed what in which revision?

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