Feature request: RPi-Tools with official Python bindings for libgpiod

  • Are there a chance that the Python bindings for libgpiod are official included into the virtual rpi-tools addon? libgpiod is already part of the system-tools addon, only the python bindings are currently missing.

    libgpiod/bindings/python at v2.2.x · brgl/libgpiod
    This is a mirror of the original repository over at kernel.org. This github page is for discussions and issue reporting only. PRs can be discussed here but the…
    github.com
    gpiod
    Python bindings for libgpiod
    pypi.org


    Why?

    Since LibreELEC 12 gpiozero is the main module intented to interact with the GPIO pins. But there are some ugly problems:

    • gpiozero takes to long to terminate (killed by KODI after 5 seconds during shutdown, may be related to the lgpio issue explained below) and doesn't frees the used GPIO ressources, so it's need to reboot instead of disable/enable the addon to get it work again
    • gpiozero is slower than libgpiod because of additional abstraction layers: https://adafruit-playground.com/u/MakerMelissa…-raspberry-pi-5
    • lgpio can be used without gpiozero to workaround the blocked ressource issue of gpiozero, but it seems to start some kind of threading as soon the Python module lgpio is imported. The thread with the imported lgpio module doesn't stop within 5 seconds (the hard limit for the CPythonInvoker of KODI) and prevents KODI to restart/shutdown in usual time. It takes 30 seconds to "systemctl restart kodi" or to shutdown LibreELEC if lgpio is directly or indirectly via gpiozero imported in a script addon. Therefore I think rpi-lgpio (RPi.GPIO replacement) will do have the same restriction.

    For a cross-check, I compiled the rpi-tools addon for testing so that it also contains these bindings. If I use gpiod instead of gpiozero / lgpio for Argon40 Device Configuration addon the "systemctl restart kodi" takes only 4 - 6 seconds (not 30 seconds), depending how much background tasks are currently running. This will enable again an ordered shutdown, if the remote control power button is used for the case shutdown instead of the KODI menu. Another story with a firmware restriction (10 seconds limit) of the Argon40 case...

    Yes, I can include the bindings in the Argon40 addon, but I would prefer a globally available gpiod Python module so that others also have the advantage of choosing the best working module for their use case.

  • Hi chewitt ,

    thanks for the review and the helpful comments. I have created another PR9592 for the master branch and updated the existing PR9591 to be able to use it as a backport for LE12.