qemu-gpiodev/libgpiod.git
7 years agobuild: fix building with static libraries
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>
7 years agogpioset: fix checking mutually exclusive options
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>
7 years agobuild: fix warnings when building with clang
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>
7 years agocore: use line bulk accessors
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>
7 years agoline: provide gpiod_line_bulk_foreach_line()
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>
7 years agocore: drop unnecessary checks
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>
7 years agocore: provide gpiod_line_bulk_num_lines()
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>
7 years agodoc: split the documentation for GPIO lines into smaller chunks
Bartosz Golaszewski [Mon, 2 Oct 2017 13:04:12 +0000 (15:04 +0200)]
doc: split the documentation for GPIO lines into smaller chunks

Create separate sections for bulk, info, requests, values, events and
misc routines and data structures for GPIO lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: group the GCC attributes together
Bartosz Golaszewski [Mon, 2 Oct 2017 12:48:03 +0000 (14:48 +0200)]
core: group the GCC attributes together

Put the defines wrapping the gcc attributes in the same place
in gpiod.h.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoiter: improve the naming of line iterator constants
Bartosz Golaszewski [Mon, 2 Oct 2017 12:46:17 +0000 (14:46 +0200)]
iter: improve the naming of line iterator constants

These three constants define the possible line iterator states. Make
their names reflect that.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: rename the constant defining the max size of a bulk line object
Bartosz Golaszewski [Mon, 2 Oct 2017 12:41:49 +0000 (14:41 +0200)]
line: rename the constant defining the max size of a bulk line object

Stay in line with other prefixes and change it to
GPIOD_LINE_BULK_MAX_LINES.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: use a common prefix for all line defines
Bartosz Golaszewski [Mon, 2 Oct 2017 12:26:42 +0000 (14:26 +0200)]
line: use a common prefix for all line defines

Prefix all constants used by line functions with GPIOD_LINE_.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiofind: use gpiod_simple_find_line() internally
Bartosz Golaszewski [Fri, 29 Sep 2017 17:18:09 +0000 (19:18 +0200)]
gpiofind: use gpiod_simple_find_line() internally

Switch to using the simple API in gpiofind.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple-api: provide gpiod_simple_find_line()
Bartosz Golaszewski [Fri, 29 Sep 2017 17:17:37 +0000 (19:17 +0200)]
simple-api: provide gpiod_simple_find_line()

Implement a simple API function for looking up GPIO lines. Include
a set of test cases.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: provide gpiod_line_get()
Bartosz Golaszewski [Fri, 29 Sep 2017 16:47:51 +0000 (18:47 +0200)]
core: provide gpiod_line_get()

Provide a routine which simplifies the process of getting the handle
for a single GPIO line by encapsulating the calls opening the chip and
retrieving the line handle in a single function.

Implement test cases as well.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: rework gpiod_line_find()
Bartosz Golaszewski [Fri, 29 Sep 2017 16:27:39 +0000 (18:27 +0200)]
core: rework gpiod_line_find()

Use gpiod_chip_find_line() internally for smaller code. Return NULL
if an error occurrs during the lookup. Update the documentation.

While we're at it: update the tests for line lookups.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: rename gpiod_line_find_by_name()
Bartosz Golaszewski [Fri, 29 Sep 2017 16:20:30 +0000 (18:20 +0200)]
core: rename gpiod_line_find_by_name()

Shorten the name of the line lookup routine as any other type of
lookup wouldn't make sense anyway.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add parentheses in assert macros
Bartosz Golaszewski [Fri, 29 Sep 2017 15:30:47 +0000 (17:30 +0200)]
tests: add parentheses in assert macros

Use parentheses around arguments wherever they can be numerical
values.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: chip: add test cases for gpiod_chip_find_line()
Bartosz Golaszewski [Fri, 29 Sep 2017 15:25:07 +0000 (17:25 +0200)]
tests: chip: add test cases for gpiod_chip_find_line()

Test two use cases: correct lookup and a search for a non-existent
line.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: use TEST_ASSERT_ERRNO_IS()
Bartosz Golaszewski [Fri, 29 Sep 2017 15:22:16 +0000 (17:22 +0200)]
tests: use TEST_ASSERT_ERRNO_IS()

Use the new assert macro wherever we're checking the errno value.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: new assertion
Bartosz Golaszewski [Fri, 29 Sep 2017 15:21:15 +0000 (17:21 +0200)]
tests: new assertion

