树莓派屏幕旋转和触摸旋转

一、屏幕

这是一块DFROBOT产的5’’ 800x480 TFT 电容屏

默认是按长边方向显示的,如果竖屏使用的话,就需要调整屏幕方向和触摸方向

二、屏幕旋转

修改屏幕旋转可以修改启动配置文件

sudo vim /boot/config.txt

添加

# 默认
display_rotate=0
# 90deg
display_rotate=1
# 180deg
display_rotate=2
# 270deg
display_rotate=3

可以根据需要添加旋转值(顺时针的)

然后重启即可生效sudo shutdown -r now

三、触摸旋转

如果只是屏幕进行了旋转的话,触摸还是保持默认方向,就无法正常操作了,需要调整与屏幕方向一致才行

编辑配置

sudo vim /usr/share/X11/xorg.conf.d/40-libinput.conf
# Match on all types of devices but joysticks
#
# If you want to configure your devices, do not copy this file.
# Instead, use a config snippet that contains something like this:
#
# Section "InputClass"
# Identifier "something or other"
# MatchDriver "libinput"
#
# MatchIsTouchpad "on"
# ... other Match directives ...
# Option "someoption" "value"
# EndSection
#
# This applies the option any libinput device also matched by the other
# directives. See the xorg.conf(5) man page for more info on
# matching devices.

Section "InputClass"
Identifier "libinput pointer catchall"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection

Section "InputClass"
Identifier "libinput keyboard catchall"
MatchIsKeyboard "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection

Section "InputClass"
Identifier "libinput touchpad catchall"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection

Section "InputClass"
Identifier "libinput touchscreen catchall"
# 90deg
Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1"
MatchIsTouchscreen "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection

Section "InputClass"
Identifier "libinput tablet catchall"
MatchIsTablet "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection

libinput touchscreen catchall部分添加一行Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1"

注意:

# 90 deg
Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1"

# 180 deg
Option "CalibrationMatrix" "-1 0 1 0 -1 1 0 0 1"

# 270 deg
Option "CalibrationMatrix" "0 -1 1 1 0 0 0 0 1"

重启即可