fix: 对不支持weak的bsp, luat_http_client_onevent报重复定义了
[LuatOS.git] / components / epaper / EPD_4in2b_V2.c
blobb25f9227c5a7a0107e24d91efc12aeb77c67d0e2
1 /*****************************************************************************
2 * | File : EPD_4in2b_V2.c
3 * | Author : Waveshare team
4 * | Function : 4.2inch e-paper b V2
5 * | Info :
6 *----------------
7 * | This version: V1.0
8 * | Date : 2020-11-25
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_4in2b_V2.h"
32 #include "Debug.h"
34 /******************************************************************************
35 function : Software reset
36 parameter:
37 ******************************************************************************/
38 static void EPD_4IN2B_V2_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(5);
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_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 /******************************************************************************
62 function : send data
63 parameter:
64 Data : Write data
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
76 parameter:
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;
84 // do{
85 // EPD_4IN2B_V2_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 // Debug("e-Paper busy release\r\n");
97 // DEV_Delay_ms(200);
100 /******************************************************************************
101 function : Turn On Display
102 parameter:
103 ******************************************************************************/
104 static void EPD_4IN2B_V2_TurnOnDisplay(void)
106 EPD_4IN2B_V2_SendCommand(0x12); // DISPLAY_REFRESH
107 DEV_Delay_ms(100);
108 EPD_4IN2B_V2_ReadBusy();
111 /******************************************************************************
112 function : Initialize the e-Paper register
113 parameter:
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
128 parameter:
129 ******************************************************************************/
130 void EPD_4IN2B_V2_Clear(void)
132 UWORD Width, Height;
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
155 parameter:
156 ******************************************************************************/
157 void EPD_4IN2B_V2_Display(const UBYTE *blackimage, const UBYTE *ryimage)
159 UWORD Width, Height;
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
182 parameter:
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);