mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-25 12:39:18 +03:00
PEP 703 [0] discusses making the GIL optional in certain builds of the CPython interpreter. This build option was available experiementally in Python 3.13 but has since been stabilized in Python 3.14 per PEP 779 [1]. According to the porting guide [2], there is no strict requirement that C extensions must be thread-safe. Experiments have shown that no logic changes are required if callers use sychronization mechanisms provided by the Python standard library. The documentation has been updated to call this out specifically using terminology from the porting guide [3]. [0]: https://peps.python.org/pep-0703/ [1]: https://peps.python.org/pep-0779/ [2]: https://py-free-threading.github.io/porting/#define-and-document-thread-safety-guarantees [3]: https://py-free-threading.github.io/documentation-principles/#free-threading-terminology Signed-off-by: Vincent Fazio <vfazio@gmail.com> Link: https://patch.msgid.link/20260527215922.18678-3-vfazio@gmail.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
|
|
from dataclasses import dataclass
|
|
from datetime import timedelta
|
|
|
|
from . import _ext
|
|
from .line import Bias, Clock, Direction, Drive, Edge, Value
|
|
|
|
__all__ = ["LineSettings"]
|
|
|
|
|
|
@dataclass(repr=False)
|
|
class LineSettings:
|
|
"""
|
|
Stores a set of line properties.
|
|
|
|
Synchronization: none required
|
|
"""
|
|
|
|
direction: Direction = Direction.AS_IS
|
|
"""Line direction."""
|
|
edge_detection: Edge = Edge.NONE
|
|
"""Edge detection setting."""
|
|
bias: Bias = Bias.AS_IS
|
|
"""Line bias setting."""
|
|
drive: Drive = Drive.PUSH_PULL
|
|
"""Line drive setting."""
|
|
active_low: bool = False
|
|
"""Active-low switch."""
|
|
debounce_period: timedelta = timedelta()
|
|
"""Debounce period of the line."""
|
|
event_clock: Clock = Clock.MONOTONIC
|
|
"""Edge event timestamping clock setting."""
|
|
output_value: Value = Value.INACTIVE
|
|
"""Output value of the line."""
|
|
|
|
# __repr__ generated by @dataclass uses repr for enum members resulting in
|
|
# an unusable representation as those are of the form: <NAME: $value>
|
|
def __repr__(self) -> str:
|
|
return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format( # noqa: UP032
|
|
str(self.direction),
|
|
str(self.edge_detection),
|
|
str(self.bias),
|
|
str(self.drive),
|
|
self.active_low,
|
|
repr(self.debounce_period),
|
|
str(self.event_clock),
|
|
str(self.output_value),
|
|
)
|
|
|
|
def __str__(self) -> str:
|
|
return "<LineSettings direction={} edge_detection={} bias={} drive={} active_low={} debounce_period={} event_clock={} output_value={}>".format( # noqa: UP032
|
|
self.direction,
|
|
self.edge_detection,
|
|
self.bias,
|
|
self.drive,
|
|
self.active_low,
|
|
self.debounce_period,
|
|
self.event_clock,
|
|
self.output_value,
|
|
)
|
|
|
|
|
|
def _line_settings_to_ext(settings: LineSettings) -> _ext.LineSettings:
|
|
return _ext.LineSettings(
|
|
direction=settings.direction.value,
|
|
edge_detection=settings.edge_detection.value,
|
|
bias=settings.bias.value,
|
|
drive=settings.drive.value,
|
|
active_low=settings.active_low,
|
|
debounce_period=int(settings.debounce_period.total_seconds() * 1000000),
|
|
event_clock=settings.event_clock.value,
|
|
output_value=settings.output_value.value,
|
|
)
|