1 /*****************************************************************************
2 * | File : EPD_4in2b_V2.c
3 * | Author : Waveshare team
4 * | Function : 4.2inch e-paper b V2
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_4in2b_V2.h"
34 /******************************************************************************
35 function : Software reset
37 ******************************************************************************/
38 static void EPD_4IN2B_V2_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_4IN2B_V2_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_4IN2B_V2_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 void EPD_4IN2B_V2_ReadBusy(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_4IN2B_V2_SendCommand(0x71);
86 // busy = DEV_Digital_Read(EPD_BUSY_PIN);
87 // busy =!(busy & 0x01);
90 // Debug("error: e-Paper busy timeout!!!\r\n");
96 // Debug("e-Paper busy release\r\n");
100 /******************************************************************************
101 function : Turn On Display
103 ******************************************************************************/
104 static void EPD_4IN2B_V2_TurnOnDisplay(void)
106 EPD_4IN2B_V2_SendCommand(0x12); // DISPLAY_REFRESH
108 EPD_4IN2B_V2_ReadBusy();
111 /******************************************************************************
112 function : Initialize the e-Paper register
114 ******************************************************************************/
115 void EPD_4IN2B_V2_Init(UBYTE mode
)
117 EPD_4IN2B_V2_Reset();
119 EPD_4IN2B_V2_SendCommand(0x04);
120 EPD_4IN2B_V2_ReadBusy();
122 EPD_4IN2B_V2_SendCommand(0x00);
123 EPD_4IN2B_V2_SendData(0x0f);
126 /******************************************************************************
127 function : Clear screen
129 ******************************************************************************/
130 void EPD_4IN2B_V2_Clear(void)
133 Width
= (EPD_4IN2B_V2_WIDTH
% 8 == 0)? (EPD_4IN2B_V2_WIDTH
/ 8 ): (EPD_4IN2B_V2_WIDTH
/ 8 + 1);
134 Height
= EPD_4IN2B_V2_HEIGHT
;
136 EPD_4IN2B_V2_SendCommand(0x10);
137 for (UWORD j
= 0; j
< Height
; j
++) {
138 for (UWORD i
= 0; i
< Width
; i
++) {
139 EPD_4IN2B_V2_SendData(0xFF);
143 EPD_4IN2B_V2_SendCommand(0x13);
144 for (UWORD j
= 0; j
< Height
; j
++) {
145 for (UWORD i
= 0; i
< Width
; i
++) {
146 EPD_4IN2B_V2_SendData(0xFF);
150 EPD_4IN2B_V2_TurnOnDisplay();
153 /******************************************************************************
154 function : Sends the image buffer in RAM to e-Paper and displays
156 ******************************************************************************/
157 void EPD_4IN2B_V2_Display(const UBYTE
*blackimage
, const UBYTE
*ryimage
)
160 Width
= (EPD_4IN2B_V2_WIDTH
% 8 == 0)? (EPD_4IN2B_V2_WIDTH
/ 8 ): (EPD_4IN2B_V2_WIDTH
/ 8 + 1);
161 Height
= EPD_4IN2B_V2_HEIGHT
;
163 EPD_4IN2B_V2_SendCommand(0x10);
164 for (UWORD j
= 0; j
< Height
; j
++) {
165 for (UWORD i
= 0; i
< Width
; i
++) {
166 EPD_4IN2B_V2_SendData(blackimage
[i
+ j
* Width
]);
170 EPD_4IN2B_V2_SendCommand(0x13);
171 for (UWORD j
= 0; j
< Height
; j
++) {
172 for (UWORD i
= 0; i
< Width
; i
++) {
173 EPD_4IN2B_V2_SendData(ryimage
[i
+ j
* Width
]);
177 EPD_4IN2B_V2_TurnOnDisplay();
180 /******************************************************************************
181 function : Enter sleep mode
183 ******************************************************************************/
184 void EPD_4IN2B_V2_Sleep(void)
186 EPD_4IN2B_V2_SendCommand(0X50);
187 EPD_4IN2B_V2_SendData(0xf7); //border floating
189 EPD_4IN2B_V2_SendCommand(0X02); //power off
190 EPD_4IN2B_V2_ReadBusy(); //waiting for the electronic paper IC to release the idle signal
191 EPD_4IN2B_V2_SendCommand(0X07); //deep sleep
192 EPD_4IN2B_V2_SendData(0xA5);