Skip to content

ESP32's RMT method does not clear edit and transmit buffers #904

@blazoncek

Description

@blazoncek

Describe the bug
When a RMT bus is started a ClearTo(0) is called to clear edit buffer, however no such call is made to clear transmit buffer. The allocation assumes user will use "consistent" Show() which will copy one buffer to another when switching buffers.
If we then use Show(false) to avoid copying edit buffer to transmit buffer (i.e. inconsistent show) pixels that are not painted using SetPixelColor() contain random values and will "blink" with each frame.

To Reproduce
This example may display behaviour (randomly blinking LEDs 1 to 8) depending on randomness of allocated memory for buffers:

#define GPIO 2
NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt0Ws2812xMethod> bus(10, GPIO);

setup() {
  bus.Begin();
}

loop() {
  bus.SetPixelColor(0, RgbColor(255,0,0));
  bus.SetPixelColor(9, RgbColor(0,0,255));
  bus.Show(false);
  delay(1000);
  bus.SetPixelColor(0, RgbColor(0,0,255));
  bus.SetPixelColor(9, RgbColor(255,0,0));
  bus.Show(false);
  delay(1000);
}

This is more pronounced when bus is allocated dynamically using new operator.
Inconsistent Show() is used for performance reasons as it is not necessary to maintain buffers that are in sync.

Expected behavior
Both buffers cleared upon allocation.

    void NeoEsp32RmtMethodBase::construct()
    {
        _dataEditing = static_cast<uint8_t*>(malloc(_sizeData));
        // data cleared later in Begin()

        _dataSending = static_cast<uint8_t*>(calloc(_sizeData, 1));
        // reset to 0s
    }

Or modify higher level Begin() to clear both buffers.

void NeoPixelBus::Begin(...) {
  _method.Initialize(...);
  ClearTo(0);
  if (_method.SwapBuffers()) ClearTo(0);
}

Development environment:

  • Library version [e.g. v2.8.4]

Minimal Sketch that reproduced the problem:
See above.

Additional context
WLED uses its own "edit" buffers and does not need NeoPixelBus to maintain "edit" and "transmit" buffers, hence calls to inconsistent Show().
I can provide a patch if this is considered a bug. I would prefer using calloc() method, however ClearTo(0) method may be more universal and future-proof.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions