EPD_4in2.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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(20);
  261. DEV_Digital_Write(EPD_RST_PIN, 0);
  262. DEV_Delay_ms(2);
  263. DEV_Digital_Write(EPD_RST_PIN, 1);
  264. DEV_Delay_ms(20);
  265. DEV_Digital_Write(EPD_RST_PIN, 0);
  266. DEV_Delay_ms(2);
  267. DEV_Digital_Write(EPD_RST_PIN, 1);
  268. DEV_Delay_ms(20);
  269. DEV_Digital_Write(EPD_RST_PIN, 0);
  270. DEV_Delay_ms(2);
  271. DEV_Digital_Write(EPD_RST_PIN, 1);
  272. DEV_Delay_ms(20);
  273. }
  274. /******************************************************************************
  275. function : send command
  276. parameter:
  277. Reg : Command register
  278. ******************************************************************************/
  279. static void EPD_4IN2_SendCommand(UBYTE Reg)
  280. {
  281. DEV_Digital_Write(EPD_DC_PIN, 0);
  282. DEV_Digital_Write(EPD_CS_PIN, 0);
  283. DEV_SPI_WriteByte(Reg);
  284. DEV_Digital_Write(EPD_CS_PIN, 1);
  285. }
  286. /******************************************************************************
  287. function : send data
  288. parameter:
  289. Data : Write data
  290. ******************************************************************************/
  291. static void EPD_4IN2_SendData(UBYTE Data)
  292. {
  293. DEV_Digital_Write(EPD_DC_PIN, 1);
  294. DEV_Digital_Write(EPD_CS_PIN, 0);
  295. DEV_SPI_WriteByte(Data);
  296. DEV_Digital_Write(EPD_CS_PIN, 1);
  297. }
  298. /******************************************************************************
  299. function : Wait until the busy_pin goes LOW
  300. parameter:
  301. ******************************************************************************/
  302. void EPD_4IN2_ReadBusy(void)
  303. {
  304. Debug("e-Paper busy\r\n");
  305. EPD_4IN2_SendCommand(0x71);
  306. while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
  307. EPD_4IN2_SendCommand(0x71);
  308. DEV_Delay_ms(100);
  309. }
  310. Debug("e-Paper busy release\r\n");
  311. }
  312. /******************************************************************************
  313. function : Turn On Display
  314. parameter:
  315. ******************************************************************************/
  316. static void EPD_4IN2_TurnOnDisplay(void)
  317. {
  318. EPD_4IN2_SendCommand(0x12);
  319. DEV_Delay_ms(100);
  320. EPD_4IN2_ReadBusy();
  321. }
  322. /******************************************************************************
  323. function : set the look-up tables
  324. parameter:
  325. ******************************************************************************/
  326. static void EPD_4IN2_SetLut(void)
  327. {
  328. UWORD count;
  329. EPD_4IN2_SendCommand(0x20); //g vcom
  330. for(count=0; count<44; count++) {
  331. EPD_4IN2_SendData(EPD_4IN2_lut_vcom0[count]);
  332. }
  333. EPD_4IN2_SendCommand(0x21);
  334. for(count=0; count<42; count++) {
  335. EPD_4IN2_SendData(EPD_4IN2_lut_ww[count]);
  336. }
  337. EPD_4IN2_SendCommand(0x22);
  338. for(count=0; count<42; count++) {
  339. EPD_4IN2_SendData(EPD_4IN2_lut_bw[count]);
  340. }
  341. EPD_4IN2_SendCommand(0x23);
  342. for(count=0; count<42; count++) {
  343. EPD_4IN2_SendData(EPD_4IN2_lut_wb[count]);
  344. }
  345. EPD_4IN2_SendCommand(0x24);
  346. for(count=0; count<42; count++) {
  347. EPD_4IN2_SendData(EPD_4IN2_lut_bb[count]);
  348. }
  349. }
  350. static void EPD_4IN2_Partial_SetLut(void)
  351. {
  352. unsigned int count;
  353. EPD_4IN2_SendCommand(0x20);
  354. for(count=0;count<44;count++)
  355. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_vcom1[count]);}
  356. EPD_4IN2_SendCommand(0x21);
  357. for(count=0;count<42;count++)
  358. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_ww1[count]);}
  359. EPD_4IN2_SendCommand(0x22);
  360. for(count=0;count<42;count++)
  361. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_bw1[count]);}
  362. EPD_4IN2_SendCommand(0x23);
  363. for(count=0;count<42;count++)
  364. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_wb1[count]);}
  365. EPD_4IN2_SendCommand(0x24);
  366. for(count=0;count<42;count++)
  367. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_bb1[count]);}
  368. }
  369. //LUT download
  370. static void EPD_4IN2_4Gray_lut(void)
  371. {
  372. unsigned int count;
  373. {
  374. EPD_4IN2_SendCommand(0x20); //vcom
  375. for(count=0;count<42;count++)
  376. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_vcom[count]);}
  377. EPD_4IN2_SendCommand(0x21); //red not use
  378. for(count=0;count<42;count++)
  379. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_ww[count]);}
  380. EPD_4IN2_SendCommand(0x22); //bw r
  381. for(count=0;count<42;count++)
  382. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_bw[count]);}
  383. EPD_4IN2_SendCommand(0x23); //wb w
  384. for(count=0;count<42;count++)
  385. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_wb[count]);}
  386. EPD_4IN2_SendCommand(0x24); //bb b
  387. for(count=0;count<42;count++)
  388. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_bb[count]);}
  389. EPD_4IN2_SendCommand(0x25); //vcom
  390. for(count=0;count<42;count++)
  391. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_ww[count]);}
  392. }
  393. }
  394. /******************************************************************************
  395. function : Initialize the e-Paper register
  396. parameter:
  397. ******************************************************************************/
  398. void EPD_4IN2_Init(void)
  399. {
  400. EPD_4IN2_Reset();
  401. EPD_4IN2_SendCommand(0x01); // POWER SETTING
  402. EPD_4IN2_SendData(0x03);
  403. EPD_4IN2_SendData(0x00);
  404. EPD_4IN2_SendData(0x2b);
  405. EPD_4IN2_SendData(0x2b);
  406. EPD_4IN2_SendCommand(0x06); // boost soft start
  407. EPD_4IN2_SendData(0x17); //A
  408. EPD_4IN2_SendData(0x17); //B
  409. EPD_4IN2_SendData(0x17); //C
  410. EPD_4IN2_SendCommand(0x04); // POWER_ON
  411. EPD_4IN2_ReadBusy();
  412. EPD_4IN2_SendCommand(0x00); // panel setting
  413. EPD_4IN2_SendData(0xbf); // KW-BF KWR-AF BWROTP 0f BWOTP 1f
  414. EPD_4IN2_SendData(0x0d);
  415. EPD_4IN2_SendCommand(0x30); // PLL setting
  416. EPD_4IN2_SendData(0x3C); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
  417. EPD_4IN2_SendCommand(0x61); // resolution setting
  418. EPD_4IN2_SendData(0x01);
  419. EPD_4IN2_SendData(0x90); //128
  420. EPD_4IN2_SendData(0x01); //
  421. EPD_4IN2_SendData(0x2c);
  422. EPD_4IN2_SendCommand(0x82); // vcom_DC setting
  423. EPD_4IN2_SendData(0x28);
  424. EPD_4IN2_SendCommand(0X50); // VCOM AND DATA INTERVAL SETTING
  425. EPD_4IN2_SendData(0x97); // 97white border 77black border VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
  426. EPD_4IN2_SetLut();
  427. }
  428. void EPD_4IN2_Init_4Gray(void)
  429. {
  430. EPD_4IN2_Reset();
  431. EPD_4IN2_SendCommand(0x01); //POWER SETTING
  432. EPD_4IN2_SendData (0x03);
  433. EPD_4IN2_SendData (0x00); //VGH=20V,VGL=-20V
  434. EPD_4IN2_SendData (0x2b); //VDH=15V
  435. EPD_4IN2_SendData (0x2b); //VDL=-15V
  436. EPD_4IN2_SendData (0x13);
  437. EPD_4IN2_SendCommand(0x06); //booster soft start
  438. EPD_4IN2_SendData (0x17); //A
  439. EPD_4IN2_SendData (0x17); //B
  440. EPD_4IN2_SendData (0x17); //C
  441. EPD_4IN2_SendCommand(0x04);
  442. EPD_4IN2_ReadBusy();
  443. EPD_4IN2_SendCommand(0x00); //panel setting
  444. EPD_4IN2_SendData(0x3f); //KW-3f KWR-2F BWROTP 0f BWOTP 1f
  445. EPD_4IN2_SendCommand(0x30); //PLL setting
  446. EPD_4IN2_SendData (0x3c); //100hz
  447. EPD_4IN2_SendCommand(0x61); //resolution setting
  448. EPD_4IN2_SendData (0x01); //400
  449. EPD_4IN2_SendData (0x90);
  450. EPD_4IN2_SendData (0x01); //300
  451. EPD_4IN2_SendData (0x2c);
  452. EPD_4IN2_SendCommand(0x82); //vcom_DC setting
  453. EPD_4IN2_SendData (0x12);
  454. EPD_4IN2_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
  455. EPD_4IN2_SendData(0x97);
  456. }
  457. /******************************************************************************
  458. function : Clear screen
  459. parameter:
  460. ******************************************************************************/
  461. void EPD_4IN2_Clear(void)
  462. {
  463. UWORD Width, Height;
  464. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  465. Height = EPD_4IN2_HEIGHT;
  466. EPD_4IN2_SendCommand(0x10);
  467. for (UWORD j = 0; j < Height; j++) {
  468. for (UWORD i = 0; i < Width; i++) {
  469. EPD_4IN2_SendData(0xFF);
  470. }
  471. }
  472. EPD_4IN2_SendCommand(0x13);
  473. for (UWORD j = 0; j < Height; j++) {
  474. for (UWORD i = 0; i < Width; i++) {
  475. EPD_4IN2_SendData(0xFF);
  476. }
  477. }
  478. EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
  479. DEV_Delay_ms(10);
  480. EPD_4IN2_TurnOnDisplay();
  481. }
  482. /******************************************************************************
  483. function : Sends the image buffer in RAM to e-Paper and displays
  484. parameter:
  485. ******************************************************************************/
  486. void EPD_4IN2_Display(UBYTE *Image)
  487. {
  488. UWORD Width, Height;
  489. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  490. Height = EPD_4IN2_HEIGHT;
  491. EPD_4IN2_SendCommand(0x13);
  492. for (UWORD j = 0; j < Height; j++) {
  493. for (UWORD i = 0; i < Width; i++) {
  494. EPD_4IN2_SendData(Image[i + j * Width]);
  495. }
  496. }
  497. EPD_4IN2_TurnOnDisplay();
  498. }
  499. void EPD_4IN2_PartialDisplay(UWORD X_start,UWORD Y_start,UWORD X_end,UWORD Y_end, UBYTE *Image)
  500. {
  501. UWORD Width, Height;
  502. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  503. Height = EPD_4IN2_HEIGHT;
  504. X_start = (X_start % 8 == 0)? (X_start): (X_start/8*8+8);
  505. X_end = (X_end % 8 == 0)? (X_end): (X_end/8*8+8);
  506. EPD_4IN2_SendCommand(0X50);
  507. EPD_4IN2_SendData(0xf7);
  508. DEV_Delay_ms(100);
  509. EPD_4IN2_SendCommand(0x82); //vcom_DC setting
  510. EPD_4IN2_SendData (0x08);
  511. EPD_4IN2_SendCommand(0X50);
  512. EPD_4IN2_SendData(0x47);
  513. EPD_4IN2_Partial_SetLut();
  514. EPD_4IN2_SendCommand(0x91); //This command makes the display enter partial mode
  515. EPD_4IN2_SendCommand(0x90); //resolution setting
  516. EPD_4IN2_SendData ((X_start)/256);
  517. EPD_4IN2_SendData ((X_start)%256); //x-start
  518. EPD_4IN2_SendData ((X_end )/256);
  519. EPD_4IN2_SendData ((X_end )%256-1); //x-end
  520. EPD_4IN2_SendData (Y_start/256);
  521. EPD_4IN2_SendData (Y_start%256); //y-start
  522. EPD_4IN2_SendData (Y_end/256);
  523. EPD_4IN2_SendData (Y_end%256-1); //y-end
  524. EPD_4IN2_SendData (0x28);
  525. EPD_4IN2_SendCommand(0x10); //writes Old data to SRAM for programming
  526. for (UWORD j = 0; j < Y_end - Y_start; j++) {
  527. for (UWORD i = 0; i < (X_end - X_start)/8; i++) {
  528. EPD_4IN2_SendData(Image[(Y_start + j)*Width + X_start/8 + i]);
  529. }
  530. }
  531. EPD_4IN2_SendCommand(0x13); //writes New data to SRAM.
  532. for (UWORD j = 0; j < Y_end - Y_start; j++) {
  533. for (UWORD i = 0; i < (X_end - X_start)/8; i++) {
  534. EPD_4IN2_SendData(~Image[(Y_start + j)*Width + X_start/8 + i]);
  535. }
  536. }
  537. EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
  538. DEV_Delay_ms(10); //The delay here is necessary, 200uS at least!!!
  539. EPD_4IN2_TurnOnDisplay();
  540. }
  541. void EPD_4IN2_4GrayDisplay(const UBYTE *Image)
  542. {
  543. UDOUBLE i,j,k,m;
  544. UBYTE temp1,temp2,temp3;
  545. /****Color display description****
  546. white gray1 gray2 black
  547. 0x10| 01 01 00 00
  548. 0x13| 01 00 01 00
  549. *********************************/
  550. EPD_4IN2_SendCommand(0x10);
  551. // EPD_4IN2_HEIGHT
  552. // EPD_4IN2_WIDTH
  553. for(m = 0; m<EPD_4IN2_HEIGHT;m++)
  554. for(i=0;i<EPD_4IN2_WIDTH/8;i++)
  555. {
  556. temp3=0;
  557. for(j=0;j<2;j++)
  558. {
  559. temp1 = Image[(m*(EPD_4IN2_WIDTH/8)+i)*2+j];
  560. for(k=0;k<2;k++)
  561. {
  562. temp2 = temp1&0xC0 ;
  563. if(temp2 == 0xC0)
  564. temp3 |= 0x01;//white
  565. else if(temp2 == 0x00)
  566. temp3 |= 0x00; //black
  567. else if(temp2 == 0x80)
  568. temp3 |= 0x01; //gray1
  569. else //0x40
  570. temp3 |= 0x00; //gray2
  571. temp3 <<= 1;
  572. temp1 <<= 2;
  573. temp2 = temp1&0xC0 ;
  574. if(temp2 == 0xC0) //white
  575. temp3 |= 0x01;
  576. else if(temp2 == 0x00) //black
  577. temp3 |= 0x00;
  578. else if(temp2 == 0x80)
  579. temp3 |= 0x01; //gray1
  580. else //0x40
  581. temp3 |= 0x00; //gray2
  582. if(j!=1 || k!=1)
  583. temp3 <<= 1;
  584. temp1 <<= 2;
  585. }
  586. }
  587. EPD_4IN2_SendData(temp3);
  588. }
  589. // new data
  590. EPD_4IN2_SendCommand(0x13);
  591. for(m = 0; m<EPD_4IN2_HEIGHT;m++)
  592. for(i=0;i<EPD_4IN2_WIDTH/8;i++)
  593. {
  594. temp3=0;
  595. for(j=0;j<2;j++)
  596. {
  597. temp1 = Image[(m*(EPD_4IN2_WIDTH/8)+i)*2+j];
  598. for(k=0;k<2;k++)
  599. {
  600. temp2 = temp1&0xC0 ;
  601. if(temp2 == 0xC0)
  602. temp3 |= 0x01;//white
  603. else if(temp2 == 0x00)
  604. temp3 |= 0x00; //black
  605. else if(temp2 == 0x80)
  606. temp3 |= 0x00; //gray1
  607. else //0x40
  608. temp3 |= 0x01; //gray2
  609. temp3 <<= 1;
  610. temp1 <<= 2;
  611. temp2 = temp1&0xC0 ;
  612. if(temp2 == 0xC0) //white
  613. temp3 |= 0x01;
  614. else if(temp2 == 0x00) //black
  615. temp3 |= 0x00;
  616. else if(temp2 == 0x80)
  617. temp3 |= 0x00; //gray1
  618. else //0x40
  619. temp3 |= 0x01; //gray2
  620. if(j!=1 || k!=1)
  621. temp3 <<= 1;
  622. temp1 <<= 2;
  623. }
  624. }
  625. EPD_4IN2_SendData(temp3);
  626. }
  627. EPD_4IN2_4Gray_lut();
  628. EPD_4IN2_TurnOnDisplay();
  629. }
  630. /******************************************************************************
  631. function : Enter sleep mode
  632. parameter:
  633. ******************************************************************************/
  634. void EPD_4IN2_Sleep(void)
  635. {
  636. // EPD_4IN2_SendCommand(0x02); // POWER_OFF
  637. // EPD_4IN2_ReadBusy();
  638. EPD_4IN2_SendCommand(0x07); // DEEP_SLEEP
  639. EPD_4IN2_SendData(0XA5);
  640. }