SP1 vers 3

Dependencies:   Fonts

Committer:
sstaub
Date:
Thu Sep 22 11:28:11 2016 +0000
Revision:
1:03129e57a003
Child:
2:5641e6bc9934
new library for EADOG displays from electronic assembly, only tested for EADOG132M

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sstaub 1:03129e57a003 1 /* mbed library for the mbed Lab Board 128*32 pixel LCD
sstaub 1:03129e57a003 2 * use ST7565R controller
sstaub 1:03129e57a003 3 * Copyright (c) 2016 Stefan Staub
sstaub 1:03129e57a003 4 * Released under the MIT License: http://mbed.org/license/mit
sstaub 1:03129e57a003 5 *
sstaub 1:03129e57a003 6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
sstaub 1:03129e57a003 7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
sstaub 1:03129e57a003 8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
sstaub 1:03129e57a003 9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
sstaub 1:03129e57a003 10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sstaub 1:03129e57a003 11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
sstaub 1:03129e57a003 12 * THE SOFTWARE.
sstaub 1:03129e57a003 13 */
sstaub 1:03129e57a003 14
sstaub 1:03129e57a003 15 #include "EADOG.h"
sstaub 1:03129e57a003 16 #include "mbed.h"
sstaub 1:03129e57a003 17 #include "stdio.h"
sstaub 1:03129e57a003 18 #include "Small_7.h"
sstaub 1:03129e57a003 19
sstaub 1:03129e57a003 20 EADOG::EADOG(PinName mosi, PinName sck, PinName reset, PinName a0, PinName cs, uint8_t type) : _spi(mosi, NC, sck), _reset(reset), _a0(a0), _cs(cs), _type(type), graphic_buffer() {
sstaub 1:03129e57a003 21 if (_type == DOGM132) {
sstaub 1:03129e57a003 22 width = 132;
sstaub 1:03129e57a003 23 height = 32;
sstaub 1:03129e57a003 24 graphic_buffer_size = 528;
sstaub 1:03129e57a003 25 graphic_buffer = new uint8_t [graphic_buffer_size];
sstaub 1:03129e57a003 26 }
sstaub 1:03129e57a003 27
sstaub 1:03129e57a003 28 if (_type == DOGM128 || _type == DOGL128) {
sstaub 1:03129e57a003 29 width = 128;
sstaub 1:03129e57a003 30 height = 64;
sstaub 1:03129e57a003 31 graphic_buffer_size = 1024;
sstaub 1:03129e57a003 32 graphic_buffer = new uint8_t [graphic_buffer_size];
sstaub 1:03129e57a003 33 }
sstaub 1:03129e57a003 34 init();
sstaub 1:03129e57a003 35 }
sstaub 1:03129e57a003 36
sstaub 1:03129e57a003 37 static void inline swap(int &a, int &b) {
sstaub 1:03129e57a003 38 int c = a;
sstaub 1:03129e57a003 39 a = b;
sstaub 1:03129e57a003 40 b = c;
sstaub 1:03129e57a003 41 }
sstaub 1:03129e57a003 42
sstaub 1:03129e57a003 43 void EADOG::display(uint8_t display) {
sstaub 1:03129e57a003 44 if (display == ON) { // display on
sstaub 1:03129e57a003 45 write_command(0xA4);
sstaub 1:03129e57a003 46 write_command(0xAF);
sstaub 1:03129e57a003 47 }
sstaub 1:03129e57a003 48 if (display == OFF) { // display off
sstaub 1:03129e57a003 49 write_command(0xAE);
sstaub 1:03129e57a003 50 }
sstaub 1:03129e57a003 51
sstaub 1:03129e57a003 52 if (display == SLEEP) {// display sleep
sstaub 1:03129e57a003 53 write_command(0xA5);
sstaub 1:03129e57a003 54 write_command(0xAE);
sstaub 1:03129e57a003 55 }
sstaub 1:03129e57a003 56 if(display == INVERT) { // invert display
sstaub 1:03129e57a003 57 write_command(0xA7);
sstaub 1:03129e57a003 58 }
sstaub 1:03129e57a003 59 if(display == DEFAULT) { // set to normal display
sstaub 1:03129e57a003 60 write_command(0xA6);
sstaub 1:03129e57a003 61 }
sstaub 1:03129e57a003 62 if (display == TOPVIEW) { // reverse orientation
sstaub 1:03129e57a003 63 write_command(0xA0); // ADC normal
sstaub 1:03129e57a003 64 write_command(0xC8); // reversed com31-com0
sstaub 1:03129e57a003 65 update(); // update necessary
sstaub 1:03129e57a003 66 }
sstaub 1:03129e57a003 67 if (display == BOTTOM) { // normal orientation
sstaub 1:03129e57a003 68 write_command(0xA1); // ADC reverse
sstaub 1:03129e57a003 69 write_command(0xC0); // normal com0-com31
sstaub 1:03129e57a003 70 update(); // update necessary
sstaub 1:03129e57a003 71 }
sstaub 1:03129e57a003 72 if (display == CONTRAST) {
sstaub 1:03129e57a003 73 if (_type == DOGM132) {
sstaub 1:03129e57a003 74 write_command(0x81); // set contrast to default for dogm 128
sstaub 1:03129e57a003 75 write_command(0x1F);
sstaub 1:03129e57a003 76 }
sstaub 1:03129e57a003 77 if (_type == DOGM128) {
sstaub 1:03129e57a003 78 write_command(0x81); // set contrast to default for dogm132
sstaub 1:03129e57a003 79 write_command(0x16);
sstaub 1:03129e57a003 80 }
sstaub 1:03129e57a003 81 if (_type == DOGL128) {
sstaub 1:03129e57a003 82 write_command(0x81); // set contrast to default for dogl132
sstaub 1:03129e57a003 83 write_command(0x10);
sstaub 1:03129e57a003 84 }
sstaub 1:03129e57a003 85 }
sstaub 1:03129e57a003 86 }
sstaub 1:03129e57a003 87
sstaub 1:03129e57a003 88 void EADOG::display(uint8_t display, uint8_t value) {
sstaub 1:03129e57a003 89 if (display == CONTRAST) {
sstaub 1:03129e57a003 90 if (value < 64) {
sstaub 1:03129e57a003 91 write_command(0x81); // set contrast
sstaub 1:03129e57a003 92 write_command(value & 0x3F);
sstaub 1:03129e57a003 93 }
sstaub 1:03129e57a003 94 }
sstaub 1:03129e57a003 95 }
sstaub 1:03129e57a003 96
sstaub 1:03129e57a003 97 // write command to lcd controller
sstaub 1:03129e57a003 98 void EADOG::write_command(uint8_t command) {
sstaub 1:03129e57a003 99 _a0 = 0;
sstaub 1:03129e57a003 100 _cs = 0;
sstaub 1:03129e57a003 101 _spi.write(command);
sstaub 1:03129e57a003 102 _cs = 1;
sstaub 1:03129e57a003 103 }
sstaub 1:03129e57a003 104
sstaub 1:03129e57a003 105 // write data to lcd controller
sstaub 1:03129e57a003 106 void EADOG::write_data(uint8_t data) {
sstaub 1:03129e57a003 107 _a0 = 1;
sstaub 1:03129e57a003 108 _cs = 0;
sstaub 1:03129e57a003 109 _spi.write(data);
sstaub 1:03129e57a003 110 _cs = 1;
sstaub 1:03129e57a003 111 }
sstaub 1:03129e57a003 112
sstaub 1:03129e57a003 113 // reset and init the lcd controller
sstaub 1:03129e57a003 114 void EADOG::init() {
sstaub 1:03129e57a003 115 _spi.format(8, 3); // 8 bit spi mode 3
sstaub 1:03129e57a003 116 _spi.frequency(20000000); // 19,2 Mhz SPI clock
sstaub 1:03129e57a003 117
sstaub 1:03129e57a003 118 //DigitalOut _reset(A1);
sstaub 1:03129e57a003 119 _a0 = 0;
sstaub 1:03129e57a003 120 _cs = 1;
sstaub 1:03129e57a003 121 _reset = 0; // display reset
sstaub 1:03129e57a003 122 wait_us(50);
sstaub 1:03129e57a003 123 _reset = 1; // end reset
sstaub 1:03129e57a003 124 wait_ms(5);
sstaub 1:03129e57a003 125
sstaub 1:03129e57a003 126 // Start Initial Sequence
sstaub 1:03129e57a003 127 write_command(0x40); // display start line 0
sstaub 1:03129e57a003 128 write_command(0xA1); // ADC reverse
sstaub 1:03129e57a003 129 write_command(0xC0); // normal com0-com31
sstaub 1:03129e57a003 130 write_command(0xA6); // display normal
sstaub 1:03129e57a003 131 write_command(0xA2); // set bias 1/9 (duty 1/33)
sstaub 1:03129e57a003 132 write_command(0x2F); // booster, regulator and follower on
sstaub 1:03129e57a003 133 write_command(0xF8); // set internal booster to 3x/4x
sstaub 1:03129e57a003 134 write_command(0x00);
sstaub 1:03129e57a003 135 if (_type == DOGM132) {
sstaub 1:03129e57a003 136 write_command(0x23); // set contrast
sstaub 1:03129e57a003 137 write_command(0x81);
sstaub 1:03129e57a003 138 write_command(0x1F);
sstaub 1:03129e57a003 139 }
sstaub 1:03129e57a003 140 if (_type == DOGM128) {
sstaub 1:03129e57a003 141 write_command(0x27); // set contrast
sstaub 1:03129e57a003 142 write_command(0x81);
sstaub 1:03129e57a003 143 write_command(0x16);
sstaub 1:03129e57a003 144 }
sstaub 1:03129e57a003 145 if (_type == DOGL128) {
sstaub 1:03129e57a003 146 write_command(0x27); // set contrast
sstaub 1:03129e57a003 147 write_command(0x81);
sstaub 1:03129e57a003 148 write_command(0x10);
sstaub 1:03129e57a003 149 }
sstaub 1:03129e57a003 150 write_command(0xAC); // no indicator
sstaub 1:03129e57a003 151 write_command(0x00);
sstaub 1:03129e57a003 152 write_command(0xAF); // display on
sstaub 1:03129e57a003 153
sstaub 1:03129e57a003 154 // clear and update LCD
sstaub 1:03129e57a003 155 cls();
sstaub 1:03129e57a003 156 auto_update = 1; // switch on auto update
sstaub 1:03129e57a003 157 locate(0, 0);
sstaub 1:03129e57a003 158 font((unsigned char*)Small_7); // standard font
sstaub 1:03129e57a003 159 }
sstaub 1:03129e57a003 160
sstaub 1:03129e57a003 161 // update lcd
sstaub 1:03129e57a003 162 void EADOG::update() {
sstaub 1:03129e57a003 163 //page 0
sstaub 1:03129e57a003 164 write_command(0x00); // set column low nibble 0
sstaub 1:03129e57a003 165 write_command(0x10); // set column hi nibble 0
sstaub 1:03129e57a003 166 write_command(0xB0); // set page address 0
sstaub 1:03129e57a003 167 _a0 = 1;
sstaub 1:03129e57a003 168
sstaub 1:03129e57a003 169 for (int i = 0; i < width; i++) {
sstaub 1:03129e57a003 170 write_data(graphic_buffer[i]);
sstaub 1:03129e57a003 171 }
sstaub 1:03129e57a003 172
sstaub 1:03129e57a003 173 // page 1
sstaub 1:03129e57a003 174 write_command(0x00); // set column low nibble 0
sstaub 1:03129e57a003 175 write_command(0x10); // set column hi nibble 0
sstaub 1:03129e57a003 176 write_command(0xB1); // set page address 1
sstaub 1:03129e57a003 177 _a0 = 1;
sstaub 1:03129e57a003 178
sstaub 1:03129e57a003 179 for (int i = width; i < width * 2; i++) {
sstaub 1:03129e57a003 180 write_data(graphic_buffer[i]);
sstaub 1:03129e57a003 181 }
sstaub 1:03129e57a003 182
sstaub 1:03129e57a003 183 //page 2
sstaub 1:03129e57a003 184 write_command(0x00); // set column low nibble 0
sstaub 1:03129e57a003 185 write_command(0x10); // set column hi nibble 0
sstaub 1:03129e57a003 186 write_command(0xB2); // set page address 2
sstaub 1:03129e57a003 187 _a0 = 1;
sstaub 1:03129e57a003 188
sstaub 1:03129e57a003 189 for (int i = width * 2; i < width * 3; i++) {
sstaub 1:03129e57a003 190 write_data(graphic_buffer[i]);
sstaub 1:03129e57a003 191 }
sstaub 1:03129e57a003 192
sstaub 1:03129e57a003 193 //page 3
sstaub 1:03129e57a003 194 write_command(0x00); // set column low nibble 0
sstaub 1:03129e57a003 195 write_command(0x10); // set column hi nibble 0
sstaub 1:03129e57a003 196 write_command(0xB3); // set page address 3
sstaub 1:03129e57a003 197 _a0 = 1;
sstaub 1:03129e57a003 198
sstaub 1:03129e57a003 199 for (int i = width * 3; i < width * 4; i++) {
sstaub 1:03129e57a003 200 write_data(graphic_buffer[i]);
sstaub 1:03129e57a003 201 }
sstaub 1:03129e57a003 202
sstaub 1:03129e57a003 203 if (_type == DOGM128 || _type == DOGL128) {
sstaub 1:03129e57a003 204 //page 4
sstaub 1:03129e57a003 205 write_command(0x00); // set column low nibble 0
sstaub 1:03129e57a003 206 write_command(0x10); // set column hi nibble 0
sstaub 1:03129e57a003 207 write_command(0xB4); // set page address 3
sstaub 1:03129e57a003 208 _a0 = 1;
sstaub 1:03129e57a003 209
sstaub 1:03129e57a003 210 for (int i = width * 4; i < width * 5; i++) {
sstaub 1:03129e57a003 211 write_data(graphic_buffer[i]);
sstaub 1:03129e57a003 212 }
sstaub 1:03129e57a003 213
sstaub 1:03129e57a003 214 //page 5
sstaub 1:03129e57a003 215 write_command(0x00); // set column low nibble 0
sstaub 1:03129e57a003 216 write_command(0x10); // set column hi nibble 0
sstaub 1:03129e57a003 217 write_command(0xB5); // set page address 3
sstaub 1:03129e57a003 218 _a0 = 1;
sstaub 1:03129e57a003 219
sstaub 1:03129e57a003 220 for (int i = width * 5; i < width * 6; i++) {
sstaub 1:03129e57a003 221 write_data(graphic_buffer[i]);
sstaub 1:03129e57a003 222 }
sstaub 1:03129e57a003 223
sstaub 1:03129e57a003 224 //page 6
sstaub 1:03129e57a003 225 write_command(0x00); // set column low nibble 0
sstaub 1:03129e57a003 226 write_command(0x10); // set column hi nibble 0
sstaub 1:03129e57a003 227 write_command(0xB6); // set page address 3
sstaub 1:03129e57a003 228 _a0 = 1;
sstaub 1:03129e57a003 229
sstaub 1:03129e57a003 230 for (int i = width * 6; i < width *7; i++) {
sstaub 1:03129e57a003 231 write_data(graphic_buffer[i]);
sstaub 1:03129e57a003 232 }
sstaub 1:03129e57a003 233
sstaub 1:03129e57a003 234 //page 7
sstaub 1:03129e57a003 235 write_command(0x00); // set column low nibble 0
sstaub 1:03129e57a003 236 write_command(0x10); // set column hi nibble 0
sstaub 1:03129e57a003 237 write_command(0xB7); // set page address 3
sstaub 1:03129e57a003 238 _a0 = 1;
sstaub 1:03129e57a003 239
sstaub 1:03129e57a003 240 for (int i = width * 7; i < width *8; i++) {
sstaub 1:03129e57a003 241 write_data(graphic_buffer[i]);
sstaub 1:03129e57a003 242 }
sstaub 1:03129e57a003 243 }
sstaub 1:03129e57a003 244
sstaub 1:03129e57a003 245 _cs = 0;
sstaub 1:03129e57a003 246
sstaub 1:03129e57a003 247 }
sstaub 1:03129e57a003 248 void EADOG::update(uint8_t mode) {
sstaub 1:03129e57a003 249 if (mode == MANUAL) auto_update = 0;
sstaub 1:03129e57a003 250 if (mode == AUTO) auto_update = 1;
sstaub 1:03129e57a003 251 }
sstaub 1:03129e57a003 252
sstaub 1:03129e57a003 253 // clear screen
sstaub 1:03129e57a003 254 void EADOG::cls() {
sstaub 1:03129e57a003 255 memset(graphic_buffer, 0x00, graphic_buffer_size); // clear display graphic_buffer
sstaub 1:03129e57a003 256 update();
sstaub 1:03129e57a003 257 }
sstaub 1:03129e57a003 258
sstaub 1:03129e57a003 259 // set one pixel in graphic_buffer
sstaub 1:03129e57a003 260 void EADOG::pixel(int x, int y, uint8_t color) {
sstaub 1:03129e57a003 261 if (x > width - 1 || y > height - 1 || x < 0 || y < 0) return;
sstaub 1:03129e57a003 262 if (color == 0) graphic_buffer[x + ((y / 8) * width)] &= ~(1 << (y % 8)); // erase pixel
sstaub 1:03129e57a003 263 else graphic_buffer[x + ((y / 8) * width)] |= (1 << (y % 8)); // set pixel
sstaub 1:03129e57a003 264 }
sstaub 1:03129e57a003 265
sstaub 1:03129e57a003 266 void EADOG::point(int x, int y, uint8_t colour) {
sstaub 1:03129e57a003 267 pixel(x, y, colour);
sstaub 1:03129e57a003 268 if (auto_update) update();
sstaub 1:03129e57a003 269 }
sstaub 1:03129e57a003 270
sstaub 1:03129e57a003 271 // This function uses Bresenham's algorithm to draw a straight line.
sstaub 1:03129e57a003 272 void EADOG::line(int x0, int y0, int x1, int y1, uint8_t colour) {
sstaub 1:03129e57a003 273 int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
sstaub 1:03129e57a003 274 int dy = -abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
sstaub 1:03129e57a003 275 int err = dx + dy, e2; /* error value e_xy */
sstaub 1:03129e57a003 276
sstaub 1:03129e57a003 277 while(1) {
sstaub 1:03129e57a003 278 pixel(x0, y0, 1);
sstaub 1:03129e57a003 279 if (x0 == x1 && y0 == y1) break;
sstaub 1:03129e57a003 280 e2 = 2 * err;
sstaub 1:03129e57a003 281 if (e2 > dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
sstaub 1:03129e57a003 282 if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
sstaub 1:03129e57a003 283 }
sstaub 1:03129e57a003 284 if (auto_update) update();
sstaub 1:03129e57a003 285 }
sstaub 1:03129e57a003 286
sstaub 1:03129e57a003 287 void EADOG::rectangle(int x0, int y0, int x1, int y1, uint8_t colour) {
sstaub 1:03129e57a003 288 uint8_t upd = auto_update;
sstaub 1:03129e57a003 289 auto_update = 0;
sstaub 1:03129e57a003 290 line(x0, y0, x1, y0, colour);
sstaub 1:03129e57a003 291 line(x0, y1, x1, y1, colour);
sstaub 1:03129e57a003 292 line(x0, y0, x0, y1, colour);
sstaub 1:03129e57a003 293 line(x1, y0, x1, y1, colour);
sstaub 1:03129e57a003 294 auto_update = upd;
sstaub 1:03129e57a003 295 if (auto_update) update();
sstaub 1:03129e57a003 296 }
sstaub 1:03129e57a003 297
sstaub 1:03129e57a003 298 void EADOG::fillrect(int x0, int y0, int x1, int y1, uint8_t colour) {
sstaub 1:03129e57a003 299 if (x0 > x1) swap(x0, x1);
sstaub 1:03129e57a003 300 if (y0 > y1) swap(y0, y1);
sstaub 1:03129e57a003 301 for (int i = x0; i <= x1; i++) {
sstaub 1:03129e57a003 302 for (int j = y0; j <= y1; j++) {
sstaub 1:03129e57a003 303 pixel(i, j, colour);
sstaub 1:03129e57a003 304 }
sstaub 1:03129e57a003 305 }
sstaub 1:03129e57a003 306 if (auto_update) update();
sstaub 1:03129e57a003 307 }
sstaub 1:03129e57a003 308
sstaub 1:03129e57a003 309 void EADOG::roundrect(int x0, int y0, int x1, int y1, int rnd, uint8_t colour) {
sstaub 1:03129e57a003 310 if (x0 > x1) swap(x0, x1);
sstaub 1:03129e57a003 311 if (y0 > y1) swap(y0, y1);
sstaub 1:03129e57a003 312 uint8_t upd = auto_update;
sstaub 1:03129e57a003 313 auto_update = 0;
sstaub 1:03129e57a003 314 int r = rnd;
sstaub 1:03129e57a003 315 int x = -r, y = 0, err = 2 - 2 * r;
sstaub 1:03129e57a003 316 line(x0 + rnd, y0, x1 - rnd, y0, colour);
sstaub 1:03129e57a003 317 line(x0 + rnd, y1, x1 - rnd, y1, colour);
sstaub 1:03129e57a003 318 line(x0, y0 + rnd, x0, y1 - rnd, colour);
sstaub 1:03129e57a003 319 line(x1, y0 + rnd, x1, y1 - rnd, colour);
sstaub 1:03129e57a003 320 do {
sstaub 1:03129e57a003 321 pixel(x1 - rnd + y, y0 + x + rnd, 1); // 1 I. quadrant
sstaub 1:03129e57a003 322 pixel(x1 - rnd - x, y1 + y - rnd, 1); // 2 IV. quadrant
sstaub 1:03129e57a003 323 pixel(x0 + rnd - y, y1 - rnd - x, 1); // 3 III. quadrant
sstaub 1:03129e57a003 324 pixel(x0 + rnd + x, y0 + rnd - y, 1); // 4 II. quadrant
sstaub 1:03129e57a003 325 r = err;
sstaub 1:03129e57a003 326 if (r <= y) err += ++y * 2 + 1;
sstaub 1:03129e57a003 327 if (r > x || err > y) err += ++x * 2 + 1;
sstaub 1:03129e57a003 328 } while (x < 0);
sstaub 1:03129e57a003 329 auto_update = upd;
sstaub 1:03129e57a003 330 if (auto_update) update();
sstaub 1:03129e57a003 331 }
sstaub 1:03129e57a003 332
sstaub 1:03129e57a003 333 void EADOG::fillrrect(int x0, int y0, int x1, int y1, int rnd, uint8_t colour) {
sstaub 1:03129e57a003 334 if (x0 > x1) swap(x0, x1);
sstaub 1:03129e57a003 335 if (y0 > y1) swap(y0, y1);
sstaub 1:03129e57a003 336 uint8_t upd = auto_update;
sstaub 1:03129e57a003 337 auto_update = 0;
sstaub 1:03129e57a003 338 int r = rnd;
sstaub 1:03129e57a003 339 int x = -r, y = 0, err = 2 - 2 * r;
sstaub 1:03129e57a003 340 for (int i = x0; i <= x1; i++) {
sstaub 1:03129e57a003 341 for (int j = y0+rnd; j <= y1-rnd; j++) {
sstaub 1:03129e57a003 342 pixel(i, j, colour);
sstaub 1:03129e57a003 343 }
sstaub 1:03129e57a003 344 }
sstaub 1:03129e57a003 345 do {
sstaub 1:03129e57a003 346 line(x0 + rnd - y, y0 + rnd + x, x1 - rnd + y, y0 + rnd + x, 1);
sstaub 1:03129e57a003 347 line(x0 + rnd + x, y1 - rnd + y, x1 - rnd - x, y1 - rnd + y, 1);
sstaub 1:03129e57a003 348 r = err;
sstaub 1:03129e57a003 349 if (r <= y) err += ++y * 2 + 1;
sstaub 1:03129e57a003 350 if (r > x || err > y) err += ++x * 2 + 1;
sstaub 1:03129e57a003 351 } while (x < 0);
sstaub 1:03129e57a003 352 auto_update = upd;
sstaub 1:03129e57a003 353 if (auto_update) update();
sstaub 1:03129e57a003 354 }
sstaub 1:03129e57a003 355
sstaub 1:03129e57a003 356 void EADOG::circle(int x0, int y0, int r, uint8_t colour) {
sstaub 1:03129e57a003 357 int x = -r, y = 0, err = 2 - 2 * r;
sstaub 1:03129e57a003 358 do {
sstaub 1:03129e57a003 359 pixel(x0 + y, y0 + x, 1); // 1 I. quadrant
sstaub 1:03129e57a003 360 pixel(x0 - x, y0 + y, 1); // 2 IV. quadrant
sstaub 1:03129e57a003 361 pixel(x0 - y, y0 - x, 1); // 3 III. quadrant
sstaub 1:03129e57a003 362 pixel(x0 + x, y0 - y, 1); // 4 II. quadrant
sstaub 1:03129e57a003 363 r = err;
sstaub 1:03129e57a003 364 if (r <= y) err += ++y * 2 + 1;
sstaub 1:03129e57a003 365 if (r > x || err > y) err += ++x * 2 + 1;
sstaub 1:03129e57a003 366 } while (x < 0);
sstaub 1:03129e57a003 367 if (auto_update) update();
sstaub 1:03129e57a003 368 }
sstaub 1:03129e57a003 369
sstaub 1:03129e57a003 370 void EADOG::fillcircle(int x0, int y0, int r, uint8_t colour) {
sstaub 1:03129e57a003 371 uint8_t upd;
sstaub 1:03129e57a003 372 upd = auto_update;
sstaub 1:03129e57a003 373 auto_update = 0;
sstaub 1:03129e57a003 374 int x = -r, y = 0, err = 2 - 2 * r;
sstaub 1:03129e57a003 375 do {
sstaub 1:03129e57a003 376 line(x0 - y, y0 + x, x0 + y, y0 + x, 1);
sstaub 1:03129e57a003 377 line(x0 + x, y0 + y, x0 - x, y0 + y, 1);
sstaub 1:03129e57a003 378 r = err;
sstaub 1:03129e57a003 379 if (r <= y) err += ++y * 2 + 1;
sstaub 1:03129e57a003 380 if (r > x || err > y) err += ++x * 2 + 1;
sstaub 1:03129e57a003 381 } while (x < 0);
sstaub 1:03129e57a003 382 auto_update = upd;
sstaub 1:03129e57a003 383 if (auto_update) update();
sstaub 1:03129e57a003 384 }
sstaub 1:03129e57a003 385
sstaub 1:03129e57a003 386 void EADOG::locate(uint8_t x, uint8_t y) {
sstaub 1:03129e57a003 387 char_x = x;
sstaub 1:03129e57a003 388 char_y = y;
sstaub 1:03129e57a003 389 }
sstaub 1:03129e57a003 390
sstaub 1:03129e57a003 391 int EADOG::_putc(int value) {
sstaub 1:03129e57a003 392 if (value == '\n') { // new line
sstaub 1:03129e57a003 393 char_x = 0;
sstaub 1:03129e57a003 394 char_y = char_y + font_buffer[2];
sstaub 1:03129e57a003 395 if (char_y >= height - font_buffer[2]) {
sstaub 1:03129e57a003 396 char_y = 0;
sstaub 1:03129e57a003 397 }
sstaub 1:03129e57a003 398 }
sstaub 1:03129e57a003 399 else {
sstaub 1:03129e57a003 400 character(char_x, char_y, value);
sstaub 1:03129e57a003 401 if (auto_update) update();
sstaub 1:03129e57a003 402 }
sstaub 1:03129e57a003 403 return value;
sstaub 1:03129e57a003 404 }
sstaub 1:03129e57a003 405
sstaub 1:03129e57a003 406 int EADOG::_getc() {
sstaub 1:03129e57a003 407 return -1;
sstaub 1:03129e57a003 408 }
sstaub 1:03129e57a003 409
sstaub 1:03129e57a003 410 void EADOG::character(uint8_t x, uint8_t y, uint8_t c) {
sstaub 1:03129e57a003 411 unsigned int hor, vert, offset, bpl, b;
sstaub 1:03129e57a003 412 uint8_t *sign;
sstaub 1:03129e57a003 413 uint8_t z, w;
sstaub 1:03129e57a003 414
sstaub 1:03129e57a003 415 if ((c < 31) || (c > 127)) return; // test char range
sstaub 1:03129e57a003 416
sstaub 1:03129e57a003 417 // read font parameter from start of array
sstaub 1:03129e57a003 418 offset = font_buffer[0]; // bytes / char
sstaub 1:03129e57a003 419 hor = font_buffer[1]; // get hor size of font
sstaub 1:03129e57a003 420 vert = font_buffer[2]; // get vert size of font
sstaub 1:03129e57a003 421 bpl = font_buffer[3]; // bytes per line
sstaub 1:03129e57a003 422
sstaub 1:03129e57a003 423 if (char_x + hor > width) {
sstaub 1:03129e57a003 424 char_x = 0;
sstaub 1:03129e57a003 425 char_y = char_y + vert;
sstaub 1:03129e57a003 426 if (char_y >= height - font_buffer[2]) {
sstaub 1:03129e57a003 427 char_y = 0;
sstaub 1:03129e57a003 428 }
sstaub 1:03129e57a003 429 }
sstaub 1:03129e57a003 430
sstaub 1:03129e57a003 431 sign = &font_buffer[((c - 32) * offset) + 4]; // start of char bitmap
sstaub 1:03129e57a003 432 w = sign[0]; // width of actual char
sstaub 1:03129e57a003 433 // construct the char into the font_graphic_buffer
sstaub 1:03129e57a003 434 for (unsigned int j = 0; j < vert; j++) { // vert line
sstaub 1:03129e57a003 435 for (unsigned int i = 0; i < hor; i++) { // horz line
sstaub 1:03129e57a003 436 z = sign[bpl * i + ((j & 0xF8) >> 3) + 1];
sstaub 1:03129e57a003 437 b = 1 << (j & 0x07);
sstaub 1:03129e57a003 438 if (( z & b ) == 0x00) {
sstaub 1:03129e57a003 439 pixel(x+i, y+j, 0);
sstaub 1:03129e57a003 440 }
sstaub 1:03129e57a003 441 else {
sstaub 1:03129e57a003 442 pixel(x+i, y+j, 1);
sstaub 1:03129e57a003 443 }
sstaub 1:03129e57a003 444 }
sstaub 1:03129e57a003 445 }
sstaub 1:03129e57a003 446 char_x += w;
sstaub 1:03129e57a003 447 }
sstaub 1:03129e57a003 448
sstaub 1:03129e57a003 449
sstaub 1:03129e57a003 450 void EADOG::font(uint8_t *f) {
sstaub 1:03129e57a003 451 font_buffer = f;
sstaub 1:03129e57a003 452 }
sstaub 1:03129e57a003 453
sstaub 1:03129e57a003 454 void EADOG::bitmap(Bitmap bm, int x, int y) {
sstaub 1:03129e57a003 455 int b;
sstaub 1:03129e57a003 456 char d;
sstaub 1:03129e57a003 457
sstaub 1:03129e57a003 458 for (int v = 0; v < bm.ySize; v++) { // lines
sstaub 1:03129e57a003 459 for (int h = 0; h < bm.xSize; h++) { // pixel
sstaub 1:03129e57a003 460 if (h + x >= width) break;
sstaub 1:03129e57a003 461 if (v + y >= height) break;
sstaub 1:03129e57a003 462 d = bm.data[bm.byte_in_Line * v + ((h & 0xF8) >> 3)];
sstaub 1:03129e57a003 463 b = 0x80 >> (h & 0x07);
sstaub 1:03129e57a003 464 if ((d & b) == 0) {
sstaub 1:03129e57a003 465 pixel(x+h, y+v, 0);
sstaub 1:03129e57a003 466 }
sstaub 1:03129e57a003 467 else {
sstaub 1:03129e57a003 468 pixel(x+h, y+v, 1);
sstaub 1:03129e57a003 469 }
sstaub 1:03129e57a003 470 }
sstaub 1:03129e57a003 471 }
sstaub 1:03129e57a003 472 if (auto_update) update();
sstaub 1:03129e57a003 473 }