Page 1 of 1

Official 7' touchscreen, rotate touch

Posted: Mon Jul 30, 2018 12:24 pm
by Bremenpl
Hello there,
I am using the latest Rasbian image with Rpi 3. I am using the official 7' Rpi touch screen. I can rotate the screen by editing /boot/config.txt (adding display_rotate=x). The problem is, after I rotate the screen, the touch panel doesnt seem to notice that, and it works as it would if the screen was not rotated (mirror when rotated by 180 degrees for example).

How to rotate the touch functionality as well?
I would appreciate all help.

Re: Official 7' touchscreen, rotate touch

Posted: Mon Jul 30, 2018 1:16 pm
by jamesh
If you use display_lcd_rotate instead, is that better?

Re: Official 7' touchscreen, rotate touch

Posted: Tue Jul 31, 2018 5:50 am
by Bremenpl
Same thing.... display_lcd_rotate=2 gives this:

https://youtu.be/ZcdE97d9NI8

Any idea what else could be done?

Re: Official 7' touchscreen, rotate touch

Posted: Wed Aug 01, 2018 3:21 am
by Bremenpl
Anyone please?

Re: Official 7' touchscreen, rotate touch

Posted: Wed Aug 01, 2018 8:30 am
by jamesh
I'll try and have a look at this today. It should 'just work', so will need to check if something has gone awry.

Re: Official 7' touchscreen, rotate touch

Posted: Thu Aug 02, 2018 11:58 am
by aBUGSworstnightmare
Sounds like your coordinate transformation matrix is wrong and needs to be adjusted to match your display rotation.

Code: Select all

[email protected]:~ $ xinput list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ PixArt USB Optical Mouse                	id=8	[slave  pointer  (2)]
⎜   ↳ FT5406 memory based driver              	id=9	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳   USB Keyboard                          	id=6	[slave  keyboard (3)]
    ↳   USB Keyboard                          	id=7	[slave  keyboard (3)]
 
This will list your input devices. FT5406 is your touch controller .
Now see what your coordinate transformation matrix is:

Code: Select all

[email protected]:~ $ xinput list-props 'FT5406 memory based driver' | grep "Coordinate Transformation Matrix"
	Coordinate Transformation Matrix (114):	1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
This shows results for default (off the shelf) settings.
Default matrix is:
⎡ 1 0 0 ⎤
⎜ 0 1 0 ⎥
⎣ 0 0 1 ⎦

If you now want/need to change your touch input (i.e. because your using the display upside down or in portrait mode) you will have to change the coordinate transformation matrix.
Rotate clockwise 90° ((from left) to the right) transformation matrix should be:
⎡ 0 -1 1 ⎤
⎜ 1 0 0 ⎥
⎣ 0 0 1 ⎦

90° counterclockwise:
⎡ 0 1 0 ⎤
⎜ -1 0 1 ⎥
⎣ 0 0 1 ⎦

invert rotate (180° either clock- or counterclockwise):
⎡ -1 0 1 ⎤
⎜ 0 -1 1 ⎥
⎣ 0 0 1 ⎦

For setting the coordinate transformation matrix you can use

Code: Select all

$ xinput set-prop '<device name>' 'Coordinate Transformation Matrix' <matrix in row-order>
You can also make your own udev-rule:
i.e. (note: not tested with the offical 7in DSI screen; only used this method with other screen!)

Code: Select all

sudo nano /etc/udev/rules.d/99-7inDSI.rules
Now add the content with the coordinate transformation matrix of your choice (example rotates 90° clockwise)

Code: Select all

ACTION=="add", ATTRS{name}=="FT5406 memory based driver", ENV{LIBINPUT_CALIBRATION_MATRIX}="-0 -1 1 1 0 0 0 0 1"

Re: Official 7' touchscreen, rotate touch

Posted: Thu Aug 02, 2018 1:03 pm
by jamesh
You could try this change to config.txt

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-swapped-x-y=1
See /boot/overlays/README for other touchscreen parameters

Re: Official 7' touchscreen, rotate touch

Posted: Fri Aug 03, 2018 5:23 am
by Bremenpl
Thanks for answers. First I tried out jamesh solution. Unfortunately it doesnt work. At first I tried out this:

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-swapped-x-y=1
But it didnt help at all, it only flipped x and y with placed making it still work wrong. I went to the README file in /boot/overlays/ directory and checked out this:

Code: Select all

