rotating framebuf

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
v923z
Posts: 23
Joined: Mon Dec 28, 2015 6:19 pm

rotating framebuf

Postby v923z » Mon Jan 09, 2017 9:32 pm

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

User avatar
pythoncoder
Posts: 1565
Joined: Fri Jul 18, 2014 8:01 am

Re: rotating framebuf

Postby pythoncoder » Tue Jan 10, 2017 7:10 am

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/micropython-samples/commit/c56753fde0477863cc01352574a8b31edd68534b 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.
Peter Hinch

User avatar
deshipu
Posts: 1037
Joined: Thu May 28, 2015 5:54 pm

Re: rotating framebuf

Postby deshipu » Tue Jan 10, 2017 10:14 am

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.

User avatar
Roberthh
Posts: 644
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: rotating framebuf

Postby Roberthh » Tue Jan 10, 2017 11:01 am

But one still must re-arrange the content of the display for the changed aspect ration, unless it's 1:1

v923z
Posts: 23
Joined: Mon Dec 28, 2015 6:19 pm

Re: rotating framebuf

Postby v923z » Tue Jan 10, 2017 12:42 pm

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.

v923z
Posts: 23
Joined: Mon Dec 28, 2015 6:19 pm

Re: rotating framebuf

Postby v923z » Tue Jan 10, 2017 12:47 pm

pythoncoder wrote:Code like my writer module https://github.com/peterhinch/micropython-samples/commit/c56753fde0477863cc01352574a8b31edd68534b 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.

v923z
Posts: 23
Joined: Mon Dec 28, 2015 6:19 pm

Re: rotating framebuf

Postby v923z » Tue Jan 10, 2017 12:49 pm

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.

User avatar
deshipu
Posts: 1037
Joined: Thu May 28, 2015 5:54 pm

Re: rotating framebuf

Postby deshipu » Tue Jan 10, 2017 1:37 pm

You would have to re-send the whole screen to the display anyways if you did it in software.

User avatar
Roberthh
Posts: 644
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: rotating framebuf

Postby Roberthh » Tue Jan 10, 2017 2:00 pm

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.


Return to “General Discussion and Questions”

Who is online

Users browsing this forum: No registered users and 1 guest