Bartosz Golaszewski [Tue, 27 Feb 2018 12:48:08 +0000 (13:48 +0100)]
bindings: cxx: rename the C++ tests executable
Include the project's prefix in the executable name.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 27 Feb 2018 12:41:46 +0000 (13:41 +0100)]
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>
Bartosz Golaszewski [Sun, 25 Feb 2018 13:18:56 +0000 (14:18 +0100)]
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>
Bartosz Golaszewski [Thu, 22 Feb 2018 20:31:56 +0000 (21:31 +0100)]
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>
Bartosz Golaszewski [Thu, 22 Feb 2018 20:21:56 +0000 (21:21 +0100)]
tests: add a new cleanup macro
The most commonly used cleanup attribute is the one used for automatic
closing of GPIO chips. For brevity: hide the long TEST_CLEANUP(...)
invocation behind a shorter TEST_CLEANUP_CHIP macro.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 22 Feb 2018 20:15:43 +0000 (21:15 +0100)]
API: provide new line accessors
Add two new public functions that allow to retrieve multiple lines from
GPIO chips at once. Include test cases.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 21 Feb 2018 12:39:25 +0000 (13:39 +0100)]
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>
Bartosz Golaszewski [Wed, 21 Feb 2018 08:38:28 +0000 (09:38 +0100)]
bindings: cxx: add pkg-config support
This will allow to use PKG_CHECK_MODULES() for C++ bindings as well.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Clemens Gruber [Tue, 20 Feb 2018 16:57:32 +0000 (17:57 +0100)]
tools: move function attributes to the header file
The attributes must be located next to function declarations in the
header file. Otherwise, the NORETURN attribute seems to have no effect
and GCC emits several Wimplicit-fallthrough warnings when compiling
libgpiod. This patch fixes those warnings.
Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 19 Feb 2018 10:43:36 +0000 (11:43 +0100)]
bindings: cxx: allow empty default values in line_bulk::request()
The core library now supports NULL default values in output requests.
Update the C++ bindings and the relevant example.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 19 Feb 2018 10:32:41 +0000 (11:32 +0100)]
core: allow NULL default_vals for output requests
Explicitly allow default_vals to be NULL for output requests, in which
case the actual default values passed to the kernel are set to 0.
Add a test case that verifies that this works correctly.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 19 Feb 2018 10:12:32 +0000 (11:12 +0100)]
core: use gpiod_line_bulk_foreach_line_off() in line_request_values()
Use the provided helper macro instead of a manual for loop.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 19 Feb 2018 10:02:48 +0000 (11:02 +0100)]
bindings: cxx: new example
Add a test case to C++ examples demonstrating the manipulation of
several lines held by a line_bulk object.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 19 Feb 2018 10:01:01 +0000 (11:01 +0100)]
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>
Bartosz Golaszewski [Mon, 19 Feb 2018 09:51:17 +0000 (10:51 +0100)]
bindings: cxx: require default values for output requests
Require users to provide default values to line_bulk::request() when
direction is output.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 19 Feb 2018 09:40:35 +0000 (10:40 +0100)]
bindings: cxx: constify default_vals in line_bulk::request()
The default values should be passed by const reference similarly to
how it's done in line_bulk::set_values().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 19 Feb 2018 09:06:07 +0000 (10:06 +0100)]
API: start certain enums from 1
For enums describing direction & active state, event types etc. use 1
as the first value as it's easier to debug when all valid values are
different than in a zero-initialized data structure.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 25 Oct 2017 19:11:37 +0000 (21:11 +0200)]
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>
Bartosz Golaszewski [Mon, 12 Feb 2018 10:55:49 +0000 (11:55 +0100)]
tests: event: new test case
Verify that the active-low flag is respected when reading line values
from lines configured for events.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 8 Feb 2018 17:25:58 +0000 (18:25 +0100)]
dist: include Doxyfile in the release tarball
Doxyfile was missing from release tarballs. Include it.
Reported-by: SZ Lin <sz.lin@moxa.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 7 Feb 2018 15:38:26 +0000 (16:38 +0100)]
libgpiod: start v1.1 development cycle
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 7 Feb 2018 13:56:03 +0000 (14:56 +0100)]
libgpiod v1.0
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 7 Feb 2018 10:11:46 +0000 (11:11 +0100)]
NEWS: updates for v1.0
Add release notes for v1.0.
Also: the master branch doesn't contain the tags for bugfix releases so
documenting them in this branche's NEWS makes no sense.
Fold all the info about bugfix releases into the next minor release and
only keep major and minor releases in NEWS on the master branch. Bugfix
releases will only be documented in their respective minor branches
from now on.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 3 Feb 2018 15:06:47 +0000 (16:06 +0100)]
core: constify *values in gpiod_line_set_value_bulk()
The values in the array passed as argument to this routine are never
modified.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 29 Jan 2018 16:10:54 +0000 (17:10 +0100)]
doc: improve the doxygen description of default_val(s)
Users report being confused by the name 'default_val(s)' for function
parameters. Because it's in line with the kernel uAPI, we'll leave it
like this, but let's improve the documentation a bit by stating
explicitly that this parameter represents the initial values for
requested GPIO lines.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 26 Jan 2018 10:02:37 +0000 (11:02 +0100)]
doc: consistently break lines in @param's descriptions
When breaking the line in doxygen's @param descriptions, start the
next one after the param's name.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 26 Jan 2018 09:58:18 +0000 (10:58 +0100)]
doc: explicitly state that the ctxless event poll callback can be NULL
This is mentioned later in the text, but state it in the argument's
description too.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 26 Jan 2018 09:53:23 +0000 (10:53 +0100)]
doc: clarify that the high-level set value callback is optional
Users have reported it as confusing so make it clear.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 24 Jan 2018 11:36:14 +0000 (12:36 +0100)]
API: use gpiod_ctxless_ as prefix for the high-level API
As suggested by Linus Walleij: the word 'simple' is generally
subjective and the high-level routines provided by libgpiod are not
necessarily simple, but rather contextless, as they don't require any
resource managemend. Use 'gpiod_ctxless_' as prefix for all high-level
symbols.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 24 Jan 2018 11:19:03 +0000 (12:19 +0100)]
gitignore: add libgpiod.pc
Add the automatically generated libgpiod.pc to .gitignore.
Fixes: 819e2f5ee3e6 ("build: add pkg-config support")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Clemens Gruber [Mon, 22 Jan 2018 16:12:12 +0000 (17:12 +0100)]
build: add pkg-config support
Create a libgpiod.pc file for pkg-config. Allows to use
PKG_CHECK_MODULES([gpiod], [libgpiod >= 1.0],,) in other
autoconf-based projects.
Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Clemens Gruber [Mon, 22 Jan 2018 16:12:13 +0000 (17:12 +0100)]
gpiomon: initialize the active low variable
The variable active_low is not initialized, so the value is undefined
and if the -l argument is not passed, the undefined value remains. Fix
it by initializing it to false.
Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 22 Jan 2018 09:23:55 +0000 (10:23 +0100)]
tests: kill test_free_str()
This function is no longer used - all strings are created using
test_build_str().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 19 Jan 2018 10:18:51 +0000 (11:18 +0100)]
all: fix various coding style issues
Make the entire code base more consistent with the linux kernel
coding style.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 13 Jan 2018 22:16:31 +0000 (23:16 +0100)]
all: update the copyright notice
All these files have been updated in 2018.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 10 Jan 2018 00:29:10 +0000 (01:29 +0100)]
all: modify the license preamble in files
This project contains both a library and executables so it's better to
use an umbrella term "This program ..." than "This library ..." in all
the source files.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 10 Jan 2018 00:00:15 +0000 (01:00 +0100)]
doc: minor documentation tweaks
Fix/tweak the in-code API documentation in a couple places.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 9 Jan 2018 23:55:53 +0000 (00:55 +0100)]
core: remove an unnecessary else
This else is not useful as all other if (else)'s in this block return.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
SZ Lin [Fri, 1 Dec 2017 14:17:40 +0000 (22:17 +0800)]
all: make license type consistent between source files and COPYING file
The license type of COPYING file is "LGPL-2.1+", but it is declared
as "LGPL-2.1" in the preamble of source files.
This patch fixes license type inconsistency issue in each source file.
Signed-off-by: SZ Lin <sz.lin@moxa.com>
[Bartosz: tweaked the commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 15 Nov 2017 13:39:58 +0000 (14:39 +0100)]
core: don't allow open-source and open-drain flags at the same time
If the hardware actually allowed it, the electrical result would be
disastrous. This has only recently been fixed in the kernel, so add
a relevant check to the library as well.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 17 Nov 2017 16:49:37 +0000 (17:49 +0100)]
core: change the prefix for line request flags
Make it clear that these are flags and that more than one can be used
simultaneously.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 17 Nov 2017 16:42:16 +0000 (17:42 +0100)]
core: coding style tweak
Remove one tab from the GPIOD_LINE_BULK_MAX_LINES definition.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 17 Nov 2017 14:16:55 +0000 (15:16 +0100)]
tests: line: remove unnecessary line releases
We don't need to release lines manually - line resources are managed
by GPIO chip objects. Remove the calls to release functions wherever
they don't make sense for any subsequent test code.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 17 Nov 2017 14:03:14 +0000 (15:03 +0100)]
core: improve error handling
Rework the way we verify that line bulk objects are consistent: split
the verify_line_bulk() function into sub-routines, make the names more
self-explanatory and add other minor fixes & tweaks.
Improve the consistency of errno codes: set errno to EPERM if the line
for which gpiod_line_event_get_fd() is called is not configured for
event monitoring.
We were already testing that line requests fail if we pass them a line
bulk containing lines from different chips, but add an analogous test
for gpiod_line_get_value_bulk().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 14 Nov 2017 12:37:01 +0000 (13:37 +0100)]
tests: make the devpath check less strict
We plan to change the way gpio-mockup platform devices are registered
in the kernel. This change will add an ID to the gpio-mockup platform
device name and will result in the devpath being changed to
'/devices/platform/gpio-mockup.X/gpiochip'.
When checking the devpath during the test case setup, it's enough to
verify that we got an event from the correct platform device - we
don't need to check the gpiochip name. Shorten the string against
which we check to skip whatever comes after the platform device name.
While we're at it: move the string definition into the function which
is the only user.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 5 Nov 2017 20:04:52 +0000 (21:04 +0100)]
iter: fix a crash occurring if no GPIO chips are present
If no GPIO chips are present in the system, we bail out from
gpiod_chip_iter_new() before allocating the chips array. Add a check
in gpiod_chip_iter_free() to avoid calling free() for iter->chips in
that case.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 5 Nov 2017 19:57:25 +0000 (20:57 +0100)]
iter: rework line iterator API
The changes roughly correspond with what we did for chip iterators.
Only perform operations that can fail in gpiod_line_iter_new(), so
that there's no need to check for errors after every call to
gpiod_line_iter_next().
Make gpiod_line_iter an opaque pointer and provide 'new' and 'free'
functions.
Update all users and relevant test cases. Extend the test API with
a new cleanup function.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 5 Nov 2017 19:23:42 +0000 (20:23 +0100)]
doc: update the descriptions for chip iterators
The 'next' routines for chip iterators can no longer fail. Update
the docs accordingly. Also: turn the extended description into a note
for the noclose variant.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 5 Nov 2017 13:31:46 +0000 (14:31 +0100)]
tests: use test_build_str() in test cases
Shrink the test code by using the newly provided helper function for
building custom strings wherever asprintf() was used before.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 5 Nov 2017 13:21:54 +0000 (14:21 +0100)]
tests: provide test_build_str()
Many test cases use asprintf() to build custom strings. This routine
can fail and the return value is tested using the TEST_ASSERT macros
but this is not the subject of the actual testing. The test case must
also free the string allocated by this function.
As a simplification: pull this functionality into the testing
framework so that we can build custom strings without keeping track of
resources. The new function will also make the whole test suite die if
the internal asprintf() call fails.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 4 Nov 2017 21:39:36 +0000 (22:39 +0100)]
iter: rework chip iterators
We can significantly simplify the chip iterators by performing all
actions that can yield an error in gpiod_chip_iter_new(). Instead of
opening each subsequent chip in gpiod_chip_iter_next(), open them all
in the new function and make next just return an active handle.
Fix relevant test cases and macros, remove related routines that are
no longer needed.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 4 Nov 2017 21:37:38 +0000 (22:37 +0100)]
tests: gpioinfo: don't use static names for GPIO chips
We need to construct the pattern strings using the names supplied by
the testing framework - otherwise we may end up getting false
negatives from these test cases if the chip layout in the system is
different than expected.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 3 Nov 2017 17:12:50 +0000 (18:12 +0100)]
doc: update the documentation for events and iterators
Various documentation updates for iterator and event routines.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 31 Oct 2017 15:00:21 +0000 (16:00 +0100)]
iter: use scandir() for chip iterators
Using scandir() instead of opendir() allows us to scan for all
gpiochip devices already when creating the iterator. This simplifies
the code and doesn't require keeping the directory open when
iterating.
Storing the array of all found GPIO chips will also make it easier if
we ever want to implement a reverse iterator (e.g. for C++ bindings).
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 31 Oct 2017 09:34:21 +0000 (10:34 +0100)]
NEWS: updates for v0.3.2
Add release notes for libgpiod v0.3.2.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 26 Oct 2017 12:12:51 +0000 (14:12 +0200)]
build: tools: use absolute path in LDADD
Specify the path to libgpiod starting from the top project directory.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 25 Oct 2017 18:38:01 +0000 (20:38 +0200)]
core: simplify consumer, label & name strings handling
The separate buffers make the code less readable for no real benefit.
Remove them and simplify the strings handling. Also: improve the way
we're handling the chip names and labels.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 24 Oct 2017 12:48:54 +0000 (14:48 +0200)]
doc: minor fix for line bulk loop macros
Make it clear in the @brief section what the difference is between the
two variants.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 24 Oct 2017 12:46:24 +0000 (14:46 +0200)]
doc: improvements for the chip operations
Tweak the docs for the low-level chip API a bit.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 24 Oct 2017 12:25:02 +0000 (14:25 +0200)]
helpers: set errno in gpiod_chip_open_by_label()
If a GPIO chip with given label cannot be found but no other error
occurred, set errno to ENOENT before returning a NULL pointer.
Update the relevant test case.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 24 Oct 2017 09:31:16 +0000 (11:31 +0200)]
doc: extend the documentation of the simple API
Fix some minor issues and tweak the style and doxygen markup.
Describe in detail the way the simple event loop works.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 24 Oct 2017 08:20:47 +0000 (10:20 +0200)]
doc: extend the introduction
Add some additional info about the way the API is logically ordered
and a note on error handling.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 24 Oct 2017 07:28:10 +0000 (09:28 +0200)]
tests: remove the MALLOC attribute from xappend()
The internally called realloc() doesn't have this attribute so we
can't propagate it up the stack.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 23 Oct 2017 21:32:33 +0000 (23:32 +0200)]
tests: event: new test case
Add a test case which verifies that we can't request line events for
a set of lines if one of them has already been requested for values.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 23 Oct 2017 21:29:16 +0000 (23:29 +0200)]
core: fix an error path in line event requests
Correctly release already requested lines in case of an error
in line_request_event_single().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 23 Oct 2017 10:49:06 +0000 (12:49 +0200)]
core: use gpiod_line_bulk_foreach_line_off()
Use the newly introduced iterator macro wherever there's a need to
access the line offset while looping over a bulk object.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 23 Oct 2017 10:47:55 +0000 (12:47 +0200)]
core: implement gpiod_line_bulk_foreach_line_off()
Implement a variant of gpiod_line_bulk_foreach_line() which allows to
store the loop state in an integer counter variable.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 20 Oct 2017 09:27:26 +0000 (11:27 +0200)]
core: code shrink for name, label & consumer strings handling
Create a helper function that implements a uniform way of copying the
info strings from the kernel data structures to gpiod_line and
gpiod_chip objects.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 20 Oct 2017 09:15:26 +0000 (11:15 +0200)]
core: update line info after requesting the event handle
Just as we do when requesting the regular line handle - update line
info to reflect the changes after the event request.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 20 Oct 2017 09:00:45 +0000 (11:00 +0200)]
helpers: fix a crash in gpiod_chip_find_line()
The name of a line can be NULL in which case we must check it and skip
the call to strcmp() to avoid a NULL pointer dereference.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 19 Oct 2017 16:07:09 +0000 (18:07 +0200)]
core: remove kernel data structures from struct gpiod_line
The structures defined in linux/gpio.h use non-standard data types.
Use them only when calling relevant ioctl()s and then copy the
necessary info to separate fields in struct gpiod_line.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 19 Oct 2017 12:15:15 +0000 (14:15 +0200)]
core: remove kernel data structures from struct gpiod_chip
The structures defined in linux/gpio.h use non-standard data types.
Use them only when calling relevant ioctl()s and then copy the
necessary info to separate fields in struct gpiod_chip.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 19 Oct 2017 07:33:24 +0000 (09:33 +0200)]
tests: line: coding style fix
Put local variables in correct order - from longest to shortest lines.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Oct 2017 19:43:43 +0000 (21:43 +0200)]
core: rename a field in struct gpiod_chip
Initially 'cinfo' stood for chip info, but since there's no other
field in this struct to confuse it with, just rename it to 'info'.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Oct 2017 16:01:53 +0000 (18:01 +0200)]
core: coding style fix
Break the lines according to the kernel coding style.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Oct 2017 15:56:34 +0000 (17:56 +0200)]
core: move helpers to a separate file
Create a new source file for helper functions that don't need to know
the internal data structures or use any symbols exported by the kernel.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Oct 2017 15:32:11 +0000 (17:32 +0200)]
core: remove unnecessary setters and getters
These routines only obscure the code. We don't need them for simple,
internal data structures.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Oct 2017 15:16:07 +0000 (17:16 +0200)]
event: improve gpiod_line_event_get_fd()
Set errno to EINVAL when the user calls this routine for a line
requested for values. Verify correct behavior with a test case.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Oct 2017 14:39:17 +0000 (16:39 +0200)]
core: move line-related static functions to more suitable places
Group the line state routines together and put line_bulk_is_requested()
next to verify_line_bulk().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Oct 2017 14:20:46 +0000 (16:20 +0200)]
core: remove line_set_offset()
This function is not used and should have been static anyway.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Oct 2017 14:13:34 +0000 (16:13 +0200)]
core: simplify the internal line context structs
The kernel uapi line handle and event request structures are only
needed for relevant ioctl() calls. After that they can be discarded as
all we need is the file descriptor.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 16 Oct 2017 15:55:55 +0000 (17:55 +0200)]
tests: set errno to 0 before running each test case
Just to make sure we start with a clean environment, set errno
to 0 before running the test callback.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 16 Oct 2017 15:45:27 +0000 (17:45 +0200)]
core: don't allow OPEN_DRAIN & OPEN_SOURCE flags for input
OPEN_DRAIN and OPEN_SOURCE flags only affect the way we drive a GPIO
line, so they only make sense for output mode.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 15 Oct 2017 19:01:44 +0000 (21:01 +0200)]
tests: line: fix the misc flags test case
Setting the open-drain or open-source flags for input doesn't make any
sense as these flags are only valid for output mode. This should
actually be checked in the kernel. For now fix the test case.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 16:33:03 +0000 (18:33 +0200)]
simple-api: modify the order of arguments in simple loop routines
Move the consumer string after the active_low property.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 16:10:31 +0000 (18:10 +0200)]
simple-api: modify the order of arguments in set value routines
Move the consumer string after the active_low property.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 15:53:32 +0000 (17:53 +0200)]
simple-api: modify the order of arguments in get value routines
Move the consumer string to the end of the argument list as the least
significant option.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 15:31:24 +0000 (17:31 +0200)]
simple-api: allow the simple event loop callback to indicate an error
Add a new return value for the simple event loop callback which, when
returned, makes the loop function return a negative value indicating
an error.
Include new test cases.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 15:01:04 +0000 (17:01 +0200)]
simple-api: improve documentation
Mention the meaning of a positive value returned from the polling
callback of the simple event loop routines.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 13:37:32 +0000 (15:37 +0200)]
simple-api: handle receiving multiple events
Make the simple event loop poll callback capable of signalling to the
caller that more than one event occurred. Make the event loop routine
for multiple lines aware of that so that it reads all the event data
queued up instead of needlessly polling in that case.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 12:20:54 +0000 (14:20 +0200)]
simple-api: use correct prefixes for callback typedefs
We want to have all simple-api-related symbols prefixed with
gpiod_simple_.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 09:48:03 +0000 (11:48 +0200)]
core: remove double whitespace
Should be 'return NULL', not 'return NULL'.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 11 Oct 2017 09:25:17 +0000 (11:25 +0200)]
event: rework gpiod_line_event_wait_bulk()
When monitoring more than one line, it's possible for two or more
events to be queued at the same time in the kernel, so the internal
call to ppoll() will return a value greater than 1. If we always only
read one event at most, we end up calling ppoll() needlessly, as we
already know more events are pending.
Allow gpiod_line_event_wait_bulk() to pass a list of all lines on
which events occurred via a line bulk object.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 10 Oct 2017 12:02:59 +0000 (14:02 +0200)]
build: fix building with static libraries
We call gpiod_version_string() from tools-common.c but adding
libgpiod.la to LDADD before libtools-common.la makes the linker
discard this symbol as unused.
Invert the LDADD order to fix the static build.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 9 Oct 2017 21:05:30 +0000 (23:05 +0200)]
gpioset: fix checking mutually exclusive options
Certain options are mutually exclusive but they're checked in a way
that doesn't always guarantee gpioset to bail out. Fix it by checking
the options that don't work together after all command-line parsing is
done.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 4 Oct 2017 09:23:08 +0000 (11:23 +0200)]
build: fix warnings when building with clang
Clang complains about "missing field 'has_arg' initializer" when
zeroing the last element of the struct option array with "{ 0 }".
Use a complete initializer to fix this warning.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 4 Oct 2017 07:32:58 +0000 (09:32 +0200)]
core: use line bulk accessors
Use provided routines for retrieving the line handles from line bulk
objects.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 4 Oct 2017 07:07:44 +0000 (09:07 +0200)]
line: provide gpiod_line_bulk_foreach_line()
Add a macro allowing to easily iterate over all lines held by a line
bulk object.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 2 Oct 2017 14:34:05 +0000 (16:34 +0200)]
core: drop unnecessary checks
The getter functions retrieving the file descriptors (both for events
and line values) check the line state internally but we don't check
their return values and just pass them on to ioctl()s. Drop the checks
altogether.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 2 Oct 2017 13:16:44 +0000 (15:16 +0200)]
core: provide gpiod_line_bulk_num_lines()
Add an inline routine allowing to retrieve the number of lines held by
a line bulk object.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>