1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00
Commit Graph

41 Commits

Author SHA1 Message Date
Bartosz Golaszewski
97bab4cc87 build: replace autotools with meson & ninja
Port the project from autotools to meson. All build options are
preserved with the same semantics.

The goal of this change is to produce the same set of files as the
current autotools approach: libraries with correct SONAME/version,
headers, pkg-config files, GObject introspection data, Python extension
modules, D-Bus interface and configuration files. This is done to enable
a one-liner test command running all available test suites.

The only thing we drop is the `make docs` target as it's rarely used and
docs can be generated easily with sphinx directly. They are also not
required for testing.

The Rust workspace is built via a custom target that invokes cargo and
uses SYSTEM_DEPS_* environment variables to point the libgpiod-sys and
gpiosim-sys crates at the locally built C libraries.

In addition to porting the build files to meson, update the docs, remove
unneded items from .gitignore files (or remove them entirely if they're
no longer needed) and update the shunit2 test scripts to no longer care
about source directories.

Tested-by: Erik Wierich <erik@riscstar.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260428-meson-build-v3-1-8da6976fb0a2@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-04 09:51:03 +02:00
Vincent Fazio
485b81cd4b bindings: python: examples: apply linter recommendations
* Sort imports
* Use f-strings where possible
* Remove usage of `tuple` for config key values

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260401001459.19159-7-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-03 11:00:36 +02:00
Vincent Fazio
d130ec7666 bindings: python: examples: add type annotations
Add type annotations to help with lint checks.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260401001459.19159-6-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-03 11:00:36 +02:00
Kent Gibson
5715f61fd2 bindings: python: examples: add graceful exit to async_watch_line_value
The purpose of the example is demonstrate using a request with poll().
It provides a hint as to how the poll can be combined with other fds but,
as Python comes with batteries included, the Python version of the example
can be readily extended to actually demonstrate this, as well as how it
can be used in multi-threaded environments.

Extend the example to use an eventfd to allow the poll() to be run in
a background thread and be gracefully terminated by the main thread.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240917125455.324551-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-09-20 11:21:24 +02:00
Bartosz Golaszewski
16a35cc268 bindings: python: fix EXTRA_DIST for examples
One of the example scripts is named differently than what the Makefile
lists it as. Change the EXTRA_DIST variable to fix it.

Fixes: 96c52d3e59 ("bindings: python: examples: replace tools examples with use case examples")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-11-03 11:53:11 +01:00
Kent Gibson
96c52d3e59 bindings: python: examples: replace tools examples with use case examples
Replace tool examples with use case examples drawn from the tools.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-06-26 12:09:10 +02:00
Kent Gibson
36a2127e58 bindings: python: examples: consistency cleanup
A collection of minor changes to be more consistent with other examples:
 - capitalize comments
 - add line offset to value outputs
 - drop comma from edge event outputs
 - improve behaviour if run on a platform that does not match the
   example configuration
 - use with to cleanup request in toggle_line_value.py

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-06-23 20:56:42 +02:00
Bartosz Golaszewski
d0e098838c bindings: python: package new examples in the distro tarball
Add new example scripts to EXTRA_DIST in the Makefile so that they end up
being shipped with the rest of the code.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-06-15 10:43:31 +02:00
Kent Gibson
953dbd6af7 bindings: python: examples: add dedicated examples
Add python equivalents of the core examples.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-06-14 15:02:07 +02:00
Bartosz Golaszewski
3fad9c3662 bindings: python: examples: gpioset: drop redundant []
dict() accepts an iterable, so the [] brackets are redundant.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-06-12 17:55:29 +02:00
Kent Gibson
e13ac9764a bindings: python: examples: fix potential glitch in gpioset.py
gpioset.py requests lines without setting their output value, and so
sets them all inactive, and subsequently sets them to their requested
value. This can result in glitches on lines which were active and
are set active.

As this is example code, it is also important to demonstrate that the
output value can be set by the request itself.

Request the lines with the correct output values set in the request
itself.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-06-12 16:29:22 +02:00
Bartosz Golaszewski
4025260351 bindings: python: examples: add gpionotify.py
Add a new Python code examples - gpionotify.py - which is a simplified
reimplementation of the gpionotify tool.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-03-12 14:44:27 +01:00
Bartosz Golaszewski
77a6347d55 treewide: use plural 'events' in read_edge_event() functions
The read_edge_event() family of functions should actually be called
read_edge_events() as they universally allow to read more than one
event. We're converting wait_edge_event() too for consistency.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-12-07 09:51:57 +01:00
Bartosz Golaszewski
b7ba732e6a treewide: libgpiod v2 implementation
This commit is the result of a squash of all the commits created during
the development of libgpiod v2. This is done to preserve bisectability
of the git tree. It contains significant re-writes of the core C library
as well as C++ and python bindings. The tools have been adjusted to work
with the new API but have not undergone significant changes yet.

