EPD_4in2_V2.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /*****************************************************************************
  2. * | File : EPD_4in2_V2.c
  3. * | Author : Waveshare team
  4. * | Function : 4.2inch e-paper V2
  5. * | Info :
  6. *----------------
  7. * | This version: V1.0
  8. * | Date : 2023-09-11
  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_4in2_V2.h"
  32. #include "Debug.h"
  33. const unsigned char LUT_ALL[233]={
  34. 0x01, 0x0A, 0x1B, 0x0F, 0x03, 0x01, 0x01,
  35. 0x05, 0x0A, 0x01, 0x0A, 0x01, 0x01, 0x01,
  36. 0x05, 0x08, 0x03, 0x02, 0x04, 0x01, 0x01,
  37. 0x01, 0x04, 0x04, 0x02, 0x00, 0x01, 0x01,
  38. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  39. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  40. 0x01, 0x0A, 0x1B, 0x0F, 0x03, 0x01, 0x01,
  41. 0x05, 0x4A, 0x01, 0x8A, 0x01, 0x01, 0x01,
  42. 0x05, 0x48, 0x03, 0x82, 0x84, 0x01, 0x01,
  43. 0x01, 0x84, 0x84, 0x82, 0x00, 0x01, 0x01,
  44. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  45. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  46. 0x01, 0x0A, 0x1B, 0x8F, 0x03, 0x01, 0x01,
  47. 0x05, 0x4A, 0x01, 0x8A, 0x01, 0x01, 0x01,
  48. 0x05, 0x48, 0x83, 0x82, 0x04, 0x01, 0x01,
  49. 0x01, 0x04, 0x04, 0x02, 0x00, 0x01, 0x01,
  50. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  51. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  52. 0x01, 0x8A, 0x1B, 0x8F, 0x03, 0x01, 0x01,
  53. 0x05, 0x4A, 0x01, 0x8A, 0x01, 0x01, 0x01,
  54. 0x05, 0x48, 0x83, 0x02, 0x04, 0x01, 0x01,
  55. 0x01, 0x04, 0x04, 0x02, 0x00, 0x01, 0x01,
  56. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  57. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  58. 0x01, 0x8A, 0x9B, 0x8F, 0x03, 0x01, 0x01,
  59. 0x05, 0x4A, 0x01, 0x8A, 0x01, 0x01, 0x01,
  60. 0x05, 0x48, 0x03, 0x42, 0x04, 0x01, 0x01,
  61. 0x01, 0x04, 0x04, 0x42, 0x00, 0x01, 0x01,
  62. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  63. 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  64. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  65. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. 0x02, 0x00, 0x00, 0x07, 0x17, 0x41, 0xA8,
  67. 0x32, 0x30,
  68. };
  69. /******************************************************************************
  70. function : Software reset
  71. parameter:
  72. ******************************************************************************/
  73. static void EPD_4IN2_V2_Reset(void)
  74. {
  75. DEV_Digital_Write(EPD_RST_PIN, 1);
  76. DEV_Delay_ms(100);
  77. DEV_Digital_Write(EPD_RST_PIN, 0);
  78. DEV_Delay_ms(2);
  79. DEV_Digital_Write(EPD_RST_PIN, 1);
  80. DEV_Delay_ms(100);
  81. }
  82. /******************************************************************************
  83. function : send command
  84. parameter:
  85. Reg : Command register
  86. ******************************************************************************/
  87. static void EPD_4IN2_V2_SendCommand(UBYTE Reg)
  88. {
  89. DEV_Digital_Write(EPD_DC_PIN, 0);
  90. DEV_Digital_Write(EPD_CS_PIN, 0);
  91. DEV_SPI_WriteByte(Reg);
  92. DEV_Digital_Write(EPD_CS_PIN, 1);
  93. }
  94. /******************************************************************************
  95. function : send data
  96. parameter:
  97. Data : Write data
  98. ******************************************************************************/
  99. static void EPD_4IN2_V2_SendData(UBYTE Data)
  100. {
  101. DEV_Digital_Write(EPD_DC_PIN, 1);
  102. DEV_Digital_Write(EPD_CS_PIN, 0);
  103. DEV_SPI_WriteByte(Data);
  104. DEV_Digital_Write(EPD_CS_PIN, 1);
  105. }
  106. /******************************************************************************
  107. function : Wait until the busy_pin goes LOW
  108. parameter:
  109. ******************************************************************************/
  110. void EPD_4IN2_V2_ReadBusy(void)
  111. {
  112. Debug("e-Paper busy\r\n");
  113. while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
  114. DEV_Delay_ms(10);
  115. }
  116. Debug("e-Paper busy release\r\n");
  117. }
  118. /******************************************************************************
  119. function : Turn On Display
  120. parameter:
  121. ******************************************************************************/
  122. static void EPD_4IN2_V2_TurnOnDisplay(void)
  123. {
  124. EPD_4IN2_V2_SendCommand(0x22);
  125. EPD_4IN2_V2_SendData(0xF7);
  126. EPD_4IN2_V2_SendCommand(0x20);
  127. EPD_4IN2_V2_ReadBusy();
  128. }
  129. static void EPD_4IN2_V2_TurnOnDisplay_Fast(void)
  130. {
  131. EPD_4IN2_V2_SendCommand(0x22);
  132. EPD_4IN2_V2_SendData(0xC7);
  133. EPD_4IN2_V2_SendCommand(0x20);
  134. EPD_4IN2_V2_ReadBusy();
  135. }
  136. static void EPD_4IN2_V2_TurnOnDisplay_Partial(void)
  137. {
  138. EPD_4IN2_V2_SendCommand(0x22);
  139. EPD_4IN2_V2_SendData(0xFF);
  140. EPD_4IN2_V2_SendCommand(0x20);
  141. EPD_4IN2_V2_ReadBusy();
  142. }
  143. static void EPD_4IN2_V2_TurnOnDisplay_4Gray(void)
  144. {
  145. EPD_4IN2_V2_SendCommand(0x22);
  146. EPD_4IN2_V2_SendData(0xCF);
  147. EPD_4IN2_V2_SendCommand(0x20);
  148. EPD_4IN2_V2_ReadBusy();
  149. }
  150. /******************************************************************************
  151. function : Setting the display window
  152. parameter:
  153. ******************************************************************************/
  154. static void EPD_4IN2_V2_SetWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
  155. {
  156. EPD_4IN2_V2_SendCommand(0x44); // SET_RAM_X_ADDRESS_START_END_POSITION
  157. EPD_4IN2_V2_SendData((Xstart>>3) & 0xFF);
  158. EPD_4IN2_V2_SendData((Xend>>3) & 0xFF);
  159. EPD_4IN2_V2_SendCommand(0x45); // SET_RAM_Y_ADDRESS_START_END_POSITION
  160. EPD_4IN2_V2_SendData(Ystart & 0xFF);
  161. EPD_4IN2_V2_SendData((Ystart >> 8) & 0xFF);
  162. EPD_4IN2_V2_SendData(Yend & 0xFF);
  163. EPD_4IN2_V2_SendData((Yend >> 8) & 0xFF);
  164. }
  165. /******************************************************************************
  166. function : Set Cursor
  167. parameter:
  168. ******************************************************************************/
  169. static void EPD_4IN2_V2_SetCursor(UWORD Xstart, UWORD Ystart)
  170. {
  171. EPD_4IN2_V2_SendCommand(0x4E); // SET_RAM_X_ADDRESS_COUNTER
  172. EPD_4IN2_V2_SendData(Xstart & 0xFF);
  173. EPD_4IN2_V2_SendCommand(0x4F); // SET_RAM_Y_ADDRESS_COUNTER
  174. EPD_4IN2_V2_SendData(Ystart & 0xFF);
  175. EPD_4IN2_V2_SendData((Ystart >> 8) & 0xFF);
  176. }
  177. //LUT download
  178. static void EPD_4IN2_V2_4Gray_lut(void)
  179. {
  180. unsigned char i;
  181. //WS byte 0~152, the content of VS[nX-LUTm], TP[nX], RP[n], SR[nXY], FR[n] and XON[nXY]
  182. EPD_4IN2_V2_SendCommand(0x32);
  183. for(i=0;i<227;i++)
  184. {
  185. EPD_4IN2_V2_SendData(LUT_ALL[i]);
  186. }
  187. //WS byte 153, the content of Option for LUT end
  188. EPD_4IN2_V2_SendCommand(0x3F);
  189. EPD_4IN2_V2_SendData(LUT_ALL[i++]);
  190. //WS byte 154, the content of gate leve
  191. EPD_4IN2_V2_SendCommand(0x03);
  192. EPD_4IN2_V2_SendData(LUT_ALL[i++]);//VGH
  193. //WS byte 155~157, the content of source level
  194. EPD_4IN2_V2_SendCommand(0x04);
  195. EPD_4IN2_V2_SendData(LUT_ALL[i++]);//VSH1
  196. EPD_4IN2_V2_SendData(LUT_ALL[i++]);//VSH2
  197. EPD_4IN2_V2_SendData(LUT_ALL[i++]);//VSL
  198. //WS byte 158, the content of VCOM level
  199. EPD_4IN2_V2_SendCommand(0x2c);
  200. EPD_4IN2_V2_SendData(LUT_ALL[i++]);//VCOM
  201. }
  202. /******************************************************************************
  203. function : Initialize the e-Paper register
  204. parameter:
  205. ******************************************************************************/
  206. void EPD_4IN2_V2_Init(void)
  207. {
  208. EPD_4IN2_V2_Reset();
  209. EPD_4IN2_V2_ReadBusy();
  210. EPD_4IN2_V2_SendCommand(0x12); // soft reset
  211. EPD_4IN2_V2_ReadBusy();
  212. EPD_4IN2_V2_SendCommand(0x21); // Display update control
  213. EPD_4IN2_V2_SendData(0x40);
  214. EPD_4IN2_V2_SendData(0x00);
  215. EPD_4IN2_V2_SendCommand(0x3C); //BorderWavefrom
  216. EPD_4IN2_V2_SendData(0x05);
  217. EPD_4IN2_V2_SendCommand(0x11); // data entry mode
  218. EPD_4IN2_V2_SendData(0x03); // X-mode
  219. EPD_4IN2_V2_SetWindows(0, 0, EPD_4IN2_V2_WIDTH-1, EPD_4IN2_V2_HEIGHT-1);
  220. EPD_4IN2_V2_SetCursor(0, 0);
  221. EPD_4IN2_V2_ReadBusy();
  222. }
  223. /******************************************************************************
  224. function : Initialize Fast the e-Paper register
  225. parameter:
  226. ******************************************************************************/
  227. void EPD_4IN2_V2_Init_Fast(UBYTE Mode)
  228. {
  229. EPD_4IN2_V2_Reset();
  230. EPD_4IN2_V2_ReadBusy();
  231. EPD_4IN2_V2_SendCommand(0x12); // soft reset
  232. EPD_4IN2_V2_ReadBusy();
  233. EPD_4IN2_V2_SendCommand(0x21);
  234. EPD_4IN2_V2_SendData(0x40);
  235. EPD_4IN2_V2_SendData(0x00);
  236. EPD_4IN2_V2_SendCommand(0x3C);
  237. EPD_4IN2_V2_SendData(0x05);
  238. if(Mode == Seconds_1_5S)
  239. {
  240. //1.5s
  241. EPD_4IN2_V2_SendCommand(0x1A); // Write to temperature register
  242. EPD_4IN2_V2_SendData(0x6E);
  243. }
  244. else if(Mode == Seconds_1S)
  245. {
  246. //1s
  247. EPD_4IN2_V2_SendCommand(0x1A); // Write to temperature register
  248. EPD_4IN2_V2_SendData(0x5A);
  249. }
  250. EPD_4IN2_V2_SendCommand(0x22); // Load temperature value
  251. EPD_4IN2_V2_SendData(0x91);
  252. EPD_4IN2_V2_SendCommand(0x20);
  253. EPD_4IN2_V2_ReadBusy();
  254. EPD_4IN2_V2_SendCommand(0x11); // data entry mode
  255. EPD_4IN2_V2_SendData(0x03); // X-mode
  256. EPD_4IN2_V2_SetWindows(0, 0, EPD_4IN2_V2_WIDTH-1, EPD_4IN2_V2_HEIGHT-1);
  257. EPD_4IN2_V2_SetCursor(0, 0);
  258. EPD_4IN2_V2_ReadBusy();
  259. }
  260. void EPD_4IN2_V2_Init_4Gray(void)
  261. {
  262. EPD_4IN2_V2_Reset();
  263. EPD_4IN2_V2_SendCommand(0x12); //SWRESET
  264. EPD_4IN2_V2_ReadBusy();
  265. EPD_4IN2_V2_SendCommand(0x21);
  266. EPD_4IN2_V2_SendData(0x00);
  267. EPD_4IN2_V2_SendData(0x00);
  268. EPD_4IN2_V2_SendCommand(0x3C);
  269. EPD_4IN2_V2_SendData(0x03);
  270. EPD_4IN2_V2_SendCommand(0x0C); //BTST
  271. EPD_4IN2_V2_SendData(0x8B);//8B
  272. EPD_4IN2_V2_SendData(0x9C);//9C
  273. EPD_4IN2_V2_SendData(0xA4);//96 A4
  274. EPD_4IN2_V2_SendData(0x0F);//0F
  275. EPD_4IN2_V2_4Gray_lut(); //LUT
  276. EPD_4IN2_V2_SendCommand(0x11); // data entry mode
  277. EPD_4IN2_V2_SendData(0x03); // X-mode
  278. EPD_4IN2_V2_SetWindows(0, 0, EPD_4IN2_V2_WIDTH-1, EPD_4IN2_V2_HEIGHT-1);
  279. EPD_4IN2_V2_SetCursor(0, 0);
  280. }
  281. /******************************************************************************
  282. function : Clear screen
  283. parameter:
  284. ******************************************************************************/
  285. void EPD_4IN2_V2_Clear(void)
  286. {
  287. UWORD Width, Height;
  288. Width = (EPD_4IN2_V2_WIDTH % 8 == 0)? (EPD_4IN2_V2_WIDTH / 8 ): (EPD_4IN2_V2_WIDTH / 8 + 1);
  289. Height = EPD_4IN2_V2_HEIGHT;
  290. EPD_4IN2_V2_SendCommand(0x24);
  291. for (UWORD j = 0; j < Height; j++) {
  292. for (UWORD i = 0; i < Width; i++) {
  293. EPD_4IN2_V2_SendData(0xFF);
  294. }
  295. }
  296. EPD_4IN2_V2_SendCommand(0x26);
  297. for (UWORD j = 0; j < Height; j++) {
  298. for (UWORD i = 0; i < Width; i++) {
  299. EPD_4IN2_V2_SendData(0xFF);
  300. }
  301. }
  302. EPD_4IN2_V2_TurnOnDisplay();
  303. }
  304. /******************************************************************************
  305. function : Sends the image buffer in RAM to e-Paper and displays
  306. parameter:
  307. ******************************************************************************/
  308. void EPD_4IN2_V2_Display(UBYTE *Image)
  309. {
  310. UWORD Width, Height;
  311. Width = (EPD_4IN2_V2_WIDTH % 8 == 0)? (EPD_4IN2_V2_WIDTH / 8 ): (EPD_4IN2_V2_WIDTH / 8 + 1);
  312. Height = EPD_4IN2_V2_HEIGHT;
  313. EPD_4IN2_V2_SendCommand(0x24);
  314. for (UWORD j = 0; j < Height; j++) {
  315. for (UWORD i = 0; i < Width; i++) {
  316. EPD_4IN2_V2_SendData(Image[i + j * Width]);
  317. }
  318. }
  319. EPD_4IN2_V2_SendCommand(0x26);
  320. for (UWORD j = 0; j < Height; j++) {
  321. for (UWORD i = 0; i < Width; i++) {
  322. EPD_4IN2_V2_SendData(Image[i + j * Width]);
  323. }
  324. }
  325. EPD_4IN2_V2_TurnOnDisplay();
  326. }
  327. /******************************************************************************
  328. function : Sends the image buffer in RAM to e-Paper and fast displays
  329. parameter:
  330. ******************************************************************************/
  331. void EPD_4IN2_V2_Display_Fast(UBYTE *Image)
  332. {
  333. UWORD Width, Height;
  334. Width = (EPD_4IN2_V2_WIDTH % 8 == 0)? (EPD_4IN2_V2_WIDTH / 8 ): (EPD_4IN2_V2_WIDTH / 8 + 1);
  335. Height = EPD_4IN2_V2_HEIGHT;
  336. EPD_4IN2_V2_SendCommand(0x24);
  337. for (UWORD j = 0; j < Height; j++) {
  338. for (UWORD i = 0; i < Width; i++) {
  339. EPD_4IN2_V2_SendData(Image[i + j * Width]);
  340. }
  341. }
  342. EPD_4IN2_V2_SendCommand(0x26);
  343. for (UWORD j = 0; j < Height; j++) {
  344. for (UWORD i = 0; i < Width; i++) {
  345. EPD_4IN2_V2_SendData(Image[i + j * Width]);
  346. }
  347. }
  348. EPD_4IN2_V2_TurnOnDisplay_Fast();
  349. }
  350. void EPD_4IN2_V2_Display_4Gray(UBYTE *Image)
  351. {
  352. UDOUBLE i,j,k,m;
  353. UBYTE temp1,temp2,temp3;
  354. /****Color display description****
  355. white gray2 gray1 black
  356. 0x10| 01 01 00 00
  357. 0x13| 01 00 01 00
  358. *********************************/
  359. EPD_4IN2_V2_SendCommand(0x24);
  360. // EPD_4IN2_HEIGHT
  361. // EPD_4IN2_WIDTH
  362. for(m = 0; m<EPD_4IN2_V2_HEIGHT;m++)
  363. for(i=0;i<EPD_4IN2_V2_WIDTH/8;i++)
  364. {
  365. temp3=0;
  366. for(j=0;j<2;j++)
  367. {
  368. temp1 = Image[(m*(EPD_4IN2_V2_WIDTH/8)+i)*2+j];
  369. for(k=0;k<2;k++)
  370. {
  371. temp2 = temp1&0xC0 ;
  372. if(temp2 == 0xC0)
  373. temp3 |= 0x01;//white
  374. else if(temp2 == 0x00)
  375. temp3 |= 0x00; //black
  376. else if(temp2 == 0x80)
  377. temp3 |= 0x00; //gray1
  378. else //0x40
  379. temp3 |= 0x01; //gray2
  380. temp3 <<= 1;
  381. temp1 <<= 2;
  382. temp2 = temp1&0xC0 ;
  383. if(temp2 == 0xC0) //white
  384. temp3 |= 0x01;
  385. else if(temp2 == 0x00) //black
  386. temp3 |= 0x00;
  387. else if(temp2 == 0x80)
  388. temp3 |= 0x00; //gray1
  389. else //0x40
  390. temp3 |= 0x01; //gray2
  391. if(j!=1 || k!=1)
  392. temp3 <<= 1;
  393. temp1 <<= 2;
  394. }
  395. }
  396. EPD_4IN2_V2_SendData(temp3);
  397. }
  398. // new data
  399. EPD_4IN2_V2_SendCommand(0x26);
  400. for(m = 0; m<EPD_4IN2_V2_HEIGHT;m++)
  401. for(i=0;i<EPD_4IN2_V2_WIDTH/8;i++)
  402. {
  403. temp3=0;
  404. for(j=0;j<2;j++)
  405. {
  406. temp1 = Image[(m*(EPD_4IN2_V2_WIDTH/8)+i)*2+j];
  407. for(k=0;k<2;k++)
  408. {
  409. temp2 = temp1&0xC0 ;
  410. if(temp2 == 0xC0)
  411. temp3 |= 0x01;//white
  412. else if(temp2 == 0x00)
  413. temp3 |= 0x00; //black
  414. else if(temp2 == 0x80)
  415. temp3 |= 0x01; //gray1
  416. else //0x40
  417. temp3 |= 0x00; //gray2
  418. temp3 <<= 1;
  419. temp1 <<= 2;
  420. temp2 = temp1&0xC0 ;
  421. if(temp2 == 0xC0) //white
  422. temp3 |= 0x01;
  423. else if(temp2 == 0x00) //black
  424. temp3 |= 0x00;
  425. else if(temp2 == 0x80)
  426. temp3 |= 0x01; //gray1
  427. else //0x40
  428. temp3 |= 0x00; //gray2
  429. if(j!=1 || k!=1)
  430. temp3 <<= 1;
  431. temp1 <<= 2;
  432. }
  433. }
  434. EPD_4IN2_V2_SendData(temp3);
  435. }
  436. EPD_4IN2_V2_TurnOnDisplay_4Gray();
  437. }
  438. // Send partial data for partial refresh
  439. void EPD_4IN2_V2_PartialDisplay(UBYTE *Image, UWORD x, UWORD y, UWORD w, UWORD l)
  440. {
  441. UWORD Width, Height;
  442. Width = (w % 8 == 0)? (w / 8 ): (w / 8 + 1);
  443. Height = l;
  444. EPD_4IN2_V2_SendCommand(0x3C); //BorderWavefrom,
  445. EPD_4IN2_V2_SendData(0x80);
  446. EPD_4IN2_V2_SendCommand(0x21);
  447. EPD_4IN2_V2_SendData(0x00);
  448. EPD_4IN2_V2_SendData(0x00);
  449. EPD_4IN2_V2_SendCommand(0x3C);
  450. EPD_4IN2_V2_SendData(0x80);
  451. EPD_4IN2_V2_SetWindows(x, y, x+w-1, y+l-1);
  452. EPD_4IN2_V2_SetCursor(x, y);
  453. EPD_4IN2_V2_SendCommand(0x24);
  454. for (UWORD j = 0; j < Height; j++) {
  455. for (UWORD i = 0; i < Width; i++) {
  456. EPD_4IN2_V2_SendData(Image[i + j * Width]);
  457. }
  458. }
  459. EPD_4IN2_V2_TurnOnDisplay_Partial();
  460. }
  461. /******************************************************************************
  462. function : Enter sleep mode
  463. parameter:
  464. ******************************************************************************/
  465. void EPD_4IN2_V2_Sleep(void)
  466. {
  467. EPD_4IN2_V2_SendCommand(0x10); // DEEP_SLEEP
  468. EPD_4IN2_V2_SendData(0x01);
  469. DEV_Delay_ms(200);
  470. }