EPD_2in7_V2_test.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*****************************************************************************
  2. * | File : EPD_2in7_V2.c
  3. * | Author : Waveshare team
  4. * | Function : 2.7inch V2 e-paper
  5. * | Info :
  6. *----------------
  7. * | This version: V1.0
  8. * | Date : 2022-08-18
  9. * | Info :
  10. * -----------------------------------------------------------------------------
  11. #
  12. # Permission is hereby granted, free of charge, to any person obtaining a copy
  13. # of this software and associated documnetation files (the "Software"), to deal
  14. # in the Software without restriction, including without limitation the rights
  15. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. # copies of the Software, and to permit persons to whom the Software is
  17. # furished to do so, subject to the following conditions:
  18. #
  19. # The above copyright notice and this permission notice shall be included in
  20. # all copies or substantial portions of the Software.
  21. #
  22. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28. # THE SOFTWARE.
  29. #
  30. ******************************************************************************/
  31. #include "EPD_Test.h"
  32. #include "EPD_2in7_V2.h"
  33. #include <time.h>
  34. int EPD_2in7_V2_test(void)
  35. {
  36. printf("EPD_2IN7_V2_test Demo\r\n");
  37. if(DEV_Module_Init()!=0){
  38. return -1;
  39. }
  40. printf("e-Paper Init and Clear...\r\n");
  41. EPD_2IN7_V2_Init();
  42. struct timespec start={0,0}, finish={0,0};
  43. clock_gettime(CLOCK_REALTIME,&start);
  44. EPD_2IN7_V2_Clear();
  45. clock_gettime(CLOCK_REALTIME,&finish);
  46. printf("%ld S\r\n",finish.tv_sec-start.tv_sec);
  47. //Create a new image cache
  48. UBYTE *BlackImage;
  49. UWORD Imagesize = ((EPD_2IN7_V2_WIDTH % 8 == 0)? (EPD_2IN7_V2_WIDTH / 8 ): (EPD_2IN7_V2_WIDTH / 8 + 1)) * EPD_2IN7_V2_HEIGHT;
  50. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  51. printf("Failed to apply for black memory...\r\n");
  52. return -1;
  53. }
  54. printf("Paint_NewImage\r\n");
  55. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 90, WHITE);
  56. Paint_Clear(WHITE);
  57. #if 1 // show bmp
  58. printf("show window BMP-----------------\r\n");
  59. Paint_SelectImage(BlackImage);
  60. GUI_ReadBmp("./pic/100x100.bmp", 10, 10);
  61. EPD_2IN7_V2_Display(BlackImage);
  62. DEV_Delay_ms(3000);
  63. printf("show bmp------------------------\r\n");
  64. Paint_SelectImage(BlackImage);
  65. GUI_ReadBmp("./pic/2in7.bmp", 0, 0);
  66. EPD_2IN7_V2_Display(BlackImage);
  67. DEV_Delay_ms(3000);
  68. #endif
  69. #if 1 // Drawing on the image
  70. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 90, WHITE);
  71. printf("Drawing\r\n");
  72. //1.Select Image
  73. Paint_SelectImage(BlackImage);
  74. Paint_Clear(WHITE);
  75. // 2.Drawing on the image
  76. printf("Drawing:BlackImage\r\n");
  77. Paint_DrawPoint(10, 80, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  78. Paint_DrawPoint(10, 90, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  79. Paint_DrawPoint(10, 100, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  80. Paint_DrawLine(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  81. Paint_DrawLine(70, 70, 20, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  82. Paint_DrawRectangle(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  83. Paint_DrawRectangle(80, 70, 130, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  84. Paint_DrawCircle(45, 95, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  85. Paint_DrawCircle(105, 95, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  86. Paint_DrawLine(85, 95, 125, 95, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  87. Paint_DrawLine(105, 75, 105, 115, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  88. Paint_DrawString_EN(10, 0, "waveshare", &Font16, BLACK, WHITE);
  89. Paint_DrawString_EN(10, 20, "hello world", &Font12, WHITE, BLACK);
  90. Paint_DrawNum(10, 33, 123456789, &Font12, BLACK, WHITE);
  91. Paint_DrawNum(10, 50, 987654321, &Font16, WHITE, BLACK);
  92. Paint_DrawString_CN(130, 0,"ÄãºÃabc", &Font12CN, BLACK, WHITE);
  93. Paint_DrawString_CN(130, 20, "΢ѩµç×Ó", &Font24CN, WHITE, BLACK);
  94. EPD_2IN7_V2_Display_Base(BlackImage);
  95. DEV_Delay_ms(3000);
  96. #endif
  97. #if 1 // Fast Drawing on the image
  98. // Fast refresh
  99. printf("This is followed by a quick refresh demo\r\n");
  100. printf("First, clear the screen\r\n");
  101. EPD_2IN7_V2_Init();
  102. EPD_2IN7_V2_Clear();
  103. printf("e-Paper Init Fast\r\n");
  104. EPD_2IN7_V2_Init_Fast();
  105. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 90, WHITE);
  106. printf("Drawing\r\n");
  107. //1.Select Image
  108. Paint_SelectImage(BlackImage);
  109. Paint_Clear(WHITE);
  110. printf("show window BMP-----------------\r\n");
  111. Paint_SelectImage(BlackImage);
  112. GUI_ReadBmp("./pic/100x100.bmp", 10, 10);
  113. EPD_2IN7_V2_Display_Fast(BlackImage);
  114. DEV_Delay_ms(3000);
  115. printf("show bmp------------------------\r\n");
  116. Paint_SelectImage(BlackImage);
  117. GUI_ReadBmp("./pic/2in7.bmp", 0, 0);
  118. EPD_2IN7_V2_Display_Fast(BlackImage);
  119. DEV_Delay_ms(3000);
  120. // 2.Drawing on the image
  121. Paint_Clear(WHITE);
  122. printf("Drawing:BlackImage\r\n");
  123. Paint_DrawPoint(10, 80, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  124. Paint_DrawPoint(10, 90, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  125. Paint_DrawPoint(10, 100, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  126. Paint_DrawLine(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  127. Paint_DrawLine(70, 70, 20, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  128. Paint_DrawRectangle(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  129. Paint_DrawRectangle(80, 70, 130, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  130. Paint_DrawCircle(45, 95, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  131. Paint_DrawCircle(105, 95, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  132. Paint_DrawLine(85, 95, 125, 95, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  133. Paint_DrawLine(105, 75, 105, 115, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  134. Paint_DrawString_EN(10, 0, "waveshare", &Font16, BLACK, WHITE);
  135. Paint_DrawString_EN(10, 20, "hello world", &Font12, WHITE, BLACK);
  136. Paint_DrawNum(10, 33, 123456789, &Font12, BLACK, WHITE);
  137. Paint_DrawNum(10, 50, 987654321, &Font16, WHITE, BLACK);
  138. Paint_DrawString_CN(130, 0,"ÄãºÃabc", &Font12CN, BLACK, WHITE);
  139. Paint_DrawString_CN(130, 20, "΢ѩµç×Ó", &Font24CN, WHITE, BLACK);
  140. EPD_2IN7_V2_Display_Fast(BlackImage);
  141. DEV_Delay_ms(3000);
  142. #endif
  143. #if 1 //Partial refresh, example shows time
  144. // If you didn't use the EPD_2IN7_V2_Display_Base() function to refresh the image before,
  145. // use the EPD_2IN7_V2_Display_Base_color() function to refresh the background color,
  146. // otherwise the background color will be garbled
  147. EPD_2IN7_V2_Init();
  148. // EPD_2IN7_V2_Display_Base_color(WHITE);
  149. Paint_NewImage(BlackImage, 50, 120, 90, WHITE);
  150. printf("Partial refresh\r\n");
  151. Paint_SelectImage(BlackImage);
  152. Paint_SetScale(2);
  153. Paint_Clear(WHITE);
  154. PAINT_TIME sPaint_time;
  155. sPaint_time.Hour = 12;
  156. sPaint_time.Min = 34;
  157. sPaint_time.Sec = 56;
  158. UBYTE num = 15;
  159. for (;;) {
  160. sPaint_time.Sec = sPaint_time.Sec + 1;
  161. if (sPaint_time.Sec == 60) {
  162. sPaint_time.Min = sPaint_time.Min + 1;
  163. sPaint_time.Sec = 0;
  164. if (sPaint_time.Min == 60) {
  165. sPaint_time.Hour = sPaint_time.Hour + 1;
  166. sPaint_time.Min = 0;
  167. if (sPaint_time.Hour == 24) {
  168. sPaint_time.Hour = 0;
  169. sPaint_time.Min = 0;
  170. sPaint_time.Sec = 0;
  171. }
  172. }
  173. }
  174. Paint_Clear(WHITE);
  175. Paint_DrawRectangle(1, 1, 120, 50, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  176. Paint_DrawTime(10, 15, &sPaint_time, &Font20, WHITE, BLACK);
  177. num = num - 1;
  178. if(num == 0) {
  179. break;
  180. }
  181. printf("Part refresh...\r\n");
  182. EPD_2IN7_V2_Display_Partial(BlackImage, 60, 134, 110, 254); // Xstart must be a multiple of 8
  183. DEV_Delay_ms(500);
  184. }
  185. #endif
  186. #if 1 // show image for array
  187. free(BlackImage);
  188. printf("show Gray------------------------\r\n");
  189. Imagesize = ((EPD_2IN7_V2_WIDTH % 4 == 0)? (EPD_2IN7_V2_WIDTH / 4 ): (EPD_2IN7_V2_WIDTH / 4 + 1)) * EPD_2IN7_V2_HEIGHT;
  190. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  191. printf("Failed to apply for black memory...\r\n");
  192. return -1;
  193. }
  194. EPD_2IN7_V2_Init_4GRAY();
  195. printf("4 grayscale display\r\n");
  196. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 90, WHITE);
  197. Paint_SetScale(4);
  198. Paint_Clear(0xff);
  199. Paint_DrawPoint(10, 80, GRAY4, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  200. Paint_DrawPoint(10, 90, GRAY4, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  201. Paint_DrawPoint(10, 100, GRAY4, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  202. Paint_DrawLine(20, 70, 70, 120, GRAY4, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  203. Paint_DrawLine(70, 70, 20, 120, GRAY4, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  204. Paint_DrawRectangle(20, 70, 70, 120, GRAY4, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  205. Paint_DrawRectangle(80, 70, 130, 120, GRAY4, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  206. Paint_DrawCircle(45, 95, 20, GRAY4, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  207. Paint_DrawCircle(105, 95, 20, GRAY2, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  208. Paint_DrawLine(85, 95, 125, 95, GRAY4, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  209. Paint_DrawLine(105, 75, 105, 115, GRAY4, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  210. Paint_DrawString_EN(10, 0, "waveshare", &Font16, GRAY4, GRAY1);
  211. Paint_DrawString_EN(10, 20, "hello world", &Font12, GRAY3, GRAY1);
  212. Paint_DrawNum(10, 33, 123456789, &Font12, GRAY4, GRAY2);
  213. Paint_DrawNum(10, 50, 987654321, &Font16, GRAY1, GRAY4);
  214. Paint_DrawString_CN(150, 0,"ÄãºÃabc", &Font12CN, GRAY4, GRAY1);
  215. Paint_DrawString_CN(150, 20,"ÄãºÃabc", &Font12CN, GRAY3, GRAY2);
  216. Paint_DrawString_CN(150, 40,"ÄãºÃabc", &Font12CN, GRAY2, GRAY3);
  217. Paint_DrawString_CN(150, 60,"ÄãºÃabc", &Font12CN, GRAY1, GRAY4);
  218. Paint_DrawString_CN(10, 130, "΢ѩµç×Ó", &Font24CN, GRAY1, GRAY4);
  219. EPD_2IN7_V2_4GrayDisplay(BlackImage);
  220. DEV_Delay_ms(3000);
  221. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 0, WHITE);
  222. Paint_SetScale(4);
  223. Paint_Clear(WHITE);
  224. GUI_ReadBmp_4Gray("./pic/2in7_Scale.bmp", 0, 0);
  225. EPD_2IN7_V2_4GrayDisplay(BlackImage);
  226. DEV_Delay_ms(3000);
  227. #endif
  228. printf("Clear...\r\n");
  229. EPD_2IN7_V2_Init();
  230. EPD_2IN7_V2_Clear();
  231. printf("Goto Sleep...\r\n");
  232. EPD_2IN7_V2_Sleep();
  233. free(BlackImage);
  234. BlackImage = NULL;
  235. DEV_Delay_ms(2000);//important, at least 2s
  236. // close 5V
  237. printf("close 5V, Module enters 0 power consumption ...\r\n");
  238. DEV_Module_Exit();
  239. return 0;
  240. }