2023-06-12 08:02 AM
Hi,
In the device we are designing, we would like to change the orientation of the screen depending on the actual orientation of the device as detected by the accelerometer. I have read the TouchGFX documentation and many posts on this forum and proceeded with the implementation. Unfortunately I encountered a problem that I hope to find a solution for here.
The default orientation of the device is landscape and so when designing the GUI I started from this position. Once completed, I switched the screen orientation in TouchGFX Designer to portrait and laid out the objects again. Based on the generated code, I implemented two functions responsible for positioning objects on the screen - setupLandscapeScreen() and setupPortraitScreen(). I also duplicated all the graphics used on this screen and changed their 'Layout rotation' property to the opposite. I use two framebuffers in the project.
When a change in orientation is detected, an event is generated which I handle in my screen presenter. There I check the current orientation of the device, then using the setDisplayOrientation() function I set the appropriate screen orientation for the TouchGFX, and if necessary invert the display using the MADCTL register in the ILI9341 driver. Finally, I perform a transition to the same screen so that, according to the note in the comment to the setDisplayOrientation() function, the orientation change can take place. Once the transition is done in the View() screen constructor, I check the current screen orientation using getDisplayOrientation() and position the objects using the setupLandscapeScreen() and setupPortraitScreen() functions mentioned earlier.
The resulting screen orientation change works correctly in all directions - 0, 90, 180 and 270 degrees. Unfortunately, there is an unauthorised effect when changing the orientation. Well, before the screen orientation is actually changed in TouchGFX, the orientation is changed by modifying the MADCTL register. As a result, when rotating the device 90 degrees clockwise from landscape to portrait, first my screen displays upside down for a fraction of a second still in landscape orientation and only then does it change to the target portrait orientation.
If I understand correctly, the solution to my problem would be to modify the MADCTL register in ILI9341 between the change from landscape framebuffer to portrait framebuffer. Is this possible to do? Perhaps there is another solution to this problem. Please help.
With best regards,
Piotr
2023-06-13 03:36 AM
Hello ypiotrp,
Maybe could be doable with the setDisplayOrientation() function of the HAL layer. This should work if it's only rotating 90° degrees
void Screen1View::ChangeOrientation()
{
if(HAL::getInstance()->getDisplayOrientation() == ORIENTATION_LANDSCAPE)
{
HAL::getInstance()->setDisplayOrientation(ORIENTATION_PORTRAIT);
}
else
{
HAL::getInstance()->setDisplayOrientation(ORIENTATION_LANDSCAPE);
}
Screen1View::invalidate();
}
I recommend you to use a "fake" interaction of screen transition to apply the changes, something like going back to the same screen you're in (a screen transition must occur before this takes effect)
/Osman