Skip to content

16-bit image on SD-card

The 16-bit image on SD-card library saves the screen as a header file on the SD-card.

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.

Info

This method is not recommended for MCUs, as the management of the SD-card is rather slow and prone to interferences.

The image 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_Image16.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 properly configured.

File_Image16 myFile(&myScreen);

The constructor File_Image16() 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
uint8_t result = myFile.beginFileSystem(pinCS,
    portSPI,
    pinDetect,
    pinLevel);

if (result != RESULT_SUCCESS)
{
    hV_HAL_Serial_crlf();
    hV_HAL_log(LEVEL_CRITICAL, "SD-card error");
    hV_HAL_exit(0x01);
}

result = myFile.setFolder("Image");

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.

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

uint8_t result = myFile.saveScreen("File_Image16");

saveScreen() saves the screen on the SD-card as a image.

The function returns RESULT_SUCCESS if successful, RESULT_ERROR otherwise.

The required parameter is

  • The first line provides the name of the file without the .h extension.
1
2
uint8_t result = myFile.saveWindow("Colours4",
    40, 71, 100, 50) // x y dx dy

saveWindow() save a window on a header file on the SD-card as an image.

The required parameters are

  • The first line provides the name of the file without the .h extension.

  • The second line defines the window with vector coordinates.

The coordinates are rounded as multiple of 8.

For example, the vector coordinates (70, 44, 155, 64) are changed to (70, 40, 155, 72).

The resulting header file is named Colours4.h and contains the structure Image_Colours4.

The function returns RESULT_SUCCESS if successful, RESULT_ERROR otherwise.

uint8_t result = myFilemyFile.endFileSystem();

endFileSystem() closes the SD-card.

The function returns RESULT_SUCCESS if successful, RESULT_ERROR otherwise.

Display

#include "Colours4.h"

myFile.readScreen(Image_Colours4);
myScreen.flush();

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_Image16 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_Image.ino.

First, generate the header file.

void displayWriteSerialImage()
{
    // 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, "File Image16");
    myScreen.flush();

    // Write to SD-card
    result = myFile.saveScreen("File_Image16");
    wait(4);
}

The generated header file is

// Image16 as header file generated by hV_File_Image16

// SDK
#include "hV_HAL_Peripherals.h"

// Release
#ifndef FILE_IMAGE_FILE_IMAGE_RELEASE
#define FILE_IMAGE_FILE_IMAGE_RELEASE

#include "hV_Image16.h"

static const uint16_t Table_File_Image16[] =
{
    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, // v= 152
    // ...
    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, // v= 1
};

const image16_s Image_File_Image16 =
{
    .minWindowH = 0,
    .minWindowV = 0,
    .maxWindowH = 151,
    .maxWindowV = 151,
    .depth = 2,
    .size = 23104,
    .table = Table_File_Image16
};

#endif // FILE_IMAGE_FILE_IMAGE_RELEASE

The window uses rectangular coordinates.