Skip to content

Commit 2de44e5

Browse files
authored
Merge pull request #2037 from weebl2000/fix-heltec-E213-E290-eink
Fix Heltec E213 and E290 e-ink board builds
2 parents ba71820 + 0e62240 commit 2de44e5

10 files changed

Lines changed: 142 additions & 37 deletions

File tree

src/helpers/ui/E213Display.cpp

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,44 +59,58 @@ bool E213Display::begin() {
5959
}
6060

6161
void E213Display::powerOn() {
62+
if (_periph_power) {
63+
_periph_power->claim();
64+
} else {
6265
#ifdef PIN_VEXT_EN
63-
pinMode(PIN_VEXT_EN, OUTPUT);
66+
pinMode(PIN_VEXT_EN, OUTPUT);
6467
#ifdef PIN_VEXT_EN_ACTIVE
65-
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
68+
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
6669
#else
67-
digitalWrite(PIN_VEXT_EN, LOW); // Active low
70+
digitalWrite(PIN_VEXT_EN, LOW); // Active low
6871
#endif
69-
delay(50); // Allow power to stabilize
7072
#endif
73+
}
74+
delay(50); // Allow power to stabilize
7175
}
7276

7377
void E213Display::powerOff() {
78+
if (_periph_power) {
79+
_periph_power->release();
80+
} else {
7481
#ifdef PIN_VEXT_EN
7582
#ifdef PIN_VEXT_EN_ACTIVE
76-
digitalWrite(PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE);
83+
digitalWrite(PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE);
7784
#else
78-
digitalWrite(PIN_VEXT_EN, HIGH); // Turn off power
85+
digitalWrite(PIN_VEXT_EN, HIGH); // Turn off power
7986
#endif
8087
#endif
88+
}
8189
}
8290

8391
void E213Display::turnOn() {
8492
if (!_init) begin();
85-
powerOn();
93+
else if (!_isOn) {
94+
powerOn();
95+
display->fastmodeOn(); // Reinitialize display controller after power was cut
96+
}
8697
_isOn = true;
8798
}
8899

89100
void E213Display::turnOff() {
90-
powerOff();
91-
_isOn = false;
101+
if (_isOn) {
102+
powerOff();
103+
_isOn = false;
104+
}
92105
}
93106

94107
void E213Display::clear() {
95108
display->clear();
96-
97109
}
98110

