add 4inch epd 4 grayscale.
This commit is contained in:
parent
702def06bc
commit
8ed1b4696c
324 changed files with 14771 additions and 1979 deletions
|
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <epd4in2.h>
|
||||
#include "epd4in2.h"
|
||||
|
||||
Epd::~Epd() {
|
||||
};
|
||||
|
|
@ -39,6 +39,7 @@ Epd::Epd() {
|
|||
height = EPD_HEIGHT;
|
||||
};
|
||||
|
||||
|
||||
int Epd::Init(void) {
|
||||
/* this calls the peripheral hardware interface, see epdif */
|
||||
if (IfInit() != 0) {
|
||||
|
|
@ -67,6 +68,50 @@ int Epd::Init(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Epd::Init_4Gray(void) {
|
||||
/* 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); //VGH=20V,VGL=-20V
|
||||
SendData (0x2b); //VDH=15V
|
||||
SendData (0x2b); //VDL=-15V
|
||||
SendData (0x13);
|
||||
|
||||
SendCommand(0x06); //booster soft start
|
||||
SendData (0x17); //A
|
||||
SendData (0x17); //B
|
||||
SendData (0x17); //C
|
||||
|
||||
SendCommand(0x04);
|
||||
WaitUntilIdle();
|
||||
|
||||
SendCommand(0x00); //panel setting
|
||||
SendData(0x3f); //KW-3f KWR-2F BWROTP 0f BWOTP 1f
|
||||
|
||||
SendCommand(0x30); //PLL setting
|
||||
SendData (0x3c); //100hz
|
||||
|
||||
SendCommand(0x61); //resolution setting
|
||||
SendData (0x01); //400
|
||||
SendData (0x90);
|
||||
SendData (0x01); //300
|
||||
SendData (0x2c);
|
||||
|
||||
SendCommand(0x82); //vcom_DC setting
|
||||
SendData (0x12);
|
||||
|
||||
SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
|
||||
SendData(0x97);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief: basic function for sending commands
|
||||
*/
|
||||
|
|
@ -87,8 +132,10 @@ void Epd::SendData(unsigned char data) {
|
|||
* @brief: Wait until the busy_pin goes HIGH
|
||||
*/
|
||||
void Epd::WaitUntilIdle(void) {
|
||||
SendCommand(0x71);
|
||||
while(DigitalRead(busy_pin) == 0) { //0: busy, 1: idle
|
||||
DelayMs(100);
|
||||
SendCommand(0x71);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,6 +181,117 @@ void Epd::SetPartialWindow(const unsigned char* buffer_black, int x, int y, int
|
|||
SendCommand(PARTIAL_OUT);
|
||||
}
|
||||
|
||||
void Epd::Set_4GrayDisplay(const char *Image, int x, int y, int w, int l)
|
||||
{
|
||||
int i,j,k,m;
|
||||
int z=0;
|
||||
unsigned char temp1,temp2,temp3;
|
||||
/****Color display description****
|
||||
white gray1 gray2 black
|
||||
0x10| 01 01 00 00
|
||||
0x13| 01 00 01 00
|
||||
*********************************/
|
||||
SendCommand(0x10);
|
||||
z=0;
|
||||
x= x/8*8;
|
||||
for(m = 0; m<EPD_HEIGHT;m++)
|
||||
for(i=0;i<EPD_WIDTH/8;i++)
|
||||
{
|
||||
if(i >= x/8 && i <(x+w)/8 && m >= y && m < y+l){
|
||||
|
||||
temp3=0;
|
||||
for(j=0;j<2;j++)
|
||||
{
|
||||
temp1 = pgm_read_byte(&Image[z*2+j]);
|
||||
for(k=0;k<2;k++)
|
||||
{
|
||||
temp2 = temp1&0xC0 ;
|
||||
if(temp2 == 0xC0)
|
||||
temp3 |= 0x01;//white
|
||||
else if(temp2 == 0x00)
|
||||
temp3 |= 0x00; //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 |= 0x01;
|
||||
else if(temp2 == 0x00) //black
|
||||
temp3 |= 0x00;
|
||||
else if(temp2 == 0x80)
|
||||
temp3 |= 0x01; //gray1
|
||||
else //0x40
|
||||
temp3 |= 0x00; //gray2
|
||||
if(j!=1 || k!=1)
|
||||
temp3 <<= 1;
|
||||
|
||||
temp1 <<= 2;
|
||||
}
|
||||
}
|
||||
z++;
|
||||
SendData(temp3);
|
||||
|
||||
}else{
|
||||
SendData(0xff);
|
||||
}
|
||||
}
|
||||
// new data
|
||||
SendCommand(0x13);
|
||||
z=0;
|
||||
for(m = 0; m<EPD_HEIGHT;m++)
|
||||
for(i=0;i<EPD_WIDTH/8;i++)
|
||||
{
|
||||
if(i >= x/8 && i <(x+w)/8 && m >= y && m < y+l){
|
||||
|
||||
temp3=0;
|
||||
for(j=0;j<2;j++)
|
||||
{
|
||||
temp1 = pgm_read_byte(&Image[z*2+j]);
|
||||
for(k=0;k<2;k++)
|
||||
{
|
||||
temp2 = temp1&0xC0 ;
|
||||
if(temp2 == 0xC0)
|
||||
temp3 |= 0x01;//white
|
||||
else if(temp2 == 0x00)
|
||||
temp3 |= 0x00; //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 |= 0x01;
|
||||
else if(temp2 == 0x00) //black
|
||||
temp3 |= 0x00;
|
||||
else if(temp2 == 0x80)
|
||||
temp3 |= 0x00; //gray1
|
||||
else //0x40
|
||||
temp3 |= 0x01; //gray2
|
||||
if(j!=1 || k!=1)
|
||||
temp3 <<= 1;
|
||||
|
||||
temp1 <<= 2;
|
||||
}
|
||||
}
|
||||
z++;
|
||||
SendData(temp3);
|
||||
}else {
|
||||
SendData(0xff);
|
||||
}
|
||||
}
|
||||
|
||||
set4Gray_lut();
|
||||
SendCommand(DISPLAY_REFRESH);
|
||||
DelayMs(100);
|
||||
WaitUntilIdle();
|
||||
}
|
||||
/**
|
||||
* @brief: set the look-up table
|
||||
*/
|
||||
|
|
@ -165,6 +323,35 @@ void Epd::SetLut(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void Epd::set4Gray_lut(void)
|
||||
{
|
||||
unsigned int count;
|
||||
{
|
||||
SendCommand(0x20); //vcom
|
||||
for(count=0;count<42;count++)
|
||||
{SendData(EPD_4IN2_4Gray_lut_vcom[count]);}
|
||||
|
||||
SendCommand(0x21); //red not use
|
||||
for(count=0;count<42;count++)
|
||||
{SendData(EPD_4IN2_4Gray_lut_ww[count]);}
|
||||
|
||||
SendCommand(0x22); //bw r
|
||||
for(count=0;count<42;count++)
|
||||
{SendData(EPD_4IN2_4Gray_lut_bw[count]);}
|
||||
|
||||
SendCommand(0x23); //wb w
|
||||
for(count=0;count<42;count++)
|
||||
{SendData(EPD_4IN2_4Gray_lut_wb[count]);}
|
||||
|
||||
SendCommand(0x24); //bb b
|
||||
for(count=0;count<42;count++)
|
||||
{SendData(EPD_4IN2_4Gray_lut_bb[count]);}
|
||||
|
||||
SendCommand(0x25); //vcom
|
||||
for(count=0;count<42;count++)
|
||||
{SendData(EPD_4IN2_4Gray_lut_ww[count]);}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief: refresh and displays the frame
|
||||
*/
|
||||
|
|
@ -223,6 +410,10 @@ void Epd::ClearFrame(void) {
|
|||
SendData(0xFF);
|
||||
}
|
||||
DelayMs(2);
|
||||
SetLut();
|
||||
SendCommand(DISPLAY_REFRESH);
|
||||
DelayMs(100);
|
||||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -316,11 +507,59 @@ const unsigned char lut_wb[] ={
|
|||
|
||||
};
|
||||
|
||||
/******************************gray*********************************/
|
||||
//0~3 gray
|
||||
const unsigned char EPD_4IN2_4Gray_lut_vcom[] =
|
||||
{
|
||||
0x00 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
|
||||
0x60 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
|
||||
0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
|
||||
0x00 ,0x13 ,0x0A ,0x01 ,0x00 ,0x01,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
|
||||
|
||||
};
|
||||
//R21
|
||||
const unsigned char EPD_4IN2_4Gray_lut_ww[] ={
|
||||
0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
|
||||
0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
|
||||
0x10 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
|
||||
0xA0 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
};
|
||||
//R22H r
|
||||
const unsigned char EPD_4IN2_4Gray_lut_bw[] ={
|
||||
0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
|
||||
0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
|
||||
0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
|
||||
0x99 ,0x0C ,0x01 ,0x03 ,0x04 ,0x01,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
};
|
||||
//R23H w
|
||||
const unsigned char EPD_4IN2_4Gray_lut_wb[] ={
|
||||
0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
|
||||
0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
|
||||
0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
|
||||
0x99 ,0x0B ,0x04 ,0x04 ,0x01 ,0x01,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
};
|
||||
//R24H b
|
||||
const unsigned char EPD_4IN2_4Gray_lut_bb[] ={
|
||||
0x80 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
|
||||
0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
|
||||
0x20 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
|
||||
0x50 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
|
||||
};
|
||||
|
||||
|
||||
/* END OF FILE */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue