A simple library for SSH1106 controlled GLCDs
SSH1106.cpp@1:ac9efaadd666, 2016-12-19 (annotated)
- Committer:
- Anaesthetix
- Date:
- Mon Dec 19 23:23:41 2016 +0000
- Revision:
- 1:ac9efaadd666
- Parent:
- 0:3cd0a11a2f91
- Child:
- 2:b55dd362afb9
Added basic drawing functions + buffered versions. More will come soon. Has a minor bug with postioning
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anaesthetix | 0:3cd0a11a2f91 | 1 | /** |
Anaesthetix | 1:ac9efaadd666 | 2 | * This is a simple library for SSH1106 controlled graphic LCD's. |
Anaesthetix | 0:3cd0a11a2f91 | 3 | * Written for a cheap 1.3" OLED GLCD |
Anaesthetix | 0:3cd0a11a2f91 | 4 | * See http://www.dx.com/p/open-smart-1-8-128-64-lcd-display-breakout-module-w-blue-backlit-444694 |
Anaesthetix | 0:3cd0a11a2f91 | 5 | * |
Anaesthetix | 0:3cd0a11a2f91 | 6 | * Written by: Erik van de Coevering |
Anaesthetix | 0:3cd0a11a2f91 | 7 | * With thanks to Tim Barr from whom I've reused some code |
Anaesthetix | 0:3cd0a11a2f91 | 8 | * Use this code in whatever way you like, as long as it stays free of charge! |
Anaesthetix | 0:3cd0a11a2f91 | 9 | */ |
Anaesthetix | 0:3cd0a11a2f91 | 10 | |
Anaesthetix | 0:3cd0a11a2f91 | 11 | #include "SSH1106.h" |
Anaesthetix | 0:3cd0a11a2f91 | 12 | |
Anaesthetix | 0:3cd0a11a2f91 | 13 | SSH1106::SSH1106(SPI &lcd, DigitalOut &lcd_cs, DigitalOut &lcd_cd, DigitalOut &lcd_rst) |
Anaesthetix | 0:3cd0a11a2f91 | 14 | { |
Anaesthetix | 0:3cd0a11a2f91 | 15 | _lcd = &lcd; |
Anaesthetix | 0:3cd0a11a2f91 | 16 | _lcd_cs = &lcd_cs; |
Anaesthetix | 0:3cd0a11a2f91 | 17 | _lcd_cd = &lcd_cd; |
Anaesthetix | 0:3cd0a11a2f91 | 18 | _lcd_rst = &lcd_rst; |
Anaesthetix | 0:3cd0a11a2f91 | 19 | } |
Anaesthetix | 0:3cd0a11a2f91 | 20 | |
Anaesthetix | 0:3cd0a11a2f91 | 21 | void SSH1106::init() |
Anaesthetix | 0:3cd0a11a2f91 | 22 | { |
Anaesthetix | 0:3cd0a11a2f91 | 23 | _lcd_cs->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 24 | _lcd->frequency(24000000); // Abusing SPI to save some time.. Try a lower freq if this doesn't work |
Anaesthetix | 0:3cd0a11a2f91 | 25 | _lcd->format(8,3); |
Anaesthetix | 0:3cd0a11a2f91 | 26 | _lcd_cs->write(0); // enable SPI |
Anaesthetix | 0:3cd0a11a2f91 | 27 | _lcd_cd->write(0); // COMMAND mode |
Anaesthetix | 1:ac9efaadd666 | 28 | |
Anaesthetix | 0:3cd0a11a2f91 | 29 | _lcd_rst->write(0); |
Anaesthetix | 0:3cd0a11a2f91 | 30 | wait_ms(100); |
Anaesthetix | 0:3cd0a11a2f91 | 31 | _lcd_rst->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 32 | |
Anaesthetix | 0:3cd0a11a2f91 | 33 | wait_ms(50); |
Anaesthetix | 0:3cd0a11a2f91 | 34 | |
Anaesthetix | 1:ac9efaadd666 | 35 | _lcd->write(0xAE); // Display off |
Anaesthetix | 0:3cd0a11a2f91 | 36 | _lcd->write(0x02); // Set lower column address |
Anaesthetix | 0:3cd0a11a2f91 | 37 | _lcd->write(0x10); // Set higher column address |
Anaesthetix | 0:3cd0a11a2f91 | 38 | _lcd->write(0x40); // Set display start line |
Anaesthetix | 0:3cd0a11a2f91 | 39 | _lcd->write(0xB0); // Set page address |
Anaesthetix | 0:3cd0a11a2f91 | 40 | _lcd->write(0x81); // Set contrast to |
Anaesthetix | 0:3cd0a11a2f91 | 41 | _lcd->write(0x80); // 128 |
Anaesthetix | 0:3cd0a11a2f91 | 42 | _lcd->write(0xA1); // Segment remap |
Anaesthetix | 0:3cd0a11a2f91 | 43 | _lcd->write(0xA6); // Inverse: normal (A7 = inverse) |
Anaesthetix | 0:3cd0a11a2f91 | 44 | _lcd->write(0xA8); // Multiplex ratio |
Anaesthetix | 0:3cd0a11a2f91 | 45 | _lcd->write(0x3F); // Duty = 1/32 |
Anaesthetix | 0:3cd0a11a2f91 | 46 | _lcd->write(0xAD); // Charge pump enable |
Anaesthetix | 0:3cd0a11a2f91 | 47 | _lcd->write(0x8B); // External VCC |
Anaesthetix | 0:3cd0a11a2f91 | 48 | _lcd->write(0x33); // VPP: 9v |
Anaesthetix | 0:3cd0a11a2f91 | 49 | _lcd->write(0xC8); // Com scan direction |
Anaesthetix | 0:3cd0a11a2f91 | 50 | _lcd->write(0xD3); // Display offset |
Anaesthetix | 1:ac9efaadd666 | 51 | _lcd->write(0x00); // 0x20 |
Anaesthetix | 0:3cd0a11a2f91 | 52 | _lcd->write(0xD5); // Osc division |
Anaesthetix | 1:ac9efaadd666 | 53 | _lcd->write(0x80); |
Anaesthetix | 0:3cd0a11a2f91 | 54 | _lcd->write(0xD9); // Pre-charge period |
Anaesthetix | 1:ac9efaadd666 | 55 | _lcd->write(0x1F); // 0x22 |
Anaesthetix | 0:3cd0a11a2f91 | 56 | _lcd->write(0xDA); // Set com pins |
Anaesthetix | 1:ac9efaadd666 | 57 | _lcd->write(0x12); |
Anaesthetix | 0:3cd0a11a2f91 | 58 | _lcd->write(0xDB); // Set vcomh |
Anaesthetix | 1:ac9efaadd666 | 59 | _lcd->write(0x40); |
Anaesthetix | 0:3cd0a11a2f91 | 60 | _lcd->write(0xAF); // Display ON |
Anaesthetix | 1:ac9efaadd666 | 61 | _lcd_cs->write(1); |
Anaesthetix | 1:ac9efaadd666 | 62 | _lcd_cd->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 63 | } |
Anaesthetix | 0:3cd0a11a2f91 | 64 | |
Anaesthetix | 0:3cd0a11a2f91 | 65 | void SSH1106::setContrast(char contrast) |
Anaesthetix | 0:3cd0a11a2f91 | 66 | { |
Anaesthetix | 0:3cd0a11a2f91 | 67 | _lcd_cs->write(0); // enable SPI |
Anaesthetix | 0:3cd0a11a2f91 | 68 | _lcd_cd->write(0); // command mode |
Anaesthetix | 0:3cd0a11a2f91 | 69 | _lcd->write(0x81); // command to set contrast |
Anaesthetix | 0:3cd0a11a2f91 | 70 | _lcd->write(contrast); // set contrast |
Anaesthetix | 0:3cd0a11a2f91 | 71 | _lcd_cs->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 72 | _lcd_cd->write(1); |
Anaesthetix | 1:ac9efaadd666 | 73 | } |
Anaesthetix | 0:3cd0a11a2f91 | 74 | |
Anaesthetix | 0:3cd0a11a2f91 | 75 | void SSH1106::setCursor(char column, char line) |
Anaesthetix | 0:3cd0a11a2f91 | 76 | { |
Anaesthetix | 0:3cd0a11a2f91 | 77 | int i, j; |
Anaesthetix | 0:3cd0a11a2f91 | 78 | column = column+2; // column+4 |
Anaesthetix | 0:3cd0a11a2f91 | 79 | |
Anaesthetix | 0:3cd0a11a2f91 | 80 | i=(column&0xF0)>>4; |
Anaesthetix | 0:3cd0a11a2f91 | 81 | j=column&0x0F; |
Anaesthetix | 0:3cd0a11a2f91 | 82 | _lcd_cd->write(0); |
Anaesthetix | 0:3cd0a11a2f91 | 83 | _lcd->write(0xb0+line); |
Anaesthetix | 0:3cd0a11a2f91 | 84 | _lcd->write(0x10+i); |
Anaesthetix | 0:3cd0a11a2f91 | 85 | _lcd->write(j); |
Anaesthetix | 0:3cd0a11a2f91 | 86 | _lcd_cd->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 87 | } |
Anaesthetix | 0:3cd0a11a2f91 | 88 | |
Anaesthetix | 0:3cd0a11a2f91 | 89 | void SSH1106::clear() |
Anaesthetix | 0:3cd0a11a2f91 | 90 | { |
Anaesthetix | 0:3cd0a11a2f91 | 91 | _lcd_cs->write(0); |
Anaesthetix | 0:3cd0a11a2f91 | 92 | _lcd_cd->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 93 | |
Anaesthetix | 0:3cd0a11a2f91 | 94 | for(unsigned short j = 0; j < 8; j++) { |
Anaesthetix | 0:3cd0a11a2f91 | 95 | SSH1106::setCursor(0, j); |
Anaesthetix | 0:3cd0a11a2f91 | 96 | for(unsigned short i = 0; i < 128 ; i++) { |
Anaesthetix | 0:3cd0a11a2f91 | 97 | _lcd->write(0x00); |
Anaesthetix | 0:3cd0a11a2f91 | 98 | } |
Anaesthetix | 0:3cd0a11a2f91 | 99 | } |
Anaesthetix | 0:3cd0a11a2f91 | 100 | |
Anaesthetix | 0:3cd0a11a2f91 | 101 | SSH1106::setCursor(0, 0); |
Anaesthetix | 0:3cd0a11a2f91 | 102 | |
Anaesthetix | 0:3cd0a11a2f91 | 103 | _lcd_cs->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 104 | } |
Anaesthetix | 0:3cd0a11a2f91 | 105 | |
Anaesthetix | 0:3cd0a11a2f91 | 106 | void SSH1106::writeText2d(char column, char page, const char font_address[96][8], const char *text, int size) |
Anaesthetix | 0:3cd0a11a2f91 | 107 | { |
Anaesthetix | 0:3cd0a11a2f91 | 108 | _lcd_cs->write(0); |
Anaesthetix | 0:3cd0a11a2f91 | 109 | SSH1106::setCursor(column, page); |
Anaesthetix | 0:3cd0a11a2f91 | 110 | for(int i=0; i<size; i++) { |
Anaesthetix | 0:3cd0a11a2f91 | 111 | for(int a=0; a<8; a++) { |
Anaesthetix | 0:3cd0a11a2f91 | 112 | _lcd->write((font_address[(text[i]-32)][a])); |
Anaesthetix | 0:3cd0a11a2f91 | 113 | } |
Anaesthetix | 0:3cd0a11a2f91 | 114 | } |
Anaesthetix | 0:3cd0a11a2f91 | 115 | _lcd_cs->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 116 | } |
Anaesthetix | 0:3cd0a11a2f91 | 117 | |
Anaesthetix | 0:3cd0a11a2f91 | 118 | void SSH1106::writeText(char column, char page, const char *font_address, const char *text, const uint8_t size) |
Anaesthetix | 0:3cd0a11a2f91 | 119 | { |
Anaesthetix | 0:3cd0a11a2f91 | 120 | // Position of character data in memory array |
Anaesthetix | 0:3cd0a11a2f91 | 121 | uint16_t pos_array; |
Anaesthetix | 0:3cd0a11a2f91 | 122 | // temporary column, page address, and column_cnt are used |
Anaesthetix | 0:3cd0a11a2f91 | 123 | // to stay inside display area |
Anaesthetix | 0:3cd0a11a2f91 | 124 | uint8_t i,y, column_cnt = 0; |
Anaesthetix | 0:3cd0a11a2f91 | 125 | uint8_t count = 0; |
Anaesthetix | 0:3cd0a11a2f91 | 126 | |
Anaesthetix | 0:3cd0a11a2f91 | 127 | // font information, needed for calculation |
Anaesthetix | 0:3cd0a11a2f91 | 128 | uint8_t start_code, last_code, width, page_height, bytes_p_char; |
Anaesthetix | 0:3cd0a11a2f91 | 129 | |
Anaesthetix | 0:3cd0a11a2f91 | 130 | uint8_t *txtbuffer; |
Anaesthetix | 0:3cd0a11a2f91 | 131 | |
Anaesthetix | 0:3cd0a11a2f91 | 132 | start_code = font_address[2]; // get first defined character |
Anaesthetix | 0:3cd0a11a2f91 | 133 | last_code = font_address[3]; // get last defined character |
Anaesthetix | 0:3cd0a11a2f91 | 134 | width = font_address[4]; // width in pixel of one char |
Anaesthetix | 0:3cd0a11a2f91 | 135 | page_height = font_address[6]; // page count per char |
Anaesthetix | 0:3cd0a11a2f91 | 136 | bytes_p_char = font_address[7]; // bytes per char |
Anaesthetix | 0:3cd0a11a2f91 | 137 | |
Anaesthetix | 0:3cd0a11a2f91 | 138 | _lcd_cs->write(0); // Enable SPI |
Anaesthetix | 0:3cd0a11a2f91 | 139 | _lcd_cd->write(1); // Data mode |
Anaesthetix | 0:3cd0a11a2f91 | 140 | |
Anaesthetix | 0:3cd0a11a2f91 | 141 | if(page_height + page > LCDPAGES) //stay inside display area |
Anaesthetix | 0:3cd0a11a2f91 | 142 | page_height = LCDPAGES - page; |
Anaesthetix | 0:3cd0a11a2f91 | 143 | |
Anaesthetix | 0:3cd0a11a2f91 | 144 | // The string is displayed character after character. If the font has more then one page, |
Anaesthetix | 0:3cd0a11a2f91 | 145 | // the top page is printed first, then the next page and so on |
Anaesthetix | 0:3cd0a11a2f91 | 146 | for(y = 0; y < page_height; y++) { |
Anaesthetix | 0:3cd0a11a2f91 | 147 | txtbuffer = &_lcdbuffer[page*LCDWIDTH + column]; |
Anaesthetix | 0:3cd0a11a2f91 | 148 | column_cnt = 0; // clear column_cnt start point |
Anaesthetix | 0:3cd0a11a2f91 | 149 | i = 0; |
Anaesthetix | 0:3cd0a11a2f91 | 150 | while(( i < size) && ((column_cnt + column) < LCDWIDTH)) { |
Anaesthetix | 0:3cd0a11a2f91 | 151 | if(text[i] < start_code || (uint8_t)text[i] > last_code) //make sure data is valid |
Anaesthetix | 0:3cd0a11a2f91 | 152 | i++; |
Anaesthetix | 0:3cd0a11a2f91 | 153 | else { |
Anaesthetix | 0:3cd0a11a2f91 | 154 | // calculate position of ASCII character in font array |
Anaesthetix | 0:3cd0a11a2f91 | 155 | // bytes for header + (ASCII - startcode) * bytes per char) |
Anaesthetix | 0:3cd0a11a2f91 | 156 | pos_array = 8 + (uint8_t)(text[i++] - start_code) * bytes_p_char; |
Anaesthetix | 0:3cd0a11a2f91 | 157 | |
Anaesthetix | 0:3cd0a11a2f91 | 158 | // get the dot pattern for the part of the char to print |
Anaesthetix | 0:3cd0a11a2f91 | 159 | pos_array += y*width; |
Anaesthetix | 0:3cd0a11a2f91 | 160 | |
Anaesthetix | 0:3cd0a11a2f91 | 161 | // stay inside display area |
Anaesthetix | 0:3cd0a11a2f91 | 162 | if((column_cnt + width + column) > LCDWIDTH) |
Anaesthetix | 0:3cd0a11a2f91 | 163 | column_cnt = LCDWIDTH-width; |
Anaesthetix | 0:3cd0a11a2f91 | 164 | |
Anaesthetix | 0:3cd0a11a2f91 | 165 | // copy character data to buffer |
Anaesthetix | 0:3cd0a11a2f91 | 166 | memcpy (txtbuffer+column_cnt,font_address+pos_array,width); |
Anaesthetix | 0:3cd0a11a2f91 | 167 | } |
Anaesthetix | 0:3cd0a11a2f91 | 168 | |
Anaesthetix | 0:3cd0a11a2f91 | 169 | column_cnt += width; |
Anaesthetix | 0:3cd0a11a2f91 | 170 | } |
Anaesthetix | 0:3cd0a11a2f91 | 171 | SSH1106::setCursor(column,page); // set start position x and y |
Anaesthetix | 0:3cd0a11a2f91 | 172 | |
Anaesthetix | 0:3cd0a11a2f91 | 173 | do { |
Anaesthetix | 0:3cd0a11a2f91 | 174 | _lcd->write(txtbuffer[count]); |
Anaesthetix | 0:3cd0a11a2f91 | 175 | count++; |
Anaesthetix | 0:3cd0a11a2f91 | 176 | } while ((count <= column_cnt)); |
Anaesthetix | 0:3cd0a11a2f91 | 177 | } |
Anaesthetix | 0:3cd0a11a2f91 | 178 | |
Anaesthetix | 0:3cd0a11a2f91 | 179 | _lcd_cs->write(1); // Disable SPI |
Anaesthetix | 0:3cd0a11a2f91 | 180 | |
Anaesthetix | 0:3cd0a11a2f91 | 181 | } |
Anaesthetix | 0:3cd0a11a2f91 | 182 | |
Anaesthetix | 0:3cd0a11a2f91 | 183 | void SSH1106::drawBitmap(const char *data) |
Anaesthetix | 0:3cd0a11a2f91 | 184 | { |
Anaesthetix | 0:3cd0a11a2f91 | 185 | int cnt = 0; |
Anaesthetix | 0:3cd0a11a2f91 | 186 | _lcd_cs->write(0); |
Anaesthetix | 0:3cd0a11a2f91 | 187 | _lcd_cd->write(1); |
Anaesthetix | 0:3cd0a11a2f91 | 188 | SSH1106::setCursor(0,0); |
Anaesthetix | 0:3cd0a11a2f91 | 189 | for(int row=0; row<8; row++) { |
Anaesthetix | 0:3cd0a11a2f91 | 190 | SSH1106::setCursor(0, row); |
Anaesthetix | 0:3cd0a11a2f91 | 191 | for(int column=0; column<128; column++) { |
Anaesthetix | 0:3cd0a11a2f91 | 192 | _lcd->write(data[cnt]); |
Anaesthetix | 0:3cd0a11a2f91 | 193 | cnt++; |
Anaesthetix | 0:3cd0a11a2f91 | 194 | } |
Anaesthetix | 0:3cd0a11a2f91 | 195 | } |
Anaesthetix | 1:ac9efaadd666 | 196 | _lcd_cs->write(1); |
Anaesthetix | 1:ac9efaadd666 | 197 | } |
Anaesthetix | 1:ac9efaadd666 | 198 | |
Anaesthetix | 1:ac9efaadd666 | 199 | void SSH1106::drawLineHor(char posx, char posy, char height, char width) |
Anaesthetix | 1:ac9efaadd666 | 200 | { |
Anaesthetix | 1:ac9efaadd666 | 201 | char page, offset, offset2; |
Anaesthetix | 1:ac9efaadd666 | 202 | char buffer[2] = {0xFF, 0xFF}; |
Anaesthetix | 1:ac9efaadd666 | 203 | |
Anaesthetix | 1:ac9efaadd666 | 204 | _lcd_cs->write(0); |
Anaesthetix | 1:ac9efaadd666 | 205 | _lcd_cd->write(1); |
Anaesthetix | 1:ac9efaadd666 | 206 | |
Anaesthetix | 1:ac9efaadd666 | 207 | if(width+posx > LCDWIDTH) width = (LCDWIDTH-posx); // keep inside display area |
Anaesthetix | 1:ac9efaadd666 | 208 | |
Anaesthetix | 1:ac9efaadd666 | 209 | page = posy/8; |
Anaesthetix | 1:ac9efaadd666 | 210 | offset = posy - (page*8); |
Anaesthetix | 1:ac9efaadd666 | 211 | buffer[0] = buffer[0] >> (8-height); |
Anaesthetix | 1:ac9efaadd666 | 212 | buffer[0] = buffer[0] << offset; |
Anaesthetix | 1:ac9efaadd666 | 213 | |
Anaesthetix | 1:ac9efaadd666 | 214 | if((offset + height) > 8) { |
Anaesthetix | 1:ac9efaadd666 | 215 | offset2 = ((offset+height)-8); |
Anaesthetix | 1:ac9efaadd666 | 216 | buffer[1] = buffer[1] - (0xFF << (offset2)); |
Anaesthetix | 1:ac9efaadd666 | 217 | } |
Anaesthetix | 1:ac9efaadd666 | 218 | |
Anaesthetix | 1:ac9efaadd666 | 219 | SSH1106::setCursor(posx, page); |
Anaesthetix | 1:ac9efaadd666 | 220 | |
Anaesthetix | 1:ac9efaadd666 | 221 | for(int i=0; i<width; i++) _lcd->write(buffer[0]); |
Anaesthetix | 1:ac9efaadd666 | 222 | |
Anaesthetix | 1:ac9efaadd666 | 223 | if(buffer[1] != 0xFF && (page+1) < 8) { // only write if line takes up > 1 page & keep inside display area |
Anaesthetix | 1:ac9efaadd666 | 224 | SSH1106::setCursor(posx, (page+1)); |
Anaesthetix | 1:ac9efaadd666 | 225 | for(int i=0; i<width; i++) _lcd->write(buffer[1]); |
Anaesthetix | 1:ac9efaadd666 | 226 | } |
Anaesthetix | 1:ac9efaadd666 | 227 | _lcd_cs->write(1); |
Anaesthetix | 1:ac9efaadd666 | 228 | } |
Anaesthetix | 1:ac9efaadd666 | 229 | |
Anaesthetix | 1:ac9efaadd666 | 230 | void SSH1106::drawLineVert(char posx, char posy, char height, char width) |
Anaesthetix | 1:ac9efaadd666 | 231 | { |
Anaesthetix | 1:ac9efaadd666 | 232 | char page, pagecount, offset, offset2; |
Anaesthetix | 1:ac9efaadd666 | 233 | |
Anaesthetix | 1:ac9efaadd666 | 234 | _lcd_cs->write(0); |
Anaesthetix | 1:ac9efaadd666 | 235 | _lcd_cd->write(1); |
Anaesthetix | 1:ac9efaadd666 | 236 | |
Anaesthetix | 1:ac9efaadd666 | 237 | page = posy/8; |
Anaesthetix | 1:ac9efaadd666 | 238 | pagecount = height/8; |
Anaesthetix | 1:ac9efaadd666 | 239 | offset2 = height - (pagecount*8); |
Anaesthetix | 1:ac9efaadd666 | 240 | |
Anaesthetix | 1:ac9efaadd666 | 241 | SSH1106::setCursor(posx, page); |
Anaesthetix | 1:ac9efaadd666 | 242 | for(int i=0; i<width; i++) _lcd->write((0xFF>>offset)); |
Anaesthetix | 1:ac9efaadd666 | 243 | |
Anaesthetix | 1:ac9efaadd666 | 244 | for(; pagecount > 1; pagecount--) { |
Anaesthetix | 1:ac9efaadd666 | 245 | page++; |
Anaesthetix | 1:ac9efaadd666 | 246 | SSH1106::setCursor(posx, page); |
Anaesthetix | 1:ac9efaadd666 | 247 | for(int i=0; i<width; i++) _lcd->write(0xFF); |
Anaesthetix | 1:ac9efaadd666 | 248 | } |
Anaesthetix | 1:ac9efaadd666 | 249 | |
Anaesthetix | 1:ac9efaadd666 | 250 | SSH1106::setCursor(posx, (page+1)); |
Anaesthetix | 1:ac9efaadd666 | 251 | for(int i=0; i<width; i++) _lcd->write((0xFF<<offset2)); |
Anaesthetix | 1:ac9efaadd666 | 252 | |
Anaesthetix | 1:ac9efaadd666 | 253 | _lcd_cs->write(1); |
Anaesthetix | 1:ac9efaadd666 | 254 | } |
Anaesthetix | 1:ac9efaadd666 | 255 | |
Anaesthetix | 1:ac9efaadd666 | 256 | void SSH1106::clearBuffer(void) |
Anaesthetix | 1:ac9efaadd666 | 257 | { |
Anaesthetix | 1:ac9efaadd666 | 258 | for(int i=0; i<(LCDWIDTH*LCDPAGES); i++) buff[i] = 0; |
Anaesthetix | 1:ac9efaadd666 | 259 | } |
Anaesthetix | 1:ac9efaadd666 | 260 | |
Anaesthetix | 1:ac9efaadd666 | 261 | void SSH1106::update(void) |
Anaesthetix | 1:ac9efaadd666 | 262 | { |
Anaesthetix | 1:ac9efaadd666 | 263 | int cnt = 0; |
Anaesthetix | 1:ac9efaadd666 | 264 | _lcd_cs->write(0); |
Anaesthetix | 1:ac9efaadd666 | 265 | _lcd_cd->write(1); |
Anaesthetix | 1:ac9efaadd666 | 266 | SSH1106::setCursor(0,0); |
Anaesthetix | 1:ac9efaadd666 | 267 | for(int row=0; row<8; row++) { |
Anaesthetix | 1:ac9efaadd666 | 268 | SSH1106::setCursor(0, row); |
Anaesthetix | 1:ac9efaadd666 | 269 | for(int column=0; column<128; column++) { |
Anaesthetix | 1:ac9efaadd666 | 270 | _lcd->write(buff[cnt]); |
Anaesthetix | 1:ac9efaadd666 | 271 | cnt++; |
Anaesthetix | 1:ac9efaadd666 | 272 | } |
Anaesthetix | 1:ac9efaadd666 | 273 | } |
Anaesthetix | 1:ac9efaadd666 | 274 | _lcd_cs->write(1); |
Anaesthetix | 1:ac9efaadd666 | 275 | } |
Anaesthetix | 1:ac9efaadd666 | 276 | |
Anaesthetix | 1:ac9efaadd666 | 277 | void SSH1106::drawbufferLineHor(char posx, char posy, char height, char width) |
Anaesthetix | 1:ac9efaadd666 | 278 | { |
Anaesthetix | 1:ac9efaadd666 | 279 | char page, offset, offset2; |
Anaesthetix | 1:ac9efaadd666 | 280 | int cursor; |
Anaesthetix | 1:ac9efaadd666 | 281 | char buffer[2] = {0xFF, 0xFF}; |
Anaesthetix | 1:ac9efaadd666 | 282 | |
Anaesthetix | 1:ac9efaadd666 | 283 | if(width+posx > LCDWIDTH) width = (LCDWIDTH-posx); // keep inside display area |
Anaesthetix | 1:ac9efaadd666 | 284 | |
Anaesthetix | 1:ac9efaadd666 | 285 | page = posy/8; |
Anaesthetix | 1:ac9efaadd666 | 286 | offset = posy - (page*8); |
Anaesthetix | 1:ac9efaadd666 | 287 | buffer[0] = buffer[0] >> (8-height); |
Anaesthetix | 1:ac9efaadd666 | 288 | buffer[0] = buffer[0] << offset; |
Anaesthetix | 1:ac9efaadd666 | 289 | |
Anaesthetix | 1:ac9efaadd666 | 290 | if((offset + height) > 8) { |
Anaesthetix | 1:ac9efaadd666 | 291 | offset2 = ((offset+height)-8); |
Anaesthetix | 1:ac9efaadd666 | 292 | buffer[1] = buffer[1] - (0xFF << (offset2)); |
Anaesthetix | 1:ac9efaadd666 | 293 | } |
Anaesthetix | 1:ac9efaadd666 | 294 | |
Anaesthetix | 1:ac9efaadd666 | 295 | cursor = posx + (page*128); |
Anaesthetix | 1:ac9efaadd666 | 296 | |
Anaesthetix | 1:ac9efaadd666 | 297 | for(int i=0; i<width; i++) SSH1106::buff[cursor+i] |= buffer[0]; |
Anaesthetix | 1:ac9efaadd666 | 298 | |
Anaesthetix | 1:ac9efaadd666 | 299 | if(buffer[1] != 0xFF && (page+1) < 8) { // only write if line takes up > 1 page & keep inside display area |
Anaesthetix | 1:ac9efaadd666 | 300 | for(int i=0; i<width; i++) SSH1106::buff[cursor+i+128] |= buffer[1]; |
Anaesthetix | 1:ac9efaadd666 | 301 | } |
Anaesthetix | 1:ac9efaadd666 | 302 | } |
Anaesthetix | 1:ac9efaadd666 | 303 | |
Anaesthetix | 1:ac9efaadd666 | 304 | void SSH1106::drawbufferLineVert(char posx, char posy, char height, char width) |
Anaesthetix | 1:ac9efaadd666 | 305 | { |
Anaesthetix | 1:ac9efaadd666 | 306 | char page, pagecount, offset, offset2; |
Anaesthetix | 1:ac9efaadd666 | 307 | int cursor; |
Anaesthetix | 1:ac9efaadd666 | 308 | |
Anaesthetix | 1:ac9efaadd666 | 309 | page = posy/8; |
Anaesthetix | 1:ac9efaadd666 | 310 | pagecount = height/8; |
Anaesthetix | 1:ac9efaadd666 | 311 | offset2 = height - (pagecount*8); |
Anaesthetix | 1:ac9efaadd666 | 312 | cursor = posx + (page*128); // LCDWIDTH |
Anaesthetix | 1:ac9efaadd666 | 313 | |
Anaesthetix | 1:ac9efaadd666 | 314 | for(int i=0; i<width; i++) SSH1106::buff[cursor+i] |= (0xFF>>offset); |
Anaesthetix | 1:ac9efaadd666 | 315 | |
Anaesthetix | 1:ac9efaadd666 | 316 | for(; pagecount > 1; pagecount--) { |
Anaesthetix | 1:ac9efaadd666 | 317 | page++; |
Anaesthetix | 1:ac9efaadd666 | 318 | cursor += 128; |
Anaesthetix | 1:ac9efaadd666 | 319 | for(int i=0; i<width; i++) SSH1106::buff[cursor+i] |= 0xFF; |
Anaesthetix | 1:ac9efaadd666 | 320 | } |
Anaesthetix | 1:ac9efaadd666 | 321 | |
Anaesthetix | 1:ac9efaadd666 | 322 | cursor += 128; |
Anaesthetix | 1:ac9efaadd666 | 323 | for(int i=0; i<width; i++) SSH1106::buff[cursor+i] |= (0xFF >> offset2); |
Anaesthetix | 0:3cd0a11a2f91 | 324 | } |