Add the Arduino program: 1.64inch e-Paper (G), 3inch e-Paper (G), 7.3inch e-Paper (G) and 3.52inch e-Paper

This commit is contained in:
SSYYL 2022-07-28 18:02:46 +08:00
commit 1cc008a55f
40 changed files with 15144 additions and 8 deletions

View file

@ -0,0 +1,259 @@
/**
* @filename : epd3in0g.cpp
* @brief : Implements for e-paper library
* @author : Waveshare
*
* Copyright (C) Waveshare 2022/7/22
*
* 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 "epd3in0g.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();
SendCommand(0x66);
SendData(0x49);
SendData(0x55);
SendData(0x13);
SendData(0x5D);
SendData(0x05);
SendData(0x10);
SendCommand(0xB0);
SendData(0x00);//1 boost
SendCommand(0x01);
SendData(0x0F);
SendData(0x00);
SendCommand(0x00);
SendData(0x4F);
SendData(0x6B);
SendCommand(0x06);
SendData(0xD7);
SendData(0xDE);
SendData(0x12);
SendCommand(0x61);
SendData(0x00);
SendData(0xA8);
SendData(0x01);
SendData(0x90);
SendCommand(0x50);
SendData(0x37);
SendCommand(0x60);
SendData(0x0C);
SendData(0x05);
SendCommand(0xE3);
SendData(0xFF);
SendCommand(0x84);
SendData(0x00);
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(0x01);
ReadBusyH();
SendCommand(0x02); // POWER_OFF
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(0x68);
SendData(0x01);
SendCommand(0x04);
ReadBusyH();
SendCommand(0x10);
for (UWORD j = 0; j < Height; j++) {
for (UWORD i = 0; i < Width; i++) {
for(UBYTE k = 0; k < 4; k++) {
SendData(color);
}
}
}
SendCommand(0x68);
SendData(0x00);
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(0x68);
SendData(0x01);
SendCommand(0x04);
ReadBusyH();
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_heigh)
{
UWORD Width, Height;
Width = (WIDTH % 4 == 0)? (WIDTH / 4 ): (WIDTH / 4 + 1);
Height = HEIGHT;
SendCommand(0x68);
SendData(0x01);
SendCommand(0x04);
ReadBusyH();
SendCommand(0x10);
for (UWORD j = 0; j < Height; j++) {
for (UWORD i = 0; i < Width; i++) {
if((j >= xstart/4) && (j < (image_width + xstart)/4) && (i >= ystart) && (i <= (ystart + image_heigh)) )
{
SendData(pgm_read_byte(&Image[(i-ystart) * image_width/4 + j - xstart/4]));
// Serial.print(Image[(i-ystart) * image_width/8 + j - xstart], HEX);
// Serial.print(" ");
}
else
{
SendData(0x55);
}
}
}
TurnOnDisplay();
}
/******************************************************************************
function : Enter sleep mode
parameter:
******************************************************************************/
void Epd::Sleep(void)
{
SendCommand(0x02); // POWER_OFF
SendData(0X00);
SendCommand(0x07); // DEEP_SLEEP
SendData(0XA5);
}
/* END OF FILE */

View file

@ -0,0 +1,74 @@
/**
* @filename : epd3in0g.h
* @brief : Header file for e-paper display library epd3in0g.cpp
* @author : Waveshare
*
* Copyright (C) Waveshare 2022/7/22
*
* 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 EPD3IN0G_H
#define EPD3IN0G_H
#include "epdif.h"
// Display resolution
#define EPD_WIDTH 168
#define EPD_HEIGHT 400
//colour
#define black 0x00
#define white 0x55
#define yellow 0xAA
#define red 0xFF
#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 Sleep(void);
private:
unsigned int reset_pin;
unsigned int dc_pin;
unsigned int cs_pin;
unsigned int busy_pin;
};
#endif /* EPD1IN54_H */
/* END OF FILE */

View file

@ -0,0 +1,62 @@
/**
* @filename : epd3in0g-demo.ino
* @brief : 3inch e-paper (G) display demo
* @author : Waveshare
*
* Copyright (C) Waveshare 2022/7/22
*
* 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 "epd3in0g.h"
#include "imagedata.h"
Epd epd;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.print("e-Paper init ");
if (epd.Init() != 0) {
Serial.print("e-Paper init failed");
return;
}
Serial.print("While \r\n");
epd.Clear(white); // While
delay(2000);
epd.Init();
epd.Display(IMAGE_DATA);
delay(2000);
epd.Init();
Serial.print("Clear...\r\n");
epd.Clear(white);
delay(2000);
Serial.print("Goto Sleep...\r\n");
epd.Sleep();
}
void loop() {
}

View file

@ -0,0 +1,64 @@
/**
* @filename : epdif.cpp
* @brief : Implements EPD interface functions
* Users have to implement all the functions in epdif.cpp
* @author : Yehui from Waveshare
*
* Copyright (C) Waveshare August 10 2017
*
* 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 "epdif.h"
#include <spi.h>
EpdIf::EpdIf() {
};
EpdIf::~EpdIf() {
};
void EpdIf::DigitalWrite(int pin, int value) {
digitalWrite(pin, value);
}
int EpdIf::DigitalRead(int pin) {
return digitalRead(pin);
}
void EpdIf::DelayMs(unsigned int delaytime) {
delay(delaytime);
}
void EpdIf::SpiTransfer(unsigned char data) {
digitalWrite(CS_PIN, LOW);
SPI.transfer(data);
digitalWrite(CS_PIN, HIGH);
}
int EpdIf::IfInit(void) {
pinMode(CS_PIN, OUTPUT);
pinMode(RST_PIN, OUTPUT);
pinMode(DC_PIN, OUTPUT);
pinMode(BUSY_PIN, INPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
return 0;
}

51
Arduino/epd3in0g/epdif.h Normal file
View file

@ -0,0 +1,51 @@
/**
* @filename : epdif.h
* @brief : Header file of epdif.cpp providing EPD interface functions
* Users have to implement all the functions in epdif.cpp
* @author : Yehui from Waveshare
*
* Copyright (C) Waveshare August 10 2017
*
* 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 EPDIF_H
#define EPDIF_H
#include <arduino.h>
// Pin definition
#define RST_PIN 8
#define DC_PIN 9
#define CS_PIN 10
#define BUSY_PIN 7
class EpdIf {
public:
EpdIf(void);
~EpdIf(void);
static int IfInit(void);
static void DigitalWrite(int pin, int value);
static int DigitalRead(int pin);
static void DelayMs(unsigned int delaytime);
static void SpiTransfer(unsigned char data);
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,30 @@
/**
* @filename : imagedata.h
* @brief : head file for imagedata.cpp
*
* Copyright (C) Waveshare 2022/7/22
*
* 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.
*/
extern const unsigned char IMAGE_DATA[];
/* FILE END */