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