Prechádzať zdrojové kódy

add 2in13_V3 example code (RPi)

SSYYL 4 rokov pred
rodič
commit
9c097b5cc3

+ 18 - 18
RaspberryPi_JetsonNano/c/examples/EPD_2in13_V3_test.c

@@ -4,8 +4,8 @@
 * | Function    :   2.13inch e-paper V3 test demo
 * | Info        :
 *----------------
-* |	This version:   V1.0
-* | Date        :   2020-12-22
+* |	This version:   V1.1
+* | Date        :   2021-10-30
 * | Info        :
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -33,40 +33,40 @@
 
 int EPD_2in13_V3_test(void)
 {
-    printf("EPD_2in13_V3_test Demo\r\n");
+    Debug("EPD_2in13_V3_test Demo\r\n");
     if(DEV_Module_Init()!=0){
         return -1;
     }
 
-    printf("e-Paper Init and Clear...\r\n");
+    Debug("e-Paper Init and Clear...\r\n");
 	EPD_2in13_V3_Init();
 
 	struct timespec start={0,0}, finish={0,0}; 
     clock_gettime(CLOCK_REALTIME,&start);
     EPD_2in13_V3_Clear();
 	clock_gettime(CLOCK_REALTIME,&finish);
-    printf("%ld S\r\n",finish.tv_sec-start.tv_sec);	
+    Debug("%ld S\r\n",finish.tv_sec-start.tv_sec);	
 
     //Create a new image cache
     UBYTE *BlackImage;
     UWORD Imagesize = ((EPD_2in13_V3_WIDTH % 8 == 0)? (EPD_2in13_V3_WIDTH / 8 ): (EPD_2in13_V3_WIDTH / 8 + 1)) * EPD_2in13_V3_HEIGHT;
     if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
-        printf("Failed to apply for black memory...\r\n");
+        Debug("Failed to apply for black memory...\r\n");
         return -1;
     }
-    printf("Paint_NewImage\r\n");
+    Debug("Paint_NewImage\r\n");
     Paint_NewImage(BlackImage, EPD_2in13_V3_WIDTH, EPD_2in13_V3_HEIGHT, 90, WHITE);
 	Paint_Clear(WHITE);
 	
 #if 1   // show bmp
 	Paint_NewImage(BlackImage, EPD_2in13_V3_WIDTH, EPD_2in13_V3_HEIGHT, 90, WHITE);
-    printf("show window BMP-----------------\r\n");
+    Debug("show window BMP-----------------\r\n");
     Paint_SelectImage(BlackImage);
-    GUI_ReadBmp("./pic/100x100.bmp", 0, 0);
+    GUI_ReadBmp("./pic/100x100.bmp", 10, 10);
     EPD_2in13_V3_Display(BlackImage);
     DEV_Delay_ms(3000);
 
-    printf("show bmp------------------------\r\n");
+    Debug("show bmp------------------------\r\n");
     Paint_SelectImage(BlackImage);
     GUI_ReadBmp("./pic/2in13_1.bmp", 0, 0);
     EPD_2in13_V3_Display(BlackImage);
@@ -74,7 +74,7 @@ int EPD_2in13_V3_test(void)
 #endif
 
 #if 1   //show image for array    
-    printf("show image for array\r\n");
+    Debug("show image for array\r\n");
     Paint_SelectImage(BlackImage);
     Paint_Clear(WHITE);
     Paint_DrawBitMap(gImage_2in13_2);
@@ -85,7 +85,7 @@ int EPD_2in13_V3_test(void)
 
 #if 1  // Drawing on the image
 	Paint_NewImage(BlackImage, EPD_2in13_V3_WIDTH, EPD_2in13_V3_HEIGHT, 90, WHITE);  	
-    printf("Drawing\r\n");
+    Debug("Drawing\r\n");
     //1.Select Image
     Paint_SelectImage(BlackImage);
     Paint_Clear(WHITE);
@@ -109,8 +109,8 @@ int EPD_2in13_V3_test(void)
     Paint_DrawString_EN(140, 15, "waveshare", &Font16, BLACK, WHITE);
     Paint_DrawNum(140, 40, 123456789, &Font16, BLACK, WHITE);
 
