qemu-gpiodev/libgpiod.git
2 years agobindings: rust: fix documentation of line_request set_values
Kent Gibson [Mon, 16 Jan 2023 12:51:44 +0000 (20:51 +0800)]
bindings: rust: fix documentation of line_request set_values

Replace "Get" with "Set".

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agocore: make the library NULL-aware
Bartosz Golaszewski [Sun, 18 Dec 2022 09:06:18 +0000 (10:06 +0100)]
core: make the library NULL-aware

Currently we almost never check the validity of pointers passed to the
core C API routines. While we cannot know if a non-NULL pointer points
to an actual object, we can at least verify that it is not NULL before
dereferencing it.

Conceptually we can think of two categories of pointers in libgpiod:

First, there are the objects we manipulate using the API. These are
normally the first arguments in any given method and they are only
instantiated inside the library and never dereferenced by the user.

They should always be valid, so passing a NULL pointer here should
always lead to a crash. Currently it will take the form of a segfault
at the moment of dereference but with this change, we make the user
program abort() with the stack trace pointing right at the offender.

The second category would be pointers to objects that are logically
parameters of methods i.e. not their first argument. Example is:
gpiod_chip_request_lines(chip, req_cfg, line_cfg) (whose logical OOP
version would be: chip->request_lines(req_cfg, line_cfg)). Here we
accept a NULL req_cfg but we'll segfault on a NULL line_cfg. For
consistency: don't crash here but instead return -1 and set errno
to EINVAL. Same everywhere else.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agogpiosim: fix error reporting in gpiosim_bank_hog_line()
Bartosz Golaszewski [Mon, 2 Jan 2023 14:31:58 +0000 (15:31 +0100)]
gpiosim: fix error reporting in gpiosim_bank_hog_line()

We don't return errno numbers from public functions - we set errno and
indicate an error by returning -1 or NULL depending on the function
signature. Make gpiosim_bank_hog_line() consistent with that behavior.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agocore: don't check if the pointer about to be freed is NULL
Bartosz Golaszewski [Fri, 16 Dec 2022 14:06:54 +0000 (15:06 +0100)]
core: don't check if the pointer about to be freed is NULL

Unless we dereference it before passing it to free(), we don't need to
care whether the pointer is NULL - free() can handle it.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agocore: chip: drop the unneeded prefix from a static function
Bartosz Golaszewski [Fri, 16 Dec 2022 09:02:09 +0000 (10:02 +0100)]
core: chip: drop the unneeded prefix from a static function

Rename the static function that uses the word 'chip' twice in its name.
Just remove the prefix as we don't export this symbol.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agoconfigure: replace deprecated macro
Bartosz Golaszewski [Fri, 16 Dec 2022 13:44:43 +0000 (14:44 +0100)]
configure: replace deprecated macro

AC_HEADER_STDC is deprecated. Replace it with AC_CHECK_INCLUDES_DEFAULT.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotools: tests: check for egrep presence in the system
Bartosz Golaszewski [Fri, 16 Dec 2022 11:16:46 +0000 (12:16 +0100)]
tools: tests: check for egrep presence in the system

egrep is not a standard shell tool so don't expect it to be present by
default on every system. Check its presence before proceeding.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotests: improve coding style for macros
Bartosz Golaszewski [Fri, 16 Dec 2022 08:32:24 +0000 (09:32 +0100)]
tests: improve coding style for macros

Using parentheses around macro arguments makes sense if lack thereof can
affect operator precedence. Remove them wherever that cannot happen.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotests: consistently use GLib types in tests
Bartosz Golaszewski [Thu, 15 Dec 2022 18:50:12 +0000 (19:50 +0100)]
tests: consistently use GLib types in tests

We use GLib in tests so instead of int use gint everywhere.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotests: don't link against pthread explicitly
Bartosz Golaszewski [Tue, 13 Dec 2022 10:55:33 +0000 (11:55 +0100)]
tests: don't link against pthread explicitly

We use GLib threads now, so there's no need to link againt pthread.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotests: drop unneeded typedef
Bartosz Golaszewski [Tue, 13 Dec 2022 09:57:26 +0000 (10:57 +0100)]
tests: drop unneeded typedef

G_DECLARE_FINAL_TYPE() already takes care of correctly declaring the type
so we don't need the explicit typedef.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agoconfigure: restore AS_IF() when using PKG_CHECK_MODULES()
Bartosz Golaszewski [Mon, 12 Dec 2022 20:16:36 +0000 (21:16 +0100)]
configure: restore AS_IF() when using PKG_CHECK_MODULES()

pkg-config fails if we only try to build the tests without building the
tools. I'm not sure why that happens and can't find any other fix than
restore the AS_IF() for the 'with_tools' block.

Surprisingly: PKG_CHECK_MODULES() works fine elsewhere. Add a FIXME in
the configure.ac and investigate later.

