Raspberry Pi

Using the Raspberry Pi Touch Display with OpenFL

I really like the new Raspberry pi display.

One of the things I was really looking forward to was using it with OpenFL.
But out of the box SDL2 wasn’t supporting the display in the mode I am running OpenFL namely without x11.

So I decided to do a little digging.
I found that mouse and keyboard devices are being handled in sdl_udev and sdl_evdev.
Basically udev was looking for and identifying input devices and evdev was handling incoming events from identified devices.

I could see that udev was finding an ID_INPUT_TOUCHSCREEN device, but there was nothing more than a comment after that.
So I decided to try and trick udev by identifying the touchscreen as a combined mouse and keyboard device.

Immediately I could move the mouse pointer but a touch triggered a key-event with an unhandled value of 330.
( later I found that this key is defined in linux/input.h as BTN_TOUCH )
So I added the button to the if statement that was catching the mousebutton values in SDL_evdev.c
and cheated a bit by changing it to mouse-button 0

I thought that it was working until I noticed something strange. It felt like the mousedown event was out of sync.
So I opened the utility evtest on an ssh session to see what was going on.
If found that the touchscreen was firing 2 unhandled events before the BTN_TOUCH event:

the code was only handling the ABS_X events so indeed the Touch event came before the x en y positions where handled.
So I added these 2 new events:

Et Voila!, the touch screen is working as a mouse.

For proper multitouch a different approach is needed.
But for testing this hack works quite well.