Name:   rpi-ft5406

Info:   Official Raspberry Pi display touchscreen

Load:   dtoverlay=rpi-ft5406,<param>=<val>

Params: touchscreen-size-x      Touchscreen X resolution (default 800)

        touchscreen-size-y      Touchscreen Y resolution (default 600);

        touchscreen-inverted-x  Invert touchscreen X coordinates (default 0);

        touchscreen-inverted-y  Invert touchscreen Y coordinates (default 0);

        touchscreen-swapped-x-y Swap X and Y cordinates (default 0);
So I started with:

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-inverted-x=1
And it worked, the x axis was now rotated by 180 degrees. Then I added second line:

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-inverted-y=1
And after this Y was properly rotated, but X went back to normal. Thus I figured out that those commands are exclusive and you cannot use them together. This is odd for me, it just doesnt work. I will now try the other solution.

Re: Official 7' touchscreen, rotate touch

Posted: Fri Aug 03, 2018 5:37 am
by Bremenpl
aBUGSworstnightmare, Your solution did the trick fully. Thank you.

Re: Official 7' touchscreen, rotate touch

Posted: Fri Aug 03, 2018 6:37 am
by jamesh
Bremenpl wrote:
Fri Aug 03, 2018 5:23 am
Thanks for answers. First I tried out jamesh solution. Unfortunately it doesnt work. At first I tried out this:

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-swapped-x-y=1
But it didnt help at all, it only flipped x and y with placed making it still work wrong. I went to the README file in /boot/overlays/ directory and checked out this:

Code: Select all

Name:   rpi-ft5406

Info:   Official Raspberry Pi display touchscreen

Load:   dtoverlay=rpi-ft5406,<param>=<val>

Params: touchscreen-size-x      Touchscreen X resolution (default 800)

        touchscreen-size-y      Touchscreen Y resolution (default 600);

        touchscreen-inverted-x  Invert touchscreen X coordinates (default 0);

        touchscreen-inverted-y  Invert touchscreen Y coordinates (default 0);

        touchscreen-swapped-x-y Swap X and Y cordinates (default 0);
So I started with:

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-inverted-x=1
And it worked, the x axis was now rotated by 180 degrees. Then I added second line:

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-inverted-y=1
And after this Y was properly rotated, but X went back to normal. Thus I figured out that those commands are exclusive and you cannot use them together. This is odd for me, it just doesnt work. I will now try the other solution.
Odd, they should not be exclusive according to the code, and my tests when I wrote it! Not sure what is going on there.

Re: Official 7' touchscreen, rotate touch

Posted: Fri Aug 03, 2018 6:45 am
by Bremenpl
Please let me know if you will need me to test anything regarding this.

Re: Official 7' touchscreen, rotate touch

Posted: Fri Aug 03, 2018 6:47 am
by jamesh
Bremenpl wrote:
Fri Aug 03, 2018 6:45 am
Please let me know if you will need me to test anything regarding this.
I'll check the code when I get into office, and let you know.

Re: Official 7' touchscreen, rotate touch

Posted: Mon Aug 06, 2018 5:52 pm
by Bremenpl
Anything new?

Re: Official 7' touchscreen, rotate touch

Posted: Mon Aug 06, 2018 7:12 pm
by jamesh
Sorry, not had a chance t ocheck this stuff out. I'm working on the panel, but with lots of custom changes, and its a PITA to swap stuff around. Will try and check in next couple of days.

Re: Official 7' touchscreen, rotate touch

Posted: Wed Aug 15, 2018 4:54 am
by Bremenpl
Hello there,
I am posting to let know that the solution provided by @aBUGSworstnightmare earlier doesnt seem to solve my problem fully. Even though When in the "desktop" the pointer works correctly, it stops when used with a Qt application with eglfs platform. Here is a video: https://www.youtube.com/watch?v=zFPPxua4l_M
It shows that comparing to the same application working on an x86 machine, the touch direction is flipped by 180 degrees. I wonder either your solution @jamesh would help?

Re: Official 7' touchscreen, rotate touch

Posted: Wed Aug 15, 2018 6:08 am
by aBUGSworstnightmare
Well...you did not mention 'Qt application with eglfs platform' in your initial post...

My uneducated guess is problem is related to EGLFS (as touch works with normal Qt application here).
BTW: what should happen when you use the touch?

Re: Official 7' touchscreen, rotate touch

