Frame-buffer header file on SD-card¶
The frame-buffer header file on SD-card library prints the frame-buffer of the screen as a header file on the serial console.
The header file is added to the source code and included in the project of the application statically at build-time. Once the application is built, it loads the image into the frame-buffer, ready to be displayed dynamically at run-time.
This option supports all the screens, monochrome and colour.
Info
This method is not recommended for MCUs, as the management of the SD-card is rather slow and prone to interferences.
The frame-buffer header file on SD-card library is available on the Commercial edition.
Configure¶
Warning
Ensure the screen is declared and initialised according to the configuration procedure.
#include "hV_File_Frame.h"
The pre-processor statement includes the file library. It should be mentioned after the statement for the screen library.
Danger
This library requires the external SD library to manage the SD-card.
Ensure the external SD library is installed and configured properly.
File_Frame myFile(&myScreen);
The constructor File_Frame()
sets the link to the screen. It should be mentioned after the constructor of the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
beginFileSystem()
checks an SD-card is available and initialises it.
The required parameter is
- The first line sets the pin for selecting the SD-card.
It is easily provided with myScreen.getBoardPins().cardCS
.
The optional parameters are
-
The second line sets the number of the SPI port,
0
by default; -
The third line sets the pin for the detect signal,
NOT_CONNECTED
or-1
par default; -
The fourth line sets the level of detect signal,
LOW
by default.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
To obtain the pin for selecting the SD-card, use
uint8_t pinCardCS = myScreen.getBoardPins().cardCS;
uint8_t result = myFile.beginFileSystem(pinCardCS);
setFolder()
sets the name of the folder for the files, and creates it if it does not exists.
By default, the files are located under the folder img
.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
Use¶
Generate¶
myFile.saveScreen("File_Frame");
saveScreen()
saves the screen on the SD-card as a frame-buffer header file.
The required parameter is
- The first line provides the name of the file without the
.h
extension.
The resulting header file is named File_Frame.h
and contains the structure Buffer_Buffer
.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
uint8_t result = myFile.endFileSystem();
endFileSystem()
closes the SD-card.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
Display¶
// Image
#include "Buffer.h"
uint8_t result;
result = myFile.readScreen(Buffer_Buffer);
if (result == RESULT_SUCCESS)
{
myScreen.flush();
wait(4);
}
The application needs to include the header file previously generated.
readScreen()
loads the image into the frame-buffer, ready to be displayed.
The header file can also be read with the Serial_Buffer
object, from the 16-bit image implementation on the Serial library.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
Example¶
This is the core of the code from example File_Write_Buffer.ino
.
First, generate the header file.
void displayPrintSerial()
{
// Initialise
uint8_t result;
result = myFile.beginFileSystem(5);
if (result != RESULT_SUCCESS)
{
hV_HAL_log(LEVEL_ERROR, "SD-card error");
hV_HAL_Serial_crlf();
return;
}
myScreen.setOrientation(myOrientation);
myScreen.selectFont(fontLarge);
myScreen.clear();
myScreen.gText(8, 8, "Header Buffer");
myScreen.flushFast();
// Write to SD-card
result = mySerialImage.saveScreen("Buffer");
wait(4);
}
The generated header file contains the frame-buffer as an array.
// Frame-buffer as header file generated by hV_Serial_Buffer
// SDK
#include "hV_HAL_Peripherals.h"
// Release
#ifndef HEADER_BUFFER_BUFFER_RELEASE
#define HEADER_BUFFER_BUFFER_RELEASE
static const uint8_t Buffer_Buffer[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // v= 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // v= 1
// ...
}
#endif // HEADER_BUFFER_BUFFER_RELEASE
The window uses rectangular coordinates.
Then, include the header file in the application and build it.
// Serial
#include "hV_Serial.h"
// Image
#include "Buffer.h"
void displayReadHeader()
{
uint8_t result;
myScreen.setOrientation(myOrientation);
myScreen.clear();
myScreen.gText(4, 4, "Reading the header back...");
myScreen.flushFast();
wait(4);
// Read from MCU Flash
myScreen.clear();
result = myHeader.readScreen(Buffer_Buffer);
if (result == RESULT_SUCCESS)
{
myScreen.flush();
wait(4);
}
}