EPD_4in2.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*****************************************************************************
  2. * | File : EPD_4in2.c
  3. * | Author : Waveshare team
  4. * | Function : 4.2inch e-paper
  5. * | Info :
  6. *----------------
  7. * | This version: V3.1
  8. * | Date : 2019-11-14
  9. * | Info :
  10. * -----------------------------------------------------------------------------
  11. * V3.1(2019-11-14):
  12. * 1.Add 4 grayscale drive and display program
  13. * Add EPD_4IN2_4Gray_lut_vcom[]
  14. * Add EPD_4IN2_4Gray_lut_ww[]
  15. * Add EPD_4IN2_4Gray_lut_bw[]
  16. * Add EPD_4IN2_4Gray_lut_wb
  17. * Add EPD_4IN2_4Gray_lut_bb
  18. * Add EPD_4IN2_Partial_SetLut()
  19. * Add EPD_4IN2_4Gray_lut()
  20. * Add EPD_4IN2_Init_4Gray()
  21. * Add EPD_4IN2_4GrayDisplay(....)
  22. * 2.Add partial refresh display
  23. * Add EPD_4IN2_Partial_lut_vcom1[]
  24. * Add EPD_4IN2_Partial_lut_ww1[]
  25. * Add EPD_4IN2_Partial_lut_bw1[]
  26. * Add EPD_4IN2_Partial_lut_wb1[]
  27. * Add EPD_4IN2_Partial_lut_bb1[]
  28. * Add EPD_4IN2_Partial_SetLut()
  29. * Add EPD_4IN2_PartialDisplay(...)
  30. * Poor display, no display function by default
  31. *
  32. * V3.0(2019-06-13):
  33. * 1.Change:
  34. * lut_vcomDC[] => EPD_4IN2_lut_vcomDC[]
  35. * lut_ww[] => EPD_4IN2_lut_ww[]
  36. * lut_bw[] => EPD_4IN2_lut_bw[]
  37. * lut_wb[] => EPD_4IN2_lut_wb[]
  38. * lut_bb[] => EPD_4IN2_lut_bb[]
  39. * EPD_Reset() => EPD_4IN2_Reset()
  40. * EPD_SendCommand() => EPD_4IN2_SendCommand()
  41. * EPD_SendData() => EPD_4IN2_SendData()
  42. * EPD_WaitUntilIdle() => EPD_4IN2_ReadBusy()
  43. * EPD_SetFullReg() => EPD_4IN2_SetFullReg()
  44. * EPD_SetPartReg() => EPD_4IN2_SetPartReg()
  45. * EPD_TurnOnDisplay() => EPD_4IN2_TurnOnDisplay()
  46. * EPD_Init() => EPD_4IN2_Init()
  47. * EPD_Clear() => EPD_4IN2_Clear()
  48. * EPD_Display() => EPD_4IN2_Display()
  49. * EPD_Sleep() => EPD_4IN2_Sleep()
  50. * 2.remove commands define:
  51. * #define PANEL_SETTING 0x00
  52. * #define POWER_SETTING 0x01
  53. * #define POWER_OFF 0x02
  54. * #define POWER_OFF_SEQUENCE_SETTING 0x03
  55. * #define POWER_ON 0x04
  56. * #define POWER_ON_MEASURE 0x05
  57. * #define BOOSTER_SOFT_START 0x06
  58. * #define DEEP_SLEEP 0x07
  59. * #define DATA_START_TRANSMISSION_1 0x10
  60. * #define DATA_STOP 0x11
  61. * #define DISPLAY_REFRESH 0x12
  62. * #define DATA_START_TRANSMISSION_2 0x13
  63. * #define VCOM_LUT 0x20
  64. * #define W2W_LUT 0x21
  65. * #define B2W_LUT 0x22
  66. * #define W2B_LUT 0x23
  67. * #define B2B_LUT 0x24
  68. * #define PLL_CONTROL 0x30
  69. * #define TEMPERATURE_SENSOR_CALIBRATION 0x40
  70. * #define TEMPERATURE_SENSOR_SELECTION 0x41
  71. * #define TEMPERATURE_SENSOR_WRITE 0x42
  72. * #define TEMPERATURE_SENSOR_READ 0x43
  73. * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50
  74. * #define LOW_POWER_DETECTION 0x51
  75. * #define TCON_SETTING 0x60
  76. * #define RESOLUTION_SETTING 0x61
  77. * #define GET_STATUS 0x71
  78. * #define AUTO_MEASURE_VCOM 0x80
  79. * #define READ_VCOM_VALUE 0x81
  80. * #define VCM_DC_SETTING 0x82
  81. * #define PARTIAL_WINDOW 0x90
  82. * #define PARTIAL_IN 0x91
  83. * #define PARTIAL_OUT 0x92
  84. * #define PROGRAM_MODE 0xA0
  85. * #define ACTIVE_PROGRAM 0xA1
  86. * #define READ_OTP_DATA 0xA2
  87. * #define POWER_SAVING 0xE3
  88. * V2.0(2018-10-30):
  89. * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8]
  90. * 2.Change:EPD_Display(UBYTE *Image)
  91. * Need to pass parameters: pointer to cached data
  92. #
  93. # Permission is hereby granted, free of charge, to any person obtaining a copy
  94. # of this software and associated documnetation files (the "Software"), to deal
  95. # in the Software without restriction, including without limitation the rights
  96. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  97. # copies of the Software, and to permit persons to whom the Software is
  98. # furished to do so, subject to the following conditions:
  99. #
  100. # The above copyright notice and this permission notice shall be included in
  101. # all copies or substantial portions of the Software.
  102. #
  103. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  104. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  105. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  106. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  107. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  108. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  109. # THE SOFTWARE.
  110. #
  111. ******************************************************************************/
  112. #include "EPD_4in2.h"
  113. #include "Debug.h"
  114. static const unsigned char EPD_4IN2_lut_vcom0[] = {
  115. 0x00, 0x17, 0x00, 0x00, 0x00, 0x02,
  116. 0x00, 0x17, 0x17, 0x00, 0x00, 0x02,
  117. 0x00, 0x0A, 0x01, 0x00, 0x00, 0x01,
  118. 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x02,
  119. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  120. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  121. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  122. };
  123. static const unsigned char EPD_4IN2_lut_ww[] = {
  124. 0x40, 0x17, 0x00, 0x00, 0x00, 0x02,
  125. 0x90, 0x17, 0x17, 0x00, 0x00, 0x02,
  126. 0x40, 0x0A, 0x01, 0x00, 0x00, 0x01,
  127. 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02,
  128. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  129. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  130. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  131. };
  132. static const unsigned char EPD_4IN2_lut_bw[] = {
  133. 0x40, 0x17, 0x00, 0x00, 0x00, 0x02,
  134. 0x90, 0x17, 0x17, 0x00, 0x00, 0x02,
  135. 0x40, 0x0A, 0x01, 0x00, 0x00, 0x01,
  136. 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02,
  137. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  138. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  139. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  140. };
  141. static const unsigned char EPD_4IN2_lut_wb[] = {
  142. 0x80, 0x17, 0x00, 0x00, 0x00, 0x02,
  143. 0x90, 0x17, 0x17, 0x00, 0x00, 0x02,
  144. 0x80, 0x0A, 0x01, 0x00, 0x00, 0x01,
  145. 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02,
  146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  147. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  148. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  149. };
  150. static const unsigned char EPD_4IN2_lut_bb[] = {
  151. 0x80, 0x17, 0x00, 0x00, 0x00, 0x02,
  152. 0x90, 0x17, 0x17, 0x00, 0x00, 0x02,
  153. 0x80, 0x0A, 0x01, 0x00, 0x00, 0x01,
  154. 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02,
  155. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  156. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  157. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  158. };
  159. /******************************partial screen update LUT*********************************/
  160. const unsigned char EPD_4IN2_Partial_lut_vcom1[] ={
  161. 0x00 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
  162. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  163. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  164. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  165. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  166. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  167. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  168. 0x00 ,0x00, };
  169. const unsigned char EPD_4IN2_Partial_lut_ww1[] ={
  170. 0x00 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
  171. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  172. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  173. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  174. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  175. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  176. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,};
  177. const unsigned char EPD_4IN2_Partial_lut_bw1[] ={
  178. 0x80 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
  179. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  180. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  181. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  182. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  183. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  184. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, };
  185. const unsigned char EPD_4IN2_Partial_lut_wb1[] ={
  186. 0x40 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
  187. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  188. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  189. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  190. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  191. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  192. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, };
  193. const unsigned char EPD_4IN2_Partial_lut_bb1[] ={
  194. 0x00 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
  195. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  196. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  197. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  198. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  199. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  200. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, };
  201. /******************************gray*********************************/
  202. //0~3 gray
  203. const unsigned char EPD_4IN2_4Gray_lut_vcom[] =
  204. {
  205. 0x00 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  206. 0x60 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  207. 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  208. 0x00 ,0x13 ,0x0A ,0x01 ,0x00 ,0x01,
  209. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  210. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  211. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
  212. };
  213. //R21
  214. const unsigned char EPD_4IN2_4Gray_lut_ww[] ={
  215. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  216. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  217. 0x10 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  218. 0xA0 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
  219. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  220. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  221. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  222. };
  223. //R22H r
  224. const unsigned char EPD_4IN2_4Gray_lut_bw[] ={
  225. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  226. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  227. 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  228. 0x99 ,0x0C ,0x01 ,0x03 ,0x04 ,0x01,
  229. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  230. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  231. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  232. };
  233. //R23H w
  234. const unsigned char EPD_4IN2_4Gray_lut_wb[] ={
  235. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  236. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  237. 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  238. 0x99 ,0x0B ,0x04 ,0x04 ,0x01 ,0x01,
  239. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  240. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  241. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  242. };
  243. //R24H b
  244. const unsigned char EPD_4IN2_4Gray_lut_bb[] ={
  245. 0x80 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  246. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  247. 0x20 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  248. 0x50 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
  249. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  250. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  251. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  252. };
  253. /******************************************************************************
  254. function : Software reset
  255. parameter:
  256. ******************************************************************************/
  257. static void EPD_4IN2_Reset(void)
  258. {
  259. DEV_Digital_Write(EPD_RST_PIN, 1);
  260. DEV_Delay_ms(200);
  261. DEV_Digital_Write(EPD_RST_PIN, 0);
  262. DEV_Delay_ms(200);
  263. DEV_Digital_Write(EPD_RST_PIN, 1);
  264. DEV_Delay_ms(200);
  265. }
  266. /******************************************************************************
  267. function : send command
  268. parameter:
  269. Reg : Command register
  270. ******************************************************************************/
  271. static void EPD_4IN2_SendCommand(UBYTE Reg)
  272. {
  273. DEV_Digital_Write(EPD_DC_PIN, 0);
  274. DEV_Digital_Write(EPD_CS_PIN, 0);
  275. DEV_SPI_WriteByte(Reg);
  276. DEV_Digital_Write(EPD_CS_PIN, 1);
  277. }
  278. /******************************************************************************
  279. function : send data
  280. parameter:
  281. Data : Write data
  282. ******************************************************************************/
  283. static void EPD_4IN2_SendData(UBYTE Data)
  284. {
  285. DEV_Digital_Write(EPD_DC_PIN, 1);
  286. DEV_Digital_Write(EPD_CS_PIN, 0);
  287. DEV_SPI_WriteByte(Data);
  288. DEV_Digital_Write(EPD_CS_PIN, 1);
  289. }
  290. /******************************************************************************
  291. function : Wait until the busy_pin goes LOW
  292. parameter:
  293. ******************************************************************************/
  294. void EPD_4IN2_ReadBusy(void)
  295. {
  296. Debug("e-Paper busy\r\n");
  297. EPD_4IN2_SendCommand(0x71);
  298. while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
  299. EPD_4IN2_SendCommand(0x71);
  300. DEV_Delay_ms(100);
  301. }
  302. Debug("e-Paper busy release\r\n");
  303. }
  304. /******************************************************************************
  305. function : Turn On Display
  306. parameter:
  307. ******************************************************************************/
  308. static void EPD_4IN2_TurnOnDisplay(void)
  309. {
  310. EPD_4IN2_SendCommand(0x12);
  311. DEV_Delay_ms(100);
  312. EPD_4IN2_ReadBusy();
  313. }
  314. /******************************************************************************
  315. function : set the look-up tables
  316. parameter:
  317. ******************************************************************************/
  318. static void EPD_4IN2_SetLut(void)
  319. {
  320. UWORD count;
  321. EPD_4IN2_SendCommand(0x20); //g vcom
  322. for(count=0; count<44; count++) {
  323. EPD_4IN2_SendData(EPD_4IN2_lut_vcom0[count]);
  324. }
  325. EPD_4IN2_SendCommand(0x21);
  326. for(count=0; count<42; count++) {
  327. EPD_4IN2_SendData(EPD_4IN2_lut_ww[count]);
  328. }
  329. EPD_4IN2_SendCommand(0x22);
  330. for(count=0; count<42; count++) {
  331. EPD_4IN2_SendData(EPD_4IN2_lut_bw[count]);
  332. }
  333. EPD_4IN2_SendCommand(0x23);
  334. for(count=0; count<42; count++) {
  335. EPD_4IN2_SendData(EPD_4IN2_lut_wb[count]);
  336. }
  337. EPD_4IN2_SendCommand(0x24);
  338. for(count=0; count<42; count++) {
  339. EPD_4IN2_SendData(EPD_4IN2_lut_bb[count]);
  340. }
  341. }
  342. static void EPD_4IN2_Partial_SetLut(void)
  343. {
  344. unsigned int count;
  345. EPD_4IN2_SendCommand(0x20);
  346. for(count=0;count<44;count++)
  347. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_vcom1[count]);}
  348. EPD_4IN2_SendCommand(0x21);
  349. for(count=0;count<42;count++)
  350. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_ww1[count]);}
  351. EPD_4IN2_SendCommand(0x22);
  352. for(count=0;count<42;count++)
  353. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_bw1[count]);}
  354. EPD_4IN2_SendCommand(0x23);
  355. for(count=0;count<42;count++)
  356. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_wb1[count]);}
  357. EPD_4IN2_SendCommand(0x24);
  358. for(count=0;count<42;count++)
  359. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_bb1[count]);}
  360. }
  361. //LUT download
  362. static void EPD_4IN2_4Gray_lut(void)
  363. {
  364. unsigned int count;
  365. {
  366. EPD_4IN2_SendCommand(0x20); //vcom
  367. for(count=0;count<42;count++)
  368. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_vcom[count]);}
  369. EPD_4IN2_SendCommand(0x21); //red not use
  370. for(count=0;count<42;count++)
  371. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_ww[count]);}
  372. EPD_4IN2_SendCommand(0x22); //bw r
  373. for(count=0;count<42;count++)
  374. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_bw[count]);}
  375. EPD_4IN2_SendCommand(0x23); //wb w
  376. for(count=0;count<42;count++)
  377. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_wb[count]);}
  378. EPD_4IN2_SendCommand(0x24); //bb b
  379. for(count=0;count<42;count++)
  380. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_bb[count]);}
  381. EPD_4IN2_SendCommand(0x25); //vcom
  382. for(count=0;count<42;count++)
  383. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_ww[count]);}
  384. }
  385. }
  386. /******************************************************************************
  387. function : Initialize the e-Paper register
  388. parameter:
  389. ******************************************************************************/
  390. void EPD_4IN2_Init(void)
  391. {
  392. EPD_4IN2_Reset();
  393. EPD_4IN2_SendCommand(0x01); // POWER SETTING
  394. EPD_4IN2_SendData(0x03);
  395. EPD_4IN2_SendData(0x00);
  396. EPD_4IN2_SendData(0x2b);
  397. EPD_4IN2_SendData(0x2b);
  398. EPD_4IN2_SendCommand(0x06); // boost soft start
  399. EPD_4IN2_SendData(0x17); //A
  400. EPD_4IN2_SendData(0x17); //B
  401. EPD_4IN2_SendData(0x17); //C
  402. EPD_4IN2_SendCommand(0x04); // POWER_ON
  403. EPD_4IN2_ReadBusy();
  404. EPD_4IN2_SendCommand(0x00); // panel setting
  405. EPD_4IN2_SendData(0xbf); // KW-BF KWR-AF BWROTP 0f BWOTP 1f
  406. EPD_4IN2_SendData(0x0d);
  407. EPD_4IN2_SendCommand(0x30); // PLL setting
  408. EPD_4IN2_SendData(0x3C); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
  409. EPD_4IN2_SendCommand(0x61); // resolution setting
  410. EPD_4IN2_SendData(0x01);
  411. EPD_4IN2_SendData(0x90); //128
  412. EPD_4IN2_SendData(0x01); //
  413. EPD_4IN2_SendData(0x2c);
  414. EPD_4IN2_SendCommand(0x82); // vcom_DC setting
  415. EPD_4IN2_SendData(0x28);
  416. EPD_4IN2_SendCommand(0X50); // VCOM AND DATA INTERVAL SETTING
  417. EPD_4IN2_SendData(0x97); // 97white border 77black border VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
  418. EPD_4IN2_SetLut();
  419. }
  420. void EPD_4IN2_Init_4Gray(void)
  421. {
  422. EPD_4IN2_Reset();
  423. EPD_4IN2_SendCommand(0x01); //POWER SETTING
  424. EPD_4IN2_SendData (0x03);
  425. EPD_4IN2_SendData (0x00); //VGH=20V,VGL=-20V
  426. EPD_4IN2_SendData (0x2b); //VDH=15V
  427. EPD_4IN2_SendData (0x2b); //VDL=-15V
  428. EPD_4IN2_SendData (0x13);
  429. EPD_4IN2_SendCommand(0x06); //booster soft start
  430. EPD_4IN2_SendData (0x17); //A
  431. EPD_4IN2_SendData (0x17); //B
  432. EPD_4IN2_SendData (0x17); //C
  433. EPD_4IN2_SendCommand(0x04);
  434. EPD_4IN2_ReadBusy();
  435. EPD_4IN2_SendCommand(0x00); //panel setting
  436. EPD_4IN2_SendData(0x3f); //KW-3f KWR-2F BWROTP 0f BWOTP 1f
  437. EPD_4IN2_SendCommand(0x30); //PLL setting
  438. EPD_4IN2_SendData (0x3c); //100hz
  439. EPD_4IN2_SendCommand(0x61); //resolution setting
  440. EPD_4IN2_SendData (0x01); //400
  441. EPD_4IN2_SendData (0x90);
  442. EPD_4IN2_SendData (0x01); //300
  443. EPD_4IN2_SendData (0x2c);
  444. EPD_4IN2_SendCommand(0x82); //vcom_DC setting
  445. EPD_4IN2_SendData (0x12);
  446. EPD_4IN2_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
  447. EPD_4IN2_SendData(0x97);
  448. }
  449. /******************************************************************************
  450. function : Clear screen
  451. parameter:
  452. ******************************************************************************/
  453. void EPD_4IN2_Clear(void)
  454. {
  455. UWORD Width, Height;
  456. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  457. Height = EPD_4IN2_HEIGHT;
  458. EPD_4IN2_SendCommand(0x10);
  459. for (UWORD j = 0; j < Height; j++) {
  460. for (UWORD i = 0; i < Width; i++) {
  461. EPD_4IN2_SendData(0xFF);
  462. }
  463. }
  464. EPD_4IN2_SendCommand(0x13);
  465. for (UWORD j = 0; j < Height; j++) {
  466. for (UWORD i = 0; i < Width; i++) {
  467. EPD_4IN2_SendData(0xFF);
  468. }
  469. }
  470. EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
  471. DEV_Delay_ms(10);
  472. EPD_4IN2_TurnOnDisplay();
  473. }
  474. /******************************************************************************
  475. function : Sends the image buffer in RAM to e-Paper and displays
  476. parameter:
  477. ******************************************************************************/
  478. void EPD_4IN2_Display(UBYTE *Image)
  479. {
  480. UWORD Width, Height;
  481. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  482. Height = EPD_4IN2_HEIGHT;
  483. EPD_4IN2_SendCommand(0x13);
  484. for (UWORD j = 0; j < Height; j++) {
  485. for (UWORD i = 0; i < Width; i++) {
  486. EPD_4IN2_SendData(Image[i + j * Width]);
  487. }
  488. }
  489. EPD_4IN2_TurnOnDisplay();
  490. }
  491. void EPD_4IN2_PartialDisplay(UWORD X_start,UWORD Y_start,UWORD X_end,UWORD Y_end, UBYTE *Image)
  492. {
  493. UWORD Width, Height;
  494. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  495. Height = EPD_4IN2_HEIGHT;
  496. X_start = (X_start % 8 == 0)? (X_start): (X_start/8*8+8);
  497. X_end = (X_end % 8 == 0)? (X_end): (X_end/8*8+8);
  498. EPD_4IN2_SendCommand(0X50);
  499. EPD_4IN2_SendData(0xf7);
  500. DEV_Delay_ms(100);
  501. EPD_4IN2_SendCommand(0x82); //vcom_DC setting
  502. EPD_4IN2_SendData (0x08);
  503. EPD_4IN2_SendCommand(0X50);
  504. EPD_4IN2_SendData(0x47);
  505. EPD_4IN2_Partial_SetLut();
  506. EPD_4IN2_SendCommand(0x91); //This command makes the display enter partial mode
  507. EPD_4IN2_SendCommand(0x90); //resolution setting
  508. EPD_4IN2_SendData ((X_start)/256);
  509. EPD_4IN2_SendData ((X_start)%256); //x-start
  510. EPD_4IN2_SendData ((X_end )/256);
  511. EPD_4IN2_SendData ((X_end )%256-1); //x-end
  512. EPD_4IN2_SendData (Y_start/256);
  513. EPD_4IN2_SendData (Y_start%256); //y-start
  514. EPD_4IN2_SendData (Y_end/256);
  515. EPD_4IN2_SendData (Y_end%256-1); //y-end
  516. EPD_4IN2_SendData (0x28);
  517. EPD_4IN2_SendCommand(0x10); //writes Old data to SRAM for programming
  518. for (UWORD j = 0; j < Y_end - Y_start; j++) {
  519. for (UWORD i = 0; i < (X_end - X_start)/8; i++) {
  520. EPD_4IN2_SendData(Image[(Y_start + j)*Width + X_start/8 + i]);
  521. }
  522. }
  523. EPD_4IN2_SendCommand(0x13); //writes New data to SRAM.
  524. for (UWORD j = 0; j < Y_end - Y_start; j++) {
  525. for (UWORD i = 0; i < (X_end - X_start)/8; i++) {
  526. EPD_4IN2_SendData(~Image[(Y_start + j)*Width + X_start/8 + i]);
  527. }
  528. }
  529. EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
  530. DEV_Delay_ms(10); //The delay here is necessary, 200uS at least!!!
  531. EPD_4IN2_TurnOnDisplay();
  532. }
  533. void EPD_4IN2_4GrayDisplay(const UBYTE *Image)
  534. {
  535. UDOUBLE i,j,k,m;
  536. UBYTE temp1,temp2,temp3;
  537. /****Color display description****
  538. white gray1 gray2 black
  539. 0x10| 01 01 00 00
  540. 0x13| 01 00 01 00
  541. *********************************/
  542. EPD_4IN2_SendCommand(0x10);
  543. // EPD_4IN2_HEIGHT
  544. // EPD_4IN2_WIDTH
  545. for(m = 0; m<EPD_4IN2_HEIGHT;m++)
  546. for(i=0;i<EPD_4IN2_WIDTH/8;i++)
  547. {
  548. temp3=0;
  549. for(j=0;j<2;j++)
  550. {
  551. temp1 = Image[(m*(EPD_4IN2_WIDTH/8)+i)*2+j];
  552. for(k=0;k<2;k++)
  553. {
  554. temp2 = temp1&0xC0 ;
  555. if(temp2 == 0xC0)
  556. temp3 |= 0x01;//white
  557. else if(temp2 == 0x00)
  558. temp3 |= 0x00; //black
  559. else if(temp2 == 0x80)
  560. temp3 |= 0x01; //gray1
  561. else //0x40
  562. temp3 |= 0x00; //gray2
  563. temp3 <<= 1;
  564. temp1 <<= 2;
  565. temp2 = temp1&0xC0 ;
  566. if(temp2 == 0xC0) //white
  567. temp3 |= 0x01;
  568. else if(temp2 == 0x00) //black
  569. temp3 |= 0x00;
  570. else if(temp2 == 0x80)
  571. temp3 |= 0x01; //gray1
  572. else //0x40
  573. temp3 |= 0x00; //gray2
  574. if(j!=1 || k!=1)
  575. temp3 <<= 1;
  576. temp1 <<= 2;
  577. }
  578. }
  579. EPD_4IN2_SendData(temp3);
  580. }
  581. // new data
  582. EPD_4IN2_SendCommand(0x13);
  583. for(m = 0; m<EPD_4IN2_HEIGHT;m++)
  584. for(i=0;i<EPD_4IN2_WIDTH/8;i++)
  585. {
  586. temp3=0;
  587. for(j=0;j<2;j++)
  588. {
  589. temp1 = Image[(m*(EPD_4IN2_WIDTH/8)+i)*2+j];
  590. for(k=0;k<2;k++)
  591. {
  592. temp2 = temp1&0xC0 ;
  593. if(temp2 == 0xC0)
  594. temp3 |= 0x01;//white
  595. else if(temp2 == 0x00)
  596. temp3 |= 0x00; //black
  597. else if(temp2 == 0x80)
  598. temp3 |= 0x00; //gray1
  599. else //0x40
  600. temp3 |= 0x01; //gray2
  601. temp3 <<= 1;
  602. temp1 <<= 2;
  603. temp2 = temp1&0xC0 ;
  604. if(temp2 == 0xC0) //white
  605. temp3 |= 0x01;
  606. else if(temp2 == 0x00) //black
  607. temp3 |= 0x00;
  608. else if(temp2 == 0x80)
  609. temp3 |= 0x00; //gray1
  610. else //0x40
  611. temp3 |= 0x01; //gray2
  612. if(j!=1 || k!=1)
  613. temp3 <<= 1;
  614. temp1 <<= 2;
  615. }
  616. }
  617. EPD_4IN2_SendData(temp3);
  618. }
  619. EPD_4IN2_4Gray_lut();
  620. EPD_4IN2_TurnOnDisplay();
  621. }
  622. /******************************************************************************
  623. function : Enter sleep mode
  624. parameter:
  625. ******************************************************************************/
  626. void EPD_4IN2_Sleep(void)
  627. {
  628. EPD_4IN2_SendCommand(0x02); // POWER_OFF
  629. EPD_4IN2_ReadBusy();
  630. EPD_4IN2_SendCommand(0x07); // DEEP_SLEEP
  631. EPD_4IN2_SendData(0XA5);
  632. }