-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaveshare-demo-epd42.h
356 lines (300 loc) · 11.1 KB
/
waveshare-demo-epd42.h
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/**
******************************************************************************
@file epd.h and edp4in2.h
@author Waveshare Team
@version V1.0.0
@date 23-January-2018
@brief This file provides e-Paper driver functions and initialisation of 4.2 and 4.2b e-Papers
void EPD_SendCommand(byte command);
void EPD_SendData(byte data);
void EPD_WaitUntilIdle();
void EPD_Send_1(byte c, byte v1);
void EPD_Send_2(byte c, byte v1, byte v2);
void EPD_Send_3(byte c, byte v1, byte v2, byte v3);
void EPD_Send_4(byte c, byte v1, byte v2, byte v3, byte v4);
void EPD_Send_5(byte c, byte v1, byte v2, byte v3, byte v4, byte v5);
void EPD_Reset();
void EPD_dispInit();
varualbes:
EPD_dispLoad; - pointer on current loading function
EPD_dispIndex; - index of current e-Paper
EPD_dispInfo EPD_dispMass[]; - array of e-Paper properties
******************************************************************************
*/
#include <SPI.h>
extern ESP8266WebServer server;
/* SPI pin definition --------------------------------------------------------*/
// SPI pin definition
#define CS_PIN 15
#define RST_PIN 5
#define DC_PIN 4
#define BUSY_PIN 16
#define GPIO_PIN_SET 1
#define GPIO_PIN_RESET 0
/* The procedure of sending a byte to e-Paper by SPI -------------------------*/
void EpdSpiTransferCallback(byte data)
{
digitalWrite(CS_PIN, GPIO_PIN_RESET);
SPI.transfer(data);
digitalWrite(CS_PIN, GPIO_PIN_SET);
}
/* Sending a byte as a command -----------------------------------------------*/
void EPD_SendCommand(byte command)
{
digitalWrite(DC_PIN, LOW);
EpdSpiTransferCallback(command);
}
/* Sending a byte as a data --------------------------------------------------*/
void EPD_SendData(byte data)
{
digitalWrite(DC_PIN, HIGH);
EpdSpiTransferCallback(data);
}
/* Waiting the e-Paper is ready for further instructions ---------------------*/
void EPD_WaitUntilIdle()
{
//0: busy, 1: idle
while (digitalRead(BUSY_PIN) == 0) delay(100);
}
/* Send a one-argument command -----------------------------------------------*/
void EPD_Send_1(byte c, byte v1)
{
EPD_SendCommand(c);
EPD_SendData(v1);
}
/* Send a two-arguments command ----------------------------------------------*/
void EPD_Send_2(byte c, byte v1, byte v2)
{
EPD_SendCommand(c);
EPD_SendData(v1);
EPD_SendData(v2);
}
/* Send a three-arguments command --------------------------------------------*/
void EPD_Send_3(byte c, byte v1, byte v2, byte v3)
{
EPD_SendCommand(c);
EPD_SendData(v1);
EPD_SendData(v2);
EPD_SendData(v3);
}
/* Send a four-arguments command ---------------------------------------------*/
void EPD_Send_4(byte c, byte v1, byte v2, byte v3, byte v4)
{
EPD_SendCommand(c);
EPD_SendData(v1);
EPD_SendData(v2);
EPD_SendData(v3);
EPD_SendData(v4);
}
/* Send a five-arguments command ---------------------------------------------*/
void EPD_Send_5(byte c, byte v1, byte v2, byte v3, byte v4, byte v5)
{
EPD_SendCommand(c);
EPD_SendData(v1);
EPD_SendData(v2);
EPD_SendData(v3);
EPD_SendData(v4);
EPD_SendData(v5);
}
/* Writting lut-data into the e-Paper ----------------------------------------*/
void EPD_lut(byte c, byte l, byte*p)
{
// lut-data writting initialization
EPD_SendCommand(c);
// lut-data writting doing
for (int i = 0; i < l; i++, p++) EPD_SendData(*p);
}
/* This function is used to 'wake up" the e-Paper from the deep sleep mode ---*/
void EPD_Reset()
{
digitalWrite(RST_PIN, LOW);
delay(200);
digitalWrite(RST_PIN, HIGH);
delay(200);
}
int EPD_dispIndex; // The index of the e-Paper's type
int EPD_dispX, EPD_dispY; // Current pixel's coordinates (for 2.13 only)
void(*EPD_dispLoad)(); // Pointer on a image data writting function
/* Image data loading function for a-type e-Paper ----------------------------*/
void EPD_loadA()
{
int index = 0;
String p = server.arg(0);
// Get the length of the image data begin
int DataLength = p.length() - 8;
// Enumerate all of image data bytes
while (index < DataLength)
{
// Get current byte
int value = ((int)p[index] - 'a') + (((int)p[index + 1] - 'a') << 4);
// Write the byte into e-Paper's memory
EPD_SendData((byte)value);
// Increment the current byte index on 2 characters
index += 2;
}
}
/* Show image and turn to deep sleep mode (a-type, 4.2 and 2.7 e-Paper) ------*/
void EPD_showA()
{
// Refresh
EPD_Send_1(0x22, 0xC4);//DISPLAY_UPDATE_CONTROL_2
EPD_SendCommand(0x20);//MASTER_ACTIVATION
EPD_SendCommand(0xFF);//TERMINATE_FRAME_READ_WRITE
EPD_WaitUntilIdle();
// Sleep
EPD_SendCommand(0x10);//DEEP_SLEEP_MODE
EPD_WaitUntilIdle();
}
/* Show image and turn to deep sleep mode (b-type, e-Paper) ------------------*/
void EPD_showB()
{
// Refresh
EPD_SendCommand(0x12);//DISPLAY_REFRESH
delay(100);
EPD_WaitUntilIdle();
// Sleep
EPD_Send_1(0x50, 0x17);//VCOM_AND_DATA_INTERVAL_SETTING
EPD_Send_1(0x82, 0x00);//VCM_DC_SETTING_REGISTER, to solve Vcom drop
EPD_Send_4(0x01, 0x02, 0x00, 0x00, 0x00);//POWER_SETTING
EPD_WaitUntilIdle();
EPD_SendCommand(0x02);//POWER_OFF
}
/* The set of pointers on 'init', 'load' and 'show' functions, title and code */
struct EPD_dispInfo
{
int(*init)(); // Initialization
void(*chBk)();// Black channel loading
int next; // Change channel code
void(*chRd)();// Red channel loading
void(*show)();// Show and sleep
char*title; // Title of an e-Paper
};
unsigned char lut_dc_4in2[] =
{
0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x17, 0x17, 0x00, 0x00,
0x02, 0x00, 0x0A, 0x01, 0x00, 0x00, 0x01, 0x00, 0x0E, 0x0E, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
//R21H
unsigned char lut_ww_4in2[] =
{
0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x40, 0x0A,
0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
//R22H r
unsigned char lut_bw_4in2[] =
{
0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x40, 0x0A,
0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
//R24H b
unsigned char lut_bb_4in2[] =
{
0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x80, 0x0A,
0x01, 0x00, 0x00, 0x01, 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
//R23H w
unsigned char lut_wb_4in2[] =
{
0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x80, 0x0A,
0x01, 0x00, 0x00, 0x01, 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int EPD_Init_4in2()
{
EPD_Reset();
EPD_SendCommand(0x01);//POWER_SETTING
EPD_SendData(0x03); // VDS_EN, VDG_EN
EPD_SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
EPD_SendData(0x2F); // VDH
EPD_SendData(0x2F); // VDL
EPD_SendData(0xFF); // VDHR
EPD_Send_3(0x06, 0x17, 0x17, 0x17);//BOOSTER_SOFT_START
EPD_SendCommand(0x04);//POWER_ON
EPD_WaitUntilIdle();
EPD_Send_2(0x00, 0xBF, 0x0B);//PANEL_SETTING: // KW-BF KWR-AF BWROTP 0f
EPD_Send_1(0x30, 0x3C);//PLL_CONTROL: 3A 100HZ, 29 150Hz, 39 200HZ, 31 171HZ
EPD_Send_4(0x61, 1, 144, 1, 44);// RESOLUTION_SETTING: HI(W), LO(W), HI(H), LO(H)
EPD_Send_1(0x82, 0x12);// VCM_DC_SETTING
EPD_Send_1(0x50, 0x97);// VCOM_AND_DATA_INTERVAL_SETTING: VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
EPD_lut(0x20,44,&lut_dc_4in2[0]);// LUT_FOR_VCOM
EPD_lut(0x21,42,&lut_ww_4in2[0]);// LUT_WHITE_TO_WHITE
EPD_lut(0x22,42,&lut_bw_4in2[0]);// LUT_BLACK_TO_WHITE
EPD_lut(0x23,42,&lut_wb_4in2[0]);// LUT_WHITE_TO_BLACK
EPD_lut(0x24,42,&lut_bb_4in2[0]);// LUT_BLACK_TO_BLACK
EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1
delay(2);
for(int i = 0; i < 400*300; i++)EPD_SendData(0xFF);//Red channel
EPD_SendCommand(0x13);//DATA_START_TRANSMISSION_2
delay(2);
return 0;
}
unsigned char lut_dc_4in2b[] =
{
0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x17, 0x17, 0x00, 0x00,
0x02, 0x00, 0x0A, 0x01, 0x00, 0x00, 0x01, 0x00, 0x0E, 0x0E, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
//R21H
unsigned char lut_ww_4in2b[] =
{
0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x40, 0x0A,
0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
//R22H r
unsigned char lut_bw_4in2b[] =
{
0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x40, 0x0A,
0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
//R24H b
unsigned char lut_bb_4in2b[] =
{
0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x80, 0x0A,
0x01, 0x00, 0x00, 0x01, 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
//R23H w
unsigned char lut_wb_4in2b[] =
{
0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x80, 0x0A,
0x01, 0x00, 0x00, 0x01, 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int EPD_Init_4in2b()
{
EPD_Reset();
EPD_Send_3(0x06,0x17,0x17,0x17);//BOOSTER_SOFT_START
EPD_SendCommand(0x04);//POWER_ON
EPD_WaitUntilIdle();
EPD_Send_1(0x00, 0x0F);//PANEL_SETTING
EPD_Send_1(0x50,0xF7);// VCOM_AND_DATA_INTERVAL_SETTING
EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1
delay(2);
return 0;
}
/* Array of sets describing the usage of e-Papers ----------------------------*/
EPD_dispInfo EPD_dispMass[] =
{
{ EPD_Init_4in2 , EPD_loadA, -1 , 0, EPD_showB, "4.2 inch" },// m 12 // IS THIS A TYPO IN THE ORIGINAL SOURCE? SHOULD IT BE EPD_showA??
{ EPD_Init_4in2b , EPD_loadA, 0x13, EPD_loadA, EPD_showB, "4.2 inch b" },// n 13
{ EPD_Init_4in2b , EPD_loadA, 0x13, EPD_loadA, EPD_showB, "4.2 inch c" },// o 14
};
/* Initialization of an e-Paper ----------------------------------------------*/
void EPD_dispInit()
{
// Call initialization function
EPD_dispMass[EPD_dispIndex].init();
// Set loading function for black channel
EPD_dispLoad = EPD_dispMass[EPD_dispIndex].chBk;
// Set initial coordinates
EPD_dispX = 0;
EPD_dispY = 0;
}