Image streaming from USB

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

  • Image streaming from USB

    Hi! I need to use some images as background in my application.
    The problem is that including the images as .c converted files, built with the project, makes the firmware size too big for my needs.
    As my application needs an USB drive plugged in for other reason, I'm thinking about loading the images directly from it, since I have a lot of free space on the drive.
    My question is: which one is the best way to do that? I mean, should I put the images on the drive as .bmp or as .c? Which function is the best for this application, GUI_DrawStreamedBitmapEx() or GUI_BMP_DrawEx()? Which theier advantages\disadvantages?
    I also have a second request: can I somewhere fin a _GetData function that points a file on an Usb drive?
    Thank you!
  • Hello,

    You can use emWin to display every supported format (dta, bmp, gif, jpeg, png) from external media, but c files. Please note that c files are intended to be compiled with your application. For an example, please refer to the emWin user manual.

    Best regards,
    Adrian
  • That's the point, I don't want to use compiled c files for preventing my code to become too big.
    All I have to do is open a .bmp file, pass the pointer to the _GetData function and then use GUI_BMP_DrawEx(), right?
    Actually my question was more about the differences between this way and using stream file.
  • I'm developing my app but I can't get the bitmap displayed.
    This is how I'm working

    The app waits for the usb to be recognized and load the bitmap

    if((USB_Host_Application_Ready==1) && (FileRead==0))
    {
    f_mount(0, &fatfs);
    if(f_open(&file, "0:Back.bmp", FA_READ | FA_OPEN_EXISTING) == FR_OK)
    {
    bytesToRead=f_size(&file);
    // Read buffer to file
    res= f_read (&file, &bmp, sizeof(bmp), (void *)&bytesRead);
    //close file and filesystem
    // f_close(&file);
    // f_mount(0, NULL);
    FileRead=1;
    }
    }

    Once the flag is set, in the main I create the framewin
    CreateBackground();

    Then into the BackgroundDLG.c I call GUI_BMP_DrawEx(APP_GetData, &file, 0, 0); in the switch (pMsg->MsgId) { case WM_INIT_DIALOG:
    APP_GetData is
    int APP_GetData(void * p, const U8 ** ppData, unsigned NumBytesReq, U32 Off)
    {
    unsigned int NumBytesRead;
    FIL * phFile;

    phFile = (FIL *)p;

    /* Check buffer size */
    if (NumBytesReq > sizeof(_acBuffer)) {
    NumBytesReq = sizeof(_acBuffer);
    }

    /* Set file pointer to the required position */
    f_lseek(phFile, Off);

    /* Read data into buffer */
    f_read(phFile, _acBuffer, NumBytesReq, &NumBytesRead);

    /* Set data pointer to the beginning of the buffer */
    *ppData =(unsigned char *) _acBuffer;

    /* Return number of available bytes */
    return NumBytesRead;
    }


    The bmp doesn't show up. Is there something wrong in the way I;m building my project? Thanks!
  • Update

    trying with a different GetData function, GUI_BMP_DrawEx shows a lot of colorful lines and then goes to HardFault

    static int _GetData(void * p, const U8 ** ppData, unsigned NumBytesReq, U32 Off)
    {
    unsigned int NumBytesRead;
    FIL * phFile;

    phFile = (FIL *)p;

    /* Set file pointer to the required position */
    f_lseek(phFile, Off);

    /* Read data into buffer */
    f_read(phFile, (U8 *)*ppData, NumBytesReq, &NumBytesRead);

    /* Return number of available bytes */
    return NumBytesRead;
    }