C12832 by dreschpe modified to work with the DOGL128-6 LCD Display (ST7565R based)

Dependents:   DOGL128Test

Fork of C12832_lcd by Peter Drescher

Committer:
Sateg
Date:
Sat Jul 16 18:59:43 2016 +0000
Revision:
13:2742c45bc9bc
Parent:
C12832_lcd.cpp@12:a66fded29327
Child:
14:a68c1c6d125a
Renamed class and files to fit library description.

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