-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from tiagocoutinho/gpio
Add support for GPIO
- Loading branch information
Showing
14 changed files
with
1,127 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ⚡ GPIO API | ||
|
||
::: linuxpy.gpio.device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ⚡ GPIO | ||
|
||
Human friendly interface to linux GPIO handling. | ||
|
||
Without further ado: | ||
|
||
<div class="termy" data-ty-macos> | ||
<span data-ty="input" data-ty-prompt="$">python</span> | ||
<span data-ty="input" data-ty-prompt=">>>">from linuxpy.gpio import find</span> | ||
<span data-ty="input" data-ty-prompt=">>>">with find() as gpio:</span> | ||
<span data-ty="input" data-ty-prompt="..."> with gpio[1, 2, 5:8] as lines:</span> | ||
<span data-ty="input" data-ty-prompt=">>>"> print(lines[:])</span> | ||
<span data-ty>{1: 0, 2: 1, 5: 0, 6: 1, 7:0}</span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# | ||
# This file is part of the linuxpy project | ||
# | ||
# Copyright (c) 2024 Tiago Coutinho | ||
# Distributed under the GPLv3 license. See LICENSE for more info. | ||
|
||
import pathlib | ||
|
||
from linuxpy.codegen.base import CEnum, run | ||
|
||
HEADERS = [ | ||
"/usr/include/linux/gpio.h", | ||
] | ||
|
||
|
||
TEMPLATE = """\ | ||
# | ||
# This file is part of the linuxpy project | ||
# | ||
# Copyright (c) 2024 Tiago Coutinho | ||
# Distributed under the GPLv3 license. See LICENSE for more info. | ||
# This file has been generated by {name} | ||
# Date: {date} | ||
# System: {system} | ||
# Release: {release} | ||
# Version: {version} | ||
import enum | ||
from linuxpy.ioctl import IOR as _IOR, IOW as _IOW, IOWR as _IOWR | ||
from linuxpy.ctypes import u8, u16, u32, cuint, cint, cchar, culonglong | ||
from linuxpy.ctypes import Struct, Union, POINTER, cvoidp | ||
class GpioLineEvent(enum.IntEnum): | ||
REQUESTED = 1 | ||
RELEASED = 2 | ||
CONFIG = 3 | ||
{enums_body} | ||
{structs_body} | ||
{iocs_body}""" | ||
|
||
|
||
class IOC(CEnum): | ||
def __init__(self): | ||
def filter(name, value): | ||
return name.endswith("_IOCTL") | ||
|
||
super().__init__("IOC", ["GPIO_GET_", "GPIO_V2_"], filter=filter) | ||
|
||
def add_item(self, name, value): | ||
name = name.removesuffix("_IOCTL") | ||
return super().add_item(name, value) | ||
|
||
|
||
# macros from #define statements | ||
MACRO_ENUMS = [ | ||
IOC(), | ||
] | ||
|
||
|
||
this_dir = pathlib.Path(__file__).parent | ||
|
||
|
||
def decode_name(name: str) -> str: | ||
return name.removeprefix("gpio_v2_").removeprefix("gpio_") | ||
|
||
|
||
def main(output=this_dir.parent / "gpio" / "raw.py"): | ||
run(__name__, HEADERS, TEMPLATE, MACRO_ENUMS, output=output, decode_enum_name=decode_name) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# This file is part of the linuxpy project | ||
# | ||
# Copyright (c) 2024 Tiago Coutinho | ||
# Distributed under the GPLv3 license. See LICENSE for more info. |
Oops, something went wrong.