You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to propose a refactoring for EInkDisplay2.cpp and EInkDisplay2.h.
Currently, the file heavily relies on board-specific macro guards (#if defined(MINI_EPAPER_S3), #elif defined(ELECROW_ThinkNode_M5), etc.) to initialize SPI buses and select display drivers.
This approach makes it difficult to maintain, scales poorly, and creates artificial barriers for adding custom DIY targets (for instance, ESP32-S3 boards combined with various third-party E-Paper modules).
The Proposal
Instead of hardcoding specific commercial board names inside the display module core, we could introduce a clean, unified macro configuration pattern. This shifts the configuration load entirely to the variant.h files, making the core display driver generic and future-proof.
We could utilize standard configuration flags like these:
#defineUSE_EINK
#defineDISPLAY_2C// Two colors (Black/White), default fallback
#defineDISPLAY_3C// Three colors (Red/Black/White or Yellow/Black/White)
#defineDISPLAY_SPI2// SPI bus index or "HSPI" / "VSPI" macros
#defineDISPLAY_ROTATE90// Screen rotation in degrees (0, 90, 180, 270)
#defineDISPLAY_EN// [Optional] Display power control pin
#defineDISPLAY_EN_INVERTED
Key Enhancements
Unified Pin Naming: Transition from prefixing pins with PIN_EINK_* to a generic DISPLAY_* naming scheme (DISPLAY_MOSI, DISPLAY_CS, etc.). This aligns with potential future refactoring where common drawing routines can check the abstract display type (OLED, EINK, TFT), rather than maintaining decoupled modules
Flexible SPI Routing: DIY builds often isolate the E-Paper display on a separate hardware SPI bus to avoid bus contention with LoRa transceivers. Explicitly defining DISPLAY_SPI simplifies routing the display onto an independent bus instance.
Example Implementation
// Connect to the display using universal macro settingsboolEInkDisplay::connect() {
LOG_INFO("Do EInk init");
// Enable display power rail if DISPLAY_EN pin is specified
#ifdef DISPLAY_EN
if (DISPLAY_EN != -1) {
pinMode(DISPLAY_EN, OUTPUT);
#ifdef DISPLAY_EN_INVERTED
digitalWrite(DISPLAY_EN, HIGH);
#elsedigitalWrite(DISPLAY_EN, LOW);
#endifdelay(10);
}
#endif// Configure SPI bus interface based on variant macros
#if defined(DISPLAY_SPI) && (DISPLAY_SPI > 1)
// Instantiate a custom hardware SPI bus on the fly using the provided number
spi_bus = newSPIClass(DISPLAY_SPI);
#else// Default fallback to the standard global Arduino SPI instance
spi_bus = &SPI;
#endif// Assign custom pins if they are fully defined in the variant header
#if defined(DISPLAY_SCLK) && defined(DISPLAY_MOSI) && defined(DISPLAY_CS)
spi_bus->begin(DISPLAY_SCLK, -1, DISPLAY_MOSI, DISPLAY_CS);
#else// Fall back to the architecture's default hardware pins for this bus
spi_bus->begin();
#endif// Instantiate low-level panel driverauto lowLevel = newEINK_DISPLAY_MODEL(DISPLAY_CS, DISPLAY_DC, DISPLAY_RES, DISPLAY_BUSY);
adafruitDisplay = new GxEPD2_BW<EINK_DISPLAY_MODEL, EINK_DISPLAY_MODEL::HEIGHT>(*lowLevel);
adafruitDisplay->init(115200, true, 20, false, *spi_bus, SPISettings(4000000, MSBFIRST, SPI_MODE0));
// 4. Apply screen rotation (0, 90, 180, 270 degrees)
#if defined(DISPLAY_ROTATE)
#if DISPLAY_ROTATE == 90
adafruitDisplay->setRotation(1);
#elif DISPLAY_ROTATE == 180
adafruitDisplay->setRotation(2);
#elif DISPLAY_ROTATE == 270
adafruitDisplay->setRotation(3);
#else
adafruitDisplay->setRotation(0);
#endif
#else
adafruitDisplay->setRotation(1); // Default landscape orientation
#endif// Set full screen update window
adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
returntrue;
}
Seamless Backward Compatibility:
To avoid breaking existing board targets and prevent the need to modify dozens of current variant.h files simultaneously, we can implement temporary macro mapping inside EInkDisplay2.h.
If the legacy PIN_EINK_* definitions are detected, they will automatically map to the new unified DISPLAY_* macros. This allows a smooth, phased migration across the codebase.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to propose a refactoring for EInkDisplay2.cpp and EInkDisplay2.h.
Currently, the file heavily relies on board-specific macro guards (#if defined(MINI_EPAPER_S3), #elif defined(ELECROW_ThinkNode_M5), etc.) to initialize SPI buses and select display drivers.
This approach makes it difficult to maintain, scales poorly, and creates artificial barriers for adding custom DIY targets (for instance, ESP32-S3 boards combined with various third-party E-Paper modules).
The Proposal
Instead of hardcoding specific commercial board names inside the display module core, we could introduce a clean, unified macro configuration pattern. This shifts the configuration load entirely to the variant.h files, making the core display driver generic and future-proof.
We could utilize standard configuration flags like these:
Key Enhancements
Example Implementation
Seamless Backward Compatibility:
To avoid breaking existing board targets and prevent the need to modify dozens of current
variant.hfiles simultaneously, we can implement temporary macro mapping insideEInkDisplay2.h.If the legacy
PIN_EINK_*definitions are detected, they will automatically map to the new unifiedDISPLAY_*macros. This allows a smooth, phased migration across the codebase.Beta Was this translation helpful? Give feedback.
All reactions