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

23 Commits

Author SHA1 Message Date
Bartosz Golaszewski
76ecc337c5 licensing: relicense C++ bindings under LGPL-2.1-or-later
Commit ea84f882d5 ("licensing: relicense C++ library code under
LGPL-3.0-or-later") changed the license of C++ bindings in order to
solve potential issues with code generated from templates[1], default
implementations, etc. However this change makes the bindings less
attractive to projects that have strict licensing restrictions and avoid
GPL-3.0 code[2].

After talking to Grant Likely I decided that the best approach is to
make the bindings available under LGPL-v2.1-or-later and simply let the
end user decide which version's text to apply.

While at it: tweak the README to also mention that examples are provided
under GPL-2.0-or-later.

Link: [1] https://www.spinics.net/lists/linux-gpio/msg46605.html
Link: [2] https://github.com/brgl/libgpiod/issues/72
Suggested-by: Walter Lozano <walter.lozano@collabora.com>
Suggested-by: Grant Likely <grant.likely@linaro.org>
Acked-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Kevin Hilman <khilman@baylibre.com>
Acked-by: Grant Likely <grant.likely@linaro.org>
Link: https://lore.kernel.org/r/20240416212141.6683-2-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-04-22 14:04:19 +02:00
Bartosz Golaszewski
b7ba732e6a treewide: libgpiod v2 implementation
This commit is the result of a squash of all the commits created during
the development of libgpiod v2. This is done to preserve bisectability
of the git tree. It contains significant re-writes of the core C library
as well as C++ and python bindings. The tools have been adjusted to work
with the new API but have not undergone significant changes yet.

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

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

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

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2021-03-18 09:34:15 +01:00
Bartosz Golaszewski
ea84f882d5 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>
2021-02-18 17:42:16 +01:00
Bartosz Golaszewski
dfb707c255 licensing: make the project REUSE-compliant
In order to make the licensing situation of libgpiod clear and enable
easy reusing of the code, let's make all the files in the repository
compliant with the REUSE v3.0 specification.

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

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

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-12-14 15:57:15 +01:00
Bartosz Golaszewski
e6f20c261d 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>
2020-12-14 15:57:07 +01:00
Bartosz Golaszewski
8496158bc0 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>
2020-12-14 15:57:05 +01:00
Bartosz Golaszewski
44ed2c098e 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>
2020-12-14 15:56:46 +01:00
Bartosz Golaszewski
da8b32402e 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>
2020-11-04 14:45:05 +01:00
David Kozub
1fd1e271b7 bindings: cxx: remove superfluous std::move
There is no need to use std::move on an r-value (e.g.
std::move(gpiod::chip())). Similarly, there is no need to use std::move
for returning a local variable as in:

T foo()
{
    U local;
    return std::move(local);
}

Not only it doesn't help, it actually inhibits named return value
optimization.

See e.g. https://isocpp.org/blog/2013/02/no-really-moving-a-return-value-is-easy-stackoverflow

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-03-29 10:41:24 +01:00
Bartosz Golaszewski
937ded4dbc treewide: order includes alphabetically
Unify the header includes by ordering them alphabetically and always
having local headers in a second group below the global ones (separated
by a newline).

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-21 09:38:57 +01:00
Bartosz Golaszewski
6610e53048 bindings: cxx: fix the return value of line_bulk::find_lines()
We should return an invalid line_bulk object if we failed to look up at
least one line from the provided list of names.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 12:01:13 +02:00
Bartosz Golaszewski
0a9faf3abf license: use C++-style comments for SPDX headers in source files
Follow the linux kernel licensing style and only use C-style comments
in C headers.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-04-04 13:19:05 +02:00
Bartosz Golaszewski
4fef448baa bindings: cxx: use SPDX license identifier
Use the SPDX license identifier for LGPLv2.1 or later in C++ bindings
directory.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-03-04 12:09:27 +01:00
Bartosz Golaszewski
42038068fc bindings: cxx: rename line_bulk::add() to line_bulk::append()
This routine adds the line at the end of the internal list of lines.
Rename it to append() in case we ever want to introduce prepend().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-27 13:41:46 +01:00
Bartosz Golaszewski
860b3b6f15 bindings: cxx: don't check the chip's label and name for empty strings
The core library guarantees that a GPIO chip will have a name and
a label. No need to check if the returned strings are empty.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-25 14:18:56 +01:00
Bartosz Golaszewski
67376bd706 bindings: cxx: provide chip::get_all_lines()
This is a C++ method for getting all lines exposed by a GPIO chip. It
corresponds with the helper function recently added to the C API.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-22 21:31:56 +01:00
Bartosz Golaszewski
8078a4a2ad bindings: implement C++ bindings
Wrap the C API in a set of C++ classes which allow to use all libgpiod
functionalities in an object-oriented manner.

Include simplified reimplementations of gpio-tools and a set of
tests/examples showing how to use the C++ interface.

The C++ API is fully documented in doxygen.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-19 09:45:45 +01:00