fix: 对不支持weak的bsp, luat_http_client_onevent报重复定义了
[LuatOS.git] / components / epaper / EPD_1in54_V2.c
blobcfb61b53e015b9ad1f32907e43013cd263c98eb1
1 /*****************************************************************************
2 * | File : EPD_1in54_V2.c
3 * | Author : Waveshare team
4 * | Function : 1.54inch e-paper V2
5 * | Info :
6 *----------------
7 * | This version: V1.0
8 * | Date : 2019-06-11
9 * | Info :
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
27 # THE SOFTWARE.
29 ******************************************************************************/
30 #include "EPD_1in54_V2.h"
31 #include "Debug.h"
33 /******************************************************************************
34 function : Software reset
35 parameter:
36 ******************************************************************************/
37 static void EPD_1IN54_V2_Reset(void)
39 DEV_Digital_Write(EPD_RST_PIN, 1);
40 DEV_Delay_ms(200);
41 DEV_Digital_Write(EPD_RST_PIN, 0);
42 DEV_Delay_ms(2);
43 DEV_Digital_Write(EPD_RST_PIN, 1);
44 DEV_Delay_ms(200);
47 /******************************************************************************
48 function : send command
49 parameter:
50 Reg : Command register
51 ******************************************************************************/
52 static void EPD_1IN54_V2_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 /******************************************************************************
61 function : send data
62 parameter:
63 Data : Write data
64 ******************************************************************************/
65 static void EPD_1IN54_V2_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);
73 /******************************************************************************
74 function : Wait until the busy_pin goes LOW
75 parameter:
76 ******************************************************************************/
77 static void EPD_1IN54_V2_ReadBusy(void)
79 EPD_Busy_WaitUntil(0,0);
81 // unsigned char count = 100;
82 // Debug("e-Paper busy\r\n");
83 // // UBYTE busy;
84 // // do {
85 // // EPD_1IN54_V2_SendCommand(0x71);
86 // // busy = DEV_Digital_Read(EPD_BUSY_PIN);
87 // // busy = !(busy & 0x01);
88 // // } while(busy);
89 // // DEV_Delay_ms(200);
90 // while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
91 // if(!(count--))
92 // {
93 // Debug("error: e-Paper busy timeout!!!\r\n");
94 // break;
95 // }
96 // else
97 // DEV_Delay_ms(100);
98 // }
99 // Debug("e-Paper busy release\r\n");
102 /******************************************************************************
103 function : Turn On Display full
104 parameter:
105 ******************************************************************************/
106 static void EPD_1IN54_V2_TurnOnDisplay(void)
108 EPD_1IN54_V2_SendCommand(0x22);
109 EPD_1IN54_V2_SendData(0xF7);
110 EPD_1IN54_V2_SendCommand(0x20);
111 EPD_1IN54_V2_ReadBusy();
114 /******************************************************************************
115 function : Turn On Display part
116 parameter:
117 ******************************************************************************/
118 static void EPD_1IN54_V2_TurnOnDisplayPart(void)
120 EPD_1IN54_V2_SendCommand(0x22);
121 EPD_1IN54_V2_SendData(0xFF);
122 EPD_1IN54_V2_SendCommand(0x20);
123 EPD_1IN54_V2_ReadBusy();
126 /******************************************************************************
127 function : Initialize the e-Paper register
128 parameter:
129 ******************************************************************************/
130 void EPD_1IN54_V2_Init(UBYTE mode)
132 EPD_1IN54_V2_Reset();
134 EPD_1IN54_V2_ReadBusy();
135 EPD_1IN54_V2_SendCommand(0x12); //SWRESET
136 EPD_1IN54_V2_ReadBusy();
138 EPD_1IN54_V2_SendCommand(0x01); //Driver output control
139 EPD_1IN54_V2_SendData(0xC7);
140 EPD_1IN54_V2_SendData(0x00);
141 EPD_1IN54_V2_SendData(0x01);
143 EPD_1IN54_V2_SendCommand(0x11); //data entry mode
144 EPD_1IN54_V2_SendData(0x01);
146 EPD_1IN54_V2_SendCommand(0x44); //set Ram-X address start/end position
147 EPD_1IN54_V2_SendData(0x00);
148 EPD_1IN54_V2_SendData(0x18); //0x0C-->(18+1)*8=200
150 EPD_1IN54_V2_SendCommand(0x45); //set Ram-Y address start/end position
151 EPD_1IN54_V2_SendData(0xC7); //0xC7-->(199+1)=200
152 EPD_1IN54_V2_SendData(0x00);
153 EPD_1IN54_V2_SendData(0x00);
154 EPD_1IN54_V2_SendData(0x00);
156 EPD_1IN54_V2_SendCommand(0x3C); //BorderWavefrom
157 EPD_1IN54_V2_SendData(0x01);
159 EPD_1IN54_V2_SendCommand(0x18);
160 EPD_1IN54_V2_SendData(0x80);
162 EPD_1IN54_V2_SendCommand(0x22); // //Load Temperature and waveform setting.
163 EPD_1IN54_V2_SendData(0XB1);
164 EPD_1IN54_V2_SendCommand(0x20);
166 EPD_1IN54_V2_SendCommand(0x4E); // set RAM x address count to 0;
167 EPD_1IN54_V2_SendData(0x00);
168 EPD_1IN54_V2_SendCommand(0x4F); // set RAM y address count to 0X199;
169 EPD_1IN54_V2_SendData(0xC7);
170 EPD_1IN54_V2_SendData(0x00);
171 EPD_1IN54_V2_ReadBusy();
174 /******************************************************************************
175 function : Clear screen
176 parameter:
177 ******************************************************************************/
178 void EPD_1IN54_V2_Clear(void)
180 UWORD Width, Height;
181 Width = (EPD_1IN54_V2_WIDTH % 8 == 0)? (EPD_1IN54_V2_WIDTH / 8 ): (EPD_1IN54_V2_WIDTH / 8 + 1);
182 Height = EPD_1IN54_V2_HEIGHT;
184 EPD_1IN54_V2_SendCommand(0x24);
185 for (UWORD j = 0; j < Height; j++) {
186 for (UWORD i = 0; i < Width; i++) {
187 EPD_1IN54_V2_SendData(0XFF);
190 EPD_1IN54_V2_TurnOnDisplay();
193 /******************************************************************************
194 function : Sends the image buffer in RAM to e-Paper and displays
195 parameter:
196 ******************************************************************************/
197 void EPD_1IN54_V2_Display(UBYTE *Image, UBYTE *Image2)
199 UWORD Width, Height;
200 Width = (EPD_1IN54_V2_WIDTH % 8 == 0)? (EPD_1IN54_V2_WIDTH / 8 ): (EPD_1IN54_V2_WIDTH / 8 + 1);
201 Height = EPD_1IN54_V2_HEIGHT;
203 UDOUBLE Addr = 0;
204 EPD_1IN54_V2_SendCommand(0x24);
205 for (UWORD j = 0; j < Height; j++) {
206 for (UWORD i = 0; i < Width; i++) {
207 Addr = i + j * Width;
208 EPD_1IN54_V2_SendData(Image[Addr]);
211 EPD_1IN54_V2_TurnOnDisplay();
214 /******************************************************************************
215 function : The image of the previous frame must be uploaded, otherwise the
216 first few seconds will display an exception.
217 parameter:
218 ******************************************************************************/
219 void EPD_1IN54_V2_DisplayPartBaseImage(UBYTE *Image)
221 UWORD Width, Height;
222 Width = (EPD_1IN54_V2_WIDTH % 8 == 0)? (EPD_1IN54_V2_WIDTH / 8 ): (EPD_1IN54_V2_WIDTH / 8 + 1);
223 Height = EPD_1IN54_V2_HEIGHT;
225 UDOUBLE Addr = 0;
226 EPD_1IN54_V2_SendCommand(0x24);
227 for (UWORD j = 0; j < Height; j++) {
228 for (UWORD i = 0; i < Width; i++) {
229 Addr = i + j * Width;
230 EPD_1IN54_V2_SendData(Image[Addr]);
233 EPD_1IN54_V2_SendCommand(0x26);
234 for (UWORD j = 0; j < Height; j++) {
235 for (UWORD i = 0; i < Width; i++) {
236 Addr = i + j * Width;
237 EPD_1IN54_V2_SendData(Image[Addr]);
240 EPD_1IN54_V2_TurnOnDisplayPart();
243 /******************************************************************************
244 function : Sends the image buffer in RAM to e-Paper and displays
245 parameter:
246 ******************************************************************************/
247 void EPD_1IN54_V2_DisplayPart(UBYTE *Image)
249 UWORD Width, Height;
250 Width = (EPD_1IN54_V2_WIDTH % 8 == 0)? (EPD_1IN54_V2_WIDTH / 8 ): (EPD_1IN54_V2_WIDTH / 8 + 1);
251 Height = EPD_1IN54_V2_HEIGHT;
253 DEV_Digital_Write(EPD_RST_PIN, 0);
254 DEV_Delay_ms(10);
255 DEV_Digital_Write(EPD_RST_PIN, 1);
256 DEV_Delay_ms(10);
257 EPD_1IN54_V2_SendCommand(0x3C); //BorderWavefrom
258 EPD_1IN54_V2_SendData(0x80);
260 UDOUBLE Addr = 0;
261 EPD_1IN54_V2_SendCommand(0x24);
262 for (UWORD j = 0; j < Height; j++) {
263 for (UWORD i = 0; i < Width; i++) {
264 Addr = i + j * Width;
265 EPD_1IN54_V2_SendData(Image[Addr]);
268 EPD_1IN54_V2_TurnOnDisplayPart();
270 /******************************************************************************
271 function : Enter sleep mode
272 parameter:
273 ******************************************************************************/
274 void EPD_1IN54_V2_Sleep(void)
276 EPD_1IN54_V2_SendCommand(0x10); //enter deep sleep
277 EPD_1IN54_V2_SendData(0x01);
278 DEV_Delay_ms(100);