#ifndef BOARD_HAS_PSRAM
#error "Please enable PSRAM, Arduino IDE -> tools -> PSRAM -> OPI !!!"
#endif

/* Simple firmware for a ESP32 displaying a static image on an EPaper Screen.
 *
 * Write an image into a header file using a 3...2...1...0 format per pixel,
 * for 4 bits color (16 colors - well, greys.) MSB first.  At 80 MHz, screen
 * clears execute in 1.075 seconds and images are drawn in 1.531 seconds.
 */

#include <Arduino.h>
#include "epd_driver.h"
#include "staticmap.h"
#include "utilities.h"

uint8_t *framebuffer;

void setup()
{
  Serial.begin(115200);

  epd_init();

  framebuffer = (uint8_t *)heap_caps_malloc(EPD_WIDTH * EPD_HEIGHT / 2, MALLOC_CAP_SPIRAM);

  if (!framebuffer)
  {
    Serial.println("alloc memory failed !!!");
    while (1)
      ;
  }

  memset(framebuffer, 0xFF, EPD_WIDTH * EPD_HEIGHT / 2);

  Rect_t area = {
      .x = EPD_WIDTH - staticmap_width,
      .y = 0,
      .width = staticmap_width,
      .height = staticmap_height};
  epd_poweron();
  epd_clear();
  epd_draw_grayscale_image(area, (uint8_t *)staticmap_data);
  epd_poweroff();
}

void loop()
{
  delay(3000);
}
