qemu-gpiodev/libgpiod.git
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>
4 years agotreewide: kill find_lines()
Bartosz Golaszewski [Wed, 2 Dec 2020 12:47:43 +0000 (13:47 +0100)]
treewide: kill find_lines()

GPIO line names are not unique. Looking up multiple lines by names would
require us to return a list of matching lines for every name. We're
simplifying the library API so drop this interface treewide.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agotreewide: kill global line lookup
Bartosz Golaszewski [Wed, 2 Dec 2020 11:10:24 +0000 (12:10 +0100)]
treewide: kill global line lookup

Global line lookup doesn't really work correctly because GPIO line names
are not unique. We'd have to return a list of matching lines. Also: not
all chips may be accessible by user in which case the chip iterator will
fail. We'll soon be removing chip iterators entirely so for now drop the
global line lookup and let users iterate over chips themselves.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agocore: kill gpiod_line_get()
Bartosz Golaszewski [Wed, 2 Dec 2020 09:58:05 +0000 (10:58 +0100)]
core: kill gpiod_line_get()

We're dropping all interfaces for global line lookup and accessing. Lines
should be always accessed via their owning chip object.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agocore: kill gpiod_line_close_chip()
Bartosz Golaszewski [Wed, 2 Dec 2020 09:56:46 +0000 (10:56 +0100)]
core: kill gpiod_line_close_chip()

This helper was supposed to be used together with global line lookup
which will soon be removed so drop this one too.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agoAPI: move gpiod_line_get_chip() to line attributes section
Bartosz Golaszewski [Tue, 1 Dec 2020 15:06:41 +0000 (16:06 +0100)]
API: move gpiod_line_get_chip() to line attributes section

This routine should logically be part of line attributes. Move it out
of the misc line section.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agotreewide: kill opening chips by label
Bartosz Golaszewski [Thu, 26 Nov 2020 11:48:08 +0000 (12:48 +0100)]
treewide: kill opening chips by label

Chip labels are not unique - opening chips by label may lead to errors
or to ignoring chips with duplicate labels. Users can easily implement
chip lookup by label themselves so remove this part from the core library
and all bindings.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agocore: drop line iterators
Bartosz Golaszewski [Wed, 25 Nov 2020 10:45:55 +0000 (11:45 +0100)]
core: drop line iterators

Hand-crafted iterators don't make much sense in C and impose an
additional layer of memory allocation and resource releasing. Remove
the line iterators from the core C library.

We're leaving the iterators where they make sense: in C++ and Python
bindings but we convert them to using other means of keeping track of
lines.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agobulk: drop the limit on the max number of lines
Bartosz Golaszewski [Tue, 24 Nov 2020 15:24:08 +0000 (16:24 +0100)]
bulk: drop the limit on the max number of lines

The limit of 64 lines max per bulk object is wrong. We may want to
retrieve all lines from a chip exporting more than 64. We'll be reducing
the role of bulk objects soon so drop this limit now.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agocore: export gpiod_is_gpiochip_device()
Bartosz Golaszewski [Tue, 24 Nov 2020 14:36:47 +0000 (15:36 +0100)]
core: export gpiod_is_gpiochip_device()

We'll be dropping chip iterators treewide. Instead we'll encourage
scanning /dev for GPIO chip devices. Exporting this function allows
users to easily check if given file represents a GPIO chip character
device.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agobuild: drop the message about tests having been built successfully
Bartosz Golaszewski [Wed, 9 Dec 2020 15:30:59 +0000 (16:30 +0100)]
build: drop the message about tests having been built successfully

This is a leftover from early times. We now have multiple different
test suites and none prints such a message. Drop it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agobindings: cxx: check for error from gpiod_line_bulk_new()
Bartosz Golaszewski [Thu, 3 Dec 2020 12:55:00 +0000 (13:55 +0100)]
bindings: cxx: check for error from gpiod_line_bulk_new()

We call gpiod_line_bulk_new() in C++ bindings but never check its return
value. This function can fail so add a private method to line_bulk that
calls it and throws an exception if it returns NULL.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
4 years agocore: improve a comment in is_gpiochip_cdev()
Bartosz Golaszewski [Tue, 24 Nov 2020 14:41:50 +0000 (15:41 +0100)]
core: improve a comment in is_gpiochip_cdev()

Drop the repetition in the comment in is_gpiochip_cdev() to make it
sound better.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agodoc: remove any referencess to context-less API
Bartosz Golaszewski [Tue, 24 Nov 2020 10:25:41 +0000 (11:25 +0100)]
doc: remove any referencess to context-less API

Context-less API has been removed. Remove any leftover bits from the
documentation.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: remove unused forward declaration
Bartosz Golaszewski [Fri, 13 Nov 2020 13:48:17 +0000 (14:48 +0100)]
core: remove unused forward declaration

struct gpiod_line_bulk_iter never made it into the API and its forward
declaration is a leftover. Remove it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: unexport GPIOD_UNUSED
Bartosz Golaszewski [Fri, 13 Nov 2020 13:20:12 +0000 (14:20 +0100)]
treewide: unexport GPIOD_UNUSED

GPIOD_UNUSED symbol isn't used in any public part of the library. We
can unexport it and put it into tools-common.h for use by tools only.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agoctxless: drop all context-less interfaces
Bartosz Golaszewski [Thu, 5 Nov 2020 17:21:46 +0000 (18:21 +0100)]
ctxless: drop all context-less interfaces

The context-less family of functions seems to be largely unused.
Drop this part of the codebase and convert tools to using the regular
low-level API.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: provide gpiod_line_bulk_reset()
Bartosz Golaszewski [Tue, 10 Nov 2020 18:12:11 +0000 (19:12 +0100)]
core: provide gpiod_line_bulk_reset()

Provide a helper function that allows to reset an existing bulk object.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: rework struct gpiod_line_bulk
Bartosz Golaszewski [Tue, 20 Oct 2020 12:56:10 +0000 (12:56 +0000)]
treewide: rework struct gpiod_line_bulk

Current implementation of struct gpiod_line_bulk uses stack memory
excessively. The structure is big: it's an array 64 pointers + 4 bytes
size. That amounts to 260 bytes on 32-bit and 516 bytes on 64-bit
architectures respectively. It's also used everywhere as all functions
dealing with single lines eventually end up calling bulk counterparts.

The rework addresses it by making the bulk structure opaque and
providing appropriate interfaces for library users while retaining a way
for internal users to allocate single line bulks on the stack.

The macro-based loop has been removed. In its place we provide a function
iterating over all lines held by a bulk and calling the provided callback
function for each line.

Since bulk operations can now fail, a bunch of test-cases has been added
to cover the relevant code.

While at it: using the word offset both when referring to line's HW
offset in a chip as well as the offset in a bulk leads to confusion.
This patch renames the bulk offset to index.

Some additional improvements to the patch by:
  Kent Gibson <warthog618@gmail.com>

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: cxx: demote the line's parent chip reference to a weak_ptr
Bartosz Golaszewski [Thu, 15 Oct 2020 14:46:39 +0000 (16:46 +0200)]
bindings: cxx: demote the line's parent chip reference to a weak_ptr

Currently the line object has the power to control the parent chip's
lifetime because it stores a hard reference (in the form of a shared
pointer) to the underlying struct gpiod_chip. This is wrong from the
relationship point-of-view - the chip should control the exposed lines,
not the other way around.

Demote the parent reference to a weak_ptr. Introduce a sub-class that
allows line and line_bulk objects to lock the chip by temporarily
converting this weak_ptr to a full shared_ptr - this way we don't risk
dropping the last reference to the parent chip when the line is calling
the underlying library functions. Chip deleted during that time will
expire right after the concerned line method returns.

This requires an API change - the global find_line() function now
returns a <line, chip> pair so that the caller gets the chance to grab
the chip's reference.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotreewide: make linux v5.10 a hard requirement for libgpiod
Bartosz Golaszewski [Mon, 26 Oct 2020 10:12:16 +0000 (11:12 +0100)]
treewide: make linux v5.10 a hard requirement for libgpiod

The library now uses v2 of the GPIO uAPI. The new user interface is
scheduled for release as part of linux v5.10. Linux v5.10-rc1 is now
tagged so make v5.10 headers a requirement for the build and update
all tests to check for the correct version.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agoMerge branch 'for-linux-v5.10-rc1'
Bartosz Golaszewski [Mon, 26 Oct 2020 10:08:29 +0000 (11:08 +0100)]
Merge branch 'for-linux-v5.10-rc1'

4 years agodoc: fix typo in gpiod_line_request_bulk() documentation
Marc Ferland [Thu, 15 Oct 2020 17:52:35 +0000 (13:52 -0400)]
doc: fix typo in gpiod_line_request_bulk() documentation

Remove the stray 'the' from the doc.

