Page 1 of 1

rotating framebuf

Posted: Mon Jan 09, 2017 9:32 pm
by v923z
Hi all,

I was wondering, whether it is possible to rotate the framebuffer. Given that the micropython board has an accelerometer, I think it is only natural to ask, whether the content of a display can automatically be adjusted, if I turn the microcontroller upside down.
Transforming the drawing primitives like vline and hline, and fill_rect is trivial, but is it possible to display text upright, if the hardware is actually upside down?


Cheers,
Zoltán

Re: rotating framebuf

Posted: Tue Jan 10, 2017 7:10 am
by pythoncoder
In my view this is a problem for the application rather than the firmware. Consider the case where the hardware is rotated through 90 degrees. Your display is now in portrait mode. Some devices can handle this natively but some cannot. In any event the text flow will be altered by the change in aspect ratio.

Code like my writer module https://github.com/peterhinch/micropyth ... 1edd68534b could easily be adapted for upside down and 90 degree text, but the application would still need to detect the orientation, cope with the changing aspect ratio and redraw the text.

Re: rotating framebuf

Posted: Tue Jan 10, 2017 10:14 am
by deshipu
I think it's much better to rotate the display in hardware -- most LCD driver chips have a number of register for controlling the orientation and scrolling of the image. Check the datasheet for your display. This has the advantage of being practically free in terms of CPU cycles.

Re: rotating framebuf

Posted: Tue Jan 10, 2017 11:01 am
by Roberthh
But one still must re-arrange the content of the display for the changed aspect ration, unless it's 1:1

Re: rotating framebuf

Posted: Tue Jan 10, 2017 12:42 pm
by v923z
I understand that the aspect ratio might be a problem, and this is why I mentioned a display upside down. In that case, the text, lines etc. could be re-drawn without having to re-calculate anything.

Re: rotating framebuf

Posted: Tue Jan 10, 2017 12:47 pm
by v923z
pythoncoder wrote:Code like my writer module https://github.com/peterhinch/micropyth ... 1edd68534b could easily be adapted for upside down and 90 degree text,
This is exactly what I am doing now, but this implies that one has to have 4 sets for each font, or the font has to be re-computed on the fly. Also, this approach doesn't really make use of the framebuffer. You have to draw the fonts anyway, but if you want to use the built-in 8-pt font, you can't rotate that at the moment.
pythoncoder wrote: but the application would still need to detect the orientation
The micropython board already does that. I read out the accelerometer regularly, and when the orientation changes, I re-draw the display.

Re: rotating framebuf

Posted: Tue Jan 10, 2017 12:49 pm
by v923z
deshipu wrote:I think it's much better to rotate the display in hardware -- most LCD driver chips have a number of register for controlling the orientation and scrolling of the image. Check the datasheet for your display. This has the advantage of being practically free in terms of CPU cycles.
Good point, thanks for the suggestion! Though, I believe, this will affect only subsequent data, but will not re-draw the display on its own. I will have to check.

Re: rotating framebuf

Posted: Tue Jan 10, 2017 1:37 pm
by deshipu
You would have to re-send the whole screen to the display anyways if you did it in software.

Re: rotating framebuf

Posted: Tue Jan 10, 2017 2:00 pm
by Roberthh
That depends. In some devices you control how the internal frame buffer content is sent to the display matrix. For these, any changes to the orientation gets immediately effective. Examples: SSD1963, ILI9341.