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