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