Skip to content

Commit a81e8b4

Browse files
authored
Merge pull request #211 from fdlamotte/techo-display
Techo display
2 parents 8f70d48 + 2d6c834 commit a81e8b4

File tree

7 files changed

+176
-4
lines changed

7 files changed

+176
-4
lines changed

examples/companion_radio/UITask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void UITask::renderCurrScreen() {
9999
_display->setColor(DisplayDriver::LIGHT);
100100
_display->print(_msg);
101101

102-
_display->setCursor(100, 9);
102+
_display->setCursor(_display->width() - 28, 9);
103103
_display->setTextSize(2);
104104
_display->setColor(DisplayDriver::ORANGE);
105105
sprintf(tmp, "%d", _msgcount);

examples/companion_radio/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
#include "UITask.h"
6262
#ifdef ST7789
6363
#include <helpers/ui/ST7789Display.h>
64+
#elif defined(HAS_GxEPD)
65+
#include <helpers/ui/GxEPDDisplay.h>
6466
#else
6567
#include <helpers/ui/SSD1306Display.h>
6668
#endif

src/helpers/ui/GxEPDDisplay.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
#include "GxEPDDisplay.h"
3+
4+
bool GxEPDDisplay::begin() {
5+
display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0));
6+
SPI1.begin();
7+
display.init(115200, true, 2, false);
8+
display.setRotation(3);
9+
#ifdef TECHO_ZOOM
10+
display.setFont(&FreeMono9pt7b);
11+
#endif
12+
display.setPartialWindow(0, 0, display.width(), display.height());
13+
14+
display.fillScreen(GxEPD_WHITE);
15+
display.display(true);
16+
#if DISP_BACKLIGHT
17+
pinMode(DISP_BACKLIGHT, OUTPUT);
18+
#endif
19+
_init = true;
20+
return true;
21+
}
22+
23+
void GxEPDDisplay::turnOn() {
24+
if (!_init) begin();
25+
#if DISP_BACKLIGHT
26+
digitalWrite(DISP_BACKLIGHT, HIGH);
27+
_isOn = true;
28+
#endif
29+
}
30+
31+
void GxEPDDisplay::turnOff() {
32+
#if DISP_BACKLIGHT
33+
digitalWrite(DISP_BACKLIGHT, LOW);
34+
#endif
35+
_isOn = false;
36+
}
37+
38+
void GxEPDDisplay::clear() {
39+
display.fillScreen(GxEPD_WHITE);
40+
display.setTextColor(GxEPD_BLACK);
41+
}
42+
43+
void GxEPDDisplay::startFrame(Color bkg) {
44+
display.fillScreen(GxEPD_WHITE);
45+
}
46+
47+
void GxEPDDisplay::setTextSize(int sz) {
48+
display.setTextSize(sz);
49+
}
50+
51+
void GxEPDDisplay::setColor(Color c) {
52+
display.setTextColor(GxEPD_BLACK);
53+
}
54+
55+
void GxEPDDisplay::setCursor(int x, int y) {
56+
#ifdef TECHO_ZOOM
57+
x = x + (x >> 1);
58+
y = y + (y >> 1);
59+
#endif
60+
display.setCursor(x, (y+10));
61+
}
62+
63+
void GxEPDDisplay::print(const char* str) {
64+
display.print(str);
65+
}
66+
67+
void GxEPDDisplay::fillRect(int x, int y, int w, int h) {
68+
#ifdef TECHO_ZOOM
69+
x = x + (x >> 1);
70+
y = y + (y >> 1);
71+
w = w + (w >> 1);
72+
h = h + (h >> 1);
73+
#endif
74+
display.fillRect(x, y, w, h, GxEPD_BLACK);
75+
}
76+
77+
void GxEPDDisplay::drawRect(int x, int y, int w, int h) {
78+
#ifdef TECHO_ZOOM
79+
x = x + (x >> 1);
80+
y = y + (y >> 1);
81+
w = w + (w >> 1);
82+
h = h + (h >> 1);
83+
#endif
84+
display.drawRect(x, y, w, h, GxEPD_BLACK);
85+
}
86+
87+
void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
88+
#ifdef TECHO_ZOOM
89+
x = x + (x >> 1);
90+
y = y + (y >> 1);
91+
w = w + (w >> 1);
92+
h = h + (h >> 1);
93+
#endif
94+
display.drawBitmap(x*1.5, (y*1.5) + 10, bits, w, h, GxEPD_BLACK);
95+
}
96+
97+
void GxEPDDisplay::endFrame() {
98+
display.display(true);
99+
}

