How to change display orientation from portrait to horizontal, how to rotate display i.MXRT

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

    • How to change display orientation from portrait to horizontal, how to rotate display i.MXRT

      Hello All,

      I work on example emWin project for i.MXRT family (NXP provides it as an example from their SDK). Example project uses few emWin funtions like

      C Source Code

      1. GUI_DispStringHCenterAt
      2. GUI_DrawPixel
      3. GUI_DrawRect
      4. GUI_FillRec
      By default, all GUI is displayed in portrait mode. Display is configured as width 720 and height 1280. I would like to switch it to horizontal view.
      From emWin docs (34.7.6.2 Color depth and display orientation (page 2469.)) I found out to play with available drivers. OK, I gave it a try and seems not everything is fully functional:
      • GUIDRV_LIN_16 (16bpp, default orientation): works fine
      • GUIDRV_LIN_OX_16 (16bpp, X axis mirrored): works fine
      • GUIDRV_LIN_OXY_16 (16bpp, X and Y axis mirrored): works fine
      • GUIDRV_LIN_OS_16 (16bpp, X and Y swapped): does not work
        • artifacts are displayed on whole screen so additional change has been made, plase see below:
        • changing macro as follows makes the situation bit better (no artfacts) however half of display is simply black

      C Source Code

      1. from
      2. #define DEMO_BUFFER_STRIDE_BYTE (DEMO_BUFFER_WIDTH * DEMO_BUFFER_BYTE_PER_PIXEL)
      3. to
      4. #define DEMO_BUFFER_STRIDE_BYTE (DEMO_BUFFER_HEIGHT * DEMO_BUFFER_BYTE_PER_PIXEL)
      • GUIDRV_LIN_OSX_16 (16bpp, X axis mirrored, X and Y swapped): does not work, half of the display is simply black
      • GUIDRV_LIN_OSY_16 (16bpp, Y axis mirrored, X and Y swapped): does not work, half of the display is simply black


      Seems there is some issue with X and Y swapping. Any hints what changes are required to make it working fine? Thanks in advance!
    • Hi,

      it seems the function LCD_X_Config() in the file emwin_support.c is not aware of the driver orientation.

      Try to exchange the LCD_X_Config() by the one below:

      C Source Code

      1. void LCD_X_Config(void)
      2. {
      3. GUI_MULTIBUF_Config(GUI_BUFFERS);
      4. GUI_DEVICE_CreateAndLink(DISPLAY_DRIVER, COLOR_CONVERSION, 0, 0);
      5. if (LCD_GetSwapXY()) {
      6. LCD_SetSizeEx (0, LCD_HEIGHT, LCD_WIDTH);
      7. LCD_SetVSizeEx(0, LCD_HEIGHT, LCD_WIDTH);
      8. } else {
      9. LCD_SetSizeEx (0, LCD_WIDTH, LCD_HEIGHT);
      10. LCD_SetVSizeEx(0, LCD_WIDTH, LCD_HEIGHT);
      11. }
      12. LCD_SetVRAMAddrEx(0, (void *)VRAM_ADDR);
      13. BOARD_Touch_Init();
      14. }
      Display All
      Best regards,
      Sven
    • Hi Sven,

      Thank you very much for your support,
      I am confirming just the suggested solution works really nice, and this is exactly what I was looking for, really appreciated!

      Let's summarize, when you want to change display orientation from portrait to horizontal (or in other words, rotate display 90 deg clockwise, or counterclockwise), you need to:
      • update LCD_X_Config() as per Sven's suggestion
      • choose right emWin display driver, for example for rotation 90 deg clockwise #define DISPLAY_DRIVER GUIDRV_LIN_OSX_16 (for other possible GUIDRV_Lin options please refer to page 2469. of emWin doc)


      And that's all! Happy rotating ;)
    • Hi,

      Yes, your summary is correct.

      Please note that you might want to also adapt the function which passes touch input to emWin. I think BOARD_TouchPoll() it is called in the NXP examples.

      You can also set up multiple driver instances and link/unlink them on runtime. This allows you to rotate on runtime just with another driver.

      Regards,
      Sven