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.

Files at this revision

API Documentation at this revision

Comitter:
Anaesthetix
Date:
Mon Dec 19 23:26:17 2016 +0000
Parent:
4:8da4c691643a
Commit message:
Added basic drawing functions + buffered versions. More will come soon. Has a minor bug with postioning

Changed in this revision

UC1701.cpp Show annotated file Show diff for this revision Revisions of this file
UC1701.h Show annotated file Show diff for this revision Revisions of this file
--- 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
--- a/UC1701.h	Mon Dec 19 14:36:19 2016 +0000
+++ b/UC1701.h	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!
  */
 
@@ -62,6 +62,32 @@
 
     // Draw a 128x64 pixel bitmap
     void drawBitmap(const char *data);
+    
+    // Draw a horizontal line, start positions / height / width in pixels
+    void drawLineHor(char posx, char posy, char height, char width);
+    
+    // Draw a vertical line, start positions / height / width in pixels
+    void drawLineVert(char posx, char posy, char height, char width);
+    
+    //-----------------------------------------------------------------------------------------------------------------------------
+    // Functions below are buffered versions; possible to write things on top of each other without clearing pixels (ORs all data).
+    // Use update() to write buffer to LCD.
+    // Clear buffer before writing 1st time (initialize all values)
+    // writetext / drawbitmap will be added soon
+    //-----------------------------------------------------------------------------------------------------------------------------
+    
+    // Clear buffer
+    void clearBuffer(void);
+    
+    // Write buffer to LCD
+    void update(void);
+    
+    // Draw a horizontal line, start positions / height / width in pixels. Buffered version; possible to write things on top of each other
+    // without clearing pixels (ORs all data). Use update() to write buffer to LCD
+    void drawbufferLineHor(char posx, char posy, char height, char width);
+    
+    // Draw a vertical line, start positions / height / width in pixels. Buffered version.
+    void drawbufferLineVert(char posx, char posy, char height, char width);
 
 private:
 
@@ -69,6 +95,7 @@
     DigitalOut  *_lcd_cs;
     DigitalOut  *_lcd_cd;
     uint8_t     _lcdbuffer[LCDWIDTH*LCDPAGES];
+    char        buff[LCDWIDTH*LCDPAGES];
 
 };