EPD_3in7.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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-16
  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(30);
  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(30);
  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. Debug("e-Paper busy\r\n");
  129. UBYTE busy;
  130. do {
  131. busy = DEV_Digital_Read(EPD_BUSY_PIN);
  132. } while(busy);
  133. DEV_Delay_ms(200);
  134. Debug("e-Paper busy release\r\n");
  135. }
  136. /******************************************************************************
  137. function : set the look-up tables
  138. parameter:
  139. ******************************************************************************/
  140. void EPD_3IN7_Load_LUT(UBYTE lut)
  141. {
  142. UWORD i;
  143. EPD_3IN7_SendCommand(0x32);
  144. for (i = 0; i < 105; i++)
  145. {
  146. if(lut == 0)
  147. EPD_3IN7_SendData(lut_4Gray_GC[i]);
  148. else if(lut == 1)
  149. EPD_3IN7_SendData(lut_1Gray_GC[i]);
  150. else if(lut == 2)
  151. EPD_3IN7_SendData(lut_1Gray_DU[i]);
  152. else if(lut == 3)
  153. EPD_3IN7_SendData(lut_1Gray_A2[i]);
  154. else
  155. Debug("There is no such lut \r\n");
  156. }
  157. }
  158. /******************************************************************************
  159. function : Initialize the e-Paper register
  160. parameter:
  161. ******************************************************************************/
  162. void EPD_3IN7_4Gray_Init(void)
  163. {
  164. EPD_3IN7_Reset();
  165. EPD_3IN7_SendCommand(0x12);
  166. DEV_Delay_ms(300);
  167. EPD_3IN7_SendCommand(0x46);
  168. EPD_3IN7_SendData(0xF7);
  169. EPD_3IN7_ReadBusy_HIGH();
  170. EPD_3IN7_SendCommand(0x47);
  171. EPD_3IN7_SendData(0xF7);
  172. EPD_3IN7_ReadBusy_HIGH();
  173. EPD_3IN7_SendCommand(0x01); // setting gaet number
  174. EPD_3IN7_SendData(0xDF);
  175. EPD_3IN7_SendData(0x01);
  176. EPD_3IN7_SendData(0x00);
  177. EPD_3IN7_SendCommand(0x03); // set gate voltage
  178. EPD_3IN7_SendData(0x00);
  179. EPD_3IN7_SendCommand(0x04); // set source voltage
  180. EPD_3IN7_SendData(0x41);
  181. EPD_3IN7_SendData(0xA8);
  182. EPD_3IN7_SendData(0x32);
  183. EPD_3IN7_SendCommand(0x11); // set data entry sequence
  184. EPD_3IN7_SendData(0x03);
  185. EPD_3IN7_SendCommand(0x3C); // set border
  186. EPD_3IN7_SendData(0x00);
  187. EPD_3IN7_SendCommand(0x0C); // set booster strength
  188. EPD_3IN7_SendData(0xAE);
  189. EPD_3IN7_SendData(0xC7);
  190. EPD_3IN7_SendData(0xC3);
  191. EPD_3IN7_SendData(0xC0);
  192. EPD_3IN7_SendData(0xC0);
  193. EPD_3IN7_SendCommand(0x18); // set internal sensor on
  194. EPD_3IN7_SendData(0x80);
  195. EPD_3IN7_SendCommand(0x2C); // set vcom value
  196. EPD_3IN7_SendData(0x44);
  197. EPD_3IN7_SendCommand(0x37); // set display option, these setting turn on previous function
  198. EPD_3IN7_SendData(0x00);
  199. EPD_3IN7_SendData(0x00);
  200. EPD_3IN7_SendData(0x00);
  201. EPD_3IN7_SendData(0x00);
  202. EPD_3IN7_SendData(0x00);
  203. EPD_3IN7_SendData(0x00);
  204. EPD_3IN7_SendData(0x00);
  205. EPD_3IN7_SendData(0x00);
  206. EPD_3IN7_SendData(0x00);
  207. EPD_3IN7_SendData(0x00);
  208. EPD_3IN7_SendCommand(0x44); // setting X direction start/end position of RAM
  209. EPD_3IN7_SendData(0x00);
  210. EPD_3IN7_SendData(0x00);
  211. EPD_3IN7_SendData(0x17);
  212. EPD_3IN7_SendData(0x01);
  213. EPD_3IN7_SendCommand(0x45); // setting Y direction start/end position of RAM
  214. EPD_3IN7_SendData(0x00);
  215. EPD_3IN7_SendData(0x00);
  216. EPD_3IN7_SendData(0xDF);
  217. EPD_3IN7_SendData(0x01);
  218. EPD_3IN7_SendCommand(0x22); // Display Update Control 2
  219. EPD_3IN7_SendData(0xCF);
  220. }
  221. /******************************************************************************
  222. function : Initialize the e-Paper register
  223. parameter:
  224. ******************************************************************************/
  225. void EPD_3IN7_1Gray_Init(void)
  226. {
  227. EPD_3IN7_Reset();
  228. EPD_3IN7_SendCommand(0x12);
  229. DEV_Delay_ms(300);
  230. EPD_3IN7_SendCommand(0x46);
  231. EPD_3IN7_SendData(0xF7);
  232. EPD_3IN7_ReadBusy_HIGH();
  233. EPD_3IN7_SendCommand(0x47);
  234. EPD_3IN7_SendData(0xF7);
  235. EPD_3IN7_ReadBusy_HIGH();
  236. EPD_3IN7_SendCommand(0x01); // setting gaet number
  237. EPD_3IN7_SendData(0xDF);
  238. EPD_3IN7_SendData(0x01);
  239. EPD_3IN7_SendData(0x00);
  240. EPD_3IN7_SendCommand(0x03); // set gate voltage
  241. EPD_3IN7_SendData(0x00);
  242. EPD_3IN7_SendCommand(0x04); // set source voltage
  243. EPD_3IN7_SendData(0x41);
  244. EPD_3IN7_SendData(0xA8);
  245. EPD_3IN7_SendData(0x32);
  246. EPD_3IN7_SendCommand(0x11); // set data entry sequence
  247. EPD_3IN7_SendData(0x03);
  248. EPD_3IN7_SendCommand(0x3C); // set border
  249. EPD_3IN7_SendData(0x00);
  250. EPD_3IN7_SendCommand(0x0C); // set booster strength
  251. EPD_3IN7_SendData(0xAE);
  252. EPD_3IN7_SendData(0xC7);
  253. EPD_3IN7_SendData(0xC3);
  254. EPD_3IN7_SendData(0xC0);
  255. EPD_3IN7_SendData(0xC0);
  256. EPD_3IN7_SendCommand(0x18); // set internal sensor on
  257. EPD_3IN7_SendData(0x80);
  258. EPD_3IN7_SendCommand(0x2C); // set vcom value
  259. EPD_3IN7_SendData(0x44);
  260. EPD_3IN7_SendCommand(0x37); // set display option, these setting turn on previous function
  261. EPD_3IN7_SendData(0x00); //can switch 1 gray or 4 gray
  262. EPD_3IN7_SendData(0xFF);
  263. EPD_3IN7_SendData(0xFF);
  264. EPD_3IN7_SendData(0xFF);
  265. EPD_3IN7_SendData(0xFF);
  266. EPD_3IN7_SendData(0x4F);
  267. EPD_3IN7_SendData(0xFF);
  268. EPD_3IN7_SendData(0xFF);
  269. EPD_3IN7_SendData(0xFF);
  270. EPD_3IN7_SendData(0xFF);
  271. EPD_3IN7_SendCommand(0x44); // setting X direction start/end position of RAM
  272. EPD_3IN7_SendData(0x00);
  273. EPD_3IN7_SendData(0x00);
  274. EPD_3IN7_SendData(0x17);
  275. EPD_3IN7_SendData(0x01);
  276. EPD_3IN7_SendCommand(0x45); // setting Y direction start/end position of RAM
  277. EPD_3IN7_SendData(0x00);
  278. EPD_3IN7_SendData(0x00);
  279. EPD_3IN7_SendData(0xDF);
  280. EPD_3IN7_SendData(0x01);
  281. EPD_3IN7_SendCommand(0x22); // Display Update Control 2
  282. EPD_3IN7_SendData(0xCF);
  283. }
  284. /******************************************************************************
  285. function : Clear screen
  286. parameter:
  287. ******************************************************************************/
  288. void EPD_3IN7_4Gray_Clear(void)
  289. {
  290. UWORD Width, Height;
  291. Width = (EPD_3IN7_WIDTH % 8 == 0)? (EPD_3IN7_WIDTH / 8 ): (EPD_3IN7_WIDTH / 8 + 1);
  292. Height = EPD_3IN7_HEIGHT;
  293. EPD_3IN7_SendCommand(0x49);
  294. EPD_3IN7_SendData(0x00);
  295. EPD_3IN7_SendCommand(0x4E);
  296. EPD_3IN7_SendData(0x00);
  297. EPD_3IN7_SendData(0x00);
  298. EPD_3IN7_SendCommand(0x4F);
  299. EPD_3IN7_SendData(0x00);
  300. EPD_3IN7_SendData(0x00);
  301. EPD_3IN7_SendCommand(0x24);
  302. for (UWORD j = 0; j < Height; j++) {
  303. for (UWORD i = 0; i < Width; i++) {
  304. EPD_3IN7_SendData(0xff);
  305. }
  306. }
  307. EPD_3IN7_SendCommand(0x4E);
  308. EPD_3IN7_SendData(0x00);
  309. EPD_3IN7_SendData(0x00);
  310. EPD_3IN7_SendCommand(0x4F);
  311. EPD_3IN7_SendData(0x00);
  312. EPD_3IN7_SendData(0x00);
  313. EPD_3IN7_SendCommand(0x26);
  314. for (UWORD j = 0; j < Height; j++) {
  315. for (UWORD i = 0; i < Width; i++) {
  316. EPD_3IN7_SendData(0xff);
  317. }
  318. }
  319. EPD_3IN7_Load_LUT(0);
  320. EPD_3IN7_SendCommand(0x22);
  321. EPD_3IN7_SendData(0xC7);
  322. EPD_3IN7_SendCommand(0x20);
  323. EPD_3IN7_ReadBusy_HIGH();
  324. }
  325. /******************************************************************************
  326. function : Clear screen
  327. parameter:
  328. ******************************************************************************/
  329. void EPD_3IN7_1Gray_Clear(void)
  330. {
  331. UWORD i;
  332. UWORD IMAGE_COUNTER = EPD_3IN7_WIDTH * EPD_3IN7_HEIGHT / 8;
  333. EPD_3IN7_SendCommand(0x4E);
  334. EPD_3IN7_SendData(0x00);
  335. EPD_3IN7_SendData(0x00);
  336. EPD_3IN7_SendCommand(0x4F);
  337. EPD_3IN7_SendData(0x00);
  338. EPD_3IN7_SendData(0x00);
  339. EPD_3IN7_SendCommand(0x24);
  340. for (i = 0; i < IMAGE_COUNTER; i++)
  341. {
  342. EPD_3IN7_SendData(0xff);
  343. }
  344. EPD_3IN7_Load_LUT(2);
  345. EPD_3IN7_SendCommand(0x20);
  346. EPD_3IN7_ReadBusy_HIGH();
  347. }
  348. /******************************************************************************
  349. function : Sends the image buffer in RAM to e-Paper and displays
  350. parameter:
  351. ******************************************************************************/
  352. void EPD_3IN7_4Gray_Display(const UBYTE *Image)
  353. {
  354. UDOUBLE i,j,k;
  355. UBYTE temp1,temp2,temp3;
  356. EPD_3IN7_SendCommand(0x49);
  357. EPD_3IN7_SendData(0x00);
  358. EPD_3IN7_SendCommand(0x4E);
  359. EPD_3IN7_SendData(0x00);
  360. EPD_3IN7_SendData(0x00);
  361. EPD_3IN7_SendCommand(0x4F);
  362. EPD_3IN7_SendData(0x00);
  363. EPD_3IN7_SendData(0x00);
  364. EPD_3IN7_SendCommand(0x24);
  365. for(i=0;i<16800;i++){
  366. temp3=0;
  367. for(j=0; j<2; j++) {
  368. temp1 = Image[i*2+j];
  369. for(k=0; k<2; k++) {
  370. temp2 = temp1&0xC0;
  371. if(temp2 == 0xC0)
  372. temp3 |= 0x01;//white
  373. else if(temp2 == 0x00)
  374. temp3 |= 0x00; //black
  375. else if(temp2 == 0x80)
  376. temp3 |= 0x00; //gray1
  377. else //0x40
  378. temp3 |= 0x01; //gray2
  379. temp3 <<= 1;
  380. temp1 <<= 2;
  381. temp2 = temp1&0xC0 ;
  382. if(temp2 == 0xC0) //white
  383. temp3 |= 0x01;
  384. else if(temp2 == 0x00) //black
  385. temp3 |= 0x00;
  386. else if(temp2 == 0x80)
  387. temp3 |= 0x00; //gray1
  388. else //0x40
  389. temp3 |= 0x01; //gray2
  390. if(j!=1 || k!=1)
  391. temp3 <<= 1;
  392. temp1 <<= 2;
  393. }
  394. }
  395. EPD_3IN7_SendData(temp3);
  396. }
  397. // new data
  398. EPD_3IN7_SendCommand(0x4E);
  399. EPD_3IN7_SendData(0x00);
  400. EPD_3IN7_SendData(0x00);
  401. EPD_3IN7_SendCommand(0x4F);
  402. EPD_3IN7_SendData(0x00);
  403. EPD_3IN7_SendData(0x00);
  404. EPD_3IN7_SendCommand(0x26);
  405. for(i=0; i<16800; i++) {
  406. temp3=0;
  407. for(j=0; j<2; j++) {
  408. temp1 = Image[i*2+j];
  409. for(k=0; k<2; k++) {
  410. temp2 = temp1&0xC0 ;
  411. if(temp2 == 0xC0)
  412. temp3 |= 0x01;//white
  413. else if(temp2 == 0x00)
  414. temp3 |= 0x00; //black
  415. else if(temp2 == 0x80)
  416. temp3 |= 0x01; //gray1
  417. else //0x40
  418. temp3 |= 0x00; //gray2
  419. temp3 <<= 1;
  420. temp1 <<= 2;
  421. temp2 = temp1&0xC0 ;
  422. if(temp2 == 0xC0) //white
  423. temp3 |= 0x01;
  424. else if(temp2 == 0x00) //black
  425. temp3 |= 0x00;
  426. else if(temp2 == 0x80)
  427. temp3 |= 0x01; //gray1
  428. else //0x40
  429. temp3 |= 0x00; //gray2
  430. if(j!=1 || k!=1)
  431. temp3 <<= 1;
  432. temp1 <<= 2;
  433. }
  434. }
  435. EPD_3IN7_SendData(temp3);
  436. }
  437. EPD_3IN7_Load_LUT(0);
  438. EPD_3IN7_SendCommand(0x22);
  439. EPD_3IN7_SendData(0xC7);
  440. EPD_3IN7_SendCommand(0x20);
  441. EPD_3IN7_ReadBusy_HIGH();
  442. }
  443. /******************************************************************************
  444. function : Sends the image buffer in RAM to e-Paper and displays
  445. parameter:
  446. ******************************************************************************/
  447. void EPD_3IN7_1Gray_Display(const UBYTE *Image)
  448. {
  449. UWORD i;
  450. UWORD IMAGE_COUNTER = EPD_3IN7_WIDTH * EPD_3IN7_HEIGHT / 8;
  451. EPD_3IN7_SendCommand(0x4E);
  452. EPD_3IN7_SendData(0x00);
  453. EPD_3IN7_SendData(0x00);
  454. EPD_3IN7_SendCommand(0x4F);
  455. EPD_3IN7_SendData(0x00);
  456. EPD_3IN7_SendData(0x00);
  457. EPD_3IN7_SendCommand(0x24);
  458. for (i = 0; i < IMAGE_COUNTER; i++)
  459. {
  460. EPD_3IN7_SendData(Image[i]);
  461. }
  462. EPD_3IN7_Load_LUT(2);
  463. EPD_3IN7_SendCommand(0x20);
  464. EPD_3IN7_ReadBusy_HIGH();
  465. }
  466. /******************************************************************************
  467. function : Sends part the image buffer in RAM to e-Paper and displays
  468. notes:
  469. You can send a part of data to e-Paper,But this function is not recommended
  470. 1.Xsize must be as big as EPD_3IN7_WIDTH
  471. 2.Ypointer must be start at 0
  472. ******************************************************************************/
  473. void EPD_3IN7_1Gray_Display_Part(const UBYTE *Image, UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
  474. {
  475. UWORD i, Width;
  476. Width = (Xend-Xstart)%8 == 0 ? (Xend-Xstart)/8 : (Xend-Xstart)/8+1;
  477. UWORD IMAGE_COUNTER = Width * (Yend-Ystart);
  478. Xend -= 1;
  479. Yend -= 1;
  480. EPD_3IN7_SendCommand(0x44);
  481. EPD_3IN7_SendData(Xstart & 0xff);
  482. EPD_3IN7_SendData((Xstart>>8) & 0x03);
  483. EPD_3IN7_SendData(Xend & 0xff);
  484. EPD_3IN7_SendData((Xend>>8) & 0x03);
  485. EPD_3IN7_SendCommand(0x45);
  486. EPD_3IN7_SendData(Ystart & 0xff);
  487. EPD_3IN7_SendData((Ystart>>8) & 0x03);
  488. EPD_3IN7_SendData(Yend & 0xff);
  489. EPD_3IN7_SendData((Yend>>8) & 0x03);
  490. EPD_3IN7_SendCommand(0x4E); // SET_RAM_X_ADDRESS_COUNTER
  491. EPD_3IN7_SendData(Xstart & 0xFF);
  492. EPD_3IN7_SendCommand(0x4F); // SET_RAM_Y_ADDRESS_COUNTER
  493. EPD_3IN7_SendData(Ystart & 0xFF);
  494. EPD_3IN7_SendData((Ystart >> 8) & 0xFF);
  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(3);
  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(0X50);
  511. EPD_3IN7_SendData(0xf7);
  512. EPD_3IN7_SendCommand(0X02); //power off
  513. EPD_3IN7_SendCommand(0X07); //deep sleep
  514. EPD_3IN7_SendData(0xA5);
  515. }