mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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