-    Paint_DrawString_CN(140, 60, "你好abc", &Font12CN, BLACK, WHITE);
-    Paint_DrawString_CN(5, 65, "微雪电�", &Font24CN, WHITE, BLACK);
+    Paint_DrawString_CN(140, 60, "ÄãºÃabc", &Font12CN, BLACK, WHITE);
+    Paint_DrawString_CN(5, 65, "΢ѩµç×Ó", &Font24CN, WHITE, BLACK);
 
     EPD_2in13_V3_Display_Base(BlackImage);
     DEV_Delay_ms(3000);
@@ -118,7 +118,7 @@ int EPD_2in13_V3_test(void)
 
 #if 1   //Partial refresh, example shows time
 	Paint_NewImage(BlackImage, EPD_2in13_V3_WIDTH, EPD_2in13_V3_HEIGHT, 90, WHITE);  
-    printf("Partial refresh\r\n");
+    Debug("Partial refresh\r\n");
     Paint_SelectImage(BlackImage);
 	
     PAINT_TIME sPaint_time;
@@ -153,17 +153,17 @@ int EPD_2in13_V3_test(void)
     }
 #endif
 
-	printf("Clear...\r\n");
+	Debug("Clear...\r\n");
 	EPD_2in13_V3_Init();
     EPD_2in13_V3_Clear();
 	
-    printf("Goto Sleep...\r\n");
+    Debug("Goto Sleep...\r\n");
     EPD_2in13_V3_Sleep();
     free(BlackImage);
     BlackImage = NULL;
     DEV_Delay_ms(2000);//important, at least 2s
     // close 5V
-    printf("close 5V, Module enters 0 power consumption ...\r\n");
+    Debug("close 5V, Module enters 0 power consumption ...\r\n");
     DEV_Module_Exit();
     return 0;
 }

+ 5 - 5
RaspberryPi_JetsonNano/c/examples/main.c

@@ -25,7 +25,7 @@ int main(void)
     // EPD_1in54_test();
     // EPD_1in54_V2_test();
     // EPD_1in54b_test();
-	// EPD_1in54b_V2_test();
+    // EPD_1in54b_V2_test();
     // EPD_1in54c_test();
 
 	// EPD_2in66_test();
@@ -43,8 +43,8 @@ int main(void)
     // EPD_2in9d_test();
 
     // EPD_2in13_test();
-    // EPD_2in13_V2_test();
-	// EPD_2in13_V3_test();
+	// EPD_2in13_V2_test();
+	EPD_2in13_V3_test();
     // EPD_2in13bc_test();
     // EPD_2in13b_V3_test();
     // EPD_2in13d_test();
@@ -63,14 +63,14 @@ int main(void)
 	// EPD_5in65f_test();
 
     // EPD_5in83_test();
-	// EPD_5in83_V2_test();
+    // EPD_5in83_V2_test();
     // EPD_5in83bc_test();
     // EPD_5in83b_V2_test();
 
 	// EPD_5in84_test();
 	
     // EPD_7in5_test();
-	// EPD_7in5_V2_test();
+    // EPD_7in5_V2_test();
 
     // EPD_7in5bc_test();
     // EPD_7in5b_V2_test();

+ 77 - 58
RaspberryPi_JetsonNano/c/lib/e-Paper/EPD_2in13_V3.c

@@ -4,8 +4,8 @@
 * | Function    :   2.13inch e-paper V3
 * | Info        :
 *----------------
-* |	This version:   V1.0
-* | Date        :   2020-12-22
+* |	This version:   V1.1
+* | Date        :   2021-10-30
 * | Info        :
 * -----------------------------------------------------------------------------
 #
@@ -31,7 +31,7 @@
 #include "EPD_2in13_V3.h"
 #include "Debug.h"
 
-UBYTE WF_PARTIAL_2IN13_V2[159] =
+UBYTE WF_PARTIAL_2IN13_V3[159] =
 {
 0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
 0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
@@ -52,9 +52,9 @@ UBYTE WF_PARTIAL_2IN13_V2[159] =
 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
 0x22,0x22,0x22,0x22,0x22,0x22,0x0,0x0,0x0,
 0x22,0x17,0x41,0x00,0x32,0x36,
-};		
+};
 