Signed-off-by: Marc Ferland <marc.ferland@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agodoc: fix typo in gpiod_line_request_bulk() documentation
Kent Gibson [Thu, 15 Oct 2020 22:47:11 +0000 (06:47 +0800)]
doc: fix typo in gpiod_line_request_bulk() documentation

Replace 'prodivided' with 'provided'.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agoTODO: add a task for replacing chrono::duration with chrono::time_point
Bartosz Golaszewski [Thu, 15 Oct 2020 08:45:27 +0000 (10:45 +0200)]
TODO: add a task for replacing chrono::duration with chrono::time_point

We should store event timestamps in C++ bindings in
::std::chrono::time_point objects rather than in
::std::chrono::duration. Add a task for that to TODO.

Suggested-by: Helmut Grohne <helmut.grohne@intenta.de>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotests: add check of event offset to wait_multiple
Kent Gibson [Wed, 14 Oct 2020 03:47:58 +0000 (11:47 +0800)]
tests: add check of event offset to wait_multiple

The offset field is added for uAPI v2, so extend the test to check that
the value returned is correct.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: Basic port to uAPI v2
Kent Gibson [Wed, 14 Oct 2020 11:30:52 +0000 (19:30 +0800)]
core: Basic port to uAPI v2

Port existing implementation from GPIO uAPI v1 to v2.
The libgpiod external interface remains unchanged, only the internal
implementation switches from uAPI v1 to v2.

This is a minimal port - uAPI v2 features are not used, only the
uAPI v1 calls are switched to the v2 equivalent.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotests: create mismatch between chip and bulk offsets in wait_multiple
Kent Gibson [Wed, 14 Oct 2020 03:47:57 +0000 (11:47 +0800)]
tests: create mismatch between chip and bulk offsets in wait_multiple

Create a mismatch between the chip offsets and the bulk offsets to ensure
the implementation is not dependent on them matching.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agoTODO: remove the task for removing deprecated interfaces
Bartosz Golaszewski [Wed, 14 Oct 2020 08:40:27 +0000 (10:40 +0200)]
TODO: remove the task for removing deprecated interfaces

We no longer have any deprecated symbols in libgpiod. This task is
now complete.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: remove deprecated functions
Bartosz Golaszewski [Wed, 14 Oct 2020 08:26:54 +0000 (10:26 +0200)]
core: remove deprecated functions

Drop all deprecated interfaces now that we're allowed to change the API
for libgpiod v2.0.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: python: remove gpiod.version_string()
Bartosz Golaszewski [Wed, 14 Oct 2020 08:08:15 +0000 (10:08 +0200)]
bindings: python: remove gpiod.version_string()

We support the standard __version__ module attribute. There's no need
to duplicate this functionality in the form of the version_string()
function.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: cxx: tests: rename freq parameter to period_ms
Kent Gibson [Wed, 14 Oct 2020 03:45:50 +0000 (11:45 +0800)]
bindings: cxx: tests: rename freq parameter to period_ms

The freq field of struct gpiod_test_event_thread is actually used as a
period measured in milliseconds, so rename it to period_ms in the struct
and wherever it is used as a function parameter.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobuild: modernize configure.ac
Bartosz Golaszewski [Tue, 13 Oct 2020 12:58:23 +0000 (14:58 +0200)]
build: modernize configure.ac

Replace deprecated macros with recommended counterparts. Require a more
recent autoconf version. Add missing brackets.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotests: break tests if line requests fail
Bartosz Golaszewski [Mon, 12 Oct 2020 14:52:38 +0000 (16:52 +0200)]
tests: break tests if line requests fail

In many test-cases we read/set values or try to poll for events after
a failed line request. Some tests even segfault because they don't check
returned values for NULL etc.

Bail out of test cases if a line request failed.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: python: fix Line.request() crashing
Jiri Benc [Tue, 6 Oct 2020 17:17:08 +0000 (19:17 +0200)]
bindings: python: fix Line.request() crashing

On an attempt to call the 'request' method of a Line object, the program
crashes with this exception:

> SystemError: ../Objects/dictobject.c:2606: bad argument to internal function
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> SystemError: <class 'gpiod.LineBulk'> returned a result with an error set

The problem is that keyword args are NULL (rather than an empty dict) if
they are not present. However, PyDict_Size sets an exception if it gets
NULL.

Fixes: 02a3d0a2ab5e ("bindings: python: fix segfault when calling Line.request()")
Signed-off-by: Jiri Benc <jbenc@upir.cz>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: python: tests: add a test-case exposing a bug in Line.request()
Bartosz Golaszewski [Fri, 9 Oct 2020 12:22:09 +0000 (14:22 +0200)]
bindings: python: tests: add a test-case exposing a bug in Line.request()

