So. Next chapter: Bought a 5" HDMI screen here. It has an HDMI input and connects to the RPi GPIO pins for power and touch functionality... and works ALMOST out of the box on a fresh Raspbian install (from 5/2016). Nice!
Set up screen resolution and touchscreen
hdmi_cvt 800 480 60 6 0 0 0
This gets the display and the touchscreen up and running. You can test if the touchscreen does anything using:
Setting up the touchscreen for X
This should give you weird output whenever you touch the screen. Fine.
Now you want to calibrate it. To do that install the calibration utility:
sudo apt-get install xinput_calibrator
Then start the GUI. You should now have an entry "Calibrate touchscreen" in your menu. Start it and tap the points. When finished the screen should be calibrated.
Or, to do the calibration from the command line, run:
You can also do this from SSH, if you don't have a keyboard attached:
Tap the points and when finished, the tool will output some calibration information:
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "114 3982 226 3883"
Option "SwapAxes" "0"
Paste the calibration info into "/usr/share/X11/xorg.conf.d/99-calibration.conf".
Setting up the touchscreen for Kodi
Now you have a calibrated X input device, so the Desktop works nicely, but Kodi still does not. When starting it from X, there is a cursor, but the calibration is way off. When starting it standalone, there is not even touch input...
Fix this by installing tslib and evtest:
sudo apt-get install evtest tslib libts-bin
Additionally you will need Then calibrate the touchscreen using:
Touch the 5 crosses and you're done. You can test the calibration using:
You might also need to add the "kodi" user to the "input" user group:
sudo usermod -a -G input kodi
If you have Kodi version >= 17 ("Krypton") you cannow set up scale factors for the display so the cursor is properly displayed.
Setting display scale factors in Kodi >= v17
Test if Kodi can use touch input now. Start Kodi and touch the upper left corner of the screen. You will see a cursor and can move it, but only in 1/5th of the screen. The problem is that the coordinates /dev/input/event0 sends are touch device coordinates (in the range you see in the calibration values above), but Kodi expects pixel screen coordinates (0-800,0-480). Kodi starts to support touchscreen calibration out-of-the-box as of v17 aka "Krypton".
Edit the file advancedsettings.xml in your users userdata folder, e.g. /home/kodi/.kodi/userdata or ~/.kodi/userdata. If it does not exist, create it and add the following entries:
<x_offset>-32</x_offset> <!-- cursor pixel x offset
<y_offset>-35</y_offset> <!-- cursor pixel y offset
<x_stretch_factor>0.209</x_stretch_factor> <!-- stretch factor
<y_stretch_factor>0.131</y_stretch_factor> <!-- stretch factor
Good start values can be calculated by dividing the screen resolution by the X11 calibration values above (e.g. for x: 800/3982=~0.2 and 480/3883=~0.124). Note that you have to restart Kodi after editing the values to see any changes.
Installing a touchscreen calibration fix
When you have an older Kodi version and can not use advancedsettings.xml, there are also ways to properly calibrate your screen. Read here about using a tslib fork and ts_uinput_touch for this.
Fixing the double-click issue
A remaining problem is that Kodi wants a double-click to activate a function. This is not good as we want to activate functions with a single click or tap. We can change this by editing the file /usr/share/kodi/system/keymaps/mouse.xml. Change the entries in the mouse section to:
P.S. Find out how to hide the cursor here.
P.P.S. You can also add backlight control to the screen...