src/helpers/ui/GxEPDDisplay.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma once
2+
3+
#include <SPI.h>
4+
#include <Wire.h>
5+
6+
#define ENABLE_GxEPD2_GFX 0
7+
8+
#include <GxEPD2_BW.h>
9+
#include <GxEPD2_3C.h>
10+
#include <GxEPD2_4C.h>
11+
#include <GxEPD2_7C.h>
12+
#include <Fonts/FreeMono9pt7b.h>
13+
14+
#define GxEPD2_DISPLAY_CLASS GxEPD2_BW
15+
#define GxEPD2_DRIVER_CLASS GxEPD2_150_BN // DEPG0150BN 200x200, SSD1681, (FPC8101), TTGO T5 V2.4.1
16+
17+
#include <epd/GxEPD2_150_BN.h> // 1.54" b/w
18+
19+
#include "DisplayDriver.h"
20+
21+
//GxEPD2_BW<GxEPD2_150_BN, 200> display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)); // DEPG0150BN 200x200, SSD1681, TTGO T5 V2.4.1
22+
23+
24+
class GxEPDDisplay : public DisplayDriver {
25+
26+
GxEPD2_BW<GxEPD2_150_BN, 200> display;
27+
bool _init = false;
28+
bool _isOn = false;
29+
30+
public:
31+
// there is a margin in y...
32+
GxEPDDisplay() : DisplayDriver(200, 200-10), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) {
33+
34+
}
35+
36+
bool begin();
37+
38+
bool isOn() override {return _isOn;};
39+
void turnOn() override;
40+
void turnOff() override;
41+
void clear() override;
42+
void startFrame(Color bkg = DARK) override;
43+
void setTextSize(int sz) override;
44+
void setColor(Color c) override;
45+
void setCursor(int x, int y) override;
46+
void print(const char* str) override;
47+
void fillRect(int x, int y, int w, int h) override;
48+
void drawRect(int x, int y, int w, int h) override;
49+
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
50+
void endFrame() override;
51+
};

variants/techo/platformio.ini

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,23 @@ build_flags =
5656
extends = LilyGo_Techo
5757
build_flags =
5858
${LilyGo_Techo.build_flags}
59+
-I src/helpers/ui
5960
-D MAX_CONTACTS=100
6061
-D MAX_GROUP_CHANNELS=8
6162
-D BLE_PIN_CODE=123456
6263
-D BLE_DEBUG_LOGGING=1
64+
-D DISPLAY_CLASS=GxEPDDisplay
65+
-D HAS_GxEPD
6366
; -D ENABLE_PRIVATE_KEY_IMPORT=1
6467
; -D ENABLE_PRIVATE_KEY_EXPORT=1
6568
; -D MESH_PACKET_LOGGING=1
6669
; -D MESH_DEBUG=1
6770
build_src_filter = ${LilyGo_Techo.build_src_filter}
68-
+<helpers/nrf52/*.cpp>
69-
+<../examples/companion_radio/main.cpp>
71+
+<helpers/nrf52/TechoBoard.cpp>
72+
+<helpers/nrf52/SerialBLEInterface.cpp>
73+
+<helpers/ui/GxEPDDisplay.cpp>
74+
+<../examples/companion_radio>
7075
lib_deps =
7176
${LilyGo_Techo.lib_deps}
7277
densaugeo/base64 @ ~1.4.0
78+
zinggjm/GxEPD2 @ 1.6.2

variants/techo/variant.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#include "wiring_constants.h"
33
#include "wiring_digital.h"
44

5+
const int MISO = PIN_SPI1_MISO;
6+
const int MOSI = PIN_SPI1_MOSI;
7+
const int SCK = PIN_SPI1_SCK;
8+
59
const uint32_t g_ADigitalPinMap[] = {
610
0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
711
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,

variants/techo/variant.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#define LED_GREEN (33)
6666
#define LED_BLUE (14)
6767

68+
#define PIN_STATUS_LED LED_GREEN
6869
#define LED_BUILTIN LED_GREEN
6970
#define PIN_LED LED_BUILTIN
7071
#define LED_PIN LED_BUILTIN
@@ -78,6 +79,7 @@
7879

7980
#define PIN_BUTTON1 (42)
8081
#define BUTTON_PIN PIN_BUTTON1
82+
#define PIN_USER_BTN BUTTON_PIN
8183

8284
#define PIN_BUTTON2 (11)
8385
#define BUTTON_PIN2 PIN_BUTTON2
@@ -96,10 +98,18 @@
9698
#define SX126X_DIO2_AS_RF_SWITCH
9799
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
98100

99-
#define PIN_SPI1_MISO (39)
101+
////////////////////////////////////////////////////////////////////////////////
102+
// SPI1
103+
104+
#define PIN_SPI1_MISO (38)
100105
#define PIN_SPI1_MOSI (29)
101106
#define PIN_SPI1_SCK (31)
102107

108+
// GxEPD2 needs that for a panel that is not even used !
109+
extern const int MISO;
110+
extern const int MOSI;
111+
extern const int SCK;
112+
103113
////////////////////////////////////////////////////////////////////////////////
104114
// Display
105115

0 commit comments

Comments
 (0)