Add a helper for checking the current errno value.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: implement gpiod_chip_find_line()
Bartosz Golaszewski [Fri, 29 Sep 2017 13:24:00 +0000 (15:24 +0200)]
core: implement gpiod_chip_find_line()

The low-level line lookup should be more fine-grained. As the first
step: introduce a routine performing a line lookup for specific chip.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: fix event counting
Bartosz Golaszewski [Fri, 29 Sep 2017 13:47:12 +0000 (15:47 +0200)]
gpiomon: fix event counting

We must not increment the events_done variable for events we're not
watching.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: correctly handle poll timeouts
Bartosz Golaszewski [Fri, 29 Sep 2017 13:31:12 +0000 (15:31 +0200)]
gpiomon: correctly handle poll timeouts

We don't check for timeout events in the simple loop event handler.

Fix it and return a correct value.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: line: use test_line_close_chip()
Bartosz Golaszewski [Thu, 28 Sep 2017 07:57:57 +0000 (09:57 +0200)]
tests: line: use test_line_close_chip()

Drop the unnecessary chip object.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: new cleanup function
Bartosz Golaszewski [Thu, 28 Sep 2017 07:56:41 +0000 (09:56 +0200)]
tests: new cleanup function

Add a new cleanup function which calls gpiod_line_close_chip().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: implement gpiod_line_close_chip()
Bartosz Golaszewski [Thu, 28 Sep 2017 07:54:10 +0000 (09:54 +0200)]
core: implement gpiod_line_close_chip()

This function works nicely with gpiod_line_find_by_name() which
returns a line object whose owning chip must be later freed by the
caller. With this routine the caller can skip creating a temporary
chip object.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotools: remove the redundant UNUSED define
Bartosz Golaszewski [Wed, 27 Sep 2017 09:47:09 +0000 (11:47 +0200)]
tools: remove the redundant UNUSED define

Use GPIOD_UNUSED instead.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple-api: improve the naming convention
Bartosz Golaszewski [Wed, 27 Sep 2017 09:44:09 +0000 (11:44 +0200)]
simple-api: improve the naming convention

Discern between the callback arguments and return values by renaming
relevant defines.

Also: prefix all simple API defines with GPIOD_SIMPLE_.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: new public macro
Bartosz Golaszewski [Wed, 27 Sep 2017 09:10:38 +0000 (11:10 +0200)]
core: new public macro

Export GPIOD_UNUSED in gpiod.h as it may be useful for users not
using all arguments in certain callback functions.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: simple-api: new test case
Bartosz Golaszewski [Wed, 27 Sep 2017 09:09:37 +0000 (11:09 +0200)]
tests: simple-api: new test case

Add a test case for gpiod_simple_event_loop_multiple().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: use the simple event loop
Bartosz Golaszewski [Tue, 26 Sep 2017 21:58:44 +0000 (23:58 +0200)]
gpiomon: use the simple event loop

Switch to using the high-level API. This significantly shrinks the
code while keeping all the functionality.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple: rework the event loop
Bartosz Golaszewski [Mon, 25 Sep 2017 17:13:48 +0000 (19:13 +0200)]
simple: rework the event loop

Implement a new routine for monitoring multiple lines with the simple
event loop and extend the simple loop interface with custom polling
capabilities.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple: event-loop: fix EINTR handling
Bartosz Golaszewski [Mon, 25 Sep 2017 18:22:03 +0000 (20:22 +0200)]
simple: event-loop: fix EINTR handling

We want to handle EINTR as a timeout event. Don't return here.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: add gpiod_line_bulk_get_line()
Bartosz Golaszewski [Sun, 24 Sep 2017 20:06:31 +0000 (22:06 +0200)]
core: add gpiod_line_bulk_get_line()

Add a getter function for retrieving line handles from bulk objects.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple: remove redundant line releases
Bartosz Golaszewski [Sun, 24 Sep 2017 19:59:45 +0000 (21:59 +0200)]
simple: remove redundant line releases

We're closing the chip right after calling the release routines in all
three cases. The chip close function releases all line resources
anyway so no need to do it twice.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple: fix the active_low switch in gpiod_simple_event_loop()
Bartosz Golaszewski [Sun, 24 Sep 2017 19:11:45 +0000 (21:11 +0200)]
simple: fix the active_low switch in gpiod_simple_event_loop()