Calling Line.request() with no keyword arguments leads to an exception
being raised by PyDict_Size(). Add a test-case exposing this bug. It
will be fixed in the subsequent commit.

Reported-by: Jiri Benc <jbenc@upir.cz>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: python: fix incorrect object size
Jiri Benc [Tue, 6 Oct 2020 17:16:02 +0000 (19:16 +0200)]
bindings: python: fix incorrect object size

tp_basicsize is the size of the allocated object, not of the class.

Fixes: 96c524c4951c ("bindings: implement python bindings")
Signed-off-by: Jiri Benc <jbenc@upir.cz>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agolibgpiod: start v2.0 development cycle
Bartosz Golaszewski [Fri, 2 Oct 2020 08:22:06 +0000 (10:22 +0200)]
libgpiod: start v2.0 development cycle

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agolibgpiod v1.6
Bartosz Golaszewski [Thu, 1 Oct 2020 10:45:45 +0000 (12:45 +0200)]
libgpiod v1.6

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agoNEWS: updates for v1.6
Bartosz Golaszewski [Thu, 1 Oct 2020 10:00:21 +0000 (12:00 +0200)]
NEWS: updates for v1.6

Add release notes for libgpiod v1.6.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agodoc: improve the part about non-unique line names
Bartosz Golaszewski [Tue, 15 Sep 2020 09:48:52 +0000 (11:48 +0200)]
doc: improve the part about non-unique line names

The current comments for functions related to line lookups state that
"lines are not unique" but they're really supposed to say "line names
are not unqiue".

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agocore: fix reading subset of available events
Kent Gibson [Sat, 12 Sep 2020 08:11:05 +0000 (16:11 +0800)]
core: fix reading subset of available events

Only read the requested number of events from the kernel rather than
reading up to 16 and quietly discarding any surplus.

The previous behavour is particularly bad for reading single events as
userspace must read the events as quickly as they arrive, effectively
negating the presence of the kernel event kfifo.

Fixes: 44921ecc9a00 ("core: provide functions for reading multiple line events at once")
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agotests: event: extend testing to cover reading a subset of available events
Kent Gibson [Sat, 12 Sep 2020 08:11:04 +0000 (16:11 +0800)]
tests: event: extend testing to cover reading a subset of available events

Add tests for gpiod_line_event_read(), including reading multiple
entries from the kernel event kfifo, and extend the existing
read_multiple_event tests to read a subset of the available events as
well as all the available events.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agobindings: cxx: fix event timestamp calculation for 32bit
Kent Gibson [Wed, 9 Sep 2020 01:40:03 +0000 (09:40 +0800)]
bindings: cxx: fix event timestamp calculation for 32bit

Use appropriate C++ chrono library functions to convert the event
timestamp from a struct timespec to ::std::chrono::nanoseconds to
ensure correct conversion independent of platform.

Fixes: 8078a4a2ad90 ("bindings: implement C++ bindings")
Reported-by: Florian Evers <florian-evers@gmx.de>
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agodoc: add @file to headers
Alexander Stein [Sat, 8 Aug 2020 09:59:44 +0000 (11:59 +0200)]
doc: add @file to headers

It's necessary to have a file reference linked in the file list.
Also: strip the top_srcdir from paths

Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agodoc: remove obsolete PERL_PATH
Alexander Stein [Sat, 8 Aug 2020 09:59:43 +0000 (11:59 +0200)]
doc: remove obsolete PERL_PATH

This fixes the following warning:

warning: Tag 'PERL_PATH' at line 110 of file 'Doxyfile' has become obsolete.

Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agodoc: fix doxygen warning
Alexander Stein [Sat, 8 Aug 2020 09:59:42 +0000 (11:59 +0200)]
doc: fix doxygen warning

This fixes the following warning:

warning: argument 'a4wide' for option PAPER_TYPE is not a valid enum value
Using the default: a4!

Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
4 years agodoc: use autotoolized Doxyfile
Alexander Stein [Sat, 8 Aug 2020 09:59:41 +0000 (11:59 +0200)]
doc: use autotoolized Doxyfile

This has several advantages:
* More simplified Makefile.am
* Actually used doxygen config is available as a file
* Building doc out-of-tree is possible

Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
[Bartosz: add a dependency on Doxygen to the doc target in Makefile]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>