Fixes: 68dd8c6e5edb ("configure: drop AS_IF() macros")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotests: add the missing newline to tests' Makefile.am
Bartosz Golaszewski [Mon, 12 Dec 2022 18:22:19 +0000 (19:22 +0100)]
tests: add the missing newline to tests' Makefile.am

Git complains about the missing newline in tests/Makefile.am so make
it happy and add one.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotools: tests: remove leftover echo
Bartosz Golaszewski [Mon, 12 Dec 2022 09:35:10 +0000 (10:35 +0100)]
tools: tests: remove leftover echo

This looks like some unneeded leftover from the development that was
missed because bats intercepts all echo output.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
2 years agocore: rename gpiod_version_string() to gpiod_api_version()
Bartosz Golaszewski [Sun, 11 Dec 2022 22:25:05 +0000 (23:25 +0100)]
core: rename gpiod_version_string() to gpiod_api_version()

Instead of telling the user what type this function returns (they can
check it by looking at the prototype), tell them what the return value
actually represents.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agoconfigure: improve the header and library function checks
Bartosz Golaszewski [Fri, 9 Dec 2022 09:40:32 +0000 (10:40 +0100)]
configure: improve the header and library function checks

The project is often cross-compiled for embedded systems with all kinds
of wonky toolchains so update configure.ac with checks for less standard
functions and headers. While at it: rearrange the existing checks a bit
so that we only check for headers and symbols when we need them for
current build configuration.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agoconfigure: use C++17 as the only standard
Bartosz Golaszewski [Fri, 9 Dec 2022 10:46:37 +0000 (11:46 +0100)]
configure: use C++17 as the only standard

The entire C++ code base has switched to using the gnu++17 standard so
update the check in configure.ac.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agobuild: use LIBEDIT_CFLAGS when building gpioset with interactive mode
Bartosz Golaszewski [Fri, 9 Dec 2022 10:19:52 +0000 (11:19 +0100)]
build: use LIBEDIT_CFLAGS when building gpioset with interactive mode

The Makefile doesn't include the libedit CLFLAGS when building gpioset
with interactive mode enabled. This can lead to a build failure if the
header is not in the standard location (/usr/include/editline/readline.h).

Add LIBEDIT_CFLAGS to AM_CFLAGS.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agoconfigure: drop AS_IF() macros
Bartosz Golaszewski [Fri, 9 Dec 2022 09:53:18 +0000 (10:53 +0100)]
configure: drop AS_IF() macros

AS_IF() is much less readable than a regular if/else and it's only called
for by docs if the code inside the expansion uses AC_REQUIRE(). Convert
AS_IF() occurrences to standard if/else syntax.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agogpiosim: add missing fcntl.h include
Bartosz Golaszewski [Fri, 9 Dec 2022 10:07:03 +0000 (11:07 +0100)]
gpiosim: add missing fcntl.h include

The fcntl.h header is needed for openat() and mkdirat() that the gpiosim
code uses. It seems to be pulled in indirectly on most toolchains but for
the sake of correctness, include it explicitly.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agogpioset: put local variables of the same type on a single line
Bartosz Golaszewski [Fri, 9 Dec 2022 09:26:08 +0000 (10:26 +0100)]
gpioset: put local variables of the same type on a single line

Unless it hurts readability, try to keep the variables of the same type
on the same line.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotreewide: add missing commas to enums and struct definitions
Bartosz Golaszewski [Wed, 7 Dec 2022 09:35:53 +0000 (10:35 +0100)]
treewide: add missing commas to enums and struct definitions

The code is not consistent with regard to following the last element in
enums and struct definitions with a comma. Unless the last element is
guaranteed not to change (e.g. '{ }', or NULL), follow it with a comma
treewide to avoid churn in git when adding new values.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agobindings: python: tests: set the process name
Bartosz Golaszewski [Tue, 6 Dec 2022 09:56:21 +0000 (10:56 +0100)]
bindings: python: tests: set the process name

When we run the test suite by calling the __main__ function of the module,
the name of the process as visible in the system becomes "python". Let's
set it to "python-gpiod" before running the tests. This way gpiosim will
name its configfs attributes appropriately.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agogpiosim: get the process name using prctl()
Bartosz Golaszewski [Tue, 6 Dec 2022 13:23:54 +0000 (14:23 +0100)]
gpiosim: get the process name using prctl()

program_invocation_short_name is set once at the program's start. If we
change the process name using prctl(), we need to retrieve it using the
same system call as program_invocation_short_name will not be updated.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agogpioset: fix memory leak in interactive mode
Esben Haabendal [Tue, 6 Dec 2022 08:46:37 +0000 (09:46 +0100)]
gpioset: fix memory leak in interactive mode

Even when readline() returns an empty buffer, we still need to free() it to
avoid leaking memory.

Signed-off-by: Esben Haabendal <esben@geanix.com>
[Kent: suggested a shorter version]
Co-developed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agobindings: python: add version.py to EXTRA_DIST
Bartosz Golaszewski [Wed, 7 Dec 2022 09:24:29 +0000 (10:24 +0100)]
bindings: python: add version.py to EXTRA_DIST

