1 /*****************************************************************************
3 * | Author : Waveshare team
4 * | Function : Electronic paper driver
10 *****************************************************************************
12 # Permission is hereby granted, free of charge, to any person obtaining a copy
13 # of this software and associated documnetation files(the "Software"), to deal
14 # in the Software without restriction, including without limitation the rights
15 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 # copies of the Software, and to permit persons to whom the Software is
17 # furished to do so, subject to the following conditions:
19 # The above copyright notice and this permission notice shall be included in
20 # all copies or substantial portions of the Software.
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 ******************************************************************************/
31 #include "EPD_7in5_V2.h"
34 /******************************************************************************
35 function : Software reset
37 ******************************************************************************/
38 static void EPD_Reset(void)
40 DEV_Digital_Write(EPD_RST_PIN
, 1);
42 DEV_Digital_Write(EPD_RST_PIN
, 0);
44 DEV_Digital_Write(EPD_RST_PIN
, 1);
48 /******************************************************************************
49 function : send command
51 Reg : Command register
52 ******************************************************************************/
53 static void EPD_SendCommand(UBYTE Reg
)
55 DEV_Digital_Write(EPD_DC_PIN
, 0);
56 DEV_Digital_Write(EPD_CS_PIN
, 0);
57 DEV_SPI_WriteByte(Reg
);
58 DEV_Digital_Write(EPD_CS_PIN
, 1);
61 /******************************************************************************
65 ******************************************************************************/
66 static void EPD_SendData(UBYTE Data
)
68 DEV_Digital_Write(EPD_DC_PIN
, 1);
69 DEV_Digital_Write(EPD_CS_PIN
, 0);
70 DEV_SPI_WriteByte(Data
);
71 DEV_Digital_Write(EPD_CS_PIN
, 1);
74 /******************************************************************************
75 function : Wait until the busy_pin goes LOW
77 ******************************************************************************/
78 static void EPD_WaitUntilIdle(void)
80 EPD_Busy_WaitUntil(1,1);
81 // unsigned char count = 200;
82 // Debug("e-Paper busy\r\n");
83 // unsigned char busy;
85 // EPD_SendCommand(0x71);
86 // busy = DEV_Digital_Read(EPD_BUSY_PIN);
87 // busy =!(busy & 0x01);
90 // Debug("error: e-Paper busy timeout!!!\r\n");
97 // Debug("e-Paper busy release\r\n");
102 /******************************************************************************
103 function : Turn On Display
105 ******************************************************************************/
106 static void EPD_7IN5_V2_TurnOnDisplay(void)
108 EPD_SendCommand(0x12); //DISPLAY REFRESH
109 DEV_Delay_ms(100); //!!!The delay here is necessary, 200uS at least!!!
113 /******************************************************************************
114 function : Initialize the e-Paper register
116 ******************************************************************************/
117 UBYTE
EPD_7IN5_V2_Init(UBYTE mode
)
121 EPD_SendCommand(0x01); //POWER SETTING
123 EPD_SendData(0x07); //VGH=20V,VGL=-20V
124 EPD_SendData(0x3f); //VDH=15V
125 EPD_SendData(0x3f); //VDL=-15V
127 EPD_SendCommand(0x04); //POWER ON
131 EPD_SendCommand(0X00); //PANNEL SETTING
132 EPD_SendData(0x1F); //KW-3f KWR-2F BWROTP 0f BWOTP 1f
134 EPD_SendCommand(0x61); //tres
135 EPD_SendData(0x03); //source 800
137 EPD_SendData(0x01); //gate 480
140 EPD_SendCommand(0X15);
143 EPD_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
147 EPD_SendCommand(0X60); //TCON SETTING
153 /******************************************************************************
154 function : Clear screen
156 ******************************************************************************/
157 void EPD_7IN5_V2_Clear(void)
160 Width
=(EPD_7IN5_V2_WIDTH
% 8 == 0)?(EPD_7IN5_V2_WIDTH
/ 8 ):(EPD_7IN5_V2_WIDTH
/ 8 + 1);
161 Height
= EPD_7IN5_V2_HEIGHT
;
164 EPD_SendCommand(0x10);
165 for(i
=0; i
<Height
*Width
; i
++) {
168 EPD_SendCommand(0x13);
169 for(i
=0; i
<Height
*Width
; i
++) {
172 EPD_7IN5_V2_TurnOnDisplay();
175 void EPD_7IN5_V2_ClearBlack(void)
178 Width
=(EPD_7IN5_V2_WIDTH
% 8 == 0)?(EPD_7IN5_V2_WIDTH
/ 8 ):(EPD_7IN5_V2_WIDTH
/ 8 + 1);
179 Height
= EPD_7IN5_V2_HEIGHT
;
182 EPD_SendCommand(0x13);
183 for(i
=0; i
<Height
*Width
; i
++) {
186 EPD_7IN5_V2_TurnOnDisplay();
189 /******************************************************************************
190 function : Sends the image buffer in RAM to e-Paper and displays
192 ******************************************************************************/
193 void EPD_7IN5_V2_Display(const UBYTE
*blackimage
, UBYTE
*Image2
)
195 UDOUBLE Width
, Height
;
196 Width
=(EPD_7IN5_V2_WIDTH
% 8 == 0)?(EPD_7IN5_V2_WIDTH
/ 8 ):(EPD_7IN5_V2_WIDTH
/ 8 + 1);
197 Height
= EPD_7IN5_V2_HEIGHT
;
200 EPD_SendCommand(0x13);
201 for (UDOUBLE j
= 0; j
< Height
; j
++) {
202 for (UDOUBLE i
= 0; i
< Width
; i
++) {
203 EPD_SendData(~blackimage
[i
+ j
* Width
]);
206 EPD_7IN5_V2_TurnOnDisplay();
209 void EPD_7IN5_V2_WritePicture(const UBYTE
*blackimage
, UBYTE Block
)
212 UDOUBLE Width
, Height
;
213 Width
=(EPD_7IN5_V2_WIDTH
% 8 == 0)?(EPD_7IN5_V2_WIDTH
/ 8 ):(EPD_7IN5_V2_WIDTH
/ 8 + 1);
214 Height
= EPD_7IN5_V2_HEIGHT
;
217 EPD_SendCommand(0x13);
219 for (UDOUBLE j
= 0; j
< Height
/2; j
++) {
220 for (UDOUBLE i
= 0; i
< Width
; i
++) {
221 EPD_SendData(~blackimage
[i
+ j
* Width
]);
225 EPD_7IN5_V2_TurnOnDisplay();
229 /******************************************************************************
230 function : Enter sleep mode
232 ******************************************************************************/
233 void EPD_7IN5_V2_Sleep(void)
235 EPD_SendCommand(0X02); //power off
237 EPD_SendCommand(0X07); //deep sleep