From ea24a12ba336539bcdacd993e03a1d4bdbf6fbcf Mon Sep 17 00:00:00 2001 From: Florent Date: Tue, 15 Apr 2025 22:37:50 +0200 Subject: [PATCH] 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