@@ -649,6 +649,20 @@ Segment &Segment::setPalette(uint8_t pal) {
649649 return *this ;
650650}
651651
652+ Segment &Segment::setName (const char *newName) {
653+ if (newName) {
654+ const int newLen = min (strlen (newName), (size_t )WLED_MAX_SEGNAME_LEN);
655+ if (newLen) {
656+ if (name) name = static_cast <char *>(realloc (name, newLen+1 ));
657+ else name = static_cast <char *>(malloc (newLen+1 ));
658+ if (name) strlcpy (name, newName, newLen+1 );
659+ name[newLen] = 0 ;
660+ return *this ;
661+ }
662+ }
663+ return clearName ();
664+ }
665+
652666// 2D matrix
653667unsigned Segment::virtualWidth () const {
654668 unsigned groupLen = groupLength ();
@@ -1311,6 +1325,34 @@ void WS2812FX::finalizeInit() {
13111325
13121326 _hasWhiteChannel = _isOffRefreshRequired = false ;
13131327
1328+ unsigned digitalCount = 0 ;
1329+ #if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3)
1330+ // determine if it is sensible to use parallel I2S outputs on ESP32 (i.e. more than 5 outputs = 1 I2S + 4 RMT)
1331+ unsigned maxLedsOnBus = 0 ;
1332+ for (const auto &bus : busConfigs) {
1333+ if (Bus::isDigital (bus.type ) && !Bus::is2Pin (bus.type )) {
1334+ digitalCount++;
1335+ if (bus.count > maxLedsOnBus) maxLedsOnBus = bus.count ;
1336+ }
1337+ }
1338+ DEBUG_PRINTF_P (PSTR (" Maximum LEDs on a bus: %u\n Digital buses: %u\n " ), maxLedsOnBus, digitalCount);
1339+ // we may remove 300 LEDs per bus limit when NeoPixelBus is updated beyond 2.9.0
1340+ if (maxLedsOnBus <= 300 && useParallelI2S) BusManager::useParallelOutput (); // must call before creating buses
1341+ else useParallelI2S = false ; // enforce single I2S
1342+ #endif
1343+
1344+ // create buses/outputs
1345+ unsigned mem = 0 ;
1346+ digitalCount = 0 ;
1347+ for (const auto &bus : busConfigs) {
1348+ mem += bus.memUsage (Bus::isDigital (bus.type ) && !Bus::is2Pin (bus.type ) ? digitalCount++ : 0 ); // includes global buffer
1349+ if (mem <= MAX_LED_MEMORY) {
1350+ if (BusManager::add (bus) == -1 ) break ;
1351+ } else DEBUG_PRINTF_P (PSTR (" Out of LED memory! Bus %d (%d) #%u not created." ), (int )bus.type , (int )bus.count , digitalCount);
1352+ }
1353+ busConfigs.clear ();
1354+ busConfigs.shrink_to_fit ();
1355+
13141356 // if busses failed to load, add default (fresh install, FS issue, ...)
13151357 if (BusManager::getNumBusses () == 0 ) {
13161358 DEBUG_PRINTLN (F (" No busses, init default" ));
@@ -1326,6 +1368,7 @@ void WS2812FX::finalizeInit() {
13261368
13271369 unsigned prevLen = 0 ;
13281370 unsigned pinsIndex = 0 ;
1371+ digitalCount = 0 ;
13291372 for (unsigned i = 0 ; i < WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES; i++) {
13301373 uint8_t defPin[OUTPUT_MAX_PINS];
13311374 // if we have less types than requested outputs and they do not align, use last known type to set current type
@@ -1390,9 +1433,11 @@ void WS2812FX::finalizeInit() {
13901433 if (Bus::isPWM (dataType) || Bus::isOnOff (dataType)) count = 1 ;
13911434 prevLen += count;
13921435 BusConfig defCfg = BusConfig (dataType, defPin, start, count, DEFAULT_LED_COLOR_ORDER, false , 0 , RGBW_MODE_MANUAL_ONLY, 0 , useGlobalLedBuffer);
1436+ mem += defCfg.memUsage (Bus::isDigital (dataType) && !Bus::is2Pin (dataType) ? digitalCount++ : 0 );
13931437 if (BusManager::add (defCfg) == -1 ) break ;
13941438 }
13951439 }
1440+ DEBUG_PRINTF_P (PSTR (" LED buffer size: %uB/%uB\n " ), mem, BusManager::memUsage ());
13961441
13971442 _length = 0 ;
13981443 for (int i=0 ; i<BusManager::getNumBusses (); i++) {
@@ -1409,6 +1454,7 @@ void WS2812FX::finalizeInit() {
14091454 // This must be done after all buses have been created, as some kinds (parallel I2S) interact
14101455 bus->begin ();
14111456 }
1457+ DEBUG_PRINTF_P (PSTR (" Heap after buses: %d\n " ), ESP.getFreeHeap ());
14121458
14131459 Segment::maxWidth = _length;
14141460 Segment::maxHeight = 1 ;
0 commit comments