EPD_7in5_V2_old.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*****************************************************************************
  2. * | File : EPD_7in5.c
  3. * | Author : Waveshare team
  4. * | Function : Electronic paper driver
  5. * | Info :
  6. *----------------
  7. * | This version: V1.0
  8. * | Date : 2023-12-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_7in5_V2_old.h"
  32. #include "Debug.h"
  33. #include <time.h>
  34. UBYTE Voltage_Frame_7IN5_V2[]={
  35. 0x6, 0x3F, 0x3F, 0x11, 0x24, 0x7, 0x17,
  36. };
  37. UBYTE LUT_VCOM_7IN5_V2[]={
  38. 0x0, 0xF, 0xF, 0x0, 0x0, 0x1,
  39. 0x0, 0xF, 0x1, 0xF, 0x1, 0x2,
  40. 0x0, 0xF, 0xF, 0x0, 0x0, 0x1,
  41. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  42. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  43. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  44. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  45. };
  46. UBYTE LUT_WW_7IN5_V2[]={
  47. 0x10, 0xF, 0xF, 0x0, 0x0, 0x1,
  48. 0x84, 0xF, 0x1, 0xF, 0x1, 0x2,
  49. 0x20, 0xF, 0xF, 0x0, 0x0, 0x1,
  50. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  51. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  52. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  53. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  54. };
  55. UBYTE LUT_BW_7IN5_V2[]={
  56. 0x10, 0xF, 0xF, 0x0, 0x0, 0x1,
  57. 0x84, 0xF, 0x1, 0xF, 0x1, 0x2,
  58. 0x20, 0xF, 0xF, 0x0, 0x0, 0x1,
  59. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  60. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  61. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  62. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  63. };
  64. UBYTE LUT_WB_7IN5_V2[]={
  65. 0x80, 0xF, 0xF, 0x0, 0x0, 0x1,
  66. 0x84, 0xF, 0x1, 0xF, 0x1, 0x2,
  67. 0x40, 0xF, 0xF, 0x0, 0x0, 0x1,
  68. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  69. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  70. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  71. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  72. };
  73. UBYTE LUT_BB_7IN5_V2[]={
  74. 0x80, 0xF, 0xF, 0x0, 0x0, 0x1,
  75. 0x84, 0xF, 0x1, 0xF, 0x1, 0x2,
  76. 0x40, 0xF, 0xF, 0x0, 0x0, 0x1,
  77. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  78. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  79. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  80. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  81. };
  82. const unsigned char
  83. Lut_all_fresh[]={0x67, 0xBF, 0x3F, 0x0D, 0x00, 0x1C,
  84. //VCOM
  85. 0x00, 0x32, 0x32, 0x00, 0x00, 0x01,
  86. 0x00, 0x0A, 0x0A, 0x00, 0x00, 0x00,
  87. 0x00, 0x28, 0x00, 0x00, 0x00, 0x00,
  88. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  89. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  90. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  91. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  92. //WW
  93. 0x60, 0x32, 0x32, 0x00, 0x00, 0x01,
  94. 0x60, 0x0A, 0x0A, 0x00, 0x00, 0x00,
  95. 0x80, 0x28, 0x00, 0x00, 0x00, 0x00,
  96. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  97. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  98. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  99. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  100. //BW
  101. 0x60, 0x32, 0x32, 0x00, 0x00, 0x01,
  102. 0x60, 0x0A, 0x0A, 0x00, 0x00, 0x00,
  103. 0x80, 0x28, 0x00, 0x00, 0x00, 0x00,
  104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  105. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  107. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  108. //WB
  109. 0x90, 0x32, 0x32, 0x00, 0x00, 0x01,
  110. 0x60, 0x0A, 0x0A, 0x00, 0x00, 0x00,
  111. 0x40, 0x28, 0x00, 0x00, 0x00, 0x00,
  112. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  113. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  114. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  115. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  116. //BB
  117. 0x90, 0x32, 0x32, 0x00, 0x00, 0x01,
  118. 0x60, 0x0A, 0x0A, 0x00, 0x00, 0x00,
  119. 0x40, 0x28, 0x00, 0x00, 0x00, 0x00,
  120. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  121. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  122. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  123. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  124. //Reserved
  125. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  126. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  127. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  128. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  129. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  130. 0xFF,
  131. };
  132. const unsigned char
  133. Lut_partial[]={0x67, 0xBF, 0x3F, 0x0D, 0x00, 0x1C,
  134. //VCOM
  135. 0x00, 0x14, 0x02, 0x00, 0x00, 0x01,
  136. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  137. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  138. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  139. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  140. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  141. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  142. //WW
  143. 0x20, 0x14, 0x02, 0x00, 0x00, 0x01,
  144. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  145. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  147. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  148. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  149. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  150. //BW
  151. 0x80, 0x14, 0x02, 0x00, 0x00, 0x01,
  152. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  153. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  154. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  155. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  156. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  157. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  158. //WB
  159. 0x40, 0x14, 0x02, 0x00, 0x00, 0x01,
  160. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  161. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  162. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  163. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  164. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  165. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  166. //BB
  167. 0x00, 0x14, 0x02, 0x00, 0x00, 0x01,
  168. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  169. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  170. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  171. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  172. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  173. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  174. //Reserved
  175. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  176. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  177. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  178. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  179. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  180. 0xFF,
  181. };
  182. /******************************************************************************
  183. function : Software reset
  184. parameter:
  185. ******************************************************************************/
  186. static void EPD_Reset(void)
  187. {
  188. DEV_Digital_Write(EPD_RST_PIN, 1);
  189. DEV_Delay_ms(20);
  190. DEV_Digital_Write(EPD_RST_PIN, 0);
  191. DEV_Delay_ms(2);
  192. DEV_Digital_Write(EPD_RST_PIN, 1);
  193. DEV_Delay_ms(20);
  194. }
  195. /******************************************************************************
  196. function : send command
  197. parameter:
  198. Reg : Command register
  199. ******************************************************************************/
  200. static void EPD_SendCommand(UBYTE Reg)
  201. {
  202. DEV_Digital_Write(EPD_DC_PIN, 0);
  203. DEV_Digital_Write(EPD_CS_PIN, 0);
  204. DEV_SPI_WriteByte(Reg);
  205. DEV_Digital_Write(EPD_CS_PIN, 1);
  206. }
  207. /******************************************************************************
  208. function : send data
  209. parameter:
  210. Data : Write data
  211. ******************************************************************************/
  212. static void EPD_SendData(UBYTE Data)
  213. {
  214. DEV_Digital_Write(EPD_DC_PIN, 1);
  215. DEV_Digital_Write(EPD_CS_PIN, 0);
  216. DEV_SPI_WriteByte(Data);
  217. DEV_Digital_Write(EPD_CS_PIN, 1);
  218. }
  219. static void EPD_SendData2(UBYTE *pData, UDOUBLE len)
  220. {
  221. DEV_Digital_Write(EPD_DC_PIN, 1);
  222. DEV_Digital_Write(EPD_CS_PIN, 0);
  223. DEV_SPI_Write_nByte(pData, len);
  224. DEV_Digital_Write(EPD_CS_PIN, 1);
  225. }
  226. /******************************************************************************
  227. function : Wait until the busy_pin goes LOW
  228. parameter:
  229. ******************************************************************************/
  230. static void EPD_WaitUntilIdle(void)
  231. {
  232. Debug("e-Paper busy\r\n");
  233. do{
  234. DEV_Delay_ms(5);
  235. }while(!(DEV_Digital_Read(EPD_BUSY_PIN)));
  236. DEV_Delay_ms(5);
  237. Debug("e-Paper busy release\r\n");
  238. }
  239. static void EPD_7IN5_V2_LUT(UBYTE* lut_vcom, UBYTE* lut_ww, UBYTE* lut_bw, UBYTE* lut_wb, UBYTE* lut_bb)
  240. {
  241. UBYTE count;
  242. EPD_SendCommand(0x20); //VCOM
  243. for(count=0; count<42; count++)
  244. EPD_SendData(lut_vcom[count]);
  245. EPD_SendCommand(0x21); //LUTBW
  246. for(count=0; count<42; count++)
  247. EPD_SendData(lut_ww[count]);
  248. EPD_SendCommand(0x22); //LUTBW
  249. for(count=0; count<42; count++)
  250. EPD_SendData(lut_bw[count]);
  251. EPD_SendCommand(0x23); //LUTWB
  252. for(count=0; count<42; count++)
  253. EPD_SendData(lut_wb[count]);
  254. EPD_SendCommand(0x24); //LUTBB
  255. for(count=0; count<42; count++)
  256. EPD_SendData(lut_bb[count]);
  257. }
  258. /******************************************************************************
  259. function : Turn On Display
  260. parameter:
  261. ******************************************************************************/
  262. static void EPD_7IN5_V2_TurnOnDisplay(void)
  263. {
  264. EPD_SendCommand(0x12); //DISPLAY REFRESH
  265. DEV_Delay_ms(100); //!!!The delay here is necessary, 200uS at least!!!
  266. EPD_WaitUntilIdle();
  267. }
  268. /******************************************************************************
  269. function : Initialize the e-Paper register
  270. parameter:
  271. ******************************************************************************/
  272. UBYTE EPD_7IN5_V2_Init(void)
  273. {
  274. EPD_Reset();
  275. // EPD_SendCommand(0x01); //POWER SETTING
  276. // EPD_SendData(0x07);
  277. // EPD_SendData(0x07); //VGH=20V,VGL=-20V
  278. // EPD_SendData(0x3f); //VDH=15V
  279. // EPD_SendData(0x3f); //VDL=-15V
  280. EPD_SendCommand(0x01); // power setting
  281. EPD_SendData(0x17); // 1-0=11: internal power
  282. EPD_SendData(*(Voltage_Frame_7IN5_V2+6)); // VGH&VGL
  283. EPD_SendData(*(Voltage_Frame_7IN5_V2+1)); // VSH
  284. EPD_SendData(*(Voltage_Frame_7IN5_V2+2)); // VSL
  285. EPD_SendData(*(Voltage_Frame_7IN5_V2+3)); // VSHR
  286. EPD_SendCommand(0x82); // VCOM DC Setting
  287. EPD_SendData(*(Voltage_Frame_7IN5_V2+4)); // VCOM
  288. EPD_SendCommand(0x06); // Booster Setting
  289. EPD_SendData(0x27);
  290. EPD_SendData(0x27);
  291. EPD_SendData(0x2F);
  292. EPD_SendData(0x17);
  293. EPD_SendCommand(0x30); // OSC Setting
  294. EPD_SendData(*(Voltage_Frame_7IN5_V2+0)); // 2-0=100: N=4 ; 5-3=111: M=7 ; 3C=50Hz 3A=100HZ
  295. EPD_SendCommand(0x04); //POWER ON
  296. DEV_Delay_ms(100);
  297. EPD_WaitUntilIdle();
  298. EPD_SendCommand(0X00); //PANNEL SETTING
  299. EPD_SendData(0x3F); //KW-3f KWR-2F BWROTP 0f BWOTP 1f
  300. EPD_SendCommand(0x61); //tres
  301. EPD_SendData(0x03); //source 800
  302. EPD_SendData(0x20);
  303. EPD_SendData(0x01); //gate 480
  304. EPD_SendData(0xE0);
  305. EPD_SendCommand(0X15);
  306. EPD_SendData(0x00);
  307. EPD_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
  308. EPD_SendData(0x10);
  309. EPD_SendData(0x00);
  310. EPD_SendCommand(0X60); //TCON SETTING
  311. EPD_SendData(0x22);
  312. EPD_SendCommand(0x65); // Resolution setting
  313. EPD_SendData(0x00);
  314. EPD_SendData(0x00);//800*480
  315. EPD_SendData(0x00);
  316. EPD_SendData(0x00);
  317. EPD_7IN5_V2_LUT(LUT_VCOM_7IN5_V2, LUT_WW_7IN5_V2, LUT_BW_7IN5_V2, LUT_WB_7IN5_V2, LUT_BB_7IN5_V2);
  318. return 0;
  319. }
  320. void Epaper_LUT_By_MCU( UBYTE* wavedata)
  321. {
  322. UBYTE count;
  323. UBYTE VCEND,BDEND,EVS,XON,PLL;
  324. VCEND=wavedata[0]&0x08;
  325. BDEND=(wavedata[1]&0xC0)>>6;
  326. EVS=VCEND|BDEND;
  327. PLL=(wavedata[0]&0xF0)>>4;
  328. XON=wavedata[2]&0xC0;
  329. EPD_SendCommand(0x52); //EVS
  330. EPD_SendData(EVS);
  331. EPD_SendCommand(0x30); //PLL setting
  332. EPD_SendData(PLL);
  333. EPD_SendCommand(0x01); //Set VGH VGL VSH VSL VSHR
  334. EPD_SendData (0x17);
  335. EPD_SendData ((*wavedata++)&0x07); //VGH/VGL Voltage Level selection
  336. EPD_SendData ((*wavedata++)&0x3F); //VSH for black
  337. EPD_SendData ((*wavedata++)&0x3F); //VSL for white
  338. EPD_SendData ((*wavedata++)&0x3F); //VSHR for red
  339. EPD_SendCommand(0x2A); //LUTOPT
  340. EPD_SendData(XON);
  341. EPD_SendData(*wavedata++);
  342. EPD_SendCommand(0x82); //VCOM_DC setting
  343. EPD_SendData (*wavedata++); //Vcom value
  344. EPD_SendCommand(0x20);
  345. for(count=0;count<42;count++)
  346. EPD_SendData(*wavedata++);
  347. EPD_SendCommand(0x21);
  348. for(count=0;count<42;count++)
  349. EPD_SendData(*wavedata++);
  350. EPD_SendCommand(0x22);
  351. for(count=0;count<42;count++)
  352. EPD_SendData(*wavedata++);
  353. EPD_SendCommand(0x23);
  354. for(count=0;count<42;count++)
  355. EPD_SendData(*wavedata++);
  356. EPD_SendCommand(0x24);
  357. for(count=0;count<42;count++)
  358. EPD_SendData(*wavedata++);
  359. }
  360. UBYTE EPD_7IN5_V2_Init2(void)
  361. {
  362. EPD_Reset();
  363. EPD_SendCommand(0x00); // Panel setting
  364. EPD_SendData(0x3F);
  365. EPD_SendCommand(0x06); // Booster Setting
  366. EPD_SendData(0x17);
  367. EPD_SendData(0x17);
  368. EPD_SendData(0x28);
  369. EPD_SendData(0x18);
  370. EPD_SendCommand(0x50); // VCOM and DATA interval setting
  371. EPD_SendData(0x22);
  372. EPD_SendData(0x07);
  373. EPD_SendCommand(0x60); // TCON setting
  374. EPD_SendData(0x22); // S-G G-S
  375. EPD_SendCommand(0x61); // Resolution setting
  376. EPD_SendData(0x03);//800*480
  377. EPD_SendData(0x20);
  378. EPD_SendData(0x01);
  379. EPD_SendData(0xE0);
  380. EPD_SendCommand(0x65); // Resolution setting
  381. EPD_SendData(0x00);
  382. EPD_SendData(0x00);
  383. EPD_SendData(0x00);
  384. EPD_SendData(0x00);
  385. EPD_SendCommand(0x04); //POWER ON
  386. DEV_Delay_ms(100);
  387. EPD_WaitUntilIdle();
  388. return 0;
  389. }
  390. UBYTE EPD_7IN5_V2_Init_Fast(void)
  391. {
  392. EPD_7IN5_V2_Init2();
  393. Epaper_LUT_By_MCU((UBYTE*)Lut_all_fresh);
  394. return 0;
  395. }
  396. UBYTE EPD_7IN5_V2_Init_Partial(void)
  397. {
  398. EPD_7IN5_V2_Init2();
  399. Epaper_LUT_By_MCU((UBYTE*)Lut_partial);
  400. return 0;
  401. }
  402. /******************************************************************************
  403. function : Clear screen
  404. parameter:
  405. ******************************************************************************/
  406. void EPD_7IN5_V2_Clear(void)
  407. {
  408. UWORD Width, Height;
  409. Width =(EPD_7IN5_V2_WIDTH % 8 == 0)?(EPD_7IN5_V2_WIDTH / 8 ):(EPD_7IN5_V2_WIDTH / 8 + 1);
  410. Height = EPD_7IN5_V2_HEIGHT;
  411. UBYTE image[EPD_7IN5_V2_WIDTH / 8] = {0x00};
  412. UWORD i;
  413. EPD_SendCommand(0x10);
  414. for(i=0; i<Width; i++) {
  415. image[i] = 0xFF;
  416. }
  417. for(i=0; i<Height; i++)
  418. {
  419. EPD_SendData2(image, Width);
  420. }
  421. EPD_SendCommand(0x13);
  422. for(i=0; i<Width; i++) {
  423. image[i] = 0x00;
  424. }
  425. for(i=0; i<Height; i++)
  426. {
  427. EPD_SendData2(image, Width);
  428. }
  429. EPD_7IN5_V2_TurnOnDisplay();
  430. }
  431. void EPD_7IN5_V2_ClearBlack(void)
  432. {
  433. UWORD Width, Height;
  434. Width =(EPD_7IN5_V2_WIDTH % 8 == 0)?(EPD_7IN5_V2_WIDTH / 8 ):(EPD_7IN5_V2_WIDTH / 8 + 1);
  435. Height = EPD_7IN5_V2_HEIGHT;
  436. UBYTE image[EPD_7IN5_V2_WIDTH / 8] = {0x00};
  437. UWORD i;
  438. EPD_SendCommand(0x10);
  439. for(i=0; i<Width; i++) {
  440. image[i] = 0x00;
  441. }
  442. for(i=0; i<Height; i++)
  443. {
  444. EPD_SendData2(image, Width);
  445. }
  446. EPD_SendCommand(0x13);
  447. for(i=0; i<Width; i++) {
  448. image[i] = 0xFF;
  449. }
  450. for(i=0; i<Height; i++)
  451. {
  452. EPD_SendData2(image, Width);
  453. }
  454. EPD_7IN5_V2_TurnOnDisplay();
  455. }
  456. /******************************************************************************
  457. function : Sends the image buffer in RAM to e-Paper and displays
  458. parameter:
  459. ******************************************************************************/
  460. void EPD_7IN5_V2_Display(UBYTE *blackimage)
  461. {
  462. UDOUBLE Width, Height;
  463. Width =(EPD_7IN5_V2_WIDTH % 8 == 0)?(EPD_7IN5_V2_WIDTH / 8 ):(EPD_7IN5_V2_WIDTH / 8 + 1);
  464. Height = EPD_7IN5_V2_HEIGHT;
  465. EPD_SendCommand(0x10);
  466. for (UDOUBLE j = 0; j < Height; j++) {
  467. EPD_SendData2((UBYTE *)(blackimage+j*Width), Width);
  468. }
  469. EPD_SendCommand(0x13);
  470. for (UDOUBLE j = 0; j < Height; j++) {
  471. for (UDOUBLE i = 0; i < Width; i++) {
  472. blackimage[i + j * Width] = ~blackimage[i + j * Width];
  473. }
  474. }
  475. for (UDOUBLE j = 0; j < Height; j++) {
  476. EPD_SendData2((UBYTE *)(blackimage+j*Width), Width);
  477. }
  478. EPD_7IN5_V2_TurnOnDisplay();
  479. }
  480. void EPD_7IN5_V2_Display_Partial(UBYTE *blackimage,UDOUBLE x_start, UDOUBLE y_start, UDOUBLE x_end, UDOUBLE y_end)
  481. {
  482. UDOUBLE Width, Height;
  483. Width =((x_end - x_start) % 8 == 0)?((x_end - x_start) / 8 ):((x_end - x_start) / 8 + 1);
  484. Height = y_end - y_start;
  485. EPD_SendCommand(0x91); //This command makes the display enter partial mode
  486. EPD_SendCommand(0x90); //resolution setting
  487. EPD_SendData(x_start/256);
  488. EPD_SendData(x_start%256); //x-start
  489. EPD_SendData((x_end-1)/256);
  490. EPD_SendData((x_end-1)%256); //x-end
  491. EPD_SendData(y_start/256); //
  492. EPD_SendData(y_start%256); //y-start
  493. EPD_SendData((y_end-1)/256);
  494. EPD_SendData((y_end-1)%256); //y-end
  495. EPD_SendData(0x01);
  496. // for (UDOUBLE j = 0; j < Height; j++) {
  497. // for (UDOUBLE i = 0; i < Width; i++) {
  498. // blackimage[i+j*Width] = ~blackimage[i+j*Width];
  499. // }
  500. // }
  501. EPD_SendCommand(0x13);
  502. for (UDOUBLE j = 0; j < Height; j++) {
  503. EPD_SendData2((UBYTE *)(blackimage+j*Width), Width);
  504. }
  505. EPD_7IN5_V2_TurnOnDisplay();
  506. EPD_SendCommand(0x92);
  507. }
  508. /******************************************************************************
  509. function : Enter sleep mode
  510. parameter:
  511. ******************************************************************************/
  512. void EPD_7IN5_V2_Sleep(void)
  513. {
  514. EPD_SendCommand(0X02); //power off
  515. EPD_WaitUntilIdle();
  516. EPD_SendCommand(0X07); //deep sleep
  517. EPD_SendData(0xA5);
  518. }