GUI_MEMDEV_CopyToLCD in a Window call back

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

  • GUI_MEMDEV_CopyToLCD in a Window call back

    In order to speed up refresh on a window that includes many PNG I'm using MEMDEV functions.

    After creating a new windows, during first show I create a MEMDEV object :
    hMemKeyWindow[MenuIndx] = GUI_MEMDEV_Create(KEY_WINDOW_X0, Y0, KEY_WINDOW_XSIZE, YSize);

    (hMemKeyWindow is a buffer of many GUI_MEMDEV_Handle:
    GUI_MEMDEV_Handle hMemKeyWindow[10];)

    inside call back of windows
    on WM_PAINT event I add:

    - select MEMDEV

    - print on MEMEDEV

    at the END I copy on LCD what I have in RAM


    after GUI_MEMDEV_CopyToLCD, if I set a breakpoint soon after my dispaly shows what I expected!

    But if I continue run my code, step by step, code jumps inside a disassembly code of GUI libraries and I can see that it calls again a GUI_MEMDEV_CopyToLCD and wrtie all screen with black color!

    I can't understand who call this function and from which buffer memory it reads data to be printed on display..
  • Hello Stefano,

    No, the Window Manager can make automatic use of Memory Devices to display windows. This can be enabled by the create flag WM_CF_MEMDEV or by calling the function WM_EnableMemdev().

    Please note that the function GUI_MEMDEV_Select() returns the previously used device. It is strongly recommended to reselect the returned device instead of selecting the LCD.

    Best regards,
  • Sorry for previous post so confused:
    I rewrote it better..

    Hello Adrian,

    thank you again
    for your precious information.

    I called WM_EnableMemdev at the beginning of my application just once:


    referred to main Window but my issue is when I use many other
    "Child" window, is it necessary to enable WM_EnableMemdev far ALL windows where it is used? Can I enable in the same
    time many WM_EnableMemdev for different windows without erase the previous
    ones to have in memory different setting and load them very fastly? I think is
    just a RAM issue and I locat my GUI buffer (GUI_ALLOC_AssignMemory) to an external one near to 8MB..

    I summarize here my code, with minimum information necessary to understand
    my problem:

    Function called once to init new window with many PNGs
    void InitKeyWindow(void)
    *aMenu[MenuIndx].pWindow = WM_CreateWindowAsChild(KEY_WINDOW_X0, Y0,
    KEY_WINDOW_XSIZE, YSize, MainWindow, WM_CF_SHOW | WM_CF_MEMDEV, _cbKeyWindow, 0);
    WM_EnableMemdev(*aMenu[MenuIndx].pWindow); Enable Memdev for any window?

    hMemKeyWindow[MenuIndx] = GUI_MEMDEV_Create(KEY_WINDOW_X0, Y0,
    KEY_WINDOW_XSIZE, YSize); Created memdev object for any window and keep it in memory to a fast recall when necessary.

    GUI_Exec(); Is it necessary?

    Callback for this window
    static void _cbKeyWindow(WM_MESSAGE * pMsg)
    switch (pMsg->MsgId)
    case WM_PAINT:
    if(hMemKeyWindowFlag[MenuIndx] == TRUE) Check on a flag to understand if the memdev has already been created
    for this
    WM_SelectWindow(PrevDevice); PrevDevice is static object use to keep in memory last device as in your suggestion
    /* Draw memdev to pWindow*/
    break; When memdev is already present I save many msec recall pixel saved on memory

    If memdev of this new window has never been created before
    PrevDevice = GUI_MEMDEV_Select(hMemKeyWindow[MenuIndx]); /* Select memdev */
    Print on memory not on display
    Copy what I design on memory to display using previous Device "PrevDevice" as global object
    /* Draw memdev to pWindow*/
    hMemKeyWindowFlag[MenuIndx] = TRUE; Setting this flag next PAINT event I should copy directly from memory and
    use ShowPNG


    From when I introduced use of PrevDevice, system crashes
    after GUI_MEMDEV_CopyToLCD during second cycle on PAINT..

    Best regards,
  • Hello Stefano,

    Please note that you can also just edit your existing posts in order to reformat it. Since you wrote another post containing the same information I deleted the first one in order to avoid redundancy.

    The function WM_SetCreateFlags() can be used to set creation flags to be used all subsequently created windows.

    Please also note my previous post.

    Best regards,
  • Hello Adrian, thank you for cleaning post.
    I followed with high attention all your previous suggestions:
    - GUI_MEMDEV_Select() returns the previously used device.. so I used it.
    - WM_SetCreateFlags() called for any windows I created
    So I rewrote callback function many times reducing cpu effort so is incredibly fast but code proceeds as described in the previous post deleting what was perfect after PAINT event.
    My study is on all events
    #define WM_PRE_PAINT 46 /* Send to a window before it receives a WM_PAINT message */
    #define WM_POST_PAINT 47 /* Send to a window after (the last) WM_PAINT message */
    because the are generated before and after PAINT as expected so I can add some function to solve the issue.. maybe..

    I'm trying to understand if there is a way to say to library: "That's all! it's ok exaclty as it is!"
    after my GUI_MEMDEV_CopyToLCD(hMemKeyWindow[MenuIndx]); inside PAINT.

    I understand that your work is just to give a suggestion and some idea to force studying of complete manual.
    I read it many times, but I didn't find solution yet so if Segger provides other kind of support more detailed I appreciate it;
    Can I for example create a simple project and share it with you..

  • Hello Stefano,

    You are doing to much in your callback function. You already enabled automatic use of Memory Devices, still you create your own Memory Device. You application will work well if you just replace the call to GUI_MEMDEV_CopyToLCD() with GUI_MEMDEV_Select() (in order to select the previously selected device) and GUI_MEMDEV_Write(). Still I would recommend you to not create your own Memory Device within a paint event as long as it is just used as a drawing container.

    Best regards,
  • MEMDEV_Test.txtHi Adrian,
    I hope this is last request for this argument.

    I wrote a complete file code with a very easy example that replicates exactly what happens in my product that has more objects\winbdows but same concepts.
    I kindly ask you to see this code created following all your previous suggestions(I use same logic of Segger Tutorial files so it should run on your simulator with a copy and paste and rename it as .c).

    Main considerations:

    1- Call WM_SetCreateFlags(WM_CF_MEMDEV); at startup to apply to main window and all derivates the use of MEMDEV on windows
    2- I have a while loop that creates and destroy same 2 windows. I need this operation because in my application size could change everytime.
    3- WM_EnableMemdev(pWindow[indexWindow]); I enable Memdev for each new window has been create, is it redundancy respect WM_SetCreateFlags(WM_CF_MEMDEV)?
    4- On PAINT event ONLY the first time each memdev has been created I print inside memory device with GUI_MEMDEV_Select(hMemKeyWindow[indexWindow]);
    5- After flag hMemKeyWindowFlag[indexWindow] = 1; has been set, the PAINT event works only with GUI_MEMDEV_Select(0);
    and GUI_MEMDEV_Write(PrevDevice); so should read from memory and copy it to display, no more (it not seems too much)

    About your suggestion to use return pointer of GUI_MEMDEV_Select to obtain old device:
    if I use GUI_MEMDEV_Write(hMemKeyWindow[indexWindow]);(is commented in my example) it shows something but it diseappers after few milliseconds.
    If I use GUI_MEMDEV_Write(PrevDevice); nothing appears on display, only noise pixels.

    Thanks again for your time.
    If we works on this example I created I'm sure we found what I'm doing wrong.


    The post was edited 1 time, last by Stefano Toselli ().