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