ePaper display for ACD52832 Dev board

Dependents:   acd52832_LSM9DS1 BB

Files at this revision

API Documentation at this revision

Comitter:
Anunnaki
Date:
Thu Sep 15 12:12:34 2016 +0000
Parent:
2:1c8f73aa2a16
Commit message:
Added most of the functions and tested their functionality.

Changed in this revision

5x7.h Show annotated file Show diff for this revision Revisions of this file
GDEP015OC1.cpp Show annotated file Show diff for this revision Revisions of this file
GDEP015OC1.h Show annotated file Show diff for this revision Revisions of this file
diff -r 1c8f73aa2a16 -r dc7b794b59b7 5x7.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/5x7.h	Thu Sep 15 12:12:34 2016 +0000
@@ -0,0 +1,96 @@
+// standard ascii 5x7 font
+// defines ascii characters 0x20-0x7F (32-127)
+
+const unsigned char Font5x7[] = {
+    0x00, 0x00, 0x00, 0x00, 0x00,// (space)
+    0x00, 0x00, 0x5F, 0x00, 0x00,// !
+    0x00, 0x07, 0x00, 0x07, 0x00,// "
+    0x14, 0x7F, 0x14, 0x7F, 0x14,// #
+    0x24, 0x2A, 0x7F, 0x2A, 0x12,// $
+    0x23, 0x13, 0x08, 0x64, 0x62,// %
+    0x36, 0x49, 0x55, 0x22, 0x50,// &
+    0x00, 0x05, 0x03, 0x00, 0x00,// '
+    0x00, 0x1C, 0x22, 0x41, 0x00,// (
+    0x00, 0x41, 0x22, 0x1C, 0x00,// )
+    0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
+    0x08, 0x08, 0x3E, 0x08, 0x08,// +
+    0x00, 0x50, 0x30, 0x00, 0x00,// ,
+    0x08, 0x08, 0x08, 0x08, 0x08,// -
+    0x00, 0x60, 0x60, 0x00, 0x00,// .
+    0x20, 0x10, 0x08, 0x04, 0x02,// /
+    0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
+    0x00, 0x42, 0x7F, 0x40, 0x00,// 1
+    0x42, 0x61, 0x51, 0x49, 0x46,// 2
+    0x21, 0x41, 0x45, 0x4B, 0x31,// 3
+    0x18, 0x14, 0x12, 0x7F, 0x10,// 4
+    0x27, 0x45, 0x45, 0x45, 0x39,// 5
+    0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
+    0x01, 0x71, 0x09, 0x05, 0x03,// 7
+    0x36, 0x49, 0x49, 0x49, 0x36,// 8
+    0x06, 0x49, 0x49, 0x29, 0x1E,// 9
+    0x00, 0x36, 0x36, 0x00, 0x00,// :
+    0x00, 0x56, 0x36, 0x00, 0x00,// ;
+    0x00, 0x08, 0x14, 0x22, 0x41,// <
+    0x14, 0x14, 0x14, 0x14, 0x14,// =
+    0x41, 0x22, 0x14, 0x08, 0x00,// >
+    0x02, 0x01, 0x51, 0x09, 0x06,// ?
+    0x32, 0x49, 0x79, 0x41, 0x3E,// @
+    0x7E, 0x11, 0x11, 0x11, 0x7E,// A
+    0x7F, 0x49, 0x49, 0x49, 0x36,// B
+    0x3E, 0x41, 0x41, 0x41, 0x22,// C
+    0x7F, 0x41, 0x41, 0x22, 0x1C,// D
+    0x7F, 0x49, 0x49, 0x49, 0x41,// E
+    0x7F, 0x09, 0x09, 0x01, 0x01,// F
+    0x3E, 0x41, 0x41, 0x51, 0x32,// G
+    0x7F, 0x08, 0x08, 0x08, 0x7F,// H
+    0x00, 0x41, 0x7F, 0x41, 0x00,// I
+    0x20, 0x40, 0x41, 0x3F, 0x01,// J
+    0x7F, 0x08, 0x14, 0x22, 0x41,// K
+    0x7F, 0x40, 0x40, 0x40, 0x40,// L
+    0x7F, 0x02, 0x04, 0x02, 0x7F,// M
+    0x7F, 0x04, 0x08, 0x10, 0x7F,// N
+    0x3E, 0x41, 0x41, 0x41, 0x3E,// O
+    0x7F, 0x09, 0x09, 0x09, 0x06,// P
+    0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
+    0x7F, 0x09, 0x19, 0x29, 0x46,// R
+    0x46, 0x49, 0x49, 0x49, 0x31,// S
+    0x01, 0x01, 0x7F, 0x01, 0x01,// T
+    0x3F, 0x40, 0x40, 0x40, 0x3F,// U
+    0x1F, 0x20, 0x40, 0x20, 0x1F,// V
+    0x7F, 0x20, 0x18, 0x20, 0x7F,// W
+    0x63, 0x14, 0x08, 0x14, 0x63,// X
+    0x03, 0x04, 0x78, 0x04, 0x03,// Y
+    0x61, 0x51, 0x49, 0x45, 0x43,// Z
+    0x00, 0x00, 0x7F, 0x41, 0x41,// [
+    0x02, 0x04, 0x08, 0x10, 0x20,// "\"
+    0x41, 0x41, 0x7F, 0x00, 0x00,// ]
+    0x04, 0x02, 0x01, 0x02, 0x04,// ^
+    0x40, 0x40, 0x40, 0x40, 0x40,// _
+    0x00, 0x01, 0x02, 0x04, 0x00,// `
+    0x20, 0x54, 0x54, 0x54, 0x78,// a
+    0x7F, 0x48, 0x44, 0x44, 0x38,// b
+    0x38, 0x44, 0x44, 0x44, 0x20,// c
+    0x38, 0x44, 0x44, 0x48, 0x7F,// d
+    0x38, 0x54, 0x54, 0x54, 0x18,// e
+    0x08, 0x7E, 0x09, 0x01, 0x02,// f
+    0x08, 0x14, 0x54, 0x54, 0x3C,// g
+    0x7F, 0x08, 0x04, 0x04, 0x78,// h
+    0x00, 0x44, 0x7D, 0x40, 0x00,// i
+    0x20, 0x40, 0x44, 0x3D, 0x00,// j
+    0x00, 0x7F, 0x10, 0x28, 0x44,// k
+    0x00, 0x41, 0x7F, 0x40, 0x00,// l
+    0x7C, 0x04, 0x18, 0x04, 0x78,// m
+    0x7C, 0x08, 0x04, 0x04, 0x78,// n
+    0x38, 0x44, 0x44, 0x44, 0x38,// o
+    0x7C, 0x14, 0x14, 0x14, 0x08,// p
+    0x08, 0x14, 0x14, 0x18, 0x7C,// q
+    0x7C, 0x08, 0x04, 0x04, 0x08,// r
+    0x48, 0x54, 0x54, 0x54, 0x20,// s
+    0x04, 0x3F, 0x44, 0x40, 0x20,// t
+    0x3C, 0x40, 0x40, 0x20, 0x7C,// u
+    0x1C, 0x20, 0x40, 0x20, 0x1C,// v
+    0x3C, 0x40, 0x30, 0x40, 0x3C,// w
+    0x44, 0x28, 0x10, 0x28, 0x44,// x
+    0x0C, 0x50, 0x50, 0x50, 0x3C,// y
+    0x44, 0x64, 0x54, 0x4C, 0x44,// z
+};
diff -r 1c8f73aa2a16 -r dc7b794b59b7 GDEP015OC1.cpp
--- a/GDEP015OC1.cpp	Thu Sep 15 09:19:30 2016 +0000
+++ b/GDEP015OC1.cpp	Thu Sep 15 12:12:34 2016 +0000
@@ -1,5 +1,9 @@
+/**
+ *  Created by Filip Hormot (f.hormot@gmail.com) on 14/09/16.
+ */
 #include "mbed.h"
 #include "GDEP015OC1.h"
