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