The version file is missing from the distro tarball, so add it.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agogpiosim: fix a resource leak
Bartosz Golaszewski [Mon, 5 Dec 2022 13:08:04 +0000 (14:08 +0100)]
gpiosim: fix a resource leak

If we set the number of lines to x, set line names or hogs for lines
from 0 through x, then set the number of lines to (x - y), we will not
unlink all the line directories as we only iterate up to num_lines in
bank_release().

Allocate a small structure for every line we create a lineX directory
for and iterate over it in bank_release() to know exactly which ones
need freeing.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agogpiosim: use wrappers around container_of()
Bartosz Golaszewski [Mon, 5 Dec 2022 10:12:13 +0000 (11:12 +0100)]
gpiosim: use wrappers around container_of()

Simplify the code a bit by providing helpers that extract the underlying
structure from struct refcount using container_of().

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agobindings: python: extend setup.py
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:31 +0000 (13:42 +0100)]
bindings: python: extend setup.py

Add additional information to setup.py. This will be visible in the EGG
file.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agobindings: python: fix the GPIOD_WITH_TESTS build flag
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:30 +0000 (13:42 +0100)]
bindings: python: fix the GPIOD_WITH_TESTS build flag

Currently in order to disable test the variable needs to be explicitly
set to GPIOD_WITH_TESTS= in the environment or setup.py will crash.

Assume tests should not be built if the variable is not set at all.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agobindings: python: decouple the version of the bindings from libgpiod API version
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:29 +0000 (13:42 +0100)]
bindings: python: decouple the version of the bindings from libgpiod API version

Python bindings now have their own setup.py script and can be built
separately from the rest of the code-base. Let's decouple the python
package version from libgpiod API (but let's keep a module attribute
containing the API version) by introducing a version.py submodule that
can be executed by the setup.py script. This way we have a single
canonical place defining the version number.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agobindings: rust: include rust sources in the release tarballs
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:28 +0000 (13:42 +0100)]
bindings: rust: include rust sources in the release tarballs

Rust sources and Cargo files are not added to EXTRA_DIST. Add them so that
they end up in the release tarballs generated by autotools.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
2 years agobindings: rust: make reuse happy
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:27 +0000 (13:42 +0100)]
bindings: rust: make reuse happy

Add missing license text files and use the CC0-1.0 license for the
rust-specific .gitignore file.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
2 years agotools: display the correct license with --version
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:26 +0000 (13:42 +0100)]
tools: display the correct license with --version

The tools are licensed under GPL-2.0-or-later so fix the output
of --version.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agogpiosim: rename HOG_DIR to DIRECTION
Bartosz Golaszewski [Wed, 7 Dec 2022 08:53:28 +0000 (09:53 +0100)]
gpiosim: rename HOG_DIR to DIRECTION

The enum itself should just define direction settings, it's the functions
that use it that should refer to hogging.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
2 years agotreewide: rename EVENT_CLOCK to CLOCK
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:24 +0000 (13:42 +0100)]
treewide: rename EVENT_CLOCK to CLOCK

While we use it for edge event timestamps exclusively at the moment,
the actual enum names shouldn't limit its application and simply just
refer to existing clock types known by the GPIO uAPI. The relevant
functions are still called set/get_event_clock() as it's in line with
their functionality.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
2 years agotreewide: use plural 'events' in read_edge_event() functions
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:23 +0000 (13:42 +0100)]
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>
2 years agotreewide: apply formatting changes with clang-format
Bartosz Golaszewski [Wed, 7 Dec 2022 08:45:06 +0000 (09:45 +0100)]
treewide: apply formatting changes with clang-format

Use linux kernel's .clang-format file to automatically improve the coding
style of libgpiod's C code base. We don't import the file into the
repository as it's not perfect and certain converted fragments were
rolled back because they looked better before the conversion.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotreewide: use C enum types explicitly
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:21 +0000 (13:42 +0100)]
treewide: use C enum types explicitly

Use enum types explicitly across the entire C API. Modern compilers can
catch some bugs with enums and it also helps IDEs and general readability.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
[Viresh: make rust bindings work with negative enum values]
Co-authored-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
2 years agobindings: python: tests: use the version parser from setuptools
Bartosz Golaszewski [Tue, 6 Dec 2022 09:23:44 +0000 (10:23 +0100)]
bindings: python: tests: use the version parser from setuptools

We currently require the third-party packaging module to be installed in
order to run tests. Let's instead use the version parser that's already
available in setuptools.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotests: join the thread at the end of the seqno test case
Bartosz Golaszewski [Mon, 5 Dec 2022 13:56:45 +0000 (14:56 +0100)]
tests: join the thread at the end of the seqno test case

The call to g_thread_join() is missing at the end of the test case for
event sequence numbers so add it and fix a resource leak.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agotests: unref GVariant objects
Bartosz Golaszewski [Mon, 5 Dec 2022 13:22:38 +0000 (14:22 +0100)]
tests: unref GVariant objects

We need to drop the reference count of the GVariants we create when
packing hogs and line names. This fixes all memory leaks in tests that
are caused by this bug.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2 years agoREADME: update Tools section for v2 tools
Kent Gibson [Mon, 21 Nov 2022 10:22:53 +0000 (18:22 +0800)]
README: update Tools section for v2 tools

Update the Tools section to reflect the changes to the tools for v2.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agotools: gpionotify tests
Kent Gibson [Mon, 21 Nov 2022 10:22:52 +0000 (18:22 +0800)]
tools: gpionotify tests

Extend the tool test suite to cover the gpionotify tool.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agotools: add gpionotify
Kent Gibson [Mon, 21 Nov 2022 10:22:51 +0000 (18:22 +0800)]
tools: add gpionotify

Add a gpionotify tool, based on gpiomon, to report line info change
events read from chip file descriptors.

Inspired by the gpio-watch tool in the linux kernel, but with gpiomon
features such as custom formatted output, filtering events of
interest and exiting after a number of events, so more useful for
scripting.

Default output is minimalist, so just time, event type and line id.
Full event details are available using the custom formatted output.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
[Bartosz: coding style tweaks]
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agotools: line name focussed rework
Kent Gibson [Mon, 21 Nov 2022 10:22:48 +0000 (18:22 +0800)]
tools: line name focussed rework

Rework the tool suite to support identifying lines by name and to
support operating on the GPIO lines available to the user at once, rather
than on one particular GPIO chip.

All tools, other than gpiodetect, now provide the name to (chip,offset)
mapping that was previously only performed by gpiofind. As names are not
guaranteed to be unique, a --strict option is provided for all tools to
either abort the operation or report all lines with the matching name, as
appropriate.
By default the tools operate on the first line found with a matching name.

Selection of line by (chip,offset) is still supported with a --chip
option, though it restricts the scope of the operation to an individual
chip.  When the --chip option is specified, the lines are assumed to be
identified by offset where they parse as an integer, else by name.
To cater for the unusual case where a line name parses as an integer,
but is different from the offset, the --by-name option forces the lines
to be identified by name.

The updated tools are intentionally NOT backwardly compatible with the
previous tools. Using old command lines with the updated tools will
almost certainly fail, though migrating old command lines is generally as
simple as adding a '-c' before the chip.

In addition the individual tools are modified as follows:

gpiodetect:

Add the option to select individual chips.

gpioinfo:

Change the focus from chips to lines, so the scope can be
an individual line, a subset of lines, all lines on a particular chip,
or all the lines available to the user.  For line scope a single line
summary is output for each line.  For chip scope the existing format
displaying a summary of the chip and each of its lines is retained.

Line attributes are consolidated into a list format, and are extended
to cover all attributes supported by uAPI v2.

gpioget:

The default output format is becomes line=value, as per the
input for gpioset, and the value is reported as active or inactive,
rather than 0 or 1.
The previous format is available using the --numeric option.

Add an optional hold period between requesting a line and reading the
value to allow the line to settle once the requested configuration has
been applied (e.g. bias).

gpiomon:

Consolidate the edge options into a single option.

Add a debounce period option.

Add options to report event times as UTC or localtime.

Add format specifiers for GPIO chip path, line name, stringified event
type, and event time as a datetime.

Rearrange default output format to place fields with more predicable
widths to the left, and to separate major field groups with tabs.
Lines are identified consistent with the command line.

gpioset:

Add a hold period option that specifies the minimum period the line
value must be held for.  This applies to all set options.

Support line values specified as active/inactive, on/off and
true/false, as well as 1/0.

Add a toggle option that specifies a time sequence over which the
requested lines should be toggled.  If the sequence is 0 terminated then
gpioset exits when the sequence completes, else it repeats the sequence.
This allows for anything from simple blinkers to bit bashing from the
command line. e.g. gpioset -t 500ms LED=on

Add an interactive option to provide a shell-like interface to allow
manual or scripted manipulation of requested lines.  A basic command set
allows lines to be get, set, or toggled, and to insert sleeps between
operations.

Remove the --mode, --sec, and --usec options.
The combination of hold period and interactive mode provide functionality
equivalent to the old --mode options.  By default gpioset now holds the
line indefinitely, rather than exiting immediately.  The old exit
behaviour can be emulated with a "-t 0" option.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
[Bartosz: coding style tweaks, dropped stray newlines and spaces]
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agobindings: rust: Integrate building of bindings with make
Viresh Kumar [Fri, 18 Nov 2022 10:44:42 +0000 (16:14 +0530)]
bindings: rust: Integrate building of bindings with make

Lets make build rust bindings as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agobindings: rust: Add tests for libgpiod crate
Viresh Kumar [Fri, 18 Nov 2022 10:44:41 +0000 (16:14 +0530)]
bindings: rust: Add tests for libgpiod crate

Add tests for the rust bindings, quite similar to the ones in cxx
bindings.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agobindings: rust: Add examples to libgpiod crate
Viresh Kumar [Fri, 18 Nov 2022 10:44:40 +0000 (16:14 +0530)]
bindings: rust: Add examples to libgpiod crate

Add examples for the usage of the rust bindings, quite similar to the
ones in cxx bindings.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agobindings: rust: Add gpiosim-sys crate
Viresh Kumar [Fri, 18 Nov 2022 10:44:39 +0000 (16:14 +0530)]
bindings: rust: Add gpiosim-sys crate

This adds gpiosim-sys rust crate, which provides helpers to emulate GPIO
chips.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agobindings: rust: Add libgpiod crate
Viresh Kumar [Fri, 18 Nov 2022 10:44:38 +0000 (16:14 +0530)]
bindings: rust: Add libgpiod crate

Add rust wrapper crate, around the libpiod-sys crate added earlier, to
provide a convenient interface for the users.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agobindings: rust: Add libgpiod-sys rust crate
Viresh Kumar [Fri, 18 Nov 2022 10:44:37 +0000 (16:14 +0530)]
bindings: rust: Add libgpiod-sys rust crate

This adds libgpiod-sys rust crate, which provides FFI (foreign function
interface) bindings for libgpiod APIs.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agotreewide: libgpiod v2 implementation
Bartosz Golaszewski [Thu, 25 Mar 2021 08:26:37 +0000 (09:26 +0100)]
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>
2 years agogitignore: ignore ctags generated tags file
Yegor Yefremov [Wed, 15 Jun 2022 10:05:05 +0000 (12:05 +0200)]
gitignore: ignore ctags generated tags file

This index file will be used by editors like, for example, vim.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2 years agogpiosim: initialize the bank's num_lines field to 1
Bartosz Golaszewski [Mon, 25 Apr 2022 12:35:56 +0000 (14:35 +0200)]
gpiosim: initialize the bank's num_lines field to 1

If we create a simulated chip and never set the num_lines property, the
num_lines field remains set to 0 and the potential lineX and hog
directories within the bank's directory will not get removed so the
removal of the bank's and device's directories will fail too leaving
a dangling chip in place.

Initialize bank->num_lines to 1 to avoid this issue.

Fixes: a2f6e8cd3540 ("libgpiosim: new library for controlling the gpio-sim module")
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agogpiosim: fix file descriptor leak
Bartosz Golaszewski [Fri, 18 Mar 2022 13:15:07 +0000 (14:15 +0100)]
gpiosim: fix file descriptor leak

If a bank gets released before the device is disabled, the sysfs file
descriptor of that bank is leaked. close() it when releasing the bank.

While at it: improve two other details - unlink the configfs directory
after closing the file descriptor associated with it and remove an
unnecessary check when closing the sysfs descriptor when disabling the
device.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agogpiosim: add an enum representing line active state
Bartosz Golaszewski [Wed, 9 Mar 2022 09:14:33 +0000 (10:14 +0100)]
gpiosim: add an enum representing line active state

In order to avoid confusion and stress the fact that "value" represents
the logical state of a GPIO line, add a two-value enum with the names
"ACTIVE" and "INACTIVE" to the libgpiosim API.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agogpiosim: use size_t in the public interface where applicable
Bartosz Golaszewski [Wed, 9 Mar 2022 09:08:03 +0000 (10:08 +0100)]
gpiosim: use size_t in the public interface where applicable

Use the standard integer type for representing sizes in the API of
libgpiod wherever it makes sense.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agotools: port the test-suite to using gpio-sim
Bartosz Golaszewski [Mon, 14 Feb 2022 09:51:59 +0000 (10:51 +0100)]
tools: port the test-suite to using gpio-sim

This makes the gpio-tools tests use the gpio-sim kernel module instead
of the old gpio-mockup.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agogpiosim: fix a memory leak
Bartosz Golaszewski [Wed, 23 Feb 2022 10:03:30 +0000 (11:03 +0100)]
gpiosim: fix a memory leak

If a bank gets dropped when the device is still enabled and before the
parent device, we leak the device path and chip name strings. This makes
sure we always free them.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agogpioinfo: Clean up scandir allocations
Joel Stanley [Wed, 2 Feb 2022 12:01:23 +0000 (22:31 +1030)]
gpioinfo: Clean up scandir allocations

