Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
248 changes: 248 additions & 0 deletions Arduino/epd2in66g/epd2in66g.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/**
* @filename : epd2in66g.cpp
* @brief : Implements for e-paper library
* @author : Waveshare
*
* Copyright (C) Waveshare 2022/08/17
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documnetation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include <stdlib.h>
#include "epd2in66g.h"

Epd::~Epd() {
};

Epd::Epd() {
reset_pin = RST_PIN;
dc_pin = DC_PIN;
cs_pin = CS_PIN;
busy_pin = BUSY_PIN;
WIDTH = EPD_WIDTH;
HEIGHT = EPD_HEIGHT;
};

int Epd::Init() {
/* this calls the peripheral hardware interface, see epdif */
if (IfInit() != 0) {
return -1;
}
Reset();
ReadBusyH();

SendCommand(0x4D);
SendData(0x78);

SendCommand(0x00); //PSR
SendData(0x0F);
SendData(0x29);

SendCommand(0x01); //PWRR
SendData(0x07);
SendData(0x00);

SendCommand(0x03); //POFS
SendData(0x10);
SendData(0x54);
SendData(0x44);

SendCommand(0x06); //BTST_P
SendData(0x05);
SendData(0x00);
SendData(0x3F);
SendData(0x0A);
SendData(0x25);
SendData(0x12);
SendData(0x1A);

SendCommand(0x50); //CDI
SendData(0x37);

SendCommand(0x60); //TCON
SendData(0x02);
SendData(0x02);

SendCommand(0x61); //TRES
SendData(WIDTH/256); // Source_BITS_H
SendData(WIDTH%256); // Source_BITS_L
SendData(HEIGHT/256); // Gate_BITS_H
SendData(HEIGHT%256); // Gate_BITS_L

SendCommand(0xE7);
SendData(0x1C);

SendCommand(0xE3);
SendData(0x22);

SendCommand(0xB4);
SendData(0xD0);
SendCommand(0xB5);
SendData(0x03);

SendCommand(0xE9);
SendData(0x01);

SendCommand(0x30);
SendData(0x08);

SendCommand(0x04);
ReadBusyH();
return 0;
}

/**
* @brief: basic function for sending commands
*/
void Epd::SendCommand(unsigned char command) {
DigitalWrite(dc_pin, LOW);
SpiTransfer(command);
}

/**
* @brief: basic function for sending data
*/
void Epd::SendData(unsigned char data) {
DigitalWrite(dc_pin, HIGH);
SpiTransfer(data);
}

/**
* @brief: Wait until the busy_pin goes LOW
*/
void Epd::ReadBusyH(void) {
Serial.print("e-Paper busy H\r\n ");
while(DigitalRead(busy_pin) == LOW) { //LOW: busy, HIGH: idle
DelayMs(5);
}
Serial.print("e-Paper busy release H\r\n ");
}

void Epd::ReadBusyL(void) {
Serial.print("e-Paper busy L\r\n ");
while(DigitalRead(busy_pin) == HIGH) { //LOW: idle, HIGH: busy
DelayMs(5);
}
Serial.print("e-Paper busy release L\r\n ");
}

/**
* @brief: module reset.
* often used to awaken the module in deep sleep,
* see Epd::Sleep();
*/
void Epd::Reset(void) {
DigitalWrite(reset_pin, HIGH);
DelayMs(20);
DigitalWrite(reset_pin, LOW); //module reset
DelayMs(2);
DigitalWrite(reset_pin, HIGH);
DelayMs(20);
}

/******************************************************************************
function : Turn On Display
parameter:
******************************************************************************/
void Epd::TurnOnDisplay(void)
{
SendCommand(0x12); // DISPLAY_REFRESH
SendData(0x00);
ReadBusyH();
}

/******************************************************************************
function : Clear screen
parameter:
******************************************************************************/
void Epd::Clear(UBYTE color)
{
UWORD Width, Height;
Width = (WIDTH % 4 == 0)? (WIDTH / 4 ): (WIDTH / 4 + 1);
Height = HEIGHT;

SendCommand(0x10);
for (UWORD j = 0; j < Height; j++) {
for (UWORD i = 0; i < Width; i++) {
SendData((color<<6) | (color<<4) | (color<<2) | color);
}
}

TurnOnDisplay();
}

