-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPL_smallLegio.cpp
201 lines (190 loc) · 6.09 KB
/
PL_smallLegio.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
/* *****************************************************************************************
PL_smallEPD - A library for 1.1”, 1.4", 2.1" and 3.1" E-Paper displays (EPDs) from
Plastic Logic based on UC8156 driver IC for Adafruit GFX core library. The communication is
SPI-based, for more information about hook-up please check: https://github.com/plasticlogic.
Created by Robert Poser, Mar 30th 2021, Dresden/Germany. Released under BSD license
(3-clause BSD license), check license.md for more information.
We invested time and resources providing this open source code, please support Plasticlogic
and open source hardware by purchasing this product @Plasticlogic
***************************************************************************************** */
#include "PL_smallLegio.h"
PL_smallLegio::PL_smallLegio(int8_t _cs, int8_t _rst, int8_t _busy) : PL_smallEPD(_cs, _rst, _busy) {
cs = _cs;
rst = _rst;
busy = _busy;
}
void PL_smallLegio::clearScreen(int8_t BGcolor) {
if (BGcolor>=0) {
setSourceVoltage(15000);
powerOn();
for (int i = 0; i < 3; i++) {
clear(EPD_WHITE);
setTPCOM(+12000);
updateLectum(EPD_UPD_FULL, true);
delay(1);
clear(EPD_BLACK);
setTPCOM(-18000);
updateLectum(EPD_UPD_FULL, true);
delay(1);
}
clear(EPD_BLACK); //BLACK
setTPCOM(-15000);
updateLectum(EPD_UPD_FULL, true);
delay(1);
clear(EPD_BLACK);
setTPCOM(-15000);
updateLectum(EPD_UPD_FULL, true);
delay(1);
if (BGcolor == EPD_WHITE) {
clear(EPD_WHITE);
updateLegio(EPD_BLACK);
}
clear(EPD_BLACK);
if (BGcolor == EPD_YELLOW)
updateLegio(EPD_YELLOW);
if (BGcolor == EPD_GREEN) {
updateLegio(EPD_YELLOW);
clear(EPD_BLACK);
updateLegio(EPD_GREEN);
}
if (BGcolor == EPD_RED)
updateLegio(EPD_RED);
if (BGcolor == EPD_BLUE) {
clear(EPD_WHITE);
updateLegio(EPD_BLACK);
clear(EPD_BLACK);
updateLegio(EPD_BLUE);
}
clear(EPD_WHITE);
powerOff();
}
}
void PL_smallLegio::loadImage(const unsigned char *pic_name, int BUFFER_COLOR_START) {
for (uint16_t j = 0; j < sizeof(buffer); j++)
buffer[j] = pgm_read_byte_near(pic_name + BUFFER_COLOR_START + j);
}
void PL_smallLegio::showImage(const unsigned char *pic_name) {
if ((byte)pic_name[3] & 0x80) {
loadImage(pic_name, BUFFER_BW_START);
updateLegio(EPD_BLACK);
}
if ((byte)pic_name[3] & 0x40) {
loadImage(pic_name, BUFFER_YELLOW_START);
updateLegio(EPD_YELLOW);
}
if ((byte)pic_name[3] & 0x20) {
loadImage(pic_name, BUFFER_GREEN_START);
updateLegio(EPD_GREEN);
}
if ((byte)pic_name[3] & 0x10) {
loadImage(pic_name, BUFFER_RED_START);
updateLegio(EPD_RED);
}
if ((byte)pic_name[3] & 0x08) {
loadImage(pic_name, BUFFER_BLUE_START);
updateLegio(EPD_BLUE);
}
}
void PL_smallLegio::setTPCOM(int v, bool VkbConsidered) {
if (v >= -2800)
writeRegister(0x1B, lowByte((v + 2800) / 30), highByte((v + 2800) / 30), -1, -1);
else
writeRegister(0x1B, lowByte((v + 2800) / 30 * (-1)), highByte((v + 2800) / 30 * (-1)) | 4, -1, -1);
}
void PL_smallLegio::setSourceVoltage(int v) {
v = round(v / 1000);
int x = (v - 8) / 1 * 2 << 4;
x = x | (v - 8) / 1 * 2;
writeRegister(EPD_DRIVERVOLTAGE, 0x25, x, -1, -1);
}
void PL_smallLegio::update(int updateMode, byte coovl, bool manPow) {
updateLegio(EPD_BLACK);
}
void PL_smallLegio::updateLegio(byte color) {
//powerOn();
switch (color) {
case EPD_BLACK: // BLACK & WHITE --> +13V/-13V
setTPCOM(0);
setSourceVoltage(13000);
/* invert();
for (int i=0; i<1; i++) {
clear(EPD_LGRAY, true);
writeToPreviousBuffer();
update(EPD_UPD_FULL);
delay(1);
}
invert();
*/
for (int i = 0; i < 3; i++) {
clear(EPD_LGRAY, true);
writeToPreviousBuffer();
updateLectum(EPD_UPD_FULL);
delay(1);
}
break;
case EPD_YELLOW: // YELLOW --> 0V/+30V
setTPCOM(15000);
setSourceVoltage(15000);
for (int i = 0; i < 3; i++) {
clear(EPD_LGRAY, true);
writeToPreviousBuffer();
invert();
updateLectum(EPD_UPD_FULL);
invert();
}
break;
case EPD_GREEN: // GREEN --> +11V/-11V
setTPCOM(0);
setSourceVoltage(12000);
clear(EPD_WHITE, true);
writeToPreviousBuffer();
updateLectum(EPD_UPD_FULL);
delay(1);
break;
case EPD_RED: // RED
setSourceVoltage(10000);
for (int i = 0; i < 2; i++) {
clear(EPD_LGRAY, true);
writeToPreviousBuffer();
invert();
setTPCOM(10000);
updateLectum(EPD_UPD_MONO);
invert();
delay(10);
clear(EPD_LGRAY, true);
writeToPreviousBuffer();
setTPCOM(-10000);
updateLectum(EPD_UPD_MONO);
delay(10);
}
break;
case EPD_BLUE:
for (int i = 0; i < 2; i++) {
clear(EPD_LGRAY, true);
writeToPreviousBuffer();
setTPCOM(-12000);
setSourceVoltage(12000);
updateLectum(EPD_UPD_MONO);
delay(1);
clear(EPD_LGRAY, true);
invert();
writeToPreviousBuffer();
setTPCOM(12000);
setSourceVoltage(12000);
updateLectum(EPD_UPD_MONO);
invert();
delay(1);
}
setSourceVoltage(12000);
setTPCOM(-12000);
for (int i = 0; i < 2; i++) {
clear(EPD_LGRAY, true);
writeToPreviousBuffer();
updateLectum(EPD_UPD_MONO);
delay(1);
}
break;
}
//powerOff();
delay(1);
}