==3017== 176 (80 direct, 96 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2
==3017==    at 0x483F6C7: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3017==    by 0x491CE92: ??? (in /lib/libc.so.6)
==3017==    by 0x10AAAC: main (gpioinfo.c:215)

The entires must be freed, and then the array itself.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agocore: Fix gpiod_line_bulk_reset type
Joel Stanley [Wed, 2 Feb 2022 12:32:48 +0000 (23:02 +1030)]
core: Fix gpiod_line_bulk_reset type

bulk->lines is an array of pointers, so it doesn't matter which pointer
type we specify to sizeof(). As it's a struct gpiod_line *, it would
make sense to use that.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agotests: port C tests to libgpiosim
Bartosz Golaszewski [Wed, 28 Apr 2021 19:31:47 +0000 (21:31 +0200)]
tests: port C tests to libgpiosim

This converts the core library tests to using libgpiosim instead of
libgpiod-mockup while keeping the same interface for tests.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agolibgpiosim: new library for controlling the gpio-sim module
Bartosz Golaszewski [Mon, 12 Apr 2021 09:45:57 +0000 (11:45 +0200)]
libgpiosim: new library for controlling the gpio-sim module

Add a C library for controlling the gpio-sim kernel module from various
libgpiod test suites. This aims at replacing the old gpio-mockup module
and its user-space library - libgpio-mockup - in the project's tree.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agoDoxyfile: remove deprecated property
Bartosz Golaszewski [Wed, 26 Jan 2022 12:40:50 +0000 (13:40 +0100)]
Doxyfile: remove deprecated property

COLS_IN_ALPHA_INDEX has been deprecated. Remove it from the Doxyfile.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agotests: remove gpiod_test_chip_num()
Bartosz Golaszewski [Thu, 29 Apr 2021 08:07:52 +0000 (10:07 +0200)]
tests: remove gpiod_test_chip_num()

This function is no longer used, remove it.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agotools: tests: check for 'timeout' program
Bartosz Golaszewski [Fri, 19 Nov 2021 10:29:01 +0000 (11:29 +0100)]
tools: tests: check for 'timeout' program

I noticed that tools ptests fail on minimal yocto systems and the
culprit of that is missing the timeout command. Check for it before
launching the bats suite.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agoconfigure: Drop unnecessary double-quote character
Andrew Jeffery [Fri, 13 Aug 2021 01:44:13 +0000 (11:14 +0930)]
configure: Drop unnecessary double-quote character

The double-quote was also missing its matching pair.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agoconfigure: Fix 'flase' typo in bats dependency test
Andrew Jeffery [Fri, 13 Aug 2021 01:44:12 +0000 (11:14 +0930)]
configure: Fix 'flase' typo in bats dependency test

Hopefully this helps identify the failure early in confiure rather than
late when the tests should be executed.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agoTODO: remove libgpiod v2 items
Bartosz Golaszewski [Sat, 22 May 2021 18:35:43 +0000 (20:35 +0200)]
TODO: remove libgpiod v2 items

The current proposed v2.0 API for libgpiod contains so many changes
since v1.x that the items in TODO have become obsolete. For instance:
we can no longer rethink the bulk line objects because they no longer
exist. Same for C++ weak references - in the new version the objects
will no longer be copyable. Remove the libgpiod v2 items entirely.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agotools: gpioget: add new --dir-as-is option for GPO read-back
Ahmad Fatoum [Tue, 27 Apr 2021 15:42:24 +0000 (17:42 +0200)]
tools: gpioget: add new --dir-as-is option for GPO read-back

Both legacy sysfs and new character device API support querying line
state of a GPIO configured as output. But while sysfs /value can
be read for these output GPIOs, gpioget unconditionally muxes the
line as input. To ease migration to the new user API, add a new
--dir-as-is parameter that doesn't force the line to input.

This is especially useful for GPIO controllers that maintain their
last configured output state.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
3 years agotreewide: rename chip property accessors
Bartosz Golaszewski [Fri, 2 Apr 2021 13:51:47 +0000 (15:51 +0200)]
treewide: rename chip property accessors

In v2 API all getters will be called using the following pattern:

    gpiod_<object>_get_<what>

Apply this to already existing getters for gpiod_chip.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
4 years agogpioset: fix a segfault with default mode
Bartosz Golaszewski [Thu, 8 Apr 2021 12:30:46 +0000 (14:30 +0200)]
gpioset: fix a segfault with default mode

The default mode (exit) doesn't have a callback so we need to check if
the callback funtion pointer isn't NULL.

Fixes: 9b6e6d268671 ("ctxless: drop all context-less interfaces")
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
4 years agocore: relax gpiod_is_gpiochip_device() even more
Bartosz Golaszewski [Thu, 1 Apr 2021 09:15:46 +0000 (11:15 +0200)]
core: relax gpiod_is_gpiochip_device() even more

Currently libgpiod requires that the GPIO chip character device be named
'gpiochip%u' in devfs. However it's a perfectly valid use-case to have
the device file renamed by udev (or equivalent) to anything else.

Modify gpiod_is_gpiochip_device() to check the major and minor device
numbers first and then ensure that the device in question is associated
with the GPIO subsystem. No longer check the name.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
4 years agocore: hide the GPIOD_API symbol
Bartosz Golaszewski [Wed, 3 Mar 2021 10:50:34 +0000 (11:50 +0100)]
core: hide the GPIOD_API symbol

GPIOD_API is unneccesarily polluting the user-facing headers. There's no
advantage to having it in public files. Let's make them internal to the
library. Upcoming modifications will also make GPIOD_BIT() redundant so
we'll be able to remove all macros unrelated to the main functionality
from gpiod.h.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: kill line updating
Bartosz Golaszewski [Sun, 21 Feb 2021 13:50:47 +0000 (14:50 +0100)]
treewide: kill line updating

This removes any trace of line updating from the API (C, C++ and Python).
The line objects will soon disappear entirely so in order to make the
gradual transition to the new data model easier, remove
gpiod_line_update().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: remove is_requested() and is_free()
Bartosz Golaszewski [Sun, 21 Feb 2021 13:27:31 +0000 (14:27 +0100)]
treewide: remove is_requested() and is_free()

This removes another two functions from the C API as well as their
bindings that don't make much sense (since the user should know if
they have requested the line or not).

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: switch to reference counting for gpio chip objects
Bartosz Golaszewski [Thu, 21 Jan 2021 10:34:57 +0000 (11:34 +0100)]
core: switch to reference counting for gpio chip objects

