draw bitmap/gif from sd card using HAL library and SDIO

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

    • draw bitmap/gif from sd card using HAL library and SDIO

      Hi.

      I want to draw bitmap or gif from external sd, but i can't understand some point...
      for reading a file from sd card using hal and sdio you should follow below steps:

      Source Code

      1. FATFS myFATFS;
      2. FIL myFILE;
      3. UINT myBYTES;
      4. FRESULT myRES;
      5. char SDPath[4];
      6. int size;
      7. uint8_t* add = (uint8_t *)0xC0000000; // Some address of external SD RAM
      8. f_mount(&myFATFS, SDPath, 1);
      9. f_open(&myFILE, "file.bmp", FA_READ);
      10. size = f_size(&myFILE);
      11. myRES = f_read(&myFILE, add, size, (UINT *)myBYTES); // read the file and copy it into the external SD RAM
      12. f_close(&myFILE);
      Display All
      unfortunately in this board i have no external ram and the file is to big to be save in internal RAM...
      my question is how to use above code along side with:

      Source Code

      1. GUI_BMP_DrawEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0);


      or should i use other functions?

      should i use myRES (or &myRES) instead of pfGetData? or should i write another function that contain these codes?
      what about p?

      thanks.
      Sora.
    • Hi,

      GUI_BMP_DrawEx() expects a pointer to a GetData function as first and the file handle as second parameter. The GetData function reads the file using the file handle, so that emWin can draw the BMP image with the data that was read.

      There is an example in the wiki that demonstrates this. The example can be run in both the Windows simulation and on a target (using emFile).

      You can apply this example to the file system you are using, since the steps are the same. The code you posted should be moved into a GetData function. Then you can call GUI_BMP_DrawEx() and pass a pointer to that function and a pointer to your file handle.

      Best regards,
      Florian
    • SEGGER - Florian wrote:

      Hi,

      GUI_BMP_DrawEx() expects a pointer to a GetData function as first and the file handle as second parameter. The GetData function reads the file using the file handle, so that emWin can draw the BMP image with the data that was read.

      There is an example in the wiki that demonstrates this. The example can be run in both the Windows simulation and on a target (using emFile).

      You can apply this example to the file system you are using, since the steps are the same. The code you posted should be moved into a GetData function. Then you can call GUI_BMP_DrawEx() and pass a pointer to that function and a pointer to your file handle.

      Best regards,
      Florian
      thanks a lot!

      it solved by:


      Source Code

      1. FATFS myFATFS;
      2. FIL myFILE;
      3. UINT myBYTES;
      4. FRESULT myRES;
      5. static U8 _acBuffer[0x2000];
      6. int main{
      7. ...
      8. GUI_Init();
      9. f_mount(&myFATFS, SDPath, 1);
      10. f_open(&myFILE, "yukino.bmp", FA_READ);
      11. size = f_size(&myFILE);
      12. GUI_BMP_DrawEx(APP_GetData, &myFILE, 0, 0);
      13. ...
      14. }
      15. int APP_GetData(void * p, const U8 * * ppData, unsigned NumBytesReq, U32 Off)
      16. {
      17. FIL * phFile;
      18. UINT NumBytesRead;
      19. //f_open(&phFile, (TCHAR const*)p, FA_READ);
      20. phFile = (FIL *) p;
      21. // Check buffer size
      22. if (NumBytesReq > sizeof(_acBuffer)) {
      23. NumBytesReq = sizeof(_acBuffer);
      24. }
      25. // Set file pointer to the offset location
      26. f_lseek(phFile, Off);
      27. // Read data into buffer
      28. f_read(phFile, _acBuffer, NumBytesReq, (UINT *)&NumBytesRead);
      29. // Set data pointer to the beginning of the buffer
      30. *ppData = _acBuffer;
      31. // Return number of available bytes
      32. return NumBytesRead;
      33. }
      Display All
      but the color of drawed pic in lcd is a bit different from the original:
      original ---- drawed (pictured by my phone so can not expressed properly)
      it's like the pic is covered by some filter
      i guess it is related to flexcolor or something... am using ili9486l driver and GUIDRV_FLEXCOLOR_F66709 with GUICC_565
      or maybe related to lcd initial?