E-Paper Device (EPD) based MiniNote module, powered by mbed on LPC1114FBD48. Shared in public domain with enclosure in 3D step format, hardware interface compatible with microBUS interface. Anyone can contribute on this project.

Dependencies:   mbed _24LCXXX

E-Badge MiniNote Project on mbed/NXP LPC1114 platform

Revision:
2:bb9f154ea2f4
Parent:
0:33994cfad0c2
Child:
3:1fa000d4da94
--- a/SSD1606/ssd1606.cpp	Sun Jun 01 03:20:40 2014 +0000
+++ b/SSD1606/ssd1606.cpp	Mon Jun 09 11:01:38 2014 +0000
@@ -1,7 +1,13 @@
-
+/*
+ * Code ported from EDP-MSP430 and IAR-STM32-SK
+ * Allan K Liu
+ */
+ 
 #include "mbed.h"
 #include "ssd1606.h"
-#include "image.h"
+//#include "font.h"
+#include "rom_image.h"
+#include "rom_font.h"
 
 #include <stdarg.h>
 
@@ -20,25 +26,39 @@
 0x00,0x00,};
 
 
-SSD1606::SSD1606(PinName cs, PinName rst, PinName dc, PinName clk, PinName busy, PinName data)
-    : _spi(data, NC, clk), 
-      _cs(cs), 
-      _reset(rst), 
-      _dc(dc),
-            _busy(busy),
-      _cursor_x(0),
-      _cursor_y(0)
+SSD1606::SSD1606(PinName cs, PinName rst, PinName dc, PinName busy, PinName data, PinName clk)
+    : _cs(cs),
+        _reset(rst),
+        _dc(dc),
+        _busy(busy),
+        _data(data),
+        _clk(clk)
 {
+    _cursor_x = 0;
+    _cursor_y = 0;
+    _cs = DigitalOut(cs);
+    _reset = DigitalOut(rst);
+    _dc = DigitalOut(dc);
+    _busy = DigitalIn(busy);
+    _data = DigitalOut(data);
+    _clk = DigitalOut(clk);
 }
 
 void SSD1606::reset()
 {
     _reset = 1;
-    wait(0.01);
+    wait_ms(1);
     _reset = 0;
-    wait(0.01);
+    wait_ms(5);
     _reset = 1;
-    wait(0.01);
+    wait_ms(5);
+}
+
+void SSD1606::read_busy()
+{
+    while(_busy==1){
+        wait_ms(1);
+    }
 }
 
 void SSD1606::initialize()
@@ -116,40 +136,56 @@
     set_lut();
 }
 
-unsigned char SSD1606::is_busy()
-{
-    return(0);
-}
+
 
 void SSD1606::rom_image(const unsigned char *bitmap)
 {
-    int i;
+    int i=0;
     _send_command(0x24);
     
     for (i=0; i <3096; i++)
         _send_data(bitmap[i]);
     
     _send_command(0x20);
-    wait(0.01);
-    
+    wait_ms(1);
+    read_busy();    
 }
 
-void SSD1606::update()
+void SSD1606::update(void)
 {
-    for (int i=0; i<3096; i++)
-        _send_data(_screen[i]);
+    int i = 0;
+    _send_command(0x24);
+    
+    for (i=0; i<3096; i++)
+        //_send_data(_screen[i]);
+        //_send_data(buf[i]);
+    
+    wait_ms(1);
+    read_busy();
 }
 
+/*  Hardware Switch off Power Supply for EPD mode (MOSFET)
+ */
 void SSD1606::off()
 {
 }
 
+void SSD1606::deepsleep()
+{
+}
+
 void SSD1606::sleep()
 {
     _send_command(0x10);
     _send_data(0x01);
 }
 
+void SSD1606::wake()
+{
+    _send_command(0x10);
+    _send_data(0x00);   
+}
+
 void SSD1606::set_command_between_images()
 {
     _send_command(0x22);
@@ -160,28 +196,52 @@
 
 void SSD1606::clear()
 {
-    for (int i=0; i<3096; i++)
-        _send_data(0);
+    for (int i=0; i<FRAMEBUF_SIZE; i++)
+        _send_data(0xFF);
     _cursor_x = 0;
     _cursor_y = 0;
 }
 
+void SSD1606::_vspi_write(unsigned char value)
+{
+    for (int i=0; i<8; i++)
+    {
+        if(value & 0x80)
+        {
+            _data = 1;          
+        }else{
+            _data = 0;
+        }
+        _data = _data<<1;
+        _clk = 1;
+        wait_us(SPI_BUS_DELAY);
+        _clk = 0;
+    }
+}
+
 void SSD1606::_send_command(unsigned char code)
 {
-    _cs = 1;
-    _dc = 0;
-    _cs = 0;
-    _spi.write(code);
-    _cs = 1;
+    _cs = 1; wait_us(SPI_BUS_DELAY);
+    _cs = 0; wait_us(SPI_BUS_DELAY);    // Maybe _cs set low before _dc set low?
+    _clk = 0; wait_us(SPI_BUS_DELAY);
+    _dc = 0; wait_us(SPI_BUS_DELAY);
+
+    //_spi.write(code);
+    _vspi_write(code);
+     wait_us(SPI_BUS_DELAY);
+    _cs = 1; wait_us(SPI_BUS_DELAY);
 }
 
 void SSD1606::_send_data(unsigned char value)
 {
-    _cs = 1;
-    _dc = 1;
-    _cs = 0;
-    _spi.write(value);
-    _cs = 1;    
+    _cs = 1; wait_us(SPI_BUS_DELAY);
+    _cs = 0; wait_us(SPI_BUS_DELAY);
+    _clk = 0; wait_us(SPI_BUS_DELAY);
+    _dc = 1; wait_us(SPI_BUS_DELAY);    // Maybe _cs set low before _dc set high?
+    //_spi.write(value);
+    _vspi_write(value);
+     wait_us(SPI_BUS_DELAY);
+    _cs = 1; wait_us(SPI_BUS_DELAY);
 }
 
 void SSD1606::set_lut(void)
@@ -193,3 +253,48 @@
         _send_data(init_data[i]);
     }
 }
+
+void SSD1606::_draw_pattern(unsigned char value, unsigned int pix)
+{
+    int i = 0;
+    unsigned char x, y;
+    for (x=0; x<SSD1606_LCDHEIGHT; x++)
+    {
+        for (y=0; y<SSD1606_LCDWIDTH; y++)
+        {
+            i++;
+            if (i<pix)
+                _send_data(value);
+            else
+                _send_data(0xFF);
+        }
+    }   
+}
+
+void SSD1606::test_image(unsigned char idx)
+{
+    switch(idx){
+        case TEST_GREY1:
+            break;
+        case TEST_GREY2:
+            break;
+        case TEST_BLK:
+            break;
+        case TEST_WHT:
+            clear();
+            break;
+        case TEST_HALF:
+            break;
+        case TEST_STRIP1:
+            break;
+        case TEST_STRIP2:
+            break;
+        default:
+            break;
+    }
+}
+
+
+void SSD1606::set_font(unsigned char *font, unsigned char width)
+{
+}