This commit contains the bulk of the work on libgpiod v2 but the
development continues with more changes planned.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
[Ben: fix format specifier for uint64_t]
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
[Viresh: Fix ioctl number for gpiod_line_request_reconfigure_lines()]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[Kent: bug fixes, improvements, better pointer contracts, type strictness]
Signed-off-by: Kent Gibson <warthog618@gmail.com>
2022-10-31 11:15:14 +01:00
Bartosz Golaszewski
0dcbafee3d treewide: simplify line lookup
We're preparing to entirely remove the line objects from the API and
split their functionality between two new objects: line_info and
line_request. The lookup functions must be limited in the process.

This reworks all the find_line methods to: a) always assume that names
looked for are unique within a single chip (because while it's
technically possible for GPIO line names to be non-unique, it doesn't
make sense to look for two lines named the same) and b) return the
hardware offset within the chip instead of the line object.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2021-03-18 09:34:15 +01:00
Bartosz Golaszewski
154e7c5a82 licensing: relicense non-library code under GPL-2.0-or-later
LGPL-2.1 is a license meant for shared libraries. Because I didn't know
any better I used it for all files in the repository, including programs
linking against libgpiod. The standard approach for many similar projects
is to use LGPL for library code and GPL for programs (and also Makefiles
and other files containing code or configuration).

Relicense all programs, tests, makefiles and autotools files under
GPL-2.0 or later.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Acked-by: Kent Gibson <warthog618@gmail.com>
2021-02-18 17:42:12 +01:00
Bartosz Golaszewski
dfb707c255 licensing: make the project REUSE-compliant
In order to make the licensing situation of libgpiod clear and enable
easy reusing of the code, let's make all the files in the repository
compliant with the REUSE v3.0 specification.

In order to achieve that:
  - put all used licenses into a separate LICENSES/ directory
  - add SPDX license identifiers to all files that were missing them with
    regular text files being licensed under CC-BY-SA-4.0, while files
    containing code and configuration are licensed under GPL-2.0-or-later
  - replace custom copyright texts with SPDX-FileCopyrightText
  - update the gpio.h kernel uAPI header with the upstream version where
    the SDPX license identifier was fixed to use 'GPL-2.0-only' variant
    instead of the deprecated 'GPL-2.0'

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Acked-by: Kent Gibson <warthog618@gmail.com>
2021-02-18 17:42:08 +01:00
Bartosz Golaszewski
d2a70828f8 treewide: simplify the active-low line property
Unlike line direction - where input and output modes are equal, no signal
inversion (active-high) is the natural state of the line while active-low
is less likely. Let's drop the ACTIVE_STATE enum treewide and provide a
boolean property for lines - is_active_low() - to reflect that fact. This
function returning false means the line is "active-high".

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-12-17 18:04:17 +01:00
Bartosz Golaszewski
d0a9ddcb9c core: kill chip iterators
Chip iterators require the user to have permission to access all GPIO
chips. They also don't take into account symbolic links. In general
they're badly designed so remove them treewide in favor of scanning /dev
manually using the provided gpiod_is_gpiochip_device() helper.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-12-14 15:57:15 +01:00
Bartosz Golaszewski
1f0d078c83 build: tweak formatting of multi-line variables in Makefiles
Don't put a tab between the asignment and the first string - just move
the whole list one line below.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-09-10 10:43:24 +02:00
Bartosz Golaszewski
8fc50f32cd bindings: python: examples: check if '__main__' is set
The examples are programs meant to be executed directly and not
imported. Use the standard "if __name__ == '__main__':" before
any code.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-09-10 10:43:24 +02:00
Bartosz Golaszewski
3212e5797a bindings: python: examples: wait for ENTER press in gpioset.py
After setting the line values in gpioset.py: don't exit until the user
presses ENTER. This makes the example work the same as the 'wait' mode
in the original gpioset utility.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-08-12 14:27:32 +02:00
Bartosz Golaszewski
ef857e6dec bindings: python: examples: don't store the return value unnecessarily
In gpioset.py: when calling lines.set_values(), there's no point in
storing the return value as it's always None. It's also not used
anywhere.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-08-12 14:20:48 +02:00
Bartosz Golaszewski
e03044f862 bindings: python: examples: make gpiomon.py output resemble the original
Modify the gpiomon.py example to describe the detected events in
a format similar to the one used by the original gpiomon tool.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-08-12 14:12:13 +02:00
Bartosz Golaszewski
452696601a bindings: python: use unittest to implement a proper test-suite
Currently the only tests we have for python bindings are in a simple
script that makes a lot of assumptions about the environment and
doesn't even work anymore with recent kernels.

