gpiod 2.3.0__tar.gz → 2.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gpiod-2.3.0/gpiod.egg-info → gpiod-2.4.0}/PKG-INFO +4 -4
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/_ext.pyi +1 -0
- gpiod-2.4.0/gpiod/_internal.py +37 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/chip.py +42 -53
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/ext/chip.c +31 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/line_request.py +30 -22
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/version.py +1 -1
- {gpiod-2.3.0 → gpiod-2.4.0/gpiod.egg-info}/PKG-INFO +4 -4
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/line-config.c +18 -1
- gpiod-2.4.0/libgpiod-version.txt +1 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/pyproject.toml +9 -3
- {gpiod-2.3.0 → gpiod-2.4.0}/setup.py +1 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_line_request.py +60 -7
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_module.py +1 -1
- gpiod-2.3.0/gpiod/_internal.py +0 -19
- gpiod-2.3.0/libgpiod-version.txt +0 -1
- {gpiod-2.3.0 → gpiod-2.4.0}/MANIFEST.in +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/README.md +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/build_tests.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/__init__.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/chip_info.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/edge_event.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/exception.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/ext/common.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/ext/internal.h +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/ext/line-config.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/ext/line-settings.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/ext/module.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/ext/request.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/info_event.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/line.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/line_info.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/line_settings.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod/py.typed +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod.egg-info/SOURCES.txt +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod.egg-info/dependency_links.txt +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/gpiod.egg-info/top_level.txt +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/include/gpiod.h +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/chip-info.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/chip.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/edge-event.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/info-event.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/internal.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/internal.h +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/line-info.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/line-request.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/line-settings.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/misc.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/request-config.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/lib/uapi/gpio.h +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/setup.cfg +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/__init__.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/__main__.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/gpiosim/__init__.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/gpiosim/chip.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/gpiosim/ext.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/helpers.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/system/__init__.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/system/ext.c +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_chip.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_chip_info.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_edge_event.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_info_event.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_line.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_line_info.py +0 -0
- {gpiod-2.3.0 → gpiod-2.4.0}/tests/tests_line_settings.py +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: gpiod
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Python bindings for libgpiod
|
|
5
5
|
Author-email: Bartosz Golaszewski <brgl@bgdev.pl>
|
|
6
|
-
License: LGPL-2.1-or-later
|
|
6
|
+
License-Expression: LGPL-2.1-or-later
|
|
7
7
|
Project-URL: Homepage, https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
|
|
8
8
|
Project-URL: Issues, https://github.com/brgl/libgpiod/issues/
|
|
9
9
|
Platform: linux
|
|
10
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
|
|
12
11
|
Classifier: Operating System :: POSIX :: Linux
|
|
13
12
|
Classifier: Typing :: Typed
|
|
14
13
|
Classifier: Programming Language :: Python
|
|
@@ -19,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
22
|
Requires-Python: >=3.9.0
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
24
|
|
|
@@ -47,6 +47,7 @@ class Chip:
|
|
|
47
47
|
def get_info(self) -> ChipInfo: ...
|
|
48
48
|
def line_offset_from_id(self, id: str) -> int: ...
|
|
49
49
|
def get_line_info(self, offset: int, watch: bool) -> LineInfo: ...
|
|
50
|
+
def get_line_name(self, offset: int) -> Optional[str]: ...
|
|
50
51
|
def request_lines(
|
|
51
52
|
self,
|
|
52
53
|
line_cfg: LineConfig,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
2
|
+
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from datetime import timedelta
|
|
7
|
+
from select import select
|
|
8
|
+
from typing import TYPE_CHECKING, Optional, Union
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from collections.abc import Generator, Iterable
|
|
12
|
+
|
|
13
|
+
from .line_settings import LineSettings
|
|
14
|
+
|
|
15
|
+
__all__ = ["poll_fd", "config_iter"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool:
|
|
19
|
+
sec: Union[float, None]
|
|
20
|
+
if isinstance(timeout, timedelta):
|
|
21
|
+
sec = timeout.total_seconds()
|
|
22
|
+
else:
|
|
23
|
+
sec = timeout
|
|
24
|
+
|
|
25
|
+
readable, _, _ = select([fd], [], [], sec)
|
|
26
|
+
return True if fd in readable else False
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def config_iter(
|
|
30
|
+
config: dict[Union[Iterable[Union[int, str]], int, str], Optional[LineSettings]],
|
|
31
|
+
) -> Generator[tuple[Union[int, str], Optional[LineSettings]]]:
|
|
32
|
+
for key, settings in config.items():
|
|
33
|
+
if isinstance(key, int) or isinstance(key, str):
|
|
34
|
+
yield key, settings
|
|
35
|
+
else:
|
|
36
|
+
for subkey in key:
|
|
37
|
+
yield subkey, settings
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
|
-
from collections import Counter
|
|
7
6
|
from errno import ENOENT
|
|
8
7
|
from typing import TYPE_CHECKING, Optional, Union, cast
|
|
9
8
|
|
|
10
9
|
from . import _ext
|
|
11
|
-
from ._internal import poll_fd
|
|
10
|
+
from ._internal import config_iter, poll_fd
|
|
12
11
|
from .exception import ChipClosedError
|
|
13
12
|
from .line import Value
|
|
14
13
|
from .line_request import LineRequest
|
|
@@ -101,7 +100,7 @@ class Chip:
|
|
|
101
100
|
longer be used after this method is called.
|
|
102
101
|
"""
|
|
103
102
|
self._check_closed()
|
|
104
|
-
cast(_ext.Chip, self._chip).close()
|
|
103
|
+
cast("_ext.Chip", self._chip).close()
|
|
105
104
|
self._chip = None
|
|
106
105
|
|
|
107
106
|
def get_info(self) -> ChipInfo:
|
|
@@ -114,7 +113,7 @@ class Chip:
|
|
|
114
113
|
self._check_closed()
|
|
115
114
|
|
|
116
115
|
if not self._info:
|
|
117
|
-
self._info = cast(_ext.Chip, self._chip).get_info()
|
|
116
|
+
self._info = cast("_ext.Chip", self._chip).get_info()
|
|
118
117
|
|
|
119
118
|
return self._info
|
|
120
119
|
|
|
@@ -139,7 +138,7 @@ class Chip:
|
|
|
139
138
|
|
|
140
139
|
if not isinstance(id, int):
|
|
141
140
|
try:
|
|
142
|
-
return cast(_ext.Chip, self._chip).line_offset_from_id(id)
|
|
141
|
+
return cast("_ext.Chip", self._chip).line_offset_from_id(id)
|
|
143
142
|
except OSError as ex:
|
|
144
143
|
if ex.errno == ENOENT:
|
|
145
144
|
try:
|
|
@@ -158,7 +157,7 @@ class Chip:
|
|
|
158
157
|
|
|
159
158
|
def _get_line_info(self, line: Union[int, str], watch: bool) -> LineInfo:
|
|
160
159
|
self._check_closed()
|
|
161
|
-
return cast(_ext.Chip, self._chip).get_line_info(
|
|
160
|
+
return cast("_ext.Chip", self._chip).get_line_info(
|
|
162
161
|
self.line_offset_from_id(line), watch
|
|
163
162
|
)
|
|
164
163
|
|
|
@@ -198,7 +197,7 @@ class Chip:
|
|
|
198
197
|
Offset or name of the line to stop watching.
|
|
199
198
|
"""
|
|
200
199
|
self._check_closed()
|
|
201
|
-
return cast(_ext.Chip, self._chip).unwatch_line_info(
|
|
200
|
+
return cast("_ext.Chip", self._chip).unwatch_line_info(
|
|
202
201
|
self.line_offset_from_id(line)
|
|
203
202
|
)
|
|
204
203
|
|
|
@@ -234,7 +233,7 @@ class Chip:
|
|
|
234
233
|
This function may block if there are no available events in the queue.
|
|
235
234
|
"""
|
|
236
235
|
self._check_closed()
|
|
237
|
-
return cast(_ext.Chip, self._chip).read_info_event()
|
|
236
|
+
return cast("_ext.Chip", self._chip).read_info_event()
|
|
238
237
|
|
|
239
238
|
def request_lines(
|
|
240
239
|
self,
|
|
@@ -269,57 +268,50 @@ class Chip:
|
|
|
269
268
|
|
|
270
269
|
line_cfg = _ext.LineConfig()
|
|
271
270
|
|
|
272
|
-
# Sanitize lines - don't allow offset repetitions or offset-name conflicts.
|
|
273
|
-
for offset, count in Counter(
|
|
274
|
-
[
|
|
275
|
-
self.line_offset_from_id(line)
|
|
276
|
-
for line in (
|
|
277
|
-
lambda t: [
|
|
278
|
-
j for i in (t) for j in (i if isinstance(i, tuple) else (i,))
|
|
279
|
-
]
|
|
280
|
-
)(tuple(config.keys()))
|
|
281
|
-
]
|
|
282
|
-
).items():
|
|
283
|
-
if count != 1:
|
|
284
|
-
raise ValueError(
|
|
285
|
-
f"line must be configured exactly once - offset {offset} repeats"
|
|
286
|
-
)
|
|
287
|
-
|
|
288
271
|
# If we have global output values - map line names to offsets
|
|
272
|
+
mapped_output_values = None
|
|
289
273
|
if output_values:
|
|
290
274
|
mapped_output_values = {
|
|
291
275
|
self.line_offset_from_id(line): value
|
|
292
276
|
for line, value in output_values.items()
|
|
293
277
|
}
|
|
294
|
-
else:
|
|
295
|
-
mapped_output_values = None
|
|
296
278
|
|
|
297
279
|
name_map = dict()
|
|
298
|
-
|
|
280
|
+
requested_lines = list()
|
|
299
281
|
global_output_values = list()
|
|
282
|
+
seen_offsets = set()
|
|
300
283
|
|
|
301
|
-
for
|
|
284
|
+
for line, settings in config_iter(config):
|
|
302
285
|
offsets = list()
|
|
303
286
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
)
|
|
287
|
+
offset = self.line_offset_from_id(line)
|
|
288
|
+
# don't allow offset repetitions or offset-name conflicts.
|
|
289
|
+
if offset in seen_offsets:
|
|
290
|
+
raise ValueError(
|
|
291
|
+
f"line must be configured exactly once - offset {offset} repeats"
|
|
292
|
+
)
|
|
293
|
+
seen_offsets.add(offset)
|
|
294
|
+
offsets.append(offset)
|
|
295
|
+
requested_lines.append(line)
|
|
296
|
+
|
|
297
|
+
# If there's a global output value for this offset, store it in the
|
|
298
|
+
# list for later.
|
|
299
|
+
if mapped_output_values:
|
|
300
|
+
global_output_values.append(
|
|
301
|
+
mapped_output_values.get(offset, Value.INACTIVE)
|
|
302
|
+
)
|
|
319
303
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
304
|
+
if isinstance(line, str):
|
|
305
|
+
# lines specifically requested by name overwrite any entries
|
|
306
|
+
name_map[line] = offset
|
|
307
|
+
else:
|
|
308
|
+
name = cast("_ext.Chip", self._chip).get_line_name(offset)
|
|
309
|
+
# Only track lines with actual names. Names from offsets do not
|
|
310
|
+
# overwrite existing entries (such as requests by name). So if
|
|
311
|
+
# multiple lines have the same name, the first in the request
|
|
312
|
+
# list is the one addressable by name
|
|
313
|
+
if name and name not in name_map:
|
|
314
|
+
name_map[name] = offset
|
|
323
315
|
|
|
324
316
|
line_cfg.add_line_settings(
|
|
325
317
|
offsets, _line_settings_to_ext(settings or LineSettings())
|
|
@@ -328,7 +320,7 @@ class Chip:
|
|
|
328
320
|
if len(global_output_values):
|
|
329
321
|
line_cfg.set_output_values(global_output_values)
|
|
330
322
|
|
|
331
|
-
req_internal = cast(_ext.Chip, self._chip).request_lines(
|
|
323
|
+
req_internal = cast("_ext.Chip", self._chip).request_lines(
|
|
332
324
|
line_cfg, consumer, event_buffer_size
|
|
333
325
|
)
|
|
334
326
|
request = LineRequest(req_internal)
|
|
@@ -336,11 +328,8 @@ class Chip:
|
|
|
336
328
|
request._chip_name = req_internal.chip_name
|
|
337
329
|
request._offsets = req_internal.offsets
|
|
338
330
|
request._name_map = name_map
|
|
339
|
-
request._offset_map = offset_map
|
|
340
331
|
|
|
341
|
-
request._lines =
|
|
342
|
-
offset_map[off] if off in offset_map else off for off in request.offsets
|
|
343
|
-
]
|
|
332
|
+
request._lines = requested_lines
|
|
344
333
|
|
|
345
334
|
return request
|
|
346
335
|
|
|
@@ -374,7 +363,7 @@ class Chip:
|
|
|
374
363
|
Filesystem path used to open this chip.
|
|
375
364
|
"""
|
|
376
365
|
self._check_closed()
|
|
377
|
-
return cast(_ext.Chip, self._chip).path
|
|
366
|
+
return cast("_ext.Chip", self._chip).path
|
|
378
367
|
|
|
379
368
|
@property
|
|
380
369
|
def fd(self) -> int:
|
|
@@ -382,4 +371,4 @@ class Chip:
|
|
|
382
371
|
File descriptor associated with this chip.
|
|
383
372
|
"""
|
|
384
373
|
self._check_closed()
|
|
385
|
-
return cast(_ext.Chip, self._chip).fd
|
|
374
|
+
return cast("_ext.Chip", self._chip).fd
|
|
@@ -147,6 +147,32 @@ static PyObject *chip_get_line_info(chip_object *self, PyObject *args)
|
|
|
147
147
|
return info_obj;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
static PyObject *chip_get_line_name(chip_object *self, PyObject *args)
|
|
151
|
+
{
|
|
152
|
+
int ret;
|
|
153
|
+
unsigned int offset;
|
|
154
|
+
struct gpiod_line_info *info;
|
|
155
|
+
PyObject *line_name;
|
|
156
|
+
const char *name;
|
|
157
|
+
|
|
158
|
+
ret = PyArg_ParseTuple(args, "I", &offset);
|
|
159
|
+
if (!ret)
|
|
160
|
+
return NULL;
|
|
161
|
+
|
|
162
|
+
Py_BEGIN_ALLOW_THREADS;
|
|
163
|
+
info = gpiod_chip_get_line_info(self->chip, offset);
|
|
164
|
+
Py_END_ALLOW_THREADS;
|
|
165
|
+
if (!info)
|
|
166
|
+
return Py_gpiod_SetErrFromErrno();
|
|
167
|
+
|
|
168
|
+
name = gpiod_line_info_get_name(info);
|
|
169
|
+
line_name = (name == NULL) ? Py_None : PyUnicode_FromString(name);
|
|
170
|
+
|
|
171
|
+
gpiod_line_info_free(info);
|
|
172
|
+
|
|
173
|
+
return line_name;
|
|
174
|
+
}
|
|
175
|
+
|
|
150
176
|
static PyObject *
|
|
151
177
|
chip_unwatch_line_info(chip_object *self, PyObject *args)
|
|
152
178
|
{
|
|
@@ -333,6 +359,11 @@ static PyMethodDef chip_methods[] = {
|
|
|
333
359
|
.ml_meth = (PyCFunction)chip_request_lines,
|
|
334
360
|
.ml_flags = METH_VARARGS,
|
|
335
361
|
},
|
|
362
|
+
{
|
|
363
|
+
.ml_name = "get_line_name",
|
|
364
|
+
.ml_meth = (PyCFunction)chip_get_line_name,
|
|
365
|
+
.ml_flags = METH_VARARGS,
|
|
366
|
+
},
|
|
336
367
|
{ }
|
|
337
368
|
};
|
|
338
369
|
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
|
+
import warnings
|
|
6
7
|
from typing import TYPE_CHECKING, Optional, Union, cast
|
|
7
8
|
|
|
8
9
|
from . import _ext
|
|
9
|
-
from ._internal import poll_fd
|
|
10
|
+
from ._internal import config_iter, poll_fd
|
|
10
11
|
from .exception import RequestReleasedError
|
|
11
|
-
from .line import Value
|
|
12
12
|
from .line_settings import LineSettings, _line_settings_to_ext
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
@@ -17,6 +17,7 @@ if TYPE_CHECKING:
|
|
|
17
17
|
from types import TracebackType
|
|
18
18
|
|
|
19
19
|
from .edge_event import EdgeEvent
|
|
20
|
+
from .line import Value
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
__all__ = ["LineRequest"]
|
|
@@ -36,7 +37,6 @@ class LineRequest:
|
|
|
36
37
|
self._chip_name: str
|
|
37
38
|
self._offsets: list[int]
|
|
38
39
|
self._name_map: dict[str, int]
|
|
39
|
-
self._offset_map: dict[int, str]
|
|
40
40
|
self._lines: list[Union[int, str]]
|
|
41
41
|
|
|
42
42
|
def __bool__(self) -> bool:
|
|
@@ -76,7 +76,7 @@ class LineRequest:
|
|
|
76
76
|
not be used after a call to this method.
|
|
77
77
|
"""
|
|
78
78
|
self._check_released()
|
|
79
|
-
cast(_ext.Request, self._req).release()
|
|
79
|
+
cast("_ext.Request", self._req).release()
|
|
80
80
|
self._req = None
|
|
81
81
|
|
|
82
82
|
def get_value(self, line: Union[int, str]) -> Value:
|
|
@@ -95,12 +95,9 @@ class LineRequest:
|
|
|
95
95
|
def _line_to_offset(self, line: Union[int, str]) -> int:
|
|
96
96
|
if isinstance(line, int):
|
|
97
97
|
return line
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
raise ValueError(f"unknown line name: {line}")
|
|
102
|
-
else:
|
|
103
|
-
return _line
|
|
98
|
+
if (_line := self._name_map.get(line)) is None:
|
|
99
|
+
raise ValueError(f"unknown line name: {line}")
|
|
100
|
+
return _line
|
|
104
101
|
|
|
105
102
|
def get_values(
|
|
106
103
|
self, lines: Optional[Iterable[Union[int, str]]] = None
|
|
@@ -122,9 +119,9 @@ class LineRequest:
|
|
|
122
119
|
|
|
123
120
|
offsets = [self._line_to_offset(line) for line in lines]
|
|
124
121
|
|
|
125
|
-
buf = cast(list[Value], [None] * len(offsets))
|
|
122
|
+
buf = cast("list[Value]", [None] * len(offsets))
|
|
126
123
|
|
|
127
|
-
cast(_ext.Request, self._req).get_values(offsets, buf)
|
|
124
|
+
cast("_ext.Request", self._req).get_values(offsets, buf)
|
|
128
125
|
return buf
|
|
129
126
|
|
|
130
127
|
def set_value(self, line: Union[int, str], value: Value) -> None:
|
|
@@ -151,7 +148,7 @@ class LineRequest:
|
|
|
151
148
|
|
|
152
149
|
mapped = {self._line_to_offset(line): value for line, value in values.items()}
|
|
153
150
|
|
|
154
|
-
cast(_ext.Request, self._req).set_values(mapped)
|
|
151
|
+
cast("_ext.Request", self._req).set_values(mapped)
|
|
155
152
|
|
|
156
153
|
def reconfigure_lines(
|
|
157
154
|
self,
|
|
@@ -174,19 +171,30 @@ class LineRequest:
|
|
|
174
171
|
line_cfg = _ext.LineConfig()
|
|
175
172
|
line_settings = {}
|
|
176
173
|
|
|
177
|
-
for
|
|
178
|
-
|
|
179
|
-
lines = [lines]
|
|
180
|
-
|
|
181
|
-
for line in lines:
|
|
174
|
+
for line, settings in config_iter(config):
|
|
175
|
+
try:
|
|
182
176
|
offset = self._line_to_offset(line)
|
|
183
|
-
|
|
177
|
+
if offset in self.offsets:
|
|
178
|
+
line_settings[offset] = settings
|
|
179
|
+
else:
|
|
180
|
+
warnings.warn(
|
|
181
|
+
f"Line offset '{offset}' was not included in original request.",
|
|
182
|
+
stacklevel=2,
|
|
183
|
+
)
|
|
184
|
+
except ValueError:
|
|
185
|
+
# _line_to_offset will raise a ValueError when it encounters
|
|
186
|
+
# an unrecognized line name. Ignore these like we do offsets
|
|
187
|
+
# that were not in the original request.
|
|
188
|
+
warnings.warn(
|
|
189
|
+
f"Line name '{line}' was not included in original request.",
|
|
190
|
+
stacklevel=2,
|
|
191
|
+
)
|
|
184
192
|
|
|
185
193
|
for offset in self.offsets:
|
|
186
194
|
settings = line_settings.get(offset) or LineSettings()
|
|
187
195
|
line_cfg.add_line_settings([offset], _line_settings_to_ext(settings))
|
|
188
196
|
|
|
189
|
-
cast(_ext.Request, self._req).reconfigure_lines(line_cfg)
|
|
197
|
+
cast("_ext.Request", self._req).reconfigure_lines(line_cfg)
|
|
190
198
|
|
|
191
199
|
def wait_edge_events(
|
|
192
200
|
self, timeout: Optional[Union[timedelta, float]] = None
|
|
@@ -220,7 +228,7 @@ class LineRequest:
|
|
|
220
228
|
"""
|
|
221
229
|
self._check_released()
|
|
222
230
|
|
|
223
|
-
return cast(_ext.Request, self._req).read_edge_events(max_events)
|
|
231
|
+
return cast("_ext.Request", self._req).read_edge_events(max_events)
|
|
224
232
|
|
|
225
233
|
def fileno(self) -> int:
|
|
226
234
|
"""
|
|
@@ -276,4 +284,4 @@ class LineRequest:
|
|
|
276
284
|
File descriptor associated with this request.
|
|
277
285
|
"""
|
|
278
286
|
self._check_released()
|
|
279
|
-
return cast(_ext.Request, self._req).fd
|
|
287
|
+
return cast("_ext.Request", self._req).fd
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: gpiod
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Python bindings for libgpiod
|
|
5
5
|
Author-email: Bartosz Golaszewski <brgl@bgdev.pl>
|
|
6
|
-
License: LGPL-2.1-or-later
|
|
6
|
+
License-Expression: LGPL-2.1-or-later
|
|
7
7
|
Project-URL: Homepage, https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
|
|
8
8
|
Project-URL: Issues, https://github.com/brgl/libgpiod/issues/
|
|
9
9
|
Platform: linux
|
|
10
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
|
|
12
11
|
Classifier: Operating System :: POSIX :: Linux
|
|
13
12
|
Classifier: Typing :: Typed
|
|
14
13
|
Classifier: Programming Language :: Python
|
|
@@ -19,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
22
|
Requires-Python: >=3.9.0
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
24
|
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
#define LINES_MAX (GPIO_V2_LINES_MAX)
|
|
14
14
|
|
|
15
15
|
struct settings_node {
|
|
16
|
+
struct settings_node *prev;
|
|
16
17
|
struct settings_node *next;
|
|
17
18
|
struct gpiod_line_settings *settings;
|
|
19
|
+
unsigned int refcnt;
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
struct per_line_config {
|
|
@@ -93,7 +95,7 @@ GPIOD_API int gpiod_line_config_add_line_settings(
|
|
|
93
95
|
size_t num_offsets, struct gpiod_line_settings *settings)
|
|
94
96
|
{
|
|
95
97
|
struct per_line_config *per_line;
|
|
96
|
-
struct settings_node *node;
|
|
98
|
+
struct settings_node *node, *old;
|
|
97
99
|
size_t i;
|
|
98
100
|
|
|
99
101
|
assert(config);
|
|
@@ -121,14 +123,29 @@ GPIOD_API int gpiod_line_config_add_line_settings(
|
|
|
121
123
|
return -1;
|
|
122
124
|
}
|
|
123
125
|
|
|
126
|
+
node->refcnt = 0;
|
|
124
127
|
node->next = config->sref_list;
|
|
128
|
+
if (config->sref_list)
|
|
129
|
+
config->sref_list->prev = node;
|
|
130
|
+
node->prev = NULL;
|
|
125
131
|
config->sref_list = node;
|
|
126
132
|
|
|
127
133
|
for (i = 0; i < num_offsets; i++) {
|
|
128
134
|
per_line = find_config(config, offsets[i]);
|
|
129
135
|
|
|
136
|
+
node->refcnt++;
|
|
130
137
|
per_line->offset = offsets[i];
|
|
138
|
+
old = per_line->node;
|
|
131
139
|
per_line->node = node;
|
|
140
|
+
|
|
141
|
+
if (old && !(--old->refcnt)) {
|
|
142
|
+
if (old->prev)
|
|
143
|
+
old->prev->next = old->next;
|
|
144
|
+
if (old->next)
|
|
145
|
+
old->next->prev = old->prev;
|
|
146
|
+
free(old->settings);
|
|
147
|
+
free(old);
|
|
148
|
+
}
|
|
132
149
|
}
|
|
133
150
|
|
|
134
151
|
return 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.2.2
|
|
@@ -10,14 +10,13 @@ name = "gpiod"
|
|
|
10
10
|
dynamic = ["version"]
|
|
11
11
|
description = "Python bindings for libgpiod"
|
|
12
12
|
readme = "README.md"
|
|
13
|
-
license =
|
|
13
|
+
license = "LGPL-2.1-or-later"
|
|
14
14
|
requires-python = ">=3.9.0"
|
|
15
15
|
authors = [
|
|
16
16
|
{name = "Bartosz Golaszewski", email = "brgl@bgdev.pl"},
|
|
17
17
|
]
|
|
18
18
|
classifiers = [
|
|
19
19
|
"Development Status :: 5 - Production/Stable",
|
|
20
|
-
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
|
|
21
20
|
"Operating System :: POSIX :: Linux",
|
|
22
21
|
"Typing :: Typed",
|
|
23
22
|
"Programming Language :: Python",
|
|
@@ -28,6 +27,7 @@ classifiers = [
|
|
|
28
27
|
"Programming Language :: Python :: 3.11",
|
|
29
28
|
"Programming Language :: Python :: 3.12",
|
|
30
29
|
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Programming Language :: Python :: 3.14",
|
|
31
31
|
]
|
|
32
32
|
|
|
33
33
|
[project.urls]
|
|
@@ -74,9 +74,15 @@ ignore=[
|
|
|
74
74
|
"E501",
|
|
75
75
|
# Ignore new Union (|) syntax until we require 3.10+
|
|
76
76
|
"UP007",
|
|
77
|
+
"UP045",
|
|
77
78
|
]
|
|
78
79
|
|
|
79
80
|
[tool.ruff.lint.per-file-ignores]
|
|
80
81
|
"gpiod/__init__.py" = ["F403", "F405"] # ignore warnings about star imports
|
|
81
82
|
"tests/__main__.py" = ["F403"]
|
|
82
|
-
"tests/**.py" = ["F841"] # ignore warnings about unused variables
|
|
83
|
+
"tests/**.py" = ["F841"] # ignore warnings about unused variables
|
|
84
|
+
|
|
85
|
+
[tool.cibuildwheel]
|
|
86
|
+
build = "cp*"
|
|
87
|
+
skip = "cp31?t-*" # Do not build free-threaded wheels
|
|
88
|
+
archs = ["x86_64", "aarch64"]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
2
2
|
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
3
3
|
|
|
4
|
+
import warnings
|
|
4
5
|
from unittest import TestCase
|
|
5
6
|
|
|
6
7
|
import gpiod
|
|
@@ -71,7 +72,9 @@ class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase):
|
|
|
71
72
|
|
|
72
73
|
class ChipLineRequestWorks(TestCase):
|
|
73
74
|
def setUp(self) -> None:
|
|
74
|
-
self.sim = gpiosim.Chip(
|
|
75
|
+
self.sim = gpiosim.Chip(
|
|
76
|
+
num_lines=8, line_names={0: "fizz", 1: "fizz", 5: "foo", 7: "bar"}
|
|
77
|
+
)
|
|
75
78
|
self.chip = gpiod.Chip(self.sim.dev_path)
|
|
76
79
|
|
|
77
80
|
def tearDown(self) -> None:
|
|
@@ -101,6 +104,10 @@ class ChipLineRequestWorks(TestCase):
|
|
|
101
104
|
with self.chip.request_lines(config={(4): None}) as req:
|
|
102
105
|
self.assertEqual(req.offsets, [4])
|
|
103
106
|
|
|
107
|
+
def test_request_single_offset_as_frozenset(self) -> None:
|
|
108
|
+
with self.chip.request_lines(config={frozenset([4]): None}) as req:
|
|
109
|
+
self.assertEqual(req.offsets, [4])
|
|
110
|
+
|
|
104
111
|
def test_request_by_name(self) -> None:
|
|
105
112
|
with self.chip.request_lines(config={(1, 2, "foo", "bar"): None}) as req:
|
|
106
113
|
self.assertEqual(req.offsets, [1, 2, 5, 7])
|
|
@@ -109,6 +116,16 @@ class ChipLineRequestWorks(TestCase):
|
|
|
109
116
|
with self.chip.request_lines(config={"foo": None}) as req:
|
|
110
117
|
self.assertEqual(req.offsets, [5])
|
|
111
118
|
|
|
119
|
+
def test_request_line_with_duplicate_names_by_offset(self) -> None:
|
|
120
|
+
with self.chip.request_lines(config={(1, 0): None}) as req:
|
|
121
|
+
self.assertEqual(req.offsets, [1, 0])
|
|
122
|
+
self.assertEqual(req.lines, [1, 0])
|
|
123
|
+
|
|
124
|
+
def test_request_line_with_duplicate_names_mixed_mode(self) -> None:
|
|
125
|
+
with self.chip.request_lines(config={(1, "fizz"): None}) as req:
|
|
126
|
+
self.assertEqual(req.offsets, [1, 0])
|
|
127
|
+
self.assertEqual(req.lines, [1, "fizz"])
|
|
128
|
+
|
|
112
129
|
|
|
113
130
|
class ModuleLineRequestWorks(TestCase):
|
|
114
131
|
def setUp(self) -> None:
|
|
@@ -496,11 +513,13 @@ class LineRequestSetOutputValues(TestCase):
|
|
|
496
513
|
|
|
497
514
|
class ReconfigureRequestedLines(TestCase):
|
|
498
515
|
def setUp(self) -> None:
|
|
499
|
-
self.sim = gpiosim.Chip(
|
|
516
|
+
self.sim = gpiosim.Chip(
|
|
517
|
+
num_lines=8, line_names={2: "fizz", 3: "foo", 4: "bar", 6: "baz", 7: "foo"}
|
|
518
|
+
)
|
|
500
519
|
self.chip = gpiod.Chip(self.sim.dev_path)
|
|
501
520
|
self.req = self.chip.request_lines(
|
|
502
521
|
{
|
|
503
|
-
(0, 2, "foo", "baz"): gpiod.LineSettings(
|
|
522
|
+
(7, 0, 2, "foo", "baz"): gpiod.LineSettings(
|
|
504
523
|
direction=Direction.OUTPUT, active_low=True, drive=Drive.OPEN_DRAIN
|
|
505
524
|
)
|
|
506
525
|
}
|
|
@@ -526,7 +545,7 @@ class ReconfigureRequestedLines(TestCase):
|
|
|
526
545
|
info = self.chip.get_line_info(2)
|
|
527
546
|
self.assertEqual(info.direction, Direction.OUTPUT)
|
|
528
547
|
self.req.reconfigure_lines(
|
|
529
|
-
{(0,
|
|
548
|
+
{(0, "fizz", "foo", "baz"): gpiod.LineSettings(direction=Direction.INPUT)}
|
|
530
549
|
)
|
|
531
550
|
info = self.chip.get_line_info(2)
|
|
532
551
|
self.assertEqual(info.direction, Direction.INPUT)
|
|
@@ -586,12 +605,46 @@ class ReconfigureRequestedLines(TestCase):
|
|
|
586
605
|
def test_reconfigure_extra_offsets(self) -> None:
|
|
587
606
|
info = self.chip.get_line_info(2)
|
|
588
607
|
self.assertEqual(info.direction, Direction.OUTPUT)
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
608
|
+
with warnings.catch_warnings(record=True) as w:
|
|
609
|
+
self.req.reconfigure_lines(
|
|
610
|
+
{(0, 2, 3, 6, 5): gpiod.LineSettings(direction=Direction.INPUT)}
|
|
611
|
+
)
|
|
612
|
+
assert len(w) == 1
|
|
613
|
+
assert issubclass(w[0].category, UserWarning)
|
|
614
|
+
assert "Line offset '5'" in str(w[0].message)
|
|
615
|
+
info = self.chip.get_line_info(2)
|
|
616
|
+
self.assertEqual(info.direction, Direction.INPUT)
|
|
617
|
+
|
|
618
|
+
def test_reconfigure_extra_names(self) -> None:
|
|
619
|
+
info = self.chip.get_line_info(2)
|
|
620
|
+
self.assertEqual(info.direction, Direction.OUTPUT)
|
|
621
|
+
with warnings.catch_warnings(record=True) as w:
|
|
622
|
+
self.req.reconfigure_lines(
|
|
623
|
+
{
|
|
624
|
+
(0, 2, "foo", "baz", "buzz"): gpiod.LineSettings(
|
|
625
|
+
direction=Direction.INPUT
|
|
626
|
+
)
|
|
627
|
+
}
|
|
628
|
+
)
|
|
629
|
+
assert len(w) == 1
|
|
630
|
+
assert issubclass(w[0].category, UserWarning)
|
|
631
|
+
assert "Line name 'buzz'" in str(w[0].message)
|
|
592
632
|
info = self.chip.get_line_info(2)
|
|
593
633
|
self.assertEqual(info.direction, Direction.INPUT)
|
|
594
634
|
|
|
635
|
+
def test_reconfigure_duplicate_names_with_offset(self) -> None:
|
|
636
|
+
info3 = self.chip.get_line_info(3)
|
|
637
|
+
info7 = self.chip.get_line_info(7)
|
|
638
|
+
self.assertEqual(info3.direction, Direction.OUTPUT)
|
|
639
|
+
self.assertEqual(info7.direction, Direction.OUTPUT)
|
|
640
|
+
self.req.reconfigure_lines(
|
|
641
|
+
{("foo", 7): gpiod.LineSettings(direction=Direction.INPUT)}
|
|
642
|
+
)
|
|
643
|
+
info3 = self.chip.get_line_info(3)
|
|
644
|
+
info7 = self.chip.get_line_info(7)
|
|
645
|
+
self.assertEqual(info3.direction, Direction.INPUT)
|
|
646
|
+
self.assertEqual(info7.direction, Direction.INPUT)
|
|
647
|
+
|
|
595
648
|
|
|
596
649
|
class ReleasedLineRequestCannotBeUsed(TestCase):
|
|
597
650
|
def test_using_released_line_request(self) -> None:
|
|
@@ -50,7 +50,7 @@ class IsGPIOChip(TestCase):
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
class VersionString(TestCase):
|
|
53
|
-
VERSION_PATTERN = "^\\d+\\.\\d
|
|
53
|
+
VERSION_PATTERN = "^\\d+\\.\\d+\\.\\d+$"
|
|
54
54
|
|
|
55
55
|
def test_api_version_string(self) -> None:
|
|
56
56
|
self.assertRegex(gpiod.api_version, VersionString.VERSION_PATTERN)
|
gpiod-2.3.0/gpiod/_internal.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
2
|
-
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
3
|
-
|
|
4
|
-
from datetime import timedelta
|
|
5
|
-
from select import select
|
|
6
|
-
from typing import Optional, Union
|
|
7
|
-
|
|
8
|
-
__all__ = ["poll_fd"]
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool:
|
|
12
|
-
sec: Union[float, None]
|
|
13
|
-
if isinstance(timeout, timedelta):
|
|
14
|
-
sec = timeout.total_seconds()
|
|
15
|
-
else:
|
|
16
|
-
sec = timeout
|
|
17
|
-
|
|
18
|
-
readable, _, _ = select([fd], [], [], sec)
|
|
19
|
-
return True if fd in readable else False
|
gpiod-2.3.0/libgpiod-version.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.2.1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|