Merge branch 'dev' into new-companion-ui

This commit is contained in:
Scott Powell 2025-08-15 15:39:11 +10:00
commit a5ebac6236
36 changed files with 1689 additions and 28 deletions

View file

@ -5,25 +5,25 @@
class RefCountedDigitalPin {
uint8_t _pin;
int8_t _claims = 0;
uint8_t _active = 0;
public:
RefCountedDigitalPin(uint8_t pin): _pin(pin) { }
RefCountedDigitalPin(uint8_t pin,uint8_t active=HIGH): _pin(pin), _active(active) { }
void begin() {
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW); // initial state
digitalWrite(_pin, !_active); // initial state
}
void claim() {
_claims++;
if (_claims > 0) {
digitalWrite(_pin, HIGH);
digitalWrite(_pin, _active);
}
}
void release() {
_claims--;
if (_claims == 0) {
digitalWrite(_pin, LOW);
digitalWrite(_pin, !_active);
}
}
};

View file

@ -2,20 +2,58 @@
#include "../../MeshCore.h"
BaseDisplay* E213Display::detectEInk()
{
// Test 1: Logic of BUSY pin
// Determines controller IC manufacturer
// Fitipower: busy when LOW
// Solomon Systech: busy when HIGH
// Force display BUSY by holding reset pin active
pinMode(DISP_RST, OUTPUT);
digitalWrite(DISP_RST, LOW);
delay(10);
// Read whether pin is HIGH or LOW while busy
pinMode(DISP_BUSY, INPUT);
bool busyLogic = digitalRead(DISP_BUSY);
// Test complete. Release pin
pinMode(DISP_RST, INPUT);
if (busyLogic == LOW) {
#ifdef VISION_MASTER_E213
return new EInkDisplay_VisionMasterE213 ;
#else
return new EInkDisplay_WirelessPaperV1_1 ;
#endif
} else {// busy HIGH
#ifdef VISION_MASTER_E213
return new EInkDisplay_VisionMasterE213V1_1 ;
#else
return new EInkDisplay_WirelessPaperV1_1_1 ;
#endif
}
}
bool E213Display::begin() {
if (_init) return true;
powerOn();
display.begin();
if(display==NULL) {
display = detectEInk();
}
display->begin();
// Set to landscape mode rotated 180 degrees
display.setRotation(3);
display->setRotation(3);
_init = true;
_isOn = true;
clear();
display.fastmodeOn(); // Enable fast mode for quicker (partial) updates
display->fastmodeOn(); // Enable fast mode for quicker (partial) updates
return true;
}
@ -23,15 +61,23 @@ bool E213Display::begin() {
void E213Display::powerOn() {
#ifdef PIN_VEXT_EN
pinMode(PIN_VEXT_EN, OUTPUT);
#ifdef PIN_VEXT_EN_ACTIVE
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
#else
digitalWrite(PIN_VEXT_EN, LOW); // Active low
#endif
delay(50); // Allow power to stabilize
#endif
}
void E213Display::powerOff() {
#ifdef PIN_VEXT_EN
#ifdef PIN_VEXT_EN_ACTIVE
digitalWrite(PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE);
#else
digitalWrite(PIN_VEXT_EN, HIGH); // Turn off power
#endif
#endif
}
void E213Display::turnOn() {
@ -46,21 +92,23 @@ void E213Display::turnOff() {
}
void E213Display::clear() {
display.clear();
display->clear();
}
void E213Display::startFrame(Color bkg) {
// Fill screen with white first to ensure clean background
display.fillRect(0, 0, width(), height(), WHITE);
display->fillRect(0, 0, width(), height(), WHITE);
if (bkg == LIGHT) {
// Fill with black if light background requested (inverted for e-ink)
display.fillRect(0, 0, width(), height(), BLACK);
display->fillRect(0, 0, width(), height(), BLACK);
}
}
void E213Display::setTextSize(int sz) {
// The library handles text size internally
display.setTextSize(sz);
display->setTextSize(sz);
}
void E213Display::setColor(Color c) {
@ -68,19 +116,19 @@ void E213Display::setColor(Color c) {
}
void E213Display::setCursor(int x, int y) {
display.setCursor(x, y);
display->setCursor(x, y);
}
void E213Display::print(const char *str) {
display.print(str);
display->print(str);
}
void E213Display::fillRect(int x, int y, int w, int h) {
display.fillRect(x, y, w, h, BLACK);
display->fillRect(x, y, w, h, BLACK);
}
void E213Display::drawRect(int x, int y, int w, int h) {
display.drawRect(x, y, w, h, BLACK);
display->drawRect(x, y, w, h, BLACK);
}
void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
@ -98,7 +146,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, BLACK);
}
}
}
@ -107,10 +155,10 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
uint16_t E213Display::getTextWidth(const char *str) {
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
display->getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
return w;
}
void E213Display::endFrame() {
display.update();
display->update();
}