We're incorrectly passing the boolean active_low argument to
gpiod_line_request_both_edges_events_flags() as flags. Add the same
conversion as in the other simple API routines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobuild: fix the kernel version in the 'make check' message
Bartosz Golaszewski [Sun, 24 Sep 2017 08:52:55 +0000 (10:52 +0200)]
build: fix the kernel version in the 'make check' message

The minimum kernel version for running tests is now 4.12.6. Reflect
that in the message displayed after building the test suite.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: rename gpiod_line_is_used_by_kernel()
Bartosz Golaszewski [Sun, 24 Sep 2017 08:48:14 +0000 (10:48 +0200)]
core: rename gpiod_line_is_used_by_kernel()

The UAPI flag checked by this routine is called GPIOLINE_FLAG_KERNEL
but its name may be a bit misleading. When set, it can mean that the
line is used by the kernel or by another user space process.

Use a more general name: gpiod_line_is_used().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoREADME: add info about the subject line for e-mails sent to linux-gpio
Bartosz Golaszewski [Thu, 14 Sep 2017 06:06:10 +0000 (08:06 +0200)]
README: add info about the subject line for e-mails sent to linux-gpio

For libgpiod-related e-mails the subject line should be prefixed
with [libgpiod].

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoREADME: update the section about contributing
Bartosz Golaszewski [Wed, 13 Sep 2017 08:52:04 +0000 (10:52 +0200)]
README: update the section about contributing

The development will no longer happen on github, but on the linux-gpio
mailing list instead.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobuild: silence an ar warning
Bartosz Golaszewski [Wed, 13 Sep 2017 08:30:28 +0000 (10:30 +0200)]
build: silence an ar warning

In some configurations ar prints the following warnings:

  ar: `u' modifier ignored since `D' is the default (see `U')

Silence it by setting the ar flags to 'cr' instead of 'cru' which is
the default.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoNEWS: updates for v0.3.1
Bartosz Golaszewski [Tue, 12 Sep 2017 16:05:48 +0000 (18:05 +0200)]
NEWS: updates for v0.3.1

Add release notes for libgpiod v0.3.1.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoREADME.md: rename to README
Bartosz Golaszewski [Tue, 12 Sep 2017 07:55:56 +0000 (09:55 +0200)]
README.md: rename to README

We now host libgpiod at kernel.org, so no need for the .md file.

This also fixes 'make dist' as README.md was not being packaged by
autotools.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioset: fix a typo
Bartosz Golaszewski [Sun, 10 Sep 2017 11:24:37 +0000 (13:24 +0200)]
tests: gpioset: fix a typo

Fix the spelling of the test case function name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: re-enable a test case for gpiomon
Bartosz Golaszewski [Sat, 12 Aug 2017 19:46:13 +0000 (21:46 +0200)]
tests: re-enable a test case for gpiomon

