-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathepd7in3f.cpp
316 lines (269 loc) · 8.12 KB
/
epd7in3f.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*****************************************************************************
* | File : EPD_7in3f.c
* | Author : Waveshare team
* | Function : 7.3inch e-Paper (F)
* | Info :
*----------------
* | This version: V1.0
* | Date : 2022-10-21
* | Info :
* -----------------------------------------------------------------------------
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include <stdlib.h>
#include "epd7in3f.h"
Epd::~Epd() {
};
Epd::Epd() {
reset_pin = RST_PIN;
dc_pin = DC_PIN;
cs_pin = CS_PIN;
busy_pin = BUSY_PIN;
width = EPD_WIDTH;
height = EPD_HEIGHT;
};
/******************************************************************************
function : Initialize the e-Paper register
parameter:
******************************************************************************/
int Epd::Init(void) {
if (IfInit() != 0) {
return -1;
}
Reset();
DelayMs(20);
EPD_7IN3F_BusyHigh();
SendCommand(0xAA); // CMDH
SendData(0x49);
SendData(0x55);
SendData(0x20);
SendData(0x08);
SendData(0x09);
SendData(0x18);
SendCommand(0x01);
SendData(0x3F);
SendData(0x00);
SendData(0x32);
SendData(0x2A);
SendData(0x0E);
SendData(0x2A);
SendCommand(0x00);
SendData(0x5F);
SendData(0x69);
SendCommand(0x03);
SendData(0x00);
SendData(0x54);
SendData(0x00);
SendData(0x44);
SendCommand(0x05);
SendData(0x40);
SendData(0x1F);
SendData(0x1F);
SendData(0x2C);
SendCommand(0x06);
SendData(0x6F);
SendData(0x1F);
SendData(0x1F); // original 0x16
SendData(0x22); // original 0x25
SendCommand(0x08);
SendData(0x6F);
SendData(0x1F);
SendData(0x1F);
SendData(0x22);
SendCommand(0x13); // IPC
SendData(0x00);
SendData(0x04);
SendCommand(0x30);
SendData(0x3C); // original 0x02
SendCommand(0x41); // TSE
SendData(0x00);
SendCommand(0x50);
SendData(0x3F);
SendCommand(0x60);
SendData(0x02);
SendData(0x00);
SendCommand(0x61);
SendData(0x03);
SendData(0x20);
SendData(0x01);
SendData(0xE0);
SendCommand(0x82);
SendData(0x1E);
SendCommand(0x84);
SendData(0x00);
SendCommand(0x86); // AGID
SendData(0x00);
SendCommand(0xE3);
SendData(0x2F);
SendCommand(0xE0); // CCSET
SendData(0x00);
SendCommand(0xE6); // TSSET
SendData(0x00);
return 0;
}
/**
* @brief: basic function for sending commands
*/
void Epd::SendCommand(unsigned char command) {
DigitalWrite(dc_pin, LOW);
SpiTransfer(command);
}
/**
* @brief: basic function for sending data
*/
void Epd::SendData(unsigned char data) {
DigitalWrite(dc_pin, HIGH);
SpiTransfer(data);
}
void Epd::EPD_7IN3F_BusyHigh(void)// If BUSYN=0 then waiting
{
while(!DigitalRead(BUSY_PIN)) {
DelayMs(1);
}
}
/**
* @brief: module reset.
* often used to awaken the module in deep sleep,
* see Epd::Sleep();
*/
void Epd::Reset(void) {
DigitalWrite(reset_pin, HIGH);
DelayMs(20);
DigitalWrite(reset_pin, LOW); //module reset
DelayMs(1);
DigitalWrite(reset_pin, HIGH);
DelayMs(20);
}
void Epd::TurnOnDisplay(void) {
SendCommand(0x04); // POWER_ON
DelayMs(20);
EPD_7IN3F_BusyHigh();
SendCommand(0x12); // DISPLAY_REFRESH
SendData(0x00); // 0x01 acc. to datasheet, does grayscale?
DelayMs(100);
EPD_7IN3F_BusyHigh();
//DelayMs(30000); // IMPROPER, waiting for busy turns off the screen too late
SendCommand(0x02); // POWER_OFF
SendData(0x00);
EPD_7IN3F_BusyHigh();
}
/******************************************************************************
function : Sends the image buffer in RAM to e-Paper and displays
parameter:
******************************************************************************/
void Epd::EPD_7IN3F_Display(const UBYTE *image) {
unsigned long i,j;
SendCommand(0x10);
for(i=0; i<height; i++) {
for(j=0; j<width/2; j++) {
SendData(image[j + width*i]);
}
}
TurnOnDisplay();
}
/******************************************************************************
function : Sends the part image buffer in RAM to e-Paper and displays
parameter:
******************************************************************************/
void Epd::EPD_7IN3F_Display_part(const UBYTE *image, UWORD xstart, UWORD ystart,
UWORD image_width, UWORD image_heigh)
{
unsigned long i,j;
SendCommand(0x10);
for(i=0; i<height; i++) {
for(j=0; j< width/2; j++) {
if(i<image_heigh+ystart && i>=ystart && j<(image_width+xstart)/2 && j>=xstart/2) {
SendData(pgm_read_byte(&image[(j-xstart/2) + (image_width/2*(i-ystart))]));
}
else {
SendData(0x11);
}
}
}
TurnOnDisplay();
}
/******************************************************************************
function : show 7 kind of color block
parameter:
******************************************************************************/
void Epd::EPD_7IN3F_Show7Block(void)
{
unsigned long i, j, k;
unsigned char const Color_seven[8] =
{EPD_7IN3F_BLACK, EPD_7IN3F_BLUE, EPD_7IN3F_GREEN, EPD_7IN3F_ORANGE,
EPD_7IN3F_RED, EPD_7IN3F_YELLOW, EPD_7IN3F_WHITE, 0x7};
SendCommand(0x10);
for(i=0; i<240; i++) {
for(k = 0 ; k < 4; k ++) {
for(j = 0 ; j < 100; j ++) {
SendData((Color_seven[k]<<4) |Color_seven[k]);
}
}
}
for(i=0; i<240; i++) {
for(k = 4 ; k < 8; k ++) {
for(j = 0 ; j < 100; j ++) {
SendData((Color_seven[k]<<4) |Color_seven[k]);
}
}
}
TurnOnDisplay();
}
/******************************************************************************
function : Draw a block of solid pixels. Requires start code beforehand
parameter:
******************************************************************************/
void Epd::EPD_7IN3F_Draw_Blank(UWORD rows, UWORD cols, UBYTE color)
{
unsigned long i, j;
for(int i=0; i<cols/2; i++) {
for(int j=0; j<rows; j++) {
SendData((color<<4)|color);
}
}
}
/******************************************************************************
function :
Clear screen
******************************************************************************/
void Epd::Clear(UBYTE color) {
SendCommand(0x10);
for(int i=0; i<width/2; i++) {
for(int j=0; j<height; j++) {
SendData((color<<4)|color);
}
}
TurnOnDisplay();
}
/**
* @brief: After this command is transmitted, the chip would enter the
* deep-sleep mode to save power.
* The deep sleep mode would return to standby by hardware reset.
* The only one parameter is a check code, the command would be
* You can use EPD_Reset() to awaken
*/
void Epd::Sleep(void) {
SendCommand(0x07);
SendData(0xA5);
DelayMs(10);
DigitalWrite(RST_PIN, 0); // Reset
}
/* END OF FILE */