fix: 对不支持weak的bsp, luat_http_client_onevent报重复定义了
[LuatOS.git] / components / epaper / EPD_7in5_V2.c
bloba71f45c7469c8f3c56a0f52b8da3c7937898685b
1 /*****************************************************************************
2 * | File : EPD_7in5.c
3 * | Author : Waveshare team
4 * | Function : Electronic paper driver
5 * | Info :
6 *----------------
7 * | This version: V2.0
8 * | Date : 2018-11-09
9 * | Info :
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
28 # THE SOFTWARE.
30 ******************************************************************************/
31 #include "EPD_7in5_V2.h"
32 #include "Debug.h"
34 /******************************************************************************
35 function : Software reset
36 parameter:
37 ******************************************************************************/
38 static void EPD_Reset(void)
40 DEV_Digital_Write(EPD_RST_PIN, 1);
41 DEV_Delay_ms(200);
42 DEV_Digital_Write(EPD_RST_PIN, 0);
43 DEV_Delay_ms(2);
44 DEV_Digital_Write(EPD_RST_PIN, 1);
45 DEV_Delay_ms(200);
48 /******************************************************************************
49 function : send command
50 parameter:
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 /******************************************************************************
62 function : send data
63 parameter:
64 Data : Write data
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
76 parameter:
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;
84 // do{
85 // EPD_SendCommand(0x71);
86 // busy = DEV_Digital_Read(EPD_BUSY_PIN);
87 // busy =!(busy & 0x01);
88 // if(!(count--))
89 // {
90 // Debug("error: e-Paper busy timeout!!!\r\n");
91 // break;
92 // }
93 // else
94 // DEV_Delay_ms(100);
95 // }while(busy);
96 // DEV_Delay_ms(200);
97 // Debug("e-Paper busy release\r\n");
102 /******************************************************************************
103 function : Turn On Display
104 parameter:
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!!!
110 EPD_WaitUntilIdle();
113 /******************************************************************************
114 function : Initialize the e-Paper register
115 parameter:
116 ******************************************************************************/
117 UBYTE EPD_7IN5_V2_Init(UBYTE mode)
119 EPD_Reset();
121 EPD_SendCommand(0x01); //POWER SETTING
122 EPD_SendData(0x07);
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
128 DEV_Delay_ms(100);
129 EPD_WaitUntilIdle();
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
136 EPD_SendData(0x20);
137 EPD_SendData(0x01); //gate 480
138 EPD_SendData(0xE0);
140 EPD_SendCommand(0X15);
141 EPD_SendData(0x00);
143 EPD_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
144 EPD_SendData(0x10);
145 EPD_SendData(0x07);
147 EPD_SendCommand(0X60); //TCON SETTING
148 EPD_SendData(0x22);
150 return 0;
153 /******************************************************************************
154 function : Clear screen
155 parameter:
156 ******************************************************************************/
157 void EPD_7IN5_V2_Clear(void)
159 UWORD Width, Height;
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;
163 UWORD i;
164 EPD_SendCommand(0x10);
165 for(i=0; i<Height*Width; i++) {
166 EPD_SendData(0x00);
168 EPD_SendCommand(0x13);
169 for(i=0; i<Height*Width; i++) {
170 EPD_SendData(0x00);
172 EPD_7IN5_V2_TurnOnDisplay();
175 void EPD_7IN5_V2_ClearBlack(void)
177 UWORD Width, Height;
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;
181 UWORD i;
182 EPD_SendCommand(0x13);
183 for(i=0; i<Height*Width; i++) {
184 EPD_SendData(0xFF);
186 EPD_7IN5_V2_TurnOnDisplay();
189 /******************************************************************************
190 function : Sends the image buffer in RAM to e-Paper and displays
191 parameter:
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;
199 //send black data
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;
216 if(Block == 0){
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]);
224 if(Block == 1){
225 EPD_7IN5_V2_TurnOnDisplay();
229 /******************************************************************************
230 function : Enter sleep mode
231 parameter:
232 ******************************************************************************/
233 void EPD_7IN5_V2_Sleep(void)
235 EPD_SendCommand(0X02); //power off
236 EPD_WaitUntilIdle();
237 EPD_SendCommand(0X07); //deep sleep
238 EPD_SendData(0xA5);