2in13_V3 Add some comments
This commit is contained in:
parent
ce75f349ac
commit
0895fc1e5a
4 changed files with 214 additions and 38 deletions
|
|
@ -78,6 +78,10 @@ Epd::~Epd()
|
|||
{
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
function : Pin definition
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
Epd::Epd()
|
||||
{
|
||||
reset_pin = RST_PIN;
|
||||
|
|
@ -88,27 +92,32 @@ Epd::Epd()
|
|||
height = EPD_HEIGHT;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief: basic function for sending commands
|
||||
*/
|
||||
/******************************************************************************
|
||||
function : send command
|
||||
parameter:
|
||||
command : Command register
|
||||
******************************************************************************/
|
||||
void Epd::SendCommand(unsigned char command)
|
||||
{
|
||||
DigitalWrite(dc_pin, LOW);
|
||||
SpiTransfer(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: basic function for sending data
|
||||
*/
|
||||
/******************************************************************************
|
||||
function : send data
|
||||
parameter:
|
||||
Data : Write data
|
||||
******************************************************************************/
|
||||
void Epd::SendData(unsigned char data)
|
||||
{
|
||||
DigitalWrite(dc_pin, HIGH);
|
||||
SpiTransfer(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: Wait until the busy_pin goes HIGH
|
||||
*/
|
||||
/******************************************************************************
|
||||
function : Wait until the busy_pin goes LOW
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void Epd::WaitUntilIdle(void)
|
||||
{
|
||||
while(1) { //LOW: idle, HIGH: busy
|
||||
|
|
@ -118,6 +127,14 @@ void Epd::WaitUntilIdle(void)
|
|||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Setting the display window
|
||||
parameter:
|
||||
Xstart : X-axis starting position
|
||||
Ystart : Y-axis starting position
|
||||
Xend : End position of X-axis
|
||||
Yend : End position of Y-axis
|
||||
******************************************************************************/
|
||||
void Epd::SetWindows(unsigned char Xstart, unsigned char Ystart, unsigned char Xend, unsigned char Yend)
|
||||
{
|
||||
SendCommand(0x44); // SET_RAM_X_ADDRESS_START_END_POSITION
|
||||
|
|
@ -131,6 +148,12 @@ void Epd::SetWindows(unsigned char Xstart, unsigned char Ystart, unsigned char X
|
|||
SendData((Yend >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Set Cursor
|
||||
parameter:
|
||||
Xstart : X-axis starting position
|
||||
Ystart : Y-axis starting position
|
||||
******************************************************************************/
|
||||
void Epd::SetCursor(unsigned char Xstart, unsigned char Ystart)
|
||||
{
|
||||
SendCommand(0x4E); // SET_RAM_X_ADDRESS_COUNTER
|
||||
|
|
@ -141,6 +164,11 @@ void Epd::SetCursor(unsigned char Xstart, unsigned char Ystart)
|
|||
SendData((Ystart >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Send lut data and configuration
|
||||
parameter:
|
||||
lut : lut data
|
||||
******************************************************************************/
|
||||
void Epd::Lut(unsigned char *lut)
|
||||
{
|
||||
unsigned char count;
|
||||
|
|
@ -161,6 +189,11 @@ void Epd::Lut(unsigned char *lut)
|
|||
SendData(*(lut+158));
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Initialize the e-Paper register
|
||||
parameter:
|
||||
Mode : Mode selection
|
||||
******************************************************************************/
|
||||
int Epd::Init(char Mode)
|
||||
{
|
||||
/* this calls the peripheral hardware interface, see epdif */
|
||||
|
|
@ -236,11 +269,10 @@ int Epd::Init(char Mode)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: module reset.
|
||||
* often used to awaken the module in deep sleep,
|
||||
* see Epd::Sleep();
|
||||
*/
|
||||
/******************************************************************************
|
||||
function : Software reset
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void Epd::Reset(void)
|
||||
{
|
||||
DigitalWrite(reset_pin, HIGH);
|
||||
|
|
@ -251,6 +283,10 @@ void Epd::Reset(void)
|
|||
DelayMs(20);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Clear screen
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void Epd::Clear(void)
|
||||
{
|
||||
int w, h;
|
||||
|
|
@ -270,6 +306,11 @@ void Epd::Clear(void)
|
|||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Sends the image buffer in RAM to e-Paper and displays
|
||||
parameter:
|
||||
frame_buffer : Image data
|
||||
******************************************************************************/
|
||||
void Epd::Display(const unsigned char* frame_buffer)
|
||||
{
|
||||
int w = (EPD_WIDTH % 8 == 0)? (EPD_WIDTH / 8 ): (EPD_WIDTH / 8 + 1);
|
||||
|
|
@ -291,6 +332,11 @@ void Epd::Display(const unsigned char* frame_buffer)
|
|||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Refresh a base image
|
||||
parameter:
|
||||
frame_buffer : Image data
|
||||
******************************************************************************/
|
||||
void Epd::DisplayPartBaseImage(const unsigned char* frame_buffer)
|
||||
{
|
||||
int w = (EPD_WIDTH % 8 == 0)? (EPD_WIDTH / 8 ): (EPD_WIDTH / 8 + 1);
|
||||
|
|
@ -319,7 +365,12 @@ void Epd::DisplayPartBaseImage(const unsigned char* frame_buffer)
|
|||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
void Epd::DisplayPart(const unsigned char* frame_buffer)
|
||||
/******************************************************************************
|
||||
function : Sends the image buffer in RAM to e-Paper and partial refresh
|
||||
parameter:
|
||||
frame_buffer : Image data
|
||||
******************************************************************************/
|
||||
void Epd::DisplayPart(const unsigned char* )
|
||||
{
|
||||
int w = (EPD_WIDTH % 8 == 0)? (EPD_WIDTH / 8 ): (EPD_WIDTH / 8 + 1);
|
||||
int h = EPD_HEIGHT;
|
||||
|
|
@ -340,6 +391,10 @@ void Epd::DisplayPart(const unsigned char* frame_buffer)
|
|||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Clear screen
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void Epd::ClearPart(void)
|
||||
{
|
||||
int w, h;
|
||||
|
|
@ -359,14 +414,10 @@ void Epd::ClearPart(void)
|
|||
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.
|
||||
* The only one parameter is a check code, the command would be
|
||||
* executed if check code = 0xA5.
|
||||
* You can use Epd::Init() to awaken
|
||||
*/
|
||||
/******************************************************************************
|
||||
function : Enter sleep mode
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void Epd::Sleep()
|
||||
{
|
||||
SendCommand(0x10); //enter deep sleep
|
||||
|
|
|
|||
|
|
@ -146,6 +146,10 @@ static void EPD_2in13_V3_TurnOnDisplay(void)
|
|||
EPD_2in13_V3_ReadBusy();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Turn On Display
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
static void EPD_2in13_V3_TurnOnDisplay_Partial(void)
|
||||
{
|
||||
EPD_2in13_V3_SendCommand(0x22); // Display Update Control
|
||||
|
|
@ -154,6 +158,11 @@ static void EPD_2in13_V3_TurnOnDisplay_Partial(void)
|
|||
EPD_2in13_V3_ReadBusy();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Set lut
|
||||
parameter:
|
||||
lut : lut data
|
||||
******************************************************************************/
|
||||
static void EPD_2IN13_V3_LUT(UBYTE *lut)
|
||||
{
|
||||
UBYTE count;
|
||||
|
|
@ -163,6 +172,11 @@ static void EPD_2IN13_V3_LUT(UBYTE *lut)
|
|||
EPD_2in13_V3_ReadBusy();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Send lut data and configuration
|
||||
parameter:
|
||||
lut : lut data
|
||||
******************************************************************************/
|
||||
static void EPD_2IN13_V2_LUT_by_host(UBYTE *lut)
|
||||
{
|
||||
EPD_2IN13_V3_LUT((UBYTE *)lut); //lut
|
||||
|
|
@ -181,6 +195,10 @@ static void EPD_2IN13_V2_LUT_by_host(UBYTE *lut)
|
|||
/******************************************************************************
|
||||
function : Setting the display window
|
||||
parameter:
|
||||
Xstart : X-axis starting position
|
||||
Ystart : Y-axis starting position
|
||||
Xend : End position of X-axis
|
||||
Yend : End position of Y-axis
|
||||
******************************************************************************/
|
||||
static void EPD_2in13_V3_SetWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
|
||||
{
|
||||
|
|
@ -198,6 +216,8 @@ static void EPD_2in13_V3_SetWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWOR
|
|||
/******************************************************************************
|
||||
function : Set Cursor
|
||||
parameter:
|
||||
Xstart : X-axis starting position
|
||||
Ystart : Y-axis starting position
|
||||
******************************************************************************/
|
||||
static void EPD_2in13_V3_SetCursor(UWORD Xstart, UWORD Ystart)
|
||||
{
|
||||
|
|
@ -270,6 +290,7 @@ void EPD_2in13_V3_Clear(void)
|
|||
/******************************************************************************
|
||||
function : Sends the image buffer in RAM to e-Paper and displays
|
||||
parameter:
|
||||
Image : Image data
|
||||
******************************************************************************/
|
||||
void EPD_2in13_V3_Display(UBYTE *Image)
|
||||
{
|
||||
|
|
@ -291,6 +312,7 @@ void EPD_2in13_V3_Display(UBYTE *Image)
|
|||
/******************************************************************************
|
||||
function : Refresh a base image
|
||||
parameter:
|
||||
Image : Image data
|
||||
******************************************************************************/
|
||||
void EPD_2in13_V3_Display_Base(UBYTE *Image)
|
||||
{
|
||||
|
|
@ -316,6 +338,7 @@ void EPD_2in13_V3_Display_Base(UBYTE *Image)
|
|||
/******************************************************************************
|
||||
function : Sends the image buffer in RAM to e-Paper and partial refresh
|
||||
parameter:
|
||||
Image : Image data
|
||||
******************************************************************************/
|
||||
void EPD_2in13_V3_Display_Partial(UBYTE *Image)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -91,7 +91,10 @@ class EPD:
|
|||
0x22, 0x17, 0x41, 0x0, 0x32, 0x36,
|
||||
]
|
||||
|
||||
# Hardware reset
|
||||
'''
|
||||
function :Hardware reset
|
||||
parameter:
|
||||
'''
|
||||
def reset(self):
|
||||
epdconfig.digital_write(self.reset_pin, 1)
|
||||
epdconfig.delay_ms(20)
|
||||
|
|
@ -99,43 +102,75 @@ class EPD:
|
|||
epdconfig.delay_ms(2)
|
||||
epdconfig.digital_write(self.reset_pin, 1)
|
||||
epdconfig.delay_ms(20)
|
||||
|
||||
|
||||
'''
|
||||
function :send command
|
||||
parameter:
|
||||
command : Command register
|
||||
'''
|
||||
def send_command(self, command):
|
||||
epdconfig.digital_write(self.dc_pin, 0)
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte([command])
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
'''
|
||||
function :send data
|
||||
parameter:
|
||||
data : Write data
|
||||
'''
|
||||
def send_data(self, data):
|
||||
epdconfig.digital_write(self.dc_pin, 1)
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte([data])
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
|
||||
'''
|
||||
function :Wait until the busy_pin goes LOW
|
||||
parameter:
|
||||
'''
|
||||
def ReadBusy(self):
|
||||
logger.debug("e-Paper busy")
|
||||
while(epdconfig.digital_read(self.busy_pin) == 1): # 0: idle, 1: busy
|
||||
epdconfig.delay_ms(10)
|
||||
logger.debug("e-Paper busy release")
|
||||
|
||||
|
||||
'''
|
||||
function : Turn On Display
|
||||
parameter:
|
||||
'''
|
||||
def TurnOnDisplay(self):
|
||||
self.send_command(0x22) # Display Update Control
|
||||
self.send_data(0xC7)
|
||||
self.send_command(0x20) # Activate Display Update Sequence
|
||||
self.ReadBusy()
|
||||
|
||||
|
||||
'''
|
||||
function : Turn On Display Part
|
||||
parameter:
|
||||
'''
|
||||
def TurnOnDisplayPart(self):
|
||||
self.send_command(0x22) # Display Update Control
|
||||
self.send_data(0x0f) # fast:0x0c, quality:0x0f, 0xcf
|
||||
self.send_command(0x20) # Activate Display Update Sequence
|
||||
self.ReadBusy()
|
||||
|
||||
|
||||
'''
|
||||
function : Set lut
|
||||
parameter:
|
||||
lut : lut data
|
||||
'''
|
||||
def Lut(self, lut):
|
||||
self.send_command(0x32)
|
||||
for i in range(0, 153):
|
||||
self.send_data(lut[i])
|
||||
self.ReadBusy()
|
||||
|
||||
'''
|
||||
function : Send lut data and configuration
|
||||
parameter:
|
||||
lut : lut data
|
||||
'''
|
||||
def SetLut(self, lut):
|
||||
self.Lut(lut)
|
||||
self.send_command(0x3f)
|
||||
|
|
@ -148,7 +183,15 @@ class EPD:
|
|||
self.send_data(lut[157]) # VSL
|
||||
self.send_command(0x2c); # VCOM
|
||||
self.send_data(lut[158])
|
||||
|
||||
|
||||
'''
|
||||
function : Setting the display window
|
||||
parameter:
|
||||
xstart : X-axis starting position
|
||||
ystart : Y-axis starting position
|
||||
xend : End position of X-axis
|
||||
yend : End position of Y-axis
|
||||
'''
|
||||
def SetWindow(self, x_start, y_start, x_end, y_end):
|
||||
self.send_command(0x44) # SET_RAM_X_ADDRESS_START_END_POSITION
|
||||
# x point must be the multiple of 8 or the last 3 bits will be ignored
|
||||
|
|
@ -160,7 +203,13 @@ class EPD:
|
|||
self.send_data((y_start >> 8) & 0xFF)
|
||||
self.send_data(y_end & 0xFF)
|
||||
self.send_data((y_end >> 8) & 0xFF)
|
||||
|
||||
|
||||
'''
|
||||
function : Set Cursor
|
||||
parameter:
|
||||
x : X-axis starting position
|
||||
y : Y-axis starting position
|
||||
'''
|
||||
def SetCursor(self, x, y):
|
||||
self.send_command(0x4E) # SET_RAM_X_ADDRESS_COUNTER
|
||||
# x point must be the multiple of 8 or the last 3 bits will be ignored
|
||||
|
|
@ -169,7 +218,11 @@ class EPD:
|
|||
self.send_command(0x4F) # SET_RAM_Y_ADDRESS_COUNTER
|
||||
self.send_data(y & 0xFF)
|
||||
self.send_data((y >> 8) & 0xFF)
|
||||
|
||||
|
||||
'''
|
||||
function : Initialize the e-Paper register
|
||||
parameter:
|
||||
'''
|
||||
def init(self):
|
||||
if (epdconfig.module_init() != 0):
|
||||
return -1
|
||||
|
|
@ -205,7 +258,12 @@ class EPD:
|
|||
|
||||
self.SetLut(self.lut_full_update)
|
||||
return 0
|
||||
|
||||
|
||||
'''
|
||||
function : Display images
|
||||
parameter:
|
||||
image : Image data
|
||||
'''
|
||||
def getbuffer(self, image):
|
||||
img = image
|
||||
imwidth, imheight = img.size
|
||||
|
|
@ -222,7 +280,11 @@ class EPD:
|
|||
buf = bytearray(img.tobytes('raw'))
|
||||
return buf
|
||||
|
||||
|
||||
'''
|
||||
function : Sends the image buffer in RAM to e-Paper and displays
|
||||
parameter:
|
||||
image : Image data
|
||||
'''
|
||||
def display(self, image):
|
||||
if self.width%8 == 0:
|
||||
linewidth = int(self.width/8)
|
||||
|
|
@ -234,7 +296,12 @@ class EPD:
|
|||
for i in range(0, linewidth):
|
||||
self.send_data(image[i + j * linewidth])
|
||||
self.TurnOnDisplay()
|
||||
|
||||
|
||||
'''
|
||||
function : Sends the image buffer in RAM to e-Paper and partial refresh
|
||||
parameter:
|
||||
image : Image data
|
||||
'''
|
||||
def displayPartial(self, image):
|
||||
if self.width%8 == 0:
|
||||
linewidth = int(self.width/8)
|
||||
|
|
@ -274,7 +341,12 @@ class EPD:
|
|||
for i in range(0, linewidth):
|
||||
self.send_data(image[i + j * linewidth])
|
||||
self.TurnOnDisplayPart()
|
||||
|
||||
|
||||
'''
|
||||
function : Refresh a base image
|
||||
parameter:
|
||||
image : Image data
|
||||
'''
|
||||
def displayPartBaseImage(self, image):
|
||||
if self.width%8 == 0:
|
||||
linewidth = int(self.width/8)
|
||||
|
|
@ -292,6 +364,10 @@ class EPD:
|
|||
self.send_data(image[i + j * linewidth])
|
||||
self.TurnOnDisplay()
|
||||
|
||||
'''
|
||||
function : Clear screen
|
||||
parameter:
|
||||
'''
|
||||
def Clear(self, color):
|
||||
if self.width%8 == 0:
|
||||
linewidth = int(self.width/8)
|
||||
|
|
@ -305,7 +381,11 @@ class EPD:
|
|||
self.send_data(color)
|
||||
|
||||
self.TurnOnDisplay()
|
||||
|
||||
|
||||
'''
|
||||
function : Enter sleep mode
|
||||
parameter:
|
||||
'''
|
||||
def sleep(self):
|
||||
self.send_command(0x10) #enter deep sleep
|
||||
self.send_data(0x01)
|
||||
|
|
|
|||
|
|
@ -146,6 +146,10 @@ static void EPD_2in13_V3_TurnOnDisplay(void)
|
|||
EPD_2in13_V3_ReadBusy();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Turn On Display
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
static void EPD_2in13_V3_TurnOnDisplay_Partial(void)
|
||||
{
|
||||
EPD_2in13_V3_SendCommand(0x22); // Display Update Control
|
||||
|
|
@ -154,6 +158,11 @@ static void EPD_2in13_V3_TurnOnDisplay_Partial(void)
|
|||
EPD_2in13_V3_ReadBusy();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Set lut
|
||||
parameter:
|
||||
lut : lut data
|
||||
******************************************************************************/
|
||||
static void EPD_2IN13_V3_LUT(UBYTE *lut)
|
||||
{
|
||||
UBYTE count;
|
||||
|
|
@ -163,6 +172,11 @@ static void EPD_2IN13_V3_LUT(UBYTE *lut)
|
|||
EPD_2in13_V3_ReadBusy();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Send lut data and configuration
|
||||
parameter:
|
||||
lut : lut data
|
||||
******************************************************************************/
|
||||
static void EPD_2IN13_V2_LUT_by_host(UBYTE *lut)
|
||||
{
|
||||
EPD_2IN13_V3_LUT((UBYTE *)lut); //lut
|
||||
|
|
@ -181,6 +195,10 @@ static void EPD_2IN13_V2_LUT_by_host(UBYTE *lut)
|
|||
/******************************************************************************
|
||||
function : Setting the display window
|
||||
parameter:
|
||||
Xstart : X-axis starting position
|
||||
Ystart : Y-axis starting position
|
||||
Xend : End position of X-axis
|
||||
Yend : End position of Y-axis
|
||||
******************************************************************************/
|
||||
static void EPD_2in13_V3_SetWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
|
||||
{
|
||||
|
|
@ -198,6 +216,8 @@ static void EPD_2in13_V3_SetWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWOR
|
|||
/******************************************************************************
|
||||
function : Set Cursor
|
||||
parameter:
|
||||
Xstart : X-axis starting position
|
||||
Ystart : Y-axis starting position
|
||||
******************************************************************************/
|
||||
static void EPD_2in13_V3_SetCursor(UWORD Xstart, UWORD Ystart)
|
||||
{
|
||||
|
|
@ -270,6 +290,7 @@ void EPD_2in13_V3_Clear(void)
|
|||
/******************************************************************************
|
||||
function : Sends the image buffer in RAM to e-Paper and displays
|
||||
parameter:
|
||||
image : Image data
|
||||
******************************************************************************/
|
||||
void EPD_2in13_V3_Display(UBYTE *Image)
|
||||
{
|
||||
|
|
@ -287,10 +308,10 @@ void EPD_2in13_V3_Display(UBYTE *Image)
|
|||
EPD_2in13_V3_TurnOnDisplay();
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
function : Refresh a base image
|
||||
parameter:
|
||||
image : Image data
|
||||
******************************************************************************/
|
||||
void EPD_2in13_V3_Display_Base(UBYTE *Image)
|
||||
{
|
||||
|
|
@ -316,6 +337,7 @@ void EPD_2in13_V3_Display_Base(UBYTE *Image)
|
|||
/******************************************************************************
|
||||
function : Sends the image buffer in RAM to e-Paper and partial refresh
|
||||
parameter:
|
||||
image : Image data
|
||||
******************************************************************************/
|
||||
void EPD_2in13_V3_Display_Partial(UBYTE *Image)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue