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

24 Commits

Author SHA1 Message Date
Bartosz Golaszewski
8d0cae535d tools: display C API *and* libgpiod package version for '-v'
With the recent changes to the versioning scheme and the disassociation
of the core C API from the libgpiod package version, it now makes sense
to display both in the output of '<tool> --version' for all gpio-tools.

Acked-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250903-api-version-detach-v1-5-027ca5928518@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-09 10:24:00 +02:00
Kent Gibson
07c5c49862 tools: line wrap period help
The help for periods is overly long so wrap it to make it more
consistent with other help lines.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20241003020743.27194-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-03 10:50:15 +02:00
Bartosz Golaszewski
c34a572c53 tools: add minutes as a new supported time unit
Make it more convenient to specify longer time periods in gpio-tools by
introducing minutes as the new time unit.

Link: https://lore.kernel.org/r/20240423100452.32958-5-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-04-24 09:55:36 +02:00
Bartosz Golaszewski
e943b144d5 tools: allow longer time periods
We currently store time as microseconds in 32-bit integers and allow
seconds as the longest time unit when parsing command-line arguments
limiting the time period possible to specify when passing arguments such
as --hold-period to 35 minutes. Let's use 64-bit integers to vastly
increase that.

Use nanosleep() instead of usleep() to extend the possible sleep time
range.

Reported-by: Gunnar Thörnqvist <gunnar@igl.se>
Link: https://lore.kernel.org/r/20240423100452.32958-4-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-04-24 09:55:36 +02:00
Bartosz Golaszewski
8a864d6693 tools: replace alphasort() with versionsort()
Sorting chip names with alphasort() results in gpiochip2 coming after
gpiochip19 as it only find the lexicographic order of strings. Switching
to using versionsort() makes it look better and the order is more logical
with the numbering being taken into account.

Reviewed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-04 09:03:56 +02:00
Benjamin Li
5fa9cb92df tools: remove dependency on glibc program_invocation_[short_]name
Platforms like Bionic libc don't have program_invocation_[short_]name,
which is a GNU extension. It does have getprogname(), a BSD extension,
but rather than supporting multiple extensions let's just introduce
our own local helpers.

We derive the short name ourselves rather than calling basename(),
as the POSIX version takes char *, not const char *, and is thus
not guaranteed to avoid modifying its input. (The GNU version does
take const char * but we are avoiding extensions here.)

Signed-off-by: Benjamin Li <benl@squareup.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-03-12 14:23:34 +01:00
Bartosz Golaszewski
47cb0726dd tools: remove unneeded #include
We don't use dirname() nor basename() anymore so pulling in libgen.h
is not necessary.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-02-25 15:15:34 +01:00
Bartosz Golaszewski
164c60c506 tools: update the copyright date in the output of --version
Update the displayed years in the output of --version for all gpio-tools.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-02-08 14:25:17 +01:00
Bartosz Golaszewski
8da5c77a54 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>
2022-12-12 09:50:47 +01:00
Bartosz Golaszewski
4108b5180c 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>
2022-12-07 09:54:00 +01:00
Bartosz Golaszewski
1226f21745 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>
2022-12-07 09:52:06 +01:00
Bartosz Golaszewski
3fe7de7a65 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>
2022-12-07 09:45:06 +01:00
Bartosz Golaszewski
e065ef962a 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>
2022-12-07 09:42:02 +01:00
Kent Gibson
8ffb648928 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>
2022-11-21 21:07:17 +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
154e7c5a82 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>
2021-02-18 17:42:12 +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
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
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
9b6e6d2686 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>
2020-11-18 09:25:49 +01:00
Bartosz Golaszewski
2537745681 tools: unduplicate signalfd() code
The code creating the signal file descriptor in gpiomon and gpioset is
pretty much the same. Move it into tools-common.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-04-30 17:07:37 +02:00
Kent Gibson
2468967460 tools: add support for bias flags
Add support for bias flags to applicable tools - gpioget, gpioset, and
gpiomon.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-12-10 14:58:08 +01:00
Bartosz Golaszewski
8159d9b540 treewide: rearrange source directories
The src directory containing lib and tools is not necessary and will
actually cause problems if we tried to add a new component to src/
which would depend on libraries from the bindings directory because it
(bindings) already depends on src/lib.

Simplify the directory structure. Move lib and tools to the root source
directory and update all relevant files. That way we can specify the
exact build order of components from the top source Makefile.am.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-03-07 13:49:00 +01:00