2019.07.31
This commit is contained in:
parent
0c77852dae
commit
717cbb8d92
734 changed files with 2999 additions and 61893 deletions
|
|
@ -45,7 +45,7 @@ void setup()
|
|||
return;
|
||||
}
|
||||
//Serial.print("ClearFrameMemory\n");
|
||||
// epd.ClearFrameMemory(); // bit set = white, bit reset = black
|
||||
// epd.ClearFrameMemory(); // bit set = white, bit reset = black
|
||||
|
||||
/**
|
||||
* there are 2 memory areas embedded in the e-paper display
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* @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
|
||||
|
|
@ -1,292 +0,0 @@
|
|||
/**
|
||||
* @filename : epd2in13.cpp
|
||||
* @brief : Implements for e-paper library
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare September 9 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 <stdlib.h>
|
||||
#include "fepd2in13.h"
|
||||
|
||||
/**
|
||||
* full screen update LUT
|
||||
**/
|
||||
const unsigned char lut_vcomDC[] = {
|
||||
0x00, 0x08, 0x00, 0x00, 0x00, 0x02,
|
||||
0x60, 0x28, 0x28, 0x00, 0x00, 0x01,
|
||||
0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x12, 0x12, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00,
|
||||
};
|
||||
const unsigned char lut_ww[] = {
|
||||
0x40, 0x08, 0x00, 0x00, 0x00, 0x02,
|
||||
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
|
||||
0x40, 0x14, 0x00, 0x00, 0x00, 0x01,
|
||||
0xA0, 0x12, 0x12, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
const unsigned char lut_bw[] = {
|
||||
0x40, 0x17, 0x00, 0x00, 0x00, 0x02,
|
||||
0x90, 0x0F, 0x0F, 0x00, 0x00, 0x03,
|
||||
0x40, 0x0A, 0x01, 0x00, 0x00, 0x01,
|
||||
0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
const unsigned char lut_wb[] = {
|
||||
0x80, 0x08, 0x00, 0x00, 0x00, 0x02,
|
||||
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
|
||||
0x80, 0x14, 0x00, 0x00, 0x00, 0x01,
|
||||
0x50, 0x12, 0x12, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
const unsigned char lut_bb[] = {
|
||||
0x80, 0x08, 0x00, 0x00, 0x00, 0x02,
|
||||
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
|
||||
0x80, 0x14, 0x00, 0x00, 0x00, 0x01,
|
||||
0x50, 0x12, 0x12, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
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() {
|
||||
Serial.begin(9600);
|
||||
/* this calls the peripheral hardware interface, see epdif */
|
||||
if (IfInit() != 0) {
|
||||
return -1;
|
||||
}
|
||||
/* EPD hardware init start */
|
||||
Reset();
|
||||
|
||||
SendCommand(0x01); //POWER SETTING
|
||||
SendData(0x03);
|
||||
SendData(0x00);
|
||||
SendData(0x2b);
|
||||
SendData(0x2b);
|
||||
SendData(0x03);
|
||||
|
||||
SendCommand(0x06); //boost soft start
|
||||
SendData(0x17); //A
|
||||
SendData(0x17); //B
|
||||
SendData(0x17); //C
|
||||
|
||||
SendCommand(0x04);
|
||||
// WaitUntilIdle();
|
||||
|
||||
SendCommand(0x00); //panel setting
|
||||
SendData(0xbf); //LUT from OTP£¬128x296
|
||||
SendData(0x0d); //VCOM to 0V fast
|
||||
|
||||
SendCommand(0x30); //PLL setting
|
||||
SendData(0x3a); // 3a 100HZ 29 150Hz 39 200HZ 31 171HZ
|
||||
|
||||
SendCommand(0x61); //resolution setting
|
||||
SendData(EPD_WIDTH);
|
||||
SendData((EPD_HEIGHT >> 8) & 0xff);
|
||||
SendData(EPD_HEIGHT& 0xff);
|
||||
|
||||
SendCommand(0x82); //vcom_DC setting
|
||||
SendData(0x28);
|
||||
/* EPD hardware init end */
|
||||
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::WaitUntilIdle(void) {
|
||||
while(DigitalRead(busy_pin) == HIGH) { //LOW: idle, HIGH: busy
|
||||
DelayMs(100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: module reset.
|
||||
* often used to awaken the module in deep sleep,
|
||||
* see Epd::Sleep();
|
||||
*/
|
||||
void Epd::Reset(void) {
|
||||
DigitalWrite(reset_pin, LOW); //module reset
|
||||
DelayMs(200);
|
||||
DigitalWrite(reset_pin, HIGH);
|
||||
DelayMs(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: set the look-up table register
|
||||
*/
|
||||
void Epd::SetFullReg(void)
|
||||
{
|
||||
SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
|
||||
SendData(0x97); //WBmode:VBDF 17|D7 VBDW 97 VBDB 57 WBRmode:VBDF F7 VBDW 77 VBDB 37 VBDR B7
|
||||
|
||||
unsigned int count;
|
||||
SendCommand(0x20);
|
||||
for(count=0; count<44; count++) {
|
||||
SendData(lut_vcomDC[count]);
|
||||
}
|
||||
|
||||
SendCommand(0x21);
|
||||
for(count=0; count<42; count++) {
|
||||
SendData(lut_ww[count]);
|
||||
}
|
||||
|
||||
SendCommand(0x22);
|
||||
for(count=0; count<42; count++) {
|
||||
SendData(lut_bw[count]);
|
||||
}
|
||||
|
||||
SendCommand(0x23);
|
||||
for(count=0; count<42; count++) {
|
||||
SendData(lut_wb[count]);
|
||||
}
|
||||
|
||||
SendCommand(0x24);
|
||||
for(count=0; count<42; count++) {
|
||||
SendData(lut_bb[count]);
|
||||
}
|
||||
}
|
||||
|
||||
void Epd::SetFrameMemory(const unsigned char* image_buffer) {
|
||||
unsigned char Width, Height, data;
|
||||
Width = (EPD_WIDTH % 8 == 0)? (EPD_WIDTH / 8 ): (EPD_WIDTH / 8 + 1);
|
||||
Height = EPD_HEIGHT;
|
||||
|
||||
SendCommand(0x10);
|
||||
for (int j = 0; j < Height; j++) {
|
||||
for (int i = 0; i < Width; i++) {
|
||||
SendData(0x00);
|
||||
}
|
||||
}
|
||||
DelayMs(10);
|
||||
|
||||
SendCommand(0x13);
|
||||
for (int j = 0; j < Height; j++) {
|
||||
for (int i = 0; i < Width; i++) {
|
||||
data = pgm_read_byte(&image_buffer[i + j * Width]);
|
||||
SendData(data);
|
||||
// Serial.print(data);
|
||||
}
|
||||
}
|
||||
DelayMs(10);
|
||||
|
||||
SetFullReg();
|
||||
DisplayFrame();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: clear the frame memory with the specified color.
|
||||
* this won't update the display.
|
||||
*/
|
||||
void Epd::ClearFrameMemory() {
|
||||
unsigned char Width, Height;
|
||||
Width = (EPD_WIDTH % 8 == 0)? (EPD_WIDTH / 8 ): (EPD_WIDTH / 8 + 1);
|
||||
Height = EPD_HEIGHT;
|
||||
|
||||
SendCommand(0x10);
|
||||
for (int j = 0; j < Height; j++) {
|
||||
for (int i = 0; i < Width; i++) {
|
||||
SendData(0x00);
|
||||
}
|
||||
}
|
||||
DelayMs(10);
|
||||
|
||||
SendCommand(0x13);
|
||||
for (int j = 0; j < Height; j++) {
|
||||
for (int i = 0; i < Width; i++) {
|
||||
SendData(0xFF);
|
||||
}
|
||||
}
|
||||
DelayMs(10);
|
||||
|
||||
SetFullReg();
|
||||
DisplayFrame();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* set the other memory area.
|
||||
*/
|
||||
void Epd::DisplayFrame(void) {
|
||||
SendCommand(0x12);
|
||||
DelayMs(100);
|
||||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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() {
|
||||
SendCommand(0X50);
|
||||
SendData(0xf7);
|
||||
SendCommand(0X02); //power off
|
||||
SendCommand(0X07); //deep sleep
|
||||
SendData(0xA5);
|
||||
}
|
||||
|
||||
|
||||
/* END OF FILE */
|
||||
|
||||
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
* @filename : epd2in13.h
|
||||
* @brief : Header file for e-paper display library epd2in13.cpp
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare September 9 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 FEPD2IN13_H
|
||||
#define FEPD2IN13_H
|
||||
|
||||
#include "epdif.h"
|
||||
|
||||
// Display resolution
|
||||
/* the resolution is 122x250 in fact */
|
||||
/* however, the logical resolution is 128x250 */
|
||||
#define EPD_WIDTH 104
|
||||
#define EPD_HEIGHT 212
|
||||
|
||||
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 WaitUntilIdle(void);
|
||||
void Reset(void);
|
||||
void SetFrameMemory(const unsigned char* image_buffer);
|
||||
void ClearFrameMemory();
|
||||
void DisplayFrame(void);
|
||||
void Sleep(void);
|
||||
|
||||
private:
|
||||
unsigned int reset_pin;
|
||||
unsigned int dc_pin;
|
||||
unsigned int cs_pin;
|
||||
unsigned int busy_pin;
|
||||
const unsigned char* lut;
|
||||
|
||||
void SetFullReg(void);
|
||||
};
|
||||
|
||||
#endif /* EPD2IN13_H */
|
||||
|
||||
/* END OF FILE */
|
||||
Loading…
Add table
Add a link
Reference in a new issue