Skip to content

Commit d53d7aa

Browse files
committed
Defer calling begin() on digital buses
NeoPixelBus requires that all parallel I2S bus members be constructed before any of them call Begin(). Implement this by deferring the call to the end of bus construction. Fixes #4301.
1 parent 548736f commit d53d7aa

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

wled00/FX_fcn.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,14 +1286,9 @@ void WS2812FX::finalizeInit() {
12861286
_isOffRefreshRequired |= bus->isOffRefreshRequired() && !bus->isPWM(); // use refresh bit for phase shift with analog
12871287
unsigned busEnd = bus->getStart() + bus->getLength();
12881288
if (busEnd > _length) _length = busEnd;
1289-
#ifdef ESP8266
1290-
// why do we need to reinitialise GPIO3???
1291-
//if (!bus->isDigital() || bus->is2Pin()) continue;
1292-
//uint8_t pins[5];
1293-
//if (!bus->getPins(pins)) continue;
1294-
//BusDigital* bd = static_cast<BusDigital*>(bus);
1295-
//if (pins[0] == 3) bd->reinit();
1296-
#endif
1289+
1290+
// This must be done after all buses have been created, as some kinds (parallel I2S) interact
1291+
bus->begin();
12971292
}
12981293

12991294
Segment::maxWidth = _length;

wled00/bus_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ std::vector<LEDType> BusDigital::getLEDTypes() {
410410
};
411411
}
412412

413-
void BusDigital::reinit() {
413+
void BusDigital::begin() {
414414
if (!_valid) return;
415415
PolyBus::begin(_busPtr, _iType, _pins);
416416
}
@@ -910,7 +910,7 @@ void BusManager::on() {
910910
if (busses[i]->isDigital() && busses[i]->getPins(pins)) {
911911
if (pins[0] == LED_BUILTIN || pins[1] == LED_BUILTIN) {
912912
BusDigital *bus = static_cast<BusDigital*>(busses[i]);
913-
bus->reinit();
913+
bus->begin();
914914
break;
915915
}
916916
}

wled00/bus_manager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Bus {
7979

8080
virtual ~Bus() {} //throw the bus under the bus
8181

82+
virtual void begin() {};
8283
virtual void show() = 0;
8384
virtual bool canShow() const { return true; }
8485
virtual void setStatusPixel(uint32_t c) {}
@@ -213,7 +214,7 @@ class BusDigital : public Bus {
213214
uint16_t getLEDCurrent() const override { return _milliAmpsPerLed; }
214215
uint16_t getUsedCurrent() const override { return _milliAmpsTotal; }
215216
uint16_t getMaxCurrent() const override { return _milliAmpsMax; }
216-
void reinit();
217+
void begin() override;
217218
void cleanup();
218219

219220
static std::vector<LEDType> getLEDTypes();

wled00/bus_wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class PolyBus {
597597
case I_HS_P98_3: busPtr = new B_HS_P98_3(len, pins[1], pins[0]); break;
598598
case I_SS_P98_3: busPtr = new B_SS_P98_3(len, pins[1], pins[0]); break;
599599
}
600-
begin(busPtr, busType, pins, clock_kHz);
600+
601601
return busPtr;
602602
}
603603

0 commit comments

Comments
 (0)