2026-01-27 18:50:15 +01:00
|
|
|
#include <HalDisplay.h>
|
|
|
|
|
#include <HalGPIO.h>
|
|
|
|
|
|
2026-04-04 09:25:43 -06:00
|
|
|
// Global HalDisplay instance
|
|
|
|
|
HalDisplay display;
|
|
|
|
|
|
2026-01-27 18:50:15 +01:00
|
|
|
#define SD_SPI_MISO 7
|
|
|
|
|
|
|
|
|
|
HalDisplay::HalDisplay() : einkDisplay(EPD_SCLK, EPD_MOSI, EPD_CS, EPD_DC, EPD_RST, EPD_BUSY) {}
|
|
|
|
|
|
|
|
|
|
HalDisplay::~HalDisplay() {}
|
|
|
|
|
|
2026-04-04 09:25:43 -06:00
|
|
|
void HalDisplay::begin() {
|
|
|
|
|
// Set X3-specific panel mode before initializing.
|
|
|
|
|
if (gpio.deviceIsX3()) {
|
|
|
|
|
einkDisplay.setDisplayX3();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
einkDisplay.begin();
|
|
|
|
|
|
|
|
|
|
// Request resync after specific wakeup events to ensure clean display state
|
|
|
|
|
const auto wakeupReason = gpio.getWakeupReason();
|
|
|
|
|
if (wakeupReason == HalGPIO::WakeupReason::PowerButton || wakeupReason == HalGPIO::WakeupReason::AfterFlash ||
|
|
|
|
|
wakeupReason == HalGPIO::WakeupReason::Other) {
|
|
|
|
|
einkDisplay.requestResync();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-27 18:50:15 +01:00
|
|
|
|
|
|
|
|
void HalDisplay::clearScreen(uint8_t color) const { einkDisplay.clearScreen(color); }
|
|
|
|
|
|
|
|
|
|
void HalDisplay::drawImage(const uint8_t* imageData, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
|
|
|
|
|
bool fromProgmem) const {
|
|
|
|
|
einkDisplay.drawImage(imageData, x, y, w, h, fromProgmem);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 17:38:09 +07:00
|
|
|
void HalDisplay::drawImageTransparent(const uint8_t* imageData, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
|
|
|
|
|
bool fromProgmem) const {
|
|
|
|
|
einkDisplay.drawImageTransparent(imageData, x, y, w, h, fromProgmem);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 18:50:15 +01:00
|
|
|
EInkDisplay::RefreshMode convertRefreshMode(HalDisplay::RefreshMode mode) {
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case HalDisplay::FULL_REFRESH:
|
|
|
|
|
return EInkDisplay::FULL_REFRESH;
|
|
|
|
|
case HalDisplay::HALF_REFRESH:
|
|
|
|
|
return EInkDisplay::HALF_REFRESH;
|
|
|
|
|
case HalDisplay::FAST_REFRESH:
|
|
|
|
|
default:
|
|
|
|
|
return EInkDisplay::FAST_REFRESH;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 13:32:05 +01:00
|
|
|
void HalDisplay::displayBuffer(HalDisplay::RefreshMode mode, bool turnOffScreen) {
|
2026-04-04 09:25:43 -06:00
|
|
|
if (gpio.deviceIsX3() && mode == RefreshMode::HALF_REFRESH) {
|
|
|
|
|
einkDisplay.requestResync(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 13:32:05 +01:00
|
|
|
einkDisplay.displayBuffer(convertRefreshMode(mode), turnOffScreen);
|
|
|
|
|
}
|
2026-01-27 18:50:15 +01:00
|
|
|
|
|
|
|
|
void HalDisplay::refreshDisplay(HalDisplay::RefreshMode mode, bool turnOffScreen) {
|
2026-04-04 09:25:43 -06:00
|
|
|
if (gpio.deviceIsX3() && mode == RefreshMode::HALF_REFRESH) {
|
|
|
|
|
einkDisplay.requestResync(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 18:50:15 +01:00
|
|
|
einkDisplay.refreshDisplay(convertRefreshMode(mode), turnOffScreen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HalDisplay::deepSleep() { einkDisplay.deepSleep(); }
|
|
|
|
|
|
|
|
|
|
uint8_t* HalDisplay::getFrameBuffer() const { return einkDisplay.getFrameBuffer(); }
|
|
|
|
|
|
|
|
|
|
void HalDisplay::copyGrayscaleBuffers(const uint8_t* lsbBuffer, const uint8_t* msbBuffer) {
|
|
|
|
|
einkDisplay.copyGrayscaleBuffers(lsbBuffer, msbBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HalDisplay::copyGrayscaleLsbBuffers(const uint8_t* lsbBuffer) { einkDisplay.copyGrayscaleLsbBuffers(lsbBuffer); }
|
|
|
|
|
|
|
|
|
|
void HalDisplay::copyGrayscaleMsbBuffers(const uint8_t* msbBuffer) { einkDisplay.copyGrayscaleMsbBuffers(msbBuffer); }
|
|
|
|
|
|
|
|
|
|
void HalDisplay::cleanupGrayscaleBuffers(const uint8_t* bwBuffer) { einkDisplay.cleanupGrayscaleBuffers(bwBuffer); }
|
|
|
|
|
|
2026-02-05 13:32:05 +01:00
|
|
|
void HalDisplay::displayGrayBuffer(bool turnOffScreen) { einkDisplay.displayGrayBuffer(turnOffScreen); }
|
2026-04-04 09:25:43 -06:00
|
|
|
|
|
|
|
|
uint16_t HalDisplay::getDisplayWidth() const { return einkDisplay.getDisplayWidth(); }
|
|
|
|
|
|
|
|
|
|
uint16_t HalDisplay::getDisplayHeight() const { return einkDisplay.getDisplayHeight(); }
|
|
|
|
|
|
|
|
|
|
uint16_t HalDisplay::getDisplayWidthBytes() const { return einkDisplay.getDisplayWidthBytes(); }
|
|
|
|
|
|
|
|
|
|
uint32_t HalDisplay::getBufferSize() const { return einkDisplay.getBufferSize(); }
|