1 /*****************************************************************************
2 * | File : EPD_5IN83BC.c
3 * | Author : Waveshare team
4 * | Function : 5.83inch e-paper b&c
9 * -----------------------------------------------------------------------------
12 * EPD_Reset() => EPD_5IN83BC_Reset()
13 * EPD_SendCommand() => EPD_5IN83BC_SendCommand()
14 * EPD_SendData() => EPD_5IN83BC_SendData()
15 * EPD_WaitUntilIdle() => EPD_5IN83BC_ReadBusy()
16 * EPD_Init() => EPD_5IN83BC_Init()
17 * EPD_Clear() => EPD_5IN83BC_Clear()
18 * EPD_Display() => EPD_5IN83BC_Display()
19 * EPD_Sleep() => EPD_5IN83BC_Sleep()
21 * #define PANEL_SETTING 0x00
22 * #define POWER_SETTING 0x01
23 * #define POWER_OFF 0x02
24 * #define POWER_OFF_SEQUENCE_SETTING 0x03
25 * #define POWER_ON 0x04
26 * #define POWER_ON_MEASURE 0x05
27 * #define BOOSTER_SOFT_START 0x06
28 * #define DEEP_SLEEP 0x07
29 * #define DATA_START_TRANSMISSION_1 0x10
30 * #define DATA_STOP 0x11
31 * #define DISPLAY_REFRESH 0x12
32 * #define IMAGE_PROCESS 0x13
33 * #define LUT_FOR_VCOM 0x20
34 * #define LUT_BLUE 0x21
35 * #define LUT_WHITE 0x22
36 * #define LUT_GRAY_1 0x23
37 * #define LUT_GRAY_2 0x24
38 * #define LUT_RED_0 0x25
39 * #define LUT_RED_1 0x26
40 * #define LUT_RED_2 0x27
41 * #define LUT_RED_3 0x28
42 * #define LUT_XON 0x29
43 * #define PLL_CONTROL 0x30
44 * #define TEMPERATURE_SENSOR_COMMAND 0x40
45 * #define TEMPERATURE_CALIBRATION 0x41
46 * #define TEMPERATURE_SENSOR_WRITE 0x42
47 * #define TEMPERATURE_SENSOR_READ 0x43
48 * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50
49 * #define LOW_POWER_DETECTION 0x51
50 * #define TCON_SETTING 0x60
51 * #define TCON_RESOLUTION 0x61
52 * #define SPI_FLASH_CONTROL 0x65
53 * #define REVISION 0x70
54 * #define GET_STATUS 0x71
55 * #define AUTO_MEASUREMENT_VCOM 0x80
56 * #define READ_VCOM_VALUE 0x81
57 * #define VCM_DC_SETTING 0x82
59 * EPD_5IN83BC_DisplayHalfScreen()
60 * -----------------------------------------------------------------------------
62 * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8]
63 * 2.Change:EPD_Display(UBYTE *Image)
64 * Need to pass parameters: pointer to cached data
66 # Permission is hereby granted, free of charge, to any person obtaining a copy
67 # of this software and associated documnetation files (the "Software"), to deal
68 # in the Software without restriction, including without limitation the rights
69 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
70 # copies of the Software, and to permit persons to whom the Software is
71 # furished to do so, subject to the following conditions:
73 # The above copyright notice and this permission notice shall be included in
74 # all copies or substantial portions of the Software.
76 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
77 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
78 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
79 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
80 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
81 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
84 ******************************************************************************/
85 #include "EPD_5in83bc.h"
88 /******************************************************************************
89 function : Software reset
91 ******************************************************************************/
92 static void EPD_5IN83BC_Reset(void)
94 DEV_Digital_Write(EPD_RST_PIN
, 1);
96 DEV_Digital_Write(EPD_RST_PIN
, 0);
98 DEV_Digital_Write(EPD_RST_PIN
, 1);
102 /******************************************************************************
103 function : send command
105 Reg : Command register
106 ******************************************************************************/
107 static void EPD_5IN83BC_SendCommand(UBYTE Reg
)
109 DEV_Digital_Write(EPD_DC_PIN
, 0);
110 DEV_Digital_Write(EPD_CS_PIN
, 0);
111 DEV_SPI_WriteByte(Reg
);
112 DEV_Digital_Write(EPD_CS_PIN
, 1);
115 /******************************************************************************
119 ******************************************************************************/
120 static void EPD_5IN83BC_SendData(UBYTE Data
)
122 DEV_Digital_Write(EPD_DC_PIN
, 1);
123 DEV_Digital_Write(EPD_CS_PIN
, 0);
124 DEV_SPI_WriteByte(Data
);
125 DEV_Digital_Write(EPD_CS_PIN
, 1);
128 /******************************************************************************
129 function : Wait until the busy_pin goes LOW
131 ******************************************************************************/
132 void EPD_5IN83BC_ReadBusy(void)
134 EPD_Busy_WaitUntil(1,1);
135 // unsigned char count = 100;
137 // Debug("e-Paper busy\r\n");
139 // EPD_5IN83BC_SendCommand(0x71);
140 // busy = DEV_Digital_Read(EPD_BUSY_PIN);
141 // busy =!(busy & 0x01);
144 // Debug("error: e-Paper busy timeout!!!\r\n");
148 // DEV_Delay_ms(100);
150 // Debug("e-Paper busy release\r\n");
153 /******************************************************************************
154 function : Turn On Display
156 ******************************************************************************/
157 static void EPD_5IN83BC_TurnOnDisplay(void)
159 EPD_5IN83BC_SendCommand(0x04); // POWER ON
160 EPD_5IN83BC_ReadBusy();
161 EPD_5IN83BC_SendCommand(0x12); // display refresh
163 EPD_5IN83BC_ReadBusy();
167 /******************************************************************************
168 function : Initialize the e-Paper register
170 ******************************************************************************/
171 void EPD_5IN83BC_Init(UBYTE mode
)
175 EPD_5IN83BC_SendCommand(0x01); // POWER_SETTING
176 EPD_5IN83BC_SendData(0x37);
177 EPD_5IN83BC_SendData(0x00);
179 EPD_5IN83BC_SendCommand(0x00); // PANEL_SETTING
180 EPD_5IN83BC_SendData(0xCF);
181 EPD_5IN83BC_SendData(0x08);
183 EPD_5IN83BC_SendCommand(0x30); // PLL_CONTROL
184 EPD_5IN83BC_SendData(0x3A); //PLL: 0-15:0x3C, 15+:0x3A
186 EPD_5IN83BC_SendCommand(0x82); // VCM_DC_SETTING
187 EPD_5IN83BC_SendData(0x28); //all temperature range
189 EPD_5IN83BC_SendCommand(0x06); // BOOSTER_SOFT_START
190 EPD_5IN83BC_SendData (0xc7);
191 EPD_5IN83BC_SendData (0xcc);
192 EPD_5IN83BC_SendData (0x15);
194 EPD_5IN83BC_SendCommand(0x50); // VCOM AND DATA INTERVAL SETTING
195 EPD_5IN83BC_SendData(0x77);
197 EPD_5IN83BC_SendCommand(0x60); // TCON_SETTING
198 EPD_5IN83BC_SendData(0x22);
200 EPD_5IN83BC_SendCommand(0x65); // FLASH CONTROL
201 EPD_5IN83BC_SendData(0x00);
203 EPD_5IN83BC_SendCommand(0x61); // TCON_RESOLUTION
204 EPD_5IN83BC_SendData (0x02); // source 600
205 EPD_5IN83BC_SendData (0x58);
206 EPD_5IN83BC_SendData (0x01); // gate 448
207 EPD_5IN83BC_SendData (0xc0);
209 EPD_5IN83BC_SendCommand(0xe5); // FLASH MODE
210 EPD_5IN83BC_SendData(0x03);
214 /******************************************************************************
215 function : Clear screen
217 ******************************************************************************/
218 void EPD_5IN83BC_Clear(void)
221 Width
= (EPD_5IN83BC_WIDTH
% 8 == 0)? (EPD_5IN83BC_WIDTH
/ 8): (EPD_5IN83BC_WIDTH
/ 8 + 1);
222 Height
= EPD_5IN83BC_HEIGHT
;
224 EPD_5IN83BC_SendCommand(0x10);
225 for (UWORD j
= 0; j
< Height
; j
++) {
226 for (UWORD i
= 0; i
< Width
; i
++) {
227 for(UBYTE k
= 0; k
< 4; k
++) {
228 EPD_5IN83BC_SendData(0x33);
233 EPD_5IN83BC_TurnOnDisplay();
236 /******************************************************************************
237 function : Sends the image buffer in RAM to e-Paper and displays
239 ******************************************************************************/
240 void EPD_5IN83BC_Display(const UBYTE
*blackimage
, const UBYTE
*ryimage
)
242 UBYTE Data_Black
, Data_RY
, Data
;
243 UDOUBLE i
, j
, Width
, Height
;
244 Width
= (EPD_5IN83BC_WIDTH
% 8 == 0)? (EPD_5IN83BC_WIDTH
/ 8 ): (EPD_5IN83BC_WIDTH
/ 8 + 1);
245 Height
= EPD_5IN83BC_HEIGHT
;
247 EPD_5IN83BC_SendCommand(0x10);
248 for (j
= 0; j
< Height
; j
++) {
249 for (i
= 0; i
< Width
; i
++) {
250 Data_Black
= blackimage
[i
+ j
* Width
];
251 Data_RY
= ryimage
[i
+ j
* Width
]; // red or yellow
252 for(UBYTE k
= 0; k
< 8; k
++) {
253 if ((Data_RY
& 0x80) == 0x00) {
255 } else if ((Data_Black
& 0x80) == 0x00) {
260 Data
= (Data
<< 4) & 0xFF;
261 Data_Black
= (Data_Black
<< 1) & 0xFF;
262 Data_RY
= (Data_RY
<< 1) & 0xFF;
265 if((Data_RY
& 0x80) == 0x00) {
267 } else if ((Data_Black
& 0x80) == 0x00) {
268 Data
|= 0x00; //black
270 Data
|= 0x03; //white
272 Data_Black
= (Data_Black
<< 1) & 0xFF;
273 Data_RY
= (Data_RY
<< 1) & 0xFF;
274 EPD_5IN83BC_SendData(Data
);
279 EPD_5IN83BC_TurnOnDisplay();
282 /******************************************************************************
283 function : Sends the image buffer in RAM to e-Paper and displays
285 ******************************************************************************/
286 void EPD_5IN83BC_DisplayHalfScreen(const UBYTE
*blackimage
, const UBYTE
*ryimage
)
288 UBYTE Data_Black
, Data_RY
, Data
;
289 UDOUBLE i
, j
, Width
, Height
;
290 Width
= (EPD_5IN83BC_WIDTH
% 8 == 0)? (EPD_5IN83BC_WIDTH
/ 8 ): (EPD_5IN83BC_WIDTH
/ 8 + 1);
291 Height
= EPD_5IN83BC_HEIGHT
;
293 EPD_5IN83BC_SendCommand(0x10);
294 for (j
= 0; j
< Height
/ 2; j
++) {
295 for (i
= 0; i
< Width
; i
++) {
296 Data_Black
= blackimage
[i
+ j
* Width
];
297 Data_RY
= ryimage
[i
+ j
* Width
]; // red or yellow
298 for(UBYTE k
= 0; k
< 8; k
++) {
299 if ((Data_RY
& 0x80) == 0x00) {
301 } else if ((Data_Black
& 0x80) == 0x00) {
306 Data
= (Data
<< 4) & 0xFF;
307 Data_Black
= (Data_Black
<< 1) & 0xFF;
308 Data_RY
= (Data_RY
<< 1) & 0xFF;
311 if((Data_RY
& 0x80) == 0x00) {
313 } else if ((Data_Black
& 0x80) == 0x00) {
314 Data
|= 0x00; //black
316 Data
|= 0x03; //white
318 Data_Black
= (Data_Black
<< 1) & 0xFF;
319 Data_RY
= (Data_RY
<< 1) & 0xFF;
320 EPD_5IN83BC_SendData(Data
);
325 for (j
= 0; j
< Height
/ 2; j
++) {
326 for (i
= 0; i
< Width
; i
++) {
327 for(UBYTE k
= 0; k
< 4; k
++) {
328 EPD_5IN83BC_SendData(0x33);
333 EPD_5IN83BC_TurnOnDisplay();
336 /******************************************************************************
337 function : Enter sleep mode
339 ******************************************************************************/
340 void EPD_5IN83BC_Sleep(void)
342 EPD_5IN83BC_SendCommand(0x02); // POWER_OFF
343 EPD_5IN83BC_ReadBusy();
344 EPD_5IN83BC_SendCommand(0x07); // DEEP_SLEEP
345 EPD_5IN83BC_SendData(0XA5);