Drawing a Bitmap from an external sd-card with GUI_BMP_DrawEx() ?

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Drawing a Bitmap from an external sd-card with GUI_BMP_DrawEx() ?

    Dear emWin-users,

    I am trying to draw a Bitmap picture (abc.bmp) from an external sd-card on the LCD with the GUI_BMP_DrawEx()-function.
    So I have stored a .bmp file on my external sd-card and do the following: here is my code:

    /////////////////
    FATFS FatFs;
    FRESULT res;
    FIL fil;


    static char _acBuffer[400];

    int APP_GetData(void * p, const U8 * * ppData, unsigned NumBytesReq, U32 Off) {
    FILE *phfile;
    DWORD NumBytesRead;
    phfile = (FILE *)p;

    //
    // Set file pointer to the offset location
    //
    fseek(phfile, Off, SEEK_SET);
    //
    // Read data into buffer
    //
    NumBytesRead = fread(_acBuffer, sizeof(char), NumBytesReq, phfile);
    //
    // Set data pointer to the beginning of the buffer
    //
    *ppData = _acBuffer;
    //
    // Return number of available bytes
    //
    return NumBytesRead;
    }


    int main (void)
    {

    res = f_mount(&FatFs, " ", 1) // it passes, it is successfully mounted (FR_OK after debugging);

    res = f_open(&fil, "abc.bmp", FA_CREATE_ALWAYS | FA_WRITE); // it passes, it is successfully opened (FR_OK after debugging)

    GUI_BMP_DrawEx(APP_GetData, fil, 0, 0);

    }

    But somehow nothing happens ..... it is not visualized on the screen....

    Can you help me or provide a small example.....

    Thanks
    Ivo
  • Hi Ivo,

    The code you have posted looks already pretty much like one of our sample and there is nothing obvious what might be faulty.

    Maybe one thing, the function GUI_BMP_DrawEx() expects a void pointer as second parameter. So instead of

    GUI_BMP_DrawEx(APP_GetData, fil, 0, 0);

    Try this one

    GUI_BMP_DrawEx(APP_GetData, (void *)&fil, 0, 0);

    If you set a break point in the APP_GetData() function, what is the value of NumBytesRead after reading from the file?

    Regards,
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi Sven,


    thank you for you continuous support here....

    So today I was able to reproduce a *.bmp file on my screen, but only with a restricted size. For example, a picture of appr. 350x200 pixels I can display well, but a 600x200 I cannot (my external display is 800x480).
    After break pointing in the APP_GetData() --> NumBytesRead for the 350x200-bitmap is 1096 and since my _acBuffer is [1200] all works fine.... I increase the buffer to _acBuffer[5000] but it still cannot reproduce 600x200 picture from an external sd-card.

    Any idea....??

    I am using an external SDRAM and I edited GUIConf.c like following (and it works, obviously I can display at least some pictures from external sd-card):

    #define GUI_NUMBYTES (1024) * 120 ---> what about this ??


    #define GUI_BUFFER_IN_EXT_RAM 1
    #define GUI_BUFFER_ADDRESS 0xD0600000
    #define OS_SUPPORT 1



    void GUI_X_Config(void) {

    //
    // 32 bit aligned memory area
    //
    #ifdef GUI_BUFFER_IN_EXT_RAM
    static U32 aMemory[GUI_NUMBYTES / 4]__attribute__((at(GUI_BUFFER_ADDRESS)));
    #else
    static U32 aMemory[GUI_NUMBYTES / 4];
    #endif
    //
    // Assign memory to emWin
    //
    GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);
    //
    // Set default font
    //
    GUI_SetDefaultFont(GUI_FONT_6X8);
    }



    Thank you
  • Hi,
    #define GUI_NUMBYTES (1024) * 120 ---> what about this ??
    This defines the amount of RAM emWin gets allocated to work with.

    Since your memory seems to be located in the SDRAM (there should be more 120k available), please try to increase the memory. Maybe this solves the issue.

    Regards,
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.