mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-25 12:39:18 +03:00
* Update pyproject.toml to require Python 3.10+ for runtime * Update mypy's target version to 3.10 syntax * Drop ruff's target version as it's inferred by the project's requires-python value * Remove the linter settings that ignored UP007 & UP0045 * Update type annotations to conform to active linter rules Closes: https://github.com/brgl/libgpiod/issues/151 Signed-off-by: Vincent Fazio <vfazio@gmail.com> Link: https://patch.msgid.link/20260329182832.39824-1-vfazio@gmail.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
|
|
from enum import Enum
|
|
|
|
from . import _ext
|
|
|
|
|
|
class Chip:
|
|
"""
|
|
Represents a simulated GPIO chip.
|
|
"""
|
|
|
|
class Pull(Enum):
|
|
DOWN = _ext.PULL_DOWN
|
|
UP = _ext.PULL_UP
|
|
|
|
class Value(Enum):
|
|
INACTIVE = _ext.VALUE_INACTIVE
|
|
ACTIVE = _ext.VALUE_ACTIVE
|
|
|
|
class Direction(Enum):
|
|
INPUT = _ext.DIRECTION_INPUT
|
|
OUTPUT_HIGH = _ext.DIRECTION_OUTPUT_HIGH
|
|
OUTPUT_LOW = _ext.DIRECTION_OUTPUT_LOW
|
|
|
|
def __init__(
|
|
self,
|
|
label: str | None = None,
|
|
num_lines: int | None = None,
|
|
line_names: dict[int, str] | None = None,
|
|
hogs: dict[int, tuple[str, Direction]] | None = None,
|
|
):
|
|
self._chip = _ext.Chip()
|
|
|
|
if label:
|
|
self._chip.set_label(label)
|
|
|
|
if num_lines:
|
|
self._chip.set_num_lines(num_lines)
|
|
|
|
if line_names:
|
|
for off, name in line_names.items():
|
|
self._chip.set_line_name(off, name)
|
|
|
|
if hogs:
|
|
for off, (name, direction) in hogs.items():
|
|
self._chip.set_hog(off, name, direction.value)
|
|
|
|
self._chip.enable()
|
|
|
|
def get_value(self, offset: int) -> Value:
|
|
val = self._chip.get_value(offset)
|
|
return Chip.Value(val)
|
|
|
|
def set_pull(self, offset: int, pull: Pull) -> None:
|
|
self._chip.set_pull(offset, pull.value)
|
|
|
|
@property
|
|
def dev_path(self) -> str:
|
|
return self._chip.dev_path
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return self._chip.name
|