99111
void E213Display::startFrame(Color bkg) {
112+
display_crc.reset();
113+
100114
// Fill screen with white first to ensure clean background
101115
display->fillRect(0, 0, width(), height(), WHITE);
102116

@@ -107,31 +121,50 @@ void E213Display::startFrame(Color bkg) {
107121
}
108122

109123
void E213Display::setTextSize(int sz) {
124+
display_crc.update<int>(sz);
110125
// The library handles text size internally
111126
display->setTextSize(sz);
112127
}
113128

114129
void E213Display::setColor(Color c) {
130+
display_crc.update<Color>(c);
115131
// implemented in individual display methods
116132
}
117133

118134
void E213Display::setCursor(int x, int y) {
135+
display_crc.update<int>(x);
136+
display_crc.update<int>(y);
119137
display->setCursor(x, y);
120138
}
121139

122140
void E213Display::print(const char *str) {
141+
display_crc.update<char>(str, strlen(str));
123142
display->print(str);
124143
}
125144

126145
void E213Display::fillRect(int x, int y, int w, int h) {
146+
display_crc.update<int>(x);
147+
display_crc.update<int>(y);
148+
display_crc.update<int>(w);
149+
display_crc.update<int>(h);
127150
display->fillRect(x, y, w, h, BLACK);
128151
}
129152

130153
void E213Display::drawRect(int x, int y, int w, int h) {
154+
display_crc.update<int>(x);
155+
display_crc.update<int>(y);
156+
display_crc.update<int>(w);
157+
display_crc.update<int>(h);
131158
display->drawRect(x, y, w, h, BLACK);
132159
}
133160

134161
void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
162+
display_crc.update<int>(x);
163+
display_crc.update<int>(y);
164+
display_crc.update<int>(w);
165+
display_crc.update<int>(h);
166+
display_crc.update<uint8_t>(bits, w * h / 8);
167+
135168
// Width in bytes for bitmap processing
136169
uint16_t widthInBytes = (w + 7) / 8;
137170

@@ -160,5 +193,9 @@ uint16_t E213Display::getTextWidth(const char *str) {
160193
}
161194

162195
void E213Display::endFrame() {
196+
uint32_t crc = display_crc.finalize();
197+
if (crc != last_display_crc_value) {
163198
display->update();
199+
last_display_crc_value = crc;
200+
}
164201
}

src/helpers/ui/E213Display.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
#include <SPI.h>
66
#include <Wire.h>
77
#include <heltec-eink-modules.h>
8+
#include <CRC32.h>
9+
#include <helpers/RefCountedDigitalPin.h>
810

911
// Display driver for E213 e-ink display
1012
class E213Display : public DisplayDriver {
1113
BaseDisplay* display=NULL;
1214
bool _init = false;
1315
bool _isOn = false;
16+
RefCountedDigitalPin* _periph_power;
17+
CRC32 display_crc;
18+
uint32_t last_display_crc_value = 0;
1419

1520
public:
16-
E213Display() : DisplayDriver(250, 122) {}
21+
E213Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(250, 122), _periph_power(periph_power) {}
1722
~E213Display(){
1823
if(display!=NULL) {
1924
delete display;
@@ -39,4 +44,4 @@ class E213Display : public DisplayDriver {
3944
BaseDisplay* detectEInk();
4045
void powerOn();
4146
void powerOff();
42-
};
47+
};

src/helpers/ui/E290Display.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,50 @@ bool E290Display::begin() {
2121
}
2222

2323
void E290Display::powerOn() {
24+
if (_periph_power) {
25+
_periph_power->claim();
26+
} else {
2427
#ifdef PIN_VEXT_EN
25-
pinMode(PIN_VEXT_EN, OUTPUT);
26-
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
27-
delay(50); // Allow power to stabilize
28+
pinMode(PIN_VEXT_EN, OUTPUT);
29+
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
2830
#endif
31+
}
32+
delay(50); // Allow power to stabilize
2933
}
3034

3135
void E290Display::powerOff() {
36+
if (_periph_power) {
37+
_periph_power->release();
38+
} else {
3239
#ifdef PIN_VEXT_EN
33-
digitalWrite(PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE); // Turn off power
40+
digitalWrite(PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE); // Turn off power
3441
#endif
42+
}
3543
}
3644

3745
void E290Display::turnOn() {
3846
if (!_init) begin();
39-
powerOn();
47+
else if (!_isOn) {
48+
powerOn();
49+
display.fastmodeOn(); // Reinitialize display controller after power was cut
50+
}
4051
_isOn = true;
4152
}
4253

4354
void E290Display::turnOff() {
44-
powerOff();
45-
_isOn = false;
55+
if (_isOn) {
56+
powerOff();
57+
_isOn = false;
58+
}
4659
}
4760

4861
void E290Display::clear() {
4962
display.clear();
5063
}
5164

5265
void E290Display::startFrame(Color bkg) {
66+
display_crc.reset();
67+
5368
// Fill screen with white first to ensure clean background
5469
display.fillRect(0, 0, width(), height(), WHITE);
5570
if (bkg == LIGHT) {
@@ -59,31 +74,50 @@ void E290Display::startFrame(Color bkg) {
5974
}
6075

6176
void E290Display::setTextSize(int sz) {
77+
display_crc.update<int>(sz);
6278
// The library handles text size internally
6379
display.setTextSize(sz);
6480
}
6581

6682
void E290Display::setColor(Color c) {
83+
display_crc.update<Color>(c);
6784
// implemented in individual display methods
6885
}
6986

7087
void E290Display::setCursor(int x, int y) {
88+
display_crc.update<int>(x);
89+
display_crc.update<int>(y);
7190
display.setCursor(x, y);
7291
}
7392

7493
void E290Display::print(const char *str) {
94+
display_crc.update<char>(str, strlen(str));
7595
display.print(str);
7696
}
7797

7898
void E290Display::fillRect(int x, int y, int w, int h) {
99+
display_crc.update<int>(x);
100+
display_crc.update<int>(y);
101+
display_crc.update<int>(w);
102+
display_crc.update<int>(h);
79103
display.fillRect(x, y, w, h, BLACK);
80104
}
81105

82106
void E290Display::drawRect(int x, int y, int w, int h) {
107+
display_crc.update<int>(x);
108+
display_crc.update<int>(y);
109+
display_crc.update<int>(w);
110+
display_crc.update<int>(h);
83111
display.drawRect(x, y, w, h, BLACK);
84112
}
85113

86114
void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
115+
display_crc.update<int>(x);
116+
display_crc.update<int>(y);
117+
display_crc.update<int>(w);
118+
display_crc.update<int>(h);
119+
display_crc.update<uint8_t>(bits, w * h / 8);
120+
87121
// Width in bytes for bitmap processing
88122
uint16_t widthInBytes = (w + 7) / 8;
89123

@@ -112,5 +146,9 @@ uint16_t E290Display::getTextWidth(const char *str) {
112146
}
113147

114148
void E290Display::endFrame() {
115-
display.update();
149+
uint32_t crc = display_crc.finalize();
150+
if (crc != last_display_crc_value) {
151+
display.update();
152+
last_display_crc_value = crc;
153+
}
116154
}

src/helpers/ui/E290Display.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
#include <SPI.h>
66
#include <Wire.h>
77
#include <heltec-eink-modules.h>
8+
#include <CRC32.h>
9+
#include <helpers/RefCountedDigitalPin.h>
810

911
// Display driver for E290 e-ink display
1012
class E290Display : public DisplayDriver {
1113
EInkDisplay_VisionMasterE290 display;
1214
bool _init = false;
1315
bool _isOn = false;
16+
RefCountedDigitalPin* _periph_power;
17+
CRC32 display_crc;
18+
uint32_t last_display_crc_value = 0;
1419

1520
public:
16-
E290Display() : DisplayDriver(296, 128) {}
21+
E290Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(296, 128), _periph_power(periph_power) {}
1722

1823
bool begin();
1924
bool isOn() override { return _isOn; }
@@ -34,4 +39,4 @@ class E290Display : public DisplayDriver {
3439
private:
3540
void powerOn();
3641
void powerOff();
37-
};
42+
};

variants/heltec_e213/platformio.ini

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ lib_deps =
4040
${esp32_base.lib_deps}
4141
https://github.com/Quency-D/heltec-eink-modules/archive/563dd41fd850a1bc3039b8723da4f3a20fe1c800.zip
4242

43-
[env:Heltec_E213_companion_radio_ble_]
43+
[env:Heltec_E213_companion_radio_ble]
4444
extends = Heltec_E213_base
4545
build_flags =
4646
${Heltec_E213_base.build_flags}
4747
-I examples/companion_radio/ui-new
4848
-D MAX_CONTACTS=350
4949
-D MAX_GROUP_CHANNELS=40
5050
-D DISPLAY_CLASS=E213Display
51+
-D AUTO_OFF_MILLIS=0
5152
-D BLE_PIN_CODE=123456 ; dynamic, random PIN
5253
-D BLE_DEBUG_LOGGING=1
5354
-D OFFLINE_QUEUE_SIZE=256
@@ -59,15 +60,17 @@ build_src_filter = ${Heltec_E213_base.build_src_filter}
5960
lib_deps =
6061
${Heltec_E213_base.lib_deps}
6162
densaugeo/base64 @ ~1.4.0
63+
bakercp/CRC32 @ ^2.0.0
6264

63-
[env:Heltec_E213_companion_radio_usb_]
65+
[env:Heltec_E213_companion_radio_usb]
6466
extends = Heltec_E213_base
6567
build_flags =
6668
${Heltec_E213_base.build_flags}
6769
-I examples/companion_radio/ui-new
6870
-D MAX_CONTACTS=350
6971
-D MAX_GROUP_CHANNELS=40
7072
-D DISPLAY_CLASS=E213Display
73+
-D AUTO_OFF_MILLIS=0
7174
-D OFFLINE_QUEUE_SIZE=256
7275
build_src_filter = ${Heltec_E213_base.build_src_filter}
7376
+<helpers/ui/E213Display.cpp>
@@ -77,8 +80,9 @@ build_src_filter = ${Heltec_E213_base.build_src_filter}
7780
lib_deps =
7881
${Heltec_E213_base.lib_deps}
7982
densaugeo/base64 @ ~1.4.0
83+
bakercp/CRC32 @ ^2.0.0
8084

81-
[env:Heltec_E213_repeater_]
85+
[env:Heltec_E213_repeater]
8286
extends = Heltec_E213_base
8387
build_flags =
8488
${Heltec_E213_base.build_flags}
@@ -94,8 +98,9 @@ build_src_filter = ${Heltec_E213_base.build_src_filter}
9498
lib_deps =
9599
${Heltec_E213_base.lib_deps}
96100
${esp32_ota.lib_deps}
101+
bakercp/CRC32 @ ^2.0.0
97102

98-
; [env:Heltec_E213_repeater_bridge_rs232_]
103+
; [env:Heltec_E213_repeater_bridge_rs232]
99104
; extends = Heltec_E213_base
100105
; build_flags =
101106
; ${Heltec_E213_base.build_flags}
@@ -118,8 +123,9 @@ lib_deps =
118123
; lib_deps =
119124
; ${Heltec_E213_base.lib_deps}
120125
; ${esp32_ota.lib_deps}
126+
; bakercp/CRC32 @ ^2.0.0
121127

122-
[env:Heltec_E213_repeater_bridge_espnow_]
128+
[env:Heltec_E213_repeater_bridge_espnow]
123129
extends = Heltec_E213_base
124130
build_flags =
125131
${Heltec_E213_base.build_flags}
@@ -140,8 +146,9 @@ build_src_filter = ${Heltec_E213_base.build_src_filter}
140146
lib_deps =
141147
${Heltec_E213_base.lib_deps}
142148
${esp32_ota.lib_deps}
149+
bakercp/CRC32 @ ^2.0.0
143150

144-
[env:Heltec_E213_room_server_]
151+
[env:Heltec_E213_room_server]
145152
extends = Heltec_E213_base
146153
build_flags =
147154
${Heltec_E213_base.build_flags}
@@ -157,3 +164,4 @@ build_src_filter = ${Heltec_E213_base.build_src_filter}
157164
lib_deps =
158165
${Heltec_E213_base.lib_deps}
159166
${esp32_ota.lib_deps}
167+
bakercp/CRC32 @ ^2.0.0

0 commit comments

Comments
 (0)