+#include "5x7.h"
 
 static const unsigned char _lutFull[] = { 
     0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 
@@ -7,6 +11,7 @@
 };
 
 GDEP015OC1::GDEP015OC1(SPI& spi, PinName cs=p5, PinName dc=p6, PinName rst=p7, PinName busy=p8) : _spi(spi), _cs(cs), _dc(dc), _rst(rst), _busy(busy){
+    _bold = _italic = false;
     _init();
 }
 
@@ -27,7 +32,7 @@
 
 void GDEP015OC1::_init(void){
     _rst = _cs = 1;
-    //empty();    
+    empty();    
 }
 
 void GDEP015OC1::_wakeUp(void){
@@ -130,7 +135,7 @@
     for(uint8_t x = 0; x < 8; x++){
         pix |= ((*(data + (i*200)%5000 + (24-i/200) + x*25)>>((i/25)%8))&(0x01))<<(7-x);
     }
-    return pix;    
+    return pix^0xFF;    
 }
 
 uint8_t GDEP015OC1::_mirrorData(uint8_t data){
@@ -194,4 +199,127 @@
         if (e2 >-dx) { err -= dy; startX += sx; }
         if (e2 < dy) { err += dx; startY += sy; }
     }
+}
+
+void GDEP015OC1::drawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, bool color=0){
+    drawLine(x1, y1, x2, y2, color);
+    drawLine(x2, y2, x3, y3, color);
+    drawLine(x3, y3, x1, y1, color);      
+}
+
+void GDEP015OC1::drawRectangle(uint16_t startX, uint16_t startY, uint16_t stopX, uint16_t stopY, bool color=0){
+    drawLine(startX, startY, stopX,  startY, color);
+    drawLine(stopX,  startY, stopX,  stopY,  color);
+    drawLine(stopX,  stopY,  startX, stopY,  color);
+    drawLine(startX, stopY,  startX, startY, color);    
+}
+
+void GDEP015OC1::drawCircle(uint16_t startX, uint16_t startY, uint16_t radius, bool color=0){
+    int d,x,y;
+
+    d=3-2*radius;
+    x=0;
+    y=radius;
+    while(x<=y){
+        drawPixel(startX+x,startY+y,color);
+        drawPixel(startX-y,startY-x,color);
+        drawPixel(startX+y,startY-x,color);
+        drawPixel(startX-y,startY+x,color);
+        drawPixel(startX+y,startY+x,color);
+        drawPixel(startX-x,startY-y,color);
+        drawPixel(startX+x,startY-y,color);
+        drawPixel(startX-x,startY+y,color);
+
+        if(d<=0)
+            d=d+4*x+6;
+        else{
+            d=d+4*x-4*y+10;
+            y--;
+        }
+        x++;
+    }
+}
+
+void GDEP015OC1::fillCircle(uint16_t startX, uint16_t startY, uint16_t radius, bool color=0){
+    for(uint16_t r = 1;r<=radius; r++){
+        drawCircle(startX,   startY, r,   color);
+        drawCircle(startX+1, startY, r-1, color);
+        drawCircle(startX-1, startY, r-1, color);
+    }
+}
+
+void GDEP015OC1::drawEllipse(uint16_t startX, uint16_t startY, uint16_t width, uint16_t height, bool color){
+    int a2 = width*width;
+    int b2 = height*height;
+    int fa2 = 4*a2, fb2 = 4*b2;
+    int x, y, sigma;
+                                                        
+  //First half                                                      
+    for(int x = 0, y = height, sigma = 2*b2+a2*(1-2*height); b2*x <= a2*y; x++){
+        drawPixel(startX+x,startY+y,color);
+        drawPixel(startX-x,startY+y,color);
+        drawPixel(startX+x,startY-y,color);
+        drawPixel(startX-x,startY-y,color);
+        if(sigma >= 0){
+            sigma += fa2 * (1-y);
+            y--;
+        }
+        sigma += b2 * ((4 * x) + 6);
+    }
+    //Second half
+    for (x = width, y = 0, sigma = 2*a2+b2*(1-2*width); a2*y <= b2*x; y++){
+        drawPixel(startX+x,startY+y,color);
+        drawPixel(startX-x,startY+y,color);
+        drawPixel(startX+x,startY-y,color);
+        drawPixel(startX-x,startY-y,color);
+        if (sigma >= 0){
+                sigma += fb2 * (1 - x);
+                x--;
+        }
+        sigma += a2 * ((4 * y) + 6);
+    }       
+}
+
+void GDEP015OC1::fillEllipse(uint16_t startX, uint16_t startY, uint16_t width, uint16_t height, bool color=0){
+    for(uint16_t w = width; w > 0; w--){
+        drawEllipse(startX, startX, w, height, color);
+    }
+    drawLine(startX, startY-height, startX, startY+height, color);
+}
+
+void GDEP015OC1::writeChar(char character, uint16_t startX, uint16_t startY, bool color=0){
+    unsigned char letter[FONT_WIDTH];
+
+    //Grab data for the corresponding font
+    for(uint8_t i = 0; i<FONT_WIDTH; i++)
+        letter[i] = Font5x7[(character - ' ') * FONT_WIDTH + i];
+
+    for(uint8_t i = 0; i<FONT_WIDTH; i++){
+        for(uint8_t j = 0; j<FONT_HEIGHT; j++){
+            if((letter[i]>>j)&0x01){
+                if(_italic){
+                    drawPixel(startX+i+(FONT_HEIGHT/3 - j/3), startY+j, color);
+                    if(_bold){
+                        for(uint8_t z=0; z<2; z++)
+                            drawPixel(startX+i-z+(FONT_HEIGHT/3- j/3), startY+j, color);
+                    }
+                }
+                else{
+                    drawPixel(startX+i, startY+j, color);
+                    if(_bold){
+                        for(uint8_t z=0; z<2; z++)
+                            drawPixel(startX+i-z, startY+j, color);
+                    }
+                }
+            }
+        }
+    }   
+}
+
+void GDEP015OC1::writeString(char *string, uint16_t startX, uint16_t startY, bool color=0){
+    uint8_t length = 0;
+    while(*(string+length) != '\0') length++;
+    
+    for(uint8_t x=0; x<length; x++)
+        writeChar(*(string+x), startX+(FONT_WIDTH)*x, startY, color);
 }
