Skip to content

Commit

Permalink
Merge branch 'MoonModules:mdev' into W5500_Support
Browse files Browse the repository at this point in the history
  • Loading branch information
troyhacks authored Aug 12, 2024
2 parents dc88b26 + a77520a commit 02ad212
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 29 deletions.
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,8 @@ HUB75_build_flags =
-D S3_LCD_DIV_NUM=20 ;; Attempt to fix wifi performance issue when panel active with S3 chips
;; HUB75_lib_deps = https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA.git @ 3.0.11 ;; breaks the build (2024-07-30)
;; HUB75_lib_deps = https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA.git#1e4c80a26454aca7b8129bd5a966b0af329d2703 ;; 3.0.10 - something strange is going on here ...
HUB75_lib_deps = https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA.git#c4ecdcfeeb5aa668d92ddf3c3c74bc93316f6e10 ;; 3.0.11
HUB75_lib_deps = https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA.git#1e4c80a26454aca7b8129bd5a966b0af329d2703 ;; 3.0.10 - something strange is going on here ...
;; HUB75_lib_deps = https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA.git#c4ecdcfeeb5aa668d92ddf3c3c74bc93316f6e10 ;; 3.0.11
HUB75_lib_ignore = ESP32 HUB75 LED MATRIX PANEL DMA Display ;; to remove the HUB75 lib dependancy (saves a few bytes)

NetDebug_build_flags =
Expand Down
11 changes: 8 additions & 3 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,22 +2148,27 @@ uint16_t mode_fire_2012() {

// Step 4. Map from heat cells to LED colors
for (int j = 0; j < SEGLEN; j++) {
SEGMENT.setPixelColor(indexToVStrip(j, stripNr), ColorFromPalette(SEGPALETTE, min(heat[j],byte(240)), 255, NOBLEND));
SEGMENT.setPixelColor(indexToVStrip(j, stripNr), ColorFromPalette(SEGPALETTE, min(heat[j], byte(240)), 255, NOBLEND));
}
}
};

for (int stripNr=0; stripNr<strips; stripNr++)
virtualStrip::runStrip(stripNr, &heat[stripNr * SEGLEN], it);

if (SEGMENT.is2D()) SEGMENT.blur(32);
if (SEGMENT.is2D()) {
uint8_t blurAmount = SEGMENT.custom2 >> 2;
if (blurAmount > 48) blurAmount += blurAmount-48; // extra blur when slider > 192 (bush burn)
if (blurAmount < 16) SEGMENT.blurCols(SEGMENT.custom2 >> 1); // no side-burn when slider < 64 (faster)
else SEGMENT.blur(blurAmount);
}

if (it != SEGENV.step)
SEGENV.step = it;

return FRAMETIME;
}
static const char _data_FX_MODE_FIRE_2012[] PROGMEM = "Fire 2012@Cooling,Spark rate,,,Boost;;!;1.5d;sx=64,ix=160,m12=1"; // bars WLEDMM 1.5d,
static const char _data_FX_MODE_FIRE_2012[] PROGMEM = "Fire 2012@Cooling,Spark rate,,2D Blur,Boost;;!;1.5d;sx=64,ix=160,c2=128,m12=1"; // bars WLEDMM 1.5d,


// ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb
Expand Down
10 changes: 10 additions & 0 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,16 @@ typedef struct Segment {
uint32_t __attribute__((pure)) color_from_palette(uint_fast16_t, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri = 255);
uint32_t __attribute__((pure)) color_wheel(uint8_t pos);

// 2D Blur: shortcuts for bluring columns or rows only (50% faster than full 2D blur)
inline void blurCols(fract8 blur_amount, bool smear = false) { // blur all columns
const unsigned cols = virtualWidth();
for (unsigned k = 0; k < cols; k++) blurCol(k, blur_amount, smear);
}
inline void blurRows(fract8 blur_amount, bool smear = false) { // blur all rows
const unsigned rows = virtualHeight();
for ( unsigned i = 0; i < rows; i++) blurRow(i, blur_amount, smear);
}

// 2D matrix
#ifndef WLEDMM_FASTPATH
inline uint16_t virtualWidth() const { // WLEDMM use fast types, and make function inline
Expand Down
61 changes: 37 additions & 24 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool getBitFromArray(const uint8_t* byteArray, size_t position) { // get bit val
}

void setBitInArray(uint8_t* byteArray, size_t position, bool value) { // set bit - with error handling for nullptr
if (byteArray == nullptr) return;
//if (byteArray == nullptr) return;
size_t byteIndex = position / 8;
unsigned bitIndex = position % 8;
if (value)
Expand Down Expand Up @@ -579,7 +579,6 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh

_valid = false;
mxconfig.double_buff = false; // default to off, known to cause issue with some effects but needs more memory
isBlack = false;

fourScanPanel = nullptr;

Expand Down Expand Up @@ -739,28 +738,35 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
USER_PRINTLN("MatrixPanel_I2S_DMA created");
// let's adjust default brightness
display->setBrightness8(25); // range is 0-255, 0 - 0%, 255 - 100%
_bri = 25;

delay(24); // experimental
// Allocate memory and start DMA display
if( not display->begin() ) {
USER_PRINTLN("****** MatrixPanel_I2S_DMA !KABOOM! I2S memory allocation failed ***********");
return;
}
else {
delay(18); // experiment - give the driver a moment (~ one full frame @ 60hz) to settle
_valid = true;
display->clearScreen(); // initially clear the screen buffer
display->setBrightness8(127); // range is 0-255, 0 - 0%, 255 - 100%
_bri = 127;

if (_ledBuffer) free(_ledBuffer); // should not happen
if (_ledsDirty) free(_ledsDirty); // should not happen
if(mxconfig.double_buff == false) {
_ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)
_ledsDirty = (byte*) malloc(getBitArrayBytes(_len)); // create LEDs dirty bits
//_ledsDirty = nullptr;
setBitArray(_ledsDirty, _len, false); // reset dirty bits
_ledsDirty = (byte*) malloc(getBitArrayBytes(_len)); // create LEDs dirty bits

if (_ledsDirty == nullptr) {
display->stopDMAoutput();
delete display; display = nullptr;
_valid = false;
USER_PRINTLN(F("MatrixPanel_I2S_DMA not started - not enough memory for dirty bits!"));
return; // fail is we cannot get memory for the buffer
}
setBitArray(_ledsDirty, _len, false); // reset dirty bits

isBlack = true;
if (mxconfig.double_buff == false) {
_ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)
}
}

switch(bc.type) {
Expand All @@ -784,8 +790,12 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
break;
}

if (_valid) {
_panelWidth = fourScanPanel ? fourScanPanel->width() : display->width(); // cache width - it will never change
}

USER_PRINT(F("MatrixPanel_I2S_DMA "));
USER_PRINTF("%sstarted.\n", _valid? "":"not ");
USER_PRINTF("%sstarted, width=%u, %u pixels.\n", _valid? "":"not ", _panelWidth, _len);

if (mxconfig.double_buff == true) USER_PRINTLN(F("MatrixPanel_I2S_DMA driver native double-buffering enabled."));
if (_ledBuffer != nullptr) USER_PRINTLN(F("MatrixPanel_I2S_DMA LEDS buffer enabled."));
Expand All @@ -806,11 +816,12 @@ void __attribute__((hot)) BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c
if (_ledBuffer[pix] != fastled_col) {
_ledBuffer[pix] = fastled_col;
setBitInArray(_ledsDirty, pix, true); // flag pixel as "dirty"
isBlack = false;
}
}
else {
if (isBlack && (c == BLACK)) return; // reject black pixels directly after clearScreen()
if ((c == BLACK) && (getBitFromArray(_ledsDirty, pix) == false)) return; // ignore black if pixel is already black
setBitInArray(_ledsDirty, pix, c != BLACK); // dirty = true means "color is not BLACK"

#ifndef NO_CIE1931
c = unGamma24(c); // to use the driver linear brightness feature, we first need to undo WLED gamma correction
#endif
Expand All @@ -819,17 +830,16 @@ void __attribute__((hot)) BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c
uint8_t b = B(c);

if(fourScanPanel != nullptr) {
unsigned width = fourScanPanel->width();
int width = _panelWidth;
int x = pix % width;
int y = pix / width;
fourScanPanel->drawPixelRGB888(int16_t(x), int16_t(y), r, g, b);
} else {
unsigned width = display->width();
int width = _panelWidth;
int x = pix % width;
int y = pix / width;
display->drawPixelRGB888(int16_t(x), int16_t(y), r, g, b);
}
isBlack = false;
}
}

