-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
system-tools: add gpiod (official Python bindings for libgpiod) #9592
Conversation
@HiassofT can you look into this one? As long as it aligns to the direction direction RPi devs are pushing for with GPIO? |
@chewitt I'll do some tests next week when I'm finished with family visits. In general I think using upstream libgpiod is a huge improvement over all the oddball gpiozero, lgpio, RPi-tools etc shenanigans which are poorly supported, have multiple long-time unfixed issues and don't seem to go anywhere with fixing them. |
As we already have a libgpiod package, for the providing the libgpiod command line tools in the system-tools addon, and this is not really RPi-specific I'd suggest to add building the python bindings in the libgpiod package and including the python module in system-tools instead of rpi-tools. For LE master this libgpiod change should work:
|
I'm support the idea to make it general available and implemented this in system-tools addon instead of rpi-tools addon. I used your design and added the one-liner to include the bindings in the addon. On that way it's not every time the most recent version of gpiod, but guarantees to be in sync with libgpiod. Currently I'm testing with this approach for LE 12 and LE 13. BTW: During compilation of system-tools I stumbled over the stanza issue (.threads/logs/xx.log) with hid_mapper and add a patch file to fix that:
What would be the next step? After successful local testing, should I revise this pull request to move the Python bindings to the system-tools addon? And is it ok to include the hid_mapper patch file in this pull request or should I open a new one? |
Hi @HungerHa - can you share the issue that is being addressed by the hid_mapper patch? These should go upstream (though I’m aware the code in currently not maintained.) |
Hi @heitbaum - without the patch the log will flooded and it seems no compilation progress:
EDIT: I created a pull request at the source: s-leroux/hid_mapper#5 |
Your build environment is Debian from the guess of things as here is the output from within the docker build environment. The Makefile as below is the root cause of the issue - as it is dragging in settings from the local Operating system (not allowing the cross compile to do its thing.)
|
@HungerHa if the suggested changes work, please update the PR and create a LE12 backport PR. Unfortunately your current LE12 PR has been merged prematurely, if it's not too much hassle please also add a drop of the gpiod package and the rpi-tools changes, plus a PKG_REV bump of rpi-tools so LE12 is in sync with master. Don't worry about hid_mapper, if anything that's a separate issue and should be handled separately (if necessary at all) |
now that the cause of the hid_mapper problem has been clarified, I am currently looking for a way to compile the bindings from libgpiod with the LE12 toolchain. If I copy the function “python_target_env” into the LE 12 environment, I am already one step further, but no build module is found. So I can't use the same mechanism at the moment. Is there an easy way to add this Python module to the toolchain of LE12? EDIT: Okay I see, there also package.mk files below ...python/devel...
BTW: @heitbaum, your updated patch files for hid_mapper from master are not in the LE12 branch, but required to compile successfully the system-tools there too. |
Build in LE12 CI/CD is fine. Just checked locally. Fine too.
|
LE12 doesn't have python_target_env, you need to build the python module with Just move the exports inside the post_make_target function, change directory like in LE13 and then (hopefully) python setup.py build should just work. I guess you'll also need the setuptools patch adapted to libgpiod directory structure |
thank you for the hint. I was believing that I tried that already and the build artifact _ext.so was missing afterwards. I must messed up something during my last attempt, now it was built and I can start to test locally. |
03146d2
to
93804bf
Compare
when I started almost from scratch (make clean), the problem with the failed build step reappeared. To fix this, I switched to post_makeinstall_target where the required build artifacts are available. Now it's available within system-tools package (instead of rpi-tools). |
This should fix the build of libgpiod (it should have been -sysroot) diff --git a/packages/addons/addon-depends/libgpiod/package.mk b/packages/addons/addon-depends/libgpiod/package.mk
index 7bd735191f..d278a8269e 100644
--- a/packages/addons/addon-depends/libgpiod/package.mk
+++ b/packages/addons/addon-depends/libgpiod/package.mk
@@ -10,14 +10,14 @@ PKG_URL="https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/snapshot/libg
PKG_DEPENDS_TARGET="toolchain Python3 setuptools:host"
PKG_LONGDESC="Tools for interacting with the linux GPIO character device."
PKG_TOOLCHAIN="autotools"
-PKG_BUILD_FLAGS="+pic"
+PKG_BUILD_FLAGS="+pic -sysroot"
PKG_CONFIGURE_OPTS_TARGET="--enable-tools --disable-shared"
-post_makeinstall_target() {
+post_make_target() {
(
- export LDFLAGS="${LDFLAGS} -L$(get_install_dir libgpiod)/usr/lib"
- export CFLAGS="${CFLAGS} -I$(get_install_dir libgpiod)/usr/include"
+ LDFLAGS+=" -L${PKG_BUILD}/.${TARGET_NAME}/lib/.libs"
+ CFLAGS+=" -I${PKG_BUILD}/include"
cd ../bindings/python
python_target_env python3 -m build -n -w -x
) |
Thank you, very nice. Every day I learn more about it. I'll check it out and update the pull requests.... |
your welcome. When you finalise your commits - use the house-style “system-tools: blah blah blah” (with the colon.) |
93804bf
to
4f9d1eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good now
Thanks a lot for your work, the changes look fine and local build testing worked, too. Only 1 minor nit then this is good to be merged: Please change the commit messages to our house-style: the libgpiod change should be Please also adjust those commit messages in your LE12 PR |
4f9d1eb
to
3a90909
Compare
You're welcome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution and your patience!
gpiod are the official Python bindings for libgpiod. libgpiod is already part of the system tools add-on, only these Python bindings are currently missing to be able to use it in Python scripts.
lgpio and gpiozero are easier to use, but currently have some insurmountable problems, as I have tried to explain here:
Feature request: RPi-Tools with official Python bindings for libgpiod