22
33#include " ../../MeshCore.h"
44
5+ EInkDetectionResult E213Display::detectEInk ()
6+ {
7+ // Test 1: Logic of BUSY pin
8+
9+ // Determines controller IC manufacturer
10+ // Fitipower: busy when LOW
11+ // Solomon Systech: busy when HIGH
12+
13+ // Force display BUSY by holding reset pin active
14+ pinMode (DISP_RST, OUTPUT);
15+ digitalWrite (DISP_RST, LOW);
16+
17+ delay (10 );
18+
19+ // Read whether pin is HIGH or LOW while busy
20+ pinMode (DISP_BUSY, INPUT);
21+ bool busyLogic = digitalRead (DISP_BUSY);
22+
23+ // Test complete. Release pin
24+ pinMode (DISP_RST, INPUT);
25+
26+ if (busyLogic == LOW)
27+ return V_LCMEN213EFC1;
28+ else // busy HIGH
29+ return V_E0213A367;
30+ }
31+
32+
533bool E213Display::begin () {
634 if (_init) return true ;
735
836 powerOn ();
9- display.begin ();
37+ _version = detectEInk ();
38+ if (_version==V_LCMEN213EFC1) {
39+ display.begin ();
40+ // Set to landscape mode rotated 180 degrees
41+ display.setRotation (3 );
42+ } else {
43+ display1.begin ();
44+ // Set to landscape mode rotated 180 degrees
45+ display1.setRotation (3 );
46+ }
1047
11- // Set to landscape mode rotated 180 degrees
12- display.setRotation (3 );
1348
1449 _init = true ;
1550 _isOn = true ;
1651
1752 clear ();
18- display.fastmodeOn (); // Enable fast mode for quicker (partial) updates
53+ if (_version==V_LCMEN213EFC1) {
54+ display.fastmodeOn (); // Enable fast mode for quicker (partial) updates
55+ } else {
56+ display1.fastmodeOn (); // Enable fast mode for quicker (partial) updates
57+ }
1958
2059 return true ;
2160}
2261
2362void E213Display::powerOn () {
2463#ifdef PIN_VEXT_EN
2564 pinMode (PIN_VEXT_EN, OUTPUT);
65+ #ifdef PIN_VEXT_EN_ACTIVE
66+ digitalWrite (PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
67+ #else
2668 digitalWrite (PIN_VEXT_EN, LOW); // Active low
69+ #endif
2770 delay (50 ); // Allow power to stabilize
2871#endif
2972}
3073
3174void E213Display::powerOff () {
3275#ifdef PIN_VEXT_EN
76+ #ifdef PIN_VEXT_EN_ACTIVE
77+ digitalWrite (PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE);
78+ #else
3379 digitalWrite (PIN_VEXT_EN, HIGH); // Turn off power
3480#endif
81+ #endif
3582}
3683
3784void E213Display::turnOn () {
@@ -46,41 +93,73 @@ void E213Display::turnOff() {
4693}
4794
4895void E213Display::clear () {
49- display.clear ();
96+ if (_version==V_LCMEN213EFC1) {
97+ display.clear ();
98+ } else {
99+ display1.clear ();
100+ }
50101}
51102
52103void E213Display::startFrame (Color bkg) {
53104 // Fill screen with white first to ensure clean background
54- display.fillRect (0 , 0 , width (), height (), WHITE);
105+ if (_version==V_LCMEN213EFC1) {
106+ display.fillRect (0 , 0 , width (), height (), WHITE);
107+ } else {
108+ display1.fillRect (0 , 0 , width (), height (), WHITE);
109+ }
55110 if (bkg == LIGHT) {
56111 // Fill with black if light background requested (inverted for e-ink)
57- display.fillRect (0 , 0 , width (), height (), BLACK);
112+ if (_version==V_LCMEN213EFC1) {
113+ display.fillRect (0 , 0 , width (), height (), BLACK);
114+ } else {
115+ display1.fillRect (0 , 0 , width (), height (), BLACK);
116+ }
58117 }
59118}
60119
61120void E213Display::setTextSize (int sz) {
62121 // The library handles text size internally
63- display.setTextSize (sz);
122+ if (_version==V_LCMEN213EFC1) {
123+ display.setTextSize (sz);
124+ } else {
125+ display1.setTextSize (sz);
126+ }
64127}
65128
66129void E213Display::setColor (Color c) {
67130 // implemented in individual display methods
68131}
69132
70133void E213Display::setCursor (int x, int y) {
71- display.setCursor (x, y);
134+ if (_version==V_LCMEN213EFC1) {
135+ display.setCursor (x, y);
136+ } else {
137+ display1.setCursor (x, y);
138+ }
72139}
73140
74141void E213Display::print (const char *str) {
75- display.print (str);
142+ if (_version==V_LCMEN213EFC1) {
143+ display.print (str);
144+ } else {
145+ display1.print (str);
146+ }
76147}
77148
78149void E213Display::fillRect (int x, int y, int w, int h) {
79- display.fillRect (x, y, w, h, BLACK);
150+ if (_version==V_LCMEN213EFC1) {
151+ display.fillRect (x, y, w, h, BLACK);
152+ } else {
153+ display1.fillRect (x, y, w, h, BLACK);
154+ }
80155}
81156
82157void E213Display::drawRect (int x, int y, int w, int h) {
83- display.drawRect (x, y, w, h, BLACK);
158+ if (_version==V_LCMEN213EFC1) {
159+ display.drawRect (x, y, w, h, BLACK);
160+ } else {
161+ display1.drawRect (x, y, w, h, BLACK);
162+ }
84163}
85164
86165void E213Display::drawXbm (int x, int y, const uint8_t *bits, int w, int h) {
@@ -98,7 +177,11 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
98177
99178 // If the bit is set, draw the pixel
100179 if (bitSet) {
101- display.drawPixel (x + bx, y + by, BLACK);
180+ if (_version==V_LCMEN213EFC1) {
181+ display.drawPixel (x + bx, y + by, BLACK);
182+ } else {
183+ display1.drawPixel (x + bx, y + by, BLACK);
184+ }
102185 }
103186 }
104187 }
@@ -107,10 +190,18 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
107190uint16_t E213Display::getTextWidth (const char *str) {
108191 int16_t x1, y1;
109192 uint16_t w, h;
110- display.getTextBounds (str, 0 , 0 , &x1, &y1, &w, &h);
193+ if (_version==V_LCMEN213EFC1) {
194+ display.getTextBounds (str, 0 , 0 , &x1, &y1, &w, &h);
195+ } else {
196+ display1.getTextBounds (str, 0 , 0 , &x1, &y1, &w, &h);
197+ }
111198 return w;
112199}
113200
114201void E213Display::endFrame () {
115- display.update ();
202+ if (_version==V_LCMEN213EFC1) {
203+ display.update ();
204+ } else {
205+ display1.update ();
206+ }
116207}
0 commit comments