1 /*****************************************************************************
2 * | File : EPD_1IN02_1in02.c
3 * | Author : Waveshare team
4 * | Function : Electronic paper driver
11 # Permission is hereby granted, free of charge, to any person obtaining a copy
12 # of this software and associated documnetation files (the "Software"), to deal
13 # in the Software without restriction, including without limitation the rights
14 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 # copies of the Software, and to permit persons to whom the Software is
16 # furished to do so, subject to the following conditions:
18 # The above copyright notice and this permission notice shall be included in
19 # all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 ******************************************************************************/
30 #include "EPD_1in02d.h"
32 * full screen update LUT
34 const unsigned char lut_w1
[] =
36 0x60 ,0x5A ,0x5A ,0x00 ,0x00 ,0x01 ,
37 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
38 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
39 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
40 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
41 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
42 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
45 const unsigned char lut_b1
[] =
47 0x90 ,0x5A ,0x5A ,0x00 ,0x00 ,0x01 ,
48 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
49 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
50 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
51 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
52 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
53 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
58 * partial screen update LUT
60 const unsigned char lut_w
[] =
62 0x60 ,0x01 ,0x01 ,0x00 ,0x00 ,0x01 ,
63 0x80 ,0x1f ,0x00 ,0x00 ,0x00 ,0x01 ,
64 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
65 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
66 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
67 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
68 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
71 const unsigned char lut_b
[] =
73 0x90 ,0x01 ,0x01 ,0x00 ,0x00 ,0x01 ,
74 0x40 ,0x1f ,0x00 ,0x00 ,0x00 ,0x01 ,
75 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
76 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
77 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
78 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
79 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
82 /******************************************************************************
83 function : Software reset
85 ******************************************************************************/
86 static void EPD_1IN02_Reset(void)
88 DEV_Digital_Write(EPD_RST_PIN
, 1);
90 DEV_Digital_Write(EPD_RST_PIN
, 0);// Module reset
92 DEV_Digital_Write(EPD_RST_PIN
, 1);
97 /******************************************************************************
98 function : send command
100 command : Command register
101 ******************************************************************************/
102 static void EPD_1IN02_SendCommand(UBYTE command
)
104 DEV_Digital_Write(EPD_CS_PIN
, 0);
105 DEV_Digital_Write(EPD_DC_PIN
, 0);// command write
107 DEV_SPI_WriteByte(command
);
108 DEV_Digital_Write(EPD_CS_PIN
, 1);
111 /******************************************************************************
115 ******************************************************************************/
116 static void EPD_1IN02_SendData(UBYTE Data
)
118 DEV_Digital_Write(EPD_CS_PIN
, 0);
119 DEV_Digital_Write(EPD_DC_PIN
, 1); // command write
120 DEV_SPI_WriteByte(Data
);
121 DEV_Digital_Write(EPD_CS_PIN
, 1);
124 /******************************************************************************
125 function : LUT download
126 ******************************************************************************/
127 void EPD_1IN02_SetFulltReg(void)
130 EPD_1IN02_SendCommand(0x23);
131 for(count
=0;count
<42;count
++)
132 {EPD_1IN02_SendData(lut_w1
[count
]);}
134 EPD_1IN02_SendCommand(0x24);
135 for(count
=0;count
<42;count
++)
136 {EPD_1IN02_SendData(lut_b1
[count
]);}
139 /******************************************************************************
140 function : LUT download
141 ******************************************************************************/
142 void EPD_1IN02_SetPartReg(void)
145 EPD_1IN02_SendCommand(0x23);
146 for(count
=0;count
<42;count
++){
147 EPD_1IN02_SendData(lut_w
[count
]);
150 EPD_1IN02_SendCommand(0x24);
151 for(count
=0;count
<42;count
++){
152 EPD_1IN02_SendData(lut_b
[count
]);
156 /******************************************************************************
157 function : Wait until the busy_pin goes LOW
158 ******************************************************************************/
159 void EPD_1IN02_WaitUntilIdle(void)
161 EPD_Busy_WaitUntil(1,1);
162 // unsigned char busy;
163 // unsigned char count = 100;
166 // EPD_1IN02_SendCommand(0x71);
167 // busy = DEV_Digital_Read(EPD_BUSY_PIN);
168 // busy =!(busy & 0x01);
172 // DEV_Delay_ms(100);
175 // DEV_Delay_ms(800);
179 /******************************************************************************
180 function : Turn On Display
181 ******************************************************************************/
182 void EPD_1IN02_TurnOnDisplay(void)
184 // EPD_1IN02_SendCommand(0x04); //power on
185 // EPD_1IN02_WaitUntilIdle();
186 EPD_1IN02_SendCommand(0x12); //Start refreshing the screen
188 EPD_1IN02_WaitUntilIdle();
189 // EPD_1IN02_SendCommand(0x02);
190 // EPD_1IN02_WaitUntilIdle(); //power off
193 /******************************************************************************
194 function :Initialize the e-Paper register
195 ******************************************************************************/
196 void EPD_1IN02_Init(UBYTE Mode
)
200 EPD_1IN02_SendCommand(0xD2);
201 EPD_1IN02_SendData(0x3F);
203 EPD_1IN02_SendCommand(0x00);
204 EPD_1IN02_SendData (0x6F); //from outside
206 EPD_1IN02_SendCommand(0x01); //power setting
207 EPD_1IN02_SendData (0x03);
208 EPD_1IN02_SendData (0x00);
209 EPD_1IN02_SendData (0x2b);
210 EPD_1IN02_SendData (0x2b);
212 EPD_1IN02_SendCommand(0x06); //Configuring the charge pump
213 EPD_1IN02_SendData(0x3f);
215 EPD_1IN02_SendCommand(0x2A); //Setting XON and the options of LUT
216 EPD_1IN02_SendData(0x00);
217 EPD_1IN02_SendData(0x00);
219 EPD_1IN02_SendCommand(0x30); //Set the clock frequency
220 EPD_1IN02_SendData(0x17); //50Hz
222 EPD_1IN02_SendCommand(0x50); //Set VCOM and data output interval
223 EPD_1IN02_SendData(0x57);
225 EPD_1IN02_SendCommand(0x60); //Set The non-overlapping period of Gate and Source.
226 EPD_1IN02_SendData(0x22);
228 EPD_1IN02_SendCommand(0x61); //resolution setting
229 EPD_1IN02_SendData (0x50); //source 128
230 EPD_1IN02_SendData (0x80);
232 EPD_1IN02_SendCommand(0x82); //sets VCOM_DC value
233 EPD_1IN02_SendData(0x12); //-1v
235 EPD_1IN02_SendCommand(0xe3);//Set POWER SAVING
236 EPD_1IN02_SendData(0x33);
237 EPD_1IN02_SetFulltReg();
238 EPD_1IN02_SendCommand(0x04); //power on
239 EPD_1IN02_WaitUntilIdle();
243 /******************************************************************************
244 function :Partial refresh initialization e-paper
245 ******************************************************************************/
246 void EPD_1IN02_Part_Init(void)
249 EPD_1IN02_SendCommand(0xD2);
250 EPD_1IN02_SendData(0x3F);
252 EPD_1IN02_SendCommand(0x00);
253 EPD_1IN02_SendData (0x6F); //from outside
255 EPD_1IN02_SendCommand(0x01); //power setting
256 EPD_1IN02_SendData (0x03);
257 EPD_1IN02_SendData (0x00);
258 EPD_1IN02_SendData (0x2b);
259 EPD_1IN02_SendData (0x2b);
261 EPD_1IN02_SendCommand(0x06); //Configuring the charge pump
262 EPD_1IN02_SendData(0x3f);
264 EPD_1IN02_SendCommand(0x2A); //Setting XON and the options of LUT
265 EPD_1IN02_SendData(0x00);
266 EPD_1IN02_SendData(0x00);
268 EPD_1IN02_SendCommand(0x30); //Set the clock frequency
269 EPD_1IN02_SendData(0x17);
271 EPD_1IN02_SendCommand(0x50); //Set VCOM and data output interval
272 EPD_1IN02_SendData(0xf2);
274 EPD_1IN02_SendCommand(0x60); //Set The non-overlapping period of Gate and Source.
275 EPD_1IN02_SendData(0x22);
277 EPD_1IN02_SendCommand(0x82); //Set VCOM_DC value
278 EPD_1IN02_SendData(0x12);//-1v
280 EPD_1IN02_SendCommand(0xe3);//Set POWER SAVING
281 EPD_1IN02_SendData(0x33);
283 EPD_1IN02_SetPartReg();
285 EPD_1IN02_SendCommand(0x04);//Set POWER SAVING
287 EPD_1IN02_WaitUntilIdle();
290 /******************************************************************************
291 function : Clear screen
292 ******************************************************************************/
293 void EPD_1IN02_Clear(void)
296 EPD_1IN02_SendCommand(0x10);
298 EPD_1IN02_SendData(0X00);
300 EPD_1IN02_SendCommand(0x13); //Transfer new data
302 EPD_1IN02_SendData(0xff);
304 EPD_1IN02_TurnOnDisplay();
309 /******************************************************************************
310 function : Sends the image buffer in RAM to e-Paper and displays
312 Image :Displayed data
313 ******************************************************************************/
314 void EPD_1IN02_Display(UBYTE
*Image
, UBYTE
*Image2
)
317 Width
= (EPD_1IN02_WIDTH
% 8 == 0)? (EPD_1IN02_WIDTH
/ 8 ): (EPD_1IN02_WIDTH
/ 8 + 1);
319 EPD_1IN02_SendCommand(0x10);
320 for (UWORD j
= 0; j
< EPD_1IN02_HEIGHT
; j
++) {
321 for (UWORD i
= 0; i
< Width
; i
++) {
322 EPD_1IN02_SendData(0xff);
326 EPD_1IN02_SendCommand(0x13);
327 for (UWORD j
= 0; j
< EPD_1IN02_HEIGHT
; j
++) {
328 for (UWORD i
= 0; i
< Width
; i
++) {
329 EPD_1IN02_SendData(Image
[i
+ j
* Width
]);
332 EPD_1IN02_TurnOnDisplay();
337 /******************************************************************************
338 function : Sends the image buffer in RAM to e-Paper and displays
340 old_Image: Last displayed data
342 ******************************************************************************/
343 void EPD_1IN02_DisplayPartial(UBYTE
*old_Image
, UBYTE
*Image
)
345 /* Set partial Windows */
346 EPD_1IN02_SendCommand(0x91); //This command makes the display enter partial mode
347 EPD_1IN02_SendCommand(0x90); //resolution setting
348 EPD_1IN02_SendData(0); //x-start
349 EPD_1IN02_SendData(79); //x-end
351 EPD_1IN02_SendData(0);
352 EPD_1IN02_SendData(127); //y-end
353 EPD_1IN02_SendData(0x00);
356 Width
= (EPD_1IN02_WIDTH
% 8 == 0)? (EPD_1IN02_WIDTH
/ 8 ): (EPD_1IN02_WIDTH
/ 8 + 1);
359 EPD_1IN02_SendCommand(0x10);
360 for (UWORD j
= 0; j
< EPD_1IN02_HEIGHT
; j
++) {
361 for (UWORD i
= 0; i
< Width
; i
++) {
362 EPD_1IN02_SendData(old_Image
[i
+ j
* Width
]);
366 EPD_1IN02_SendCommand(0x13);
367 for (UWORD j
= 0; j
< EPD_1IN02_HEIGHT
; j
++) {
368 for (UWORD i
= 0; i
< Width
; i
++) {
369 EPD_1IN02_SendData(Image
[i
+ j
* Width
]);
373 /* Set partial refresh */
374 EPD_1IN02_TurnOnDisplay();
377 /******************************************************************************
378 function : Enter sleep mode
379 ******************************************************************************/
380 void EPD_1IN02_Sleep(void)
382 EPD_1IN02_SendCommand(0X50);
383 EPD_1IN02_SendData(0xf7);
384 EPD_1IN02_SendCommand(0X02); //power off
385 EPD_1IN02_WaitUntilIdle();
386 EPD_1IN02_SendCommand(0X07); //deep sleep
387 EPD_1IN02_SendData(0xA5);
390 //printf("Turn off the power!!! \r\n");
391 DEV_Digital_Write(EPD_RST_PIN
, 0);// Module reset