Simple library for UC1701 based GLCD's

Dependents:   Opensmart_LCD_UC1701

With lots of fonts! Will include more in the future. A couple bitmaps have also been added.

Revision:
5:7494bdca926b
Parent:
4:8da4c691643a
--- a/UC1701.cpp	Mon Dec 19 14:36:19 2016 +0000
+++ b/UC1701.cpp	Mon Dec 19 23:26:17 2016 +0000
@@ -4,7 +4,7 @@
  * See      http://www.dx.com/p/open-smart-1-8-128-64-lcd-display-breakout-module-w-blue-backlit-444694
  *
  * Written by:  Erik van de Coevering
- * With special thanks to Tim Barr from whom I've reused some code
+ * With thanks to Tim Barr from whom I've reused some code
  * Use this code in whatever way you like, as long as it stays free of charge!
  */
 
@@ -198,4 +198,131 @@
             cnt++;
         }
     }
+}
+
+void UC1701::drawLineHor(char posx, char posy, char height, char width)
+{
+    char page, offset, offset2;
+    char buffer[2] = {0xFF, 0xFF};
+
+    _lcd_cs->write(0);
+    _lcd_cd->write(1);
+
+    if(width+posx > LCDWIDTH) width = (LCDWIDTH-posx); // keep inside display area
+
+    page = posy/8;
+    offset = posy - (page*8);
+    buffer[0] = buffer[0] >> (8-height);
+    buffer[0] = buffer[0] << offset;
+
+    if((offset + height) > 8) {
+        offset2 = ((offset+height)-8);
+        buffer[1] = buffer[1] - (0xFF << (offset2));
+    }
+
+    UC1701::setCursor(posx, page);
+
+    for(int i=0; i<width; i++) _lcd->write(buffer[0]);
+
+    if(buffer[1] != 0xFF && (page+1) < 8) {         // only write if line takes up > 1 page & keep inside display area
+        UC1701::setCursor(posx, (page+1));
+        for(int i=0; i<width; i++) _lcd->write(buffer[1]);
+    }
+    _lcd_cs->write(1);
+}
+
+void UC1701::drawLineVert(char posx, char posy, char height, char width)
+{
+    char page, pagecount, offset, offset2;
+    
+    _lcd_cs->write(0);
+    _lcd_cd->write(1);
+
+    page = posy/8;
+    pagecount = height/8;
+    offset2 = height - (pagecount*8);
+
+    UC1701::setCursor(posx, page);
+    for(int i=0; i<width; i++) _lcd->write((0xFF>>offset));
+
+    for(; pagecount > 1; pagecount--) {
+        page++;
+        UC1701::setCursor(posx, page);
+        for(int i=0; i<width; i++) _lcd->write(0xFF);
+    }
+
+    UC1701::setCursor(posx, (page+1));
+    for(int i=0; i<width; i++) _lcd->write((0xFF<<offset2));
+
+    _lcd_cs->write(1);
+}
+
+void UC1701::clearBuffer(void)
+{
+    for(int i=0; i<(LCDWIDTH*LCDPAGES); i++) buff[i] = 0;
+}
+
+void UC1701::update(void)
+{
+    int cnt = 0;
+    _lcd_cs->write(0);
+    _lcd_cd->write(1);
+    UC1701::setCursor(0,0);
+    for(int row=0; row<8; row++) {
+        UC1701::setCursor(0, row);
+        for(int column=0; column<128; column++) {
+            _lcd->write(buff[cnt]);
+            cnt++;
+        }
+    }
+    _lcd_cs->write(1);
+}
+
+void UC1701::drawbufferLineHor(char posx, char posy, char height, char width)
+{
+    char page, offset, offset2;
+    int cursor;
+    char buffer[2] = {0xFF, 0xFF};
+
+    if(width+posx > LCDWIDTH) width = (LCDWIDTH-posx); // keep inside display area
+
+    page = posy/8;
+    offset = posy - (page*8);
+    buffer[0] = buffer[0] >> (8-height);
+    buffer[0] = buffer[0] << offset;
+
+    if((offset + height) > 8) {
+        offset2 = ((offset+height)-8);
+        buffer[1] = buffer[1] - (0xFF << (offset2));
+    }
+
+    cursor = posx + (page*128);
+
+    for(int i=0; i<width; i++) UC1701::buff[cursor+i] |= buffer[0];
+
+    if(buffer[1] != 0xFF && (page+1) < 8) {         // only write if line takes up > 1 page & keep inside display area
+        for(int i=0; i<width; i++) UC1701::buff[cursor+i+128] |= buffer[1];
+    }
+}
+
+void UC1701::drawbufferLineVert(char posx, char posy, char height, char width)
+{
+    char page, pagecount, offset, offset2;
+    int cursor;
+
+    page = posy/8;
+    pagecount = height/8;
+    offset2 = height - (pagecount*8);
+    cursor = posx + (page*128); // LCDWIDTH
+
+    for(int i=0; i<width; i++) UC1701::buff[cursor+i] |= (0xFF>>offset);
+
+    for(; pagecount > 1; pagecount--) {
+        page++;
+        cursor += 128;
+        for(int i=0; i<width; i++) UC1701::buff[cursor+i] |= 0xFF;
+    }
+
+    cursor += 128;
+    for(int i=0; i<width; i++) UC1701::buff[cursor+i] |= (0xFF >> offset2);
 }
\ No newline at end of file