EPD_3in7.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*****************************************************************************
  2. * | File : EPD_3IN7.C
  3. * | Author : Waveshare team
  4. * | Function : 3.7inch e-paper
  5. * | Info :
  6. *----------------
  7. * | This version: V1.0
  8. * | Date : 2020-07-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_3in7.h"
  32. #include "Debug.h"
  33. static const UBYTE lut_4Gray_GC[] =
  34. {
  35. 0x2A,0x06,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//1
  36. 0x28,0x06,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//2
  37. 0x20,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//3
  38. 0x14,0x06,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//4
  39. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//5
  40. 0x00,0x02,0x02,0x0A,0x00,0x00,0x00,0x08,0x08,0x02,//6
  41. 0x00,0x02,0x02,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,//7
  42. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//8
  43. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//9
  44. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//10
  45. 0x22,0x22,0x22,0x22,0x22
  46. };
  47. static const UBYTE lut_1Gray_GC[] =
  48. {
  49. 0x2A,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//1
  50. 0x05,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//2
  51. 0x2A,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//3
  52. 0x05,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//4
  53. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//5
  54. 0x00,0x02,0x03,0x0A,0x00,0x02,0x06,0x0A,0x05,0x00,//6
  55. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//7
  56. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//8
  57. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//9
  58. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//10
  59. 0x22,0x22,0x22,0x22,0x22
  60. };
  61. static const UBYTE lut_1Gray_DU[] =
  62. {
  63. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//1
  64. 0x01,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65. 0x0A,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//3
  66. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//5
  68. 0x00,0x00,0x05,0x05,0x00,0x05,0x03,0x05,0x05,0x00,
  69. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//7
  70. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//9
  72. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73. 0x22,0x22,0x22,0x22,0x22
  74. };
  75. static const UBYTE lut_1Gray_A2[] =
  76. {
  77. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //1
  78. 0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //2
  79. 0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //3
  80. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //4
  81. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //5
  82. 0x00,0x00,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00, //6
  83. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //7
  84. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //8
  85. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //9
  86. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //10
  87. 0x22,0x22,0x22,0x22,0x22
  88. };
  89. /******************************************************************************
  90. function : Software reset
  91. parameter:
  92. ******************************************************************************/
  93. static void EPD_3IN7_Reset(void)
  94. {
  95. DEV_Digital_Write(EPD_RST_PIN, 1);
  96. DEV_Delay_ms(300);
  97. DEV_Digital_Write(EPD_RST_PIN, 0);
  98. DEV_Delay_ms(3);
  99. DEV_Digital_Write(EPD_RST_PIN, 1);
  100. DEV_Delay_ms(300);
  101. }
  102. /******************************************************************************
  103. function : send command
  104. parameter:
  105. Reg : Command register
  106. ******************************************************************************/
  107. static void EPD_3IN7_SendCommand(UBYTE Reg)
  108. {
  109. DEV_Digital_Write(EPD_DC_PIN, 0);
  110. DEV_Digital_Write(EPD_CS_PIN, 0);
  111. DEV_SPI_WriteByte(Reg);
  112. DEV_Digital_Write(EPD_CS_PIN, 1);
  113. }
  114. /******************************************************************************
  115. function : send data
  116. parameter:
  117. Data : Write data
  118. ******************************************************************************/
  119. static void EPD_3IN7_SendData(UBYTE Data)
  120. {
  121. DEV_Digital_Write(EPD_DC_PIN, 1);
  122. DEV_Digital_Write(EPD_CS_PIN, 0);
  123. DEV_SPI_WriteByte(Data);
  124. DEV_Digital_Write(EPD_CS_PIN, 1);
  125. }
  126. static void EPD_3IN7_ReadBusy_HIGH(void)
  127. {
  128. EPD_Busy_WaitUntil(0,0);
  129. // unsigned char count = 100;
  130. // Debug("e-Paper busy\r\n");
  131. // UBYTE busy;
  132. // do {
  133. // busy = DEV_Digital_Read(EPD_BUSY_PIN);
  134. // if(!(count--))
  135. // {
  136. // Debug("error: e-Paper busy timeout!!!\r\n");
  137. // break;
  138. // }
  139. // else
  140. // DEV_Delay_ms(100);
  141. // } while(busy);
  142. // DEV_Delay_ms(200);
  143. // Debug("e-Paper busy release\r\n");
  144. }
  145. /******************************************************************************
  146. function : set the look-up tables
  147. parameter:
  148. ******************************************************************************/
  149. void EPD_3IN7_Load_LUT(UBYTE lut)
  150. {
  151. UWORD i;
  152. EPD_3IN7_SendCommand(0x32);
  153. for (i = 0; i < 105; i++)
  154. {
  155. if(lut == 0)
  156. EPD_3IN7_SendData(lut_4Gray_GC[i]);
  157. else if(lut == 1)
  158. EPD_3IN7_SendData(lut_1Gray_GC[i]);
  159. else if(lut == 2)
  160. EPD_3IN7_SendData(lut_1Gray_DU[i]);
  161. else if(lut == 3)
  162. EPD_3IN7_SendData(lut_1Gray_A2[i]);
  163. else
  164. Debug("There is no such lut \r\n");
  165. }
  166. }
  167. /******************************************************************************
  168. function : Initialize the e-Paper register
  169. parameter:
  170. ******************************************************************************/
  171. void EPD_3IN7_4Gray_Init(UBYTE mode)
  172. {
  173. EPD_3IN7_Reset();
  174. EPD_3IN7_SendCommand(0x12);
  175. DEV_Delay_ms(300);
  176. EPD_3IN7_SendCommand(0x46);
  177. EPD_3IN7_SendData(0xF7);
  178. EPD_3IN7_ReadBusy_HIGH();
  179. EPD_3IN7_SendCommand(0x47);
  180. EPD_3IN7_SendData(0xF7);
  181. EPD_3IN7_ReadBusy_HIGH();
  182. EPD_3IN7_SendCommand(0x01); // setting gaet number
  183. EPD_3IN7_SendData(0xDF);
  184. EPD_3IN7_SendData(0x01);
  185. EPD_3IN7_SendData(0x00);
  186. EPD_3IN7_SendCommand(0x03); // set gate voltage
  187. EPD_3IN7_SendData(0x00);
  188. EPD_3IN7_SendCommand(0x04); // set source voltage
  189. EPD_3IN7_SendData(0x41);
  190. EPD_3IN7_SendData(0xA8);
  191. EPD_3IN7_SendData(0x32);
  192. EPD_3IN7_SendCommand(0x11); // set data entry sequence
  193. EPD_3IN7_SendData(0x03);
  194. EPD_3IN7_SendCommand(0x3C); // set border
  195. EPD_3IN7_SendData(0x00);
  196. EPD_3IN7_SendCommand(0x0C); // set booster strength
  197. EPD_3IN7_SendData(0xAE);
  198. EPD_3IN7_SendData(0xC7);
  199. EPD_3IN7_SendData(0xC3);
  200. EPD_3IN7_SendData(0xC0);
  201. EPD_3IN7_SendData(0xC0);
  202. EPD_3IN7_SendCommand(0x18); // set internal sensor on
  203. EPD_3IN7_SendData(0x80);
  204. EPD_3IN7_SendCommand(0x2C); // set vcom value
  205. EPD_3IN7_SendData(0x44);
  206. EPD_3IN7_SendCommand(0x37); // set display option, these setting turn on previous function
  207. EPD_3IN7_SendData(0x00);
  208. EPD_3IN7_SendData(0x00);
  209. EPD_3IN7_SendData(0x00);
  210. EPD_3IN7_SendData(0x00);
  211. EPD_3IN7_SendData(0x00);
  212. EPD_3IN7_SendData(0x00);
  213. EPD_3IN7_SendData(0x00);
  214. EPD_3IN7_SendData(0x00);
  215. EPD_3IN7_SendData(0x00);
  216. EPD_3IN7_SendData(0x00);
  217. EPD_3IN7_SendData(0x00);
  218. EPD_3IN7_SendCommand(0x44); // setting X direction start/end position of RAM
  219. EPD_3IN7_SendData(0x00);
  220. EPD_3IN7_SendData(0x00);
  221. EPD_3IN7_SendData(0x17);
  222. EPD_3IN7_SendData(0x01);
  223. EPD_3IN7_SendCommand(0x45); // setting Y direction start/end position of RAM
  224. EPD_3IN7_SendData(0x00);
  225. EPD_3IN7_SendData(0x00);
  226. EPD_3IN7_SendData(0xDF);
  227. EPD_3IN7_SendData(0x01);
  228. EPD_3IN7_SendCommand(0x22); // Display Update Control 2
  229. EPD_3IN7_SendData(0xCF);
  230. }
  231. /******************************************************************************
  232. function : Initialize the e-Paper register
  233. parameter:
  234. ******************************************************************************/
  235. void EPD_3IN7_1Gray_Init(UBYTE mode)
  236. {
  237. EPD_3IN7_Reset();
  238. EPD_3IN7_SendCommand(0x12);
  239. DEV_Delay_ms(300);
  240. EPD_3IN7_SendCommand(0x46);
  241. EPD_3IN7_SendData(0xF7);
  242. EPD_3IN7_ReadBusy_HIGH();
  243. EPD_3IN7_SendCommand(0x47);
  244. EPD_3IN7_SendData(0xF7);
  245. EPD_3IN7_ReadBusy_HIGH();
  246. EPD_3IN7_SendCommand(0x01); // setting gaet number
  247. EPD_3IN7_SendData(0xDF);
  248. EPD_3IN7_SendData(0x01);
  249. EPD_3IN7_SendData(0x00);
  250. EPD_3IN7_SendCommand(0x03); // set gate voltage
  251. EPD_3IN7_SendData(0x00);
  252. EPD_3IN7_SendCommand(0x04); // set source voltage
  253. EPD_3IN7_SendData(0x41);
  254. EPD_3IN7_SendData(0xA8);
  255. EPD_3IN7_SendData(0x32);
  256. EPD_3IN7_SendCommand(0x11); // set data entry sequence
  257. EPD_3IN7_SendData(0x03);
  258. EPD_3IN7_SendCommand(0x3C); // set border
  259. EPD_3IN7_SendData(0x00);
  260. EPD_3IN7_SendCommand(0x0C); // set booster strength
  261. EPD_3IN7_SendData(0xAE);
  262. EPD_3IN7_SendData(0xC7);
  263. EPD_3IN7_SendData(0xC3);
  264. EPD_3IN7_SendData(0xC0);
  265. EPD_3IN7_SendData(0xC0);
  266. EPD_3IN7_SendCommand(0x18); // set internal sensor on
  267. EPD_3IN7_SendData(0x80);
  268. EPD_3IN7_SendCommand(0x2C); // set vcom value
  269. EPD_3IN7_SendData(0x44);
  270. EPD_3IN7_SendCommand(0x37); // set display option, these setting turn on previous function
  271. EPD_3IN7_SendData(0x00); //can switch 1 gray or 4 gray
  272. EPD_3IN7_SendData(0xFF);
  273. EPD_3IN7_SendData(0xFF);
  274. EPD_3IN7_SendData(0xFF);
  275. EPD_3IN7_SendData(0xFF);
  276. EPD_3IN7_SendData(0x4F);
  277. EPD_3IN7_SendData(0xFF);
  278. EPD_3IN7_SendData(0xFF);
  279. EPD_3IN7_SendData(0xFF);
  280. EPD_3IN7_SendData(0xFF);
  281. EPD_3IN7_SendCommand(0x44); // setting X direction start/end position of RAM
  282. EPD_3IN7_SendData(0x00);
  283. EPD_3IN7_SendData(0x00);
  284. EPD_3IN7_SendData(0x17);
  285. EPD_3IN7_SendData(0x01);
  286. EPD_3IN7_SendCommand(0x45); // setting Y direction start/end position of RAM
  287. EPD_3IN7_SendData(0x00);
  288. EPD_3IN7_SendData(0x00);
  289. EPD_3IN7_SendData(0xDF);
  290. EPD_3IN7_SendData(0x01);
  291. EPD_3IN7_SendCommand(0x22); // Display Update Control 2
  292. EPD_3IN7_SendData(0xCF);
  293. }
  294. /******************************************************************************
  295. function : Clear screen
  296. parameter:
  297. ******************************************************************************/
  298. void EPD_3IN7_4Gray_Clear(void)
  299. {
  300. UWORD Width, Height;
  301. Width = (EPD_3IN7_WIDTH % 8 == 0)? (EPD_3IN7_WIDTH / 8 ): (EPD_3IN7_WIDTH / 8 + 1);
  302. Height = EPD_3IN7_HEIGHT;
  303. EPD_3IN7_SendCommand(0x49);
  304. EPD_3IN7_SendData(0x00);
  305. EPD_3IN7_SendCommand(0x4E);
  306. EPD_3IN7_SendData(0x00);
  307. EPD_3IN7_SendData(0x00);
  308. EPD_3IN7_SendCommand(0x4F);
  309. EPD_3IN7_SendData(0x00);
  310. EPD_3IN7_SendData(0x00);
  311. EPD_3IN7_SendCommand(0x24);
  312. for (UWORD j = 0; j < Height; j++) {
  313. for (UWORD i = 0; i < Width; i++) {
  314. EPD_3IN7_SendData(0xff);
  315. }
  316. }
  317. EPD_3IN7_SendCommand(0x4E);
  318. EPD_3IN7_SendData(0x00);
  319. EPD_3IN7_SendData(0x00);
  320. EPD_3IN7_SendCommand(0x4F);
  321. EPD_3IN7_SendData(0x00);
  322. EPD_3IN7_SendData(0x00);
  323. EPD_3IN7_SendCommand(0x26);
  324. for (UWORD j = 0; j < Height; j++) {
  325. for (UWORD i = 0; i < Width; i++) {
  326. EPD_3IN7_SendData(0xff);
  327. }
  328. }
  329. EPD_3IN7_Load_LUT(0);
  330. EPD_3IN7_SendCommand(0x22);
  331. EPD_3IN7_SendData(0xC7);
  332. EPD_3IN7_SendCommand(0x20);
  333. EPD_3IN7_ReadBusy_HIGH();
  334. }
  335. /******************************************************************************
  336. function : Clear screen
  337. parameter:
  338. ******************************************************************************/
  339. void EPD_3IN7_1Gray_Clear(void)
  340. {
  341. UWORD i;
  342. UWORD IMAGE_COUNTER = EPD_3IN7_WIDTH * EPD_3IN7_HEIGHT / 8;
  343. EPD_3IN7_SendCommand(0x4E);
  344. EPD_3IN7_SendData(0x00);
  345. EPD_3IN7_SendData(0x00);
  346. EPD_3IN7_SendCommand(0x4F);
  347. EPD_3IN7_SendData(0x00);
  348. EPD_3IN7_SendData(0x00);
  349. EPD_3IN7_SendCommand(0x24);
  350. for (i = 0; i < IMAGE_COUNTER; i++)
  351. {
  352. EPD_3IN7_SendData(0xff);
  353. }
  354. EPD_3IN7_Load_LUT(2);
  355. EPD_3IN7_SendCommand(0x20);
  356. EPD_3IN7_ReadBusy_HIGH();
  357. }
  358. /******************************************************************************
  359. function : Sends the image buffer in RAM to e-Paper and displays
  360. parameter:
  361. ******************************************************************************/
  362. void EPD_3IN7_4Gray_Display(const UBYTE *Image)
  363. {
  364. UDOUBLE i,j,k;
  365. UBYTE temp1,temp2,temp3;
  366. EPD_3IN7_SendCommand(0x49);
  367. EPD_3IN7_SendData(0x00);
  368. EPD_3IN7_SendCommand(0x4E);
  369. EPD_3IN7_SendData(0x00);
  370. EPD_3IN7_SendData(0x00);
  371. EPD_3IN7_SendCommand(0x4F);
  372. EPD_3IN7_SendData(0x00);
  373. EPD_3IN7_SendData(0x00);
  374. EPD_3IN7_SendCommand(0x24);
  375. for(i=0;i<16800;i++){
  376. temp3=0;
  377. for(j=0; j<2; j++) {
  378. temp1 = Image[i*2+j];
  379. for(k=0; k<2; k++) {
  380. temp2 = temp1&0xC0;
  381. if(temp2 == 0xC0)
  382. temp3 |= 0x01;//white
  383. else if(temp2 == 0x00)
  384. temp3 |= 0x00; //black
  385. else if(temp2 == 0x80)
  386. temp3 |= 0x00; //gray1
  387. else //0x40
  388. temp3 |= 0x01; //gray2
  389. temp3 <<= 1;
  390. temp1 <<= 2;
  391. temp2 = temp1&0xC0 ;
  392. if(temp2 == 0xC0) //white
  393. temp3 |= 0x01;
  394. else if(temp2 == 0x00) //black
  395. temp3 |= 0x00;
  396. else if(temp2 == 0x80)
  397. temp3 |= 0x00; //gray1
  398. else //0x40
  399. temp3 |= 0x01; //gray2
  400. if(j!=1 || k!=1)
  401. temp3 <<= 1;
  402. temp1 <<= 2;
  403. }
  404. }
  405. EPD_3IN7_SendData(temp3);
  406. }
  407. // new data
  408. EPD_3IN7_SendCommand(0x4E);
  409. EPD_3IN7_SendData(0x00);
  410. EPD_3IN7_SendData(0x00);
  411. EPD_3IN7_SendCommand(0x4F);
  412. EPD_3IN7_SendData(0x00);
  413. EPD_3IN7_SendData(0x00);
  414. EPD_3IN7_SendCommand(0x26);
  415. for(i=0; i<16800; i++) {
  416. temp3=0;
  417. for(j=0; j<2; j++) {
  418. temp1 = Image[i*2+j];
  419. for(k=0; k<2; k++) {
  420. temp2 = temp1&0xC0 ;
  421. if(temp2 == 0xC0)
  422. temp3 |= 0x01;//white
  423. else if(temp2 == 0x00)
  424. temp3 |= 0x00; //black
  425. else if(temp2 == 0x80)
  426. temp3 |= 0x01; //gray1
  427. else //0x40
  428. temp3 |= 0x00; //gray2
  429. temp3 <<= 1;
  430. temp1 <<= 2;
  431. temp2 = temp1&0xC0 ;
  432. if(temp2 == 0xC0) //white
  433. temp3 |= 0x01;
  434. else if(temp2 == 0x00) //black
  435. temp3 |= 0x00;
  436. else if(temp2 == 0x80)
  437. temp3 |= 0x01; //gray1
  438. else //0x40
  439. temp3 |= 0x00; //gray2
  440. if(j!=1 || k!=1)
  441. temp3 <<= 1;
  442. temp1 <<= 2;
  443. }
  444. }
  445. EPD_3IN7_SendData(temp3);
  446. }
  447. EPD_3IN7_Load_LUT(0);
  448. EPD_3IN7_SendCommand(0x22);
  449. EPD_3IN7_SendData(0xC7);
  450. EPD_3IN7_SendCommand(0x20);
  451. EPD_3IN7_ReadBusy_HIGH();
  452. }
  453. /******************************************************************************
  454. function : Sends the image buffer in RAM to e-Paper and displays
  455. parameter:
  456. ******************************************************************************/
  457. void EPD_3IN7_1Gray_Display(const UBYTE *Image, UBYTE *Image2)
  458. {
  459. UWORD i;
  460. UWORD IMAGE_COUNTER = EPD_3IN7_WIDTH * EPD_3IN7_HEIGHT / 8;
  461. EPD_3IN7_SendCommand(0x4E);
  462. EPD_3IN7_SendData(0x00);
  463. EPD_3IN7_SendData(0x00);
  464. EPD_3IN7_SendCommand(0x4F);
  465. EPD_3IN7_SendData(0x00);
  466. EPD_3IN7_SendData(0x00);
  467. EPD_3IN7_SendCommand(0x24);
  468. for (i = 0; i < IMAGE_COUNTER; i++)
  469. {
  470. EPD_3IN7_SendData(Image[i]);
  471. }
  472. EPD_3IN7_Load_LUT(2);
  473. EPD_3IN7_SendCommand(0x20);
  474. EPD_3IN7_ReadBusy_HIGH();
  475. }
  476. /******************************************************************************
  477. function : Sends the image buffer in RAM to e-Paper and displays
  478. parameter:
  479. ******************************************************************************/
  480. void EPD_3IN7_1Gray_Display_Part(const UBYTE *Image, UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
  481. {
  482. UWORD i, Width;
  483. Width = (Xend-Xstart)%8 == 0 ? (Xend-Xstart)/8 : (Xend-Xstart)/8+1;
  484. UWORD IMAGE_COUNTER = Width * (Yend-Ystart);
  485. EPD_3IN7_SendCommand(0x44);
  486. EPD_3IN7_SendData(Xstart & 0xff);
  487. EPD_3IN7_SendData((Xstart>>8) & 0x03);
  488. EPD_3IN7_SendData(Xend & 0xff);
  489. EPD_3IN7_SendData((Xend>>8) & 0x03);
  490. EPD_3IN7_SendCommand(0x45);
  491. EPD_3IN7_SendData(Ystart & 0xff);
  492. EPD_3IN7_SendData((Ystart>>8) & 0x03);
  493. EPD_3IN7_SendData(Yend & 0xff);
  494. EPD_3IN7_SendData((Yend>>8) & 0x03);
  495. EPD_3IN7_SendCommand(0x24);
  496. for (i = 0; i < IMAGE_COUNTER; i++)
  497. {
  498. EPD_3IN7_SendData(Image[i]);
  499. }
  500. EPD_3IN7_Load_LUT(2);
  501. EPD_3IN7_SendCommand(0x20);
  502. EPD_3IN7_ReadBusy_HIGH();
  503. }
  504. /******************************************************************************
  505. function : Enter sleep mode
  506. parameter:
  507. ******************************************************************************/
  508. void EPD_3IN7_Sleep(void)
  509. {
  510. EPD_3IN7_SendCommand(0X10); //deep sleep
  511. EPD_3IN7_SendData(0x03);
  512. }