Right now I have 3 copies of my FB:
backgroundBuffers[currentRefreshBuffer]
backgroundBuffers[currentDrawBuffer]
CRGB matrixleds[w*h]; (in SmartMatrix_GFX)
Currently, I need to do this:
CRGB matrixleds[w*h]
void show_callback() {
memcpy(backgroundLayer.backBuffer(), matrixleds, kMatrixHeight*kMatrixWidth*3);
backgroundLayer.swapBuffers(false);
}
I’m not entirely sure how the 2 FBs in backgroundBuffers work.
I can see they get swapped, and I can see that
backgroundLayer.swapBuffers(true) allows keeping the 2 frames in sync
I tried to do 2 things
First I tried to add this code to Layer_Background_Impl.h
template<typename RGB, unsigned int optionFlags>
void SMLayerBackground<RGB, optionFlags>::ResetBackBuffer(RGB* newbuffer) {
RGB *old = backgroundBuffers[currentDrawBuffer];
backgroundBuffers[currentDrawBuffer] = newbuffer;
free(old);
}
Then, I was kind of hoping that I could just draw in it directly, but that didn’t take care of my swapping problem, so that’s likely a dead end.
Instead, the solution was apparently do go the other way, let SmartMatrix manage its 2 buffers and repoint my CRGB FastLED buffer to the SM backbuffer.
CRGB and rgb24 are not equivalent due to the methods added to the CRGB object, but the underlying storage should be the same, no? (afterall I can memcpy from one to the other and that works fine).
//CRGB matrixleds[width*height];
CRGB *matrixleds; // don't malloc, have a pointer I can repoint
// and then after each swap, point it to the bg buffer
void show_callback() {
//memcpy(backgroundLayer.backBuffer(), matrixleds, kMatrixHeight*kMatrixWidth*3);
backgroundLayer.swapBuffers(false); // maybe true instead
//matrixleds = (CRGB *) backgroundLayer.getRealBackBuffer();
matrixleds = (CRGB *) backgroundLayer.backBuffer();
}
matrixLayer.addLayer(&backgroundLayer);
matrixLayer.begin();
//matrixleds = (CRGB *) backgroundLayer.getRealBackBuffer();
matrixleds = (CRGB *) backgroundLayer.backBuffer();
I wasn’t too clear on which one was correct between getRealBackBuffer and backBuffer.
Sadly, either way, I get a crash as soon as I write in matrixleds. I haven’t quite figured out why, yet.
Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.
0x400d5399: SmartMatrix_GFX::drawPixel(short, short, CRGB) at /home/merlin/Arduino/libraries/FastLED/pixeltypes.h line 178
So, is my hope to remove my GFX buffer mostly doomed?
Thanks