From 39bf245d1ed0479d70260f03ab37faa2ff9c8815 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 3 Nov 2024 21:54:41 +0100 Subject: [PATCH] HUB75 driver optimization gains up to 3 fps in some effects. --- wled00/bus_manager.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 68066a36..fc07909f 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -11,14 +11,14 @@ // WLEDMM functions to get/set bits in an array - based on functions created by Brandon for GOL // toDo : make this a class that's completely defined in a header file -bool getBitFromArray(const uint8_t* byteArray, size_t position) { // get bit value +inline bool getBitFromArray(const uint8_t* byteArray, size_t position) { // get bit value size_t byteIndex = position / 8; unsigned bitIndex = position % 8; uint8_t byteValue = byteArray[byteIndex]; return (byteValue >> bitIndex) & 1; } -void setBitInArray(uint8_t* byteArray, size_t position, bool value) { // set bit - with error handling for nullptr +inline void setBitInArray(uint8_t* byteArray, size_t position, bool value) { // set bit - with error handling for nullptr //if (byteArray == nullptr) return; size_t byteIndex = position / 8; unsigned bitIndex = position % 8; @@ -1018,19 +1018,13 @@ void __attribute__((hot)) BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c } uint32_t BusHub75Matrix::getPixelColor(uint16_t pix) const { - if (!_valid || pix >= _len) return BLACK; - if (_ledBuffer) - return uint32_t(_ledBuffer[pix].scale8(_bri)) & 0x00FFFFFF; // scale8() is needed to mimic NeoPixelBus, which returns scaled-down colours - else - return BLACK; // we don't know anything about the pixel + if (!_valid || pix >= _len || !_ledBuffer) return BLACK; + return uint32_t(_ledBuffer[pix].scale8(_bri)) & 0x00FFFFFF; // scale8() is needed to mimic NeoPixelBus, which returns scaled-down colours } uint32_t __attribute__((hot)) BusHub75Matrix::getPixelColorRestored(uint16_t pix) const { - if (!_valid || pix >= _len) return BLACK; - if (_ledBuffer) - return uint32_t(_ledBuffer[pix]) & 0x00FFFFFF; - else - return BLACK; // we don't know anything about the pixel + if (!_valid || pix >= _len || !_ledBuffer) return BLACK; + return uint32_t(_ledBuffer[pix]) & 0x00FFFFFF; } void BusHub75Matrix::setBrightness(uint8_t b, bool immediate) { @@ -1056,19 +1050,23 @@ void __attribute__((hot)) BusHub75Matrix::show(void) { unsigned height = isFourScan ? fourScanPanel->height() : display->height(); unsigned width = _panelWidth; + // Cache pointers to LED array and bitmask array, to avoid repeated accesses + const byte* ledsDirty = _ledsDirty; + const CRGB* ledBuffer = _ledBuffer; + //while(!previousBufferFree) delay(1); // experimental - Wait before we allow any writing to the buffer. Stop flicker. size_t pix = 0; // running pixel index for (int y=0; y