mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-11-02 19:02:00 +00:00
refactor(ui): upstream's UIColor palette in place of the DARK/LIGHT enum
- DisplayDriver takes ColorVal; each driver's .cpp defines the UIColor roles (window_bkg, primary_txt, ...) in its own values. ui-new draws in two: window_bkg and primary_txt. OLED and e-ink look as before (sim screens pixel-identical). - E213, E290, LGFX, Null, ST7735, ST7789LCD, U8g2 taken whole from upstream (with them the rewritten ST7735 driver and the Heltec V4 R8 TFT display). - SH1106, SSD1306, ST7789, EinkGfxDisplay and the sim drivers converted. - ui-orig, ui-tiny, simple_* get upstream's colour roles; the repeater's UI taken from upstream (its power-off screen). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,15 @@
|
||||
#include <string.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
using ColorVal = uint16_t;
|
||||
|
||||
// Colours by element type, in the display's own native values. Each display
|
||||
// driver's .cpp defines the palette (mono panels: background 0, ink 1).
|
||||
class UIColor {
|
||||
public:
|
||||
static ColorVal window_bkg, title_bkg, title_txt, primary_txt, secondary_txt, warning_txt, popup_bkg, popup_txt, corp_blue;
|
||||
};
|
||||
|
||||
class DisplayDriver {
|
||||
int _w, _h;
|
||||
protected:
|
||||
@@ -39,8 +48,6 @@ protected:
|
||||
void* _busy_pump_ctx = nullptr;
|
||||
void callBusyPump() { if (_busy_pump_fn) _busy_pump_fn(_busy_pump_ctx); }
|
||||
public:
|
||||
enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light
|
||||
|
||||
int width() const { return _w; }
|
||||
int height() const { return _h; }
|
||||
|
||||
@@ -50,9 +57,9 @@ public:
|
||||
virtual void turnOn() = 0;
|
||||
virtual void turnOff() = 0;
|
||||
virtual void clear() = 0;
|
||||
virtual void startFrame(Color bkg = DARK) = 0;
|
||||
virtual void startFrame(ColorVal bkg = UIColor::window_bkg) = 0;
|
||||
virtual void setTextSize(int sz) = 0;
|
||||
virtual void setColor(Color c) = 0;
|
||||
virtual void setColor(ColorVal c) = 0;
|
||||
virtual void setCursor(int x, int y) = 0;
|
||||
virtual void print(const char* str) = 0;
|
||||
virtual void printWordWrap(const char* str, int max_width) { print(str); } // fallback to basic print() if no override
|
||||
@@ -186,15 +193,15 @@ public:
|
||||
}
|
||||
|
||||
// Common selection-row pattern: when sel, fills (x,y,w,h) with ink and sets
|
||||
// colour to DARK so the next text render appears inverted; when not sel,
|
||||
// just sets ink colour to LIGHT. Replaces the 5-line if/else copy-paste
|
||||
// colour to window_bkg so the next text render appears inverted; when not sel,
|
||||
// just sets ink colour to primary_txt. Replaces the 5-line if/else copy-paste
|
||||
// present in every list-style screen.
|
||||
void drawSelectionRow(int x, int y, int w, int h, bool sel) {
|
||||
setColor(LIGHT);
|
||||
setColor(UIColor::primary_txt);
|
||||
if (sel) {
|
||||
if (w > 2 && h > 2) fillSoftRect(x, y, w, h); // soft corners, like every box
|
||||
else fillRect(x, y, w, h);
|
||||
setColor(DARK);
|
||||
setColor(UIColor::window_bkg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,11 +224,11 @@ public:
|
||||
}
|
||||
// A box floating over the screen (alert, popup, hint): clears a 1 px moat
|
||||
// around it so lines of the view below stop short of the border instead of
|
||||
// running into it, fills it dark and draws the soft border. Leaves ink LIGHT.
|
||||
// running into it, fills it dark and draws the soft border. Leaves ink primary_txt.
|
||||
void drawPanel(int x, int y, int w, int h) {
|
||||
setColor(DARK);
|
||||
setColor(UIColor::window_bkg);
|
||||
fillRect(x - 1, y - 1, w + 2, h + 2);
|
||||
setColor(LIGHT);
|
||||
setColor(UIColor::primary_txt);
|
||||
drawSoftRect(x, y, w, h);
|
||||
}
|
||||
|
||||
@@ -262,15 +269,15 @@ public:
|
||||
// too (paper capsule + ink digits) and stays visible. The four corners are
|
||||
// knocked back to the surrounding colour for a rounded-capsule look.
|
||||
// overflow: see fmtBadgeCount -- appends "+" for a ring-capped, understated count.
|
||||
// Restores ink to LIGHT. Returns the pill width.
|
||||
// Restores ink to primary_txt. Returns the pill width.
|
||||
int drawUnreadBadge(int right_x, int y, int count, bool sel, bool overflow = false) {
|
||||
char buf[5]; fmtBadgeCount(buf, count, overflow);
|
||||
int pad = sepH() + 1;
|
||||
int pw = getTextWidth(buf) - textWidthTrailingGap() + pad * 2;
|
||||
int ph = getLineHeight();
|
||||
int px = right_x - pw;
|
||||
Color body = sel ? DARK : LIGHT;
|
||||
Color ink = sel ? LIGHT : DARK;
|
||||
ColorVal body = sel ? UIColor::window_bkg : UIColor::primary_txt;
|
||||
ColorVal ink = sel ? UIColor::primary_txt : UIColor::window_bkg;
|
||||
setColor(body);
|
||||
fillRect(px, y, pw, ph);
|
||||
setColor(ink);
|
||||
@@ -280,56 +287,56 @@ public:
|
||||
fillRect(px + pw - 1, y + ph - 1, 1, 1);
|
||||
setCursor(px + pad, y);
|
||||
print(buf);
|
||||
setColor(LIGHT);
|
||||
setColor(UIColor::primary_txt);
|
||||
return pw;
|
||||
}
|
||||
|
||||
// Inverted title bar: light background, dark ellipsized label, then the
|
||||
// standard separator line. The label is UTF-8 translated by
|
||||
// drawTextEllipsized. Leaves ink colour LIGHT for following content.
|
||||
// drawTextEllipsized. Leaves ink colour primary_txt for following content.
|
||||
// Pixel width the ≡ context-menu hint reserves at the header's right edge.
|
||||
int menuHintWidth() const { return getCharWidth() + 3; }
|
||||
|
||||
// Small ≡ glyph at the header's top-right, signalling the screen has a
|
||||
// Hold-Enter context menu. Three stacked bars, drawn in colour c (LIGHT on a
|
||||
// plain header, DARK on an inverted bar). When active (the menu is open) the
|
||||
// Hold-Enter context menu. Three stacked bars, drawn in colour c (primary_txt on a
|
||||
// plain header, window_bkg on an inverted bar). When active (the menu is open) the
|
||||
// corner cell is highlighted and the bars knocked out, tying the glyph to the
|
||||
// popup it spawned. Call after the header body.
|
||||
void drawContextMenuHint(Color c = LIGHT, bool active = false) {
|
||||
void drawContextMenuHint(ColorVal c = UIColor::primary_txt, bool active = false) {
|
||||
int gw = getCharWidth() + 1;
|
||||
int gx = width() - gw - 1;
|
||||
int th = sepH();
|
||||
int gy = (getLineHeight() - (th * 3 + 4)) / 2;
|
||||
if (gy < 0) gy = 0;
|
||||
Color bars = c;
|
||||
ColorVal bars = c;
|
||||
if (active) {
|
||||
setColor(c);
|
||||
fillRect(gx - 1, 0, gw + 2, headerH() - sepH());
|
||||
bars = (c == LIGHT) ? DARK : LIGHT;
|
||||
bars = (c == UIColor::primary_txt) ? UIColor::window_bkg : UIColor::primary_txt;
|
||||
}
|
||||
setColor(bars);
|
||||
for (int i = 0; i < 3; i++) fillRect(gx, gy + i * (th + 2), gw, th);
|
||||
setColor(LIGHT);
|
||||
setColor(UIColor::primary_txt);
|
||||
}
|
||||
|
||||
void drawInvertedHeader(const char* label, bool menu_hint = false, bool menu_open = false) {
|
||||
int hdr = headerH();
|
||||
setColor(LIGHT);
|
||||
setColor(UIColor::primary_txt);
|
||||
fillRect(0, 0, width(), hdr - 1);
|
||||
int reserve = menu_hint ? menuHintWidth() : 0;
|
||||
setColor(DARK);
|
||||
setColor(UIColor::window_bkg);
|
||||
drawTextEllipsized(2, 1, width() - 4 - reserve, (label && label[0]) ? label : "");
|
||||
if (menu_hint) drawContextMenuHint(DARK, menu_open);
|
||||
setColor(LIGHT);
|
||||
if (menu_hint) drawContextMenuHint(UIColor::window_bkg, menu_open);
|
||||
setColor(UIColor::primary_txt);
|
||||
fillRect(0, hdr - 1, width(), sepH());
|
||||
}
|
||||
|
||||
// Centred screen title + bottom separator line — the standard top bar for
|
||||
// full-screen list/detail views. Leaves ink LIGHT; callers can draw extra
|
||||
// full-screen list/detail views. Leaves ink primary_txt; callers can draw extra
|
||||
// header content (counters, etc.) afterwards. menu_hint adds the ≡ glyph;
|
||||
// menu_open highlights it while the context menu is on screen.
|
||||
void drawCenteredHeader(const char* title, bool menu_hint = false, bool menu_open = false) {
|
||||
setColor(LIGHT);
|
||||
setColor(UIColor::primary_txt);
|
||||
int reserve = menu_hint ? menuHintWidth() : 0;
|
||||
char buf[96];
|
||||
translateUTF8ToBlocks(buf, (title && title[0]) ? title : "", sizeof(buf));
|
||||
@@ -345,7 +352,7 @@ public:
|
||||
drawTextEllipsized(2, 0, avail, buf);
|
||||
}
|
||||
fillRect(0, headerH() - sepH(), width(), sepH());
|
||||
if (menu_hint) drawContextMenuHint(LIGHT, menu_open);
|
||||
if (menu_hint) drawContextMenuHint(UIColor::primary_txt, menu_open);
|
||||
}
|
||||
|
||||
// Advance a UTF-8 pointer by one codepoint, returning the decoded value.
|
||||
|
||||
@@ -2,6 +2,17 @@
|
||||
|
||||
#include "../../MeshCore.h"
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = WHITE;
|
||||
ColorVal UIColor::title_bkg = WHITE;
|
||||
ColorVal UIColor::title_txt = BLACK;
|
||||
ColorVal UIColor::primary_txt = BLACK;
|
||||
ColorVal UIColor::secondary_txt = BLACK;
|
||||
ColorVal UIColor::warning_txt = BLACK;
|
||||
ColorVal UIColor::popup_bkg = WHITE;
|
||||
ColorVal UIColor::popup_txt = BLACK;
|
||||
ColorVal UIColor::corp_blue = BLACK;
|
||||
|
||||
BaseDisplay* E213Display::detectEInk()
|
||||
{
|
||||
// Test 1: Logic of BUSY pin
|
||||
@@ -108,16 +119,18 @@ void E213Display::clear() {
|
||||
display->clear();
|
||||
}
|
||||
|
||||
void E213Display::startFrame(Color bkg) {
|
||||
void E213Display::startFrame(ColorVal bkg) {
|
||||
display_crc.reset();
|
||||
|
||||
// Fill screen with white first to ensure clean background
|
||||
display->fillRect(0, 0, width(), height(), WHITE);
|
||||
|
||||
if (bkg == LIGHT) {
|
||||
if (bkg == 0) {
|
||||
// Fill with black if light background requested (inverted for e-ink)
|
||||
display->fillRect(0, 0, width(), height(), BLACK);
|
||||
}
|
||||
_color = UIColor::primary_txt;
|
||||
display->setTextColor(_color);
|
||||
}
|
||||
|
||||
void E213Display::setTextSize(int sz) {
|
||||
@@ -126,9 +139,10 @@ void E213Display::setTextSize(int sz) {
|
||||
display->setTextSize(sz);
|
||||
}
|
||||
|
||||
void E213Display::setColor(Color c) {
|
||||
display_crc.update<Color>(c);
|
||||
// implemented in individual display methods
|
||||
void E213Display::setColor(ColorVal c) {
|
||||
_color = c;
|
||||
display_crc.update<ColorVal>(c);
|
||||
display->setTextColor(_color);
|
||||
}
|
||||
|
||||
void E213Display::setCursor(int x, int y) {
|
||||
@@ -147,7 +161,7 @@ void E213Display::fillRect(int x, int y, int w, int h) {
|
||||
display_crc.update<int>(y);
|
||||
display_crc.update<int>(w);
|
||||
display_crc.update<int>(h);
|
||||
display->fillRect(x, y, w, h, BLACK);
|
||||
display->fillRect(x, y, w, h, _color);
|
||||
}
|
||||
|
||||
void E213Display::drawRect(int x, int y, int w, int h) {
|
||||
@@ -155,7 +169,7 @@ void E213Display::drawRect(int x, int y, int w, int h) {
|
||||
display_crc.update<int>(y);
|
||||
display_crc.update<int>(w);
|
||||
display_crc.update<int>(h);
|
||||
display->drawRect(x, y, w, h, BLACK);
|
||||
display->drawRect(x, y, w, h, _color);
|
||||
}
|
||||
|
||||
void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
|
||||
@@ -179,7 +193,7 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
|
||||
|
||||
// If the bit is set, draw the pixel
|
||||
if (bitSet) {
|
||||
display->drawPixel(x + bx, y + by, BLACK);
|
||||
display->drawPixel(x + bx, y + by, _color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ class E213Display : public DisplayDriver {
|
||||
RefCountedDigitalPin* _periph_power;
|
||||
CRC32 display_crc;
|
||||
uint32_t last_display_crc_value = 0;
|
||||
uint16_t _color;
|
||||
|
||||
public:
|
||||
E213Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(250, 122), _periph_power(periph_power) {}
|
||||
@@ -30,9 +31,9 @@ public:
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal 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;
|
||||
|
||||
@@ -2,6 +2,17 @@
|
||||
|
||||
#include "../../MeshCore.h"
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = WHITE;
|
||||
ColorVal UIColor::title_bkg = WHITE;
|
||||
ColorVal UIColor::title_txt = BLACK;
|
||||
ColorVal UIColor::primary_txt = BLACK;
|
||||
ColorVal UIColor::secondary_txt = BLACK;
|
||||
ColorVal UIColor::warning_txt = BLACK;
|
||||
ColorVal UIColor::popup_bkg = WHITE;
|
||||
ColorVal UIColor::popup_txt = BLACK;
|
||||
ColorVal UIColor::corp_blue = BLACK;
|
||||
|
||||
bool E290Display::begin() {
|
||||
if (_init) return true;
|
||||
|
||||
@@ -62,15 +73,17 @@ void E290Display::clear() {
|
||||
display.clear();
|
||||
}
|
||||
|
||||
void E290Display::startFrame(Color bkg) {
|
||||
void E290Display::startFrame(ColorVal bkg) {
|
||||
display_crc.reset();
|
||||
|
||||
// Fill screen with white first to ensure clean background
|
||||
display.fillRect(0, 0, width(), height(), WHITE);
|
||||
if (bkg == LIGHT) {
|
||||
if (bkg == 0) {
|
||||
// Fill with black if light background requested (inverted for e-ink)
|
||||
display.fillRect(0, 0, width(), height(), BLACK);
|
||||
}
|
||||
_color = UIColor::primary_txt;
|
||||
display.setTextColor(_color);
|
||||
}
|
||||
|
||||
void E290Display::setTextSize(int sz) {
|
||||
@@ -79,9 +92,10 @@ void E290Display::setTextSize(int sz) {
|
||||
display.setTextSize(sz);
|
||||
}
|
||||
|
||||
void E290Display::setColor(Color c) {
|
||||
display_crc.update<Color>(c);
|
||||
// implemented in individual display methods
|
||||
void E290Display::setColor(ColorVal c) {
|
||||
_color = c;
|
||||
display_crc.update<ColorVal>(c);
|
||||
display.setTextColor(_color);
|
||||
}
|
||||
|
||||
void E290Display::setCursor(int x, int y) {
|
||||
@@ -100,7 +114,7 @@ void E290Display::fillRect(int x, int y, int w, int h) {
|
||||
display_crc.update<int>(y);
|
||||
display_crc.update<int>(w);
|
||||
display_crc.update<int>(h);
|
||||
display.fillRect(x, y, w, h, BLACK);
|
||||
display.fillRect(x, y, w, h, _color);
|
||||
}
|
||||
|
||||
void E290Display::drawRect(int x, int y, int w, int h) {
|
||||
@@ -108,7 +122,7 @@ void E290Display::drawRect(int x, int y, int w, int h) {
|
||||
display_crc.update<int>(y);
|
||||
display_crc.update<int>(w);
|
||||
display_crc.update<int>(h);
|
||||
display.drawRect(x, y, w, h, BLACK);
|
||||
display.drawRect(x, y, w, h, _color);
|
||||
}
|
||||
|
||||
void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
|
||||
@@ -132,7 +146,7 @@ void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
|
||||
|
||||
// If the bit is set, draw the pixel
|
||||
if (bitSet) {
|
||||
display.drawPixel(x + bx, y + by, BLACK);
|
||||
display.drawPixel(x + bx, y + by, _color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ class E290Display : public DisplayDriver {
|
||||
RefCountedDigitalPin* _periph_power;
|
||||
CRC32 display_crc;
|
||||
uint32_t last_display_crc_value = 0;
|
||||
uint16_t _color;
|
||||
|
||||
public:
|
||||
E290Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(296, 128), _periph_power(periph_power) {}
|
||||
@@ -26,9 +27,9 @@ public:
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal 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;
|
||||
|
||||
@@ -25,8 +25,7 @@ class Adafruit_GFX;
|
||||
|
||||
class EinkGfxDisplay : public DisplayDriver {
|
||||
Adafruit_GFX& _gfx;
|
||||
const uint16_t _ink, _paper; // LIGHT and DARK in the panel's colours
|
||||
uint16_t _curr;
|
||||
ColorVal _curr;
|
||||
const GFXfont* _font;
|
||||
int _cell_w = 6, _cell_h = 9; // the font's cell, before _px and the text size
|
||||
int _px = 1; // pixel multiplier (landscape: EINK_FONT_PX, or Text size)
|
||||
@@ -43,7 +42,7 @@ class EinkGfxDisplay : public DisplayDriver {
|
||||
template <class T> void mix(T v) { mix(&v, sizeof(v)); }
|
||||
|
||||
protected:
|
||||
EinkGfxDisplay(int w, int h, Adafruit_GFX& gfx, uint16_t ink, uint16_t paper);
|
||||
EinkGfxDisplay(int w, int h, Adafruit_GFX& gfx);
|
||||
|
||||
// After a size or rotation change: picks the font for the new shape.
|
||||
void updateLayout();
|
||||
@@ -83,9 +82,9 @@ public:
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal 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;
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
#define EINK_LARGE_GFXFONT MiscFixed8x13
|
||||
#endif
|
||||
|
||||
EinkGfxDisplay::EinkGfxDisplay(int w, int h, Adafruit_GFX& gfx, uint16_t ink, uint16_t paper)
|
||||
: DisplayDriver(w, h), _gfx(gfx), _ink(ink), _paper(paper), _curr(ink), _font(&MiscFixed) {
|
||||
EinkGfxDisplay::EinkGfxDisplay(int w, int h, Adafruit_GFX& gfx)
|
||||
: DisplayDriver(w, h), _gfx(gfx), _curr(UIColor::primary_txt), _font(&MiscFixed) {
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ void EinkGfxDisplay::updateLayout() {
|
||||
_force = true;
|
||||
}
|
||||
|
||||
void EinkGfxDisplay::startFrame(Color bkg) {
|
||||
_gfx.fillScreen(_paper);
|
||||
_curr = _ink;
|
||||
void EinkGfxDisplay::startFrame(ColorVal bkg) {
|
||||
_gfx.fillScreen(bkg);
|
||||
_curr = UIColor::primary_txt;
|
||||
_text_sz = 1;
|
||||
_hash = 2166136261u;
|
||||
}
|
||||
@@ -51,9 +51,9 @@ void EinkGfxDisplay::setTextSize(int sz) {
|
||||
mix<int>(sz);
|
||||
}
|
||||
|
||||
void EinkGfxDisplay::setColor(Color c) {
|
||||
mix<Color>(c);
|
||||
_curr = (c == DARK) ? _paper : _ink; // DARK is the paper, LIGHT the ink
|
||||
void EinkGfxDisplay::setColor(ColorVal c) {
|
||||
mix<ColorVal>(c);
|
||||
_curr = c;
|
||||
}
|
||||
|
||||
void EinkGfxDisplay::setCursor(int x, int y) {
|
||||
|
||||
@@ -22,6 +22,17 @@
|
||||
#define EINK_SPI_HZ 4000000
|
||||
#endif
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = GxEPD_WHITE;
|
||||
ColorVal UIColor::title_bkg = GxEPD_WHITE;
|
||||
ColorVal UIColor::title_txt = GxEPD_BLACK;
|
||||
ColorVal UIColor::primary_txt = GxEPD_BLACK;
|
||||
ColorVal UIColor::secondary_txt = GxEPD_BLACK;
|
||||
ColorVal UIColor::warning_txt = GxEPD_BLACK;
|
||||
ColorVal UIColor::popup_bkg = GxEPD_WHITE;
|
||||
ColorVal UIColor::popup_txt = GxEPD_BLACK;
|
||||
ColorVal UIColor::corp_blue = GxEPD_BLACK;
|
||||
|
||||
bool GxEPDDisplay::begin() {
|
||||
display.epd2.selectSPI(SPI1, SPISettings(EINK_SPI_HZ, MSBFIRST, SPI_MODE0));
|
||||
#ifdef ESP32
|
||||
|
||||
@@ -92,7 +92,7 @@ class GxEPDDisplay : private GxEPDPanel, public EinkGfxDisplay {
|
||||
}
|
||||
|
||||
public:
|
||||
GxEPDDisplay() : EinkGfxDisplay(EINK_DISP_W, EINK_DISP_H, display, GxEPD_BLACK, GxEPD_WHITE) {}
|
||||
GxEPDDisplay() : EinkGfxDisplay(EINK_DISP_W, EINK_DISP_H, display) {}
|
||||
|
||||
#ifdef ENABLE_SCREENSHOT
|
||||
const uint8_t* getBuffer() override { return display.getBuffer(); }
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
#include "LGFXDisplay.h"
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = 0xFFFF;
|
||||
ColorVal UIColor::title_bkg = 0x001F;
|
||||
ColorVal UIColor::title_txt = 0xFFFF;
|
||||
ColorVal UIColor::primary_txt = 0x0000;
|
||||
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
|
||||
ColorVal UIColor::warning_txt = 0xFD20;
|
||||
ColorVal UIColor::popup_bkg = 0x07FF; // CYAN
|
||||
ColorVal UIColor::popup_txt = 0x0000;
|
||||
ColorVal UIColor::corp_blue = 0x001A;
|
||||
|
||||
bool LGFXDisplay::begin() {
|
||||
turnOn();
|
||||
display->init();
|
||||
@@ -35,45 +46,20 @@ void LGFXDisplay::clear() {
|
||||
buffer.clearDisplay();
|
||||
}
|
||||
|
||||
void LGFXDisplay::startFrame(Color bkg) {
|
||||
void LGFXDisplay::startFrame(ColorVal bkg) {
|
||||
// display->startWrite();
|
||||
// display->getScanLine();
|
||||
buffer.clearDisplay();
|
||||
buffer.setTextColor(TFT_WHITE);
|
||||
_color = bkg;
|
||||
buffer.fillScreen(_color);
|
||||
buffer.setTextColor(_color = UIColor::primary_txt);
|
||||
}
|
||||
|
||||
void LGFXDisplay::setTextSize(int sz) {
|
||||
buffer.setTextSize(sz);
|
||||
}
|
||||
|
||||
void LGFXDisplay::setColor(Color c) {
|
||||
// _color = (c != 0) ? ILI9342_WHITE : ILI9342_BLACK;
|
||||
switch (c) {
|
||||
case DARK:
|
||||
_color = TFT_BLACK;
|
||||
break;
|
||||
case LIGHT:
|
||||
_color = TFT_WHITE;
|
||||
break;
|
||||
case RED:
|
||||
_color = TFT_RED;
|
||||
break;
|
||||
case GREEN:
|
||||
_color = TFT_GREEN;
|
||||
break;
|
||||
case BLUE:
|
||||
_color = TFT_BLUE;
|
||||
break;
|
||||
case YELLOW:
|
||||
_color = TFT_YELLOW;
|
||||
break;
|
||||
case ORANGE:
|
||||
_color = TFT_ORANGE;
|
||||
break;
|
||||
default:
|
||||
_color = TFT_WHITE;
|
||||
}
|
||||
buffer.setTextColor(_color);
|
||||
void LGFXDisplay::setColor(ColorVal c) {
|
||||
buffer.setTextColor(_color = c);
|
||||
}
|
||||
|
||||
void LGFXDisplay::setCursor(int x, int y) {
|
||||
|
||||
@@ -25,9 +25,9 @@ public:
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal 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;
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
#include "NullDisplayDriver.h"
|
||||
|
||||
ColorVal UIColor::window_bkg = 0;
|
||||
ColorVal UIColor::title_bkg = 0;
|
||||
ColorVal UIColor::title_txt = 0;
|
||||
ColorVal UIColor::primary_txt = 0;
|
||||
ColorVal UIColor::secondary_txt = 0;
|
||||
ColorVal UIColor::warning_txt = 0;
|
||||
ColorVal UIColor::popup_bkg = 0;
|
||||
ColorVal UIColor::popup_txt = 0;
|
||||
ColorVal UIColor::corp_blue = 0;
|
||||
|
||||
@@ -11,9 +11,9 @@ public:
|
||||
void turnOn() override { }
|
||||
void turnOff() override { }
|
||||
void clear() override { }
|
||||
void startFrame(Color bkg = DARK) override { }
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override { }
|
||||
void setTextSize(int sz) override { }
|
||||
void setColor(Color c) override { }
|
||||
void setColor(ColorVal 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 { }
|
||||
|
||||
@@ -11,6 +11,17 @@ bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr)
|
||||
return (error == 0);
|
||||
}
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = SH110X_BLACK;
|
||||
ColorVal UIColor::title_bkg = SH110X_BLACK;
|
||||
ColorVal UIColor::title_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::primary_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::secondary_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::warning_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::popup_bkg = SH110X_BLACK;
|
||||
ColorVal UIColor::popup_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::corp_blue = SH110X_WHITE;
|
||||
|
||||
bool SH1106Display::begin()
|
||||
{
|
||||
// Wire must already be initialised by board.begin() before this is called.
|
||||
@@ -55,7 +66,7 @@ void SH1106Display::clear()
|
||||
_force_redraw = true; // next endFrame() must flush even if its CRC matches a pre-clear frame
|
||||
}
|
||||
|
||||
void SH1106Display::startFrame(Color bkg)
|
||||
void SH1106Display::startFrame(ColorVal bkg)
|
||||
{
|
||||
display.clearDisplay(); // TODO: apply 'bkg'
|
||||
_color = SH110X_WHITE;
|
||||
@@ -102,9 +113,9 @@ void SH1106Display::setTextSize(int sz)
|
||||
display.setTextSize(sz);
|
||||
}
|
||||
|
||||
void SH1106Display::setColor(Color c)
|
||||
void SH1106Display::setColor(ColorVal c)
|
||||
{
|
||||
_color = (c != 0) ? SH110X_WHITE : SH110X_BLACK;
|
||||
_color = c;
|
||||
display.setTextColor(_color);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,11 @@ public:
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
bool slideBegin(int y0) override;
|
||||
void slideCompose(int dx) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal 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;
|
||||
|
||||
@@ -9,6 +9,17 @@ bool SSD1306Display::i2c_probe(TwoWire& wire, uint8_t addr) {
|
||||
return (error == 0);
|
||||
}
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = SSD1306_BLACK;
|
||||
ColorVal UIColor::title_bkg = SSD1306_BLACK;
|
||||
ColorVal UIColor::title_txt = SSD1306_WHITE;
|
||||
ColorVal UIColor::primary_txt = SSD1306_WHITE;
|
||||
ColorVal UIColor::secondary_txt = SSD1306_WHITE;
|
||||
ColorVal UIColor::warning_txt = SSD1306_WHITE;
|
||||
ColorVal UIColor::popup_bkg = SSD1306_BLACK;
|
||||
ColorVal UIColor::popup_txt = SSD1306_WHITE;
|
||||
ColorVal UIColor::corp_blue = SSD1306_WHITE;
|
||||
|
||||
bool SSD1306Display::begin() {
|
||||
if (!_isOn) {
|
||||
if (_peripher_power) _peripher_power->claim();
|
||||
@@ -50,7 +61,7 @@ void SSD1306Display::clear() {
|
||||
_force_redraw = true; // next endFrame() must flush even if its hash matches a pre-clear frame
|
||||
}
|
||||
|
||||
void SSD1306Display::startFrame(Color bkg) {
|
||||
void SSD1306Display::startFrame(ColorVal bkg) {
|
||||
display.clearDisplay(); // TODO: apply 'bkg'
|
||||
_color = SSD1306_WHITE;
|
||||
display.setTextColor(_color);
|
||||
@@ -64,8 +75,8 @@ void SSD1306Display::setTextSize(int sz) {
|
||||
display.setTextSize(sz);
|
||||
}
|
||||
|
||||
void SSD1306Display::setColor(Color c) {
|
||||
_color = (c != 0) ? SSD1306_WHITE : SSD1306_BLACK;
|
||||
void SSD1306Display::setColor(ColorVal c) {
|
||||
_color = c;
|
||||
display.setTextColor(_color);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,9 +86,9 @@ public:
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal 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;
|
||||
|
||||
@@ -1,12 +1,409 @@
|
||||
#include "ST7735Display.h"
|
||||
|
||||
#ifndef DISPLAY_ROTATION
|
||||
#define DISPLAY_ROTATION 2
|
||||
//#include <Fonts/GFXFF/FreeSans9pt7b.h>
|
||||
|
||||
// Optimised ST7735 display driver, derived from Adafruit_ST7735 library.
|
||||
|
||||
#define ST_CMD_DELAY 0x80 // special signifier for command lists
|
||||
|
||||
#define ST77XX_NOP 0x00
|
||||
#define ST77XX_SWRESET 0x01
|
||||
#define ST77XX_RDDID 0x04
|
||||
#define ST77XX_RDDST 0x09
|
||||
|
||||
#define ST77XX_SLPIN 0x10
|
||||
#define ST77XX_SLPOUT 0x11
|
||||
#define ST77XX_PTLON 0x12
|
||||
#define ST77XX_NORON 0x13
|
||||
|
||||
#define ST77XX_INVOFF 0x20
|
||||
#define ST77XX_INVON 0x21
|
||||
#define ST77XX_DISPOFF 0x28
|
||||
#define ST77XX_DISPON 0x29
|
||||
#define ST77XX_CASET 0x2A
|
||||
#define ST77XX_RASET 0x2B
|
||||
#define ST77XX_RAMWR 0x2C
|
||||
#define ST77XX_RAMRD 0x2E
|
||||
|
||||
#define ST77XX_PTLAR 0x30
|
||||
#define ST77XX_TEOFF 0x34
|
||||
#define ST77XX_TEON 0x35
|
||||
#define ST77XX_MADCTL 0x36
|
||||
#define ST77XX_COLMOD 0x3A
|
||||
|
||||
#define ST77XX_MADCTL_MY 0x80
|
||||
#define ST77XX_MADCTL_MX 0x40
|
||||
#define ST77XX_MADCTL_MV 0x20
|
||||
#define ST77XX_MADCTL_ML 0x10
|
||||
#define ST77XX_MADCTL_RGB 0x00
|
||||
|
||||
#define ST77XX_RDID1 0xDA
|
||||
#define ST77XX_RDID2 0xDB
|
||||
#define ST77XX_RDID3 0xDC
|
||||
#define ST77XX_RDID4 0xDD
|
||||
|
||||
// Some ready-made 16-bit ('565') color settings:
|
||||
#define ST77XX_BLACK 0x0000
|
||||
#define ST77XX_WHITE 0xFFFF
|
||||
#define ST77XX_RED 0xF800
|
||||
#define ST77XX_GREEN 0x07E0
|
||||
#define ST77XX_BLUE 0x001F
|
||||
#define ST77XX_CYAN 0x07FF
|
||||
#define ST77XX_MAGENTA 0xF81F
|
||||
#define ST77XX_YELLOW 0xFFE0
|
||||
#define ST77XX_ORANGE 0xFC00
|
||||
|
||||
|
||||
// some flags for initR() :(
|
||||
#define INITR_GREENTAB 0x00
|
||||
#define INITR_REDTAB 0x01
|
||||
#define INITR_BLACKTAB 0x02
|
||||
#define INITR_18GREENTAB INITR_GREENTAB
|
||||
#define INITR_18REDTAB INITR_REDTAB
|
||||
#define INITR_18BLACKTAB INITR_BLACKTAB
|
||||
#define INITR_144GREENTAB 0x01
|
||||
#define INITR_MINI160x80 0x04
|
||||
#define INITR_HALLOWING 0x05
|
||||
#define INITR_MINI160x80_PLUGIN 0x06
|
||||
|
||||
// Some register settings
|
||||
#define ST7735_MADCTL_BGR 0x08
|
||||
#define ST7735_MADCTL_MH 0x04
|
||||
|
||||
#define ST7735_FRMCTR1 0xB1
|
||||
#define ST7735_FRMCTR2 0xB2
|
||||
#define ST7735_FRMCTR3 0xB3
|
||||
#define ST7735_INVCTR 0xB4
|
||||
#define ST7735_DISSET5 0xB6
|
||||
|
||||
#define ST7735_PWCTR1 0xC0
|
||||
#define ST7735_PWCTR2 0xC1
|
||||
#define ST7735_PWCTR3 0xC2
|
||||
#define ST7735_PWCTR4 0xC3
|
||||
#define ST7735_PWCTR5 0xC4
|
||||
#define ST7735_VMCTR1 0xC5
|
||||
|
||||
#define ST7735_PWCTR6 0xFC
|
||||
|
||||
#define ST7735_GMCTRP1 0xE0
|
||||
#define ST7735_GMCTRN1 0xE1
|
||||
|
||||
// Some ready-made 16-bit ('565') color settings:
|
||||
#define ST7735_BLACK ST77XX_BLACK
|
||||
#define ST7735_WHITE ST77XX_WHITE
|
||||
#define ST7735_RED ST77XX_RED
|
||||
#define ST7735_GREEN ST77XX_GREEN
|
||||
#define ST7735_BLUE ST77XX_BLUE
|
||||
#define ST7735_CYAN ST77XX_CYAN
|
||||
#define ST7735_MAGENTA ST77XX_MAGENTA
|
||||
#define ST7735_YELLOW ST77XX_YELLOW
|
||||
#define ST7735_ORANGE ST77XX_ORANGE
|
||||
|
||||
static TFT_eSPI lcd = TFT_eSPI(160, 80);
|
||||
static uint32_t curr_color;
|
||||
|
||||
#if defined(HELTEC_LORA_V3) || defined(HELTEC_TRACKER_V2)
|
||||
static SPIClass tft_spi(HSPI);
|
||||
#define _spi (&tft_spi)
|
||||
#else
|
||||
#define _spi (&SPI1)
|
||||
#endif
|
||||
|
||||
SPISettings _spiSettings = SPISettings(40000000, MSBFIRST, SPI_MODE0);
|
||||
|
||||
// clang-format off
|
||||
static const uint8_t PROGMEM
|
||||
Bcmd[] = { // Init commands for 7735B screens
|
||||
18, // 18 commands in list:
|
||||
ST77XX_SWRESET, ST_CMD_DELAY, // 1: Software reset, no args, w/delay
|
||||
50, // 50 ms delay
|
||||
ST77XX_SLPOUT, ST_CMD_DELAY, // 2: Out of sleep mode, no args, w/delay
|
||||
255, // 255 = max (500 ms) delay
|
||||
ST77XX_COLMOD, 1+ST_CMD_DELAY, // 3: Set color mode, 1 arg + delay:
|
||||
0x05, // 16-bit color
|
||||
10, // 10 ms delay
|
||||
ST7735_FRMCTR1, 3+ST_CMD_DELAY, // 4: Frame rate control, 3 args + delay:
|
||||
0x00, // fastest refresh
|
||||
0x06, // 6 lines front porch
|
||||
0x03, // 3 lines back porch
|
||||
10, // 10 ms delay
|
||||
ST77XX_MADCTL, 1, // 5: Mem access ctl (directions), 1 arg:
|
||||
0x08, // Row/col addr, bottom-top refresh
|
||||
ST7735_DISSET5, 2, // 6: Display settings #5, 2 args:
|
||||
0x15, // 1 clk cycle nonoverlap, 2 cycle gate
|
||||
// rise, 3 cycle osc equalize
|
||||
0x02, // Fix on VTL
|
||||
ST7735_INVCTR, 1, // 7: Display inversion control, 1 arg:
|
||||
0x0, // Line inversion
|
||||
ST7735_PWCTR1, 2+ST_CMD_DELAY, // 8: Power control, 2 args + delay:
|
||||
0x02, // GVDD = 4.7V
|
||||
0x70, // 1.0uA
|
||||
10, // 10 ms delay
|
||||
ST7735_PWCTR2, 1, // 9: Power control, 1 arg, no delay:
|
||||
0x05, // VGH = 14.7V, VGL = -7.35V
|
||||
ST7735_PWCTR3, 2, // 10: Power control, 2 args, no delay:
|
||||
0x01, // Opamp current small
|
||||
0x02, // Boost frequency
|
||||
ST7735_VMCTR1, 2+ST_CMD_DELAY, // 11: Power control, 2 args + delay:
|
||||
0x3C, // VCOMH = 4V
|
||||
0x38, // VCOML = -1.1V
|
||||
10, // 10 ms delay
|
||||
ST7735_PWCTR6, 2, // 12: Power control, 2 args, no delay:
|
||||
0x11, 0x15,
|
||||
ST7735_GMCTRP1,16, // 13: Gamma Adjustments (pos. polarity), 16 args + delay:
|
||||
0x09, 0x16, 0x09, 0x20, // (Not entirely necessary, but provides
|
||||
0x21, 0x1B, 0x13, 0x19, // accurate colors)
|
||||
0x17, 0x15, 0x1E, 0x2B,
|
||||
0x04, 0x05, 0x02, 0x0E,
|
||||
ST7735_GMCTRN1,16+ST_CMD_DELAY, // 14: Gamma Adjustments (neg. polarity), 16 args + delay:
|
||||
0x0B, 0x14, 0x08, 0x1E, // (Not entirely necessary, but provides
|
||||
0x22, 0x1D, 0x18, 0x1E, // accurate colors)
|
||||
0x1B, 0x1A, 0x24, 0x2B,
|
||||
0x06, 0x06, 0x02, 0x0F,
|
||||
10, // 10 ms delay
|
||||
ST77XX_CASET, 4, // 15: Column addr set, 4 args, no delay:
|
||||
0x00, 0x02, // XSTART = 2
|
||||
0x00, 0x81, // XEND = 129
|
||||
ST77XX_RASET, 4, // 16: Row addr set, 4 args, no delay:
|
||||
0x00, 0x02, // XSTART = 1
|
||||
0x00, 0x81, // XEND = 160
|
||||
ST77XX_NORON, ST_CMD_DELAY, // 17: Normal display on, no args, w/delay
|
||||
10, // 10 ms delay
|
||||
ST77XX_DISPON, ST_CMD_DELAY, // 18: Main screen turn on, no args, delay
|
||||
255 }, // 255 = max (500 ms) delay
|
||||
|
||||
Rcmd1[] = { // 7735R init, part 1 (red or green tab)
|
||||
14, // 14 commands in list:
|
||||
/*ST77XX_SWRESET, ST_CMD_DELAY, // 1: Software reset, 0 args, w/delay
|
||||
150, */ // 150 ms delay
|
||||
ST77XX_SLPOUT, ST_CMD_DELAY, // 2: Out of sleep mode, 0 args, w/delay
|
||||
120, // 120 ms delay
|
||||
ST7735_FRMCTR1, 3, // 3: Framerate ctrl - normal mode, 3 arg:
|
||||
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
|
||||
ST7735_FRMCTR2, 3, // 4: Framerate ctrl - idle mode, 3 args:
|
||||
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
|
||||
ST7735_FRMCTR3, 6, // 5: Framerate - partial mode, 6 args:
|
||||
0x01, 0x2C, 0x2D, // Dot inversion mode
|
||||
0x01, 0x2C, 0x2D, // Line inversion mode
|
||||
ST7735_INVCTR, 1, // 6: Display inversion ctrl, 1 arg:
|
||||
0x07, // No inversion
|
||||
ST7735_PWCTR1, 3, // 7: Power control, 3 args, no delay:
|
||||
0xA2,
|
||||
0x02, // -4.6V
|
||||
0x84, // AUTO mode
|
||||
ST7735_PWCTR2, 1, // 8: Power control, 1 arg, no delay:
|
||||
0xC5, // VGH25=2.4C VGSEL=-10 VGH=3 * AVDD
|
||||
ST7735_PWCTR3, 2, // 9: Power control, 2 args, no delay:
|
||||
0x0A, // Opamp current small
|
||||
0x00, // Boost frequency
|
||||
ST7735_PWCTR4, 2, // 10: Power control, 2 args, no delay:
|
||||
0x8A, // BCLK/2,
|
||||
0x2A, // opamp current small & medium low
|
||||
ST7735_PWCTR5, 2, // 11: Power control, 2 args, no delay:
|
||||
0x8A, 0xEE,
|
||||
ST7735_VMCTR1, 1, // 12: Power control, 1 arg, no delay:
|
||||
0x0E,
|
||||
ST77XX_INVOFF, 0, // 13: Don't invert display, no args
|
||||
ST77XX_MADCTL, 1, // 14: Mem access ctl (directions), 1 arg:
|
||||
0xC8, // row/col addr, bottom-top refresh
|
||||
ST77XX_COLMOD, 1, // 15: set color mode, 1 arg, no delay:
|
||||
0x05 }, // 16-bit color
|
||||
|
||||
Rcmd2green[] = { // 7735R init, part 2 (green tab only)
|
||||
2, // 2 commands in list:
|
||||
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
|
||||
0x00, 0x02, // XSTART = 0
|
||||
0x00, 0x7F+0x02, // XEND = 127
|
||||
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
|
||||
0x00, 0x01, // XSTART = 0
|
||||
0x00, 0x9F+0x01 }, // XEND = 159
|
||||
|
||||
Rcmd2red[] = { // 7735R init, part 2 (red tab only)
|
||||
2, // 2 commands in list:
|
||||
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x7F, // XEND = 127
|
||||
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x9F }, // XEND = 159
|
||||
|
||||
Rcmd2green144[] = { // 7735R init, part 2 (green 1.44 tab)
|
||||
2, // 2 commands in list:
|
||||
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x7F, // XEND = 127
|
||||
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x7F }, // XEND = 127
|
||||
|
||||
Rcmd2green160x80[] = { // 7735R init, part 2 (mini 160x80)
|
||||
2, // 2 commands in list:
|
||||
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x4F, // XEND = 79
|
||||
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x9F }, // XEND = 159
|
||||
|
||||
Rcmd2green160x80plugin[] = { // 7735R init, part 2 (mini 160x80 with plugin FPC)
|
||||
3, // 3 commands in list:
|
||||
ST77XX_INVON, 0, // 1: Display is inverted
|
||||
ST77XX_CASET, 4, // 2: Column addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x4F, // XEND = 79
|
||||
ST77XX_RASET, 4, // 3: Row addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x9F }, // XEND = 159
|
||||
|
||||
Rcmd2invert[] = { // Tracker V1, part 2
|
||||
1, // 1 command in list:
|
||||
ST77XX_INVON, 0 }, // 1: Display is inverted
|
||||
|
||||
Rcmd3[] = { // 7735R init, part 3 (red or green tab)
|
||||
2, // 2 commands in list:
|
||||
ST7735_GMCTRP1, 16 , // 1: Gamma Adjustments (pos. polarity), 16 args + delay:
|
||||
0x02, 0x1c, 0x07, 0x12, // (Not entirely necessary, but provides
|
||||
0x37, 0x32, 0x29, 0x2d, // accurate colors)
|
||||
0x29, 0x25, 0x2B, 0x39,
|
||||
0x00, 0x01, 0x03, 0x10,
|
||||
ST7735_GMCTRN1, 16 , // 2: Gamma Adjustments (neg. polarity), 16 args + delay:
|
||||
0x03, 0x1d, 0x07, 0x06, // (Not entirely necessary, but provides
|
||||
0x2E, 0x2C, 0x29, 0x2D, // accurate colors)
|
||||
0x2E, 0x2E, 0x37, 0x3F,
|
||||
0x00, 0x00, 0x02, 0x10 }; // 100 ms delay
|
||||
|
||||
static int16_t _xstart = 0; ///< Internal framebuffer X offset
|
||||
static int16_t _ystart = 0; ///< Internal framebuffer Y offset
|
||||
static uint8_t _colstart = 0; ///< Some displays need this changed to offset
|
||||
static uint8_t _rowstart = 0; ///< Some displays need this changed to offset
|
||||
static uint8_t rotation = 0;
|
||||
static int16_t _width = 0; ///< Display width as modified by current rotation
|
||||
static int16_t _height = 0; ///< Display height as modified by current rotation
|
||||
|
||||
static void set_CS(uint8_t level) {
|
||||
//if (_cs != (uint8_t) -1) {
|
||||
digitalWrite(PIN_TFT_CS, level);
|
||||
//}
|
||||
}
|
||||
static void sendCommand(uint8_t com) {
|
||||
set_CS(HIGH);
|
||||
digitalWrite(PIN_TFT_DC, LOW);
|
||||
set_CS(LOW);
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
_spi->transfer(com);
|
||||
_spi->endTransaction();
|
||||
set_CS(HIGH);
|
||||
digitalWrite(PIN_TFT_DC, HIGH);
|
||||
}
|
||||
|
||||
static void WriteData(uint8_t data) {
|
||||
digitalWrite(PIN_TFT_CS, LOW);
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
_spi->transfer(data);
|
||||
_spi->endTransaction();
|
||||
digitalWrite(PIN_TFT_CS, HIGH);
|
||||
}
|
||||
static void SPI_WRITE32(uint32_t l) {
|
||||
_spi->transfer(l >> 24);
|
||||
_spi->transfer(l >> 16);
|
||||
_spi->transfer(l >> 8);
|
||||
_spi->transfer(l);
|
||||
}
|
||||
static void writeCommand(uint8_t cmd) {
|
||||
digitalWrite(PIN_TFT_DC, LOW);
|
||||
_spi->transfer(cmd);
|
||||
digitalWrite(PIN_TFT_DC, HIGH);
|
||||
}
|
||||
|
||||
static void displayInit(const uint8_t *addr) {
|
||||
uint8_t numCommands, cmd, numArgs;
|
||||
uint16_t ms;
|
||||
|
||||
numCommands = pgm_read_byte(addr++); // Number of commands to follow
|
||||
while (numCommands--) { // For each command...
|
||||
cmd = pgm_read_byte(addr++); // Read command
|
||||
numArgs = pgm_read_byte(addr++); // Number of args to follow
|
||||
ms = numArgs & ST_CMD_DELAY; // If hibit set, delay follows args
|
||||
numArgs &= ~ST_CMD_DELAY; // Mask out delay bit
|
||||
sendCommand(cmd);
|
||||
for (int k = 0; k < numArgs; k++) {
|
||||
WriteData(addr[k]);
|
||||
}
|
||||
addr += numArgs;
|
||||
|
||||
if (ms) {
|
||||
ms = pgm_read_byte(addr++); // Read post-command delay time (ms)
|
||||
if (ms == 255)
|
||||
ms = 500; // If 255, delay for 500 ms
|
||||
delay(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void setRotation(uint8_t m) {
|
||||
uint8_t madctl = 0;
|
||||
|
||||
rotation = m & 3; // can't be higher than 3
|
||||
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST7735_MADCTL_BGR;
|
||||
|
||||
_height = 160;
|
||||
_width = 80;
|
||||
_xstart = _colstart;
|
||||
_ystart = _rowstart;
|
||||
break;
|
||||
case 1:
|
||||
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST7735_MADCTL_BGR;
|
||||
|
||||
_width = 160;
|
||||
_height = 80;
|
||||
_ystart = _colstart;
|
||||
_xstart = _rowstart;
|
||||
break;
|
||||
case 2:
|
||||
madctl = ST7735_MADCTL_BGR;
|
||||
|
||||
_height = 160;
|
||||
_width = 80;
|
||||
_xstart = _colstart;
|
||||
_ystart = _rowstart;
|
||||
break;
|
||||
case 3:
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST7735_MADCTL_BGR;
|
||||
|
||||
_width = 160;
|
||||
_height = 80;
|
||||
_ystart = _colstart;
|
||||
_xstart = _rowstart;
|
||||
break;
|
||||
}
|
||||
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
}
|
||||
|
||||
static void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
x += _xstart;
|
||||
y += _ystart;
|
||||
uint32_t xa = ((uint32_t)x << 16) | (x + w - 1);
|
||||
uint32_t ya = ((uint32_t)y << 16) | (y + h - 1);
|
||||
|
||||
writeCommand(ST77XX_CASET); // Column addr set
|
||||
SPI_WRITE32(xa);
|
||||
|
||||
writeCommand(ST77XX_RASET); // Row addr set
|
||||
SPI_WRITE32(ya);
|
||||
|
||||
writeCommand(ST77XX_RAMWR); // write to RAM
|
||||
}
|
||||
|
||||
#define SCALE_X 1.25f // 160 / 128
|
||||
#define SCALE_Y 1.25f // 80 / 64
|
||||
|
||||
static TFT_eSprite *sprite = NULL;
|
||||
|
||||
bool ST7735Display::i2c_probe(TwoWire& wire, uint8_t addr) {
|
||||
return true;
|
||||
/*
|
||||
@@ -16,53 +413,121 @@ bool ST7735Display::i2c_probe(TwoWire& wire, uint8_t addr) {
|
||||
*/
|
||||
}
|
||||
|
||||
#ifndef PIN_TFT_LEDA_CTL_ACTIVE
|
||||
#define PIN_TFT_LEDA_CTL_ACTIVE HIGH
|
||||
#endif
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = ST77XX_WHITE;
|
||||
ColorVal UIColor::title_bkg = ST77XX_BLUE;
|
||||
ColorVal UIColor::title_txt = ST77XX_WHITE;
|
||||
ColorVal UIColor::primary_txt = ST77XX_BLACK;
|
||||
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
|
||||
ColorVal UIColor::warning_txt = ST77XX_ORANGE;
|
||||
ColorVal UIColor::popup_bkg = ST77XX_CYAN;
|
||||
ColorVal UIColor::popup_txt = ST77XX_BLACK;
|
||||
ColorVal UIColor::corp_blue = 0x001A;
|
||||
|
||||
bool ST7735Display::begin() {
|
||||
if (!sprite) {
|
||||
// alloc offscreen canvas
|
||||
sprite = new TFT_eSprite(&lcd);
|
||||
if (sprite) {
|
||||
if (sprite->createSprite(160, 80)) {
|
||||
sprite->fillScreen(ST77XX_BLACK);
|
||||
sprite->setTextColor(curr_color = ST77XX_WHITE);
|
||||
} else {
|
||||
Serial.printf("ST7735Display: failed to alloc canvas pixels");
|
||||
}
|
||||
} else {
|
||||
Serial.printf("ST7735Display: failed to alloc canvas");
|
||||
}
|
||||
}
|
||||
|
||||
if (!_isOn) {
|
||||
if (_peripher_power) _peripher_power->claim();
|
||||
|
||||
delay(100); // TEMP!!
|
||||
pinMode(PIN_TFT_RST, OUTPUT);
|
||||
pinMode(PIN_TFT_CS, OUTPUT);
|
||||
pinMode(PIN_TFT_DC, OUTPUT);
|
||||
pinMode(PIN_TFT_LEDA_CTL, OUTPUT);
|
||||
#if defined(PIN_TFT_LEDA_CTL_ACTIVE)
|
||||
digitalWrite(PIN_TFT_LEDA_CTL, PIN_TFT_LEDA_CTL_ACTIVE);
|
||||
#else
|
||||
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
|
||||
#endif
|
||||
digitalWrite(PIN_TFT_RST, HIGH);
|
||||
|
||||
#if defined(HELTEC_T1)
|
||||
display.initR(INITR_MINI160x80);
|
||||
display.setRotation(DISPLAY_ROTATION);
|
||||
#elif defined(HELTEC_TRACKER_V2) || defined(HELTEC_T096)
|
||||
display.initR(INITR_MINI160x80);
|
||||
display.setRotation(DISPLAY_ROTATION);
|
||||
uint8_t madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV |ST7735_MADCTL_BGR;//Adjust color to BGR
|
||||
display.sendCommand(ST77XX_MADCTL, &madctl, 1);
|
||||
#ifdef ESP_PLATFORM
|
||||
_spi->begin(PIN_TFT_SCL, -1 /* _miso */, PIN_TFT_SDA /* _mosi */, -1);
|
||||
#else
|
||||
display.initR(INITR_MINI160x80_PLUGIN);
|
||||
display.setRotation(DISPLAY_ROTATION);
|
||||
_spi->begin();
|
||||
#endif
|
||||
display.setSPISpeed(40000000);
|
||||
display.fillScreen(ST77XX_BLACK);
|
||||
display.setTextColor(ST77XX_WHITE);
|
||||
display.setTextSize(2);
|
||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||
_spi->setClockDivider(SPI_CLOCK_DIV2);
|
||||
|
||||
_height = 80;
|
||||
_width = 160;
|
||||
#if defined(HELTEC_LORA_V3) // Tracker v1
|
||||
_colstart = 26;
|
||||
_rowstart = 1;
|
||||
#else
|
||||
_colstart = 24;
|
||||
_rowstart = 0;
|
||||
#endif
|
||||
|
||||
_resetAndInit();
|
||||
|
||||
sendCommand(ST77XX_DISPON);
|
||||
|
||||
_isOn = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ST7735Display::_resetAndInit() {
|
||||
// Pulse Reset low for 10ms
|
||||
digitalWrite(PIN_TFT_RST, HIGH);
|
||||
delay(2);
|
||||
digitalWrite(PIN_TFT_RST, LOW);
|
||||
delay(10);
|
||||
digitalWrite(PIN_TFT_RST, HIGH);
|
||||
delay(2);
|
||||
|
||||
// run init commands
|
||||
displayInit(Rcmd1);
|
||||
#if defined(HELTEC_TRACKER_V2) || defined(HELTEC_T096)
|
||||
displayInit(Rcmd2green160x80);
|
||||
//uint8_t madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV |ST7735_MADCTL_BGR;//Adjust color to BGR
|
||||
//display.sendCommand(ST77XX_MADCTL, &madctl, 1);
|
||||
#elif defined(HELTEC_LORA_V3) // Tracker v1
|
||||
displayInit(Rcmd2invert); // invert RGB
|
||||
#endif
|
||||
displayInit(Rcmd3);
|
||||
setRotation(DISPLAY_ROTATION);
|
||||
|
||||
// clear the buffer before display on
|
||||
sprite->fillScreen(ST77XX_BLACK);
|
||||
endFrame();
|
||||
|
||||
// turn on backlight
|
||||
digitalWrite(PIN_TFT_LEDA_CTL, PIN_TFT_LEDA_CTL_ACTIVE);
|
||||
|
||||
}
|
||||
|
||||
void ST7735Display::turnOn() {
|
||||
ST7735Display::begin();
|
||||
if (!_isOn) {
|
||||
if (_peripher_power) _peripher_power->claim();
|
||||
_resetAndInit();
|
||||
sendCommand(ST77XX_DISPON);
|
||||
|
||||
// Now turn on the backlight
|
||||
// digitalWrite(PIN_TFT_LEDA_CTL, PIN_TFT_LEDA_CTL_ACTIVE);
|
||||
_isOn = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ST7735Display::turnOff() {
|
||||
if (_isOn) {
|
||||
digitalWrite(PIN_TFT_RST, LOW);
|
||||
#if defined(PIN_TFT_LEDA_CTL_ACTIVE)
|
||||
sendCommand(ST77XX_DISPOFF);
|
||||
|
||||
//digitalWrite(PIN_TFT_RST, LOW);
|
||||
// Now turn off the backlight
|
||||
digitalWrite(PIN_TFT_LEDA_CTL, !PIN_TFT_LEDA_CTL_ACTIVE);
|
||||
#else
|
||||
digitalWrite(PIN_TFT_LEDA_CTL, LOW);
|
||||
#endif
|
||||
_isOn = false;
|
||||
|
||||
if (_peripher_power) _peripher_power->release();
|
||||
@@ -70,78 +535,65 @@ void ST7735Display::turnOff() {
|
||||
}
|
||||
|
||||
void ST7735Display::clear() {
|
||||
//Serial.println("DBG: display.Clear");
|
||||
display.fillScreen(ST77XX_BLACK);
|
||||
sprite->fillScreen(ST77XX_BLACK);
|
||||
}
|
||||
|
||||
void ST7735Display::startFrame(Color bkg) {
|
||||
display.fillScreen(0x00);
|
||||
display.setTextColor(ST77XX_WHITE);
|
||||
display.setTextSize(1); // This one affects size of Please wait... message
|
||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||
void ST7735Display::startFrame(ColorVal bkg) {
|
||||
sprite->fillScreen(bkg);
|
||||
sprite->setTextColor(curr_color = UIColor::primary_txt);
|
||||
sprite->setFreeFont();
|
||||
sprite->setTextSize(1); // This one affects size of Please wait... message
|
||||
//sprite->cp437(true); // Use full 256 char 'Code Page 437' font
|
||||
}
|
||||
|
||||
void ST7735Display::setTextSize(int sz) {
|
||||
display.setTextSize(sz);
|
||||
sprite->setTextSize(sz);
|
||||
}
|
||||
|
||||
void ST7735Display::setColor(Color c) {
|
||||
switch (c) {
|
||||
case DisplayDriver::DARK :
|
||||
_color = ST77XX_BLACK;
|
||||
break;
|
||||
case DisplayDriver::LIGHT :
|
||||
_color = ST77XX_WHITE;
|
||||
break;
|
||||
case DisplayDriver::RED :
|
||||
_color = ST77XX_RED;
|
||||
break;
|
||||
case DisplayDriver::GREEN :
|
||||
_color = ST77XX_GREEN;
|
||||
break;
|
||||
case DisplayDriver::BLUE :
|
||||
_color = ST77XX_BLUE;
|
||||
break;
|
||||
case DisplayDriver::YELLOW :
|
||||
_color = ST77XX_YELLOW;
|
||||
break;
|
||||
case DisplayDriver::ORANGE :
|
||||
_color = ST77XX_ORANGE;
|
||||
break;
|
||||
default:
|
||||
_color = ST77XX_WHITE;
|
||||
break;
|
||||
}
|
||||
display.setTextColor(_color);
|
||||
void ST7735Display::setColor(ColorVal c) {
|
||||
curr_color = c;
|
||||
sprite->setTextColor(curr_color);
|
||||
}
|
||||
|
||||
void ST7735Display::setCursor(int x, int y) {
|
||||
display.setCursor(x*SCALE_X, y*SCALE_Y);
|
||||
sprite->setCursor(x*SCALE_X, y*SCALE_Y);
|
||||
}
|
||||
|
||||
void ST7735Display::print(const char* str) {
|
||||
display.print(str);
|
||||
sprite->print(str);
|
||||
}
|
||||
|
||||
void ST7735Display::fillRect(int x, int y, int w, int h) {
|
||||
display.fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _color);
|
||||
sprite->fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, curr_color);
|
||||
}
|
||||
|
||||
void ST7735Display::drawRect(int x, int y, int w, int h) {
|
||||
display.drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _color);
|
||||
sprite->drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, curr_color);
|
||||
}
|
||||
|
||||
void ST7735Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
|
||||
display.drawBitmap(x*SCALE_X, y*SCALE_Y, bits, w, h, _color);
|
||||
sprite->drawBitmap(x*SCALE_X, y*SCALE_Y, bits, w, h, curr_color);
|
||||
}
|
||||
|
||||
uint16_t ST7735Display::getTextWidth(const char* str) {
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
|
||||
return w / SCALE_X;
|
||||
return sprite->textWidth(str) / SCALE_X;
|
||||
}
|
||||
|
||||
void ST7735Display::endFrame() {
|
||||
// display.display();
|
||||
// blit the canvas buffer to LCD
|
||||
set_CS(LOW);
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
uint16_t x, y;
|
||||
uint16_t* pixels = (uint16_t *) ((TFT_eSprite *) sprite)->getPointer();
|
||||
for (y = 0; y < 80; y++, pixels += 160) {
|
||||
setAddrWindow(0, y, 160, 1);
|
||||
#ifdef ESP_PLATFORM
|
||||
_spi->transferBytes((uint8_t *)pixels, NULL, 2 * 160);
|
||||
#else
|
||||
_spi->transfer(pixels, NULL, 2 * 160);
|
||||
#endif
|
||||
}
|
||||
|
||||
_spi->endTransaction();
|
||||
set_CS(HIGH);
|
||||
}
|
||||
|
||||
@@ -3,28 +3,25 @@
|
||||
#include "DisplayDriver.h"
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_ST7735.h>
|
||||
#include "TFT_eSPI.h"
|
||||
#include <helpers/RefCountedDigitalPin.h>
|
||||
|
||||
class ST7735Display : public DisplayDriver {
|
||||
Adafruit_ST7735 display;
|
||||
bool _isOn;
|
||||
uint16_t _color;
|
||||
RefCountedDigitalPin* _peripher_power;
|
||||
|
||||
bool i2c_probe(TwoWire& wire, uint8_t addr);
|
||||
public:
|
||||
#ifdef USE_PIN_TFT
|
||||
ST7735Display(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
|
||||
display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST),
|
||||
// display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST),
|
||||
_peripher_power(peripher_power)
|
||||
{
|
||||
_isOn = false;
|
||||
}
|
||||
#else
|
||||
ST7735Display(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
|
||||
display(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST),
|
||||
// display(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST),
|
||||
_peripher_power(peripher_power)
|
||||
{
|
||||
_isOn = false;
|
||||
@@ -36,9 +33,9 @@ public:
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal 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;
|
||||
@@ -46,4 +43,7 @@ public:
|
||||
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
|
||||
uint16_t getTextWidth(const char* str) override;
|
||||
void endFrame() override;
|
||||
|
||||
protected:
|
||||
void _resetAndInit();
|
||||
};
|
||||
|
||||
@@ -33,6 +33,17 @@
|
||||
#define SCALE_Y DISPLAY_SCALE_Y
|
||||
#endif
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = OLEDDISPLAY_COLOR::BLACK;
|
||||
ColorVal UIColor::title_bkg = OLEDDISPLAY_COLOR::BLACK;
|
||||
ColorVal UIColor::title_txt = OLEDDISPLAY_COLOR::WHITE;
|
||||
ColorVal UIColor::primary_txt = OLEDDISPLAY_COLOR::WHITE;
|
||||
ColorVal UIColor::secondary_txt = OLEDDISPLAY_COLOR::WHITE;
|
||||
ColorVal UIColor::warning_txt = OLEDDISPLAY_COLOR::WHITE;
|
||||
ColorVal UIColor::popup_bkg = OLEDDISPLAY_COLOR::BLACK;
|
||||
ColorVal UIColor::popup_txt = OLEDDISPLAY_COLOR::WHITE;
|
||||
ColorVal UIColor::corp_blue = OLEDDISPLAY_COLOR::WHITE;
|
||||
|
||||
#ifdef OLED_MISC_FIXED_FONT
|
||||
// MiscFixedFont.h/LemonIcons.h store each glyph's rows bit-packed
|
||||
// *continuously* (Adafruit_GFX's native GFXfont convention -- no per-row byte
|
||||
@@ -132,10 +143,9 @@ void ST7789Display::clear() {
|
||||
display.clear();
|
||||
}
|
||||
|
||||
void ST7789Display::startFrame(Color bkg) {
|
||||
display.clear();
|
||||
_color = ST77XX_WHITE;
|
||||
display.setRGB(_color);
|
||||
void ST7789Display::startFrame(ColorVal bkg) {
|
||||
display.clear(); // TODO: use bkg
|
||||
setColor(UIColor::primary_txt);
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
}
|
||||
|
||||
@@ -152,38 +162,10 @@ void ST7789Display::setTextSize(int sz) {
|
||||
}
|
||||
}
|
||||
|
||||
void ST7789Display::setColor(Color c) {
|
||||
switch (c) {
|
||||
case DisplayDriver::DARK :
|
||||
_color = ST77XX_BLACK;
|
||||
display.setColor(OLEDDISPLAY_COLOR::BLACK);
|
||||
break;
|
||||
#if 0
|
||||
case DisplayDriver::LIGHT :
|
||||
_color = ST77XX_WHITE;
|
||||
break;
|
||||
case DisplayDriver::RED :
|
||||
_color = ST77XX_RED;
|
||||
break;
|
||||
case DisplayDriver::GREEN :
|
||||
_color = ST77XX_GREEN;
|
||||
break;
|
||||
case DisplayDriver::BLUE :
|
||||
_color = ST77XX_BLUE;
|
||||
break;
|
||||
case DisplayDriver::YELLOW :
|
||||
_color = ST77XX_YELLOW;
|
||||
break;
|
||||
case DisplayDriver::ORANGE :
|
||||
_color = ST77XX_ORANGE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
_color = ST77XX_WHITE;
|
||||
display.setColor(OLEDDISPLAY_COLOR::WHITE);
|
||||
break;
|
||||
}
|
||||
display.setRGB(_color);
|
||||
void ST7789Display::setColor(ColorVal c) {
|
||||
_color = c;
|
||||
display.setColor((OLEDDISPLAY_COLOR)_color);
|
||||
display.setRGB(_color == OLEDDISPLAY_COLOR::WHITE ? ST77XX_WHITE : ST77XX_BLACK);
|
||||
}
|
||||
|
||||
void ST7789Display::setCursor(int x, int y) {
|
||||
|
||||
@@ -56,9 +56,9 @@ public:
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal c) override;
|
||||
void setCursor(int x, int y) override;
|
||||
void print(const char* str) override;
|
||||
void printWordWrap(const char* str, int max_width) override;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#include "ST7789LCDDisplay.h"
|
||||
|
||||
#ifndef PIN_TFT_MISO
|
||||
#define PIN_TFT_MISO -1
|
||||
#endif
|
||||
|
||||
#ifndef DISPLAY_ROTATION
|
||||
#define DISPLAY_ROTATION 3
|
||||
#endif
|
||||
@@ -19,6 +23,17 @@ bool ST7789LCDDisplay::i2c_probe(TwoWire& wire, uint8_t addr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = ST77XX_WHITE;
|
||||
ColorVal UIColor::title_bkg = ST77XX_BLUE;
|
||||
ColorVal UIColor::title_txt = ST77XX_WHITE;
|
||||
ColorVal UIColor::primary_txt = ST77XX_BLACK;
|
||||
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
|
||||
ColorVal UIColor::warning_txt = ST77XX_ORANGE;
|
||||
ColorVal UIColor::popup_bkg = ST77XX_CYAN;
|
||||
ColorVal UIColor::popup_txt = ST77XX_BLACK;
|
||||
ColorVal UIColor::corp_blue = 0x001A;
|
||||
|
||||
bool ST7789LCDDisplay::begin() {
|
||||
if (!_isOn) {
|
||||
if (_peripher_power) _peripher_power->claim();
|
||||
@@ -29,8 +44,8 @@ bool ST7789LCDDisplay::begin() {
|
||||
}
|
||||
|
||||
// Im not sure if this is just a t-deck problem or not, if your display is slow try this.
|
||||
#if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT)
|
||||
displaySPI.begin(PIN_TFT_SCL, -1, PIN_TFT_SDA, PIN_TFT_CS);
|
||||
#if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT)
|
||||
displaySPI.begin(PIN_TFT_SCL, PIN_TFT_MISO, PIN_TFT_SDA, PIN_TFT_CS);
|
||||
#endif
|
||||
|
||||
display.init(DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
@@ -74,9 +89,9 @@ void ST7789LCDDisplay::clear() {
|
||||
display.fillScreen(ST77XX_BLACK);
|
||||
}
|
||||
|
||||
void ST7789LCDDisplay::startFrame(Color bkg) {
|
||||
display.fillScreen(ST77XX_BLACK);
|
||||
display.setTextColor(ST77XX_WHITE);
|
||||
void ST7789LCDDisplay::startFrame(ColorVal bkg) {
|
||||
display.fillScreen(bkg);
|
||||
display.setTextColor(_color = UIColor::primary_txt);
|
||||
display.setTextSize(1 * DISPLAY_SCALE_X); // This one affects size of Please wait... message
|
||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||
}
|
||||
@@ -85,34 +100,8 @@ void ST7789LCDDisplay::setTextSize(int sz) {
|
||||
display.setTextSize(sz * DISPLAY_SCALE_X);
|
||||
}
|
||||
|
||||
void ST7789LCDDisplay::setColor(Color c) {
|
||||
switch (c) {
|
||||
case DisplayDriver::DARK :
|
||||
_color = ST77XX_BLACK;
|
||||
break;
|
||||
case DisplayDriver::LIGHT :
|
||||
_color = ST77XX_WHITE;
|
||||
break;
|
||||
case DisplayDriver::RED :
|
||||
_color = ST77XX_RED;
|
||||
break;
|
||||
case DisplayDriver::GREEN :
|
||||
_color = ST77XX_GREEN;
|
||||
break;
|
||||
case DisplayDriver::BLUE :
|
||||
_color = ST77XX_BLUE;
|
||||
break;
|
||||
case DisplayDriver::YELLOW :
|
||||
_color = ST77XX_YELLOW;
|
||||
break;
|
||||
case DisplayDriver::ORANGE :
|
||||
_color = ST77XX_ORANGE;
|
||||
break;
|
||||
default:
|
||||
_color = ST77XX_WHITE;
|
||||
break;
|
||||
}
|
||||
display.setTextColor(_color);
|
||||
void ST7789LCDDisplay::setColor(ColorVal c) {
|
||||
display.setTextColor(_color = c);
|
||||
}
|
||||
|
||||
void ST7789LCDDisplay::setCursor(int x, int y) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <helpers/RefCountedDigitalPin.h>
|
||||
|
||||
class ST7789LCDDisplay : public DisplayDriver {
|
||||
#if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT)
|
||||
#if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT)
|
||||
SPIClass displaySPI;
|
||||
#endif
|
||||
Adafruit_ST7789 display;
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
{
|
||||
_isOn = false;
|
||||
}
|
||||
#elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT)
|
||||
#elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT)
|
||||
ST7789LCDDisplay(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
|
||||
displaySPI(HSPI),
|
||||
display(&displaySPI, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST),
|
||||
@@ -47,9 +47,9 @@ public:
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setColor(ColorVal 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;
|
||||
|
||||
@@ -1 +1,12 @@
|
||||
#include "U8g2Display.h"
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = 0;
|
||||
ColorVal UIColor::title_bkg = 0;
|
||||
ColorVal UIColor::title_txt = 1;
|
||||
ColorVal UIColor::primary_txt = 1;
|
||||
ColorVal UIColor::secondary_txt = 1;
|
||||
ColorVal UIColor::warning_txt = 1;
|
||||
ColorVal UIColor::popup_bkg = 0;
|
||||
ColorVal UIColor::popup_txt = 1;
|
||||
ColorVal UIColor::corp_blue = 1;
|
||||
|
||||
@@ -72,10 +72,10 @@ public:
|
||||
_u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void startFrame(Color bkg = DARK) override {
|
||||
_u8g2.clearBuffer();
|
||||
_drawColor = 1;
|
||||
_u8g2.setDrawColor(1);
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override {
|
||||
_u8g2.clearBuffer(); // TODO: apply 'bkg' color
|
||||
_drawColor = UIColor::primary_txt;
|
||||
_u8g2.setDrawColor(_drawColor);
|
||||
applyFont(1);
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ public:
|
||||
applyFont(sz);
|
||||
}
|
||||
|
||||
void setColor(Color c) override {
|
||||
_drawColor = (c != DARK) ? 1 : 0;
|
||||
void setColor(ColorVal c) override {
|
||||
_drawColor = c;
|
||||
_u8g2.setDrawColor(_drawColor);
|
||||
}
|
||||
|
||||
@@ -94,22 +94,18 @@ public:
|
||||
}
|
||||
|
||||
void print(const char* str) override {
|
||||
_u8g2.setDrawColor(_drawColor);
|
||||
_u8g2.drawStr(_cursorX, _cursorY, str);
|
||||
}
|
||||
|
||||
void fillRect(int x, int y, int w, int h) override {
|
||||
_u8g2.setDrawColor(_drawColor);
|
||||
_u8g2.drawBox(x, y, w, h);
|
||||
}
|
||||
|
||||
void drawRect(int x, int y, int w, int h) override {
|
||||
_u8g2.setDrawColor(_drawColor);
|
||||
_u8g2.drawFrame(x, y, w, h);
|
||||
}
|
||||
|
||||
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override {
|
||||
_u8g2.setDrawColor(1);
|
||||
_u8g2.drawXBM(x, y, w, h, bits);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user