\ No newline at end of file
diff -r 1c8f73aa2a16 -r dc7b794b59b7 GDEP015OC1.h
--- a/GDEP015OC1.h	Thu Sep 15 09:19:30 2016 +0000
+++ b/GDEP015OC1.h	Thu Sep 15 12:12:34 2016 +0000
@@ -1,6 +1,12 @@
+/**
+ *  Created by Filip Hormot (f.hormot@gmail.com) on 14/09/16.
+ */
+
 #include "mbed.h"
 
 #define BUFFER_SIZE     5000
+#define FONT_WIDTH         5
+#define FONT_HEIGHT        7
 #define BUSY_STATE         1
 
 class GDEP015OC1 {
@@ -14,6 +20,14 @@
         void write(void);            
         void drawPixel(uint16_t startX, uint16_t startY, bool color);            
         void drawLine(uint16_t startX,  uint16_t startY, uint16_t stopX, uint16_t stopY, bool color);
+        void drawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, bool color);
+        void drawRectangle(uint16_t startX, uint16_t startY, uint16_t stopX, uint16_t stopY, bool color);
+        void drawCircle(uint16_t startX, uint16_t startY, uint16_t radius, bool color);
+        void fillCircle(uint16_t startX, uint16_t startY, uint16_t radius, bool color);
+        void drawEllipse(uint16_t startX, uint16_t startY, uint16_t width, uint16_t height, bool color);
+        void fillEllipse(uint16_t startX, uint16_t startY, uint16_t width, uint16_t height, bool color);
+        void writeChar(char character, uint16_t startX, uint16_t startY, bool color);
+        void writeString(char *string, uint16_t startX, uint16_t startY, bool color);
     private:
         SPI& _spi;
         DigitalOut _cs;
@@ -21,9 +35,10 @@
         DigitalOut _rst;
         DigitalIn  _busy;
         
+        bool _italic, _bold;
+        
         unsigned char _buffer[BUFFER_SIZE];
          
-    
         void _spiCommand(unsigned char command);            
         void _spiData(unsigned char data);            
         void _init(void);