Mark gpiod_ctxless_event_loop() and gpiod_ctxless_event_loop_multiple()
as deprecated. Those functions suffer from an issue where HW may not
allow setting up both rising and falling egde interrupts. All users
have been converted to using the new event monitor helpers.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
We want to deprecate the badly designed event loop functions. Introduce
a macro that allows marking API routines as deprecated.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Current implementation of gpiod_ctxless_event_loop() (and its variant
for multiple lines) always requests GPIO lines for listening for both
rising and falling edge events. This causes a problem when the
underlying hardware doesn't allow this.
It can e.g. result in the following error raised by the interrupt
controller:
genirq: Setting trigger mode 3 for irq 107 failed (kempld_irq_set_type+0x0/0x130 [gpio_kempld])
For the sake of backward compatibility we're leaving the old
implementation in place and provide two new routines that that take an
additional parameter allowing users to specify the events libgpiod
should listen for.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Make it clear that this function returns the API version as we now have
separate API and ABI versions.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Implement a new helper that allows to look-up multiple GPIO lines by
their names. Include a set of test cases.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Use the SPDX license identifier for LGPLv2.1 or later in the public
API header and the corresponding Makefile.am.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
These three constants define the possible line iterator states. Make
their names reflect that.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
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>
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>
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>
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>