EPD display library.
Dependents: acd52832_ePaper acd52832_SAADC_Differential_input_2 acd52832_SAADC_Differential_input_EPD acd52832_Car_battery_ch ... more
Fork of GDEP015OC1 by
GDEP015OC1.cpp@10:eeb4adb54689, 2017-03-13 (annotated)
- Committer:
- jurica238814
- Date:
- Mon Mar 13 10:27:16 2017 +0000
- Revision:
- 10:eeb4adb54689
- Parent:
- 9:9c1a15bd5ef1
- Child:
- 11:9cf09f5a693a
EPD works with sleep.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anunnaki | 3:dc7b794b59b7 | 1 | /** |
Anunnaki | 3:dc7b794b59b7 | 2 | * Created by Filip Hormot (f.hormot@gmail.com) on 14/09/16. |
jurica238814 | 9:9c1a15bd5ef1 | 3 | * Edited by Jurica Resetar on 10/3/17. |
Anunnaki | 3:dc7b794b59b7 | 4 | */ |
Anunnaki | 1:4fff95e316c9 | 5 | #include "mbed.h" |
Anunnaki | 1:4fff95e316c9 | 6 | #include "GDEP015OC1.h" |
Anunnaki | 3:dc7b794b59b7 | 7 | #include "5x7.h" |
Anunnaki | 1:4fff95e316c9 | 8 | |
jurica238814 | 8:5ae728fa8820 | 9 | #define EPD_WAIT_CONSTANT 100 |
jurica238814 | 8:5ae728fa8820 | 10 | |
Anunnaki | 2:1c8f73aa2a16 | 11 | static const unsigned char _lutFull[] = { |
Anunnaki | 2:1c8f73aa2a16 | 12 | 0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, |
Anunnaki | 2:1c8f73aa2a16 | 13 | 0x88, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51, 0x35, 0x51, 0x51, 0x19, 0x01, 0x00 |
Anunnaki | 2:1c8f73aa2a16 | 14 | }; |
Anunnaki | 2:1c8f73aa2a16 | 15 | |
Anunnaki | 7:70c58d3cbc8b | 16 | static const unsigned char _lutPart[] = { |
Anunnaki | 7:70c58d3cbc8b | 17 | 0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Anunnaki | 7:70c58d3cbc8b | 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
Anunnaki | 7:70c58d3cbc8b | 19 | }; |
Anunnaki | 7:70c58d3cbc8b | 20 | |
Anunnaki | 2:1c8f73aa2a16 | 21 | GDEP015OC1::GDEP015OC1(SPI& spi, PinName cs=p5, PinName dc=p6, PinName rst=p7, PinName busy=p8) : _spi(spi), _cs(cs), _dc(dc), _rst(rst), _busy(busy){ |
Anunnaki | 6:45d2ec037fd6 | 22 | _bold = true; |
Anunnaki | 6:45d2ec037fd6 | 23 | _italic = false; |
Anunnaki | 1:4fff95e316c9 | 24 | _init(); |
Anunnaki | 1:4fff95e316c9 | 25 | } |
Anunnaki | 1:4fff95e316c9 | 26 | |
Anunnaki | 2:1c8f73aa2a16 | 27 | void GDEP015OC1::_spiCommand(unsigned char command){ |
Anunnaki | 2:1c8f73aa2a16 | 28 | _cs = _dc = 0; |
Anunnaki | 2:1c8f73aa2a16 | 29 | wait_us(1); |
Anunnaki | 2:1c8f73aa2a16 | 30 | _spi.write(command); |
Anunnaki | 2:1c8f73aa2a16 | 31 | } |
Anunnaki | 2:1c8f73aa2a16 | 32 | |
Anunnaki | 2:1c8f73aa2a16 | 33 | void GDEP015OC1::_spiData(unsigned char data){ |
Anunnaki | 2:1c8f73aa2a16 | 34 | _cs = 0; |
Anunnaki | 2:1c8f73aa2a16 | 35 | _dc = 1; |
Anunnaki | 2:1c8f73aa2a16 | 36 | wait_us(1); |
Anunnaki | 2:1c8f73aa2a16 | 37 | _spi.write(data); |
Anunnaki | 2:1c8f73aa2a16 | 38 | } |
Anunnaki | 2:1c8f73aa2a16 | 39 | |
Anunnaki | 2:1c8f73aa2a16 | 40 | void GDEP015OC1::_init(void){ |
Anunnaki | 2:1c8f73aa2a16 | 41 | _rst = _cs = 1; |
Anunnaki | 3:dc7b794b59b7 | 42 | empty(); |
Anunnaki | 1:4fff95e316c9 | 43 | } |
Anunnaki | 1:4fff95e316c9 | 44 | |
Anunnaki | 7:70c58d3cbc8b | 45 | void GDEP015OC1::_wakeUp(bool partial){ |
Anunnaki | 2:1c8f73aa2a16 | 46 | _rst = 0; |
jurica238814 | 8:5ae728fa8820 | 47 | wait_ms(EPD_WAIT_CONSTANT); |
Anunnaki | 2:1c8f73aa2a16 | 48 | _rst = 1; |
jurica238814 | 8:5ae728fa8820 | 49 | wait_ms(EPD_WAIT_CONSTANT); |
Anunnaki | 1:4fff95e316c9 | 50 | |
Anunnaki | 2:1c8f73aa2a16 | 51 | //Stage 3 |
Anunnaki | 2:1c8f73aa2a16 | 52 | //Driver Output control |
Anunnaki | 2:1c8f73aa2a16 | 53 | _spiCommand(0x01); |
jurica238814 | 9:9c1a15bd5ef1 | 54 | _spiData(0xC7); // (yDot-1)%256 |
jurica238814 | 9:9c1a15bd5ef1 | 55 | _spiData(0x00); // (yDot-1)/256 |
jurica238814 | 9:9c1a15bd5ef1 | 56 | _spiData(0x00); // 0x00 |
jurica238814 | 9:9c1a15bd5ef1 | 57 | |
Anunnaki | 2:1c8f73aa2a16 | 58 | //Softstart |
Anunnaki | 2:1c8f73aa2a16 | 59 | _spiCommand(0x0C); |
Anunnaki | 2:1c8f73aa2a16 | 60 | _spiData(0xD7); |
Anunnaki | 2:1c8f73aa2a16 | 61 | _spiData(0xD6); |
Anunnaki | 2:1c8f73aa2a16 | 62 | _spiData(0x9D); |
Anunnaki | 2:1c8f73aa2a16 | 63 | |
Anunnaki | 2:1c8f73aa2a16 | 64 | //VCOM setting |
Anunnaki | 2:1c8f73aa2a16 | 65 | _spiCommand(0x2C); |
Anunnaki | 2:1c8f73aa2a16 | 66 | _spiData(0xA8); |
jurica238814 | 9:9c1a15bd5ef1 | 67 | |
Anunnaki | 2:1c8f73aa2a16 | 68 | //Dummy line period |
Anunnaki | 2:1c8f73aa2a16 | 69 | _spiCommand(0x3A); |
Anunnaki | 2:1c8f73aa2a16 | 70 | _spiData(0x1A); |
jurica238814 | 9:9c1a15bd5ef1 | 71 | |
jurica238814 | 9:9c1a15bd5ef1 | 72 | //Gate line width // 2us per line |
Anunnaki | 2:1c8f73aa2a16 | 73 | _spiCommand(0x3B); |
Anunnaki | 2:1c8f73aa2a16 | 74 | _spiData(0x08); |
jurica238814 | 9:9c1a15bd5ef1 | 75 | |
Anunnaki | 2:1c8f73aa2a16 | 76 | //Set data entry mode |
Anunnaki | 2:1c8f73aa2a16 | 77 | _spiCommand(0x11); |
Anunnaki | 2:1c8f73aa2a16 | 78 | _spiData(0x01); //DO NOT TOUCH THIS! (MUST BE 0x01) |
Anunnaki | 2:1c8f73aa2a16 | 79 | |
Anunnaki | 2:1c8f73aa2a16 | 80 | //Define X display size |
Anunnaki | 2:1c8f73aa2a16 | 81 | _spiCommand(0x44); |
Anunnaki | 2:1c8f73aa2a16 | 82 | _spiData(0x00); |
jurica238814 | 9:9c1a15bd5ef1 | 83 | _spiData(0x18); //(xDot-1)/8 |
Anunnaki | 2:1c8f73aa2a16 | 84 | //Define Y display size |
Anunnaki | 2:1c8f73aa2a16 | 85 | _spiCommand(0x45); |
jurica238814 | 9:9c1a15bd5ef1 | 86 | _spiData(0xC7); //(yDot-1)%256 |
jurica238814 | 9:9c1a15bd5ef1 | 87 | _spiData(0x00); //(yDot-1)/256 |
jurica238814 | 9:9c1a15bd5ef1 | 88 | _spiData(0x00); // Was 0x2B |
jurica238814 | 9:9c1a15bd5ef1 | 89 | _spiData(0x00); // Was 0x01 |
Anunnaki | 2:1c8f73aa2a16 | 90 | |
Anunnaki | 2:1c8f73aa2a16 | 91 | //Define X RAM address |
Anunnaki | 2:1c8f73aa2a16 | 92 | _spiCommand(0x4E); |
Anunnaki | 2:1c8f73aa2a16 | 93 | _spiData(0x00); |
Anunnaki | 2:1c8f73aa2a16 | 94 | //Define Y RAM address |
Anunnaki | 2:1c8f73aa2a16 | 95 | _spiCommand(0x4F); |
Anunnaki | 2:1c8f73aa2a16 | 96 | _spiData(0xC7); |
Anunnaki | 2:1c8f73aa2a16 | 97 | _spiData(0x00); |
Anunnaki | 2:1c8f73aa2a16 | 98 | |
Anunnaki | 2:1c8f73aa2a16 | 99 | //Write LUT |
Anunnaki | 2:1c8f73aa2a16 | 100 | _spiCommand(0x32); |
Anunnaki | 7:70c58d3cbc8b | 101 | if(partial){ |
Anunnaki | 7:70c58d3cbc8b | 102 | for(uint8_t i = 0; i<30;i++){ |
Anunnaki | 7:70c58d3cbc8b | 103 | _spiData(_lutPart[i]); |
Anunnaki | 7:70c58d3cbc8b | 104 | } |
Anunnaki | 7:70c58d3cbc8b | 105 | } else{ |
Anunnaki | 7:70c58d3cbc8b | 106 | for(uint8_t i = 0; i<30;i++){ |
Anunnaki | 7:70c58d3cbc8b | 107 | _spiData(_lutFull[i]); |
Anunnaki | 7:70c58d3cbc8b | 108 | } |
Anunnaki | 7:70c58d3cbc8b | 109 | } |
Anunnaki | 1:4fff95e316c9 | 110 | } |
Anunnaki | 1:4fff95e316c9 | 111 | |
Anunnaki | 2:1c8f73aa2a16 | 112 | void GDEP015OC1::_sleep(void){ |
Anunnaki | 2:1c8f73aa2a16 | 113 | while(_busy == BUSY_STATE); |
Anunnaki | 2:1c8f73aa2a16 | 114 | |
Anunnaki | 2:1c8f73aa2a16 | 115 | _spiCommand(0x10); |
Anunnaki | 2:1c8f73aa2a16 | 116 | _spiData(0x01); |
Anunnaki | 2:1c8f73aa2a16 | 117 | } |
Anunnaki | 2:1c8f73aa2a16 | 118 | |
Anunnaki | 6:45d2ec037fd6 | 119 | /* |
Anunnaki | 6:45d2ec037fd6 | 120 | * If you touch this function satan will feast on your soul for an eternity! |
Anunnaki | 6:45d2ec037fd6 | 121 | * IM NOT PLAYING AROUND DONT FUCKING TOUCH IT! |
Anunnaki | 6:45d2ec037fd6 | 122 | * You are thinking about it... |
Anunnaki | 6:45d2ec037fd6 | 123 | * . |
Anunnaki | 6:45d2ec037fd6 | 124 | * . |
Anunnaki | 6:45d2ec037fd6 | 125 | * . |
Anunnaki | 6:45d2ec037fd6 | 126 | * DONT! |
Anunnaki | 6:45d2ec037fd6 | 127 | */ |
Anunnaki | 2:1c8f73aa2a16 | 128 | unsigned char GDEP015OC1::_pixelConv(unsigned char *data, int i){ |
Anunnaki | 2:1c8f73aa2a16 | 129 | uint8_t pix = 0x00; |
Anunnaki | 2:1c8f73aa2a16 | 130 | for(uint8_t x = 0; x < 8; x++){ |
Anunnaki | 2:1c8f73aa2a16 | 131 | pix |= ((*(data + (i*200)%5000 + (24-i/200) + x*25)>>((i/25)%8))&(0x01))<<(7-x); |
Anunnaki | 2:1c8f73aa2a16 | 132 | } |
Anunnaki | 3:dc7b794b59b7 | 133 | return pix^0xFF; |
Anunnaki | 2:1c8f73aa2a16 | 134 | } |
Anunnaki | 2:1c8f73aa2a16 | 135 | |
Anunnaki | 2:1c8f73aa2a16 | 136 | uint8_t GDEP015OC1::_mirrorData(uint8_t data){ |
Anunnaki | 2:1c8f73aa2a16 | 137 | uint8_t mirror = 0x00; |
Anunnaki | 2:1c8f73aa2a16 | 138 | for(uint8_t i=0; i<8; i++) |
Anunnaki | 2:1c8f73aa2a16 | 139 | mirror |= ((data>>i) & 0x01) << (7 - i); |
Anunnaki | 2:1c8f73aa2a16 | 140 | |
Anunnaki | 2:1c8f73aa2a16 | 141 | return mirror; |
Anunnaki | 2:1c8f73aa2a16 | 142 | } |
Anunnaki | 2:1c8f73aa2a16 | 143 | |
Anunnaki | 4:86114342ce8f | 144 | void GDEP015OC1::fill(unsigned char data, int x){ |
Anunnaki | 4:86114342ce8f | 145 | _buffer[x] = data; |
Anunnaki | 4:86114342ce8f | 146 | } |
Anunnaki | 4:86114342ce8f | 147 | |
Anunnaki | 2:1c8f73aa2a16 | 148 | void GDEP015OC1::empty(void){ |
Anunnaki | 2:1c8f73aa2a16 | 149 | for(uint16_t x=0; x<5000; x++) |
Anunnaki | 2:1c8f73aa2a16 | 150 | _buffer[x] = 0x00; |
Anunnaki | 2:1c8f73aa2a16 | 151 | } |
Anunnaki | 2:1c8f73aa2a16 | 152 | |
Anunnaki | 2:1c8f73aa2a16 | 153 | void GDEP015OC1::write(void){ |
Anunnaki | 7:70c58d3cbc8b | 154 | _wakeUp(true); |
Anunnaki | 7:70c58d3cbc8b | 155 | |
Anunnaki | 7:70c58d3cbc8b | 156 | _spiCommand(0x24); |
Anunnaki | 7:70c58d3cbc8b | 157 | for(int16_t x=0; x>=0 && x<200; x++){ |
Anunnaki | 7:70c58d3cbc8b | 158 | for(int16_t y=24; y>=0 && y<25; y--){ |
Anunnaki | 7:70c58d3cbc8b | 159 | _spiData(_mirrorData(_pixelConv(_buffer, x*25+y))); |
jurica238814 | 8:5ae728fa8820 | 160 | wait_us(EPD_WAIT_CONSTANT); |
Anunnaki | 7:70c58d3cbc8b | 161 | } |
Anunnaki | 7:70c58d3cbc8b | 162 | } |
Anunnaki | 7:70c58d3cbc8b | 163 | |
Anunnaki | 7:70c58d3cbc8b | 164 | _spiCommand(0x22); |
Anunnaki | 7:70c58d3cbc8b | 165 | _spiData(0x04); |
Anunnaki | 7:70c58d3cbc8b | 166 | _spiCommand(0x22); |
Anunnaki | 7:70c58d3cbc8b | 167 | _spiData(0x08); |
Anunnaki | 7:70c58d3cbc8b | 168 | |
Anunnaki | 7:70c58d3cbc8b | 169 | //Update |
Anunnaki | 7:70c58d3cbc8b | 170 | _spiCommand(0x22); |
Anunnaki | 7:70c58d3cbc8b | 171 | _spiData(0xC7); |
Anunnaki | 7:70c58d3cbc8b | 172 | _spiCommand(0x20); |
Anunnaki | 7:70c58d3cbc8b | 173 | |
Anunnaki | 7:70c58d3cbc8b | 174 | _sleep(); |
Anunnaki | 7:70c58d3cbc8b | 175 | } |
Anunnaki | 7:70c58d3cbc8b | 176 | |
Anunnaki | 7:70c58d3cbc8b | 177 | void GDEP015OC1::writeFull(void){ |
Anunnaki | 7:70c58d3cbc8b | 178 | _wakeUp(false); |
Anunnaki | 2:1c8f73aa2a16 | 179 | |
Anunnaki | 2:1c8f73aa2a16 | 180 | _spiCommand(0x24); |
Anunnaki | 2:1c8f73aa2a16 | 181 | for(int16_t x=0; x>=0 && x<200; x++){ |
Anunnaki | 2:1c8f73aa2a16 | 182 | for(int16_t y=24; y>=0 && y<25; y--){ |
Anunnaki | 2:1c8f73aa2a16 | 183 | _spiData(_mirrorData(_pixelConv(_buffer, x*25+y))); |
jurica238814 | 8:5ae728fa8820 | 184 | wait_us(EPD_WAIT_CONSTANT); |
Anunnaki | 2:1c8f73aa2a16 | 185 | } |
Anunnaki | 2:1c8f73aa2a16 | 186 | } |
Anunnaki | 2:1c8f73aa2a16 | 187 | |
Anunnaki | 2:1c8f73aa2a16 | 188 | _spiCommand(0x22); |
Anunnaki | 2:1c8f73aa2a16 | 189 | _spiData(0x04); |
Anunnaki | 2:1c8f73aa2a16 | 190 | _spiCommand(0x22); |
Anunnaki | 2:1c8f73aa2a16 | 191 | _spiData(0x08); |
Anunnaki | 2:1c8f73aa2a16 | 192 | |
Anunnaki | 2:1c8f73aa2a16 | 193 | //Update |
Anunnaki | 2:1c8f73aa2a16 | 194 | _spiCommand(0x22); |
Anunnaki | 2:1c8f73aa2a16 | 195 | _spiData(0xC7); |
Anunnaki | 2:1c8f73aa2a16 | 196 | _spiCommand(0x20); |
Anunnaki | 2:1c8f73aa2a16 | 197 | |
Anunnaki | 2:1c8f73aa2a16 | 198 | _sleep(); |
Anunnaki | 2:1c8f73aa2a16 | 199 | } |
Anunnaki | 2:1c8f73aa2a16 | 200 | |
Anunnaki | 2:1c8f73aa2a16 | 201 | void GDEP015OC1::drawPixel(uint16_t startX, uint16_t startY, bool color=0){ |
Anunnaki | 2:1c8f73aa2a16 | 202 | if(startX>199 || startY>199) return; |
Anunnaki | 2:1c8f73aa2a16 | 203 | |
Anunnaki | 2:1c8f73aa2a16 | 204 | uint16_t i = startX/8 + startY*25; |
Anunnaki | 2:1c8f73aa2a16 | 205 | |
Anunnaki | 2:1c8f73aa2a16 | 206 | if(!color) |
Anunnaki | 2:1c8f73aa2a16 | 207 | _buffer[i] = (_buffer[i] | (1<<(7-startX%8))); |
Anunnaki | 2:1c8f73aa2a16 | 208 | else |
Anunnaki | 2:1c8f73aa2a16 | 209 | _buffer[i] = (_buffer[i] & (0xFF^(1<<(7-startX%8)))); |
Anunnaki | 2:1c8f73aa2a16 | 210 | } |
Anunnaki | 2:1c8f73aa2a16 | 211 | |
Anunnaki | 2:1c8f73aa2a16 | 212 | |
Anunnaki | 2:1c8f73aa2a16 | 213 | void GDEP015OC1::drawLine(uint16_t startX, uint16_t startY, uint16_t stopX, uint16_t stopY, bool color=0){ |
Anunnaki | 2:1c8f73aa2a16 | 214 | int dx = abs(stopX-startX), sx = startX<stopX ? 1 : -1; |
Anunnaki | 2:1c8f73aa2a16 | 215 | int dy = abs(stopY-startY), sy = startY<stopY ? 1 : -1; |
Anunnaki | 2:1c8f73aa2a16 | 216 | int err = (dx>dy ? dx : -dy)/2, e2; |
Anunnaki | 2:1c8f73aa2a16 | 217 | |
Anunnaki | 2:1c8f73aa2a16 | 218 | for(;;){ |
Anunnaki | 2:1c8f73aa2a16 | 219 | drawPixel(startX,startY,color); |
Anunnaki | 2:1c8f73aa2a16 | 220 | if (startX==stopX && startY==stopY) break; |
Anunnaki | 2:1c8f73aa2a16 | 221 | e2 = err; |
Anunnaki | 2:1c8f73aa2a16 | 222 | if (e2 >-dx) { err -= dy; startX += sx; } |
Anunnaki | 2:1c8f73aa2a16 | 223 | if (e2 < dy) { err += dx; startY += sy; } |
Anunnaki | 2:1c8f73aa2a16 | 224 | } |
Anunnaki | 3:dc7b794b59b7 | 225 | } |
Anunnaki | 3:dc7b794b59b7 | 226 | |
Anunnaki | 3:dc7b794b59b7 | 227 | void GDEP015OC1::drawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, bool color=0){ |
Anunnaki | 3:dc7b794b59b7 | 228 | drawLine(x1, y1, x2, y2, color); |
Anunnaki | 3:dc7b794b59b7 | 229 | drawLine(x2, y2, x3, y3, color); |
Anunnaki | 3:dc7b794b59b7 | 230 | drawLine(x3, y3, x1, y1, color); |
Anunnaki | 3:dc7b794b59b7 | 231 | } |
Anunnaki | 3:dc7b794b59b7 | 232 | |
Anunnaki | 3:dc7b794b59b7 | 233 | void GDEP015OC1::drawRectangle(uint16_t startX, uint16_t startY, uint16_t stopX, uint16_t stopY, bool color=0){ |
Anunnaki | 3:dc7b794b59b7 | 234 | drawLine(startX, startY, stopX, startY, color); |
Anunnaki | 3:dc7b794b59b7 | 235 | drawLine(stopX, startY, stopX, stopY, color); |
Anunnaki | 3:dc7b794b59b7 | 236 | drawLine(stopX, stopY, startX, stopY, color); |
Anunnaki | 3:dc7b794b59b7 | 237 | drawLine(startX, stopY, startX, startY, color); |
Anunnaki | 3:dc7b794b59b7 | 238 | } |
Anunnaki | 3:dc7b794b59b7 | 239 | |
Anunnaki | 3:dc7b794b59b7 | 240 | void GDEP015OC1::drawCircle(uint16_t startX, uint16_t startY, uint16_t radius, bool color=0){ |
Anunnaki | 3:dc7b794b59b7 | 241 | int d,x,y; |
Anunnaki | 3:dc7b794b59b7 | 242 | |
Anunnaki | 3:dc7b794b59b7 | 243 | d=3-2*radius; |
Anunnaki | 3:dc7b794b59b7 | 244 | x=0; |
Anunnaki | 3:dc7b794b59b7 | 245 | y=radius; |
Anunnaki | 3:dc7b794b59b7 | 246 | while(x<=y){ |
Anunnaki | 3:dc7b794b59b7 | 247 | drawPixel(startX+x,startY+y,color); |
Anunnaki | 3:dc7b794b59b7 | 248 | drawPixel(startX-y,startY-x,color); |
Anunnaki | 3:dc7b794b59b7 | 249 | drawPixel(startX+y,startY-x,color); |
Anunnaki | 3:dc7b794b59b7 | 250 | drawPixel(startX-y,startY+x,color); |
Anunnaki | 3:dc7b794b59b7 | 251 | drawPixel(startX+y,startY+x,color); |
Anunnaki | 3:dc7b794b59b7 | 252 | drawPixel(startX-x,startY-y,color); |
Anunnaki | 3:dc7b794b59b7 | 253 | drawPixel(startX+x,startY-y,color); |
Anunnaki | 3:dc7b794b59b7 | 254 | drawPixel(startX-x,startY+y,color); |
Anunnaki | 3:dc7b794b59b7 | 255 | |
Anunnaki | 3:dc7b794b59b7 | 256 | if(d<=0) |
Anunnaki | 3:dc7b794b59b7 | 257 | d=d+4*x+6; |
Anunnaki | 3:dc7b794b59b7 | 258 | else{ |
Anunnaki | 3:dc7b794b59b7 | 259 | d=d+4*x-4*y+10; |
Anunnaki | 3:dc7b794b59b7 | 260 | y--; |
Anunnaki | 3:dc7b794b59b7 | 261 | } |
Anunnaki | 3:dc7b794b59b7 | 262 | x++; |
Anunnaki | 3:dc7b794b59b7 | 263 | } |
Anunnaki | 3:dc7b794b59b7 | 264 | } |
Anunnaki | 3:dc7b794b59b7 | 265 | |
Anunnaki | 3:dc7b794b59b7 | 266 | void GDEP015OC1::fillCircle(uint16_t startX, uint16_t startY, uint16_t radius, bool color=0){ |
Anunnaki | 3:dc7b794b59b7 | 267 | for(uint16_t r = 1;r<=radius; r++){ |
Anunnaki | 3:dc7b794b59b7 | 268 | drawCircle(startX, startY, r, color); |
Anunnaki | 3:dc7b794b59b7 | 269 | drawCircle(startX+1, startY, r-1, color); |
Anunnaki | 3:dc7b794b59b7 | 270 | drawCircle(startX-1, startY, r-1, color); |
Anunnaki | 3:dc7b794b59b7 | 271 | } |
Anunnaki | 3:dc7b794b59b7 | 272 | } |
Anunnaki | 3:dc7b794b59b7 | 273 | |
Anunnaki | 3:dc7b794b59b7 | 274 | void GDEP015OC1::drawEllipse(uint16_t startX, uint16_t startY, uint16_t width, uint16_t height, bool color){ |
Anunnaki | 3:dc7b794b59b7 | 275 | int a2 = width*width; |
Anunnaki | 3:dc7b794b59b7 | 276 | int b2 = height*height; |
Anunnaki | 3:dc7b794b59b7 | 277 | int fa2 = 4*a2, fb2 = 4*b2; |
Anunnaki | 3:dc7b794b59b7 | 278 | int x, y, sigma; |
Anunnaki | 3:dc7b794b59b7 | 279 | |
Anunnaki | 3:dc7b794b59b7 | 280 | //First half |
Anunnaki | 3:dc7b794b59b7 | 281 | for(int x = 0, y = height, sigma = 2*b2+a2*(1-2*height); b2*x <= a2*y; x++){ |
Anunnaki | 3:dc7b794b59b7 | 282 | drawPixel(startX+x,startY+y,color); |
Anunnaki | 3:dc7b794b59b7 | 283 | drawPixel(startX-x,startY+y,color); |
Anunnaki | 3:dc7b794b59b7 | 284 | drawPixel(startX+x,startY-y,color); |
Anunnaki | 3:dc7b794b59b7 | 285 | drawPixel(startX-x,startY-y,color); |
Anunnaki | 3:dc7b794b59b7 | 286 | if(sigma >= 0){ |
Anunnaki | 3:dc7b794b59b7 | 287 | sigma += fa2 * (1-y); |
Anunnaki | 3:dc7b794b59b7 | 288 | y--; |
Anunnaki | 3:dc7b794b59b7 | 289 | } |
Anunnaki | 3:dc7b794b59b7 | 290 | sigma += b2 * ((4 * x) + 6); |
Anunnaki | 3:dc7b794b59b7 | 291 | } |
Anunnaki | 3:dc7b794b59b7 | 292 | //Second half |
Anunnaki | 3:dc7b794b59b7 | 293 | for (x = width, y = 0, sigma = 2*a2+b2*(1-2*width); a2*y <= b2*x; y++){ |
Anunnaki | 3:dc7b794b59b7 | 294 | drawPixel(startX+x,startY+y,color); |
Anunnaki | 3:dc7b794b59b7 | 295 | drawPixel(startX-x,startY+y,color); |
Anunnaki | 3:dc7b794b59b7 | 296 | drawPixel(startX+x,startY-y,color); |
Anunnaki | 3:dc7b794b59b7 | 297 | drawPixel(startX-x,startY-y,color); |
Anunnaki | 3:dc7b794b59b7 | 298 | if (sigma >= 0){ |
Anunnaki | 3:dc7b794b59b7 | 299 | sigma += fb2 * (1 - x); |
Anunnaki | 3:dc7b794b59b7 | 300 | x--; |
Anunnaki | 3:dc7b794b59b7 | 301 | } |
Anunnaki | 3:dc7b794b59b7 | 302 | sigma += a2 * ((4 * y) + 6); |
Anunnaki | 3:dc7b794b59b7 | 303 | } |
Anunnaki | 3:dc7b794b59b7 | 304 | } |
Anunnaki | 3:dc7b794b59b7 | 305 | |
Anunnaki | 3:dc7b794b59b7 | 306 | void GDEP015OC1::fillEllipse(uint16_t startX, uint16_t startY, uint16_t width, uint16_t height, bool color=0){ |
Anunnaki | 3:dc7b794b59b7 | 307 | for(uint16_t w = width; w > 0; w--){ |
Anunnaki | 3:dc7b794b59b7 | 308 | drawEllipse(startX, startX, w, height, color); |
Anunnaki | 3:dc7b794b59b7 | 309 | } |
Anunnaki | 3:dc7b794b59b7 | 310 | drawLine(startX, startY-height, startX, startY+height, color); |
Anunnaki | 3:dc7b794b59b7 | 311 | } |
Anunnaki | 3:dc7b794b59b7 | 312 | |
Anunnaki | 3:dc7b794b59b7 | 313 | void GDEP015OC1::writeChar(char character, uint16_t startX, uint16_t startY, bool color=0){ |
Anunnaki | 3:dc7b794b59b7 | 314 | unsigned char letter[FONT_WIDTH]; |
Anunnaki | 3:dc7b794b59b7 | 315 | |
Anunnaki | 3:dc7b794b59b7 | 316 | //Grab data for the corresponding font |
Anunnaki | 3:dc7b794b59b7 | 317 | for(uint8_t i = 0; i<FONT_WIDTH; i++) |
Anunnaki | 3:dc7b794b59b7 | 318 | letter[i] = Font5x7[(character - ' ') * FONT_WIDTH + i]; |
Anunnaki | 3:dc7b794b59b7 | 319 | |
Anunnaki | 3:dc7b794b59b7 | 320 | for(uint8_t i = 0; i<FONT_WIDTH; i++){ |
Anunnaki | 3:dc7b794b59b7 | 321 | for(uint8_t j = 0; j<FONT_HEIGHT; j++){ |
Anunnaki | 3:dc7b794b59b7 | 322 | if((letter[i]>>j)&0x01){ |
Anunnaki | 3:dc7b794b59b7 | 323 | if(_italic){ |
Anunnaki | 3:dc7b794b59b7 | 324 | drawPixel(startX+i+(FONT_HEIGHT/3 - j/3), startY+j, color); |
Anunnaki | 3:dc7b794b59b7 | 325 | if(_bold){ |
Anunnaki | 3:dc7b794b59b7 | 326 | for(uint8_t z=0; z<2; z++) |
Anunnaki | 3:dc7b794b59b7 | 327 | drawPixel(startX+i-z+(FONT_HEIGHT/3- j/3), startY+j, color); |
Anunnaki | 3:dc7b794b59b7 | 328 | } |
Anunnaki | 3:dc7b794b59b7 | 329 | } |
Anunnaki | 3:dc7b794b59b7 | 330 | else{ |
Anunnaki | 3:dc7b794b59b7 | 331 | drawPixel(startX+i, startY+j, color); |
Anunnaki | 3:dc7b794b59b7 | 332 | if(_bold){ |
Anunnaki | 3:dc7b794b59b7 | 333 | for(uint8_t z=0; z<2; z++) |
Anunnaki | 3:dc7b794b59b7 | 334 | drawPixel(startX+i-z, startY+j, color); |
Anunnaki | 3:dc7b794b59b7 | 335 | } |
Anunnaki | 3:dc7b794b59b7 | 336 | } |
Anunnaki | 3:dc7b794b59b7 | 337 | } |
Anunnaki | 3:dc7b794b59b7 | 338 | } |
Anunnaki | 3:dc7b794b59b7 | 339 | } |
Anunnaki | 3:dc7b794b59b7 | 340 | } |
Anunnaki | 3:dc7b794b59b7 | 341 | |
Anunnaki | 3:dc7b794b59b7 | 342 | void GDEP015OC1::writeString(char *string, uint16_t startX, uint16_t startY, bool color=0){ |
Anunnaki | 3:dc7b794b59b7 | 343 | uint8_t length = 0; |
Anunnaki | 3:dc7b794b59b7 | 344 | while(*(string+length) != '\0') length++; |
Anunnaki | 3:dc7b794b59b7 | 345 | |
Anunnaki | 3:dc7b794b59b7 | 346 | for(uint8_t x=0; x<length; x++) |
Anunnaki | 4:86114342ce8f | 347 | writeChar(*(string+x), startX+(FONT_WIDTH+1)*x, startY, color); //FONT_WIDTH+1 gives a 1px space between the characters |
Anunnaki | 2:1c8f73aa2a16 | 348 | } |