/******************************************************************************
function : Sends the image buffer in RAM to e-Paper and displays
parameter:
******************************************************************************/
void Epd::Display(UBYTE *Image)
{
UWORD Width, Height;
Width = (WIDTH % 4 == 0)? (WIDTH / 4 ): (WIDTH / 4 + 1);
Height = HEIGHT;

SendCommand(0x10);
for (UWORD j = 0; j < Height; j++) {
for (UWORD i = 0; i < Width; i++) {
SendData(pgm_read_byte(&Image[i + j * Width]));
}
}

TurnOnDisplay();
}

void Epd::Display_part(UBYTE *Image, UWORD xstart, UWORD ystart, UWORD image_width, UWORD image_height)
{
UWORD Width, Height, i, j;
Width = (WIDTH % 4 == 0)? (WIDTH / 4 ): (WIDTH / 4 + 1);
Height = HEIGHT;

SendCommand(0x10);
for(i=0; i<Height; i++) {
for(j=0; j< Width; j++) {
if(i<image_height+ystart && i>=ystart && j<(image_width+xstart)/4 && j>=xstart/4) {
SendData(pgm_read_byte(&Image[(j-xstart/4) + (image_width/4*(i-ystart))]));
}
else {
SendData(0x55);
}
}
}


TurnOnDisplay();
}

/******************************************************************************
function : Enter sleep mode
parameter:
******************************************************************************/
void Epd::Sleep(void)
{
SendCommand(0x02); // POWER_OFF
SendData(0X00);
ReadBusyH();

SendCommand(0x07); // DEEP_SLEEP
SendData(0XA5);
}

/* END OF FILE */


74 changes: 74 additions & 0 deletions Arduino/epd2in66g/epd2in66g.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @filename : epd2in66g.h
* @brief : Header file for e-paper display library epd4in37g.cpp
* @author : Waveshare
*
* Copyright (C) Waveshare 2022/08/17
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documnetation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef EPD2IN66G_H
#define EPD2IN66G_H

#include "epdif.h"

// Display resolution
#define EPD_WIDTH 184
#define EPD_HEIGHT 360

// Color
#define black 0x0
#define white 0x1
#define yellow 0x2
#define red 0x3

#define UWORD unsigned int
#define UBYTE unsigned char
#define UDOUBLE unsigned long

class Epd : EpdIf {
public:
unsigned long WIDTH;
unsigned long HEIGHT;

Epd();
~Epd();
int Init();
void SendCommand(unsigned char command);
void SendData(unsigned char data);
void Reset(void);
void ReadBusyH(void);
void ReadBusyL(void);
void TurnOnDisplay(void);
void Clear(UBYTE color);
void Display(UBYTE *Image);
void Display_part(UBYTE *Image, UWORD xstart, UWORD ystart, UWORD image_width, UWORD image_height);
void Sleep(void);

private:
unsigned int reset_pin;
unsigned int dc_pin;
unsigned int cs_pin;
unsigned int busy_pin;
};

#endif /* EPD4IN37_H */

/* END OF FILE */
60 changes: 60 additions & 0 deletions Arduino/epd2in66g/epd2in66g.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @filename : epd2in66g-demo.ino
* @brief : 2.66inch e-Paper (G) display demo
* @author : Waveshare
*
* Copyright (C) Waveshare 2022/08/17
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documnetation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include <SPI.h>
#include "epd2in66g.h"
#include "imagedata.h"

Epd epd;

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.print("e-Paper init \r\n");
if (epd.Init() != 0) {
Serial.print("e-Paper init failed");
return;
}

Serial.print("White \r\n");
epd.Clear(white);
delay(2000);

Serial.print("Small Image \r\n");
epd.Display_part(Image4color, 10, 96, 168, 168);
delay(2000);

Serial.print("Clear...\r\n");
epd.Clear(white);
delay(2000);

Serial.print("Goto Sleep...\r\n");
epd.Sleep();
}

void loop() {

}
Loading