Posted: Wed Aug 15, 2018 6:24 am
by Bremenpl
Thank for answer,
Could you elaborate more? Do you mean in general or just in this example application from youtube video?

Re: Official 7' touchscreen, rotate touch

Posted: Thu Aug 16, 2018 1:09 pm
by aBUGSworstnightmare
I'm running a Standard Qt app where touch is working as expected (official 7in DSI Screen, as well as Manga Screen 2 touch).
Qt is installed by using command below

Code: Select all

sudo apt install qtcreator qttools5-dev qtbase5-dev qt5-default qtdeclarative5-dev libqt5svg5-dev libqtwebkit-dev libqt5webkit5-dev libsdl1.2-dev build-essential libudev-dev qtmultimedia5-dev

Re: Official 7' touchscreen, rotate touch

Posted: Thu Aug 16, 2018 2:58 pm
by Bremenpl
Could you try a qml based app with -platform eglfs arguments?

Re: Official 7' touchscreen, rotate touch

Posted: Thu Aug 16, 2018 4:51 pm
by aBUGSworstnightmare
Bremenpl wrote: Could you try a qml based app with -platform eglfs arguments?
sorry, no!

Re: Official 7' touchscreen, rotate touch

Posted: Mon Aug 27, 2018 1:28 am
by XDSFyP
Thanks to everyone in this thread, I got the touches to map correctly to the image rotation. Adding my solution for future reference.

I am using raspbian lite Linux raspberrypi 4.14.62-v7+ #1134 SMP Tue Aug 14 17:10:10 BST 2018 armv7l without (Pixel?) desktop environment.
RPI3B+

I rotated the official 7 inch touchscreen 90 degrees appending the following to my /boot/config.txt

Code: Select all

display_lcd_rotate=1 # rotates image
dtoverlay=rpi-ft5406,touchscreen-swapped-x-y=1,touchscreen-inverted-x=1 # rotates touches

I am using the pi to run a Qt C++ program from bash with sudo startx ./qtApp after I have installed apt-get install xserver-xorg x11-xserver-utils xinit

Re: Official 7' touchscreen, rotate touch

Posted: Mon Jan 28, 2019 11:15 pm
by eatmyvolts
Bremenpl wrote:
Fri Aug 03, 2018 5:23 am

So I started with:

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-inverted-x=1
And it worked, the x axis was now rotated by 180 degrees. Then I added second line:

Code: Select all

dtoverlay=rpi-ft5406,touchscreen-inverted-y=1
And after this Y was properly rotated, but X went back to normal. Thus I figured out that those commands are exclusive and you cannot use them together. This is odd for me, it just doesnt work. I will now try the other solution.
Thank you for putting me on the right track for what I needed to do. Which was rotate the screen 180 degrees while using both touchscreen and mouse.
By chance I tried this and the commands are not mutually exclusive, they just have to be combined on one line

Code: Select all

display_lcd_rotate=2
dtoverlay=rpi-ft5406,touchscreen-inverted-x=1,touchscreen-inverted-y=1
Works for me, thanks again.

Re: Official 7' touchscreen, rotate touch

Posted: Tue Feb 26, 2019 12:27 am
by moderatelyfunky
Thanks, eatmyvolts. Your version worked!

Re: Official 7' touchscreen, rotate touch

Posted: Fri Aug 02, 2019 4:31 pm
by jlinkels
I am using Raspi 3, Raspbian Stretch and the official 7"touch screen.

This worked for me in /boot/config.txt:

Code: Select all

display_rotate=1
dtoverlay=rpi-ft5406,touchscreen-swapped-x-y=1,touchscreen-inverted-x=1,touchscreen-inverted-y=1
I am using a Tcl/Tk graphical application. It works as expected in both the desktop and the application. Thanks to y'all for posting their solutions and reports.

jlinkels

Re: Official 7' touchscreen, rotate touch

Posted: Tue Sep 03, 2019 7:42 pm
by zapping
After much research and change the 3 parameters for the position

Code: Select all

display_rotate=3
I have found that it only works fine if I set:

Code: Select all

dtoverlay=rpi-ft5406, touchscreen-swapped-x-y=1, touchscreen-inverted-y=1
But don't work if I set:

Code: Select all

dtoverlay=rpi-ft5406, touchscreen-swapped-x-y=1, touchscreen-inverted-x=0, touchscreen-inverted-y=1
In case it serves to someone.