EPD_5in79.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. void EPD_5in79_4GrayDisplay_Partial(UBYTE *Image)
  781. {
  782. UDOUBLE i,j,k,o;
  783. UBYTE temp1,temp2,temp3;
  784. UDOUBLE Width, Height;
  785. Width =(EPD_5in79_WIDTH % 16 == 0)?(EPD_5in79_WIDTH / 16 ):(EPD_5in79_WIDTH / 16 + 1);
  786. Height = EPD_5in79_HEIGHT;
  787. EPD_5in79_SendCommand(0x24);
  788. for (j = 0; j < Height; j++) {
  789. for (i = 0; i < Width; i++) {
  790. temp3=0;
  791. for(o=0; o<2; o++) {
  792. temp1 = Image[(j * Width + i)*2+o];
  793. for(k=0; k<4; k++) {
  794. temp2 = temp1&0xC0;
  795. if(temp2 == 0xC0) //white
  796. temp3 |= 0x01;
  797. else if(temp2 == 0x00) //black
  798. temp3 |= 0x00;
  799. else if(temp2 == 0x80) //gray1
  800. temp3 |= 0x00;
  801. else //0x40 //gray2
  802. temp3 |= 0x01;
  803. if(o!=1 || k!=3)
  804. temp3 <<= 1;
  805. temp1 <<= 2;
  806. }
  807. }
  808. EPD_5in79_SendData(temp3);
  809. // printf("%x",temp3);
  810. }
  811. }
  812. EPD_5in79_SendCommand(0x26);
  813. for (j = 0; j < Height; j++) {
  814. for (i = 0; i < Width; i++) {
  815. temp3=0;
  816. for(o=0; o<2; o++) {
  817. temp1 = Image[(j * Width + i)*2+o];
  818. for(k=0; k<4; k++) {
  819. temp2 = temp1&0xC0;
  820. if(temp2 == 0xC0) //white
  821. temp3 |= 0x01;
  822. else if(temp2 == 0x00) //black
  823. temp3 |= 0x00;
  824. else if(temp2 == 0x80) //gray1
  825. temp3 |= 0x01;
  826. else //0x40 //gray2
  827. temp3 |= 0x00;
  828. if(o!=1 || k!=3)
  829. temp3 <<= 1;
  830. temp1 <<= 2;
  831. }
  832. }
  833. EPD_5in79_SendData(temp3);
  834. // printf("%x",temp3);
  835. }
  836. }
  837. EPD_5in79_SendCommand(0xA4);
  838. for (j = 0; j < Height; j++) {
  839. for (i = 0; i < Width; i++) {
  840. EPD_5in79_SendData(0xFF);
  841. // printf("%x",temp3);
  842. }
  843. }
  844. EPD_5in79_SendCommand(0xA6);
  845. for (j = 0; j < Height; j++) {
  846. for (i = 0; i < Width; i++) {
  847. EPD_5in79_SendData(0xFF);
  848. // printf("%x",temp3);
  849. }
  850. }
  851. EPD_5in79_TurnOnDisplay_4GRAY();
  852. }
  853. /******************************************************************************
  854. function : Enter sleep mode
  855. parameter:
  856. ******************************************************************************/
  857. void EPD_5in79_Sleep(void)
  858. {
  859. EPD_5in79_SendCommand(0X10); //deep sleep
  860. EPD_5in79_SendData(0x01);
  861. }