1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-25 12:39:18 +03:00
Commit Graph

31 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
66af3e1af8 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>
2022-12-09 10:16:11 +01:00
Bartosz Golaszewski
b7ba732e6a treewide: libgpiod v2 implementation
This commit is the result of a squash of all the commits created during
the development of libgpiod v2. This is done to preserve bisectability
of the git tree. It contains significant re-writes of the core C library
as well as C++ and python bindings. The tools have been adjusted to work
with the new API but have not undergone significant changes yet.

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

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
[Ben: fix format specifier for uint64_t]
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
[Viresh: Fix ioctl number for gpiod_line_request_reconfigure_lines()]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[Kent: bug fixes, improvements, better pointer contracts, type strictness]
Signed-off-by: Kent Gibson <warthog618@gmail.com>
2022-10-31 11:15:14 +01:00
Bartosz Golaszewski
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
dd8f3a47ca 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>
2021-03-18 09:34:15 +01:00
Bartosz Golaszewski
f6f918d6cc 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>
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
Jan Kundrát
3e47f2ba98 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>
2021-02-03 13:30:22 +01:00
Bartosz Golaszewski
28890f7623 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>
2021-01-19 10:49:36 +01:00
Bartosz Golaszewski
555b0cdcd5 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>
2021-01-19 10:49:36 +01:00
Bartosz Golaszewski
b929f278cf 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>
2021-01-19 10:49:36 +01:00
Bartosz Golaszewski
aee8a15625 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>
2021-01-19 10:49:15 +01:00
Bartosz Golaszewski
d2a70828f8 treewide: simplify the active-low line property
Unlike line direction - where input and output modes are equal, no signal
inversion (active-high) is the natural state of the line while active-low
is less likely. Let's drop the ACTIVE_STATE enum treewide and provide a
boolean property for lines - is_active_low() - to reflect that fact. This
function returning false means the line is "active-high".

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-12-17 18:04:17 +01:00
Bartosz Golaszewski
fa1fe46653 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>
2020-12-14 15:56:57 +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
Kent Gibson
2fd82f7048 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: 8078a4a2ad ("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>
2020-09-14 10:30:10 +02:00
Bartosz Golaszewski
c5c00ef3bc bindings: cxx: provide a method for reading multiple line events
Add a new method to gpiod::line class allowing to read up to 16 line
events at once.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-01-02 18:30:53 +01:00
Kent Gibson
d3fa0ad31d bindings: cxx: add support for SET_CONFIG
Add methods to support setting line configuration.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-12-10 11:48:54 +01:00
Kent Gibson
98419c968a bindings: cxx: add support for bias flags
Add support for bias flags in line requests and returning the line bias
setting via a bias accessor.

Based on initial work by Drew Fustini <drew@pdp7.com>.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-12-09 17:47:04 +01:00
Kent Gibson
bf7ce9f632 bindings: cxx: drop noexcept from direction() and active_state()
Both line::direction() and line::active_state() methods can throw and
so should not be declared as noexcept.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-11-18 15:27:21 +01:00
Bartosz Golaszewski
0297ef69af bindings: cxx: provide line::update()
The C++ bindings are missing the functionality provided by the core C
library's gpiod_line_update(). Extend the line class with the update()
method that allows to re-read the line information from the kernel.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-09-14 15:27:46 +02:00
Bartosz Golaszewski
d001dde47c bindings: cxx: add a missing throw to line::event_get_fd()
If the call to gpiod_line_event_get_fd() fails, we're not actually
throwing the exception - we're only creating it on stack. Add the
missing throw keyword.

Fixes: 8078a4a2ad ("bindings: implement C++ bindings")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-08-07 10:54:30 +02:00
David Kozub
a02f790d54 bindings: cxx: make operator bool() explicit
A non-explicit operator bool() is dangerous: It allows unwanted
conversion to integral types:

gpiod::chip c;
int i = c;

This is a trivial example, but more insidious effects are possible,
e.g. with std::set<gpiod::chip>, which would use the operator bool()
to implement element comparison, thus turning such set into a set that
has at most 2 elements: An invalid (false) element and just 1 valid
element:

std::set<gpiod::chip> s;
s.emplace();
s.emplace("/dev/gpiochip0");
s.emplace("/dev/gpiochip1");
// s.size() is still 2 even if both chips were opened!

Making the operator explicit disables this.

See e.g.
https://en.cppreference.com/w/cpp/language/implicit_conversion#The_safe_bool_problem
for more info on this.

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-03-29 10:43:45 +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
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
ff56d075ac bindings: cxx: rename line and chip iterator classes
Use a shorter name for code brevity. Change chip_iterator to chip_iter
and line_iterator to line_iter.

Rename the helper functions as well.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-21 13:41:31 +01:00
Bartosz Golaszewski
10a156752b bindings: cxx: provide methods for releasing requested lines
Add release methods to line and line_bulk classes. This allows to
release requested lines without having to destroy the owning objects.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-19 11:01:01 +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