EPD_2in7_V2_test.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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-09-17
  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_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. EPD_2IN7_V2_Clear();
  43. //Create a new image cache
  44. UBYTE *BlackImage;
  45. UWORD Imagesize = ((EPD_2IN7_V2_WIDTH % 8 == 0)? (EPD_2IN7_V2_WIDTH / 8 ): (EPD_2IN7_V2_WIDTH / 8 + 1)) * EPD_2IN7_V2_HEIGHT;
  46. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  47. printf("Failed to apply for black memory...\r\n");
  48. return -1;
  49. }
  50. printf("Paint_NewImage\r\n");
  51. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 90, WHITE);
  52. Paint_Clear(WHITE);
  53. #if 1 // Fast Drawing on the image
  54. // Fast refresh
  55. printf("This is followed by a quick refresh demo\r\n");
  56. printf("First, clear the screen\r\n");
  57. EPD_2IN7_V2_Init();
  58. EPD_2IN7_V2_Clear();
  59. printf("e-Paper Init Fast\r\n");
  60. EPD_2IN7_V2_Init_Fast();
  61. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 90, WHITE);
  62. printf("Drawing\r\n");
  63. //1.Select Image
  64. Paint_SelectImage(BlackImage);
  65. // 2.Drawing on the image
  66. Paint_Clear(WHITE);
  67. printf("Drawing:BlackImage\r\n");
  68. Paint_DrawPoint(10, 80, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  69. Paint_DrawPoint(10, 90, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  70. Paint_DrawPoint(10, 100, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  71. Paint_DrawLine(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  72. Paint_DrawLine(70, 70, 20, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  73. Paint_DrawRectangle(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  74. Paint_DrawRectangle(80, 70, 130, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  75. Paint_DrawCircle(45, 95, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  76. Paint_DrawCircle(105, 95, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  77. Paint_DrawLine(85, 95, 125, 95, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  78. Paint_DrawLine(105, 75, 105, 115, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  79. Paint_DrawString_EN(10, 0, "waveshare", &Font16, BLACK, WHITE);
  80. Paint_DrawString_EN(10, 20, "hello world", &Font12, WHITE, BLACK);
  81. Paint_DrawNum(10, 33, 123456789, &Font12, BLACK, WHITE);
  82. Paint_DrawNum(10, 50, 987654321, &Font16, WHITE, BLACK);
  83. Paint_DrawString_CN(130, 0,"���abc", &Font12CN, BLACK, WHITE);
  84. Paint_DrawString_CN(130, 20, "΢ѩ����", &Font24CN, WHITE, BLACK);
  85. EPD_2IN7_V2_Display_Fast(BlackImage);
  86. DEV_Delay_ms(3000);
  87. #endif
  88. #if 1 // show bmp
  89. printf("show window BMP-----------------\r\n");
  90. EPD_2IN7_V2_Init();
  91. Paint_SelectImage(BlackImage);
  92. Paint_Clear(WHITE);
  93. Paint_DrawBitMap(gImage_2in7);
  94. EPD_2IN7_V2_Display(BlackImage);
  95. DEV_Delay_ms(3000);
  96. #endif
  97. #if 1 // Drawing on the image
  98. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 90, WHITE);
  99. printf("Drawing\r\n");
  100. //1.Select Image
  101. EPD_2IN7_V2_Init();
  102. Paint_SelectImage(BlackImage);
  103. Paint_Clear(WHITE);
  104. // 2.Drawing on the image
  105. printf("Drawing:BlackImage\r\n");
  106. Paint_DrawPoint(10, 80, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  107. Paint_DrawPoint(10, 90, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  108. Paint_DrawPoint(10, 100, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  109. Paint_DrawLine(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  110. Paint_DrawLine(70, 70, 20, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  111. Paint_DrawRectangle(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  112. Paint_DrawRectangle(80, 70, 130, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  113. Paint_DrawCircle(45, 95, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  114. Paint_DrawCircle(105, 95, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  115. Paint_DrawLine(85, 95, 125, 95, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  116. Paint_DrawLine(105, 75, 105, 115, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  117. Paint_DrawString_EN(10, 0, "waveshare", &Font16, BLACK, WHITE);
  118. Paint_DrawString_EN(10, 20, "hello world", &Font12, WHITE, BLACK);
  119. Paint_DrawNum(10, 33, 123456789, &Font12, BLACK, WHITE);
  120. Paint_DrawNum(10, 50, 987654321, &Font16, WHITE, BLACK);
  121. Paint_DrawString_CN(130, 0,"你好abc", &Font12CN, BLACK, WHITE);
  122. Paint_DrawString_CN(130, 20, "微雪电子", &Font24CN, WHITE, BLACK);
  123. EPD_2IN7_V2_Display_Base(BlackImage);
  124. DEV_Delay_ms(3000);
  125. #endif
  126. #if 1 //Partial refresh, example shows time
  127. // If you didn't use the EPD_2IN7_V2_Display_Base() function to refresh the image before,
  128. // use the EPD_2IN7_V2_Display_Base_color() function to refresh the background color,
  129. // otherwise the background color will be garbled
  130. EPD_2IN7_V2_Init();
  131. // EPD_2IN7_V2_Display_Base_color(WHITE);
  132. Paint_NewImage(BlackImage, 50, 120, 90, WHITE);
  133. printf("Partial refresh\r\n");
  134. Paint_SelectImage(BlackImage);
  135. Paint_SetScale(2);
  136. Paint_Clear(WHITE);
  137. PAINT_TIME sPaint_time;
  138. sPaint_time.Hour = 12;
  139. sPaint_time.Min = 34;
  140. sPaint_time.Sec = 56;
  141. UBYTE num = 15;
  142. for (;;) {
  143. sPaint_time.Sec = sPaint_time.Sec + 1;
  144. if (sPaint_time.Sec == 60) {
  145. sPaint_time.Min = sPaint_time.Min + 1;
  146. sPaint_time.Sec = 0;
  147. if (sPaint_time.Min == 60) {
  148. sPaint_time.Hour = sPaint_time.Hour + 1;
  149. sPaint_time.Min = 0;
  150. if (sPaint_time.Hour == 24) {
  151. sPaint_time.Hour = 0;
  152. sPaint_time.Min = 0;
  153. sPaint_time.Sec = 0;
  154. }
  155. }
  156. }
  157. Paint_Clear(WHITE);
  158. Paint_DrawRectangle(1, 1, 120, 50, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  159. Paint_DrawTime(10, 15, &sPaint_time, &Font20, WHITE, BLACK);
  160. num = num - 1;
  161. if(num == 0) {
  162. break;
  163. }
  164. printf("Part refresh...\r\n");
  165. EPD_2IN7_V2_Display_Partial(BlackImage, 60, 134, 110, 254); // Xstart must be a multiple of 8
  166. DEV_Delay_ms(500);
  167. }
  168. #endif
  169. #if 1 // show image for array
  170. free(BlackImage);
  171. printf("show Gray------------------------\r\n");
  172. Imagesize = ((EPD_2IN7_V2_WIDTH % 4 == 0)? (EPD_2IN7_V2_WIDTH / 4 ): (EPD_2IN7_V2_WIDTH / 4 + 1)) * EPD_2IN7_V2_HEIGHT;
  173. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  174. printf("Failed to apply for black memory...\r\n");
  175. return -1;
  176. }
  177. EPD_2IN7_V2_Init_4GRAY();
  178. printf("4 grayscale display\r\n");
  179. Paint_NewImage(BlackImage, EPD_2IN7_V2_WIDTH, EPD_2IN7_V2_HEIGHT, 90, WHITE);
  180. Paint_SetScale(4);
  181. Paint_Clear(0xff);
  182. Paint_DrawPoint(10, 80, GRAY4, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  183. Paint_DrawPoint(10, 90, GRAY4, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  184. Paint_DrawPoint(10, 100, GRAY4, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  185. Paint_DrawLine(20, 70, 70, 120, GRAY4, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  186. Paint_DrawLine(70, 70, 20, 120, GRAY4, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  187. Paint_DrawRectangle(20, 70, 70, 120, GRAY4, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  188. Paint_DrawRectangle(80, 70, 130, 120, GRAY4, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  189. Paint_DrawCircle(45, 95, 20, GRAY4, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  190. Paint_DrawCircle(105, 95, 20, GRAY2, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  191. Paint_DrawLine(85, 95, 125, 95, GRAY4, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  192. Paint_DrawLine(105, 75, 105, 115, GRAY4, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  193. Paint_DrawString_EN(10, 0, "waveshare", &Font16, GRAY4, GRAY1);
  194. Paint_DrawString_EN(10, 20, "hello world", &Font12, GRAY3, GRAY1);
  195. Paint_DrawNum(10, 33, 123456789, &Font12, GRAY4, GRAY2);
  196. Paint_DrawNum(10, 50, 987654321, &Font16, GRAY1, GRAY4);
  197. Paint_DrawString_CN(150, 0,"你好abc", &Font12CN, GRAY4, GRAY1);
  198. Paint_DrawString_CN(150, 20,"你好abc", &Font12CN, GRAY3, GRAY2);
  199. Paint_DrawString_CN(150, 40,"你好abc", &Font12CN, GRAY2, GRAY3);
  200. Paint_DrawString_CN(150, 60,"你好abc", &Font12CN, GRAY1, GRAY4);
  201. Paint_DrawString_CN(10, 130, "微雪电子", &Font24CN, GRAY1, GRAY4);
  202. EPD_2IN7_V2_4GrayDisplay(BlackImage);
  203. DEV_Delay_ms(3000);
  204. Paint_SelectImage(BlackImage);
  205. Paint_Clear(WHITE);
  206. Paint_DrawBitMap(gImage_2in7_4Gray);
  207. EPD_2IN7_V2_4GrayDisplay(BlackImage);
  208. DEV_Delay_ms(3000);
  209. #endif
  210. printf("Clear...\r\n");
  211. EPD_2IN7_V2_Init();
  212. EPD_2IN7_V2_Clear();
  213. printf("Goto Sleep...\r\n");
  214. EPD_2IN7_V2_Sleep();
  215. free(BlackImage);
  216. BlackImage = NULL;
  217. DEV_Delay_ms(2000);//important, at least 2s
  218. // close 5V
  219. printf("close 5V, Module enters 0 power consumption ...\r\n");
  220. DEV_Module_Exit();
  221. return 0;
  222. }