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 aconno dev team

Committer:
jurica238814
Date:
Mon Mar 13 09:45:26 2017 +0000
Revision:
9:9c1a15bd5ef1
Parent:
8:5ae728fa8820
Child:
10:eeb4adb54689
Errors with partial refresh fixed.

Who changed what in which revision?

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