EPD_2in7.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*****************************************************************************
  2. * | File : EPD_2in7.c
  3. * | Author : Waveshare team
  4. * | Function : 2.7inch e-paper
  5. * | Info :
  6. *----------------
  7. * | This version: V3.1
  8. * | Date : 2019-10-10
  9. * | Info :
  10. * -----------------------------------------------------------------------------
  11. * V3.1(2019-10-10):
  12. * 1. Add 4 grayscale display
  13. * Add EPD_2in7_gray_lut_vcom[]
  14. * Add EPD_2in7_gray_lut_ww[]
  15. * Add EPD_2in7_gray_lut_bw[]
  16. * Add EPD_2in7_gray_lut_wb[]
  17. * Add EPD_2in7_gray_lut_bb[]
  18. * Add EPD_2in7_gray_SetLut()
  19. * Add EPD_2IN7_Init_4Gray()
  20. * Add EPD_2IN7_4GrayDisplay()
  21. * V3.0(2019-06-12):
  22. * 1.Change:
  23. * lut_vcom_dc[] => EPD_2in7_lut_vcom_dc[]
  24. * lut_ww[] => EPD_2in7_lut_ww[]
  25. * lut_bw[] => EPD_2in7_lut_bw[]
  26. * lut_bb[] => EPD_2in7_lut_bb[]
  27. * lut_wb[] => EPD_2in7_lut_wb[]
  28. * EPD_Reset() => EPD_2in7_Reset()
  29. * EPD_SendCommand() => EPD_2in7_SendCommand()
  30. * EPD_SendData() => EPD_2in7_SendData()
  31. * EPD_WaitUntilIdle() => EPD_2in7_ReadBusy()
  32. * EPD_SetLut() => EPD_2in7_SetLut()
  33. * EPD_Init() => EPD_2in7_Init()
  34. * EPD_Clear() => EPD_2in7_Clear()
  35. * EPD_Display() => EPD_2in7_Display()
  36. * EPD_Sleep() => EPD_2in7_Sleep()
  37. * 2.remove commands define:
  38. * #define PANEL_SETTING 0x00
  39. * #define POWER_SETTING 0x01
  40. * #define POWER_OFF 0x02
  41. * #define POWER_OFF_SEQUENCE_SETTING 0x03
  42. * #define POWER_ON 0x04
  43. * #define POWER_ON_MEASURE 0x05
  44. * #define BOOSTER_SOFT_START 0x06
  45. * #define DEEP_SLEEP 0x07
  46. * #define DATA_START_TRANSMISSION_1 0x10
  47. * #define DATA_STOP 0x11
  48. * #define DISPLAY_REFRESH 0x12
  49. * #define DATA_START_TRANSMISSION_2 0x13
  50. * #define PLL_CONTROL 0x30
  51. * #define TEMPERATURE_SENSOR_COMMAND 0x40
  52. * #define TEMPERATURE_SENSOR_CALIBRATION 0x41
  53. * #define TEMPERATURE_SENSOR_WRITE 0x42
  54. * #define TEMPERATURE_SENSOR_READ 0x43
  55. * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50
  56. * #define LOW_POWER_DETECTION 0x51
  57. * #define TCON_SETTING 0x60
  58. * #define TCON_RESOLUTION 0x61
  59. * #define SOURCE_AND_GATE_START_SETTING 0x62
  60. * #define GET_STATUS 0x71
  61. * #define AUTO_MEASURE_VCOM 0x80
  62. * #define VCOM_VALUE 0x81
  63. * #define VCM_DC_SETTING_REGISTER 0x82
  64. * #define PROGRAM_MODE 0xA0
  65. * #define ACTIVE_PROGRAM 0xA1
  66. * #define READ_OTP_DATA 0xA2
  67. * -----------------------------------------------------------------------------
  68. * V2.0(2018-11-06):
  69. * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8]
  70. * 2.Change:EPD_Display(UBYTE *Image)
  71. * Need to pass parameters: pointer to cached data
  72. #
  73. # Permission is hereby granted, free of charge, to any person obtaining a copy
  74. # of this software and associated documnetation files (the "Software"), to deal
  75. # in the Software without restriction, including without limitation the rights
  76. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  77. # copies of the Software, and to permit persons to whom the Software is
  78. # furished to do so, subject to the following conditions:
  79. #
  80. # The above copyright notice and this permission notice shall be included in
  81. # all copies or substantial portions of the Software.
  82. #
  83. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  84. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  85. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  86. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  87. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  88. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  89. # THE SOFTWARE.
  90. #
  91. ******************************************************************************/
  92. #include "EPD_2in7.h"
  93. #include "Debug.h"
  94. static const unsigned char EPD_2in7_lut_vcom_dc[] = {
  95. 0x00 ,0x00,
  96. 0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  97. 0x60 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  98. 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  99. 0x00 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  100. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  101. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  102. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
  103. };
  104. static const unsigned char EPD_2in7_lut_ww[] = {
  105. 0x40 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  106. 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  107. 0x40 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  108. 0xA0 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  109. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  110. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  111. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  112. };
  113. static const unsigned char EPD_2in7_lut_bw[] = {
  114. 0x40 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  115. 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  116. 0x40 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  117. 0xA0 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  118. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  119. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  120. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  121. };
  122. static const unsigned char EPD_2in7_lut_bb[] = {
  123. 0x80 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  124. 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  125. 0x80 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  126. 0x50 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  127. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  128. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  129. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  130. };
  131. static const unsigned char EPD_2in7_lut_wb[] = {
  132. 0x80 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
  133. 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
  134. 0x80 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  135. 0x50 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
  136. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  137. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  138. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  139. };
  140. //////////////////////////////////////full screen update LUT////////////////////////////////////////////
  141. //0~3 gray
  142. static const unsigned char EPD_2in7_gray_lut_vcom[] = {
  143. 0x00 ,0x00,
  144. 0x00 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  145. 0x60 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  146. 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
  147. 0x00 ,0x13 ,0x0A ,0x01 ,0x00 ,0x01,
  148. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  149. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  150. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  151. };
  152. //R21
  153. static const unsigned char EPD_2in7_gray_lut_ww[] = {
  154. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  155. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  156. 0x10 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  157. 0xA0 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
  158. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  159. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  160. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  161. };
  162. //R22H r
  163. static const unsigned char EPD_2in7_gray_lut_bw[] = {
  164. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  165. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  166. 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  167. 0x99 ,0x0C ,0x01 ,0x03 ,0x04 ,0x01,
  168. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  169. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  170. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  171. };
  172. //R23H w
  173. static const unsigned char EPD_2in7_gray_lut_wb[] = {
  174. 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  175. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  176. 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  177. 0x99 ,0x0B ,0x04 ,0x04 ,0x01 ,0x01,
  178. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  179. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  180. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  181. };
  182. //R24H b
  183. static const unsigned char EPD_2in7_gray_lut_bb[] = {
  184. 0x80 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
  185. 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
  186. 0x20 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
  187. 0x50 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
  188. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  189. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  190. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  191. };
  192. /******************************************************************************
  193. function : Software reset
  194. parameter:
  195. ******************************************************************************/
  196. static void EPD_2in7_Reset(void)
  197. {
  198. DEV_Digital_Write(EPD_RST_PIN, 1);
  199. DEV_Delay_ms(200);
  200. DEV_Digital_Write(EPD_RST_PIN, 0);
  201. DEV_Delay_ms(2);
  202. DEV_Digital_Write(EPD_RST_PIN, 1);
  203. DEV_Delay_ms(200);
  204. }
  205. /******************************************************************************
  206. function : send command
  207. parameter:
  208. Reg : Command register
  209. ******************************************************************************/
  210. static void EPD_2in7_SendCommand(UBYTE Reg)
  211. {
  212. DEV_Digital_Write(EPD_DC_PIN, 0);
  213. DEV_Digital_Write(EPD_CS_PIN, 0);
  214. DEV_SPI_WriteByte(Reg);
  215. DEV_Digital_Write(EPD_CS_PIN, 1);
  216. }
  217. /******************************************************************************
  218. function : send data
  219. parameter:
  220. Data : Write data
  221. ******************************************************************************/
  222. static void EPD_2in7_SendData(UBYTE Data)
  223. {
  224. DEV_Digital_Write(EPD_DC_PIN, 1);
  225. DEV_Digital_Write(EPD_CS_PIN, 0);
  226. DEV_SPI_WriteByte(Data);
  227. DEV_Digital_Write(EPD_CS_PIN, 1);
  228. }
  229. /******************************************************************************
  230. function : Wait until the busy_pin goes LOW
  231. parameter:
  232. ******************************************************************************/
  233. static void EPD_2in7_ReadBusy(void)
  234. {
  235. Debug("e-Paper busy\r\n");
  236. UBYTE busy;
  237. do {
  238. EPD_2in7_SendCommand(0x71);
  239. busy = DEV_Digital_Read(EPD_BUSY_PIN);
  240. busy =!(busy & 0x01);
  241. } while(busy);
  242. DEV_Delay_ms(200);
  243. Debug("e-Paper busy release\r\n");
  244. }
  245. /******************************************************************************
  246. function : set the look-up tables
  247. parameter:
  248. ******************************************************************************/
  249. static void EPD_2in7_SetLut(void)
  250. {
  251. unsigned int count;
  252. EPD_2in7_SendCommand(0x20); //vcom
  253. for(count = 0; count < 44; count++) {
  254. EPD_2in7_SendData(EPD_2in7_lut_vcom_dc[count]);
  255. }
  256. EPD_2in7_SendCommand(0x21); //ww --
  257. for(count = 0; count < 42; count++) {
  258. EPD_2in7_SendData(EPD_2in7_lut_ww[count]);
  259. }
  260. EPD_2in7_SendCommand(0x22); //bw r
  261. for(count = 0; count < 42; count++) {
  262. EPD_2in7_SendData(EPD_2in7_lut_bw[count]);
  263. }
  264. EPD_2in7_SendCommand(0x23); //wb w
  265. for(count = 0; count < 42; count++) {
  266. EPD_2in7_SendData(EPD_2in7_lut_bb[count]);
  267. }
  268. EPD_2in7_SendCommand(0x24); //bb b
  269. for(count = 0; count < 42; count++) {
  270. EPD_2in7_SendData(EPD_2in7_lut_wb[count]);
  271. }
  272. }
  273. void EPD_2in7_gray_SetLut(void)
  274. {
  275. unsigned int count;
  276. EPD_2in7_SendCommand(0x20); //vcom
  277. for(count=0; count<44; count++) {
  278. EPD_2in7_SendData(EPD_2in7_gray_lut_vcom[count]);
  279. }
  280. EPD_2in7_SendCommand(0x21); //red not use
  281. for(count=0; count<42; count++) {
  282. EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);
  283. }
  284. EPD_2in7_SendCommand(0x22); //bw r
  285. for(count=0; count<42; count++) {
  286. EPD_2in7_SendData(EPD_2in7_gray_lut_bw[count]);
  287. }
  288. EPD_2in7_SendCommand(0x23); //wb w
  289. for(count=0; count<42; count++) {
  290. EPD_2in7_SendData(EPD_2in7_gray_lut_wb[count]);
  291. }
  292. EPD_2in7_SendCommand(0x24); //bb b
  293. for(count=0; count<42; count++) {
  294. EPD_2in7_SendData(EPD_2in7_gray_lut_bb[count]);
  295. }
  296. EPD_2in7_SendCommand(0x25); //vcom
  297. for(count=0; count<42; count++) {
  298. EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);
  299. }
  300. }
  301. /******************************************************************************
  302. function : Initialize the e-Paper register
  303. parameter:
  304. ******************************************************************************/
  305. void EPD_2IN7_Init(void)
  306. {
  307. EPD_2in7_Reset();
  308. EPD_2in7_SendCommand(0x01); // POWER_SETTING
  309. EPD_2in7_SendData(0x03); // VDS_EN, VDG_EN
  310. EPD_2in7_SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
  311. EPD_2in7_SendData(0x2b); // VDH
  312. EPD_2in7_SendData(0x2b); // VDL
  313. EPD_2in7_SendData(0x09); // VDHR
  314. EPD_2in7_SendCommand(0x06); // BOOSTER_SOFT_START
  315. EPD_2in7_SendData(0x07);
  316. EPD_2in7_SendData(0x07);
  317. EPD_2in7_SendData(0x17);
  318. // Power optimization
  319. EPD_2in7_SendCommand(0xF8);
  320. EPD_2in7_SendData(0x60);
  321. EPD_2in7_SendData(0xA5);
  322. // Power optimization
  323. EPD_2in7_SendCommand(0xF8);
  324. EPD_2in7_SendData(0x89);
  325. EPD_2in7_SendData(0xA5);
  326. // Power optimization
  327. EPD_2in7_SendCommand(0xF8);
  328. EPD_2in7_SendData(0x90);
  329. EPD_2in7_SendData(0x00);
  330. // Power optimization
  331. EPD_2in7_SendCommand(0xF8);
  332. EPD_2in7_SendData(0x93);
  333. EPD_2in7_SendData(0x2A);
  334. // Power optimization
  335. EPD_2in7_SendCommand(0xF8);
  336. EPD_2in7_SendData(0xA0);
  337. EPD_2in7_SendData(0xA5);
  338. // Power optimization
  339. EPD_2in7_SendCommand(0xF8);
  340. EPD_2in7_SendData(0xA1);
  341. EPD_2in7_SendData(0x00);
  342. // Power optimization
  343. EPD_2in7_SendCommand(0xF8);
  344. EPD_2in7_SendData(0x73);
  345. EPD_2in7_SendData(0x41);
  346. EPD_2in7_SendCommand(0x16); // PARTIAL_DISPLAY_REFRESH
  347. EPD_2in7_SendData(0x00);
  348. EPD_2in7_SendCommand(0x04); // POWER_ON
  349. EPD_2in7_ReadBusy();
  350. EPD_2in7_SendCommand(0x00); // PANEL_SETTING
  351. EPD_2in7_SendData(0xAF); // KW-BF KWR-AF BWROTP 0f
  352. EPD_2in7_SendCommand(0x30); // PLL_CONTROL
  353. EPD_2in7_SendData(0x3A); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
  354. EPD_2in7_SendCommand(0x82); // VCM_DC_SETTING_REGISTER
  355. EPD_2in7_SendData(0x12);
  356. EPD_2in7_SetLut();
  357. }
  358. void EPD_2IN7_Init_4Gray(void)
  359. {
  360. EPD_2in7_Reset();
  361. EPD_2in7_SendCommand(0x01); //POWER SETTING
  362. EPD_2in7_SendData (0x03);
  363. EPD_2in7_SendData (0x00);
  364. EPD_2in7_SendData (0x2b);
  365. EPD_2in7_SendData (0x2b);
  366. EPD_2in7_SendCommand(0x06); //booster soft start
  367. EPD_2in7_SendData (0x07); //A
  368. EPD_2in7_SendData (0x07); //B
  369. EPD_2in7_SendData (0x17); //C
  370. EPD_2in7_SendCommand(0xF8); //boost??
  371. EPD_2in7_SendData (0x60);
  372. EPD_2in7_SendData (0xA5);
  373. EPD_2in7_SendCommand(0xF8); //boost??
  374. EPD_2in7_SendData (0x89);
  375. EPD_2in7_SendData (0xA5);
  376. EPD_2in7_SendCommand(0xF8); //boost??
  377. EPD_2in7_SendData (0x90);
  378. EPD_2in7_SendData (0x00);
  379. EPD_2in7_SendCommand(0xF8); //boost??
  380. EPD_2in7_SendData (0x93);
  381. EPD_2in7_SendData (0x2A);
  382. EPD_2in7_SendCommand(0xF8); //boost??
  383. EPD_2in7_SendData (0xa0);
  384. EPD_2in7_SendData (0xa5);
  385. EPD_2in7_SendCommand(0xF8); //boost??
  386. EPD_2in7_SendData (0xa1);
  387. EPD_2in7_SendData (0x00);
  388. EPD_2in7_SendCommand(0xF8); //boost??
  389. EPD_2in7_SendData (0x73);
  390. EPD_2in7_SendData (0x41);
  391. EPD_2in7_SendCommand(0x16);
  392. EPD_2in7_SendData(0x00);
  393. EPD_2in7_SendCommand(0x04);
  394. EPD_2in7_ReadBusy();
  395. EPD_2in7_SendCommand(0x00); //panel setting
  396. EPD_2in7_SendData(0xbf); //KW-BF KWR-AF BWROTP 0f
  397. EPD_2in7_SendCommand(0x30); //PLL setting
  398. EPD_2in7_SendData (0x90); //100hz
  399. EPD_2in7_SendCommand(0x61); //resolution setting
  400. EPD_2in7_SendData (0x00); //176
  401. EPD_2in7_SendData (0xb0);
  402. EPD_2in7_SendData (0x01); //264
  403. EPD_2in7_SendData (0x08);
  404. EPD_2in7_SendCommand(0x82); //vcom_DC setting
  405. EPD_2in7_SendData (0x12);
  406. EPD_2in7_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
  407. EPD_2in7_SendData(0x97);
  408. }
  409. /******************************************************************************
  410. function : Clear screen
  411. parameter:
  412. ******************************************************************************/
  413. void EPD_2IN7_Clear(void)
  414. {
  415. UWORD Width, Height;
  416. Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
  417. Height = EPD_2IN7_HEIGHT;
  418. EPD_2in7_SendCommand(0x10);
  419. for (UWORD j = 0; j < Height; j++) {
  420. for (UWORD i = 0; i < Width; i++) {
  421. EPD_2in7_SendData(0XFF);
  422. }
  423. }
  424. EPD_2in7_SendCommand(0x13);
  425. for (UWORD j = 0; j < Height; j++) {
  426. for (UWORD i = 0; i < Width; i++) {
  427. EPD_2in7_SendData(0XFF);
  428. }
  429. }
  430. EPD_2in7_SendCommand(0x12);
  431. EPD_2in7_ReadBusy();
  432. }
  433. /******************************************************************************
  434. function : Sends the image buffer in RAM to e-Paper and displays
  435. parameter:
  436. ******************************************************************************/
  437. void EPD_2IN7_Display(const UBYTE *Image)
  438. {
  439. UWORD Width, Height;
  440. Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
  441. Height = EPD_2IN7_HEIGHT;
  442. /* EPD_2in7_SendCommand(0x10);
  443. for (UWORD j = 0; j < Height; j++) {
  444. for (UWORD i = 0; i < Width; i++) {
  445. EPD_2in7_SendData(0XFF);
  446. }
  447. }
  448. */
  449. EPD_2in7_SendCommand(0x13);
  450. for (UWORD j = 0; j < Height; j++) {
  451. for (UWORD i = 0; i < Width; i++) {
  452. EPD_2in7_SendData(Image[i + j * Width]);
  453. }
  454. }
  455. EPD_2in7_SendCommand(0x12);
  456. EPD_2in7_ReadBusy();
  457. }
  458. void EPD_2IN7_4GrayDisplay(const UBYTE *Image)
  459. {
  460. UDOUBLE i,j,k;
  461. UBYTE temp1,temp2,temp3;
  462. // old data
  463. EPD_2in7_SendCommand(0x10);
  464. for(i=0; i<5808; i++) { //5808*4 46464
  465. temp3=0;
  466. for(j=0; j<2; j++) {
  467. temp1 = Image[i*2+j];
  468. for(k=0; k<2; k++) {
  469. temp2 = temp1&0xC0;
  470. if(temp2 == 0xC0)
  471. temp3 |= 0x01;//white
  472. else if(temp2 == 0x00)
  473. temp3 |= 0x00; //black
  474. else if(temp2 == 0x80)
  475. temp3 |= 0x01; //gray1
  476. else //0x40
  477. temp3 |= 0x00; //gray2
  478. temp3 <<= 1;
  479. temp1 <<= 2;
  480. temp2 = temp1&0xC0 ;
  481. if(temp2 == 0xC0) //white
  482. temp3 |= 0x01;
  483. else if(temp2 == 0x00) //black
  484. temp3 |= 0x00;
  485. else if(temp2 == 0x80)
  486. temp3 |= 0x01; //gray1
  487. else //0x40
  488. temp3 |= 0x00; //gray2
  489. if(j!=1 || k!=1)
  490. temp3 <<= 1;
  491. temp1 <<= 2;
  492. }
  493. }
  494. EPD_2in7_SendData(temp3);
  495. }
  496. // new data
  497. EPD_2in7_SendCommand(0x13);
  498. for(i=0; i<5808; i++) { //5808*4 46464
  499. temp3=0;
  500. for(j=0; j<2; j++) {
  501. temp1 = Image[i*2+j];
  502. for(k=0; k<2; k++) {
  503. temp2 = temp1&0xC0 ;
  504. if(temp2 == 0xC0)
  505. temp3 |= 0x01;//white
  506. else if(temp2 == 0x00)
  507. temp3 |= 0x00; //black
  508. else if(temp2 == 0x80)
  509. temp3 |= 0x00; //gray1
  510. else //0x40
  511. temp3 |= 0x01; //gray2
  512. temp3 <<= 1;
  513. temp1 <<= 2;
  514. temp2 = temp1&0xC0 ;
  515. if(temp2 == 0xC0) //white
  516. temp3 |= 0x01;
  517. else if(temp2 == 0x00) //black
  518. temp3 |= 0x00;
  519. else if(temp2 == 0x80)
  520. temp3 |= 0x00; //gray1
  521. else //0x40
  522. temp3 |= 0x01; //gray2
  523. if(j!=1 || k!=1)
  524. temp3 <<= 1;
  525. temp1 <<= 2;
  526. }
  527. }
  528. EPD_2in7_SendData(temp3);
  529. }
  530. EPD_2in7_gray_SetLut();
  531. EPD_2in7_SendCommand(0x12);
  532. DEV_Delay_ms(200);
  533. EPD_2in7_ReadBusy();
  534. }
  535. /******************************************************************************
  536. function : Enter sleep mode
  537. parameter:
  538. ******************************************************************************/
  539. void EPD_2IN7_Sleep(void)
  540. {
  541. EPD_2in7_SendCommand(0X50);
  542. EPD_2in7_SendData(0xf7);
  543. EPD_2in7_SendCommand(0X02); //power off
  544. EPD_2in7_SendCommand(0X07); //deep sleep
  545. EPD_2in7_SendData(0xA5);
  546. }