EPD_5in79.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. /*****************************************************************************
  2. * | File : EPD_5in79.c
  3. * | Author : Waveshare team
  4. * | Function : Electronic paper driver
  5. * | Info :
  6. *----------------
  7. * | This version: V1.0
  8. * | Date : 2024-03-05
  9. * | Info :
  10. ******************************************************************************
  11. # Permission is hereby granted, free of charge, to any person obtaining a copy
  12. # of this software and associated documnetation files(the "Software"), to deal
  13. # in the Software without restriction, including without limitation the rights
  14. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. # copies of the Software, and to permit persons to whom the Software is
  16. # furished to do so, subject to the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included in
  19. # all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. # THE SOFTWARE.
  28. #
  29. ******************************************************************************/
  30. #include "EPD_5in79.h"
  31. #include "Debug.h"
  32. /************4 Gray******************************************************/
  33. unsigned char LUT_DATA_4Gray[] =
  34. {
  35. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  38. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41. 0x01, 0x4A, 0x00, 0x00, 0x00, 0x01, 0x00,
  42. 0x01, 0x82, 0x42, 0x00, 0x00, 0x10, 0x00,
  43. 0x01, 0x8A, 0x00, 0x00, 0x00, 0x01, 0x00,
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0x01, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00,
  48. 0x01, 0x82, 0x42, 0x00, 0x00, 0x10, 0x00,
  49. 0x01, 0x81, 0x00, 0x00, 0x00, 0x01, 0x00,
  50. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  51. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  52. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  53. 0x01, 0x81, 0x00, 0x00, 0x00, 0x01, 0x00,
  54. 0x01, 0x82, 0x42, 0x00, 0x00, 0x10, 0x00,
  55. 0x01, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00,
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59. 0x01, 0x8A, 0x00, 0x00, 0x00, 0x01, 0x00,
  60. 0x01, 0x82, 0x42, 0x00, 0x00, 0x10, 0x00,
  61. 0x01, 0x4A, 0x00, 0x00, 0x00, 0x01, 0x00,
  62. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  63. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  64. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  65. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  67. 0x02, 0x00, 0x00, //FR, XON
  68. 0x22, 0x17, 0x41, 0xA8, 0x32, 0x40,
  69. //EOPT VGH VSH1 VSH2 VSL VCOM
  70. };
  71. /******************************************************************************
  72. function : Software reset
  73. parameter:
  74. ******************************************************************************/
  75. static void EPD_5in79_Reset(void)
  76. {
  77. DEV_Digital_Write(EPD_RST_PIN, 1);
  78. DEV_Delay_ms(200);
  79. DEV_Digital_Write(EPD_RST_PIN, 0);
  80. DEV_Delay_ms(1);
  81. DEV_Digital_Write(EPD_RST_PIN, 1);
  82. DEV_Delay_ms(200);
  83. }
  84. /******************************************************************************
  85. function : send command
  86. parameter:
  87. Reg : Command register
  88. ******************************************************************************/
  89. static void EPD_5in79_SendCommand(UBYTE Reg)
  90. {
  91. DEV_Digital_Write(EPD_DC_PIN, 0);
  92. DEV_Digital_Write(EPD_CS_PIN, 0);
  93. DEV_SPI_WriteByte(Reg);
  94. DEV_Digital_Write(EPD_CS_PIN, 1);
  95. }
  96. /******************************************************************************
  97. function : send data
  98. parameter:
  99. Data : Write data
  100. ******************************************************************************/
  101. static void EPD_5in79_SendData(UBYTE Data)
  102. {
  103. DEV_Digital_Write(EPD_CS_PIN, 0);
  104. DEV_Digital_Write(EPD_DC_PIN, 1);
  105. DEV_SPI_WriteByte(Data);
  106. DEV_Digital_Write(EPD_CS_PIN, 1);
  107. }
  108. /******************************************************************************
  109. function : Wait until the busy_pin goes LOW
  110. parameter:
  111. ******************************************************************************/
  112. void EPD_5in79_ReadBusy(void)
  113. {
  114. Debug("e-Paper busy\r\n");
  115. UBYTE busy;
  116. do
  117. {
  118. busy = DEV_Digital_Read(EPD_BUSY_PIN);
  119. DEV_Delay_ms(10);
  120. }
  121. while(busy);
  122. DEV_Delay_ms(200);
  123. Debug("e-Paper busy release\r\n");
  124. }
  125. /******************************************************************************
  126. function : Turn On Display
  127. parameter:
  128. ******************************************************************************/
  129. static void EPD_5in79_TurnOnDisplay(void)
  130. {
  131. EPD_5in79_SendCommand(0x22);
  132. EPD_5in79_SendData(0xF7);
  133. EPD_5in79_SendCommand(0x20); //DISPLAY REFRESH
  134. DEV_Delay_ms(100); //!!!The delay here is necessary, 200uS at least!!!
  135. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  136. }
  137. static void EPD_5in79_TurnOnDisplay_Fast(void)
  138. {
  139. EPD_5in79_SendCommand(0x22);
  140. EPD_5in79_SendData(0xC7);
  141. EPD_5in79_SendCommand(0x20); //DISPLAY REFRESH
  142. DEV_Delay_ms(100); //!!!The delay here is necessary, 200uS at least!!!
  143. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  144. }
  145. static void EPD_5in79_TurnOnDisplay_Partial(void)
  146. {
  147. EPD_5in79_SendCommand(0x22);
  148. EPD_5in79_SendData(0xFF);
  149. EPD_5in79_SendCommand(0x20); //DISPLAY REFRESH
  150. DEV_Delay_ms(100); //!!!The delay here is necessary, 200uS at least!!!
  151. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  152. }
  153. static void EPD_5in79_TurnOnDisplay_4GRAY(void)
  154. {
  155. EPD_5in79_SendCommand(0x22);
  156. EPD_5in79_SendData(0xCF);
  157. EPD_5in79_SendCommand(0x20); //DISPLAY REFRESH
  158. DEV_Delay_ms(100); //!!!The delay here is necessary, 200uS at least!!!
  159. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  160. }
  161. /******************************************************************************
  162. function : set the look-up tables
  163. parameter:
  164. ******************************************************************************/
  165. static void EPD_5in79_Lut(void)
  166. {
  167. unsigned int count;
  168. EPD_5in79_SendCommand(0x32);
  169. for(count = 0; count < 227 ; count++) {
  170. EPD_5in79_SendData(LUT_DATA_4Gray[count]);
  171. }
  172. EPD_5in79_SendCommand(0x3f);
  173. EPD_5in79_SendData(LUT_DATA_4Gray[227]);
  174. EPD_5in79_SendCommand(0x03);
  175. EPD_5in79_SendData(LUT_DATA_4Gray[228]);
  176. EPD_5in79_SendCommand(0x04);
  177. EPD_5in79_SendData(LUT_DATA_4Gray[229]);
  178. EPD_5in79_SendData(LUT_DATA_4Gray[230]);
  179. EPD_5in79_SendData(LUT_DATA_4Gray[231]);
  180. EPD_5in79_SendCommand(0x2C);
  181. EPD_5in79_SendData(LUT_DATA_4Gray[232]);
  182. }
  183. /******************************************************************************
  184. function : Initialize the e-Paper register
  185. parameter:
  186. ******************************************************************************/
  187. UBYTE EPD_5in79_Init(void)
  188. {
  189. EPD_5in79_Reset();
  190. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  191. EPD_5in79_SendCommand(0x12); //POWER ON
  192. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  193. EPD_5in79_SendCommand(0x11);
  194. EPD_5in79_SendData(0x01);
  195. EPD_5in79_SendCommand(0x44); // Set Ram X- address Start / End position
  196. EPD_5in79_SendData(0x00); // XStart, POR = 00h
  197. EPD_5in79_SendData(0x31); //400/8-1
  198. EPD_5in79_SendCommand(0x45); // Set Ram Y- address Start / End position
  199. EPD_5in79_SendData(0x0f);
  200. EPD_5in79_SendData(0x01); //300-1
  201. EPD_5in79_SendData(0x00); // YEnd L
  202. EPD_5in79_SendData(0x00); // YEnd H
  203. EPD_5in79_SendCommand(0x4e);
  204. EPD_5in79_SendData(0x00);
  205. EPD_5in79_SendCommand(0x4f);
  206. EPD_5in79_SendData(0x0f);
  207. EPD_5in79_SendData(0x01);
  208. EPD_5in79_ReadBusy();
  209. EPD_5in79_SendCommand(0x91);
  210. EPD_5in79_SendData(0x00);
  211. EPD_5in79_SendCommand(0xC4); // Set Ram X- address Start / End position
  212. EPD_5in79_SendData(0x31); // XStart, POR = 00h
  213. EPD_5in79_SendData(0x00); //400/8-1
  214. EPD_5in79_SendCommand(0xC5); // Set Ram Y- address Start / End position
  215. EPD_5in79_SendData(0x0f);
  216. EPD_5in79_SendData(0x01); //300-1
  217. EPD_5in79_SendData(0x00); // YEnd L
  218. EPD_5in79_SendData(0x00); // YEnd H
  219. EPD_5in79_SendCommand(0xCE);
  220. EPD_5in79_SendData(0x31);
  221. EPD_5in79_SendCommand(0xCF);
  222. EPD_5in79_SendData(0x0f);
  223. EPD_5in79_SendData(0x01);
  224. EPD_5in79_ReadBusy();
  225. return 0;
  226. }
  227. UBYTE EPD_5in79_Init_Fast(void)
  228. {
  229. EPD_5in79_Reset();
  230. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  231. EPD_5in79_SendCommand(0x12); //POWER ON
  232. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  233. EPD_5in79_SendCommand(0x18); //Read built-in temperature sensor
  234. EPD_5in79_SendData(0x80);
  235. EPD_5in79_SendCommand(0x22); // Load temperature value
  236. EPD_5in79_SendData(0xB1);
  237. EPD_5in79_SendCommand(0x20);
  238. EPD_5in79_ReadBusy();
  239. EPD_5in79_SendCommand(0x1A); // Write to temperature register
  240. EPD_5in79_SendData(0x64);
  241. EPD_5in79_SendData(0x00);
  242. EPD_5in79_SendCommand(0x22); // Load temperature value
  243. EPD_5in79_SendData(0x91);
  244. EPD_5in79_SendCommand(0x20);
  245. EPD_5in79_ReadBusy();
  246. EPD_5in79_SendCommand(0x11);
  247. EPD_5in79_SendData(0x01);
  248. EPD_5in79_SendCommand(0x44); // Set Ram X- address Start / End position
  249. EPD_5in79_SendData(0x00); // XStart, POR = 00h
  250. EPD_5in79_SendData(0x31); //400/8-1
  251. EPD_5in79_SendCommand(0x45); // Set Ram Y- address Start / End position
  252. EPD_5in79_SendData(0x0f);
  253. EPD_5in79_SendData(0x01); //300-1
  254. EPD_5in79_SendData(0x00); // YEnd L
  255. EPD_5in79_SendData(0x00); // YEnd H
  256. EPD_5in79_SendCommand(0x4e);
  257. EPD_5in79_SendData(0x00);
  258. EPD_5in79_SendCommand(0x4f);
  259. EPD_5in79_SendData(0x0f);
  260. EPD_5in79_SendData(0x01);
  261. EPD_5in79_ReadBusy();
  262. EPD_5in79_SendCommand(0x91);
  263. EPD_5in79_SendData(0x00);
  264. EPD_5in79_SendCommand(0xC4); // Set Ram X- address Start / End position
  265. EPD_5in79_SendData(0x31); // XStart, POR = 00h
  266. EPD_5in79_SendData(0x00); //400/8-1
  267. EPD_5in79_SendCommand(0xC5); // Set Ram Y- address Start / End position
  268. EPD_5in79_SendData(0x0f);
  269. EPD_5in79_SendData(0x01); //300-1
  270. EPD_5in79_SendData(0x00); // YEnd L
  271. EPD_5in79_SendData(0x00); // YEnd H
  272. EPD_5in79_SendCommand(0xCe);
  273. EPD_5in79_SendData(0x31);
  274. EPD_5in79_SendCommand(0xCf);
  275. EPD_5in79_SendData(0x0f);
  276. EPD_5in79_SendData(0x01);
  277. EPD_5in79_ReadBusy();
  278. return 0;
  279. }
  280. UBYTE EPD_5in79_Init_Partial(void)
  281. {
  282. EPD_5in79_Reset();
  283. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  284. EPD_5in79_SendCommand(0x12); //POWER ON
  285. EPD_5in79_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
  286. EPD_5in79_SendCommand(0x3C); //BorderWavefrom
  287. EPD_5in79_SendData(0x80);
  288. return 0;
  289. }
  290. UBYTE EPD_5in79_Init_4Gray(void)
  291. {
  292. EPD_5in79_Reset();
  293. EPD_5in79_ReadBusy();
  294. EPD_5in79_SendCommand(0x12);
  295. EPD_5in79_ReadBusy();
  296. EPD_5in79_SendCommand(0x0C);
  297. EPD_5in79_SendData(0x8B);
  298. EPD_5in79_SendData(0x9C);
  299. EPD_5in79_SendData(0xA6);
  300. EPD_5in79_SendData(0x0F);
  301. EPD_5in79_SendCommand(0x3C); //set border
  302. EPD_5in79_SendData(0x81);
  303. EPD_5in79_ReadBusy();
  304. EPD_5in79_SendCommand(0x11);
  305. EPD_5in79_SendData(0x01);
  306. EPD_5in79_SendCommand(0x44); // Set Ram X- address Start / End position
  307. EPD_5in79_SendData(0x00); // XStart, POR = 00h
  308. EPD_5in79_SendData(0x31); //400/8-1
  309. EPD_5in79_SendCommand(0x45); // Set Ram Y- address Start / End position
  310. EPD_5in79_SendData(0x0f);
  311. EPD_5in79_SendData(0x01); //300-1
  312. EPD_5in79_SendData(0x00); // YEnd L
  313. EPD_5in79_SendData(0x00); // YEnd H
  314. EPD_5in79_SendCommand(0x4e);
  315. EPD_5in79_SendData(0x00);
  316. EPD_5in79_SendCommand(0x4f);
  317. EPD_5in79_SendData(0x0f);
  318. EPD_5in79_SendData(0x01);
  319. EPD_5in79_ReadBusy();
  320. EPD_5in79_SendCommand(0x91);
  321. EPD_5in79_SendData(0x00);
  322. EPD_5in79_SendCommand(0xC4); // Set Ram X- address Start / End position
  323. EPD_5in79_SendData(0x31); // XStart, POR = 00h
  324. EPD_5in79_SendData(0x00); //400/8-1
  325. EPD_5in79_SendCommand(0xC5); // Set Ram Y- address Start / End position
  326. EPD_5in79_SendData(0x0f);
  327. EPD_5in79_SendData(0x01); //300-1
  328. EPD_5in79_SendData(0x00); // YEnd L
  329. EPD_5in79_SendData(0x00); // YEnd H
  330. EPD_5in79_SendCommand(0xCe);
  331. EPD_5in79_SendData(0x31);
  332. EPD_5in79_SendCommand(0xCf);
  333. EPD_5in79_SendData(0x0f);
  334. EPD_5in79_SendData(0x01);
  335. EPD_5in79_Lut();
  336. return 0;
  337. }
  338. /******************************************************************************
  339. function : Clear screen
  340. parameter:
  341. ******************************************************************************/
  342. void EPD_5in79_Clear(void)
  343. {
  344. UDOUBLE i;
  345. // M part 396*272
  346. EPD_5in79_SendCommand(0x24);
  347. for(i=0; i<13600; i++)
  348. {
  349. EPD_5in79_SendData(0xff);
  350. }
  351. EPD_5in79_SendCommand(0X26);
  352. for(i=0; i<13600; i++)
  353. {
  354. EPD_5in79_SendData(0x00);
  355. }
  356. // S part 396*272
  357. EPD_5in79_SendCommand(0xA4);
  358. for(i=0; i<13600; i++)
  359. {
  360. EPD_5in79_SendData(0xff);
  361. }
  362. EPD_5in79_SendCommand(0xA6);
  363. for(i=0; i<13600; i++)
  364. {
  365. EPD_5in79_SendData(0x00);
  366. }
  367. EPD_5in79_TurnOnDisplay();
  368. }
  369. void EPD_5in79_Clear_Black(void)
  370. {
  371. UDOUBLE i;
  372. // M part 396*272
  373. EPD_5in79_SendCommand(0x24);
  374. for(i=0; i<13600; i++)
  375. {
  376. EPD_5in79_SendData(0x00);
  377. }
  378. EPD_5in79_SendCommand(0X26);
  379. for(i=0; i<13600; i++)
  380. {
  381. EPD_5in79_SendData(0x00);
  382. }
  383. // S part 396*272
  384. EPD_5in79_SendCommand(0xA4);
  385. for(i=0; i<13600; i++)
  386. {
  387. EPD_5in79_SendData(0x00);
  388. }
  389. EPD_5in79_SendCommand(0xA6);
  390. for(i=0; i<13600; i++)
  391. {
  392. EPD_5in79_SendData(0x00);
  393. }
  394. EPD_5in79_TurnOnDisplay();
  395. }
  396. /******************************************************************************
  397. function : Sends the image buffer in RAM to e-Paper and displays
  398. parameter:
  399. ******************************************************************************/
  400. void EPD_5in79_Display(const UBYTE *Image)
  401. {
  402. UDOUBLE Width, Width1, Height;
  403. Width =(EPD_5in79_WIDTH % 16 == 0)?(EPD_5in79_WIDTH / 16 ):(EPD_5in79_WIDTH / 16 + 1);
  404. Width1 =(EPD_5in79_WIDTH % 8 == 0)?(EPD_5in79_WIDTH / 8 ):(EPD_5in79_WIDTH / 8 + 1);
  405. Height = EPD_5in79_HEIGHT;
  406. // M part 396*272
  407. EPD_5in79_SendCommand(0x24);
  408. for (UDOUBLE j = 0; j < Height; j++) {
  409. for (UDOUBLE i = 0; i < Width; i++) {
  410. EPD_5in79_SendData(Image[j * Width1 + i]);
  411. }
  412. }
  413. EPD_5in79_SendCommand(0X26);
  414. for (UDOUBLE j = 0; j < Height; j++) {
  415. for (UDOUBLE i = 0; i < Width; i++) {
  416. EPD_5in79_SendData(0x00);
  417. }
  418. }
  419. // S part 396*272
  420. EPD_5in79_SendCommand(0xA4);
  421. for (UDOUBLE j = 0; j < Height; j++) {
  422. for (UDOUBLE i = 0; i < Width; i++) {
  423. EPD_5in79_SendData(Image[j * Width1 + i + Width - 1]);
  424. }
  425. }
  426. EPD_5in79_SendCommand(0XA6);
  427. for (UDOUBLE j = 0; j < Height; j++) {
  428. for (UDOUBLE i = 0; i < Width; i++) {
  429. EPD_5in79_SendData(0x00);
  430. }
  431. }
  432. EPD_5in79_TurnOnDisplay();
  433. }
  434. void EPD_5in79_Display_Base(const UBYTE *Image)
  435. {
  436. UDOUBLE Width, Width1, Height;
  437. Width =(EPD_5in79_WIDTH % 16 == 0)?(EPD_5in79_WIDTH / 16 ):(EPD_5in79_WIDTH / 16 + 1);
  438. Width1 =(EPD_5in79_WIDTH % 8 == 0)?(EPD_5in79_WIDTH / 8 ):(EPD_5in79_WIDTH / 8 + 1);
  439. Height = EPD_5in79_HEIGHT;
  440. // M part 396*272
  441. EPD_5in79_SendCommand(0x24);
  442. for (UDOUBLE j = 0; j < Height; j++) {
  443. for (UDOUBLE i = 0; i < Width; i++) {
  444. EPD_5in79_SendData(Image[j * Width1 + i]);
  445. }
  446. }
  447. EPD_5in79_SendCommand(0X26);
  448. for (UDOUBLE j = 0; j < Height; j++) {
  449. for (UDOUBLE i = 0; i < Width; i++) {
  450. EPD_5in79_SendData(0x00);
  451. }
  452. }
  453. // S part 396*272
  454. EPD_5in79_SendCommand(0xA4);
  455. for (UDOUBLE j = 0; j < Height; j++) {
  456. for (UDOUBLE i = 0; i < Width; i++) {
  457. EPD_5in79_SendData(Image[j * Width1 + i + Width - 1]);
  458. }
  459. }
  460. EPD_5in79_SendCommand(0XA6);
  461. for (UDOUBLE j = 0; j < Height; j++) {
  462. for (UDOUBLE i = 0; i < Width; i++) {
  463. EPD_5in79_SendData(0x00);
  464. }
  465. }
  466. EPD_5in79_TurnOnDisplay();
  467. EPD_5in79_SendCommand(0x26);
  468. for (UDOUBLE j = 0; j < Height; j++) {
  469. for (UDOUBLE i = 0; i < Width; i++) {
  470. EPD_5in79_SendData(Image[j * Width1 + i]);
  471. }
  472. }
  473. EPD_5in79_SendCommand(0xA6);
  474. for (UDOUBLE j = 0; j < Height; j++) {
  475. for (UDOUBLE i = 0; i < Width; i++) {
  476. EPD_5in79_SendData(Image[j * Width1 + i + Width - 1]);
  477. }
  478. }
  479. }
  480. void EPD_5in79_Display_Base_color(UBYTE color)
  481. {
  482. UDOUBLE Width, Height;
  483. Width =(EPD_5in79_WIDTH % 16 == 0)?(EPD_5in79_WIDTH / 16 ):(EPD_5in79_WIDTH / 16 + 1);
  484. Height = EPD_5in79_HEIGHT;
  485. // M part 396*272
  486. EPD_5in79_SendCommand(0x24);
  487. for (UDOUBLE j = 0; j < Height; j++) {
  488. for (UDOUBLE i = 0; i < Width; i++) {
  489. EPD_5in79_SendData(color);
  490. }
  491. }
  492. EPD_5in79_SendCommand(0X26);
  493. for (UDOUBLE j = 0; j < Height; j++) {
  494. for (UDOUBLE i = 0; i < Width; i++) {
  495. EPD_5in79_SendData(0x00);
  496. }
  497. }
  498. // S part 396*272
  499. EPD_5in79_SendCommand(0xA4);
  500. for (UDOUBLE j = 0; j < Height; j++) {
  501. for (UDOUBLE i = 0; i < Width; i++) {
  502. EPD_5in79_SendData(color);
  503. }
  504. }
  505. EPD_5in79_SendCommand(0XA6);
  506. for (UDOUBLE j = 0; j < Height; j++) {
  507. for (UDOUBLE i = 0; i < Width; i++) {
  508. EPD_5in79_SendData(0x00);
  509. }
  510. }
  511. EPD_5in79_TurnOnDisplay();
  512. // M part 396*272
  513. EPD_5in79_SendCommand(0X26);
  514. for (UDOUBLE j = 0; j < Height; j++) {
  515. for (UDOUBLE i = 0; i < Width; i++) {
  516. EPD_5in79_SendData(color);
  517. }
  518. }
  519. EPD_5in79_SendCommand(0XA6);
  520. for (UDOUBLE j = 0; j < Height; j++) {
  521. for (UDOUBLE i = 0; i < Width; i++) {
  522. EPD_5in79_SendData(color);
  523. }
  524. }
  525. }
  526. /******************************************************************************
  527. function : Sends the image buffer in RAM to e-Paper and displays
  528. parameter:
  529. ******************************************************************************/
  530. void EPD_5in79_Display_Fast(const UBYTE *Image)
  531. {
  532. UDOUBLE Width, Width1, Height;
  533. Width =(EPD_5in79_WIDTH % 16 == 0)?(EPD_5in79_WIDTH / 16 ):(EPD_5in79_WIDTH / 16 + 1);
  534. Width1 =(EPD_5in79_WIDTH % 8 == 0)?(EPD_5in79_WIDTH / 8 ):(EPD_5in79_WIDTH / 8 + 1);
  535. Height = EPD_5in79_HEIGHT;
  536. // M part 396*272
  537. EPD_5in79_SendCommand(0x24);
  538. for (UDOUBLE j = 0; j < Height; j++) {
  539. for (UDOUBLE i = 0; i < Width; i++) {
  540. EPD_5in79_SendData(Image[j * Width1 + i]);
  541. }
  542. }
  543. EPD_5in79_SendCommand(0X26);
  544. for (UDOUBLE j = 0; j < Height; j++) {
  545. for (UDOUBLE i = 0; i < Width; i++) {
  546. EPD_5in79_SendData(0x00);
  547. }
  548. }
  549. // S part 396*272
  550. EPD_5in79_SendCommand(0xA4);
  551. for (UDOUBLE j = 0; j < Height; j++) {
  552. for (UDOUBLE i = 0; i < Width; i++) {
  553. EPD_5in79_SendData(Image[j * Width1 + i + Width - 1]);
  554. }
  555. }
  556. EPD_5in79_SendCommand(0XA6);
  557. for (UDOUBLE j = 0; j < Height; j++) {
  558. for (UDOUBLE i = 0; i < Width; i++) {
  559. EPD_5in79_SendData(0x00);
  560. }
  561. }
  562. EPD_5in79_TurnOnDisplay_Fast();
  563. }
  564. void EPD_5in79_Display_Partial(const UBYTE *Image, UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
  565. {
  566. UDOUBLE Width, Width1, Width2, Height;
  567. Width =((Xend - Xstart) % 8 == 0)?((Xend - Xstart) / 8 ):((Xend - Xstart) / 8 + 1);
  568. Height = Yend - Ystart;
  569. EPD_5in79_SendCommand(0x22);
  570. EPD_5in79_SendData(0xc0);
  571. EPD_5in79_SendCommand(0x20);
  572. EPD_5in79_ReadBusy();
  573. EPD_5in79_SendCommand(0x11);
  574. EPD_5in79_SendData(0x01);
  575. EPD_5in79_SendCommand(0x91);
  576. EPD_5in79_SendData(0x00);
  577. if(Xstart>395)
  578. {
  579. Width1 = 0;
  580. Width2 = Width;
  581. EPD_5in79_SendCommand(0xC4); // Set Ram X- address Start / End position
  582. EPD_5in79_SendData((792-Xstart)/8-1); // XStart, POR = 00h
  583. EPD_5in79_SendData((792-Xend)/8); //400/8-1
  584. EPD_5in79_SendCommand(0xC5); // Set Ram Y- address Start / End position
  585. EPD_5in79_SendData((Yend-1)%256);
  586. EPD_5in79_SendData((Yend-1)/256); //300-1
  587. EPD_5in79_SendData(Ystart%256); // YEnd L
  588. EPD_5in79_SendData(Ystart/256); // YEnd H
  589. EPD_5in79_SendCommand(0xCE);
  590. EPD_5in79_SendData((792-Xstart)/8-1);
  591. EPD_5in79_SendCommand(0xCF);
  592. EPD_5in79_SendData((Yend-1)%256);
  593. EPD_5in79_SendData((Yend-1)/256);
  594. EPD_5in79_SendCommand(0xA4);
  595. for (UDOUBLE j = 0; j < Height; j++) {
  596. for (UDOUBLE i = 1; i < Width2+1; i++) {
  597. EPD_5in79_SendData(Image[j * Width + i + Width1 - 1]);
  598. }
  599. }
  600. }
  601. else if(Xend<396)
  602. {
  603. Width1 = Width;
  604. Width2 = 0;
  605. EPD_5in79_SendCommand(0x44); // Set Ram X- address Start / End position
  606. EPD_5in79_SendData(Xstart/8);
  607. EPD_5in79_SendData((Xstart/8+Width1)-1);
  608. EPD_5in79_SendCommand(0x45); // Set Ram Y- address Start / End position
  609. EPD_5in79_SendData((Yend-1)%256);
  610. EPD_5in79_SendData((Yend-1)/256);
  611. EPD_5in79_SendData(Ystart%256);
  612. EPD_5in79_SendData(Ystart/256);
  613. EPD_5in79_SendCommand(0x4e);
  614. EPD_5in79_SendData(Xstart/8);
  615. EPD_5in79_SendCommand(0x4f);
  616. EPD_5in79_SendData((Yend-1)%256);
  617. EPD_5in79_SendData((Yend-1)/256);
  618. EPD_5in79_SendCommand(0x24);
  619. for (UDOUBLE j = 0; j < Height; j++) {
  620. for (UDOUBLE i = 0; i < Width1; i++) {
  621. EPD_5in79_SendData(Image[j * Width + i]);
  622. }
  623. }
  624. }
  625. else
  626. {
  627. Width1 = ((396 - Xstart) % 8 == 0)?((396 - Xstart) / 8 ):((396 - Xstart) / 8 + 1);
  628. Width2 = ((Xend - 395) % 8 == 0)?((Xend - 395) / 8 ):((Xend - 395) / 8 + 1);
  629. EPD_5in79_SendCommand(0x44); // Set Ram X- address Start / End position
  630. EPD_5in79_SendData(0x32-Width1);
  631. EPD_5in79_SendData(0x31);
  632. EPD_5in79_SendCommand(0x45); // Set Ram Y- address Start / End position
  633. EPD_5in79_SendData((Yend-1)%256);
  634. EPD_5in79_SendData((Yend-1)/256);
  635. EPD_5in79_SendData(Ystart%256);
  636. EPD_5in79_SendData(Ystart/256);
  637. EPD_5in79_SendCommand(0x4e);
  638. EPD_5in79_SendData(0x32-Width1);
  639. EPD_5in79_SendCommand(0x4f);
  640. EPD_5in79_SendData((Yend-1)%256);
  641. EPD_5in79_SendData((Yend-1)/256);
  642. EPD_5in79_SendCommand(0x24);
  643. for (UDOUBLE j = 0; j < Height; j++) {
  644. for (UDOUBLE i = 0; i < Width1; i++) {
  645. EPD_5in79_SendData(Image[j * Width + i]);
  646. }
  647. }
  648. EPD_5in79_SendCommand(0xC4); // Set Ram X- address Start / End position
  649. EPD_5in79_SendData(0x31);
  650. EPD_5in79_SendData(0x32-Width2);
  651. EPD_5in79_SendCommand(0xC5); // Set Ram Y- address Start / End position
  652. EPD_5in79_SendData((Yend-1)%256);
  653. EPD_5in79_SendData((Yend-1)/256);
  654. EPD_5in79_SendData(Ystart%256);
  655. EPD_5in79_SendData(Ystart/256);
  656. EPD_5in79_SendCommand(0xCE);
  657. EPD_5in79_SendData(0x31);
  658. EPD_5in79_SendCommand(0xCF);
  659. EPD_5in79_SendData((Yend-1)%256);
  660. EPD_5in79_SendData((Yend-1)/256);
  661. EPD_5in79_SendCommand(0xA4);
  662. for (UDOUBLE j = 0; j < Height; j++) {
  663. for (UDOUBLE i = 1; i < Width2+1; i++) {
  664. EPD_5in79_SendData(Image[j * Width + i + Width1 - 1]);
  665. }
  666. }
  667. }
  668. EPD_5in79_TurnOnDisplay_Partial();
  669. }
  670. void EPD_5in79_4GrayDisplay(UBYTE *Image)
  671. {
  672. UDOUBLE i,j,k,o;
  673. UBYTE temp1,temp2,temp3;
  674. UDOUBLE Width, Width1, Height;
  675. Width =(EPD_5in79_WIDTH % 16 == 0)?(EPD_5in79_WIDTH / 16 ):(EPD_5in79_WIDTH / 16 + 1);
  676. Width1 =(EPD_5in79_WIDTH % 8 == 0)?(EPD_5in79_WIDTH / 8 ):(EPD_5in79_WIDTH / 8 + 1);
  677. Height = EPD_5in79_HEIGHT;
  678. EPD_5in79_SendCommand(0x24);
  679. for (j = 0; j < Height; j++) {
  680. for (i = 0; i < Width; i++) {
  681. temp3=0;
  682. for(o=0; o<2; o++) {
  683. temp1 = Image[(j * Width1 + i)*2+o];
  684. for(k=0; k<4; k++) {
  685. temp2 = temp1&0xC0;
  686. if(temp2 == 0xC0) //white
  687. temp3 |= 0x01;
  688. else if(temp2 == 0x00) //black
  689. temp3 |= 0x00;
  690. else if(temp2 == 0x80) //gray1
  691. temp3 |= 0x00;
  692. else //0x40 //gray2
  693. temp3 |= 0x01;
  694. if(o!=1 || k!=3)
  695. temp3 <<= 1;
  696. temp1 <<= 2;
  697. }
  698. }
  699. EPD_5in79_SendData(temp3);
  700. // printf("%x",temp3);
  701. }
  702. }
  703. EPD_5in79_SendCommand(0x26);
  704. for (j = 0; j < Height; j++) {
  705. for (i = 0; i < Width; i++) {
  706. temp3=0;
  707. for(o=0; o<2; o++) {
  708. temp1 = Image[(j * Width1 + i)*2+o];
  709. for(k=0; k<4; k++) {
  710. temp2 = temp1&0xC0;
  711. if(temp2 == 0xC0) //white
  712. temp3 |= 0x01;
  713. else if(temp2 == 0x00) //black
  714. temp3 |= 0x00;
  715. else if(temp2 == 0x80) //gray1
  716. temp3 |= 0x01;
  717. else //0x40 //gray2
  718. temp3 |= 0x00;
  719. if(o!=1 || k!=3)
  720. temp3 <<= 1;
  721. temp1 <<= 2;
  722. }
  723. }
  724. EPD_5in79_SendData(temp3);
  725. // printf("%x",temp3);
  726. }
  727. }
  728. EPD_5in79_SendCommand(0xA4);
  729. for (j = 0; j < Height; j++) {
  730. for (i = 0; i < Width; i++) {
  731. temp3=0;
  732. for(o=0; o<2; o++) {
  733. temp1 = Image[(j * Width1 + i + Width - 1)*2+o];
  734. for(k=0; k<4; k++) {
  735. temp2 = temp1&0xC0;
  736. if(temp2 == 0xC0) //white
  737. temp3 |= 0x01;
  738. else if(temp2 == 0x00) //black
  739. temp3 |= 0x00;
  740. else if(temp2 == 0x80) //gray1
  741. temp3 |= 0x00;
  742. else //0x40 //gray2
  743. temp3 |= 0x01;
  744. if(o!=1 || k!=3)
  745. temp3 <<= 1;
  746. temp1 <<= 2;
  747. }
  748. }
  749. EPD_5in79_SendData(temp3);
  750. // printf("%x",temp3);
  751. }
  752. }
  753. EPD_5in79_SendCommand(0xA6);
  754. for (j = 0; j < Height; j++) {
  755. for (i = 0; i < Width; i++) {
  756. temp3=0;
  757. for(o=0; o<2; o++) {
  758. temp1 = Image[(j * Width1 + i + Width - 1)*2+o];
  759. for(k=0; k<4; k++) {
  760. temp2 = temp1&0xC0;
  761. if(temp2 == 0xC0) //white
  762. temp3 |= 0x01;
  763. else if(temp2 == 0x00) //black
  764. temp3 |= 0x00;
  765. else if(temp2 == 0x80) //gray1
  766. temp3 |= 0x01;
  767. else //0x40 //gray2
  768. temp3 |= 0x00;
  769. if(o!=1 || k!=3)
  770. temp3 <<= 1;
  771. temp1 <<= 2;
  772. }
  773. }
  774. EPD_5in79_SendData(temp3);
  775. // printf("%x",temp3);
  776. }
  777. }
  778. EPD_5in79_TurnOnDisplay_4GRAY();
  779. }
  780. /******************************************************************************
  781. function : Enter sleep mode
  782. parameter:
  783. ******************************************************************************/
  784. void EPD_5in79_Sleep(void)
  785. {
  786. EPD_5in79_SendCommand(0X10); //deep sleep
  787. EPD_5in79_SendData(0x01);
  788. }