Expand All @@ -838,28 +848,31 @@ uint32_t BusHub75Matrix::getPixelColor(uint16_t pix) const {
if (_ledBuffer)
return uint32_t(_ledBuffer[pix].scale8(_bri)) & 0x00FFFFFF; // scale8() is needed to mimic NeoPixelBus, which returns scaled-down colours
else
return BLACK;
return getBitFromArray(_ledsDirty, pix) ? DARKGREY: BLACK; // just a hack - we only know if the pixel is black or not
}

void BusHub75Matrix::setBrightness(uint8_t b, bool immediate) {
this->display->setBrightness(b);
_bri = b;
if (_bri > 238) _bri=238;
display->setBrightness(_bri);
}

void __attribute__((hot)) BusHub75Matrix::show(void) {
if (!_valid) return;
display->setBrightness(_bri);

if (_ledBuffer) {
// write out buffered LEDs
bool haveDirtyBits = (_ledsDirty != nullptr);
bool isFourScan = (fourScanPanel != nullptr);
unsigned width = isFourScan ? fourScanPanel->width() : display->width();
//if (isFourScan) fourScanPanel->setRotation(0);
unsigned height = isFourScan ? fourScanPanel->height() : display->height();
unsigned width = _panelWidth;

//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<height; y++) for (int x=0; x<width; x++) {
if ( !haveDirtyBits || (getBitFromArray(_ledsDirty, pix) == true)) { // only repaint the "dirty" pixels
if (getBitFromArray(_ledsDirty, pix) == true) { // only repaint the "dirty" pixels
uint32_t c = uint32_t(_ledBuffer[pix]) & 0x00FFFFFF; // get RGB color, removing FastLED "alpha" component
#ifndef NO_CIE1931
c = unGamma24(c); // to use the driver linear brightness feature, we first need to undo WLED gamma correction
Expand All @@ -872,28 +885,28 @@ void __attribute__((hot)) BusHub75Matrix::show(void) {
}
pix ++;
}
if (haveDirtyBits) setBitArray(_ledsDirty, _len, false); // reset dirty bits
setBitArray(_ledsDirty, _len, false); // buffer shown - reset all dirty bits
}

if(mxconfig.double_buff) {
display->flipDMABuffer(); // Show the back buffer, set current output buffer to the back (i.e. no longer being sent to LED panels)
// while(!previousBufferFree) delay(1); // experimental - Wait before we allow any writing to the buffer. Stop flicker.
display->clearScreen(); // Now clear the back-buffer
isBlack = true;
setBitArray(_ledsDirty, _len, false); // dislay buffer is blank - reset all dirty bits
}
}

void BusHub75Matrix::cleanup() {
if (display && _valid) display->stopDMAoutput(); // terminate DMA driver (display goes black)
_valid = false;
_panelWidth = 0;
deallocatePins();
USER_PRINTLN("HUB75 output ended.");

//if (fourScanPanel != nullptr) delete fourScanPanel; // warning: deleting object of polymorphic class type 'VirtualMatrixPanel' which has non-virtual destructor might cause undefined behavior
delete display;
display = nullptr;
fourScanPanel = nullptr;
isBlack = false;
if (_ledBuffer != nullptr) free(_ledBuffer); _ledBuffer = nullptr;
if (_ledsDirty != nullptr) free(_ledsDirty); _ledsDirty = nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class BusHub75Matrix : public Bus {
MatrixPanel_I2S_DMA *display = nullptr;
VirtualMatrixPanel *fourScanPanel = nullptr;
HUB75_I2S_CFG mxconfig;
bool isBlack = false;
unsigned _panelWidth = 0;
CRGB *_ledBuffer = nullptr;
byte *_ledsDirty = nullptr;
};
Expand Down
6 changes: 6 additions & 0 deletions wled00/dmx_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ void DMXInput::updateInternal()
unsigned long now = millis();
if (dmx_receive(inputPortNum, &packet, DMX_TIMEOUT_TICK)) {
if (!packet.err) {
if(!connected) {
USER_PRINTLN("DMX Input - connected");
}
connected = true;
identify = isIdentifyOn();
if (!packet.is_rdm) {
Expand All @@ -199,6 +202,9 @@ void DMXInput::updateInternal()
}
}
else {
if(connected) {
USER_PRINTLN("DMX Input - disconnected");
}
connected = false;
}
}
Expand Down

0 comments on commit 02ad212

Please sign in to comment.