Added new programs 2.7inch V2 e-Paper routine.
This commit is contained in:
parent
6d99bdb672
commit
ae96a23767
34 changed files with 23147 additions and 1125 deletions
585
Arduino/epd2in7_V2/epd2in7_V2.cpp
Normal file
585
Arduino/epd2in7_V2/epd2in7_V2.cpp
Normal file
|
|
@ -0,0 +1,585 @@
|
|||
/**
|
||||
* @filename : epd2in7_V2.cpp
|
||||
* @brief : Implements for e-paper library
|
||||
* @author : Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare September 20 2022
|
||||
*
|
||||
* 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 "epd2in7_V2.h"
|
||||
|
||||
static const unsigned char LUT_DATA_4Gray[159] =
|
||||
{
|
||||
0x40, 0x48, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x8, 0x48, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x2, 0x48, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x20, 0x48, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0xA, 0x19, 0x0, 0x3, 0x8, 0x0, 0x0,
|
||||
0x14, 0x1, 0x0, 0x14, 0x1, 0x0, 0x3,
|
||||
0xA, 0x3, 0x0, 0x8, 0x19, 0x0, 0x0,
|
||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x0, 0x0, 0x0,
|
||||
0x22, 0x17, 0x41, 0x0, 0x32, 0x1C
|
||||
};
|
||||
|
||||
|
||||
|
||||
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) {
|
||||
/* this calls the peripheral hardware interface, see epdif */
|
||||
if (IfInit() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reset();
|
||||
ReadBusy();
|
||||
|
||||
SendCommand(0x12); //SWRESET
|
||||
ReadBusy();
|
||||
|
||||
SendCommand(0x45); //set Ram-Y address start/end position
|
||||
SendData(0x00);
|
||||
SendData(0x00);
|
||||
SendData(0x07); //0x0107-->(263+1)=264
|
||||
SendData(0x01);
|
||||
|
||||
SendCommand(0x4F); // set RAM y address count to 0;
|
||||
SendData(0x00);
|
||||
SendData(0x00);
|
||||
|
||||
SendCommand(0x11); // data entry mode
|
||||
SendData(0x03);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Epd::Init_Fast(void) {
|
||||
/* this calls the peripheral hardware interface, see epdif */
|
||||
if (IfInit() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reset();
|
||||
ReadBusy();
|
||||
|
||||
SendCommand(0x12); //SWRESET
|
||||
ReadBusy();
|
||||
|
||||
SendCommand(0x18); //Read built-in temperature sensor
|
||||
SendData(0x80);
|
||||
|
||||
SendCommand(0x22); // Load temperature value
|
||||
SendData(0xB1);
|
||||
SendCommand(0x20);
|
||||
ReadBusy();
|
||||
|
||||
SendCommand(0x1A); // Write to temperature register
|
||||
SendData(0x64);
|
||||
SendData(0x00);
|
||||
|
||||
SendCommand(0x45); //set Ram-Y address start/end position
|
||||
SendData(0x00);
|
||||
SendData(0x00);
|
||||
SendData(0x07); //0x0107-->(263+1)=264
|
||||
SendData(0x01);
|
||||
|
||||
SendCommand(0x4F); // set RAM y address count to 0;
|
||||
SendData(0x00);
|
||||
SendData(0x00);
|
||||
|
||||
SendCommand(0x11); // data entry mode
|
||||
SendData(0x03);
|
||||
|
||||
SendCommand(0x22); // Load temperature value
|
||||
SendData(0x91);
|
||||
SendCommand(0x20);
|
||||
ReadBusy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Epd::Init_4Gray(void)
|
||||
{
|
||||
Reset();
|
||||
|
||||
ReadBusy();
|
||||
SendCommand(0x12); // soft reset
|
||||
ReadBusy();
|
||||
|
||||
SendCommand(0x74); //set analog block control
|
||||
SendData(0x54);
|
||||
SendCommand(0x7E); //set digital block control
|
||||
SendData(0x3B);
|
||||
|
||||
SendCommand(0x01); //Driver output control
|
||||
SendData(0x07);
|
||||
SendData(0x01);
|
||||
SendData(0x00);
|
||||
|
||||
SendCommand(0x11); //data entry mode
|
||||
SendData(0x03);
|
||||
|
||||
SendCommand(0x44); //set Ram-X address start/end position
|
||||
SendData(0x00);
|
||||
SendData(0x15); //0x15-->(21+1)*8=176
|
||||
|
||||
SendCommand(0x45); //set Ram-Y address start/end position
|
||||
SendData(0x00);
|
||||
SendData(0x00);
|
||||
SendData(0x07);//0x0107-->(263+1)=264
|
||||
SendData(0x01);
|
||||
|
||||
|
||||
SendCommand(0x3C); //BorderWavefrom
|
||||
SendData(0x00);
|
||||
|
||||
|
||||
SendCommand(0x2C); //VCOM Voltage
|
||||
SendData(LUT_DATA_4Gray[158]); //0x1C
|
||||
|
||||
|
||||
SendCommand(0x3F); //EOPQ
|
||||
SendData(LUT_DATA_4Gray[153]);
|
||||
|
||||
SendCommand(0x03); //VGH
|
||||
SendData(LUT_DATA_4Gray[154]);
|
||||
|
||||
SendCommand(0x04); //
|
||||
SendData(LUT_DATA_4Gray[155]); //VSH1
|
||||
SendData(LUT_DATA_4Gray[156]); //VSH2
|
||||
SendData(LUT_DATA_4Gray[157]); //VSL
|
||||
|
||||
Lut(); //LUT
|
||||
|
||||
|
||||
SendCommand(0x4E); // set RAM x address count to 0;
|
||||
SendData(0x00);
|
||||
SendCommand(0x4F); // set RAM y address count to 0X199;
|
||||
SendData(0x00);
|
||||
SendData(0x00);
|
||||
ReadBusy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
Serial.print("e-Paper busy\r\n");
|
||||
while(DigitalRead(busy_pin) == 1) { //1: busy, 0: idle
|
||||
DelayMs(100);
|
||||
}
|
||||
Serial.print("e-Paper busy release\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(200);
|
||||
DigitalWrite(reset_pin, LOW);
|
||||
DelayMs(2);
|
||||
DigitalWrite(reset_pin, HIGH);
|
||||
DelayMs(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: set the look-up tables
|
||||
*/
|
||||
void Epd::Lut(void) {
|
||||
unsigned int count;
|
||||
SendCommand(0x32); //vcom
|
||||
for(count = 0; count < 153; count++) {
|
||||
SendData(LUT_DATA_4Gray[count]);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Turn on display
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void Epd::TurnOnDisplay(void)
|
||||
{
|
||||
SendCommand(0x22); //Display Update Control
|
||||
SendData(0xF7);
|
||||
SendCommand(0x20); //Activate Display Update Sequence
|
||||
ReadBusy();
|
||||
}
|
||||
|
||||
void Epd::TurnOnDisplay_Fast(void)
|
||||
{
|
||||
SendCommand(0x22); //Display Update Control
|
||||
SendData(0xC7);
|
||||
SendCommand(0x20); //Activate Display Update Sequence
|
||||
ReadBusy();
|
||||
}
|
||||
|
||||
void Epd::TurnOnDisplay_Partial(void)
|
||||
{
|
||||
SendCommand(0x22);
|
||||
SendData(0xFF);
|
||||
SendCommand(0x20);
|
||||
ReadBusy();
|
||||
}
|
||||
|
||||
void Epd::TurnOnDisplay_4GRAY(void)
|
||||
{
|
||||
SendCommand(0x22);
|
||||
SendData(0xC7);
|
||||
SendCommand(0x20);
|
||||
ReadBusy();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Clear screen
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void Epd::Clear(void)
|
||||
{
|
||||
unsigned int Width, Height;
|
||||
Width = (WIDTH % 8 == 0)? (WIDTH / 8 ): (WIDTH / 8 + 1);
|
||||
Height = HEIGHT;
|
||||
|
||||
SendCommand(0x24);
|
||||
for (unsigned int j = 0; j < Height; j++) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
SendData(0XFF);
|
||||
}
|
||||
}
|
||||
TurnOnDisplay();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Sends the image buffer in RAM to e-Paper and displays
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void Epd::Display(const unsigned char* Image)
|
||||
{
|
||||
unsigned int Width, Height;
|
||||
Width = (WIDTH % 8 == 0)? (WIDTH / 8 ): (WIDTH / 8 + 1);
|
||||
Height = HEIGHT;
|
||||
|
||||
SendCommand(0x24);
|
||||
for (unsigned int j = 0; j < Height; j++) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
SendData(pgm_read_byte(&Image[i + j * Width]));
|
||||
}
|
||||
}
|
||||
TurnOnDisplay();
|
||||
}
|
||||
|
||||
void Epd::Display_Fast(const unsigned char* Image)
|
||||
{
|
||||
unsigned int Width, Height;
|
||||
Width = (WIDTH % 8 == 0)? (WIDTH / 8 ): (WIDTH / 8 + 1);
|
||||
Height = HEIGHT;
|
||||
|
||||
SendCommand(0x24);
|
||||
for (unsigned int j = 0; j < Height; j++) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
SendData(pgm_read_byte(&Image[i + j * Width]));
|
||||
}
|
||||
}
|
||||
TurnOnDisplay_Fast();
|
||||
}
|
||||
|
||||
void Epd::Display_Base(const unsigned char* Image)
|
||||
{
|
||||
unsigned int Width, Height;
|
||||
Width = (WIDTH % 8 == 0)? (WIDTH / 8 ): (WIDTH / 8 + 1);
|
||||
Height = HEIGHT;
|
||||
|
||||
SendCommand(0x24); //Write Black and White image to RAM
|
||||
for (unsigned int j = 0; j < Height; j++) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
SendData(pgm_read_byte(&Image[i + j * Width]));
|
||||
}
|
||||
}
|
||||
SendCommand(0x26); //Write Black and White image to RAM
|
||||
for (unsigned int j = 0; j < Height; j++) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
SendData(pgm_read_byte(&Image[i + j * Width]));
|
||||
}
|
||||
}
|
||||
TurnOnDisplay();
|
||||
}
|
||||
|
||||
void Epd::Display_Base_color(unsigned char color)
|
||||
{
|
||||
unsigned int Width, Height;
|
||||
Width = (WIDTH % 8 == 0)? (WIDTH / 8 ): (WIDTH / 8 + 1);
|
||||
Height = HEIGHT;
|
||||
|
||||
SendCommand(0x24); //Write Black and White image to RAM
|
||||
for (unsigned int j = 0; j < Height; j++) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
SendData(color);
|
||||
}
|
||||
}
|
||||
SendCommand(0x26); //Write Black and White image to RAM
|
||||
for (unsigned int j = 0; j < Height; j++) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
SendData(color);
|
||||
}
|
||||
}
|
||||
// TurnOnDisplay();
|
||||
}
|
||||
|
||||
void Epd::Display_Partial(unsigned char* Image, unsigned int Xstart, unsigned int Ystart, unsigned int Xend, unsigned int Yend)
|
||||
{
|
||||
|
||||
unsigned int i, Width;
|
||||
unsigned int IMAGE_COUNTER;
|
||||
|
||||
if((Xstart % 8 + Xend % 8 == 8 && Xstart % 8 > Xend % 8) || Xstart % 8 + Xend % 8 == 0 || (Xend - Xstart)%8 == 0)
|
||||
{
|
||||
Xstart = Xstart / 8 ;
|
||||
Xend = Xend / 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
Xstart = Xstart / 8 ;
|
||||
Xend = Xend % 8 == 0 ? Xend / 8 : Xend / 8 + 1;
|
||||
}
|
||||
|
||||
Width = Xend - Xstart;
|
||||
IMAGE_COUNTER = Width * (Yend-Ystart);
|
||||
Serial.println(IMAGE_COUNTER);
|
||||
|
||||
Xend -= 1;
|
||||
Yend -= 1;
|
||||
//Reset
|
||||
Reset();
|
||||
|
||||
SendCommand(0x3C); //BorderWavefrom
|
||||
SendData(0x80);
|
||||
//
|
||||
SendCommand(0x44); // set RAM x address start/end, in page 35
|
||||
SendData(Xstart & 0xff); // RAM x address start at 00h;
|
||||
SendData(Xend & 0xff); // RAM x address end at 0fh(15+1)*8->128
|
||||
SendCommand(0x45); // set RAM y address start/end, in page 35
|
||||
SendData(Ystart & 0xff); // RAM y address start at 0127h;
|
||||
SendData((Ystart>>8) & 0x01); // RAM y address start at 0127h;
|
||||
SendData(Yend & 0xff); // RAM y address end at 00h;
|
||||
SendData((Yend>>8) & 0x01);
|
||||
|
||||
SendCommand(0x4E); // set RAM x address count to 0;
|
||||
SendData(Xstart & 0xff);
|
||||
SendCommand(0x4F); // set RAM y address count to 0X127;
|
||||
SendData(Ystart & 0xff);
|
||||
SendData((Ystart>>8) & 0x01);
|
||||
|
||||
|
||||
SendCommand(0x24); //Write Black and White image to RAM
|
||||
for (i = 0; i < IMAGE_COUNTER; i++) {
|
||||
SendData(Image[i]);
|
||||
}
|
||||
TurnOnDisplay_Partial();
|
||||
}
|
||||
|
||||
void Epd::Display_Partial_Not_refresh(unsigned char* Image, unsigned int Xstart, unsigned int Ystart, unsigned int Xend, unsigned int Yend)
|
||||
{
|
||||
|
||||
unsigned int i, Width;
|
||||
unsigned int IMAGE_COUNTER;
|
||||
|
||||
if((Xstart % 8 + Xend % 8 == 8 && Xstart % 8 > Xend % 8) || Xstart % 8 + Xend % 8 == 0 || (Xend - Xstart)%8 == 0)
|
||||
{
|
||||
Xstart = Xstart / 8 ;
|
||||
Xend = Xend / 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
Xstart = Xstart / 8 ;
|
||||
Xend = Xend % 8 == 0 ? Xend / 8 : Xend / 8 + 1;
|
||||
}
|
||||
|
||||
Width = Xend - Xstart;
|
||||
IMAGE_COUNTER = Width * (Yend-Ystart);
|
||||
Serial.println(IMAGE_COUNTER);
|
||||
|
||||
Xend -= 1;
|
||||
Yend -= 1;
|
||||
//Reset
|
||||
Reset();
|
||||
|
||||
SendCommand(0x3C); //BorderWavefrom
|
||||
SendData(0x80);
|
||||
//
|
||||
SendCommand(0x44); // set RAM x address start/end, in page 35
|
||||
SendData(Xstart & 0xff); // RAM x address start at 00h;
|
||||
SendData(Xend & 0xff); // RAM x address end at 0fh(15+1)*8->128
|
||||
SendCommand(0x45); // set RAM y address start/end, in page 35
|
||||
SendData(Ystart & 0xff); // RAM y address start at 0127h;
|
||||
SendData((Ystart>>8) & 0x01); // RAM y address start at 0127h;
|
||||
SendData(Yend & 0xff); // RAM y address end at 00h;
|
||||
SendData((Yend>>8) & 0x01);
|
||||
|
||||
SendCommand(0x4E); // set RAM x address count to 0;
|
||||
SendData(Xstart & 0xff);
|
||||
SendCommand(0x4F); // set RAM y address count to 0X127;
|
||||
SendData(Ystart & 0xff);
|
||||
SendData((Ystart>>8) & 0x01);
|
||||
|
||||
|
||||
SendCommand(0x24); //Write Black and White image to RAM
|
||||
for (i = 0; i < IMAGE_COUNTER; i++) {
|
||||
SendData(Image[i]);
|
||||
}
|
||||
// TurnOnDisplay_Partial();
|
||||
}
|
||||
|
||||
void Epd::Display4Gray(const unsigned char *Image)
|
||||
{
|
||||
int i,j,k;
|
||||
unsigned char temp1,temp2,temp3;
|
||||
|
||||
SendCommand(0x24);
|
||||
for(i=0;i<5808;i++) //5808*4 46464
|
||||
{
|
||||
temp3=0;
|
||||
for(j=0;j<2;j++)
|
||||
{
|
||||
temp1 = pgm_read_byte(&Image[i*2+j]);
|
||||
for(k=0;k<2;k++)
|
||||
{
|
||||
temp2 = temp1&0xC0 ;
|
||||
if(temp2 == 0xC0)
|
||||
temp3 |= 0x00;//white
|
||||
else if(temp2 == 0x00)
|
||||
temp3 |= 0x01; //black
|
||||
else if(temp2 == 0x80)
|
||||
temp3 |= 0x01; //gray1
|
||||
else //0x40
|
||||
temp3 |= 0x00; //gray2
|
||||
temp3 <<= 1;
|
||||
|
||||
temp1 <<= 2;
|
||||
temp2 = temp1&0xC0 ;
|
||||
if(temp2 == 0xC0) //white
|
||||
temp3 |= 0x00;
|
||||
else if(temp2 == 0x00) //black
|
||||
temp3 |= 0x01;
|
||||
else if(temp2 == 0x80)
|
||||
temp3 |= 0x01; //gray1
|
||||
else //0x40
|
||||
temp3 |= 0x00; //gray2
|
||||
if(j!=1 || k!=1)
|
||||
temp3 <<= 1;
|
||||
|
||||
temp1 <<= 2;
|
||||
}
|
||||
|
||||
}
|
||||
SendData(temp3);
|
||||
}
|
||||
// new data
|
||||
SendCommand(0x26);
|
||||
for(i=0;i<5808;i++) //5808*4 46464
|
||||
{
|
||||
temp3=0;
|
||||
for(j=0;j<2;j++)
|
||||
{
|
||||
temp1 = pgm_read_byte(&Image[i*2+j]);
|
||||
for(k=0;k<2;k++)
|
||||
{
|
||||
temp2 = temp1&0xC0 ;
|
||||
if(temp2 == 0xC0)
|
||||
temp3 |= 0x00;//white
|
||||
else if(temp2 == 0x00)
|
||||
temp3 |= 0x01; //black
|
||||
else if(temp2 == 0x80)
|
||||
temp3 |= 0x00; //gray1
|
||||
else //0x40
|
||||
temp3 |= 0x01; //gray2
|
||||
temp3 <<= 1;
|
||||
|
||||
temp1 <<= 2;
|
||||
temp2 = temp1&0xC0 ;
|
||||
if(temp2 == 0xC0) //white
|
||||
temp3 |= 0x00;
|
||||
else if(temp2 == 0x00) //black
|
||||
temp3 |= 0x01;
|
||||
else if(temp2 == 0x80)
|
||||
temp3 |= 0x00; //gray1
|
||||
else //0x40
|
||||
temp3 |= 0x01; //gray2
|
||||
if(j!=1 || k!=1)
|
||||
temp3 <<= 1;
|
||||
|
||||
temp1 <<= 2;
|
||||
}
|
||||
|
||||
}
|
||||
SendData(temp3);
|
||||
}
|
||||
|
||||
TurnOnDisplay_4GRAY();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 and use Epd::Init() to initialize.
|
||||
*/
|
||||
void Epd::Sleep() {
|
||||
SendCommand(0X10);
|
||||
SendData(0x01);
|
||||
}
|
||||
75
Arduino/epd2in7_V2/epd2in7_V2.h
Normal file
75
Arduino/epd2in7_V2/epd2in7_V2.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* @filename : epd2in7_V2.h
|
||||
* @brief : Header file for e-paper library epd2in7_V2.cpp
|
||||
* @author : Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare September 20 2022
|
||||
*
|
||||
* 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 EPD2IN7_V2_H
|
||||
#define EPD2IN7_V2_H
|
||||
|
||||
#include "epdif.h"
|
||||
|
||||
// Display resolution
|
||||
#define EPD_WIDTH 176
|
||||
#define EPD_HEIGHT 264
|
||||
|
||||
|
||||
class Epd : EpdIf {
|
||||
public:
|
||||
unsigned int WIDTH;
|
||||
unsigned int HEIGHT;
|
||||
|
||||
Epd();
|
||||
~Epd();
|
||||
int Init(void);
|
||||
int Init_Fast(void);
|
||||
void Init_4Gray(void);
|
||||
void SendCommand(unsigned char command);
|
||||
void SendData(unsigned char data);
|
||||
void ReadBusy(void);
|
||||
void Reset(void);
|
||||
void Lut(void);
|
||||
void TurnOnDisplay(void);
|
||||
void TurnOnDisplay_Fast(void);
|
||||
void TurnOnDisplay_Partial(void);
|
||||
void TurnOnDisplay_4GRAY(void);
|
||||
void Clear(void);
|
||||
void Display(const unsigned char* Image);
|
||||
void Display_Fast(const unsigned char* Image);
|
||||
void Display_Base(const unsigned char* Image);
|
||||
void Display_Base_color(unsigned char color);
|
||||
void Display_Partial(unsigned char* Image, unsigned int Xstart, unsigned int Ystart, unsigned int Xend, unsigned int Yend);
|
||||
void Display_Partial_Not_refresh(unsigned char* Image, unsigned int Xstart, unsigned int Ystart, unsigned int Xend, unsigned int Yend);
|
||||
void Display4Gray(const unsigned char *Image);
|
||||
void Sleep(void);
|
||||
|
||||
private:
|
||||
unsigned int reset_pin;
|
||||
unsigned int dc_pin;
|
||||
unsigned int cs_pin;
|
||||
unsigned int busy_pin;
|
||||
};
|
||||
|
||||
#endif /* EPD2IN7_H */
|
||||
|
||||
/* END OF FILE */
|
||||
114
Arduino/epd2in7_V2/epd2in7_V2.ino
Normal file
114
Arduino/epd2in7_V2/epd2in7_V2.ino
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/**
|
||||
@filename : epd2in7_V2-demo.ino
|
||||
@brief : 2.7inch e-paper display demo
|
||||
@author : Waveshare
|
||||
|
||||
Copyright (C) Waveshare September 20 2022
|
||||
|
||||
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 "epd2in7_V2.h"
|
||||
#include "imagedata.h"
|
||||
#include "epdpaint.h"
|
||||
|
||||
#define COLORED 0
|
||||
#define UNCOLORED 1
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* This clears the SRAM of the e-paper display */
|
||||
epd.Clear();
|
||||
|
||||
/**
|
||||
Due to RAM not enough in Arduino UNO, a frame buffer is not allowed.
|
||||
In this case, a smaller image buffer is allocated and you have to
|
||||
update a partial display several times.
|
||||
1 byte = 8 pixels, therefore you have to set 8*N pixels at a time.
|
||||
*/
|
||||
#if 1
|
||||
epd.Display_Base_color(0xff);
|
||||
unsigned char image[1024];
|
||||
Paint paint(image, 176, 24); //width should be the multiple of 8
|
||||
|
||||
paint.Clear(UNCOLORED);
|
||||
paint.DrawStringAt(20, 5, "e-Paper Demo", &Font16, COLORED);
|
||||
epd.Display_Partial_Not_refresh(paint.GetImage(), 0, 32, 0+paint.GetWidth(), 32+paint.GetHeight());
|
||||
|
||||
paint.Clear(COLORED);
|
||||
paint.DrawStringAt(20, 5, "Hello world!", &Font16, UNCOLORED);
|
||||
epd.Display_Partial_Not_refresh(paint.GetImage(), 0, 64, 0+paint.GetWidth(), 64+paint.GetHeight());
|
||||
|
||||
paint.SetWidth(64);
|
||||
paint.SetHeight(64);
|
||||
|
||||
paint.Clear(UNCOLORED);
|
||||
paint.DrawRectangle(0, 0, 40, 50, COLORED);
|
||||
paint.DrawLine(0, 0, 40, 50, COLORED);
|
||||
paint.DrawLine(40, 0, 0, 50, COLORED);
|
||||
epd.Display_Partial_Not_refresh(paint.GetImage(), 10, 130, 10+paint.GetWidth(), 130+paint.GetHeight());
|
||||
|
||||
paint.Clear(UNCOLORED);
|
||||
paint.DrawCircle(32, 32, 30, COLORED);
|
||||
epd.Display_Partial_Not_refresh(paint.GetImage(), 90, 120, 90+paint.GetWidth(), 120+paint.GetHeight());
|
||||
|
||||
paint.Clear(UNCOLORED);
|
||||
paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
|
||||
epd.Display_Partial_Not_refresh(paint.GetImage(), 10, 200, 10+paint.GetWidth(), 200+paint.GetHeight());
|
||||
|
||||
paint.Clear(UNCOLORED);
|
||||
paint.DrawFilledCircle(32, 32, 30, COLORED);
|
||||
epd.Display_Partial(paint.GetImage(), 90, 190, 90+paint.GetWidth(), 190+paint.GetHeight());
|
||||
|
||||
delay(1000);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
/* This displays an image */
|
||||
epd.Init();
|
||||
Serial.print("show 2-gray image\r\n");
|
||||
epd.Display(IMAGE_DATA);
|
||||
delay(1000);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
Serial.print("show 4-gray image\r\n");
|
||||
epd.Init_4Gray();
|
||||
epd.Display4Gray(IMAGE_DATA_4Gray);
|
||||
#endif
|
||||
|
||||
/* Deep sleep */
|
||||
Serial.print("sleep...");
|
||||
epd.Sleep();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
||||
64
Arduino/epd2in7_V2/epdif.cpp
Normal file
64
Arduino/epd2in7_V2/epdif.cpp
Normal 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/epd2in7_V2/epdif.h
Normal file
51
Arduino/epd2in7_V2/epdif.h
Normal 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
|
||||
342
Arduino/epd2in7_V2/epdpaint.cpp
Normal file
342
Arduino/epd2in7_V2/epdpaint.cpp
Normal file
|
|
@ -0,0 +1,342 @@
|
|||
/**
|
||||
* @filename : epdpaint.cpp
|
||||
* @brief : Paint tools
|
||||
* @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 <avr/pgmspace.h>
|
||||
#include "epdpaint.h"
|
||||
|
||||
Paint::Paint(unsigned char* image, int width, int height) {
|
||||
this->rotate = ROTATE_0;
|
||||
this->image = image;
|
||||
/* 1 byte = 8 pixels, so the width should be the multiple of 8 */
|
||||
this->width = width % 8 ? width + 8 - (width % 8) : width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
Paint::~Paint() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: clear the image
|
||||
*/
|
||||
void Paint::Clear(int colored) {
|
||||
for (int x = 0; x < this->width; x++) {
|
||||
for (int y = 0; y < this->height; y++) {
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a pixel by absolute coordinates.
|
||||
* this function won't be affected by the rotate parameter.
|
||||
*/
|
||||
void Paint::DrawAbsolutePixel(int x, int y, int colored) {
|
||||
if (x < 0 || x >= this->width || y < 0 || y >= this->height) {
|
||||
return;
|
||||
}
|
||||
if (IF_INVERT_COLOR) {
|
||||
if (colored) {
|
||||
image[(x + y * this->width) / 8] |= 0x80 >> (x % 8);
|
||||
} else {
|
||||
image[(x + y * this->width) / 8] &= ~(0x80 >> (x % 8));
|
||||
}
|
||||
} else {
|
||||
if (colored) {
|
||||
image[(x + y * this->width) / 8] &= ~(0x80 >> (x % 8));
|
||||
} else {
|
||||
image[(x + y * this->width) / 8] |= 0x80 >> (x % 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: Getters and Setters
|
||||
*/
|
||||
unsigned char* Paint::GetImage(void) {
|
||||
return this->image;
|
||||
}
|
||||
|
||||
int Paint::GetWidth(void) {
|
||||
return this->width;
|
||||
}
|
||||
|
||||
void Paint::SetWidth(int width) {
|
||||
this->width = width % 8 ? width + 8 - (width % 8) : width;
|
||||
}
|
||||
|
||||
int Paint::GetHeight(void) {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
void Paint::SetHeight(int height) {
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
int Paint::GetRotate(void) {
|
||||
return this->rotate;
|
||||
}
|
||||
|
||||
void Paint::SetRotate(int rotate){
|
||||
this->rotate = rotate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a pixel by the coordinates
|
||||
*/
|
||||
void Paint::DrawPixel(int x, int y, int colored) {
|
||||
int point_temp;
|
||||
if (this->rotate == ROTATE_0) {
|
||||
if(x < 0 || x >= this->width || y < 0 || y >= this->height) {
|
||||
return;
|
||||
}
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
} else if (this->rotate == ROTATE_90) {
|
||||
if(x < 0 || x >= this->height || y < 0 || y >= this->width) {
|
||||
return;
|
||||
}
|
||||
point_temp = x;
|
||||
x = this->width - y;
|
||||
y = point_temp;
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
} else if (this->rotate == ROTATE_180) {
|
||||
if(x < 0 || x >= this->width || y < 0 || y >= this->height) {
|
||||
return;
|
||||
}
|
||||
x = this->width - x;
|
||||
y = this->height - y;
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
} else if (this->rotate == ROTATE_270) {
|
||||
if(x < 0 || x >= this->height || y < 0 || y >= this->width) {
|
||||
return;
|
||||
}
|
||||
point_temp = x;
|
||||
x = y;
|
||||
y = this->height - point_temp;
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a charactor on the frame buffer but not refresh
|
||||
*/
|
||||
void Paint::DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored) {
|
||||
int i, j;
|
||||
unsigned int char_offset = (ascii_char - ' ') * font->Height * (font->Width / 8 + (font->Width % 8 ? 1 : 0));
|
||||
const unsigned char* ptr = &font->table[char_offset];
|
||||
|
||||
for (j = 0; j < font->Height; j++) {
|
||||
for (i = 0; i < font->Width; i++) {
|
||||
if (pgm_read_byte(ptr) & (0x80 >> (i % 8))) {
|
||||
DrawPixel(x + i, y + j, colored);
|
||||
}
|
||||
if (i % 8 == 7) {
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
if (font->Width % 8 != 0) {
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this displays a string on the frame buffer but not refresh
|
||||
*/
|
||||
void Paint::DrawStringAt(int x, int y, const char* text, sFONT* font, int colored) {
|
||||
const char* p_text = text;
|
||||
unsigned int counter = 0;
|
||||
int refcolumn = x;
|
||||
|
||||
/* Send the string character by character on EPD */
|
||||
while (*p_text != 0) {
|
||||
/* Display one character on EPD */
|
||||
DrawCharAt(refcolumn, y, *p_text, font, colored);
|
||||
/* Decrement the column position by 16 */
|
||||
refcolumn += font->Width;
|
||||
/* Point on the next character */
|
||||
p_text++;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a line on the frame buffer
|
||||
*/
|
||||
void Paint::DrawLine(int x0, int y0, int x1, int y1, int colored) {
|
||||
/* Bresenham algorithm */
|
||||
int dx = x1 - x0 >= 0 ? x1 - x0 : x0 - x1;
|
||||
int sx = x0 < x1 ? 1 : -1;
|
||||
int dy = y1 - y0 <= 0 ? y1 - y0 : y0 - y1;
|
||||
int sy = y0 < y1 ? 1 : -1;
|
||||
int err = dx + dy;
|
||||
|
||||
while((x0 != x1) && (y0 != y1)) {
|
||||
DrawPixel(x0, y0 , colored);
|
||||
if (2 * err >= dy) {
|
||||
err += dy;
|
||||
x0 += sx;
|
||||
}
|
||||
if (2 * err <= dx) {
|
||||
err += dx;
|
||||
y0 += sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a horizontal line on the frame buffer
|
||||
*/
|
||||
void Paint::DrawHorizontalLine(int x, int y, int line_width, int colored) {
|
||||
int i;
|
||||
for (i = x; i < x + line_width; i++) {
|
||||
DrawPixel(i, y, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a vertical line on the frame buffer
|
||||
*/
|
||||
void Paint::DrawVerticalLine(int x, int y, int line_height, int colored) {
|
||||
int i;
|
||||
for (i = y; i < y + line_height; i++) {
|
||||
DrawPixel(x, i, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a rectangle
|
||||
*/
|
||||
void Paint::DrawRectangle(int x0, int y0, int x1, int y1, int colored) {
|
||||
int min_x, min_y, max_x, max_y;
|
||||
min_x = x1 > x0 ? x0 : x1;
|
||||
max_x = x1 > x0 ? x1 : x0;
|
||||
min_y = y1 > y0 ? y0 : y1;
|
||||
max_y = y1 > y0 ? y1 : y0;
|
||||
|
||||
DrawHorizontalLine(min_x, min_y, max_x - min_x + 1, colored);
|
||||
DrawHorizontalLine(min_x, max_y, max_x - min_x + 1, colored);
|
||||
DrawVerticalLine(min_x, min_y, max_y - min_y + 1, colored);
|
||||
DrawVerticalLine(max_x, min_y, max_y - min_y + 1, colored);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a filled rectangle
|
||||
*/
|
||||
void Paint::DrawFilledRectangle(int x0, int y0, int x1, int y1, int colored) {
|
||||
int min_x, min_y, max_x, max_y;
|
||||
int i;
|
||||
min_x = x1 > x0 ? x0 : x1;
|
||||
max_x = x1 > x0 ? x1 : x0;
|
||||
min_y = y1 > y0 ? y0 : y1;
|
||||
max_y = y1 > y0 ? y1 : y0;
|
||||
|
||||
for (i = min_x; i <= max_x; i++) {
|
||||
DrawVerticalLine(i, min_y, max_y - min_y + 1, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a circle
|
||||
*/
|
||||
void Paint::DrawCircle(int x, int y, int radius, int colored) {
|
||||
/* Bresenham algorithm */
|
||||
int x_pos = -radius;
|
||||
int y_pos = 0;
|
||||
int err = 2 - 2 * radius;
|
||||
int e2;
|
||||
|
||||
do {
|
||||
DrawPixel(x - x_pos, y + y_pos, colored);
|
||||
DrawPixel(x + x_pos, y + y_pos, colored);
|
||||
DrawPixel(x + x_pos, y - y_pos, colored);
|
||||
DrawPixel(x - x_pos, y - y_pos, colored);
|
||||
e2 = err;
|
||||
if (e2 <= y_pos) {
|
||||
err += ++y_pos * 2 + 1;
|
||||
if(-x_pos == y_pos && e2 <= x_pos) {
|
||||
e2 = 0;
|
||||
}
|
||||
}
|
||||
if (e2 > x_pos) {
|
||||
err += ++x_pos * 2 + 1;
|
||||
}
|
||||
} while (x_pos <= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a filled circle
|
||||
*/
|
||||
void Paint::DrawFilledCircle(int x, int y, int radius, int colored) {
|
||||
/* Bresenham algorithm */
|
||||
int x_pos = -radius;
|
||||
int y_pos = 0;
|
||||
int err = 2 - 2 * radius;
|
||||
int e2;
|
||||
|
||||
do {
|
||||
DrawPixel(x - x_pos, y + y_pos, colored);
|
||||
DrawPixel(x + x_pos, y + y_pos, colored);
|
||||
DrawPixel(x + x_pos, y - y_pos, colored);
|
||||
DrawPixel(x - x_pos, y - y_pos, colored);
|
||||
DrawHorizontalLine(x + x_pos, y + y_pos, 2 * (-x_pos) + 1, colored);
|
||||
DrawHorizontalLine(x + x_pos, y - y_pos, 2 * (-x_pos) + 1, colored);
|
||||
e2 = err;
|
||||
if (e2 <= y_pos) {
|
||||
err += ++y_pos * 2 + 1;
|
||||
if(-x_pos == y_pos && e2 <= x_pos) {
|
||||
e2 = 0;
|
||||
}
|
||||
}
|
||||
if(e2 > x_pos) {
|
||||
err += ++x_pos * 2 + 1;
|
||||
}
|
||||
} while(x_pos <= 0);
|
||||
}
|
||||
|
||||
/* END OF FILE */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
75
Arduino/epd2in7_V2/epdpaint.h
Normal file
75
Arduino/epd2in7_V2/epdpaint.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* @filename : epdpaint.h
|
||||
* @brief : Header file for epdpaint.cpp
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare July 28 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 EPDPAINT_H
|
||||
#define EPDPAINT_H
|
||||
|
||||
// Display orientation
|
||||
#define ROTATE_0 0
|
||||
#define ROTATE_90 1
|
||||
#define ROTATE_180 2
|
||||
#define ROTATE_270 3
|
||||
|
||||
// Color inverse. 1 or 0 = set or reset a bit if set a colored pixel
|
||||
#define IF_INVERT_COLOR 1
|
||||
|
||||
#include "fonts.h"
|
||||
|
||||
class Paint {
|
||||
public:
|
||||
Paint(unsigned char* image, int width, int height);
|
||||
~Paint();
|
||||
void Clear(int colored);
|
||||
int GetWidth(void);
|
||||
void SetWidth(int width);
|
||||
int GetHeight(void);
|
||||
void SetHeight(int height);
|
||||
int GetRotate(void);
|
||||
void SetRotate(int rotate);
|
||||
unsigned char* GetImage(void);
|
||||
void DrawAbsolutePixel(int x, int y, int colored);
|
||||
void DrawPixel(int x, int y, int colored);
|
||||
void DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored);
|
||||
void DrawStringAt(int x, int y, const char* text, sFONT* font, int colored);
|
||||
void DrawLine(int x0, int y0, int x1, int y1, int colored);
|
||||
void DrawHorizontalLine(int x, int y, int width, int colored);
|
||||
void DrawVerticalLine(int x, int y, int height, int colored);
|
||||
void DrawRectangle(int x0, int y0, int x1, int y1, int colored);
|
||||
void DrawFilledRectangle(int x0, int y0, int x1, int y1, int colored);
|
||||
void DrawCircle(int x, int y, int radius, int colored);
|
||||
void DrawFilledCircle(int x, int y, int radius, int colored);
|
||||
|
||||
private:
|
||||
unsigned char* image;
|
||||
int width;
|
||||
int height;
|
||||
int rotate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* END OF FILE */
|
||||
|
||||
1385
Arduino/epd2in7_V2/font12.cpp
Normal file
1385
Arduino/epd2in7_V2/font12.cpp
Normal file
File diff suppressed because it is too large
Load diff
1765
Arduino/epd2in7_V2/font16.cpp
Normal file
1765
Arduino/epd2in7_V2/font16.cpp
Normal file
File diff suppressed because it is too large
Load diff
2143
Arduino/epd2in7_V2/font20.cpp
Normal file
2143
Arduino/epd2in7_V2/font20.cpp
Normal file
File diff suppressed because it is too large
Load diff
2521
Arduino/epd2in7_V2/font24.cpp
Normal file
2521
Arduino/epd2in7_V2/font24.cpp
Normal file
File diff suppressed because it is too large
Load diff
1005
Arduino/epd2in7_V2/font8.cpp
Normal file
1005
Arduino/epd2in7_V2/font8.cpp
Normal file
File diff suppressed because it is too large
Load diff
65
Arduino/epd2in7_V2/fonts.h
Normal file
65
Arduino/epd2in7_V2/fonts.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file fonts.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief Header for fonts.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __FONTS_H
|
||||
#define __FONTS_H
|
||||
|
||||
/* Max size of bitmap will based on a font24 (17x24) */
|
||||
#define MAX_HEIGHT_FONT 24
|
||||
#define MAX_WIDTH_FONT 17
|
||||
#define OFFSET_BITMAP 54
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
struct sFONT {
|
||||
const uint8_t *table;
|
||||
uint16_t Width;
|
||||
uint16_t Height;
|
||||
};
|
||||
|
||||
extern sFONT Font24;
|
||||
extern sFONT Font20;
|
||||
extern sFONT Font16;
|
||||
extern sFONT Font12;
|
||||
extern sFONT Font8;
|
||||
|
||||
#endif /* __FONTS_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
1125
Arduino/epd2in7_V2/imagedata.cpp
Normal file
1125
Arduino/epd2in7_V2/imagedata.cpp
Normal file
File diff suppressed because it is too large
Load diff
32
Arduino/epd2in7_V2/imagedata.h
Normal file
32
Arduino/epd2in7_V2/imagedata.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* @filename : imagedata.h
|
||||
* @brief : head file for imagedata.cpp
|
||||
*
|
||||
* Copyright (C) Waveshare August 18 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.
|
||||
*/
|
||||
|
||||
extern const unsigned char IMAGE_DATA[];
|
||||
extern const unsigned char IMAGE_DATA_4Gray[];
|
||||
|
||||
/* END OF FILE*/
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue