Whilst you can usually flip the official touchscreen display (180 degrees) using 'lcd_rotate=2' in the Raspberry Pi config file, some projects require the display and touch to be rotated 90 degrees or other rotations.
Rotating 90 degrees (or others) requires a different line to be added to the config file:
Open the config.txt file by using the following command in a terminal window:
sudo nano /boot/config.txt
Then add the line that best fits your needs:
- Rotate left 90 = xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1
- Rotate 180 = xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
- Rotate right 90 = xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1
- Return to upright = xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
More information on xinput can be found here: https://wiki.ubuntu.com/X/InputCoordinateTransformation
You can also use these commands on other types of screens, you just need to know the screen name to replace the 'raspberrypi-ts' part. For example, the Pimoroni Hyperpixel 4 Touchscreen is known as a 'Goodix Capacitive TouchScreen'.