EPD_3in7.c 18 KB

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