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

266 Commits

Author SHA1 Message Date
Bartosz Golaszewski
16e5a3ce56 bindings: python: provide Line.is_requested()
Add a python wrapper around gpiod_line_is_requested().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 18:34:52 +02:00
Bartosz Golaszewski
345d408836 bindings: python: improve readability in test cases
Mostly just add new lines for improved readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 18:13:36 +02:00
Bartosz Golaszewski
0596dfb0b5 bindings: python: new test cases/examples
Add more test cases/code examples for python bindings.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 14:51:00 +02:00
Bartosz Golaszewski
d463052184 bindings: python: provide Chip.get_all_lines()
Add a method for retrieving all GPIO lines exposed by a chip.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 12:05:28 +02:00
Bartosz Golaszewski
2c8127eba1 bindings: python: improve readability
Order the arguments in a reverse christmas tree shape in
gpiod_Chip_find_lines();

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 11:50:16 +02:00
Bartosz Golaszewski
7a64b84885 bindings: python: code shrink
Provide a helper for converting a list of lines into a LineBulk object
in a single call.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 11:49:16 +02:00
Bartosz Golaszewski
e6d1647a8f bindings: python: implement Chip.find_lines()
Provide a method for looking up multiple lines by name at once.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 11:41:52 +02:00
Bartosz Golaszewski
2df328e989 bindings: python: extend tests
Add more test cases/examples, implement some helper functions, tweak
the output messages, mention the need for a dummy chip in the system
in the module's pydoc string.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 12:01:13 +02:00
Bartosz Golaszewski
1e47c4d6ea bindings: python: change the return value of gpiod_LineBulk_event_wait()
gpiod_Line_event_wait() works differently than its LineBulk
counterpart. While the latter returns either a list of lines or False,
the former returns True if an event occurred on this line or False
otherwise.

False is not a good counterpart for an actual object, so instead return
None if no events occurred on any of the monitored lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 12:01:13 +02:00
Bartosz Golaszewski
15a623a7d2 bindings: python: fix a memory leak in gpiod_Line_event_wait()
We don't return the object returned from gpiod_LineBulk_event_wait()
back to the interpreter. We need to collect it before returning True.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 12:01:13 +02:00
Bartosz Golaszewski
27fec345ca bindings: python: fix a memory leak in Line.set_value()
We're not collecting the bulk object we're creating in this method. Add
Py_DECREF() where needed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 12:01:13 +02:00
Bartosz Golaszewski
d331321f01 bindings: python: return None if line can't be found by name
For both find_line() variants (Chip's method and global function)
return None if the internal call to the C find_line function fails
with ENOENT. This is not an error so don't raise an exception.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 11:49:13 +02:00
Bartosz Golaszewski
f36a27f1cc bindings: python: decref the chip object in gpiod_Module_find_line()
When returning back to the interpreter from gpiod_Module_find_line(),
there's only one chip object reference holder, but we set the refcount
to 2 (as if the chip object existed separately in the interpreter).

Fix it by decreasing the chip's refcount by one before returning the
line object.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-12 14:51:28 +02:00
Bartosz Golaszewski
039b301b17 bindings: python: release the GIL during blocking I/O operations
We should release the python global interpreter lock when performing
blocking operations and reacquire it again when we're done. Use the
relevant APIs provided by libpython.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-04-22 23:16:40 +02:00
Bartosz Golaszewski
696de1b973 build: fix cross-compilation of python bindings
AX_PYTHON_DEVEL macro from the autoconf-archive collection doesn't work
when we're trying to cross-compile python bindings in environments such
as buildroot or yocto. It can't properly detect the location of python
headers.

Let's use AM_PATH_PYTHON to detect the python3 interpreter and then
either take the PYTHON_CPPFLAGS and PYTHON_LIBS variables from the
environment (so that cross-compiling build systems can pass their
custom locations to autotools) or try to detect them ourselves using
the python3-config tool.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-04-20 14:10:09 +02:00
Bartosz Golaszewski
96c524c495 bindings: implement python bindings
Create a C extension module wrapping the functionality of libgpiod
in a set of Python classes.

Add code examples including simplified reimplementations of gpio-tools
in Python.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-04-17 10:19:34 +02:00