-UBYTE WS_20_30_2IN13_V2[159] =
+UBYTE WS_20_30_2IN13_V3[159] =
 {											
 0x80,	0x4A,	0x40,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
 0x40,	0x4A,	0x80,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
@@ -75,7 +75,7 @@ UBYTE WS_20_30_2IN13_V2[159] =
 0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,					
 0x22,	0x22,	0x22,	0x22,	0x22,	0x22,	0x0,	0x0,	0x0,			
 0x22,	0x17,	0x41,	0x0,	0x32,	0x36						
-};	
+};
 
 /******************************************************************************
 function :	Software reset
@@ -84,11 +84,11 @@ parameter:
 static void EPD_2in13_V3_Reset(void)
 {
     DEV_Digital_Write(EPD_RST_PIN, 1);
-    DEV_Delay_ms(100);
+    DEV_Delay_ms(20);
     DEV_Digital_Write(EPD_RST_PIN, 0);
     DEV_Delay_ms(2);
     DEV_Digital_Write(EPD_RST_PIN, 1);
-    DEV_Delay_ms(100);
+    DEV_Delay_ms(20);
 }
 
 /******************************************************************************
@@ -140,17 +140,17 @@ parameter:
 ******************************************************************************/
 static void EPD_2in13_V3_TurnOnDisplay(void)
 {
-	EPD_2in13_V3_SendCommand(0x22); //Display Update Control
+	EPD_2in13_V3_SendCommand(0x22); // Display Update Control
 	EPD_2in13_V3_SendData(0xc7);
-	EPD_2in13_V3_SendCommand(0x20); //Activate Display Update Sequence
+	EPD_2in13_V3_SendCommand(0x20); // Activate Display Update Sequence
 	EPD_2in13_V3_ReadBusy();
 }
 
 static void EPD_2in13_V3_TurnOnDisplay_Partial(void)
 {
-	EPD_2in13_V3_SendCommand(0x22); //Display Update Control
-	EPD_2in13_V3_SendData(0x0f); 		// c0/ff  
-	EPD_2in13_V3_SendCommand(0x20); //Activate Display Update Sequence
+	EPD_2in13_V3_SendCommand(0x22); // Display Update Control
+	EPD_2in13_V3_SendData(0x0f);	// fast:0x0c, quality:0x0f, 0xcf
+	EPD_2in13_V3_SendCommand(0x20); // Activate Display Update Sequence
 	EPD_2in13_V3_ReadBusy();
 }
 
@@ -176,7 +176,6 @@ static void EPD_2IN13_V2_LUT_by_host(UBYTE *lut)
 	EPD_2in13_V3_SendData(*(lut+157));	// VSL
 	EPD_2in13_V3_SendCommand(0x2c);		// VCOM
 	EPD_2in13_V3_SendData(*(lut+158));
