2
0

EPD_4in2.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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, 0x08, 0x08, 0x00, 0x00, 0x02,
  116. 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x01,
  117. 0x00, 0x08, 0x08, 0x00, 0x00, 0x02,
  118. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  119. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  120. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  121. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  122. 0x00, 0x00,
  123. };
  124. static const unsigned char EPD_4IN2_lut_ww[] = {
  125. 0x50, 0x08, 0x08, 0x00, 0x00, 0x02,
  126. 0x90, 0x0F, 0x0F, 0x00, 0x00, 0x01,
  127. 0xA0, 0x08, 0x08, 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. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  132. };
  133. static const unsigned char EPD_4IN2_lut_bw[] = {
  134. 0x50, 0x08, 0x08, 0x00, 0x00, 0x02,
  135. 0x90, 0x0F, 0x0F, 0x00, 0x00, 0x01,
  136. 0xA0, 0x08, 0x08, 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. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  141. };
  142. static const unsigned char EPD_4IN2_lut_wb[] = {
  143. 0xA0, 0x08, 0x08, 0x00, 0x00, 0x02,
  144. 0x90, 0x0F, 0x0F, 0x00, 0x00, 0x01,
  145. 0x50, 0x08, 0x08, 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. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  150. };
  151. static const unsigned char EPD_4IN2_lut_bb[] = {
  152. 0x20, 0x08, 0x08, 0x00, 0x00, 0x02,
  153. 0x90, 0x0F, 0x0F, 0x00, 0x00, 0x01,
  154. 0x10, 0x08, 0x08, 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. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  159. };
  160. /******************************partial screen update LUT*********************************/
  161. const unsigned char EPD_4IN2_Partial_lut_vcom1[] ={
  162. 0x00, 0x01, 0x20, 0x01, 0x00, 0x01,
  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, 0x00, 0x00, 0x00, 0x00,
  169. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  170. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  171. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  172. };
  173. const unsigned char EPD_4IN2_Partial_lut_ww1[] ={
  174. 0x00, 0x01, 0x20, 0x01, 0x00, 0x01,
  175. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  176. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  177. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  178. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  179. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  180. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  181. };
  182. const unsigned char EPD_4IN2_Partial_lut_bw1[] ={
  183. 0x20, 0x01, 0x20, 0x01, 0x00, 0x01,
  184. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  185. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  186. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  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. };
  194. const unsigned char EPD_4IN2_Partial_lut_wb1[] ={
  195. 0x10, 0x01, 0x20, 0x01, 0x00, 0x01,
  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. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  202. };
  203. const unsigned char EPD_4IN2_Partial_lut_bb1[] ={
  204. 0x00, 0x01,0x20, 0x01, 0x00, 0x01,
  205. 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
  206. 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
  207. 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
  208. 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
  209. 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
  210. 0x00, 0x00,0x00, 0x00, 0x00, 0x00,
  211. };
  212. /******************************gray*********************************/
  213. //0~3 gray
  214. const unsigned char EPD_4IN2_4Gray_lut_vcom[] =
  215. {
  216. 0x00 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  217. 0x60 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  218. 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  219. 0x00 ,0x13 ,0x0A ,0x01 ,0x00 ,0x01,
  220. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  221. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  222. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
  223. };
  224. //R21
  225. const unsigned char EPD_4IN2_4Gray_lut_ww[] ={
  226. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  227. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  228. 0x10 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  229. 0xA0 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
  230. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  231. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  232. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  233. };
  234. //R22H r
  235. const unsigned char EPD_4IN2_4Gray_lut_bw[] ={
  236. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  237. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  238. 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  239. 0x99 ,0x0C ,0x01 ,0x03 ,0x04 ,0x01,
  240. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  241. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  242. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  243. };
  244. //R23H w
  245. const unsigned char EPD_4IN2_4Gray_lut_wb[] ={
  246. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  247. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  248. 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  249. 0x99 ,0x0B ,0x04 ,0x04 ,0x01 ,0x01,
  250. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  251. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  252. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  253. };
  254. //R24H b
  255. const unsigned char EPD_4IN2_4Gray_lut_bb[] ={
  256. 0x80 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  257. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  258. 0x20 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  259. 0x50 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
  260. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  261. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  262. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  263. };
  264. /******************************************************************************
  265. function : Software reset
  266. parameter:
  267. ******************************************************************************/
  268. static void EPD_4IN2_Reset(void)
  269. {
  270. DEV_Digital_Write(EPD_RST_PIN, 0);
  271. DEV_Delay_ms(10);
  272. DEV_Digital_Write(EPD_RST_PIN, 1);
  273. DEV_Delay_ms(10);
  274. DEV_Digital_Write(EPD_RST_PIN, 0);
  275. DEV_Delay_ms(10);
  276. DEV_Digital_Write(EPD_RST_PIN, 1);
  277. DEV_Delay_ms(10);
  278. DEV_Digital_Write(EPD_RST_PIN, 0);
  279. DEV_Delay_ms(10);
  280. DEV_Digital_Write(EPD_RST_PIN, 1);
  281. DEV_Delay_ms(10);
  282. }
  283. /******************************************************************************
  284. function : send command
  285. parameter:
  286. Reg : Command register
  287. ******************************************************************************/
  288. static void EPD_4IN2_SendCommand(UBYTE Reg)
  289. {
  290. DEV_Digital_Write(EPD_DC_PIN, 0);
  291. DEV_Digital_Write(EPD_CS_PIN, 0);
  292. DEV_SPI_WriteByte(Reg);
  293. DEV_Digital_Write(EPD_CS_PIN, 1);
  294. }
  295. /******************************************************************************
  296. function : send data
  297. parameter:
  298. Data : Write data
  299. ******************************************************************************/
  300. static void EPD_4IN2_SendData(UBYTE Data)
  301. {
  302. DEV_Digital_Write(EPD_DC_PIN, 1);
  303. DEV_Digital_Write(EPD_CS_PIN, 0);
  304. DEV_SPI_WriteByte(Data);
  305. DEV_Digital_Write(EPD_CS_PIN, 1);
  306. }
  307. /******************************************************************************
  308. function : Wait until the busy_pin goes LOW
  309. parameter:
  310. ******************************************************************************/
  311. void EPD_4IN2_ReadBusy(void)
  312. {
  313. Debug("e-Paper busy\r\n");
  314. EPD_4IN2_SendCommand(0x71);
  315. while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
  316. EPD_4IN2_SendCommand(0x71);
  317. DEV_Delay_ms(100);
  318. }
  319. Debug("e-Paper busy release\r\n");
  320. }
  321. /******************************************************************************
  322. function : Turn On Display
  323. parameter:
  324. ******************************************************************************/
  325. static void EPD_4IN2_TurnOnDisplay(void)
  326. {
  327. EPD_4IN2_SendCommand(0x12);
  328. DEV_Delay_ms(100);
  329. EPD_4IN2_ReadBusy();
  330. }
  331. /******************************************************************************
  332. function : set the look-up tables
  333. parameter:
  334. ******************************************************************************/
  335. static void EPD_4IN2_Partial_SetLut(void)
  336. {
  337. unsigned int count;
  338. EPD_4IN2_SendCommand(0x20);
  339. for(count=0;count<44;count++)
  340. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_vcom1[count]);}
  341. EPD_4IN2_SendCommand(0x21);
  342. for(count=0;count<42;count++)
  343. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_ww1[count]);}
  344. EPD_4IN2_SendCommand(0x22);
  345. for(count=0;count<42;count++)
  346. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_bw1[count]);}
  347. EPD_4IN2_SendCommand(0x23);
  348. for(count=0;count<42;count++)
  349. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_wb1[count]);}
  350. EPD_4IN2_SendCommand(0x24);
  351. for(count=0;count<42;count++)
  352. {EPD_4IN2_SendData(EPD_4IN2_Partial_lut_bb1[count]);}
  353. }
  354. static void EPD_4IN2_SetLut(void)
  355. {
  356. unsigned int count;
  357. EPD_4IN2_SendCommand(0x20);
  358. for(count=0;count<36;count++)
  359. {EPD_4IN2_SendData(EPD_4IN2_lut_vcom0[count]);}
  360. EPD_4IN2_SendCommand(0x21);
  361. for(count=0;count<36;count++)
  362. {EPD_4IN2_SendData(EPD_4IN2_lut_ww[count]);}
  363. EPD_4IN2_SendCommand(0x22);
  364. for(count=0;count<36;count++)
  365. {EPD_4IN2_SendData(EPD_4IN2_lut_bw[count]);}
  366. EPD_4IN2_SendCommand(0x23);
  367. for(count=0;count<36;count++)
  368. {EPD_4IN2_SendData(EPD_4IN2_lut_wb[count]);}
  369. EPD_4IN2_SendCommand(0x24);
  370. for(count=0;count<36;count++)
  371. {EPD_4IN2_SendData(EPD_4IN2_lut_bb[count]);}
  372. }
  373. //LUT download
  374. static void EPD_4IN2_4Gray_lut(void)
  375. {
  376. unsigned int count;
  377. {
  378. EPD_4IN2_SendCommand(0x20); //vcom
  379. for(count=0;count<42;count++)
  380. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_vcom[count]);}
  381. EPD_4IN2_SendCommand(0x21); //red not use
  382. for(count=0;count<42;count++)
  383. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_ww[count]);}
  384. EPD_4IN2_SendCommand(0x22); //bw r
  385. for(count=0;count<42;count++)
  386. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_bw[count]);}
  387. EPD_4IN2_SendCommand(0x23); //wb w
  388. for(count=0;count<42;count++)
  389. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_wb[count]);}
  390. EPD_4IN2_SendCommand(0x24); //bb b
  391. for(count=0;count<42;count++)
  392. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_bb[count]);}
  393. EPD_4IN2_SendCommand(0x25); //vcom
  394. for(count=0;count<42;count++)
  395. {EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_ww[count]);}
  396. }
  397. }
  398. /******************************************************************************
  399. function : Initialize the e-Paper register
  400. parameter:
  401. ******************************************************************************/
  402. void EPD_4IN2_Init_Partial(void)
  403. {
  404. EPD_4IN2_Reset();
  405. EPD_4IN2_SendCommand(0x01); // POWER SETTING
  406. EPD_4IN2_SendData(0x03);
  407. EPD_4IN2_SendData(0x00);
  408. EPD_4IN2_SendData(0x2b);
  409. EPD_4IN2_SendData(0x2b);
  410. EPD_4IN2_SendCommand(0x06); // boost soft start
  411. EPD_4IN2_SendData(0x17); //A
  412. EPD_4IN2_SendData(0x17); //B
  413. EPD_4IN2_SendData(0x17); //C
  414. EPD_4IN2_SendCommand(0x04); // POWER_ON
  415. EPD_4IN2_ReadBusy();
  416. EPD_4IN2_SendCommand(0x00); // panel setting
  417. EPD_4IN2_SendData(0xbf); // KW-BF KWR-AF BWROTP 0f BWOTP 1f
  418. EPD_4IN2_SendCommand(0x30); // PLL setting
  419. EPD_4IN2_SendData(0x3C); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
  420. EPD_4IN2_SendCommand(0x61); // resolution setting
  421. EPD_4IN2_SendData(0x01);
  422. EPD_4IN2_SendData(0x90); //128
  423. EPD_4IN2_SendData(0x01); //
  424. EPD_4IN2_SendData(0x2c);
  425. EPD_4IN2_SendCommand(0x82); // vcom_DC setting
  426. EPD_4IN2_SendData(0x12);
  427. EPD_4IN2_SendCommand(0X50); // VCOM AND DATA INTERVAL SETTING
  428. EPD_4IN2_SendData(0x07); // 97white border 77black border VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
  429. EPD_4IN2_Partial_SetLut();
  430. }
  431. //UC8176C
  432. void EPD_4IN2_Init_Fast(void)
  433. {
  434. EPD_4IN2_Reset();
  435. EPD_4IN2_SendCommand(0x01); //POWER SETTING
  436. EPD_4IN2_SendData (0x03);
  437. EPD_4IN2_SendData (0x00);
  438. EPD_4IN2_SendData (0x2b);
  439. EPD_4IN2_SendData (0x2b);
  440. EPD_4IN2_SendCommand(0x06); //boost soft start
  441. EPD_4IN2_SendData (0x17); //A
  442. EPD_4IN2_SendData (0x17); //B
  443. EPD_4IN2_SendData (0x17); //C
  444. EPD_4IN2_SendCommand(0x04);
  445. EPD_4IN2_ReadBusy();
  446. EPD_4IN2_SendCommand(0x00); //panel setting
  447. EPD_4IN2_SendData(0xbf); //KW-bf KWR-2F BWROTP 0f BWOTP 1f
  448. EPD_4IN2_SendCommand(0x30);
  449. EPD_4IN2_SendData (0x3c); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
  450. EPD_4IN2_SendCommand(0x61); //resolution setting
  451. EPD_4IN2_SendData (0x01);
  452. EPD_4IN2_SendData (0x90); //400
  453. EPD_4IN2_SendData (0x01); //300
  454. EPD_4IN2_SendData (0x2c);
  455. EPD_4IN2_SendCommand(0x82); //vcom_DC setting
  456. EPD_4IN2_SendData (0x12);
  457. EPD_4IN2_SendCommand(0X50);
  458. EPD_4IN2_SendData(0x97);
  459. EPD_4IN2_SetLut();
  460. }
  461. void EPD_4IN2_Init_4Gray(void)
  462. {
  463. EPD_4IN2_Reset();
  464. EPD_4IN2_SendCommand(0x01); //POWER SETTING
  465. EPD_4IN2_SendData (0x03);
  466. EPD_4IN2_SendData (0x00); //VGH=20V,VGL=-20V
  467. EPD_4IN2_SendData (0x2b); //VDH=15V
  468. EPD_4IN2_SendData (0x2b); //VDL=-15V
  469. EPD_4IN2_SendData (0x13);
  470. EPD_4IN2_SendCommand(0x06); //booster soft start
  471. EPD_4IN2_SendData (0x17); //A
  472. EPD_4IN2_SendData (0x17); //B
  473. EPD_4IN2_SendData (0x17); //C
  474. EPD_4IN2_SendCommand(0x04);
  475. EPD_4IN2_ReadBusy();
  476. EPD_4IN2_SendCommand(0x00); //panel setting
  477. EPD_4IN2_SendData(0x3f); //KW-3f KWR-2F BWROTP 0f BWOTP 1f
  478. EPD_4IN2_SendCommand(0x30); //PLL setting
  479. EPD_4IN2_SendData (0x3c); //100hz
  480. EPD_4IN2_SendCommand(0x61); //resolution setting
  481. EPD_4IN2_SendData (0x01); //400
  482. EPD_4IN2_SendData (0x90);
  483. EPD_4IN2_SendData (0x01); //300
  484. EPD_4IN2_SendData (0x2c);
  485. EPD_4IN2_SendCommand(0x82); //vcom_DC setting
  486. EPD_4IN2_SendData (0x12);
  487. EPD_4IN2_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
  488. EPD_4IN2_SendData(0x97);
  489. }
  490. /******************************************************************************
  491. function : Clear screen
  492. parameter:
  493. ******************************************************************************/
  494. void EPD_4IN2_Clear(void)
  495. {
  496. UWORD Width, Height;
  497. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  498. Height = EPD_4IN2_HEIGHT;
  499. EPD_4IN2_SendCommand(0x10);
  500. for (UWORD j = 0; j < Height; j++) {
  501. for (UWORD i = 0; i < Width; i++) {
  502. EPD_4IN2_SendData(0xFF);
  503. }
  504. }
  505. EPD_4IN2_SendCommand(0x13);
  506. for (UWORD j = 0; j < Height; j++) {
  507. for (UWORD i = 0; i < Width; i++) {
  508. EPD_4IN2_SendData(0xFF);
  509. }
  510. }
  511. EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
  512. DEV_Delay_ms(1);
  513. EPD_4IN2_TurnOnDisplay();
  514. }
  515. /******************************************************************************
  516. function : Sends the image buffer in RAM to e-Paper and displays
  517. parameter:
  518. ******************************************************************************/
  519. void EPD_4IN2_Display(UBYTE *Image)
  520. {
  521. UWORD Width, Height;
  522. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  523. Height = EPD_4IN2_HEIGHT;
  524. EPD_4IN2_SendCommand(0x10);
  525. for (UWORD j = 0; j < Height; j++) {
  526. for (UWORD i = 0; i < Width; i++) {
  527. EPD_4IN2_SendData(0x00);
  528. }
  529. }
  530. EPD_4IN2_SendCommand(0x13);
  531. for (UWORD j = 0; j < Height; j++) {
  532. for (UWORD i = 0; i < Width; i++) {
  533. EPD_4IN2_SendData(Image[i + j * Width]);
  534. }
  535. }
  536. EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
  537. DEV_Delay_ms(10);
  538. EPD_4IN2_TurnOnDisplay();
  539. }
  540. void EPD_4IN2_PartialDisplay(UWORD X_start,UWORD Y_start,UWORD X_end,UWORD Y_end, UBYTE *Image)
  541. {
  542. UWORD Width, Height;
  543. static UBYTE DATA[EPD_4IN2_WIDTH * EPD_4IN2_HEIGHT / 8] = {0x00};
  544. Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
  545. Height = EPD_4IN2_HEIGHT;
  546. X_start = (X_start % 8 == 0)? (X_start): (X_start/8*8+8);
  547. X_end = (X_end % 8 == 0)? (X_end): (X_end/8*8+8);
  548. EPD_4IN2_SendCommand(0x91); //This command makes the display enter partial mode
  549. EPD_4IN2_SendCommand(0x90); //resolution setting
  550. EPD_4IN2_SendData ((X_start)/256);
  551. EPD_4IN2_SendData ((X_start)%256); //x-start
  552. EPD_4IN2_SendData ((X_end )/256);
  553. EPD_4IN2_SendData ((X_end )%256-1); //x-end
  554. EPD_4IN2_SendData (Y_start/256);
  555. EPD_4IN2_SendData (Y_start%256); //y-start
  556. EPD_4IN2_SendData (Y_end/256);
  557. EPD_4IN2_SendData (Y_end%256-1); //y-end
  558. EPD_4IN2_SendData (0x28);
  559. EPD_4IN2_SendCommand(0x10); //writes Old data to SRAM for programming
  560. for (UWORD j = 0; j < Y_end - Y_start; j++) {
  561. for (UWORD i = 0; i < (X_end - X_start)/8; i++) {
  562. EPD_4IN2_SendData(DATA[(Y_start + j)*Width + X_start/8 + i]);
  563. }
  564. }
  565. EPD_4IN2_SendCommand(0x13); //writes New data to SRAM.
  566. for (UWORD j = 0; j < Y_end - Y_start; j++) {
  567. for (UWORD i = 0; i < (X_end - X_start)/8; i++) {
  568. EPD_4IN2_SendData(~Image[(Y_start + j)*Width + X_start/8 + i]);
  569. DATA[(Y_start + j)*Width + X_start/8 + i] = ~Image[(Y_start + j)*Width + X_start/8 + i];
  570. }
  571. }
  572. EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
  573. DEV_Delay_ms(10); //The delay here is necessary, 200uS at least!!!
  574. EPD_4IN2_TurnOnDisplay();
  575. }
  576. void EPD_4IN2_4GrayDisplay(const UBYTE *Image)
  577. {
  578. UDOUBLE i,j,k,m;
  579. UBYTE temp1,temp2,temp3;
  580. /****Color display description****
  581. white gray1 gray2 black
  582. 0x10| 01 01 00 00
  583. 0x13| 01 00 01 00
  584. *********************************/
  585. EPD_4IN2_SendCommand(0x10);
  586. // EPD_4IN2_HEIGHT
  587. // EPD_4IN2_WIDTH
  588. for(m = 0; m<EPD_4IN2_HEIGHT;m++)
  589. for(i=0;i<EPD_4IN2_WIDTH/8;i++)
  590. {
  591. temp3=0;
  592. for(j=0;j<2;j++)
  593. {
  594. temp1 = Image[(m*(EPD_4IN2_WIDTH/8)+i)*2+j];
  595. for(k=0;k<2;k++)
  596. {
  597. temp2 = temp1&0xC0 ;
  598. if(temp2 == 0xC0)
  599. temp3 |= 0x01;//white
  600. else if(temp2 == 0x00)
  601. temp3 |= 0x00; //black
  602. else if(temp2 == 0x80)
  603. temp3 |= 0x01; //gray1
  604. else //0x40
  605. temp3 |= 0x00; //gray2
  606. temp3 <<= 1;
  607. temp1 <<= 2;
  608. temp2 = temp1&0xC0 ;
  609. if(temp2 == 0xC0) //white
  610. temp3 |= 0x01;
  611. else if(temp2 == 0x00) //black
  612. temp3 |= 0x00;
  613. else if(temp2 == 0x80)
  614. temp3 |= 0x01; //gray1
  615. else //0x40
  616. temp3 |= 0x00; //gray2
  617. if(j!=1 || k!=1)
  618. temp3 <<= 1;
  619. temp1 <<= 2;
  620. }
  621. }
  622. EPD_4IN2_SendData(temp3);
  623. }
  624. // new data
  625. EPD_4IN2_SendCommand(0x13);
  626. for(m = 0; m<EPD_4IN2_HEIGHT;m++)
  627. for(i=0;i<EPD_4IN2_WIDTH/8;i++)
  628. {
  629. temp3=0;
  630. for(j=0;j<2;j++)
  631. {
  632. temp1 = Image[(m*(EPD_4IN2_WIDTH/8)+i)*2+j];
  633. for(k=0;k<2;k++)
  634. {
  635. temp2 = temp1&0xC0 ;
  636. if(temp2 == 0xC0)
  637. temp3 |= 0x01;//white
  638. else if(temp2 == 0x00)
  639. temp3 |= 0x00; //black
  640. else if(temp2 == 0x80)
  641. temp3 |= 0x00; //gray1
  642. else //0x40
  643. temp3 |= 0x01; //gray2
  644. temp3 <<= 1;
  645. temp1 <<= 2;
  646. temp2 = temp1&0xC0 ;
  647. if(temp2 == 0xC0) //white
  648. temp3 |= 0x01;
  649. else if(temp2 == 0x00) //black
  650. temp3 |= 0x00;
  651. else if(temp2 == 0x80)
  652. temp3 |= 0x00; //gray1
  653. else //0x40
  654. temp3 |= 0x01; //gray2
  655. if(j!=1 || k!=1)
  656. temp3 <<= 1;
  657. temp1 <<= 2;
  658. }
  659. }
  660. EPD_4IN2_SendData(temp3);
  661. }
  662. EPD_4IN2_4Gray_lut();
  663. EPD_4IN2_TurnOnDisplay();
  664. }
  665. /******************************************************************************
  666. function : Enter sleep mode
  667. parameter:
  668. ******************************************************************************/
  669. void EPD_4IN2_Sleep(void)
  670. {
  671. EPD_4IN2_SendCommand(0x50); // DEEP_SLEEP
  672. EPD_4IN2_SendData(0XF7);
  673. EPD_4IN2_SendCommand(0x02); // POWER_OFF
  674. EPD_4IN2_ReadBusy();
  675. EPD_4IN2_SendCommand(0x07); // DEEP_SLEEP
  676. EPD_4IN2_SendData(0XA5);
  677. }