The preferred approach in low-level system libraries is to make all
exposed data structures opaque and use reference counting for their
memory management. This changes the chip objects to only close their
underlying character device and release all resources once the reference
count goes down to 0. We remove the gpiod_chip_close() function and
replace it with gpiod_chip_ref() and gpiod_chip_unref().

Other objects in the API will either be removed or are not opaque yet
and will be reworked later.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotests: remove line bulk test cases
Bartosz Golaszewski [Wed, 20 Jan 2021 10:27:20 +0000 (11:27 +0100)]
tests: remove line bulk test cases

Together with the removal of line objects, we'll entirely drop the
line bulk concept. In order to avoid having to update tests that will
soon be unneeded when introducing further changes, let's remove line
bulk test cases already.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: simplify line lookup
Bartosz Golaszewski [Mon, 18 Jan 2021 15:51:47 +0000 (16:51 +0100)]
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>
4 years agobuild: add a space between arguments of AC_INIT() in configure.ac
Bartosz Golaszewski [Tue, 2 Mar 2021 11:25:51 +0000 (12:25 +0100)]
build: add a space between arguments of AC_INIT() in configure.ac

Make the AC_INIT() expansion consistent with other macros.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: python: add semicolons to PyObject_HEAD
Bartosz Golaszewski [Tue, 2 Mar 2021 09:31:51 +0000 (10:31 +0100)]
bindings: python: add semicolons to PyObject_HEAD

While not necessary to compile, the PyObject_HEAD macros look more
consistent with the rest of the code if they too have semicolons at the
end of the lines.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agolicensing: relicense C++ library code under LGPL-3.0-or-later
Bartosz Golaszewski [Sun, 14 Feb 2021 15:37:37 +0000 (16:37 +0100)]
licensing: relicense C++ library code under LGPL-3.0-or-later

Using LGPL-2.1 for C++ library code is an issue raised several times on
the linux-gpio mailing list. Programs using C++ libraries often include
significant portions of code generated behind the scenes from C++ headers
(via templates, default implementations etc.).

Section 3 of LGPL-3.0 clarifies the use of code defined in or generated
from C++ headers so this changset proposes to use LGPL-3.0 for all C++
library code in libgpiod.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Acked-by: Kent Gibson <warthog618@gmail.com>
4 years agolicensing: relicense non-library code under GPL-2.0-or-later
Bartosz Golaszewski [Sun, 14 Feb 2021 15:16:50 +0000 (16:16 +0100)]
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>
4 years agolicensing: make the project REUSE-compliant
Bartosz Golaszewski [Wed, 3 Feb 2021 12:14:41 +0000 (13:14 +0100)]
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>
4 years agobindings: python: fix uninitialized default_vals being passed to gpiod_LineBulk_request()
Kent Gibson [Mon, 15 Feb 2021 14:39:19 +0000 (15:39 +0100)]
bindings: python: fix uninitialized default_vals being passed to gpiod_LineBulk_request()

If "default_vals" is not provided in the kwds then default_vals are
passed uninitialized to gpiod_line_request_bulk(), so rename the
existing default_vals to vals and introduce a new default_vals that
points to vals, or NULL if no defaults have been passed.

Fixes: 96c524c4951c (bindings: implement python bindings)
Reported-by: Pedro Botella <pbotella@gmail.com>
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: cxx: tests: remove stray tab
Bartosz Golaszewski [Sun, 14 Feb 2021 15:43:18 +0000 (16:43 +0100)]
bindings: cxx: tests: remove stray tab

Remove an unnecessary tab from the mockup class header.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: cxx: fix building with clang's libc++
Jan Kundrát [Wed, 3 Feb 2021 12:28:57 +0000 (13:28 +0100)]
bindings: cxx: fix building with clang's libc++

This fixes the following error with clang 11 with libc++:

 line.cpp:248:39: error: implicit instantiation of undefined template 'std::__1::array<gpiod_line_event, 16>'
         ::std::array<::gpiod_line_event, 16> event_buf;
                                              ^
 /nix/store/vk8ynr4hj2a8w7g1b9m8wknzj39iiv4x-libc++-11.0.1/include/c++/v1/__tuple:219:64: note: template is declared here
 template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;

Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: add the kernel uapi header to the repository
Bartosz Golaszewski [Wed, 6 Jan 2021 07:20:00 +0000 (08:20 +0100)]
core: add the kernel uapi header to the repository