Remove it and replace it with a proper test-suite implemented using
libgpiod and the standard python unittest package.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-08-09 14:52:01 +02:00
Bartosz Golaszewski
ba8ee34516 bindings: python: bail-out if the line was not found in gpiofind.py
Currently we're not checking if the object returned from
gpiod.fine_line() is None which results in an attribute error being
raised when we try to call line methods on a non-line object.

Add an if and bail-out with an error code if the line with given name
was not found.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-31 14:40:09 +02:00
Bartosz Golaszewski
cdf5ef94c4 bindings: python: fix gpiod_Chip_find_lines() for nonexistent lines
Currently if we call gpiod_Chip_find_lines() with some names that
cannot be looked up, we end up getting an exception from the LineBulk
object's constructor (because None is not a Line and LineBulk can only
hold Line objects).

Fix the behavior of gpiod_Chip_find_lines() for nonexistent lines by
raising an explicit exception if the underlying gpiod_Chip_find_line()
call returns None. Also: add a relevant test case.

Fixes: 96c524c495 ("bindings: implement python bindings")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-31 14:30:46 +02:00
Bartosz Golaszewski
1d87088b1e bindings: python: examples: close chip objects where needed
Unlike the C++ bindings: we can't expect the python runtime to call
the Chip object's destructor when all references are dropped. We need
to close each chip explicitly. Either call the close() method directly
or use controlled execution in all examples.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-31 14:30:46 +02:00
Bartosz Golaszewski
445793aabf bindings: python: examples: new test case
Add a test case for incorrect number of default values in line
requests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-22 20:14:50 +02:00
Bartosz Golaszewski
e03e802add bindings: python: add test cases for default values in line requests
Add two new tests verifying the default_vals argument in line requests
for single and multiple lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-20 10:35:35 +02:00
Bartosz Golaszewski
a610c5077e bindings: python: examples: remove unnecessary import
We no longer need sys in gpiod_tests.py. Remove it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-13 19:47:37 +02:00
Bartosz Golaszewski
ce2853562e bindings: python: examples: don't use sys.argv[0] as consumer string
Strings with slashes trigger a warning in the kernel in
fs/proc/generic.c. Use a hardcoded consumer string.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-13 16:01:06 +02:00
Bartosz Golaszewski
e421f0d776 bindings: python: add a test case for line_event's __repr__
Check if an event's representation string is generated correctly.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-06-07 09:25:48 +02:00
Bartosz Golaszewski
2dfb43260a bindings: python: add support for controlled execution
Provide __enter__ and __exit__ callbacks for Chip so that it can be
used with the 'with' statement.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-16 12:29:17 +02:00
Bartosz Golaszewski
e04d4d45c2 bindings: python: provide better resource control
So far we rely on cpython's reference counting for closing the GPIO
chips and freeing the underlying resources. This is however wrong.
Python doesn't guarantee anything regarding the lifetime of an object.

Provide a method for closing the underlying chip handle and add
relevant checks to all methods using the resources associated with
a GPIO chip, so that we raise an error should the user use a chip
after closing it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-16 12:01:45 +02:00
Bartosz Golaszewski
7cc5304f33 bindings: python: provide gpiod.version_string()
Implement a python wrapper around gpiod_version_string().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-16 10:39:11 +02:00
Bartosz Golaszewski
3107d63692 bindings: python: test case for line flags
Add a new test case verifying that line flags work as expected.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 18:35:16 +02:00
Bartosz Golaszewski
345d408836 bindings: python: improve readability in test cases
Mostly just add new lines for improved readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 18:13:36 +02:00
Bartosz Golaszewski
0596dfb0b5 bindings: python: new test cases/examples
Add more test cases/code examples for python bindings.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 14:51:00 +02:00
Bartosz Golaszewski
2df328e989 bindings: python: extend tests
Add more test cases/examples, implement some helper functions, tweak
the output messages, mention the need for a dummy chip in the system
in the module's pydoc string.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 12:01:13 +02:00
Bartosz Golaszewski
96c524c495 bindings: implement python bindings
Create a C extension module wrapping the functionality of libgpiod
in a set of Python classes.

Add code examples including simplified reimplementations of gpio-tools
in Python.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-04-17 10:19:34 +02:00