E_paper, E_ink, Screen size 1.54", resolution 200x200, 4 wire spi, Waveshare, Black and White, Kl25Z, 8 wire print connector, supply 3.3 Volt, IL0373 Controller, font size is 8, 12, 16 and 24.

Dependencies:   mbed

Revision:
8:01db118d1694
Parent:
7:25cadf37fd86
Child:
9:9503e1ff98ea
--- a/epd1in54.cpp	Wed Mar 28 10:17:33 2018 +0000
+++ b/epd1in54.cpp	Thu Mar 29 18:27:28 2018 +0000
@@ -28,10 +28,12 @@
 
 extern Serial pc;
 
-Epd::~Epd() {
+Epd::~Epd()
+{
 };
 
-Epd::Epd() {
+Epd::Epd()
+{
     reset_pin_no= 0;
     dc_pin_no = 1;
     cs_pin_no = 2;
@@ -40,7 +42,9 @@
     height = EPD_HEIGHT;
 };
 
-int Epd::Init(const unsigned char* lut) {
+int Epd::Init(const unsigned char* lut)
+{
+    pc.printf("Init...  \n\r");
     /* this calls the peripheral hardware interface, see epdif */
     if (IfInit() != 0) {
         return -1;
@@ -66,13 +70,15 @@
     SendData(0x03);                     // X increment; Y increment
     SetLut(this->lut);
     /* EPD hardware init end */
+    pc.printf("Init done \n\r");
     return 0;
 }
 
 /**
  *  @brief: basic function for sending commands
  */
-void Epd::SendCommand(unsigned char command) {
+void Epd::SendCommand(unsigned char command)
+{
     DigitalWrite(dc_pin_no, LOW);
     SpiTransfer(command);
 }
@@ -80,7 +86,8 @@
 /**
  *  @brief: basic function for sending data
  */
-void Epd::SendData(unsigned char data) {
+void Epd::SendData(unsigned char data)
+{
     DigitalWrite(dc_pin_no, HIGH);
     SpiTransfer(data);
 }
@@ -89,10 +96,13 @@
 /**
  *  @brief: Wait until the busy_pin goes LOW
  */
-void Epd::WaitUntilIdle(void) {
+void Epd::WaitUntilIdle(void)
+{
+    pc.printf("Wait for idle Busy pin goes low \n\r");
     while(DigitalRead(busy_pin_no) == HIGH) {      //LOW: idle, HIGH: busy
+    pc.printf(".");
         DelayMs(100);
-    }      
+    }
 }
 
 /**
@@ -100,17 +110,21 @@
  *          often used to awaken the module in deep sleep,
  *          see Epd::Sleep();
  */
-void Epd::Reset(void) {
-    DigitalWrite(reset_pin_no, LOW);                //module reset    
+void Epd::Reset(void)
+{
+    pc.printf("Reset...  \n\r");
+    DigitalWrite(reset_pin_no, LOW);                //module reset
     DelayMs(200);
     DigitalWrite(reset_pin_no, HIGH);
-    DelayMs(200);    
+    DelayMs(200);
 }
 
 /**
  *  @brief: set the look-up table register
  */
-void Epd::SetLut(const unsigned char* lut) {
+void Epd::SetLut(const unsigned char* lut)
+{
+    pc.printf("Set LUT \n\r");
     this->lut = lut;
     SendCommand(WRITE_LUT_REGISTER);
     /* the length of look-up table is 30 bytes */
@@ -125,14 +139,13 @@
  */
 void Epd::SetFrameMemory(
     const unsigned char* image_buffer,
-    int x,
-    int y,
-    int image_width,
-    int image_height
-) {
+    int x,int y, int image_width, int image_height)
+{
     int x_end;
     int y_end;
 
+    pc.printf("SetFrameMemory regel 141\n\r");
+
     if (
         image_buffer == NULL ||
         x < 0 || image_width < 0 ||
@@ -168,7 +181,7 @@
  *  @brief: put an image buffer to the frame memory.
  *          this won't update the display.
  *
- *          Question: When do you use this function instead of 
+ *          Question: When do you use this function instead of
  *          void SetFrameMemory(
  *              const unsigned char* image_buffer,
  *              int x,
@@ -178,17 +191,20 @@
  *          );
  *          Answer: SetFrameMemory with parameters only reads image data
  *          from the RAM but not from the flash in AVR chips (for AVR chips,
- *          you have to use the function pgm_read_byte to read buffers 
+ *          you have to use the function pgm_read_byte to read buffers
  *          from the flash).
  */
-void Epd::SetFrameMemory(const unsigned char* image_buffer) {
+void Epd::SetFrameMemory(const unsigned char* image_buffer)
+{
+    pc.printf("SetFrameMemory \n\r");
+
     SetMemoryArea(0, 0, this->width - 1, this->height - 1);
     SetMemoryPointer(0, 0);
     SendCommand(WRITE_RAM);
     /* send the image data */
     for (int i = 0; i < this->width / 8 * this->height; i++) {
         //SendData(pgm_read_byte(&image_buffer[i]));
-         SendData(*(&image_buffer[i]));
+        SendData(*(&image_buffer[i]));
     }
 }
 
@@ -196,20 +212,21 @@
  *  @brief: clear the frame memory with the specified color.
  *          this won't update the display.
  */
-void Epd::ClearFrameMemory(unsigned char color) {
-     pc.printf("width= %d, height %d\n\r",this->width ,this->height);
-     
+void Epd::ClearFrameMemory(unsigned char color)
+{
+    pc.printf("width= %d, height %d\n\r",this->width ,this->height);
+
     SetMemoryArea(0, 0, this->width - 1, this->height - 1);
-      pc.printf("setpointer \n\r");
+    pc.printf("setpointer \n\r");
     SetMemoryPointer(0, 0);
-       pc.printf("send command \n\r");
+    pc.printf("send command \n\r");
     SendCommand(WRITE_RAM);
-    
+
     /* send the color data */
-     pc.printf("Write to memory\r\n");
+    pc.printf("Write to memory\r\n");
     for (int i = 0; i < this->width / 8 * this->height; i++) {
         SendData(color);
-         pc.printf("color= %x ,", color);
+        pc.printf("color= %x ,", color);
     }
 }
 
@@ -217,10 +234,12 @@
  *  @brief: update the display
  *          there are 2 memory areas embedded in the e-paper display
  *          but once this function is called,
- *          the the next action of SetFrameMemory or ClearFrame will 
+ *          the the next action of SetFrameMemory or ClearFrame will
  *          set the other memory area.
  */
-void Epd::DisplayFrame(void) {
+void Epd::DisplayFrame(void)
+{
+    pc.printf("DisplayFrame \n\r");
     SendCommand(DISPLAY_UPDATE_CONTROL_2);
     SendData(0xC4);
     SendCommand(MASTER_ACTIVATION);
@@ -231,7 +250,9 @@
 /**
  *  @brief: private function to specify the memory area for data R/W
  */
-void Epd::SetMemoryArea(int x_start, int y_start, int x_end, int y_end) {
+void Epd::SetMemoryArea(int x_start, int y_start, int x_end, int y_end)
+{
+    pc.printf("SetMemoryArea \n\r");
     SendCommand(SET_RAM_X_ADDRESS_START_END_POSITION);
     /* x point must be the multiple of 8 or the last 3 bits will be ignored */
     SendData((x_start >> 3) & 0xFF);
@@ -246,42 +267,44 @@
 /**
  *  @brief: private function to specify the start point for data R/W
  */
-void Epd::SetMemoryPointer(int x, int y) {
-    
+void Epd::SetMemoryPointer(int x, int y)
+{
+    pc.printf("SetMemoryPointer \n\r");
     SendCommand(SET_RAM_X_ADDRESS_COUNTER);
-    
+
     /* x point must be the multiple of 8 or the last 3 bits will be ignored */
     SendData((x >> 3) & 0xFF);
     SendCommand(SET_RAM_Y_ADDRESS_COUNTER);
     SendData(y & 0xFF);
     SendData((y >> 8) & 0xFF);
+    pc.printf("WaitUntilidle \n\r");
     WaitUntilIdle();
+    pc.printf("Done SetMemoryPointer \n\r");
 }
 
 /**
- *  @brief: After this command is transmitted, the chip would enter the 
- *          deep-sleep mode to save power. 
- *          The deep sleep mode would return to standby by hardware reset. 
+ *  @brief: After this command is transmitted, the chip would enter the
+ *          deep-sleep mode to save power.
+ *          The deep sleep mode would return to standby by hardware reset.
  *          You can use Epd::Init() to awaken
  */
-void Epd::Sleep() {
+void Epd::Sleep()
+{
     SendCommand(DEEP_SLEEP_MODE);
     WaitUntilIdle();
 }
 
-const unsigned char lut_full_update[] =
-{
-    0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 
-    0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88, 
-    0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51, 
+const unsigned char lut_full_update[] = {
+    0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22,
+    0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88,
+    0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51,
     0x35, 0x51, 0x51, 0x19, 0x01, 0x00
 };
 
-const unsigned char lut_partial_update[] =
-{
-    0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, 
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
-    0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12, 
+const unsigned char lut_partial_update[] = {
+    0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12,
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };