I am trying to use libwebp
to decode animated images and display them on an RGB LED Matrix driven by an Adafruit MatrixPortal. My development environment is as follows:
board=adafruit_matrix_portal_m4
lib_deps
libwebp
included as a submodule in the lib
directorylib/assets
The lib structure is modeled after the tidbyt/hdk firmware, and the webp asset is pulled directly from there.
I have been able to successfully compile and upload my main.cpp
and display a basic text graphic on my LED matrix, so I feel pretty good about my overall architecture.
When I add the single line to initialize a decoder using libwebp
's WebPAnimDecoderNew
, the upload fails around 50% with the message SAM-BA operation failed
. The following is my working main.cpp
, with the problem line commented out.
#include <Arduino.h>
#include <Adafruit_Protomatter.h>
#include <webp/demux.h>
#include <assets.h>
uint8_t rgbCount = 1;
uint8_t rgbPins[] = {7, 8, 9, 10, 11, 12};
uint8_t addrCount = 4;
uint8_t addrPins[] = {17, 18, 19, 20};
uint8_t clockPin = 14;
uint8_t latchPin = 15;
uint8_t oePin = 16;
uint8_t bitDepth = 6; // 5;
Adafruit_Protomatter matrix(
128, bitDepth, rgbCount, rgbPins, addrCount, addrPins, clockPin, latchPin, oePin, false);
WebPData webPData;
void setup()
{
Serial.begin(9600);
delay(2000);
ProtomatterStatus status = matrix.begin();
Serial.print("Protomatter begin() status: ");
Serial.println((int)status);
if (status != PROTOMATTER_OK)
{
for (;;)
;
}
}
void loop()
{
Serial.print("Refresh FPS = ~");
Serial.println(matrix.getFrameCount());
drawTestGraphic();
drawWebP();
delay(1000);
}
void drawTestGraphic()
{
for (int x = 0; x < matrix.width(); x++)
{
uint8_t level = x * 256 / matrix.width();
matrix.drawPixel(x, matrix.height() - 4, matrix.color565(level, 0, 0));
matrix.drawPixel(x, matrix.height() - 3, matrix.color565(0, level, 0));
matrix.drawPixel(x, matrix.height() - 2, matrix.color565(0, 0, level));
matrix.drawPixel(x, matrix.height() - 1, matrix.color565(level, level, level));
}
matrix.show();
}
void drawWebP()
{
WebPDataClear(&webPData);
webPData.size = ASSET_NOAPPS_WEBP_LEN;
webPData.bytes = (uint8_t *)malloc(ASSET_NOAPPS_WEBP_LEN);
memcpy((void *)webPData.bytes, ASSET_NOAPPS_WEBP, ASSET_NOAPPS_WEBP_LEN);
// Where I want to start decoding...
// WebPAnimDecoder *decoder = WebPAnimDecoderNew(&webPData, NULL);
free((void *)webPData.bytes);
}
Has anyone experienced this before with libwebp
? Any suggestions on what might be causing this issue with this line specifically?
As @TimRoberts pointed out, this is due to the limited memory of the MatrixPortal M4. The confusion was in the fact that the M4 has both a ATSAMD51J19 Cortex M4 processor and an ESP32 WiFi co-processor. Even though there is a co-processor, the RAM accessible to the firmware is in limited to kb.
Most of the projects I was looking at use an ESP32-S3, which has significantly more (8MB) memory.
Coincidentally, Adafruit just released a Matrixportal S3 that uses the ESP32S3. I'm going to try to either migrate this project to one of those or to a Raspberry Pi.