From ea24a12ba336539bcdacd993e03a1d4bdbf6fbcf Mon Sep 17 00:00:00 2001 From: Florent Date: Tue, 15 Apr 2025 22:37:50 +0200 Subject: [PATCH 1/4] techo-display: first bits --- examples/companion_radio/main.cpp | 2 + src/helpers/ui/GxEPDDisplay.cpp | 63 +++++++++++++++++++++++++++++++ src/helpers/ui/GxEPDDisplay.h | 49 ++++++++++++++++++++++++ variants/techo/platformio.ini | 10 ++++- variants/techo/variant.cpp | 4 ++ variants/techo/variant.h | 10 ++++- 6 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 src/helpers/ui/GxEPDDisplay.cpp create mode 100644 src/helpers/ui/GxEPDDisplay.h diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 7438dd89..95bcd460 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -61,6 +61,8 @@ #include "UITask.h" #ifdef ST7789 #include + #elif defined(HAS_GxEPD) + #include #else #include #endif diff --git a/src/helpers/ui/GxEPDDisplay.cpp b/src/helpers/ui/GxEPDDisplay.cpp new file mode 100644 index 00000000..2e3e5589 --- /dev/null +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -0,0 +1,63 @@ + +#include "GxEPDDisplay.h" + +bool GxEPDDisplay::begin() { + display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0)); + SPI1.begin(); + display.init(115200, true, 2, false); + display.setRotation(3); + display.setFont(&FreeMono9pt7b); + + display.setPartialWindow(0, 0, display.width(), display.height()); + + display.fillScreen(GxEPD_WHITE); + display.display(); + _init = true; + return true; +} + +void GxEPDDisplay::turnOn() { + if (!_init) begin(); +} + +void GxEPDDisplay::turnOff() { + +} + +void GxEPDDisplay::clear() { + display.fillScreen(GxEPD_WHITE); + display.setTextColor(GxEPD_BLACK); +} + +void GxEPDDisplay::startFrame(Color bkg) { + display.fillScreen(GxEPD_WHITE); +} + +void GxEPDDisplay::setTextSize(int sz) { +} + +void GxEPDDisplay::setColor(Color c) { + display.setTextColor(GxEPD_BLACK); +} + +void GxEPDDisplay::setCursor(int x, int y) { + display.setCursor(x*1.5, (y*1.5)+10); +} + +void GxEPDDisplay::print(const char* str) { + display.print(str); +} + +void GxEPDDisplay::fillRect(int x, int y, int w, int h) { +} + +void GxEPDDisplay::drawRect(int x, int y, int w, int h) { +} + +void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { + display.drawBitmap(x*1.5, (y*1.5) + 10, bits, w, h, GxEPD_BLACK); +} + +void GxEPDDisplay::endFrame() { + display.display(true); +} diff --git a/src/helpers/ui/GxEPDDisplay.h b/src/helpers/ui/GxEPDDisplay.h new file mode 100644 index 00000000..1dbf3a9a --- /dev/null +++ b/src/helpers/ui/GxEPDDisplay.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include + +#define ENABLE_GxEPD2_GFX 0 + +#include +#include +#include +#include +#include + +#define GxEPD2_DISPLAY_CLASS GxEPD2_BW +#define GxEPD2_DRIVER_CLASS GxEPD2_150_BN // DEPG0150BN 200x200, SSD1681, (FPC8101), TTGO T5 V2.4.1 + +#include // 1.54" b/w + +#include "DisplayDriver.h" + +//GxEPD2_BW display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)); // DEPG0150BN 200x200, SSD1681, TTGO T5 V2.4.1 + + +class GxEPDDisplay : public DisplayDriver { + + GxEPD2_BW display; + bool _init = false; + +public: + GxEPDDisplay() : DisplayDriver(200, 200), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) { + + } + + bool begin(); + + bool isOn() override { return true; } + void turnOn() override; + void turnOff() override; + void clear() override; + void startFrame(Color bkg = DARK) override; + void setTextSize(int sz) override; + void setColor(Color c) override; + void setCursor(int x, int y) override; + void print(const char* str) override; + void fillRect(int x, int y, int w, int h) override; + void drawRect(int x, int y, int w, int h) override; + void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override; + void endFrame() override; +}; diff --git a/variants/techo/platformio.ini b/variants/techo/platformio.ini index 6b681fb4..f3c2f973 100644 --- a/variants/techo/platformio.ini +++ b/variants/techo/platformio.ini @@ -56,17 +56,23 @@ build_flags = extends = LilyGo_Techo build_flags = ${LilyGo_Techo.build_flags} + -I src/helpers/ui -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 -D BLE_DEBUG_LOGGING=1 + -D DISPLAY_CLASS=GxEPDDisplay + -D HAS_GxEPD ; -D ENABLE_PRIVATE_KEY_IMPORT=1 ; -D ENABLE_PRIVATE_KEY_EXPORT=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${LilyGo_Techo.build_src_filter} - + - +<../examples/companion_radio/main.cpp> + + + + + + + +<../examples/companion_radio> lib_deps = ${LilyGo_Techo.lib_deps} densaugeo/base64 @ ~1.4.0 + zinggjm/GxEPD2 @ 1.6.2 diff --git a/variants/techo/variant.cpp b/variants/techo/variant.cpp index 7b7bee95..155aa42d 100644 --- a/variants/techo/variant.cpp +++ b/variants/techo/variant.cpp @@ -2,6 +2,10 @@ #include "wiring_constants.h" #include "wiring_digital.h" +const int MISO = PIN_SPI1_MISO; +const int MOSI = PIN_SPI1_MOSI; +const int SCK = PIN_SPI1_SCK; + const uint32_t g_ADigitalPinMap[] = { 0xff, 0xff, 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, diff --git a/variants/techo/variant.h b/variants/techo/variant.h index 9f4da8e7..6228fce9 100644 --- a/variants/techo/variant.h +++ b/variants/techo/variant.h @@ -96,10 +96,18 @@ #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 -#define PIN_SPI1_MISO (39) +//////////////////////////////////////////////////////////////////////////////// +// SPI1 + +#define PIN_SPI1_MISO (38) #define PIN_SPI1_MOSI (29) #define PIN_SPI1_SCK (31) +// GxEPD2 needs that for a panel that is not even used ! +extern const int MISO; +extern const int MOSI; +extern const int SCK; + //////////////////////////////////////////////////////////////////////////////// // Display From 512f0900da20714964027214d176541b65f865e2 Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 20 Apr 2025 16:41:33 +0200 Subject: [PATCH 2/4] led and button assigned in ui --- variants/techo/variant.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variants/techo/variant.h b/variants/techo/variant.h index 6228fce9..f553ab42 100644 --- a/variants/techo/variant.h +++ b/variants/techo/variant.h @@ -65,6 +65,7 @@ #define LED_GREEN (33) #define LED_BLUE (14) +#define PIN_STATUS_LED LED_GREEN #define LED_BUILTIN LED_GREEN #define PIN_LED LED_BUILTIN #define LED_PIN LED_BUILTIN @@ -78,6 +79,7 @@ #define PIN_BUTTON1 (42) #define BUTTON_PIN PIN_BUTTON1 +#define PIN_USER_BTN BUTTON_PIN #define PIN_BUTTON2 (11) #define BUTTON_PIN2 PIN_BUTTON2 From 052ca9f12f3febdbcce6aa85f1223b00c08645f8 Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 20 Apr 2025 16:44:30 +0200 Subject: [PATCH 3/4] fix screen boot --- src/helpers/ui/GxEPDDisplay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/ui/GxEPDDisplay.cpp b/src/helpers/ui/GxEPDDisplay.cpp index 2e3e5589..0b8bf502 100644 --- a/src/helpers/ui/GxEPDDisplay.cpp +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -11,7 +11,7 @@ bool GxEPDDisplay::begin() { display.setPartialWindow(0, 0, display.width(), display.height()); display.fillScreen(GxEPD_WHITE); - display.display(); + display.display(true); _init = true; return true; } From 2d6c834887d02abd8afef1bfd647666a8a272f50 Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 20 Apr 2025 17:10:57 +0200 Subject: [PATCH 4/4] std behaviour --- examples/companion_radio/UITask.cpp | 2 +- src/helpers/ui/GxEPDDisplay.cpp | 44 ++++++++++++++++++++++++++--- src/helpers/ui/GxEPDDisplay.h | 6 ++-- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index 01770363..7448f303 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -99,7 +99,7 @@ void UITask::renderCurrScreen() { _display->setColor(DisplayDriver::LIGHT); _display->print(_msg); - _display->setCursor(100, 9); + _display->setCursor(_display->width() - 28, 9); _display->setTextSize(2); _display->setColor(DisplayDriver::ORANGE); sprintf(tmp, "%d", _msgcount); diff --git a/src/helpers/ui/GxEPDDisplay.cpp b/src/helpers/ui/GxEPDDisplay.cpp index 0b8bf502..e7b70b49 100644 --- a/src/helpers/ui/GxEPDDisplay.cpp +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -6,22 +6,33 @@ bool GxEPDDisplay::begin() { SPI1.begin(); display.init(115200, true, 2, false); display.setRotation(3); - display.setFont(&FreeMono9pt7b); - + #ifdef TECHO_ZOOM + display.setFont(&FreeMono9pt7b); + #endif display.setPartialWindow(0, 0, display.width(), display.height()); display.fillScreen(GxEPD_WHITE); display.display(true); + #if DISP_BACKLIGHT + pinMode(DISP_BACKLIGHT, OUTPUT); + #endif _init = true; return true; } void GxEPDDisplay::turnOn() { if (!_init) begin(); +#if DISP_BACKLIGHT + digitalWrite(DISP_BACKLIGHT, HIGH); + _isOn = true; +#endif } void GxEPDDisplay::turnOff() { - +#if DISP_BACKLIGHT + digitalWrite(DISP_BACKLIGHT, LOW); +#endif + _isOn = false; } void GxEPDDisplay::clear() { @@ -34,6 +45,7 @@ void GxEPDDisplay::startFrame(Color bkg) { } void GxEPDDisplay::setTextSize(int sz) { + display.setTextSize(sz); } void GxEPDDisplay::setColor(Color c) { @@ -41,7 +53,11 @@ void GxEPDDisplay::setColor(Color c) { } void GxEPDDisplay::setCursor(int x, int y) { - display.setCursor(x*1.5, (y*1.5)+10); +#ifdef TECHO_ZOOM + x = x + (x >> 1); + y = y + (y >> 1); +#endif + display.setCursor(x, (y+10)); } void GxEPDDisplay::print(const char* str) { @@ -49,12 +65,32 @@ void GxEPDDisplay::print(const char* str) { } void GxEPDDisplay::fillRect(int x, int y, int w, int h) { +#ifdef TECHO_ZOOM + x = x + (x >> 1); + y = y + (y >> 1); + w = w + (w >> 1); + h = h + (h >> 1); +#endif + display.fillRect(x, y, w, h, GxEPD_BLACK); } void GxEPDDisplay::drawRect(int x, int y, int w, int h) { +#ifdef TECHO_ZOOM + x = x + (x >> 1); + y = y + (y >> 1); + w = w + (w >> 1); + h = h + (h >> 1); +#endif + display.drawRect(x, y, w, h, GxEPD_BLACK); } void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { +#ifdef TECHO_ZOOM + x = x + (x >> 1); + y = y + (y >> 1); + w = w + (w >> 1); + h = h + (h >> 1); +#endif display.drawBitmap(x*1.5, (y*1.5) + 10, bits, w, h, GxEPD_BLACK); } diff --git a/src/helpers/ui/GxEPDDisplay.h b/src/helpers/ui/GxEPDDisplay.h index 1dbf3a9a..ecadc50c 100644 --- a/src/helpers/ui/GxEPDDisplay.h +++ b/src/helpers/ui/GxEPDDisplay.h @@ -25,15 +25,17 @@ class GxEPDDisplay : public DisplayDriver { GxEPD2_BW display; bool _init = false; + bool _isOn = false; public: - GxEPDDisplay() : DisplayDriver(200, 200), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) { + // there is a margin in y... + GxEPDDisplay() : DisplayDriver(200, 200-10), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) { } bool begin(); - bool isOn() override { return true; } + bool isOn() override {return _isOn;}; void turnOn() override; void turnOff() override; void clear() override;