Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15287

Giga Display Shield: SDRAM

$
0
0

Has anyone been able to store a copy of the screen to SDRAM then redraw the copy to screen? The code below gets close, but screen is garbled.


#include <Arduino_GigaDisplay_GFX.h>
//#include <Adafruit_GFX.h>
#include "ArduinoGraphics.h"
#include <Arduino_USBHostMbed5.h>
#include <DigitalOut.h>
#include <FATFileSystem.h>
//#include "SDRAM.h"  //not needed for Giga R1

GigaDisplay_GFX tft;

USBHostMSD msd;
mbed::FATFileSystem usb("SD"); // "SD" For compatibility with legacy code 

uint16_t* sdRam = (uint16_t*)SDRAM.malloc(800*480*2); // or (HW_SDRAM_SIZE)

extern "C" char* sbrk(int incr);

void display_freeram(){
  Serial.print(F("- SRAM left: "));
  Serial.println(freeRam());
}

int freeRam() {
  char top;
  return &top - reinterpret_cast<char*>(sbrk(0));
}


void setup() {
  Serial.begin(115200);
  delay(10);
  display_freeram();
  //sdram_init();
  tft.begin();
  tft.setRotation(1); 

  while (!msd.connect()) {
     //while (!port.connected()) {
     delay(1000);
    }

  Serial.print("Mounting USB device... ");
    int err = usb.mount(&msd);
    if (err) {
        Serial.print("Error mounting USB device ");
        Serial.println(err);
        while (1);
    }
  Serial.println("done.");

  //tft.drawRGBBitmap(0, 0, zermat_swissalps, zermat_swissalpsWidth, zermat_swissalpsHeight); 
  
  drawRaw("/SD/Zermat-SwissAlps.raw", 0, 0, 800, 480);
 
  sdRam = (uint16_t*)dsi_getActiveFrameBuffer();
  Serial.print("Size of sdRam: "); Serial.println(sizeof(sdRam));
  
  tft.fillScreen(0);
  tft.drawRGBBitmap(0, 0, sdRam, 800, 480);

}

void loop() { }



void drawRaw(char* filename, int x, int y, int rawWidth, int rawHeight) {
  uint8_t    rowMultp = 5;                  // number of rows to read/write,
                                             // evenly divisible by rawHeight
  uint16_t   sdBuffer[rowMultp * rawWidth]; // SD read pixel buffer (16 bits per pixel)
  uint8_t    buffidx = 0;                    // Current position in sdBuffer
  int        freadReturn;
  uint32_t   drawTime = millis();            // Keep track of speed

  // Check file exists and open it
  FILE* rawFile = fopen(filename, "rb+");
  if (rawFile == NULL) Serial.print("File not found...");
  else {Serial.print("Opened "); Serial.println(filename);} 
  Serial.print("sizeof sdBuffer: "); Serial.println(sizeof(sdBuffer));

  for (int row = y; row < rawHeight; row+=rowMultp) {

     //Read data from SD card or USB in raw rgb565 format (little endian)
     freadReturn = fread(&sdBuffer, sizeof(uint16_t), rawWidth * rowMultp, rawFile);
     //Serial.print("freadReturn = "); Serial.println(freadReturn);

    //Draw image by block of rows specified in rowMultp var
     tft.drawRGBBitmap(x, row, sdBuffer, rawWidth, rowMultp);
     }
   
  fclose(rawFile);
  fflush(stdout);
   
  Serial.print("drawTime: ");
  Serial.println(millis() - drawTime);
  Serial.println();
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 15287

Trending Articles