GUI_BMP_DrawEx() from SPI flash

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

    • GUI_BMP_DrawEx() from SPI flash

      Hi to all,


      I need to draw several images saved on SPI flash.

      With GUIBuilder I converted the images into arrays and saved they in flash.
      Every image has an start address like
      unsigned long ADDR_IMMAGE1 = 0x00000000;
      unsigned long ADDR_IMMAGE2 = 0x00002000;

      I understood that the function to use is GUI_BMP_DrawEx() but I have some questions:

      1) How to chose which image to show ?
      2) How do I indicate th size of the image ( in flash I only have an array) ?
      3) How do I define the function GUI_DTA_FUNC () ?

      I saw several post on this forum like :
      Loading images from external SPI flash (not addressable)
      C stream
      GUI_DrawStreamedBitmapEX()

      but no solution is given.

      For the third question I wrote the function like this:

      C Source Code

      1. int GUI_ReadFromFlash(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off){
      2. unsigned long start_ADDR;
      3. if (NumBytes > SIZE_FLASHBUFFER) {
      4. NumBytes = SIZE_FLASHBUFFER;
      5. }
      6. start_ADDR = *(unsigned long * )p;
      7. M25P80_Read_Data_Bytes((start_ADDR + Off), FlashBuffer, NumBytes);
      8. *ppData = FlashBuffer;
      9. return NumBytes;
      10. }
      Display All


      where I assumed that "void *p" is usable at will.

      And calling GUI_BMP_DrawEx() like:
      GUI_BMP_DrawEx(GUI_ReadFromFlash, (void *)&ADDR_IMMAGE1, 0, 0);

      It the correct way ?

      Can you give me some tips ?

      Thanks to all.
    • Hi,

      ter2 wrote:

      How to chose which image to show ?

      Your program has to call GUI_DrawBMPEx() with the desired memory address as the parameter.

      ter2 wrote:

      How do I indicate th size of the image ( in flash I only have an array) ?

      It is sufficient to simply pass the address to where the BMP image is located. The routine will stop reading when the file has ended.

      ter2 wrote:

      How do I define the function GUI_DTA_FUNC () ?

      The GetData() functions are user-defined, so that they fit to the needs of the user. Typically the GetData() functions are used with a file system to read the file into a buffer, which the BMP drawing routine then uses. But given that your image is located in addressable memory, you don't have to read the file but you can simply pass the address to *ppData:

      C Source Code

      1. /*********************************************************************
      2. *
      3. * APP_GetData
      4. */
      5. int APP_GetData(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off) {
      6. const U8 * pData;
      7. pData = (const U8 *)p; // p is the start of the buffer
      8. pData += Off; // Off is the byte offset where we currently are reading
      9. *ppData = pData; // *ppData expects a pointer to the data
      10. return NumBytes;
      11. }
      Display All
      Have a look at the example I have attached. Also, you can find infos about the requirements for GetData functions in our manual.

      Best regards,

      Florian
      Files
      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 Florian,

      thanks for your response.


      SEGGER - Florian wrote:

      It is sufficient to simply pass the address to where the BMP image is located. The routine will stop reading when the file has ended.

      I understand in the case of a file (like a reading from FAT32) but in my case, I have to foresee something in the App_get_data routine that returns 0 when the end of the image is reached?

      In the example you posted I don't see any reference to the _acsegger_logo length check.

      I must implement somethings like:

      Source Code

      1. if((pData + NumBytes) > sizeof (_acsegger_logo))
      2. return 0;

      The post was edited 1 time, last by ter2: clarifing ().

    • Hi,

      ter2 wrote:

      I have to foresee something in the App_get_data routine that returns 0 when the end of the image is reached?

      In the example you posted I don't see any reference to the _acsegger_logo length check.
      This check is not necessary, as the GUI_BMP_DrawEx() already checks when the end of file has been reached.

      In the example that uses a file system, the only check that is performed is that the size of the buffer is not exceeded. But as said before, you don't need to read the file into a buffer since it is already in accessible memory.

      Best regards,
      Florian
      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 Florian,

      I have found the solution to my doubt.

      When GUIBUilder creates the image array, it contains information about the image at the top. So functions like GUI_BMP_DrawEx() take the information about the size of the image right from this header.


      Thank you!