-	
 }
 
 /******************************************************************************
@@ -185,17 +184,15 @@ parameter:
 ******************************************************************************/
 static void EPD_2in13_V3_SetWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
 {
-	// Ystart = 295 - Ystart;
-	
     EPD_2in13_V3_SendCommand(0x44); // SET_RAM_X_ADDRESS_START_END_POSITION
     EPD_2in13_V3_SendData((Xstart>>3) & 0xFF);
     EPD_2in13_V3_SendData((Xend>>3) & 0xFF);
 	
     EPD_2in13_V3_SendCommand(0x45); // SET_RAM_Y_ADDRESS_START_END_POSITION
-    EPD_2in13_V3_SendData(Yend & 0xFF);
-    EPD_2in13_V3_SendData((Yend >> 8) & 0xFF);
     EPD_2in13_V3_SendData(Ystart & 0xFF);
     EPD_2in13_V3_SendData((Ystart >> 8) & 0xFF);
+    EPD_2in13_V3_SendData(Yend & 0xFF);
+    EPD_2in13_V3_SendData((Yend >> 8) & 0xFF);
 }
 
 /******************************************************************************
@@ -204,8 +201,6 @@ parameter:
 ******************************************************************************/
 static void EPD_2in13_V3_SetCursor(UWORD Xstart, UWORD Ystart)
 {
-	Ystart = 295 - Ystart;
-	
     EPD_2in13_V3_SendCommand(0x4E); // SET_RAM_X_ADDRESS_COUNTER
     EPD_2in13_V3_SendData(Xstart & 0xFF);
 
@@ -228,14 +223,15 @@ void EPD_2in13_V3_Init(void)
 	EPD_2in13_V3_ReadBusy();   
 
 	EPD_2in13_V3_SendCommand(0x01); //Driver output control      
-	EPD_2in13_V3_SendData(0x27);
-	EPD_2in13_V3_SendData(0x01);
-	EPD_2in13_V3_SendData(0x01);
+	EPD_2in13_V3_SendData(0xf9);
+	EPD_2in13_V3_SendData(0x00);
+	EPD_2in13_V3_SendData(0x00);
 
 	EPD_2in13_V3_SendCommand(0x11); //data entry mode       
-	EPD_2in13_V3_SendData(0x01);
+	EPD_2in13_V3_SendData(0x03);
 
-	EPD_2in13_V3_SetWindows(0, 0, EPD_2in13_V3_WIDTH-1, 296-1);
+	EPD_2in13_V3_SetWindows(0, 0, EPD_2in13_V3_WIDTH-1, EPD_2in13_V3_HEIGHT-1);
+	EPD_2in13_V3_SetCursor(0, 0);
 	
 	EPD_2in13_V3_SendCommand(0x3C); //BorderWavefrom
 	EPD_2in13_V3_SendData(0x05);	
@@ -246,11 +242,9 @@ void EPD_2in13_V3_Init(void)
 
 	EPD_2in13_V3_SendCommand(0x18); //Read built-in temperature sensor
 	EPD_2in13_V3_SendData(0x80);	
-	
-	EPD_2in13_V3_SetCursor(0, 0);
+
 	EPD_2in13_V3_ReadBusy();
-	
-	EPD_2IN13_V2_LUT_by_host(WS_20_30_2IN13_V2);
+	EPD_2IN13_V2_LUT_by_host(WS_20_30_2IN13_V3);
 }
 
 /******************************************************************************
@@ -259,12 +253,17 @@ parameter:
 ******************************************************************************/
 void EPD_2in13_V3_Clear(void)
 {
-	UWORD i;
-	EPD_2in13_V3_SendCommand(0x24);   //write RAM for black(0)/white (1)
-	for(i=0;i<4736;i++)
-	{
-		EPD_2in13_V3_SendData(0xff);
-	}
+	UWORD Width, Height;
+    Width = (EPD_2in13_V3_WIDTH % 8 == 0)? (EPD_2in13_V3_WIDTH / 8 ): (EPD_2in13_V3_WIDTH / 8 + 1);
+    Height = EPD_2in13_V3_HEIGHT;
+	
+    EPD_2in13_V3_SendCommand(0x24);
+    for (UWORD j = 0; j < Height; j++) {
+        for (UWORD i = 0; i < Width; i++) {
+            EPD_2in13_V3_SendData(0XFF);
+        }
+    }	
+
 	EPD_2in13_V3_TurnOnDisplay();
 }
 
@@ -274,43 +273,62 @@ parameter:
 ******************************************************************************/
 void EPD_2in13_V3_Display(UBYTE *Image)
 {
-	UWORD i;	
-	EPD_2in13_V3_SendCommand(0x24);   //write RAM for black(0)/white (1)
-	for(i=0;i<4736;i++)
-	{
-		EPD_2in13_V3_SendData(Image[i]);
-	}
+	UWORD Width, Height;
+    Width = (EPD_2in13_V3_WIDTH % 8 == 0)? (EPD_2in13_V3_WIDTH / 8 ): (EPD_2in13_V3_WIDTH / 8 + 1);
+    Height = EPD_2in13_V3_HEIGHT;
+	
+    EPD_2in13_V3_SendCommand(0x24);
+    for (UWORD j = 0; j < Height; j++) {
+        for (UWORD i = 0; i < Width; i++) {
+            EPD_2in13_V3_SendData(Image[i + j * Width]);
+        }
+    }	
+	
 	EPD_2in13_V3_TurnOnDisplay();	
 }
 