In order to avoid any problems with symbols missing from the host linux
kernel headers (for example: if current version of libgpiod supports
features that were added recently to the kernel but the host headers are
outdated and don't export required symbols) let's add the uapi header to
the repository and include it instead of the one in /usr/include/linux.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: cxx: line: reorder bias mapping entries
Bartosz Golaszewski [Thu, 17 Dec 2020 14:15:03 +0000 (15:15 +0100)]
bindings: cxx: line: reorder bias mapping entries

Reorder the definitions so that they match the order in which they're
declared in the class. This is cosmetic only.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: make drive settings an enum
Bartosz Golaszewski [Thu, 17 Dec 2020 14:07:34 +0000 (15:07 +0100)]
treewide: make drive settings an enum

Open-source and open-drain drive settings are mutually exclusive just like
the bias settings. Make them into an enum so that becomes clear.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: rename BIAS_DISABLE to BIAS_DISABLED
Bartosz Golaszewski [Thu, 14 Jan 2021 13:32:51 +0000 (14:32 +0100)]
treewide: rename BIAS_DISABLE to BIAS_DISABLED

When we're reading the current bias setting of a line, it is already
disabled so the flag should be named as such. While BIAS_DISABLE would
technically be fine when modifying the setting, let's rename it to
BIAS_DISABLED too for consistency.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: rename BIAS_AS_IS to BIAS_UNKNOWN
Bartosz Golaszewski [Thu, 17 Dec 2020 13:23:59 +0000 (14:23 +0100)]
treewide: rename BIAS_AS_IS to BIAS_UNKNOWN

When inspecting the current bias setting of a GPIO line, the AS_IS name
of one of the possible values really means that the kernel GPIO subsystem
can't determine the bias setting because it didn't set it itself (e.g.
the hardware may have internally initialized pull-up or pull-down
resistors). In this case it's better to change the name to BIAS_UNKNOWN
to reflect that.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: simplify the active-low line property
Bartosz Golaszewski [Wed, 16 Dec 2020 12:19:59 +0000 (13:19 +0100)]
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>
4 years agotreewide: remove helpers for opening chips by name & number
Bartosz Golaszewski [Tue, 15 Dec 2020 12:44:17 +0000 (13:44 +0100)]
treewide: remove helpers for opening chips by name & number

Helper wrappers around gpiod_chip_open() shouldn't really be part of
the core, low-level library. They assume that devtmpfs is mounted at
/dev and that GPIO chips follow the gpiochipX naming convention.

This changeset removes all variants of gpiod_chip_open() other than
the one taking the path as argument. We're doing this treewide so
C++ and Python bindings lose the 'how' argument that currently allows
to change the way the chips are opened by the chip's constructors or
the open() method in C++.

The gpio-tools programs still support opening chips by number, name
and path but they implement this functionality locally rather than
using the library code.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: remove unneeded include from gpiod.h
Bartosz Golaszewski [Thu, 17 Dec 2020 16:32:23 +0000 (17:32 +0100)]
core: remove unneeded include from gpiod.h

This header is a leftover from previous development. Remove it as nobody
requires it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotests: line: remove a bad test case
Bartosz Golaszewski [Wed, 16 Dec 2020 09:58:57 +0000 (10:58 +0100)]
tests: line: remove a bad test case

The test case for requesting multiple lines exposed by different chips
has never been correct. The request call does indeed fail with EINVAL
but now that we've disallowed adding lines from different chips to
the same bulk object, this happens only because we're using a wrong
constant in the flags field of the request structure.

Remove the entire test as it's no longer required.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: kill chip iterators
Bartosz Golaszewski [Thu, 26 Nov 2020 13:11:54 +0000 (14:11 +0100)]
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>
4 years agobuild: add a configure switch for building examples
Bartosz Golaszewski [Mon, 7 Dec 2020 19:38:30 +0000 (20:38 +0100)]
build: add a configure switch for building examples

Example code for bindings is currently always built if bindings are
enabled. Make it conditional with a new configure switch.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agocore: rework gpiod_chip_find_line()
Bartosz Golaszewski [Wed, 2 Dec 2020 14:18:36 +0000 (15:18 +0100)]
core: rework gpiod_chip_find_line()

GPIO line names are not unique and the library has been incorrectly
making such assumption in v1.x series. We've already dropped interfaces
that would be too complicated to maintain when taking this into account.

Let's now rework the remaming API. This introduces a new function to the
C API: gpiod_chip_find_line_unique() which assumes that the line name is
unique and signals an error if it's not. The previous
gpiod_chip_find_line() function now returns a bulk object containing all
matching lines.

Python and C++ bindings are updated: their find_line() functions return
bulk objects (or an ::std::vector> too now and they take an additional
argument specifying whether we're looking for a unique line or not.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>