Rotating an HMI to Portrait Without Reversing Touch
Map touch coordinates through a 90-degree rotation and use an asymmetric corner test to separate axis swaps from scaling errors.

The portrait home screen looks right. Pressing the top-left button activates a control on the far side. Before recalibrating the sensor, record one tap at three points in the input path: raw controller coordinates, coordinates after the input driver, and the position delivered to the application.
A rotation you can check on paper
Assume an 800 × 480 source, origin at top left, x increasing rightward and y downward. For a clockwise image rotation into a 480 × 800 destination, a source pixel (x, y) lands at (479 − y, x). The subtraction uses the last valid index. Using 480 instead creates a one-pixel error and sends one edge outside the destination.
| Source landmark | Expected portrait position |
|---|---|
| Top left (0, 0) | Top right (479, 0) |
| Top right (799, 0) | Bottom right (479, 799) |
| Bottom left (0, 479) | Top left (0, 0) |
| Interior point (100, 50) | (429, 100) |

A square screen offers no aspect-ratio clue to a swapped axis. Use different targets at the corners.
Find the layer that already rotated the event
First normalize the controller’s reported range into the source coordinate system. Some controllers report counts extending far beyond the pixel dimensions. Next trace which layer owns display orientation. If the compositor already rotates input, adding the same transform in the application applies it twice.
Draw four different corner targets with enough inset for a finger, plus a fifth target away from either diagonal. A center tap can appear correct through several wrong transforms. A constant offset suggests a viewport origin error. An error that grows toward one edge points toward scaling. Track both contacts during a two-finger gesture and repeat after suspend. Store the expected orientation alongside the touch controller interface configuration and repeat the capacitive touch validation on the assembled unit.
Cover photograph from Raspberry Pi documentation, reproduced as JPEG under CC BY-SA 4.0.