-void EPD_2in13_V3_Display_Base(UBYTE *Image)
-{
-	UWORD i;   
 
+/******************************************************************************
+function :	Refresh a base image
+parameter:
+******************************************************************************/
+void EPD_2in13_V3_Display_Base(UBYTE *Image)
+{  
+	UWORD Width, Height;
+    Width = (EPD_2in13_V3_WIDTH % 8 == 0)? (EPD_2in13_V3_WIDTH / 8 ): (EPD_2in13_V3_WIDTH / 8 + 1);
+    Height = EPD_2in13_V3_HEIGHT;
+	
 	EPD_2in13_V3_SendCommand(0x24);   //Write Black and White image to RAM
-	for(i=0;i<4736;i++)
-	{               
-		EPD_2in13_V3_SendData(Image[i]);
+    for (UWORD j = 0; j < Height; j++) {
+        for (UWORD i = 0; i < Width; i++) {        
+			EPD_2in13_V3_SendData(Image[i + j * Width]);
+		}
 	}
 	EPD_2in13_V3_SendCommand(0x26);   //Write Black and White image to RAM
-	for(i=0;i<4736;i++)
-	{               
-		EPD_2in13_V3_SendData(Image[i]);
+    for (UWORD j = 0; j < Height; j++) {
+        for (UWORD i = 0; i < Width; i++) {
+			EPD_2in13_V3_SendData(Image[i + j * Width]);
+		}
 	}
 	EPD_2in13_V3_TurnOnDisplay();	
 }
 
+/******************************************************************************
+function :	Sends the image buffer in RAM to e-Paper and partial refresh
+parameter:
+******************************************************************************/
 void EPD_2in13_V3_Display_Partial(UBYTE *Image)
 {
-	UWORD i;
+	UWORD Width, Height;
+    Width = (EPD_2in13_V3_WIDTH % 8 == 0)? (EPD_2in13_V3_WIDTH / 8 ): (EPD_2in13_V3_WIDTH / 8 + 1);
+    Height = EPD_2in13_V3_HEIGHT;
 	
 	//Reset
     DEV_Digital_Write(EPD_RST_PIN, 0);
-    DEV_Delay_ms(2);
+    DEV_Delay_ms(1);
     DEV_Digital_Write(EPD_RST_PIN, 1);
-    DEV_Delay_ms(3);
 
-	EPD_2IN13_V2_LUT_by_host(WF_PARTIAL_2IN13_V2);
+	EPD_2IN13_V2_LUT_by_host(WF_PARTIAL_2IN13_V3);
 
 	EPD_2in13_V3_SendCommand(0x37); 
 	EPD_2in13_V3_SendData(0x00);  
@@ -332,13 +350,14 @@ void EPD_2in13_V3_Display_Partial(UBYTE *Image)
 	EPD_2in13_V3_SendCommand(0x20);  //Activate Display Update Sequence
 	EPD_2in13_V3_ReadBusy();  
 	
-	EPD_2in13_V3_SetWindows(0, 0, EPD_2in13_V3_WIDTH-1, 296-1);
+	EPD_2in13_V3_SetWindows(0, 0, EPD_2in13_V3_WIDTH-1, EPD_2in13_V3_HEIGHT-1);
 	EPD_2in13_V3_SetCursor(0, 0);
 
 	EPD_2in13_V3_SendCommand(0x24);   //Write Black and White image to RAM
-	for(i=0;i<4736;i++)
-	{
-		EPD_2in13_V3_SendData(Image[i]);
+    for (UWORD j = 0; j < Height; j++) {
+        for (UWORD i = 0; i < Width; i++) {
+			EPD_2in13_V3_SendData(Image[i + j * Width]);
+		}
 	}
 	EPD_2in13_V3_TurnOnDisplay_Partial();
 }

+ 2 - 2
RaspberryPi_JetsonNano/c/lib/e-Paper/EPD_2in13_V3.h

@@ -4,8 +4,8 @@
 * | Function    :   2.13inch e-paper V3
 * | Info        :
 *----------------
-* |	This version:   V1.0
-* | Date        :   2020-12-22
+* |	This version:   V1.1
+* | Date        :   2021-10-30
 * | Info        :
 * -----------------------------------------------------------------------------
 #

+ 93 - 0
RaspberryPi_JetsonNano/python/examples/epd_2in13_V3_test.py

@@ -0,0 +1,93 @@
+#!/usr/bin/python
+# -*- coding:utf-8 -*-
+import sys
+import os
+picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
+libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
+if os.path.exists(libdir):
+    sys.path.append(libdir)
+
+import logging
+from waveshare_epd import epd2in13_V3
+import time
+from PIL import Image,ImageDraw,ImageFont
+import traceback
+
+logging.basicConfig(level=logging.DEBUG)
+
+try:
+    logging.info("epd2in13_V3 Demo")
+    
+    epd = epd2in13_V3.EPD()
+    logging.info("init and Clear")
+    epd.init()
+    epd.Clear(0xFF)
+
+    # Drawing on the image
+    font15 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15)
+    font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
+    
+    logging.info("1.Drawing on the image...")
+    image = Image.new('1', (epd.height, epd.width), 255)  # 255: clear the frame    
+    draw = ImageDraw.Draw(image)
+    
+    draw.rectangle([(0,0),(50,50)],outline = 0)
+    draw.rectangle([(55,0),(100,50)],fill = 0)
+    draw.line([(0,0),(50,50)], fill = 0,width = 1)
+    draw.line([(0,50),(50,0)], fill = 0,width = 1)
+    draw.chord((10, 60, 50, 100), 0, 360, fill = 0)
+    draw.ellipse((55, 60, 95, 100), outline = 0)
+    draw.pieslice((55, 60, 95, 100), 90, 180, outline = 0)
+    draw.pieslice((55, 60, 95, 100), 270, 360, fill = 0)
+    draw.polygon([(110,0),(110,50),(150,25)],outline = 0)
+    draw.polygon([(190,0),(190,50),(150,25)],fill = 0)
+    draw.text((120, 60), 'e-Paper demo', font = font15, fill = 0)
+    draw.text((110, 90), u'微雪电子', font = font24, fill = 0)
+    # image = image.rotate(180) # rotate
+    epd.display(epd.getbuffer(image))
+    time.sleep(2)
+    
+    # read bmp file 
+    logging.info("2.read bmp file...")
+    image = Image.open(os.path.join(picdir, '2in13.bmp'))
+    epd.display(epd.getbuffer(image))
+    time.sleep(2)
+    
+    # read bmp file on window
+    logging.info("3.read bmp file on window...")
+    # epd.Clear(0xFF)
+    image1 = Image.new('1', (epd.height, epd.width), 255)  # 255: clear the frame
+    bmp = Image.open(os.path.join(picdir, '100x100.bmp'))
+    image1.paste(bmp, (2,2))    
+    epd.display(epd.getbuffer(image1))
+    time.sleep(2)
+    
+    # # partial update
+    logging.info("4.show time...")
+    time_image = Image.new('1', (epd.height, epd.width), 255)
+    time_draw = ImageDraw.Draw(time_image)
+    
+    epd.displayPartBaseImage(epd.getbuffer(time_image))
+    num = 0
+    while (True):
+        time_draw.rectangle((120, 80, 220, 105), fill = 255)
+        time_draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0)
+        epd.displayPartial(epd.getbuffer(time_image))
+        num = num + 1
+        if(num == 10):
+            break
+    
+    logging.info("Clear...")
+    epd.init()
+    epd.Clear(0xFF)
+    
+    logging.info("Goto Sleep...")
+    epd.sleep()
+        
+except IOError as e:
+    logging.info(e)
+    
+except KeyboardInterrupt:    
+    logging.info("ctrl + c:")
+    epd2in13_V3.epdconfig.module_exit()
+    exit()

+ 317 - 0
RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd2in13_V3.py

@@ -0,0 +1,317 @@
+# *****************************************************************************
+# * | File        :	  epd2in13_V3.py
+# * | Author      :   Waveshare team
+# * | Function    :   Electronic paper driver
+# * | Info        :
+# *----------------
+# * | This version:   V1.1
+# * | Date        :   2021-10-30
+# # | Info        :   python demo
+# -----------------------------------------------------------------------------
+# 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.
+#
+
+
+import logging
+from . import epdconfig
+import numpy as np
+
+# Display resolution
+EPD_WIDTH       = 122
+EPD_HEIGHT      = 250
+
+logger = logging.getLogger(__name__)
+
+class EPD:
+    def __init__(self):
+        self.reset_pin = epdconfig.RST_PIN
+        self.dc_pin = epdconfig.DC_PIN
+        self.busy_pin = epdconfig.BUSY_PIN
+        self.cs_pin = epdconfig.CS_PIN
+        self.width = EPD_WIDTH
+        self.height = EPD_HEIGHT
+        
+    lut_partial_update= [
+        0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
+        0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
+        0x40,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
+        0x0,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
+        0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
+        0x14,0x0,0x0,0x0,0x0,0x0,0x0,  
+        0x1,0x0,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,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,0x00,0x32,0x36,
+    ]
+
+    lut_full_update = [ 
+        0x80,	0x4A,	0x40,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
+        0x40,	0x4A,	0x80,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
+        0x80,	0x4A,	0x40,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
+        0x40,	0x4A,	0x80,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
+        0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
+        0xF,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,					
+        0xF,	0x0,	0x0,	0xF,	0x0,	0x0,	0x2,					
+        0xF,	0x0,	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,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,					
+        0x22,	0x22,	0x22,	0x22,	0x22,	0x22,	0x0,	0x0,	0x0,			
+        0x22,	0x17,	0x41,	0x0,	0x32,	0x36,
+    ]
+        
+    # Hardware reset
+    def reset(self):
+        epdconfig.digital_write(self.reset_pin, 1)
+        epdconfig.delay_ms(20) 
+        epdconfig.digital_write(self.reset_pin, 0)
+        epdconfig.delay_ms(2)
+        epdconfig.digital_write(self.reset_pin, 1)
+        epdconfig.delay_ms(20)   
+
+    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)
+
+    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)
+        
+    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")
+
+    def TurnOnDisplay(self):
+        self.send_command(0x22) # Display Update Control
+        self.send_data(0xC7)
+        self.send_command(0x20) # Activate Display Update Sequence
+        self.ReadBusy()
+        
+    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()
+        
+    def Lut(self, lut):
+        self.send_command(0x32)
+        for i in range(0, 153):
+            self.send_data(lut[i])
+        self.ReadBusy()
+    
+    def SetLut(self, lut):
+        self.Lut(lut)
+        self.send_command(0x3f)
+        self.send_data(lut[153])
+        self.send_command(0x03);	# gate voltage
+        self.send_data(lut[154])
+        self.send_command(0x04);	# source voltage
+        self.send_data(lut[155])	# VSH
+        self.send_data(lut[156])	# VSH2
+        self.send_data(lut[157])	# VSL
+        self.send_command(0x2c);    # VCOM
+        self.send_data(lut[158])
+       
+    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
+        self.send_data((x_start>>3) & 0xFF)
+        self.send_data((x_end>>3) & 0xFF)
+        
+        self.send_command(0x45) # SET_RAM_Y_ADDRESS_START_END_POSITION
+        self.send_data(y_start & 0xFF)
+        self.send_data((y_start >> 8) & 0xFF)
+        self.send_data(y_end & 0xFF)
+        self.send_data((y_end >> 8) & 0xFF)
+
+    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
+        self.send_data(x & 0xFF)
+        
+        self.send_command(0x4F) # SET_RAM_Y_ADDRESS_COUNTER
+        self.send_data(y & 0xFF)
+        self.send_data((y >> 8) & 0xFF)
+       
+    def init(self):
+        if (epdconfig.module_init() != 0):
+            return -1
+        # EPD hardware init start
+        self.reset()
+        
+        self.ReadBusy()
+        self.send_command(0x12)  #SWRESET
+        self.ReadBusy() 
+
+        self.send_command(0x01) #Driver output control      
+        self.send_data(0xf9)
+        self.send_data(0x00)
+        self.send_data(0x00)
+    
+        self.send_command(0x11) #data entry mode       
+        self.send_data(0x03)
+
+        self.SetWindow(0, 0, self.width-1, self.height-1)
+        self.SetCursor(0, 0)
+        
+        self.send_command(0x3c)
+        self.send_data(0x05)
+
+        self.send_command(0x21) #  Display update control
+        self.send_data(0x00)
+        self.send_data(0x80)
+    
+        self.send_command(0x18)
+        self.send_data(0x80)
+        
+        self.ReadBusy()
+        
+        self.SetLut(self.lut_full_update)
+        return 0
+
+    def getbuffer(self, image):
+        img = image
+        imwidth, imheight = img.size
+        if(imwidth == self.width and imheight == self.height):
+            img = img.convert('1')
+        elif(imwidth == self.height and imheight == self.width):
+            # image has correct dimensions, but needs to be rotated
+            img = img.rotate(90, expand=True).convert('1')
+        else:
+            logger.warning("Wrong image dimensions: must be " + str(self.width) + "x" + str(self.height))
+            # return a blank buffer
+            return [0x00] * (int(self.width/8) * self.height)
+
+        buf = bytearray(img.tobytes('raw'))
+        return buf
+        
+        
+    def display(self, image):
+        if self.width%8 == 0:
+            linewidth = int(self.width/8)
+        else:
+            linewidth = int(self.width/8) + 1
+
+        self.send_command(0x24)
+        for j in range(0, self.height):
+            for i in range(0, linewidth):
+                self.send_data(image[i + j * linewidth])   
+        self.TurnOnDisplay()
+        
+    def displayPartial(self, image):
+        if self.width%8 == 0:
+            linewidth = int(self.width/8)
+        else:
+            linewidth = int(self.width/8) + 1
+
+        epdconfig.digital_write(self.reset_pin, 0)
+        epdconfig.delay_ms(1)
+        epdconfig.digital_write(self.reset_pin, 1)  
+        
+        self.SetLut(self.lut_partial_update)
+        self.send_command(0x37)
+        self.send_data(0x00)
+        self.send_data(0x00)
+        self.send_data(0x00)
+        self.send_data(0x00)
+        self.send_data(0x00)
+        self.send_data(0x40)
+        self.send_data(0x00)
+        self.send_data(0x00)
+        self.send_data(0x00)  
+        self.send_data(0x00)
+
+        self.send_command(0x3C) #BorderWavefrom
+        self.send_data(0x80)
+
+        self.send_command(0x22) 
+        self.send_data(0xC0)
+        self.send_command(0x20)
+        self.ReadBusy()
+
+        self.SetWindow(0, 0, self.width - 1, self.height - 1)
+        self.SetCursor(0, 0)
+        
+        self.send_command(0x24) # WRITE_RAM
+        for j in range(0, self.height):
+            for i in range(0, linewidth):
+                self.send_data(image[i + j * linewidth])   
+        self.TurnOnDisplayPart()
+
+    def displayPartBaseImage(self, image):
+        if self.width%8 == 0:
+            linewidth = int(self.width/8)
+        else:
+            linewidth = int(self.width/8) + 1
+
+        self.send_command(0x24)
+        for j in range(0, self.height):
+            for i in range(0, linewidth):
+                self.send_data(image[i + j * linewidth])   
+                
+        self.send_command(0x26)
+        for j in range(0, self.height):
+            for i in range(0, linewidth):
+                self.send_data(image[i + j * linewidth])  
+        self.TurnOnDisplay()
+    
+    def Clear(self, color):
+        if self.width%8 == 0:
+            linewidth = int(self.width/8)
+        else:
+            linewidth = int(self.width/8) + 1
+        # logger.debug(linewidth)
+        
+        self.send_command(0x24)
+        for j in range(0, self.height):
+            for i in range(0, linewidth):
+                self.send_data(color)
+                
+        self.TurnOnDisplay()
+
+    def sleep(self):
+        self.send_command(0x10) #enter deep sleep
+        self.send_data(0x01)
+        
+        epdconfig.delay_ms(2000)
+        epdconfig.module_exit()
+
+### END OF FILE ###
+