Makuna / NeoPixelBus

An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs. Please refer to the Wiki for more details. Please use the GitHub Discussions to ask questions as the GitHub Issues feature is used for bug tracking.
GNU Lesser General Public License v3.0
1.18k stars 264 forks source link

ESP32 I2S parallel channels - Compiler error because IsWriteDone() is not `const` ( NeoPixelBrightnessBus) #695

Closed softhack007 closed 1 year ago

softhack007 commented 1 year ago

Hi, I'm playing with the new I2S parallel mode, to see how it could be integrated into WLED.

I'm still on NeoPixelBrightnessBus and haven't changed to NeoPixelBusLg in my in-work version yet. So not sure if this problem happens with the depricated BrightnessBus only.

I'm running into a compile error, that seems to come because the IsWriteDone() method of NeoEsp32I2sXMethod is not const. Actually I can fix my build by adding const, however I'm not sure if this the right solution. Please advise.

https://github.com/Makuna/NeoPixelBus/blob/327b2d86d7902d7a73af24d1c6264028b495bcdb/src/internal/methods/NeoEsp32I2sXMethod.h#L472-L475

my humble workaround:

    bool IsWriteDone() const
    {

The code in WLED is a bit complicated, as we use void* to store arbitrary bus objects. Basically we do this:

#include "NeoPixelBrightnessBus.h"
#define B_32_I1X_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1X8Ws2812xMethod>

void* busPtr = nullptr;
busPtr = new B_32_I1X_NEO_3(len, pins[0]);

static void begin(void* busPtr) { (static_cast<B_32_I1X_NEO_3 *>(busPtr))->Begin(); }              // works
static bool canShow(void* busPtr) { return (static_cast<B_32_I1X_NEO_3 *>(busPtr))->CanShow(); }   // compile error 

compile error:

In file included from .pio/libdeps/esp32_16MB_V4_M_debug/NeoPixelBus/src/internal/NeoMethods.h:54,
                 from .pio/libdeps/esp32_16MB_V4_M_debug/NeoPixelBus/src/NeoPixelBus.h:43,
                 from .pio/libdeps/esp32_16MB_V4_M_debug/NeoPixelBus/src/NeoPixelBrightnessBus.h:29,
                 from wled00/bus_wrapper.h:4,
                 from wled00/bus_manager.cpp:9:
.pio/libdeps/esp32_16MB_V4_M_debug/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h: In instantiation of 'bool NeoEsp32I2sXMethodBase<T_SPEED, T_BUS, T_INVERT>::IsReadyToUpdate() const [with T_SPEED = NeoEsp32I2sSpeedWs2812x; T_BUS = NeoEsp32I2sMuxBus<NeoEspI2sDblBuffContext<NeoEspI2sMuxMap<unsigned char, NeoEspI2sMuxBusSize8Bit> >, NeoEsp32I2sBusOne>; T_INVERT = NeoEsp32I2sNotInverted]':
.pio/libdeps/esp32_16MB_V4_M_debug/NeoPixelBus/src/NeoPixelBus.h:138:40:   required from 'bool NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::CanShow() const [with T_COLOR_FEATURE = NeoGrbFeature; T_METHOD = NeoEsp32I2sXMethodBase<NeoEsp32I2sSpeedWs2812x, NeoEsp32I2sMuxBus<NeoEspI2sDblBuffContext<NeoEspI2sMuxMap<unsigned char, NeoEspI2sMuxBusSize8Bit> >, NeoEsp32I2sBusOne>, NeoEsp32I2sNotInverted>]'
wled00/bus_wrapper.h:519:86:   required from here
.pio/libdeps/esp32_16MB_V4_M_debug/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h:539:33: error: passing 'const NeoEsp32I2sMuxBus<NeoEspI2sDblBuffContext<NeoEspI2sMuxMap<unsigned char, NeoEspI2sMuxBusSize8Bit> >, NeoEsp32I2sBusOne>' as 'this' argument discards qualifiers [-fpermissive]
         return _bus.IsWriteDone();
                                 ^
.pio/libdeps/esp32_16MB_V4_M_debug/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h:472:10: note:   in call to 'bool NeoEsp32I2sMuxBus<T_BUSCONTEXT, T_BUS>::IsWriteDone() [with T_BUSCONTEXT = NeoEspI2sDblBuffContext<NeoEspI2sMuxMap<unsigned char, NeoEspI2sMuxBusSize8Bit> >; T_BUS = NeoEsp32I2sBusOne]'
     bool IsWriteDone()
          ^~~~~~~~~~~
*** [.pio\build\esp32_16MB_V4_M_debug\src\bus_manager.cpp.o] Error 1

Evironment:

Makuna commented 1 year ago

Interesting, you are correct; that method should be marked const and it should not be compiling as is.

Will you create a pull with the change?

softhack007 commented 1 year ago

yep, can do.

Makuna commented 1 year ago

https://github.com/Makuna/NeoPixelBus/releases/tag/2.7.6