Close

Software stack cleanup

A project log for Light pen support for RetroPie

Can a Raspberry Pi with CRT display support 8-bit era light pen?

Maciej WitkowiakMaciej Witkowiak 07/05/2020 at 12:280 Comments

I have reorganized the code and pushed everything to Github.

There are only three source files:

  1. rpi-lightpen.c - Linux kernel driver that will timestamp IRQs from VSYNC and the light pen sensor. From the time offset between those two events it calculates the difference in microseconds and divides it by 64 (timing of scanning one PAL line) and shows this as Y coordinate (row). The remainder from division is the X coordinate (column). The third result is the lightpen button state. All of this can be read from /dev/lightpen0 device.
  2. lp-int.py - this python3 pygame program will start with calibration and then will just show a text that follows light pen position
  3. lp-int-uinput.py - this python3 pygame program will start with calibration and then will convert numbers from /dev/lightpen0 into uinput events as if coming from a touchpad/touchscreen/tablet with absolute coordinates

I tried to use lp-int-uinput.py with classic NES Duck Hunt game but the crosshair shakes uncontrollably. This is very strange considering that lp-int.py uses exactly the same code and the position of the text on the screen is rather stable.

Enjoy: https://github.com/ytmytm/rpi-lightpen

Discussions