1 /*****************************************************************************
2 * | File : EPD_5in65f.c
3 * | Author : Waveshare team
4 * | Function : 5.65inch e-paper
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_5in65f.h"
33 /******************************************************************************
34 function : Software reset
36 ******************************************************************************/
37 static void EPD_5IN65F_Reset(void)
39 DEV_Digital_Write(EPD_RST_PIN
, 1);
41 DEV_Digital_Write(EPD_RST_PIN
, 0);
43 DEV_Digital_Write(EPD_RST_PIN
, 1);
47 /******************************************************************************
48 function : send command
50 Reg : Command register
51 ******************************************************************************/
52 static void EPD_5IN65F_SendCommand(UBYTE Reg
)
54 DEV_Digital_Write(EPD_DC_PIN
, 0);
55 DEV_Digital_Write(EPD_CS_PIN
, 0);
56 DEV_SPI_WriteByte(Reg
);
57 DEV_Digital_Write(EPD_CS_PIN
, 1);
60 /******************************************************************************
64 ******************************************************************************/
65 static void EPD_5IN65F_SendData(UBYTE Data
)
67 DEV_Digital_Write(EPD_DC_PIN
, 1);
68 DEV_Digital_Write(EPD_CS_PIN
, 0);
69 DEV_SPI_WriteByte(Data
);
70 DEV_Digital_Write(EPD_CS_PIN
, 1);
74 static void EPD_5IN65F_BusyHigh(void)// If BUSYN=0 then waiting
76 EPD_Busy_WaitUntil(1,0);
77 // unsigned char count = 100;
78 // while(!(DEV_Digital_Read(EPD_BUSY_PIN))){
88 static void EPD_5IN65F_BusyLow(void)// If BUSYN=1 then waiting
90 EPD_Busy_WaitUntil(0,0);
91 // unsigned char count = 100;
92 // while(DEV_Digital_Read(EPD_BUSY_PIN)){
102 /******************************************************************************
103 function : Initialize the e-Paper register
105 ******************************************************************************/
106 void EPD_5IN65F_Init(UBYTE mode
)
109 EPD_5IN65F_BusyHigh();
110 EPD_5IN65F_SendCommand(0x00);
111 EPD_5IN65F_SendData(0xEF);
112 EPD_5IN65F_SendData(0x08);
113 EPD_5IN65F_SendCommand(0x01);
114 EPD_5IN65F_SendData(0x37);
115 EPD_5IN65F_SendData(0x00);
116 EPD_5IN65F_SendData(0x23);
117 EPD_5IN65F_SendData(0x23);
118 EPD_5IN65F_SendCommand(0x03);
119 EPD_5IN65F_SendData(0x00);
120 EPD_5IN65F_SendCommand(0x06);
121 EPD_5IN65F_SendData(0xC7);
122 EPD_5IN65F_SendData(0xC7);
123 EPD_5IN65F_SendData(0x1D);
124 EPD_5IN65F_SendCommand(0x30);
125 EPD_5IN65F_SendData(0x3C);
126 EPD_5IN65F_SendCommand(0x40);
127 EPD_5IN65F_SendData(0x00);
128 EPD_5IN65F_SendCommand(0x50);
129 EPD_5IN65F_SendData(0x37);
130 EPD_5IN65F_SendCommand(0x60);
131 EPD_5IN65F_SendData(0x22);
132 EPD_5IN65F_SendCommand(0x61);
133 EPD_5IN65F_SendData(0x02);
134 EPD_5IN65F_SendData(0x58);
135 EPD_5IN65F_SendData(0x01);
136 EPD_5IN65F_SendData(0xC0);
137 EPD_5IN65F_SendCommand(0xE3);
138 EPD_5IN65F_SendData(0xAA);
141 EPD_5IN65F_SendCommand(0x50);
142 EPD_5IN65F_SendData(0x37);
145 /******************************************************************************
146 function : Clear screen
148 ******************************************************************************/
149 void EPD_5IN65F_Clear(UBYTE color
)
151 EPD_5IN65F_SendCommand(0x61);//Set Resolution setting
152 EPD_5IN65F_SendData(0x02);
153 EPD_5IN65F_SendData(0x58);
154 EPD_5IN65F_SendData(0x01);
155 EPD_5IN65F_SendData(0xC0);
156 EPD_5IN65F_SendCommand(0x10);
157 for(int i
=0; i
<EPD_5IN65F_WIDTH
/2; i
++) {
158 for(int j
=0; j
<EPD_5IN65F_HEIGHT
; j
++)
159 EPD_5IN65F_SendData((color
<<4)|color
);
161 EPD_5IN65F_SendCommand(0x04);//0x04
162 EPD_5IN65F_BusyHigh();
163 EPD_5IN65F_SendCommand(0x12);//0x12
164 EPD_5IN65F_BusyHigh();
165 EPD_5IN65F_SendCommand(0x02); //0x02
166 EPD_5IN65F_BusyLow();
170 /******************************************************************************
171 function : show 7 kind of color block
173 ******************************************************************************/
174 void EPD_5IN65F_Show7Block(void)
177 unsigned char const Color_seven
[8] =
178 {EPD_5IN65F_BLACK
,EPD_5IN65F_BLUE
,EPD_5IN65F_GREEN
,EPD_5IN65F_ORANGE
,
179 EPD_5IN65F_RED
,EPD_5IN65F_YELLOW
,EPD_5IN65F_WHITE
,EPD_5IN65F_WHITE
};
180 EPD_5IN65F_SendCommand(0x61);//Set Resolution setting
181 EPD_5IN65F_SendData(0x02);
182 EPD_5IN65F_SendData(0x58);
183 EPD_5IN65F_SendData(0x01);
184 EPD_5IN65F_SendData(0xC0);
185 EPD_5IN65F_SendCommand(0x10);
187 for(i
=0; i
<224; i
++) {
188 for(k
= 0 ; k
< 4; k
++) {
189 for(j
= 0 ; j
< 75; j
++) {
190 EPD_5IN65F_SendData((Color_seven
[k
]<<4) |Color_seven
[k
]);
194 for(i
=0; i
<224; i
++) {
195 for(k
= 4 ; k
< 8; k
++) {
196 for(j
= 0 ; j
< 75; j
++) {
197 EPD_5IN65F_SendData((Color_seven
[k
]<<4) |Color_seven
[k
]);
201 EPD_5IN65F_SendCommand(0x04);//0x04
202 EPD_5IN65F_BusyHigh();
203 EPD_5IN65F_SendCommand(0x12);//0x12
204 EPD_5IN65F_BusyHigh();
205 EPD_5IN65F_SendCommand(0x02); //0x02
206 EPD_5IN65F_BusyLow();
210 /******************************************************************************
211 function : Sends the image buffer in RAM to e-Paper and displays
213 ******************************************************************************/
214 void EPD_5IN65F_Display(const UBYTE
*image
, UBYTE
*Image2
)
217 EPD_5IN65F_SendCommand(0x61);//Set Resolution setting
218 EPD_5IN65F_SendData(0x02);
219 EPD_5IN65F_SendData(0x58);
220 EPD_5IN65F_SendData(0x01);
221 EPD_5IN65F_SendData(0xC0);
222 EPD_5IN65F_SendCommand(0x10);
223 for(i
=0; i
<EPD_5IN65F_HEIGHT
; i
++) {
224 for(j
=0; j
<EPD_5IN65F_WIDTH
/2; j
++)
225 EPD_5IN65F_SendData(image
[j
+((EPD_5IN65F_WIDTH
/2)*i
)]);
227 EPD_5IN65F_SendCommand(0x04);//0x04
228 EPD_5IN65F_BusyHigh();
229 EPD_5IN65F_SendCommand(0x12);//0x12
230 EPD_5IN65F_BusyHigh();
231 EPD_5IN65F_SendCommand(0x02); //0x02
232 EPD_5IN65F_BusyLow();
237 /******************************************************************************
238 function : Sends the part image buffer in RAM to e-Paper and displays
240 ******************************************************************************/
241 void EPD_5IN65F_Display_part(const UBYTE
*image
, UWORD xstart
, UWORD ystart
,
242 UWORD image_width
, UWORD image_heigh
)
245 EPD_5IN65F_SendCommand(0x61);//Set Resolution setting
246 EPD_5IN65F_SendData(0x02);
247 EPD_5IN65F_SendData(0x58);
248 EPD_5IN65F_SendData(0x01);
249 EPD_5IN65F_SendData(0xC0);
250 EPD_5IN65F_SendCommand(0x10);
251 for(i
=0; i
<EPD_5IN65F_HEIGHT
; i
++) {
252 for(j
=0; j
< EPD_5IN65F_WIDTH
/2; j
++) {
253 if(i
<image_heigh
+ystart
&& i
>=ystart
&& j
<(image_width
+xstart
)/2 && j
>=xstart
/2) {
254 EPD_5IN65F_SendData(image
[(j
-xstart
/2) + (image_width
/2*(i
-ystart
))]);
257 EPD_5IN65F_SendData(0x11);
261 EPD_5IN65F_SendCommand(0x04);//0x04
262 EPD_5IN65F_BusyHigh();
263 EPD_5IN65F_SendCommand(0x12);//0x12
264 EPD_5IN65F_BusyHigh();
265 EPD_5IN65F_SendCommand(0x02); //0x02
266 EPD_5IN65F_BusyLow();
271 /******************************************************************************
272 function : Enter sleep mode
274 ******************************************************************************/
275 void EPD_5IN65F_Sleep(void)
278 EPD_5IN65F_SendCommand(0x07);
279 EPD_5IN65F_SendData(0xA5);
281 DEV_Digital_Write(EPD_RST_PIN
, 0); // Reset