View file

@ -8,13 +8,17 @@
// Display driver for E213 e-ink display
class E213Display : public DisplayDriver {
EInkDisplay_VisionMasterE213 display;
BaseDisplay* display=NULL;
bool _init = false;
bool _isOn = false;
public:
E213Display() : DisplayDriver(250, 122) {}
~E213Display(){
if(display!=NULL) {
delete display;
}
}
bool begin();
bool isOn() override { return _isOn; }
void turnOn() override;
@ -32,6 +36,7 @@ public:
void endFrame() override;
private:
BaseDisplay* detectEInk();
void powerOn();
void powerOff();
};

View file

@ -0,0 +1,116 @@
#include "E290Display.h"
#include "../../MeshCore.h"
bool E290Display::begin() {
if (_init) return true;
powerOn();
display.begin();
// Set to landscape mode rotated 180 degrees
display.setRotation(3);
_init = true;
_isOn = true;
clear();
display.fastmodeOn(); // Enable fast mode for quicker (partial) updates
return true;
}
void E290Display::powerOn() {
#ifdef PIN_VEXT_EN
pinMode(PIN_VEXT_EN, OUTPUT);
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
delay(50); // Allow power to stabilize
#endif
}
void E290Display::powerOff() {
#ifdef PIN_VEXT_EN
digitalWrite(PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE); // Turn off power
#endif
}
void E290Display::turnOn() {
if (!_init) begin();
powerOn();
_isOn = true;
}
void E290Display::turnOff() {
powerOff();
_isOn = false;
}
void E290Display::clear() {
display.clear();
}
void E290Display::startFrame(Color bkg) {
// Fill screen with white first to ensure clean background
display.fillRect(0, 0, width(), height(), WHITE);
if (bkg == LIGHT) {
// Fill with black if light background requested (inverted for e-ink)
display.fillRect(0, 0, width(), height(), BLACK);
}
}
void E290Display::setTextSize(int sz) {
// The library handles text size internally
display.setTextSize(sz);
}
void E290Display::setColor(Color c) {
// implemented in individual display methods
}
void E290Display::setCursor(int x, int y) {
display.setCursor(x, y);
}
void E290Display::print(const char *str) {
display.print(str);
}
void E290Display::fillRect(int x, int y, int w, int h) {
display.fillRect(x, y, w, h, BLACK);
}
void E290Display::drawRect(int x, int y, int w, int h) {
display.drawRect(x, y, w, h, BLACK);
}
void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
// Width in bytes for bitmap processing
uint16_t widthInBytes = (w + 7) / 8;
// Process the bitmap row by row
for (int by = 0; by < h; by++) {
// Scan across the row bit by bit
for (int bx = 0; bx < w; bx++) {
// Get the current bit using MSB ordering (like GxEPDDisplay)
uint16_t byteOffset = (by * widthInBytes) + (bx / 8);
uint8_t bitMask = 0x80 >> (bx & 7);
bool bitSet = bits[byteOffset] & bitMask;
// If the bit is set, draw the pixel
if (bitSet) {
display.drawPixel(x + bx, y + by, BLACK);
}
}
}
}
uint16_t E290Display::getTextWidth(const char *str) {
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
return w;
}
void E290Display::endFrame() {
display.update();
}

View file

@ -0,0 +1,37 @@
#pragma once
#include "DisplayDriver.h"
#include <SPI.h>
#include <Wire.h>
#include <heltec-eink-modules.h>
// Display driver for E290 e-ink display
class E290Display : public DisplayDriver {
EInkDisplay_VisionMasterE290 display;
bool _init = false;
bool _isOn = false;
public:
E290Display() : DisplayDriver(296, 128) {}
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;
uint16_t getTextWidth(const char *str) override;
void endFrame() override;
private:
void powerOn();
void powerOff();
};

View file

@ -7,6 +7,9 @@ bool SSD1306Display::i2c_probe(TwoWire& wire, uint8_t addr) {
}
bool SSD1306Display::begin() {
#ifdef DISPLAY_ROTATION
display.setRotation(DISPLAY_ROTATION);
#endif
return display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_ADDRESS, true, false) && i2c_probe(Wire, DISPLAY_ADDRESS);
}