Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Dependents:   Brew

Committer:
dreschpe
Date:
Mon Feb 06 12:29:33 2017 +0000
Revision:
33:f87f06292637
Parent:
27:acb2594b8aa4
Add I2C protocol. ; Add SSD1306 i2C modus

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 4:12ba0ecc2c1f 1 /* mbed UniGraphic library - universal LCD driver class
Geremia 4:12ba0ecc2c1f 2 * Copyright (c) 2015 Giuliano Dianda
Geremia 4:12ba0ecc2c1f 3 * Released under the MIT License: http://mbed.org/license/mit
Geremia 4:12ba0ecc2c1f 4 *
Geremia 4:12ba0ecc2c1f 5 * Derived work of:
Geremia 4:12ba0ecc2c1f 6 *
Geremia 4:12ba0ecc2c1f 7 * mbed library for the mbed Lab Board 128*32 pixel LCD
Geremia 3:48f3282c2be8 8 * use C12832 controller
Geremia 3:48f3282c2be8 9 * Copyright (c) 2012 Peter Drescher - DC2PD
Geremia 3:48f3282c2be8 10 * Released under the MIT License: http://mbed.org/license/mit
Geremia 3:48f3282c2be8 11 *
Geremia 3:48f3282c2be8 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Geremia 3:48f3282c2be8 13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Geremia 3:48f3282c2be8 14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Geremia 3:48f3282c2be8 15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Geremia 3:48f3282c2be8 16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Geremia 3:48f3282c2be8 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Geremia 3:48f3282c2be8 18 * THE SOFTWARE.
Geremia 3:48f3282c2be8 19 */
dreschpe 27:acb2594b8aa4 20 #include "platform.h"
dreschpe 27:acb2594b8aa4 21 #include "LCD.h"
Geremia 3:48f3282c2be8 22
dreschpe 27:acb2594b8aa4 23 #if DEVICE_PORTINOUT
dreschpe 27:acb2594b8aa4 24 #include "PAR8.h"
dreschpe 27:acb2594b8aa4 25 #include "PAR16.h"
dreschpe 27:acb2594b8aa4 26 #endif
Geremia 0:75ec1b3cde17 27
Geremia 0:75ec1b3cde17 28 //#include "mbed_debug.h"
Geremia 7:bb0383b91104 29
Geremia 0:75ec1b3cde17 30 #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; }
Geremia 2:713844a55c4e 31
dreschpe 27:acb2594b8aa4 32 #if DEVICE_PORTINOUT
Geremia 0:75ec1b3cde17 33 LCD::LCD(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char *name)
Geremia 7:bb0383b91104 34 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y), _LCDPAGES(lcdsize_y>>3), _IC_X_SEGS(ic_x_segs), _IC_Y_COMS(ic_y_coms), _IC_PAGES(ic_y_coms>>3)
Geremia 0:75ec1b3cde17 35 {
dreschpe 27:acb2594b8aa4 36 if(displayproto==PAR_8) proto = new PAR8(port, CS, reset, DC, WR, RD);
Geremia 1:ff019d22b275 37 useNOP=false;
Geremia 7:bb0383b91104 38 buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES);
Geremia 1:ff019d22b275 39 buffer16 = (unsigned short*)buffer;
Geremia 0:75ec1b3cde17 40 draw_mode = NORMAL;
Geremia 0:75ec1b3cde17 41 set_orientation(1);
Geremia 4:12ba0ecc2c1f 42 foreground(White);
Geremia 4:12ba0ecc2c1f 43 background(Black);
Geremia 2:713844a55c4e 44 set_auto_up(true);
Geremia 7:bb0383b91104 45 tftID=0;
Geremia 0:75ec1b3cde17 46 // cls();
Geremia 0:75ec1b3cde17 47 // locate(0,0);
Geremia 0:75ec1b3cde17 48 }
dreschpe 27:acb2594b8aa4 49 #endif
dreschpe 27:acb2594b8aa4 50
Geremia 21:ae0a4eedfc90 51 LCD::LCD(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char *name)
Geremia 21:ae0a4eedfc90 52 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y), _LCDPAGES(lcdsize_y>>3), _IC_X_SEGS(ic_x_segs), _IC_Y_COMS(ic_y_coms), _IC_PAGES(ic_y_coms>>3)
Geremia 21:ae0a4eedfc90 53 {
Geremia 21:ae0a4eedfc90 54 if(displayproto==BUS_8)
Geremia 21:ae0a4eedfc90 55 {
Geremia 21:ae0a4eedfc90 56 PinName pins[16];
Geremia 21:ae0a4eedfc90 57 for(int i=0; i<16; i++) pins[i]=NC;
Geremia 21:ae0a4eedfc90 58 for(int i=0; i<8; i++) pins[i]=buspins[i];
Geremia 21:ae0a4eedfc90 59 proto = new BUS8(pins, CS, reset, DC, WR, RD);
Geremia 21:ae0a4eedfc90 60 }
Geremia 21:ae0a4eedfc90 61 useNOP=false;
Geremia 21:ae0a4eedfc90 62 buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES);
Geremia 21:ae0a4eedfc90 63 buffer16 = (unsigned short*)buffer;
Geremia 21:ae0a4eedfc90 64 draw_mode = NORMAL;
Geremia 21:ae0a4eedfc90 65 set_orientation(1);
Geremia 21:ae0a4eedfc90 66 foreground(White);
Geremia 21:ae0a4eedfc90 67 background(Black);
Geremia 21:ae0a4eedfc90 68 set_auto_up(true);
Geremia 21:ae0a4eedfc90 69 tftID=0;
Geremia 21:ae0a4eedfc90 70 // cls();
Geremia 21:ae0a4eedfc90 71 // locate(0,0);
Geremia 21:ae0a4eedfc90 72 }
Geremia 1:ff019d22b275 73 LCD::LCD(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char *name)
Geremia 7:bb0383b91104 74 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y), _LCDPAGES(lcdsize_y>>3), _IC_X_SEGS(ic_x_segs), _IC_Y_COMS(ic_y_coms), _IC_PAGES(ic_y_coms>>3)
Geremia 0:75ec1b3cde17 75 {
Geremia 1:ff019d22b275 76 if(displayproto==SPI_8)
Geremia 1:ff019d22b275 77 {
Geremia 1:ff019d22b275 78 proto = new SPI8(Hz, mosi, miso, sclk, CS, reset, DC);
Geremia 1:ff019d22b275 79 useNOP=false;
Geremia 1:ff019d22b275 80 }
Geremia 1:ff019d22b275 81 else if(displayproto==SPI_16)
Geremia 1:ff019d22b275 82 {
Geremia 1:ff019d22b275 83 proto = new SPI16(Hz, mosi, miso, sclk, CS, reset, DC);
Geremia 1:ff019d22b275 84 useNOP=true;
Geremia 1:ff019d22b275 85 }
Geremia 7:bb0383b91104 86 buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES);
Geremia 1:ff019d22b275 87 buffer16 = (unsigned short*)buffer;
Geremia 0:75ec1b3cde17 88 draw_mode = NORMAL;
Geremia 0:75ec1b3cde17 89 // cls();
Geremia 0:75ec1b3cde17 90 set_orientation(1);
Geremia 4:12ba0ecc2c1f 91 foreground(White);
Geremia 4:12ba0ecc2c1f 92 background(Black);
Geremia 2:713844a55c4e 93 set_auto_up(true);
Geremia 7:bb0383b91104 94 tftID=0;
Geremia 0:75ec1b3cde17 95 // locate(0,0);
Geremia 1:ff019d22b275 96
Geremia 0:75ec1b3cde17 97 }
dreschpe 33:f87f06292637 98 LCD::LCD(proto_t displayproto, int Hz, int address, PinName sda, PinName scl, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name)
dreschpe 33:f87f06292637 99 : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y), _LCDPAGES(lcdsize_y>>3), _IC_X_SEGS(ic_x_segs), _IC_Y_COMS(ic_y_coms), _IC_PAGES(ic_y_coms>>3)
dreschpe 33:f87f06292637 100 {
dreschpe 33:f87f06292637 101 if(displayproto==I2C_){
dreschpe 33:f87f06292637 102 proto = new I2C_bus(Hz,address,sda,scl);
dreschpe 33:f87f06292637 103 useNOP=false;
dreschpe 33:f87f06292637 104 }
dreschpe 33:f87f06292637 105 buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES);
dreschpe 33:f87f06292637 106 buffer16 = (unsigned short*)buffer;
dreschpe 33:f87f06292637 107 draw_mode = NORMAL;
dreschpe 33:f87f06292637 108 // cls();
dreschpe 33:f87f06292637 109 set_orientation(1);
dreschpe 33:f87f06292637 110 foreground(White);
dreschpe 33:f87f06292637 111 background(Black);
dreschpe 33:f87f06292637 112 set_auto_up(true);
dreschpe 33:f87f06292637 113 tftID=0;
dreschpe 33:f87f06292637 114 }
dreschpe 33:f87f06292637 115
Geremia 0:75ec1b3cde17 116 LCD::~LCD()
Geremia 0:75ec1b3cde17 117 {
Geremia 0:75ec1b3cde17 118 free(buffer);
Geremia 0:75ec1b3cde17 119 }
Geremia 0:75ec1b3cde17 120
Geremia 1:ff019d22b275 121 void LCD::wr_cmd8(unsigned char cmd)
Geremia 0:75ec1b3cde17 122 {
Geremia 2:713844a55c4e 123 if(useNOP) proto->wr_cmd16(0xE300|cmd); // E3 is NOP cmd for LCD
Geremia 1:ff019d22b275 124 else proto->wr_cmd8(cmd);
Geremia 0:75ec1b3cde17 125 }
Geremia 1:ff019d22b275 126 void LCD::wr_data8(unsigned char data)
Geremia 0:75ec1b3cde17 127 {
Geremia 1:ff019d22b275 128 proto->wr_data8(data);
Geremia 1:ff019d22b275 129 }
Geremia 1:ff019d22b275 130 void LCD::wr_cmd16(unsigned short cmd)
Geremia 1:ff019d22b275 131 {
Geremia 1:ff019d22b275 132 proto->wr_cmd16(cmd);
Geremia 0:75ec1b3cde17 133 }
Geremia 4:12ba0ecc2c1f 134 void LCD::wr_gram(unsigned short data, unsigned int count)
Geremia 0:75ec1b3cde17 135 {
Geremia 4:12ba0ecc2c1f 136 proto->wr_gram(data, count);
Geremia 1:ff019d22b275 137 }
Geremia 4:12ba0ecc2c1f 138 void LCD::wr_grambuf(unsigned short* data, unsigned int lenght)
Geremia 1:ff019d22b275 139 {
Geremia 4:12ba0ecc2c1f 140 proto->wr_grambuf(data, lenght);
Geremia 0:75ec1b3cde17 141 }
Geremia 0:75ec1b3cde17 142 void LCD::hw_reset()
Geremia 0:75ec1b3cde17 143 {
Geremia 0:75ec1b3cde17 144 proto->hw_reset();
Geremia 0:75ec1b3cde17 145 }
Geremia 0:75ec1b3cde17 146 void LCD::BusEnable(bool enable)
Geremia 0:75ec1b3cde17 147 {
Geremia 0:75ec1b3cde17 148 proto->BusEnable(enable);
Geremia 0:75ec1b3cde17 149 }
Geremia 0:75ec1b3cde17 150
Geremia 0:75ec1b3cde17 151
Geremia 0:75ec1b3cde17 152
Geremia 0:75ec1b3cde17 153 // monochrome LCD driver ICs does not have ram rotate in hw (swap raw<->columns) like TFT displays
Geremia 0:75ec1b3cde17 154 // for portrait views, XY swap will be done in sw in pixel() function
Geremia 0:75ec1b3cde17 155 void LCD::set_orientation(int o)
Geremia 0:75ec1b3cde17 156 {
Geremia 0:75ec1b3cde17 157 orientation = o;
Geremia 0:75ec1b3cde17 158 switch (o) {
Geremia 0:75ec1b3cde17 159 case (0):// portrait view -90°
Geremia 0:75ec1b3cde17 160 mirrorXY(Y);
Geremia 0:75ec1b3cde17 161 col_offset = 0;
Geremia 7:bb0383b91104 162 page_offset = _IC_PAGES-_LCDPAGES;
Geremia 7:bb0383b91104 163 set_width(screensize_Y);
Geremia 7:bb0383b91104 164 set_height(screensize_X);
Geremia 0:75ec1b3cde17 165 // portrait = true;
Geremia 0:75ec1b3cde17 166 break;
Geremia 0:75ec1b3cde17 167 case (1): // default, landscape view 0°
Geremia 0:75ec1b3cde17 168 mirrorXY(NONE);
Geremia 0:75ec1b3cde17 169 col_offset = 0;
Geremia 0:75ec1b3cde17 170 page_offset = 0;
Geremia 7:bb0383b91104 171 set_width(screensize_X);
Geremia 7:bb0383b91104 172 set_height(screensize_Y);
Geremia 0:75ec1b3cde17 173 // portrait = false;
Geremia 0:75ec1b3cde17 174 break;
Geremia 0:75ec1b3cde17 175 case (2):// portrait view +90°
Geremia 0:75ec1b3cde17 176 mirrorXY(X);
Geremia 7:bb0383b91104 177 col_offset = _IC_X_SEGS-screensize_X; // some displays have less pixels than IC ram
Geremia 0:75ec1b3cde17 178 page_offset = 0;
Geremia 7:bb0383b91104 179 set_width(screensize_Y);
Geremia 7:bb0383b91104 180 set_height(screensize_X);
Geremia 0:75ec1b3cde17 181 // portrait = true;
Geremia 0:75ec1b3cde17 182 break;
Geremia 0:75ec1b3cde17 183 case (3):// landscape view +180°
Geremia 0:75ec1b3cde17 184 mirrorXY(XY);
Geremia 7:bb0383b91104 185 col_offset = _IC_X_SEGS-screensize_X;
Geremia 7:bb0383b91104 186 page_offset = _IC_PAGES-_LCDPAGES;
Geremia 7:bb0383b91104 187 set_width(screensize_X);
Geremia 7:bb0383b91104 188 set_height(screensize_Y);
Geremia 0:75ec1b3cde17 189 // portrait = false;
Geremia 0:75ec1b3cde17 190 break;
Geremia 0:75ec1b3cde17 191 }
Geremia 0:75ec1b3cde17 192 }
Geremia 0:75ec1b3cde17 193 void LCD::mirrorXY(mirror_t mode)
Geremia 0:75ec1b3cde17 194 {
Geremia 0:75ec1b3cde17 195 switch (mode)
Geremia 0:75ec1b3cde17 196 {
Geremia 0:75ec1b3cde17 197 case(NONE):
Geremia 1:ff019d22b275 198 // wr_cmd8(0xA0);
Geremia 1:ff019d22b275 199 wr_cmd16(0xA0C8); // this is in real Y mirror command, but seems most displays have COMs wired inverted, so assume this is the default no-y-mirror
Geremia 0:75ec1b3cde17 200 break;
Geremia 0:75ec1b3cde17 201 case(X):
Geremia 1:ff019d22b275 202 // wr_cmd8(0xA1);
Geremia 1:ff019d22b275 203 wr_cmd16(0xA1C8);
Geremia 0:75ec1b3cde17 204 break;
Geremia 0:75ec1b3cde17 205 case(Y):
Geremia 1:ff019d22b275 206 // wr_cmd8(0xA0);
Geremia 1:ff019d22b275 207 wr_cmd16(0xA0C0);
Geremia 0:75ec1b3cde17 208 break;
Geremia 0:75ec1b3cde17 209 case(XY):
Geremia 1:ff019d22b275 210 // wr_cmd8(0xA1);
Geremia 1:ff019d22b275 211 wr_cmd16(0xA1C0);
Geremia 0:75ec1b3cde17 212 break;
Geremia 0:75ec1b3cde17 213 }
Geremia 0:75ec1b3cde17 214 }
Geremia 0:75ec1b3cde17 215 void LCD::invert(unsigned char o)
Geremia 0:75ec1b3cde17 216 {
Geremia 1:ff019d22b275 217 if(o == 0) wr_cmd8(0xA6);
Geremia 1:ff019d22b275 218 else wr_cmd8(0xA7);
Geremia 0:75ec1b3cde17 219 }
Geremia 0:75ec1b3cde17 220
Geremia 0:75ec1b3cde17 221 void LCD::set_contrast(int o)
Geremia 0:75ec1b3cde17 222 {
Geremia 0:75ec1b3cde17 223 contrast = o;
Geremia 1:ff019d22b275 224 // wr_cmd8(0x81); // set volume
Geremia 1:ff019d22b275 225 wr_cmd16(0x8100|(o&0x3F));
Geremia 0:75ec1b3cde17 226 }
Geremia 2:713844a55c4e 227
Geremia 0:75ec1b3cde17 228 int LCD::get_contrast(void)
Geremia 0:75ec1b3cde17 229 {
Geremia 0:75ec1b3cde17 230 return(contrast);
Geremia 0:75ec1b3cde17 231 }
Geremia 0:75ec1b3cde17 232 void LCD::window(int x, int y, int w, int h) {
Geremia 0:75ec1b3cde17 233 // current pixel location
Geremia 0:75ec1b3cde17 234 cur_x = x;
Geremia 0:75ec1b3cde17 235 cur_y = y;
Geremia 0:75ec1b3cde17 236 // window settings
Geremia 0:75ec1b3cde17 237 win_x1 = x;
Geremia 0:75ec1b3cde17 238 win_x2 = x + w - 1;
Geremia 0:75ec1b3cde17 239 win_y1 = y;
Geremia 0:75ec1b3cde17 240 win_y2 = y + h - 1;
Geremia 0:75ec1b3cde17 241 }
Geremia 0:75ec1b3cde17 242 void LCD::window_pushpixel(unsigned short color) {
Geremia 0:75ec1b3cde17 243 pixel(cur_x, cur_y, color);
Geremia 0:75ec1b3cde17 244 cur_x++;
Geremia 0:75ec1b3cde17 245 if(cur_x > win_x2) {
Geremia 0:75ec1b3cde17 246 cur_x = win_x1;
Geremia 0:75ec1b3cde17 247 cur_y++;
Geremia 0:75ec1b3cde17 248 if(cur_y > win_y2) {
Geremia 0:75ec1b3cde17 249 cur_y = win_y1;
Geremia 0:75ec1b3cde17 250 }
Geremia 0:75ec1b3cde17 251 }
Geremia 0:75ec1b3cde17 252 }
Geremia 2:713844a55c4e 253 void LCD::window_pushpixel(unsigned short color, unsigned int count) {
Geremia 2:713844a55c4e 254 while(count)
Geremia 2:713844a55c4e 255 {
Geremia 2:713844a55c4e 256 pixel(cur_x, cur_y, color);
Geremia 2:713844a55c4e 257 cur_x++;
Geremia 2:713844a55c4e 258 if(cur_x > win_x2)
Geremia 2:713844a55c4e 259 {
Geremia 2:713844a55c4e 260 cur_x = win_x1;
Geremia 2:713844a55c4e 261 cur_y++;
Geremia 2:713844a55c4e 262 if(cur_y > win_y2)
Geremia 2:713844a55c4e 263 {
Geremia 2:713844a55c4e 264 cur_y = win_y1;
Geremia 2:713844a55c4e 265 }
Geremia 2:713844a55c4e 266 }
Geremia 2:713844a55c4e 267 count--;
Geremia 2:713844a55c4e 268 }
Geremia 2:713844a55c4e 269 }
Geremia 2:713844a55c4e 270 void LCD::window_pushpixelbuf(unsigned short* color, unsigned int lenght) {
Geremia 2:713844a55c4e 271 while(lenght)
Geremia 2:713844a55c4e 272 {
Geremia 2:713844a55c4e 273 pixel(cur_x, cur_y, *color++);
Geremia 2:713844a55c4e 274 cur_x++;
Geremia 2:713844a55c4e 275 if(cur_x > win_x2)
Geremia 2:713844a55c4e 276 {
Geremia 2:713844a55c4e 277 cur_x = win_x1;
Geremia 2:713844a55c4e 278 cur_y++;
Geremia 2:713844a55c4e 279 if(cur_y > win_y2)
Geremia 2:713844a55c4e 280 {
Geremia 2:713844a55c4e 281 cur_y = win_y1;
Geremia 2:713844a55c4e 282 }
Geremia 2:713844a55c4e 283 }
Geremia 2:713844a55c4e 284 lenght--;
Geremia 2:713844a55c4e 285 }
Geremia 2:713844a55c4e 286 }
Geremia 0:75ec1b3cde17 287 void LCD::pixel(int x, int y, unsigned short color)
Geremia 0:75ec1b3cde17 288 {
Geremia 0:75ec1b3cde17 289 if(!(orientation&1)) SWAP(x,y);
Geremia 0:75ec1b3cde17 290 // first check parameter
Geremia 7:bb0383b91104 291 if((x >= screensize_X) || (y >= screensize_Y)) return;
Geremia 0:75ec1b3cde17 292
Geremia 20:14daa48ffd4c 293 if(color) buffer[(x + ((y>>3)*screensize_X))^1] &= ~(1 << (y&7)); // erase pixel
Geremia 20:14daa48ffd4c 294 else buffer[(x + ((y>>3)*screensize_X))^1] |= (1 << (y&7)); //Black=0000, set pixel
Geremia 20:14daa48ffd4c 295 }
Geremia 20:14daa48ffd4c 296 unsigned short LCD::pixelread(int x, int y)
Geremia 20:14daa48ffd4c 297 {
Geremia 20:14daa48ffd4c 298 if(!(orientation&1)) SWAP(x,y);
Geremia 20:14daa48ffd4c 299 // first check parameter
Geremia 20:14daa48ffd4c 300 if((x >= screensize_X) || (y >= screensize_Y)) return 0;
Geremia 20:14daa48ffd4c 301
Geremia 20:14daa48ffd4c 302 if((buffer[(x + ((y>>3)*screensize_X))^1] & (1 << (y&7)))==0) return 0xFFFF ; // pixel not set, White
Geremia 20:14daa48ffd4c 303 else return 0; // pixel set, Black
Geremia 0:75ec1b3cde17 304 }
Geremia 0:75ec1b3cde17 305 void LCD::copy_to_lcd(void)
Geremia 0:75ec1b3cde17 306 {
Geremia 0:75ec1b3cde17 307 unsigned short i=0;
Geremia 1:ff019d22b275 308 unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4);
Geremia 7:bb0383b91104 309 for(int page=0; page<_LCDPAGES; page++)
Geremia 0:75ec1b3cde17 310 {
Geremia 1:ff019d22b275 311 // wr_cmd8(col_offset&0xF); // set column low nibble
Geremia 1:ff019d22b275 312 // wr_cmd8(0x10|(col_offset>>4)); // set column hi nibble
Geremia 1:ff019d22b275 313 wr_cmd16(setcolcmd);
Geremia 1:ff019d22b275 314 wr_cmd8(0xB0|(page+page_offset)); // set page
Geremia 7:bb0383b91104 315 wr_grambuf(buffer16+i, screensize_X>>1); // send whole page pixels
Geremia 7:bb0383b91104 316 i+=screensize_X>>1;
Geremia 0:75ec1b3cde17 317 }
Geremia 0:75ec1b3cde17 318 }
Geremia 0:75ec1b3cde17 319 void LCD::cls(void)
Geremia 0:75ec1b3cde17 320 {
Geremia 4:12ba0ecc2c1f 321 unsigned short tmp = _background^0xFFFF;
Geremia 7:bb0383b91104 322 memset(buffer,tmp,screensize_X*_LCDPAGES); // clear display buffer
Geremia 1:ff019d22b275 323 unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4);
Geremia 7:bb0383b91104 324 for(int page=0; page<_LCDPAGES; page++)
Geremia 0:75ec1b3cde17 325 {
Geremia 1:ff019d22b275 326 // wr_cmd8((unsigned char)col_offset&0xF); // set column low nibble
Geremia 1:ff019d22b275 327 // wr_cmd8(0x10|(col_offset>>4)); // set column hi nibble
Geremia 1:ff019d22b275 328 wr_cmd16(setcolcmd);
Geremia 1:ff019d22b275 329 wr_cmd8(0xB0|(page+page_offset)); // set page
Geremia 18:ffa58f1a680a 330 wr_gram(tmp, screensize_X>>1); // send whole page pixels = background
Geremia 0:75ec1b3cde17 331 }
Geremia 7:bb0383b91104 332 }
Geremia 7:bb0383b91104 333 int LCD::sizeX()
Geremia 7:bb0383b91104 334 {
Geremia 7:bb0383b91104 335 return screensize_X;
Geremia 7:bb0383b91104 336 }
Geremia 7:bb0383b91104 337 int LCD::sizeY()
Geremia 7:bb0383b91104 338 {
Geremia 7:bb0383b91104 339 return screensize_Y;
Geremia 0:75ec1b3cde17 340 }