I recently bought a 7" HDMI touch display to connect to my Raspberry Pi 4B. Unfortunately, when in the "proper" orientation the HDMI and USB ports are on the left side of the display which is not optimal for my setup. I wanted to rotate the display 180 degrees so the ports were on the right.
On the 3B this is easy - in /boot/config.txt
you can add the line:
display_hdmi_rotate=2
to the end and that will rotate the display. But on the 4B this doesn't work unless you also disable the vc4-fkms-v3d
overlay so you don't have hardware accelerated video.
However, there is a way to have your cake and eat it too - an inverted display and hardware acceleration. The answer is to add a video=
option to the end of the text in cmdline.txt
such as:
video=HDMI-A-1:1024x600MR,margin_left=0,margin_right=0,margin_top=0,margin_bottom=0,rotate=180
HDMI-A-1
corresponds to the first micro-HDMI port (the one closest to the USB-C connector). Replace 1024x600
with whatever the resolution of your display is, such as 800x480
. This needs to be added to the end of the single line in cmdline.txt
- do not start a new line.
An example complete line in cmdline.txt
would be:
console=serial0,115200 console=tty1 root=PARTUUID=6c586e13-02 rootfstype=ext4 elevator=deadline rootwait video=HDMI-A-1:1024x600MR,margin_left=0,margin_right=0,margin_top=0,margin_bottom=0,rotate=180
This will completely invert the display. There should be no need for any other options in config.txt
or to use xrandr
to invert the X display. However, this does not invert the touchscreen input, if any. If the touchscreen uses USB, you can do the following to invert the input to match the display.
Create a file /etc/X11/xorg.conf.d/40-libinput.conf
with the following contents:
Section "InputClass"
Identifier "libinput touchscreen catchall"
MatchIsTouchscreen "on"
MatchDevicePath "/dev/input/event*"
# Inverted
Option "TransformationMatrix" "-1 0 1 0 -1 1 0 0 1"
EndSection
The next time you reboot your Pi, the display will be inverted both for the console and X, and your USB touch screen input will be inverted to match.