Better handling of DMA re-init

This commit is contained in:
cschwinne 2021-01-19 17:22:37 +01:00
parent 67833c5513
commit 849e04ab83
2 changed files with 18 additions and 3 deletions

View File

@ -62,7 +62,7 @@ void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
_lengthRaw += LED_SKIP_AMOUNT; _lengthRaw += LED_SKIP_AMOUNT;
} }
uint8_t pins[] = {2}; uint8_t pins[] = {LEDPIN};
while (!busses->canAllShow()) yield(); while (!busses->canAllShow()) yield();
busses->removeAll(); busses->removeAll();
@ -72,6 +72,17 @@ void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
_segments[0].stop = _length; _segments[0].stop = _length;
setBrightness(_brightness); setBrightness(_brightness);
#ifdef ESP8266
for (uint8_t i = 0; i < busses->getNumBusses(); i++) {
Bus* b = busses->getBus(i);
if ((!IS_DIGITAL(b->getType()) || IS_2PIN(b->getType()))) continue;
uint8_t pins[5];
b->getPins(pins);
BusDigital* bd = static_cast<BusDigital*>(b);
if (pins[0] == 3) bd->reinit();
}
#endif
} }
void WS2812FX::service() { void WS2812FX::service() {

View File

@ -102,10 +102,10 @@ class BusDigital : public Bus {
} }
void setBrightness(uint8_t b) { void setBrightness(uint8_t b) {
//Fix for turning off onboard LED breaking bus and quick fix for DMA not initializing correctly //Fix for turning off onboard LED breaking bus
#ifdef LED_BUILTIN #ifdef LED_BUILTIN
if (_bri == 0 && b > 0) { if (_bri == 0 && b > 0) {
if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN || (_pins[0] == 3 && _iType < 17)) PolyBus::begin(_busPtr, _iType); if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN) PolyBus::begin(_busPtr, _iType);
} }
#endif #endif
_bri = b; _bri = b;
@ -141,6 +141,10 @@ class BusDigital : public Bus {
_colorOrder = colorOrder; _colorOrder = colorOrder;
} }
void reinit() {
PolyBus::begin(_busPtr, _iType);
}
void cleanup() { void cleanup() {
//Serial.println("Digital Cleanup"); //Serial.println("Digital Cleanup");
PolyBus::cleanup(_busPtr, _iType); PolyBus::cleanup(_busPtr, _iType);