thios
Posts: 4
Joined: Sat Oct 13, 2018 12:26 pm

Dynamic Rotation

Sat Oct 13, 2018 12:39 pm

Hi. I'm trying to get a tablet-style dynamic screen rotation to work.

I'm using:
-pi3b
-the official 7'' touchscreen in 800x480 resolution
-latest raspbian stretch lite, with mate desktop
-the experimental fake kms/v3d driver. Full kms results in black screen; legacy driver doesn't allow dynamic rotation.
-the latest revision of the kernel module. I checked out the source through rpi-source and diff-ed with latest rpi-ft5406.c in github

I can rotate the display without problems:

Code: Select all

xrandr -o normal
xrandr -o left
xrandr -o right
xrandr -o inverted
For inverted orientation, touchscreen rotation's also working great with:

Code: Select all

xinput --set-prop 'FT5406 memory based driver' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
For portrait orientation, eg left, I tried:

Code: Select all

xinput --set-prop 'FT5406 memory based driver' 'Coordinate Transformation Matrix'
That got the directions right, but I noticed a variable offset, which made me think I should scale the 800x480 resolution to 480x800. So I applied a scale transform to the rotation transform I passed to xinput:

[scale transform] * [rotation transform]:

Code: Select all

⎡ 0.6        0 0 ⎤   ⎡ 0 -1 1 ⎤   ⎡ 0        -0.6 0.6 ⎤
⎜ 0   1.666666 0 ⎥ * ⎜ 1  0 0 ⎥ = ⎜ 1.666666  0   0   ⎥
⎣ 0          0 1 ⎦   ⎣ 0  0 1 ⎦   ⎣ 0         0   1   ⎦
Therefore:

Code: Select all

xinput --set-prop 'FT5406 memory based driver' 'Coordinate Transformation Matrix' 0 -0.6 0.6 1.666666 0 0 0 0 1
Now that gets direction and position right, with the caveat that I can't get a y value in portrait orientation higher than 480. If I try to tap any lower on the screen, the cursor's y gets stuck to the 480 value, while the x changes correctly.

I'm thinking it's an issue of the driver reporting a 800x480 resolution and capping the y value of taps at 480.

Thoughts?

:)

thios
Posts: 4
Joined: Sat Oct 13, 2018 12:26 pm

Re: Dynamic Rotation

Thu Oct 18, 2018 5:03 pm

OK, it turns out I had to switch from evdev to libinput and then simply use the rotation matrix values from here.

For example, for left rotation:

Code: Select all

xinput --set-prop 'FT5406 memory based driver' 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1
It's now working as expected!

kiltjim
Posts: 11
Joined: Mon Jan 28, 2013 1:53 am

Re: Dynamic Rotation

Fri Oct 19, 2018 6:07 pm

How coincidental that I am looking for something very similar!

I'm primarily only concerned about rotating my command line (no X windows manager running) to portrait. First, would the above even work, or is this only directed toward something running under an windows manager?

If it would pertain to anything running on the Pi, do you need the latest revision of the kernel, and would you need the 'experimental fake kms/v3d driver' to make it work?

thios
Posts: 4
Joined: Sat Oct 13, 2018 12:26 pm

Re: Dynamic Rotation

Sun Oct 21, 2018 1:40 pm

Sorry, xrandr and xinput need a running xserver, so I don't think the above can help you.

Maybe try this suggestion?

kiltjim
Posts: 11
Joined: Mon Jan 28, 2013 1:53 am

Re: Dynamic Rotation

Sun Oct 21, 2018 4:05 pm

Thanks for the response. I tried:

Code: Select all

echo 1 | sudo tee /sys/class/graphics/fbcon/rotate
Maybe I'm not doing it right, or maybe there's something different about my kernel, Linux version etc. (I'm running Berryboot with retropie for now), but doing the above, didn't do anything. In fact, checking the rotate file with:

Code: Select all

cat /sys/class/graphics/fbcon/rotate
echoed out "0", which meant it didn't do anything at all. I could of course write to config.txt, but this requires a restart, and my goal was to run anything under an x server in landscape, and anything in the terminal (after shutting down X) in portrait.

Back to the search I guess. Thanks!

thios
Posts: 4
Joined: Sat Oct 13, 2018 12:26 pm

Re: Dynamic Rotation

Mon Oct 22, 2018 10:55 pm

You probably need to enable framebuffer rotation in the kernel.

First get your current kernel's source with rpi-source:

Code: Select all

sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update
rpi-source --skip-gcc
cd linux
make oldconfig
sudo apt-get install libncurses-dev
make menuconfig
Then enable framebuffer rotation:

Code: Select all

Device Drivers  --->
    Graphics support  --->
        Console display driver support  --->
            [*] Framebuffer Console Rotation
Then build the kernel. From the raspberry docs:

Code: Select all

make -j4 zImage modules dtbs
sudo make modules_install
sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
sudo cp arch/arm/boot/zImage /boot/$KERNEL.img
Edit: Reboot here.

Finally, cross your fingers and try again!

Return to “Official Display”