diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index 01770363b..7448f303d 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/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 7438dd899..95bcd4606 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 000000000..e7b70b492 --- /dev/null +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -0,0 +1,99 @@ + +#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); + #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() { + display.fillScreen(GxEPD_WHITE); + display.setTextColor(GxEPD_BLACK); +} + +void GxEPDDisplay::startFrame(Color bkg) { + display.fillScreen(GxEPD_WHITE); +} + +void GxEPDDisplay::setTextSize(int sz) { + display.setTextSize(sz); +} + +void GxEPDDisplay::setColor(Color c) { + display.setTextColor(GxEPD_BLACK); +} + +void GxEPDDisplay::setCursor(int x, int y) { +#ifdef TECHO_ZOOM + x = x + (x >> 1); + y = y + (y >> 1); +#endif + display.setCursor(x, (y+10)); +} + +void GxEPDDisplay::print(const char* str) { + display.print(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); +} + +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 000000000..ecadc50c1 --- /dev/null +++ b/src/helpers/ui/GxEPDDisplay.h @@ -0,0 +1,51 @@ +#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; + bool _isOn = false; + +public: + // 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 _isOn;}; + 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 6b681fb4a..f3c2f9737 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 7b7bee959..155aa42db 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 9f4da8e77..f553ab423 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 @@ -96,10 +98,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