Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync changes improvements in the AC-HUB75 back #169

Draft
wants to merge 7 commits into
base: mdev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden
${common_mm.build_flags_S} ${common_mm.build_flags_M}
${Speed_Flags.build_flags_V4} ;; optimize for speed
${common_mm.HUB75_build_flags}
-D DEFAULT_LED_TYPE=101
-D MOONHUB_S3_PINOUT ;; HUB75 pinout
${common_mm.animartrix_build_flags}
-D WLED_RELEASE_NAME=esp32S3_16MB_PSRAM_M_HUB75
Expand Down
194 changes: 52 additions & 142 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ void BusNetwork::cleanup() {

#ifdef WLED_ENABLE_HUB75MATRIX
#warning "HUB75 driver enabled (experimental)"
#ifdef ESP8266
#error ESP8266 does not support HUB75
#endif


// BusHub75Matrix "global" variables (static members)
MatrixPanel_I2S_DMA* BusHub75Matrix::activeDisplay = nullptr;
Expand Down Expand Up @@ -665,28 +669,15 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
else mxconfig.setPixelColorDepthBits(3); // 9bit



// HUB75_I2S_CFG::i2s_pins _pins={R1_PIN, G1_PIN, B1_PIN, R2_PIN, G2_PIN, B2_PIN, A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, LAT_PIN, OE_PIN, CLK_PIN};

#if defined(ARDUINO_ADAFRUIT_MATRIXPORTAL_ESP32S3) // MatrixPortal ESP32-S3

// https://www.adafruit.com/product/5778

USER_PRINTLN("MatrixPanel_I2S_DMA - Matrix Portal S3 config");
mxconfig.gpio = { 42, 41, 40, 38, 39, 37, 45, 36, 48, 35, 21, 47, 14, 2 };

mxconfig.gpio.r1 = 42;
mxconfig.gpio.g1 = 41;
mxconfig.gpio.b1 = 40;
mxconfig.gpio.r2 = 38;
mxconfig.gpio.g2 = 39;
mxconfig.gpio.b2 = 37;

mxconfig.gpio.lat = 47;
mxconfig.gpio.oe = 14;
mxconfig.gpio.clk = 2;

mxconfig.gpio.a = 45;
mxconfig.gpio.b = 36;
mxconfig.gpio.c = 48;
mxconfig.gpio.d = 35;
mxconfig.gpio.e = 21;

#elif defined(CONFIG_IDF_TARGET_ESP32S3) && defined(BOARD_HAS_PSRAM)// ESP32-S3 with PSRAM

Expand All @@ -698,23 +689,8 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh

#else
USER_PRINTLN("MatrixPanel_I2S_DMA - S3 with PSRAM");
mxconfig.gpio = { 1, 2, 42, 41, 40, 39, 45, 48, 47, 21, 38, 8, 3, 18 };

mxconfig.gpio.r1 = 1;
mxconfig.gpio.g1 = 2;
mxconfig.gpio.b1 = 42;
// 4th pin is GND
mxconfig.gpio.r2 = 41;
mxconfig.gpio.g2 = 40;
mxconfig.gpio.b2 = 39;
mxconfig.gpio.e = 38;
mxconfig.gpio.a = 45;
mxconfig.gpio.b = 48;
mxconfig.gpio.c = 47;
mxconfig.gpio.d = 21;
mxconfig.gpio.clk = 18;
mxconfig.gpio.lat = 8;
mxconfig.gpio.oe = 3;
// 16th pin is GND
#endif

#elif defined(CONFIG_IDF_TARGET_ESP32S3) // ESP32-S3 HD-WF2
Expand All @@ -724,76 +700,28 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
// https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA/issues/433

USER_PRINTLN("MatrixPanel_I2S_DMA - HD-WF2 S3 config");
mxconfig.gpio = {2, 6, 10, 3, 7, 11, 39, 38, 37, 36, 21, 33, 35, 34};

mxconfig.gpio.r1 = 2;
mxconfig.gpio.g1 = 6;
mxconfig.gpio.b1 = 10;
mxconfig.gpio.r2 = 3;
mxconfig.gpio.g2 = 7;
mxconfig.gpio.b2 = 11;

mxconfig.gpio.lat = 33;
mxconfig.gpio.oe = 35;
mxconfig.gpio.clk = 34;

mxconfig.gpio.a = 39;
mxconfig.gpio.b = 38;
mxconfig.gpio.c = 37;
mxconfig.gpio.d = 36;
mxconfig.gpio.e = 21;

#elif defined(CONFIG_IDF_TARGET_ESP32S2) // ESP32-S2

// Huidu HD-WF1 ESP32-S2
// https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA/issues/433

USER_PRINTLN("MatrixPanel_I2S_DMA - HD-WF1 S2 config");

mxconfig.gpio.r1 = 2;
mxconfig.gpio.g1 = 6;
mxconfig.gpio.b1 = 3;
mxconfig.gpio.r2 = 4;
mxconfig.gpio.g2 = 8;
mxconfig.gpio.b2 = 5;

mxconfig.gpio.lat = 33;
mxconfig.gpio.oe = 35;
mxconfig.gpio.clk = 34;

mxconfig.gpio.a = 39;
mxconfig.gpio.b = 38;
mxconfig.gpio.c = 37;
mxconfig.gpio.d = 36;
mxconfig.gpio.e = 12;
mxconfig.gpio = {2, 6, 3, 4, 8, 5, 39, 38, 37, 36, 12, 33, 35, 34};

#elif defined(ESP32_FORUM_PINOUT) // Common format for boards designed for SmartMatrix

USER_PRINTLN("MatrixPanel_I2S_DMA - ESP32_FORUM_PINOUT");

/*
ESP32 with SmartMatrix's default pinout - ESP32_FORUM_PINOUT

https://github.com/pixelmatix/SmartMatrix/blob/teensylc/src/MatrixHardware_ESP32_V0.h

Can use a board like https://github.com/rorosaurus/esp32-hub75-driver
*/

mxconfig.gpio.r1 = 2;
mxconfig.gpio.g1 = 15;
mxconfig.gpio.b1 = 4;
mxconfig.gpio.r2 = 16;
mxconfig.gpio.g2 = 27;
mxconfig.gpio.b2 = 17;

mxconfig.gpio.lat = 26;
mxconfig.gpio.oe = 25;
mxconfig.gpio.clk = 22;

mxconfig.gpio.a = 5;
mxconfig.gpio.b = 18;
mxconfig.gpio.c = 19;
mxconfig.gpio.d = 21;
mxconfig.gpio.e = 12;
mxconfig.gpio = { 2, 15, 4, 16, 27, 17, 5, 18, 19, 21, 12, 26, 25, 22 };

#else
USER_PRINTLN("MatrixPanel_I2S_DMA - Default pins");
Expand All @@ -806,27 +734,35 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
https://www.electrodragon.com/product/rgb-matrix-panel-drive-interface-board-for-esp32-dma/

*/
mxconfig.gpio.r1 = 25;
mxconfig.gpio.g1 = 26;
mxconfig.gpio.b1 = 27;
mxconfig.gpio.r2 = 14;
mxconfig.gpio.g2 = 12;
mxconfig.gpio.b2 = 13;

mxconfig.gpio.lat = 4;
mxconfig.gpio.oe = 15;
mxconfig.gpio.clk = 16;

mxconfig.gpio.a = 23;
mxconfig.gpio.b = 19;
mxconfig.gpio.c = 5;
mxconfig.gpio.d = 17;
mxconfig.gpio.e = 18;
mxconfig.gpio = { 25, 26, 27, 14, 12, 13, 23, 9, 5, 17, 18, 4, 15, 16 };

#endif

uint8_t pins[PIN_COUNT];
memcpy(pins, &mxconfig.gpio, sizeof(mxconfig.gpio));
pinManager.allocateMultiplePins(pins, PIN_COUNT, PinOwner::HUB75, true);

if(bc.colorOrder == COL_ORDER_RGB) {
USER_PRINTLN("MatrixPanel_I2S_DMA = Default color order (RGB)");
} else if(bc.colorOrder == COL_ORDER_BGR) {
USER_PRINTLN("MatrixPanel_I2S_DMA = color order BGR");
int8_t tmpPin;
tmpPin = mxconfig.gpio.r1;
mxconfig.gpio.r1 = mxconfig.gpio.b1;
mxconfig.gpio.b1 = tmpPin;
tmpPin = mxconfig.gpio.r2;
mxconfig.gpio.r2 = mxconfig.gpio.b2;
mxconfig.gpio.b2 = tmpPin;
}
else {
USER_PRINTF("MatrixPanel_I2S_DMA = unsupported color order %u\n", bc.colorOrder);
}

USER_PRINTF("R1_PIN=%u, G1_PIN=%u, B1_PIN=%u, R2_PIN=%u, G2_PIN=%u, B2_PIN=%u, A_PIN=%u, B_PIN=%u, C_PIN=%u, D_PIN=%u, E_PIN=%u, LAT_PIN=%u, OE_PIN=%u, CLK_PIN=%u\n",
mxconfig.gpio.r1, mxconfig.gpio.g1, mxconfig.gpio.b1, mxconfig.gpio.r2, mxconfig.gpio.g2, mxconfig.gpio.b2,
mxconfig.gpio.a, mxconfig.gpio.b, mxconfig.gpio.c, mxconfig.gpio.d, mxconfig.gpio.e, mxconfig.gpio.lat, mxconfig.gpio.oe, mxconfig.gpio.clk);
USER_PRINTF("MatrixPanel_I2S_DMA config - %ux%u (type %u) length: %u, %u bits/pixel.\n", mxconfig.mx_width, mxconfig.mx_height, bc.type, mxconfig.chain_length, mxconfig.getPixelColorDepthBits() * 3);
DEBUG_PRINT(F("Free heap: ")); DEBUG_PRINTLN(ESP.getFreeHeap()); lastHeap = ESP.getFreeHeap();
USER_PRINT(F("Free heap: ")); USER_PRINTLN(ESP.getFreeHeap()); lastHeap = ESP.getFreeHeap();

// check if we can re-use the existing display driver
if (activeDisplay) {
Expand All @@ -842,7 +778,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
|| (activeMXconfig.getPixelColorDepthBits() != mxconfig.getPixelColorDepthBits()) )
{
// not the same as before - delete old driver
DEBUG_PRINTLN("MatrixPanel_I2S_DMA deleting old driver!");
USER_PRINTLN("MatrixPanel_I2S_DMA deleting old driver!");
activeDisplay->stopDMAoutput();
delay(28);
//#if !defined(CONFIG_IDF_TARGET_ESP32S3) // prevent crash
Expand Down Expand Up @@ -877,32 +813,13 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh

this->_len = (display->width() * display->height());

pinManager.allocatePin(mxconfig.gpio.r1, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.g1, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.b1, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.r2, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.g2, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.b2, true, PinOwner::HUB75);

pinManager.allocatePin(mxconfig.gpio.lat, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.oe, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.clk, true, PinOwner::HUB75);

pinManager.allocatePin(mxconfig.gpio.a, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.b, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.c, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.d, true, PinOwner::HUB75);
pinManager.allocatePin(mxconfig.gpio.e, true, PinOwner::HUB75);

// display->setLatBlanking(4);

USER_PRINTLN("MatrixPanel_I2S_DMA created");
// let's adjust default brightness
//display->setBrightness8(25); // range is 0-255, 0 - 0%, 255 - 100% // [setBrightness()] Tried to set output brightness before begin()
_bri = 25;

delay(24); // experimental
DEBUG_PRINT(F("heap usage: ")); DEBUG_PRINTLN(int(lastHeap - ESP.getFreeHeap()));
USER_PRINT(F("heap usage: ")); USER_PRINTLN(int(lastHeap - ESP.getFreeHeap()));
// Allocate memory and start DMA display
if (newDisplay && (display->begin() == false)) {
USER_PRINTLN("****** MatrixPanel_I2S_DMA !KABOOM! I2S memory allocation failed ***********");
Expand All @@ -922,7 +839,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh

if (_ledBuffer) free(_ledBuffer); // should not happen
if (_ledsDirty) free(_ledsDirty); // should not happen

USER_PRINTLN("MatrixPanel_I2S_DMA allocate memory");
_ledsDirty = (byte*) malloc(getBitArrayBytes(_len)); // create LEDs dirty bits
if (_ledsDirty) setBitArray(_ledsDirty, _len, false); // reset dirty bits

Expand Down Expand Up @@ -1135,25 +1052,18 @@ void BusHub75Matrix::cleanup() {
}

void BusHub75Matrix::deallocatePins() {
uint8_t pins[PIN_COUNT];
memcpy(pins, &activeMXconfig.gpio, sizeof(activeMXconfig.gpio));
pinManager.deallocateMultiplePins(pins, PIN_COUNT, PinOwner::HUB75);
}

pinManager.deallocatePin(activeMXconfig.gpio.r1, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.g1, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.b1, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.r2, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.g2, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.b2, PinOwner::HUB75);

pinManager.deallocatePin(activeMXconfig.gpio.lat, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.oe, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.clk, PinOwner::HUB75);

pinManager.deallocatePin(activeMXconfig.gpio.a, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.b, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.c, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.d, PinOwner::HUB75);
pinManager.deallocatePin(activeMXconfig.gpio.e, PinOwner::HUB75);

uint8_t BusHub75Matrix::getPins(uint8_t* pinArray) const {
pinArray[0] = activeMXconfig.mx_width;
pinArray[1] = activeMXconfig.mx_height;
pinArray[2] = activeMXconfig.chain_length;
return 3;
}

#endif
// ***************************************************************************

Expand Down Expand Up @@ -1181,12 +1091,12 @@ uint32_t BusManager::memUsage(BusConfig &bc) {

int BusManager::add(BusConfig &bc) {
if (getNumBusses() - getNumVirtualBusses() >= WLED_MAX_BUSSES) return -1;
DEBUG_PRINTF("BusManager::add(bc.type=%u)\n", bc.type);
USER_PRINTF("BusManager::add(bc.type=%u)\n", bc.type);
if (bc.type >= TYPE_NET_DDP_RGB && bc.type < 96) {
busses[numBusses] = new BusNetwork(bc);
} else if (bc.type >= TYPE_HUB75MATRIX && bc.type <= (TYPE_HUB75MATRIX + 10)) {
#ifdef WLED_ENABLE_HUB75MATRIX
DEBUG_PRINTLN("BusManager::add - Adding BusHub75Matrix");
USER_PRINTLN("BusManager::add - Adding BusHub75Matrix");
busses[numBusses] = new BusHub75Matrix(bc);
USER_PRINTLN("[BusHub75Matrix] ");
#else
Expand Down
6 changes: 2 additions & 4 deletions wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ class BusHub75Matrix : public Bus {

void setBrightness(uint8_t b, bool immediate) override;

uint8_t getPins(uint8_t* pinArray) const override {
pinArray[0] = activeMXconfig.chain_length;
return 1;
} // Fake value due to keep finaliseInit happy
uint8_t getPins(uint8_t* pinArray) const override;

void deallocatePins();

Expand All @@ -404,6 +401,7 @@ class BusHub75Matrix : public Bus {
unsigned _panelWidth = 0;
CRGB *_ledBuffer = nullptr;
byte *_ledsDirty = nullptr;
const int PIN_COUNT = 14;
// C++ dirty trick: private static variables are actually _not_ part of the class (however only visibile to class instances).
// These variables persist when BusHub75Matrix gets deleted.
static MatrixPanel_I2S_DMA *activeDisplay; // active display object
Expand Down
2 changes: 1 addition & 1 deletion wled00/data/settings_leds.htm
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
}
gId("rf"+n).onclick = (t == 31) ? (()=>{return false}) : (()=>{}); // prevent change for TM1814
gRGBW |= isRGBW = ((t > 17 && t < 22) || (t > 28 && t < 32) || (t > 40 && t < 46 && t != 43) || t == 88); // RGBW checkbox, TYPE_xxxx values from const.h
gId("co"+n).style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)||(t >= 100 && t < 110)) ? "none":"inline"; // hide color order for PWM
gId("co"+n).style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? "none":"inline"; // hide color order for PWM
gId("dig"+n+"w").style.display = (t > 28 && t < 32) ? "inline":"none"; // show swap channels dropdown
if (!(t > 28 && t < 32)) d.getElementsByName("WO"+n)[0].value = 0; // reset swapping
gId("dig"+n+"c").style.display = ((t >= 40 && t < 48)||(t >= 100 && t < 110)) ? "none":"inline"; // hide count for analog and HUB75
Expand Down
6 changes: 6 additions & 0 deletions wled00/pin_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ bool PinManagerClass::allocateMultiplePins(const managed_pin_type * mptArray, by
return true;
}

bool PinManagerClass::allocateMultiplePins(const uint8_t * mptArray, byte arrayElementCount, PinOwner tag, boolean output) {
PinManagerPinType pins[arrayElementCount];
for (int i=0; i<arrayElementCount; i++) pins[i] = {mptArray[i], output};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my compiler doesn't like this line.

wled00/pin_manager.cpp: In member function 'bool PinManagerClass::allocateMultiplePins(const uint8_t*, byte, PinOwner, boolean)':
wled00/pin_manager.cpp:456:64: warning: narrowing conversion of '(uint8_t)(*(mptArray + ((sizetype)i)))' from 'uint8_t' {aka 'unsigned char'} to 'int8_t' {aka 'signed char'} inside { } [-Wnarrowing]
   for (int i=0; i<arrayElementCount; i++) pins[i] = {mptArray[i], output};
                                                      ~~~~~~~~~~^

might be worth to add an explicit cast to int8_t :

for (int i=0; i<arrayElementCount; i++) pins[i] = {int8_t(mptArray[i]), output};

return allocateMultiplePins(pins, arrayElementCount, tag);
}

bool PinManagerClass::allocatePin(byte gpio, bool output, PinOwner tag)
{
// HW I2C & SPI pins have to be allocated using allocateMultiplePins variant since there is always SCL/SDA pair
Expand Down
1 change: 1 addition & 0 deletions wled00/pin_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class PinManagerClass {
// Provided to simplify error condition handling in clients
// using more than one pin, such as I2C, SPI, rotary encoders,
// ethernet, etc..
bool allocateMultiplePins(const uint8_t * mptArray, byte arrayElementCount, PinOwner tag, boolean output);
bool allocateMultiplePins(const managed_pin_type * mptArray, byte arrayElementCount, PinOwner tag );

#if !defined(ESP8266) // ESP8266 compiler doesn't understand deprecated attribute
Expand Down