Linked Questions

Popular Questions

Some Context

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:

  • Mac M2 running Ventura 13.4.1
  • PlatformIO Project configured for board=adafruit_matrix_portal_m4
  • The Adafruit Protomatter library included in lib_deps
  • libwebp included as a submodule in the lib directory
  • A hard-coded WebP for testing stored in lib/assets

The lib structure is modeled after the tidbyt/hdk firmware, and the webp asset is pulled directly from there.

What's Working

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.

What's Not Working

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?

Related Questions