Bartosz Golaszewski [Fri, 13 Jan 2023 09:41:44 +0000 (10:41 +0100)]
bindings: python: add the output_values argument to Chip.request_lines()
Add a new optional argument to Chip.request_lines() called output_values.
It accepts a dictionary of mappings between line names or offsets to the
output values the requested lines should be set to at request-time.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:30:25 +0000 (19:30 +0100)]
bindings: cxx: add line_config.set_output_values()
Extend line_config to expose a new method - set_output_values() - which
wraps the new C function for setting multiple output values at once.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:13:12 +0000 (19:13 +0100)]
gpioset: use gpiod_line_config_set_output_values()
Use the new line config function to shrink the gpioset code and drop one
for loop.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:12:51 +0000 (19:12 +0100)]
core: provide gpiod_line_config_set_output_values()
Currently if user wants to use the same settings for a set of requested
lines with the exception of the output value - they need to go through
hoops by updating the line settings object and adding it one by one to
the line config. Provide a helper function that allows to set a global
list of output values that override the settings. For details on the
interface: see documentation in this commit.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 24 Jan 2023 09:58:11 +0000 (10:58 +0100)]
treewide: unify gpiod_line_config/request_get_offsets() functions
We have two functions in the C API that allow users to retrieve a list
of offsets from objects: gpiod_line_request_get_offsets() and
gpiod_line_config_get_offsets(). Even though they serve pretty much the
same purpose, they have different signatures and one of them also
requires the user to free the memory allocated within the libgpiod
library with a non-libgpiod free() function.
Unify them: make them take the array in which to store offsets and the
size of this array. Make them return the number of offsets actually
stored in the array and make them impossible to fail. Change their names
to be more descriptive and in the case of line_config: add a new function
that allows users to get the number of configured offsets.
Update the entire tree to use the new interfaces.
For rust bindings: also unify the line config interface to return a map
of line settings like C++ bindings do instead of having a function to
get settings by offset. A map returned from a single call is easier to
iterate over with a for loop than using an integer and calling the
previous line_settings() method.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Viresh Kumar [Tue, 24 Jan 2023 08:23:43 +0000 (13:53 +0530)]
bindings: rust: Allow reusing locally installed gpio library
The rust crates builds fine when built with the 'make' command, as
static linking works fine. But when referenced from a remote rust crate,
it gives following error:
error: could not find native static library `gpiod`, perhaps an -L flag is missing?
This happens since we only support 'static' LIB-KIND currently. Remove
the same to allow others to work too.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Viresh Kumar [Tue, 24 Jan 2023 08:23:46 +0000 (13:53 +0530)]
bindings: rust: Align formatting to what's suggested by 'cargo fmt'
Align code to follow what 'cargo fmt' suggests.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 11 Jan 2023 12:30:24 +0000 (13:30 +0100)]
README: update for libgpiod v2
Certain parts of the README file still refer to concepts removed from
libgpiod v2. Update whatever needs updating.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 13 Jan 2023 13:51:09 +0000 (14:51 +0100)]
bindings: rust: make request_config optional in Chip.request_lines()
Request config is not necessary to request lines. In C API we accept
a NULL pointer, in C++ it's not necessary to assign a request_config
to the request builder, in Python the consumer and event buffer size
arguments are optional. Let's make rust bindings consistent and not
require the request config to be always present. Convert the argument
in request_lines to Option and update the rest of the code.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:16:38 +0000 (19:16 +0100)]
tests: add a helper for reading back line settings from line config
Add a helper for getting line settings from line config that allows to
shrink the test code a bit.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:15:12 +0000 (19:15 +0100)]
tests: fix the line config reset test case
We're using testing wrong variables in the reset_config test case. We
should be checking the retrieved0 settings which are read back from
the line config object.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 13 Jan 2023 08:52:24 +0000 (09:52 +0100)]
bindings: cxx: allow to copy line_settings
Implement the copy operator for line_settings. We have a copy() method
for line settings in C API while in C++ it's useful to copy line_settings
returned in an std::map from line_config.get_line_settings().
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:36:32 +0000 (19:36 +0100)]
bindings: cxx: prepend all C symbols with the scope resolution operator
We explicitly resolve all global C symbols from libgpiod to the top-level
namespace. Fix it wherever its missing (mostly for C enum types).
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 11 Jan 2023 16:24:44 +0000 (17:24 +0100)]
doc: update docs for libgpiod v2
Update docs in gpiod.h wherever they're outdated or make incorrect
statements. While at it: fix formatting in some places.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 11 Jan 2023 13:13:21 +0000 (14:13 +0100)]
build: unify the coding style of source files lists in Makefiles
Use the most common and readable convention for listing source files
in Makefiles wherever it's not consistent yet.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 11 Jan 2023 13:08:40 +0000 (14:08 +0100)]
tests: avoid shadowing local variables with common names in macros
The name 'ret' if very common for local variables so change it to _ret
in test helper macros to avoid potential shadowing.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Bartosz Golaszewski [Mon, 16 Jan 2023 15:15:25 +0000 (16:15 +0100)]
build: update the required python version
We don't guarantee libgpiod python bindings to work with anything older
than python 3.9. Let's fix the required version in configure.ac.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 16 Jan 2023 15:08:21 +0000 (16:08 +0100)]
build: drop unused python-related bits from configure.ac
We no longer use autotools to build python bindings. We should still
check the interpreter but let's not set any automake variables.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Joerg Faschingbauer [Wed, 18 Jan 2023 09:11:45 +0000 (10:11 +0100)]
bindings: python: fix out-of-tree build
Makefile.am delegates the build of the python extension to its
setup.py file, which references the extension .c files relative to the
source dir. This makes it impossible to build in a directory that is
different from the source directory (for example, for PC and ARM but
from the same source).
* Invoke setup.py from $(srcdir)
* Modify setup.py to pick up .c files relative from setup.py's own
directory.
Signed-off-by: Joerg Faschingbauer <jf@faschingbauer.co.at>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 17 Jan 2023 08:24:44 +0000 (09:24 +0100)]
Revert "configure: replace deprecated macro"
This reverts commit
b353e7b1b65450d04bcbc72e42efc13b04d98a00.
AC_CHECK_INCLUDES_DEFAULT is only available in autoconf v2.70 while we
want to keep supporting v2.69.
Reported-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>