Skip to content

Commit

Permalink
Added new programs 13.3inch e-Paper (K) routine
Browse files Browse the repository at this point in the history
  • Loading branch information
shhds committed Sep 25, 2023
1 parent 8316a45 commit 4822c07
Show file tree
Hide file tree
Showing 159 changed files with 43,054 additions and 4,588 deletions.
202 changes: 202 additions & 0 deletions Arduino/epd13in3k/epd13in3k.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/**
* @filename : epd13in3k.cpp
* @brief : Implements for e-paper library
* @author : Yehui from Waveshare
*
* Copyright (C) Waveshare September 25 2023
*
* 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 "epd13in3k.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(void) {
if (IfInit() != 0) {
return -1;
}
Reset();
ReadBusy();

SendCommand(0x12);
ReadBusy();

SendCommand(0x0C);
SendData(0xAE);
SendData(0xC7);
SendData(0xC3);
SendData(0xC0);
SendData(0x80);

SendCommand(0x01);
SendData(0xA7);
SendData(0x02);
SendData(0x00);

SendCommand(0x11);
SendData(0x03);

SendCommand(0x44);
SendData(0x00);
SendData(0x00);
SendData(0xBF);
SendData(0x03);

SendCommand(0x45);
SendData(0x00);
SendData(0x00);
SendData(0xA7);
SendData(0x02);

SendCommand(0x3C);
SendData(0x05);

SendCommand(0x18);
SendData(0x80);

SendCommand(0x4E);
SendData(0x00);

SendCommand(0x4F);
SendData(0x00);
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 HIGH
*/
void Epd::ReadBusy(void) {
unsigned char busy;
Serial.print("e-Paper Busy\r\n ");
do{
DelayMs(20);
busy = DigitalRead(busy_pin);
}while(busy == 1);
Serial.print("e-Paper Busy Release\r\n ");
DelayMs(20);
}

/**
* @brief: Refresh function
*/
void Epd::TurnOnDisplay(void) {
SendCommand(0x22);
SendData(0xF7);
SendCommand(0x20);
ReadBusy();
}

/**
* @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(4);
DigitalWrite(reset_pin, HIGH);
DelayMs(20);
}

void Epd::DisplayFrame(const unsigned char* frame_buffer) {

SendCommand(0x24);
for (unsigned long j = 0; j < height; j++) {
for (unsigned long i = 0; i < width/8; i++) {
SendData(frame_buffer[i + j * width/8]);
}
}
TurnOnDisplay();
}

void Epd::Displaypart(const unsigned char* pbuffer, unsigned long xStart, unsigned long yStart,unsigned long Picture_Width,unsigned long Picture_Height) {
SendCommand(0x24);
for (unsigned long j = 0; j < height; j++) {
for (unsigned long i = 0; i < width/8; i++) {
if( (j>=yStart) && (j<yStart+Picture_Height) && (i*8>=xStart) && (i*8<xStart+Picture_Width)){
SendData((pgm_read_byte(&(pbuffer[i-xStart/8 + (Picture_Width)/8*(j-yStart)]))) );
// SendData(0xff);
}else {
SendData(0xFF);
}
}
}
TurnOnDisplay();
}

/**
* @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.
* The only one parameter is a check code, the command would be
* executed if check code = 0xA5.
* You can use EPD_Reset() to awaken
*/
void Epd::Sleep(void) {
SendCommand(0x10);
SendData(0x01);
DelayMs(100);
ReadBusy();
}

void Epd::Clear(void) {

SendCommand(0x24);
for(unsigned long i=0; i<height*width/8; i++) {
SendData(0xFF);
}
TurnOnDisplay();
}


/* END OF FILE */


62 changes: 62 additions & 0 deletions Arduino/epd13in3k/epd13in3k.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @filename : epd13in3k.h
* @brief : Header file for e-paper library epd7in5.cpp
* @author : Yehui from Waveshare
*
* Copyright (C) Waveshare September 25 2023
*
* 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 EPD13IN3_H
#define EPD13IN3_H

#include "epdif.h"

// Display resolution
#define EPD_WIDTH 960
#define EPD_HEIGHT 680

class Epd : EpdIf {
public:
Epd();
~Epd();
int Init(void);
void ReadBusy(void);
void Reset(void);
void TurnOnDisplay(void);
void DisplayFrame(const unsigned char* frame_buffer);
void SendCommand(unsigned char command);
void SendData(unsigned char data);
void Sleep(void);
void Clear(void);
void Epd::Displaypart(const unsigned char* pbuffer, unsigned long Start_X, unsigned long Start_Y,unsigned long END_X,unsigned long END_Y);

private:
unsigned int reset_pin;
unsigned int dc_pin;
unsigned int cs_pin;
unsigned int busy_pin;
unsigned long width;
unsigned long height;
};

#endif /* EPD7IN5_H */

/* END OF FILE */
53 changes: 53 additions & 0 deletions Arduino/epd13in3k/epd13in3k.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @filename : epd13in3k-demo.ino
* @brief : 7.5inch e-paper display demo
* @author : Yehui from Waveshare
*
* Copyright (C) Waveshare September 25 2023
*
* 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 "epd13in3k.h"
#include "imagedata.h"

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

Serial.print("e-Paper Display\r\n ");
epd.Displaypart(IMAGE_DATA,250, 200,240,103);

Serial.print("e-Paper Clear\r\n ");
epd.Clear();

epd.Sleep();
}

void loop() {
// put your main code here, to run repeatedly:

}
68 changes: 68 additions & 0 deletions Arduino/epd13in3k/epdif.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @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);

pinMode(PWR_PIN, OUTPUT);
DigitalWrite(PWR_PIN, 1);

SPI.begin();
SPI.beginTransaction(SPISettings(7000000, MSBFIRST, SPI_MODE0));
return 0;
}

Loading

0 comments on commit 4822c07

Please sign in to comment.