C12832 LCD library

Dependents:   app-board-demo

Fork of C12832_lcd by Peter Drescher

Committer:
MACRUM
Date:
Thu Jun 05 04:54:25 2014 +0000
Revision:
9:55d53324e7fa
Parent:
3:468cdccff7af
Constructor changed

Who changed what in which revision?

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