The test case in which we verify if falling-edge events are correctly
ignored was failing due to a bug in the kernel. This has now been
fixed with commit df1e76f28ffe ("gpiolib: skip unwanted events, don't
convert them to opposite edge") and released in linux v4.12.6.

Re-enable the test and make this version a hard requirement for
running the test suite.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotools: use program_invocation_name
Bartosz Golaszewski [Fri, 28 Jul 2017 11:00:41 +0000 (13:00 +0200)]
tools: use program_invocation_name

Remove set_progname() from tools-common and use the global
program_invocation_name variable.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: use program_invocation_name
Bartosz Golaszewski [Sat, 22 Jul 2017 15:31:47 +0000 (17:31 +0200)]
tests: use program_invocation_name

We're using _GNU_SOURCE, so it's ok to use program_invocation_name
instead of storing it manually.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiod.h: improve the documentation for gpiod_line_iter_last_offset()
Bartosz Golaszewski [Fri, 14 Jul 2017 11:25:40 +0000 (13:25 +0200)]
gpiod.h: improve the documentation for gpiod_line_iter_last_offset()

Mention the undefined behavior if gpiod_line_iter_last_offset() is
ever called before gpiod_line_iter_next().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiod.h: extend the introduction to the simple API
Bartosz Golaszewski [Fri, 14 Jul 2017 10:58:47 +0000 (12:58 +0200)]
gpiod.h: extend the introduction to the simple API

Add more info on the simple API functions.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiod.h: move the mainpage doxygen comment down
Bartosz Golaszewski [Fri, 14 Jul 2017 10:45:51 +0000 (12:45 +0200)]
gpiod.h: move the mainpage doxygen comment down

Move it to where the libgpiod declarations begin.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: readability tweak
Bartosz Golaszewski [Thu, 13 Jul 2017 16:24:54 +0000 (18:24 +0200)]
core: readability tweak

Create separate static functions for checking the request type.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: add the offset argument to the simple event loop callback
Bartosz Golaszewski [Thu, 13 Jul 2017 16:09:17 +0000 (18:09 +0200)]
core: add the offset argument to the simple event loop callback

In preparation for introducing a multiple lines variant of the simple
event loop routine, add the offset argument to the callback prototype.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: fix single line event requests with flags
Bartosz Golaszewski [Thu, 13 Jul 2017 16:07:25 +0000 (18:07 +0200)]
core: fix single line event requests with flags

We currently always request rising edge events for the 'flags'
variants. Request correct event types.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: add bulk event requests
Bartosz Golaszewski [Thu, 13 Jul 2017 11:53:46 +0000 (13:53 +0200)]
core: add bulk event requests

Add functions for requesting events for line bulk objects. Both with
and without additional flags.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: remove the active_low argument from line bulk requests
Bartosz Golaszewski [Thu, 13 Jul 2017 11:29:27 +0000 (13:29 +0200)]
core: remove the active_low argument from line bulk requests

We previously removed this argument from routines dealing with single
line requests. Do the same for bulk requests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: group the line request code together
Bartosz Golaszewski [Thu, 13 Jul 2017 11:15:39 +0000 (13:15 +0200)]
core: group the line request code together

Put both the regular input & output requests as well as event requests
together in the same place in core.c.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move the chip-related code to the top of core.c
Bartosz Golaszewski [Thu, 13 Jul 2017 10:57:14 +0000 (12:57 +0200)]
core: move the chip-related code to the top of core.c

Just as with the public header - move the chip code above the line
definitions.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: remove the active_low boolean argument from single-line requests
Bartosz Golaszewski [Wed, 12 Jul 2017 18:37:43 +0000 (20:37 +0200)]
core: remove the active_low boolean argument from single-line requests

Remove the separate argument for setting the active-state to low in
helper functions doing the single GPIO line requests.

Introduce new variants of these helpers that allow to pass
a combination of all available flags to the request.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: set the active state using the request flags
Bartosz Golaszewski [Wed, 12 Jul 2017 18:17:01 +0000 (20:17 +0200)]
core: set the active state using the request flags

Having to always set the active state in the line request config
structure makes users create unnecessary boilerplate code. Remove the
active state field from the config structure and add a new flag, which
when set, sets the active state to low, while high is the default.

This patch updates the main request function and all the callers - we
still need to update all the helper request routines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: add a test case for empty consumer strings
Bartosz Golaszewski [Wed, 12 Jul 2017 18:09:45 +0000 (20:09 +0200)]
line: add a test case for empty consumer strings

Check that both libgpiod and the kernel behave correctly when passed
an empty string as the consumer name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: accept NULL consumer strings
Bartosz Golaszewski [Wed, 12 Jul 2017 17:46:50 +0000 (19:46 +0200)]
core: accept NULL consumer strings

If the user passes a NULL pointer as the consumer name to any of the
line request functions, pass an empty string to the kernel instead of
segfaulting. The kernel code will then set the consumer string to "?".

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiod.h: remove the separate doxygen group for events
Bartosz Golaszewski [Wed, 12 Jul 2017 17:18:24 +0000 (19:18 +0200)]
gpiod.h: remove the separate doxygen group for events

Much of the event functionality has been merged with regular GPIO line
definitions. We no longer need a separate group for events in the
documentation.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiod.h: move the chip operations before line definitions
Bartosz Golaszewski [Wed, 12 Jul 2017 17:15:40 +0000 (19:15 +0200)]
gpiod.h: move the chip operations before line definitions

Chip operations should come earlier in the public header.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: merge chip.c and line.c
Bartosz Golaszewski [Wed, 12 Jul 2017 15:47:07 +0000 (17:47 +0200)]
core: merge chip.c and line.c

Splitting the line and chip functionality led to unnecessary bloat.
Just put the code together into a single file.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod: unify the header comments
Bartosz Golaszewski [Wed, 12 Jul 2017 15:22:09 +0000 (17:22 +0200)]
libgpiod: unify the header comments

Make the header comment look the same in every file. Move additional
descriptions of files' contents below the header.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoevent: rename event requests routines
Bartosz Golaszewski [Mon, 10 Jul 2017 08:15:05 +0000 (10:15 +0200)]
event: rename event requests routines

The event request functionality is now merged with the regular
requests. Change the naming pattern for event requests and move the
prototypes under the input and output requests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: merge event requests with regular line requests
Bartosz Golaszewski [Sat, 1 Jul 2017 17:50:11 +0000 (19:50 +0200)]
core: merge event requests with regular line requests

Requesting the lines both for reading/setting values as well as for
watching events will now be done using the gpiod_line_request_*()
family of functions.

This is the first part of changes required to fully convert the API.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agochip: lazily allocate lines
Bartosz Golaszewski [Sat, 1 Jul 2017 12:11:40 +0000 (14:11 +0200)]
chip: lazily allocate lines

Only allocate the array of line pointers is they're actually needed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: don't duplicate chip-related data structures
Bartosz Golaszewski [Sat, 1 Jul 2017 11:54:33 +0000 (13:54 +0200)]
core: don't duplicate chip-related data structures

Introduce an internal structure - line_chip_ctx - used to store the
chip-related information. This structure is shared among all line
objects exposed by a single chip.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple-api: reposition the prototypes in the public header
Bartosz Golaszewski [Sat, 1 Jul 2017 09:14:52 +0000 (11:14 +0200)]
simple-api: reposition the prototypes in the public header

Move the 'multiple' variants below the single value ones.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: line: new test case
Bartosz Golaszewski [Sat, 1 Jul 2017 09:07:13 +0000 (11:07 +0200)]
tests: line: new test case

Verify that a consumer string over 31 characters long is correctly
cropped.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: remove an unnecessary check
Bartosz Golaszewski [Sat, 1 Jul 2017 08:56:06 +0000 (10:56 +0200)]
line: remove an unnecessary check

We have changed the way line objects are allocated. This check is no
longer needed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agochip: use a temporary variable in gpiod_chip_close()
Bartosz Golaszewski [Fri, 30 Jun 2017 14:28:30 +0000 (16:28 +0200)]
chip: use a temporary variable in gpiod_chip_close()

The code looks better if we use a temporary pointer to gpiod_line.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: separate the chip and line logic
Bartosz Golaszewski [Fri, 30 Jun 2017 10:55:36 +0000 (12:55 +0200)]
core: separate the chip and line logic

Lazily allocate memory for line objects in chip.c. This eliminates the
need for chip routines to know the size of a line object.

Line objects now contain the chip file descriptor as well, so that we
don't need to access the chip object in any way from line.c.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agochip: release lines in bulk on close()
Bartosz Golaszewski [Thu, 29 Jun 2017 15:10:57 +0000 (17:10 +0200)]
chip: release lines in bulk on close()

When closing the chip use a bulk operation to release all lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: remove stray semicolons
Bartosz Golaszewski [Thu, 29 Jun 2017 15:05:27 +0000 (17:05 +0200)]
line: remove stray semicolons

These got introduced accidentally when adding chip_get_fd().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agochip: rename is_unsigned_int()
Bartosz Golaszewski [Thu, 29 Jun 2017 13:36:01 +0000 (15:36 +0200)]
chip: rename is_unsigned_int()

Use a shorter name for this simple routine.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: coding style fix
Bartosz Golaszewski [Thu, 29 Jun 2017 13:27:27 +0000 (15:27 +0200)]
line: coding style fix

Correctly align a broken line.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: tweak some comments
Bartosz Golaszewski [Thu, 29 Jun 2017 13:23:55 +0000 (15:23 +0200)]
core: tweak some comments

Minor changes to the file header comments in the core library.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move all line-related code to line.c and remove core.c
Bartosz Golaszewski [Thu, 29 Jun 2017 13:12:22 +0000 (15:12 +0200)]
core: move all line-related code to line.c and remove core.c

This is the final stage of splitting the core library code into
separate files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move chip definitions to a separate file
Bartosz Golaszewski [Wed, 28 Jun 2017 15:33:51 +0000 (17:33 +0200)]
core: move chip definitions to a separate file

Move all chip-related code to chip.c and create temporary glue-code
header for chip.c and core.c.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill gpiod_line_event_release()
Bartosz Golaszewski [Wed, 28 Jun 2017 14:39:36 +0000 (16:39 +0200)]
core: kill gpiod_line_event_release()

We can (and already do in gpiod_chip_close()) easily figure out if
a GPIO line was configured for events or values, so there's no need
to have a separate release function for events.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move gpiod_version_string() to misc.c
Bartosz Golaszewski [Wed, 28 Jun 2017 14:15:04 +0000 (16:15 +0200)]
core: move gpiod_version_string() to misc.c

Create a separate .c file for misc definitions.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move iterator definitions to a separate file
Bartosz Golaszewski [Sat, 24 Jun 2017 11:05:34 +0000 (13:05 +0200)]
core: move iterator definitions to a separate file

Move all iterator-related code to iter.c.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple API: un-inline simple API routines
Bartosz Golaszewski [Sat, 24 Jun 2017 10:54:20 +0000 (12:54 +0200)]
simple API: un-inline simple API routines

Try to avoid inline functions in the public header wherever possible.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move the simple API definitions into a separate file
Bartosz Golaszewski [Sat, 24 Jun 2017 10:48:54 +0000 (12:48 +0200)]
core: move the simple API definitions into a separate file

This is the first step in splitting up the core library code.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill nsec_to_timespec()
Bartosz Golaszewski [Sat, 24 Jun 2017 10:43:00 +0000 (12:43 +0200)]
core: kill nsec_to_timespec()

This function is tiny and only used in one place.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill zalloc() and use calloc() where applicable
Bartosz Golaszewski [Sat, 24 Jun 2017 10:37:50 +0000 (12:37 +0200)]
core: kill zalloc() and use calloc() where applicable

Remove zalloc() and use malloc() + memset() in the code. When
allocating an array of elements, use calloc(). This is done in
preparation for splitting up the core library code into separate
files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill gpio_ioctl()
Bartosz Golaszewski [Sat, 24 Jun 2017 10:32:01 +0000 (12:32 +0200)]
core: kill gpio_ioctl()

We used this wrapper around ioctl() to set the libgpiod-specific error
number if the ioctl() call failed.

We no longer use custom error numbers, so remove this function.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill custom error handling
Bartosz Golaszewski [Sat, 24 Jun 2017 10:21:57 +0000 (12:21 +0200)]
core: kill custom error handling

The libgpiod-specific error codes are not really necessary and can be
easily replaced with regular libc error numbers defined in errno.h.

Remove all routines and definitions dealing with error numbers and
switch to using errnos in the library code.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix checking the kernel version
Bartosz Golaszewski [Thu, 6 Jul 2017 08:41:15 +0000 (10:41 +0200)]
tests: fix checking the kernel version

Previous check was incorrect and would break at major version change.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod: start 1.0 development cycle
Bartosz Golaszewski [Sat, 24 Jun 2017 09:41:19 +0000 (11:41 +0200)]
libgpiod: start 1.0 development cycle

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod v0.3
Bartosz Golaszewski [Fri, 23 Jun 2017 14:56:09 +0000 (16:56 +0200)]
libgpiod v0.3

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoNEWS: updates for v0.3
Bartosz Golaszewski [Fri, 23 Jun 2017 14:52:07 +0000 (16:52 +0200)]
NEWS: updates for v0.3

Add release notes for libgpiod v0.3.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: new test case
Bartosz Golaszewski [Fri, 23 Jun 2017 14:42:07 +0000 (16:42 +0200)]
tests: gpiomon: new test case

Verify that gpiomon bails out if the same line offset is given more
than once.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: new test case for watching multiple lines
Bartosz Golaszewski [Fri, 23 Jun 2017 14:38:56 +0000 (16:38 +0200)]
tests: gpiomon: new test case for watching multiple lines

Make sure gpiomon behaves correctly when the requested line offsets
are not in order.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: implement monitoring multiple lines at the same time
Bartosz Golaszewski [Fri, 23 Jun 2017 09:25:13 +0000 (11:25 +0200)]
gpiomon: implement monitoring multiple lines at the same time

Switch from the simple API to low-level libgpiod routines and
implement watching multiple lines at the same time.

Update tests and README.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: event: use correct flags when requesting events
Bartosz Golaszewski [Fri, 23 Jun 2017 10:37:21 +0000 (12:37 +0200)]
core: event: use correct flags when requesting events

We must use the GPIOEVENT_REQUEST_* flags, not GPIOEVENT_EVENT_* since
the latter are only meaningful when receiving event info.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpioset: improve error messages
Bartosz Golaszewski [Fri, 23 Jun 2017 09:04:18 +0000 (11:04 +0200)]
gpioset: improve error messages

Say more than just the name of the failed function.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>