The final project of Embedde class.

Dependents:   project_ver3_F

Committer:
pkr7098
Date:
Thu Jun 03 07:05:21 2021 +0000
Revision:
19:e0ff672950db
Parent:
18:03069e3deaa4
The final project of Embedded class.

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