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