python-periphery 2.4.0__tar.gz → 2.4.2__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.
- python_periphery-2.4.2/.flake8 +2 -0
- python_periphery-2.4.2/.github/workflows/tests.yml +53 -0
- python_periphery-2.4.2/.gitignore +6 -0
- python_periphery-2.4.2/.readthedocs.yaml +13 -0
- python_periphery-2.4.2/CHANGELOG.md +126 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/LICENSE +1 -1
- {python-periphery-2.4.0/python_periphery.egg-info → python_periphery-2.4.2}/PKG-INFO +11 -2
- {python-periphery-2.4.0 → python_periphery-2.4.2}/README.md +1 -1
- python_periphery-2.4.2/docs/Makefile +20 -0
- python_periphery-2.4.2/docs/conf.py +48 -0
- python_periphery-2.4.2/docs/gpio.rst +51 -0
- python_periphery-2.4.2/docs/i2c.rst +33 -0
- python_periphery-2.4.2/docs/index.rst +30 -0
- python_periphery-2.4.2/docs/led.rst +37 -0
- python_periphery-2.4.2/docs/mmio.rst +46 -0
- python_periphery-2.4.2/docs/pwm.rst +38 -0
- python_periphery-2.4.2/docs/requirements.txt +2 -0
- python_periphery-2.4.2/docs/serial.rst +34 -0
- python_periphery-2.4.2/docs/spi.rst +34 -0
- python_periphery-2.4.2/docs/version.rst +8 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/__init__.py +2 -2
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/gpio_cdev2.py +2 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/i2c.py +1 -1
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/spi.py +11 -10
- {python-periphery-2.4.0 → python_periphery-2.4.2/python_periphery.egg-info}/PKG-INFO +11 -2
- {python-periphery-2.4.0 → python_periphery-2.4.2}/python_periphery.egg-info/SOURCES.txt +18 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/setup.py +1 -1
- python_periphery-2.4.2/tests/__init__.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/__init__.pyi +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/gpio.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/gpio.pyi +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/gpio_cdev1.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/gpio_sysfs.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/i2c.pyi +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/led.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/led.pyi +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/mmio.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/mmio.pyi +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/pwm.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/pwm.pyi +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/py.typed +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/serial.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/serial.pyi +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/periphery/spi.pyi +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/python_periphery.egg-info/dependency_links.txt +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/python_periphery.egg-info/top_level.txt +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/setup.cfg +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test_gpio.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test_gpio_sysfs.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test_i2c.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test_led.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test_mmio.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test_pwm.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test_serial.py +0 -0
- {python-periphery-2.4.0 → python_periphery-2.4.2}/tests/test_spi.py +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
- push
|
|
5
|
+
- pull_request
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
strategy:
|
|
10
|
+
fail-fast: false
|
|
11
|
+
matrix:
|
|
12
|
+
container: ["python:2.7-slim", "python:3.5-slim", "python:3.6-slim", "python:3.7-slim",
|
|
13
|
+
"python:3.8-slim", "python:3.9-slim", "python:3.10-slim", "python:3.11-slim",
|
|
14
|
+
"python:3.12-slim", "python:3.13-slim", "pypy:2.7-slim", "pypy:3.11-slim"]
|
|
15
|
+
include:
|
|
16
|
+
- check-types: true
|
|
17
|
+
- container: "python:2.7-slim"
|
|
18
|
+
check-types: false
|
|
19
|
+
- container: "python:3.5-slim"
|
|
20
|
+
check-types: false
|
|
21
|
+
- container: "pypy:2.7-slim"
|
|
22
|
+
check-types: false
|
|
23
|
+
- container: "pypy:3.11-slim"
|
|
24
|
+
check-types: false
|
|
25
|
+
|
|
26
|
+
runs-on: ubuntu-24.04
|
|
27
|
+
container: ${{ matrix.container }}
|
|
28
|
+
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v4
|
|
31
|
+
|
|
32
|
+
- name: Upgrade pip
|
|
33
|
+
run: python -m pip install --upgrade pip
|
|
34
|
+
|
|
35
|
+
- name: Install mypy
|
|
36
|
+
if: ${{ matrix.check-types }}
|
|
37
|
+
run: python -m pip install mypy
|
|
38
|
+
|
|
39
|
+
- name: Check Types
|
|
40
|
+
if: ${{ matrix.check-types }}
|
|
41
|
+
run: mypy periphery
|
|
42
|
+
|
|
43
|
+
- name: Run tests
|
|
44
|
+
run: |
|
|
45
|
+
python --version
|
|
46
|
+
python -m tests.test_gpio
|
|
47
|
+
python -m tests.test_gpio_sysfs
|
|
48
|
+
python -m tests.test_spi
|
|
49
|
+
python -m tests.test_i2c
|
|
50
|
+
python -m tests.test_mmio
|
|
51
|
+
python -m tests.test_serial
|
|
52
|
+
python -m tests.test_led
|
|
53
|
+
python -m tests.test_pwm
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
* v2.4.2 - 09/15/2026
|
|
2
|
+
* I2C
|
|
3
|
+
* Fix buffer size for `I2C_FUNCS` `ioctl()`.
|
|
4
|
+
* Contributors
|
|
5
|
+
* Florian Larysch (@florolf) - bb7c82e
|
|
6
|
+
|
|
7
|
+
* v2.4.1 - 04/21/2023
|
|
8
|
+
* GPIO
|
|
9
|
+
* Fix realtime timestamp reporting for line events in gpio-cdev v2
|
|
10
|
+
implementation.
|
|
11
|
+
|
|
12
|
+
* v2.4.0 - 04/17/2023
|
|
13
|
+
* GPIO
|
|
14
|
+
* Avoid writing `direction` and `inverted` on open to retain existing
|
|
15
|
+
state with sysfs GPIOs
|
|
16
|
+
* Add support for gpio-cdev v2 ABI.
|
|
17
|
+
* Add type stubs.
|
|
18
|
+
* Contributors
|
|
19
|
+
* Juho Kim, @AussieSeaweed - ea1ecc2
|
|
20
|
+
|
|
21
|
+
* v2.3.0 - 02/14/2021
|
|
22
|
+
* GPIO
|
|
23
|
+
* Add kernel version check for line bias support.
|
|
24
|
+
* Fix docstring for `close()`.
|
|
25
|
+
* SPI
|
|
26
|
+
* Add kernel version check for 32-bit mode support.
|
|
27
|
+
* MMIO
|
|
28
|
+
* Fix duplicate transactions in integral read and write methods.
|
|
29
|
+
* Fix memory offset of `pointer` property.
|
|
30
|
+
* Contributors
|
|
31
|
+
* Michael Murton, @CrazyIvan359 - 9c1a4f3
|
|
32
|
+
* @paul-demo - b318a6a
|
|
33
|
+
|
|
34
|
+
* v2.2.0 - 12/16/2020
|
|
35
|
+
* MMIO
|
|
36
|
+
* Add `path` keyword argument to constructor for use with alternate
|
|
37
|
+
memory character devices (e.g. `/dev/gpiomem`).
|
|
38
|
+
* SPI
|
|
39
|
+
* Add support for 32-bit flags to `extra_flags` property and
|
|
40
|
+
constructor.
|
|
41
|
+
|
|
42
|
+
* v2.1.1 - 11/19/2020
|
|
43
|
+
* GPIO
|
|
44
|
+
* Add direction checks for improved error reporting to `write()`,
|
|
45
|
+
`read_event()`, and `poll()` for character device GPIOs.
|
|
46
|
+
* Contributors
|
|
47
|
+
* Michael Murton, @CrazyIvan359 - 69bd36e
|
|
48
|
+
|
|
49
|
+
* v2.1.0 - 05/29/2020
|
|
50
|
+
* GPIO
|
|
51
|
+
* Add `poll_multiple()` static method.
|
|
52
|
+
* Add line consumer `label` property.
|
|
53
|
+
* Add line `bias`, line `drive`, and `inverted` properties.
|
|
54
|
+
* Add additional properties as keyword arguments to constructor for
|
|
55
|
+
character device GPIOs.
|
|
56
|
+
* Only unexport GPIO in `close()` if exported in open for sysfs GPIOs.
|
|
57
|
+
* Improve wording and fix typos in docstrings.
|
|
58
|
+
* Serial
|
|
59
|
+
* Fix performance of blocking read in `read()`.
|
|
60
|
+
* Raise exception on unexpected empty read in `read()`, which may be
|
|
61
|
+
caused by a serial port disconnect.
|
|
62
|
+
* Add `vmin` and `vtime` properties for the corresponding termios
|
|
63
|
+
settings.
|
|
64
|
+
* Add support for termios timeout with `read()`.
|
|
65
|
+
* Improve wording in docstrings.
|
|
66
|
+
* Contributors
|
|
67
|
+
* @xrombik - 444f778
|
|
68
|
+
* Alexander Steffen, @webmeister - f0403da
|
|
69
|
+
|
|
70
|
+
* v2.0.1 - 01/08/2020
|
|
71
|
+
* PWM
|
|
72
|
+
* Add retry loop for opening PWM period file after export to
|
|
73
|
+
accommodate delayed udev permission rule application.
|
|
74
|
+
* Contributors
|
|
75
|
+
* Jonas Larsson, @jonasl - 28653d4
|
|
76
|
+
|
|
77
|
+
* v2.0.0 - 10/28/2019
|
|
78
|
+
* GPIO
|
|
79
|
+
* Add support for character device GPIOs.
|
|
80
|
+
* Remove support for preserve direction from GPIO constructor.
|
|
81
|
+
* Add retry loop to direction write after export to accommodate delayed
|
|
82
|
+
udev permission rule application for sysfs GPIOs.
|
|
83
|
+
* Unexport GPIO line on close for sysfs GPIOs.
|
|
84
|
+
* Fix handling of `timeout=None` with sysfs GPIO `poll()`.
|
|
85
|
+
* Add `devpath` property.
|
|
86
|
+
* PWM
|
|
87
|
+
* Fix chip and channel argument names in PWM constructor and
|
|
88
|
+
documentation.
|
|
89
|
+
* Add retry loop to PWM open after export to accommodate delayed
|
|
90
|
+
creation of sysfs files by kernel driver.
|
|
91
|
+
* Unexport PWM channel on close.
|
|
92
|
+
* Add nanosecond `period_ns` and `duty_cycle_ns` properties.
|
|
93
|
+
* Add `devpath` property.
|
|
94
|
+
* LED
|
|
95
|
+
* Raise `LookupError` instead of `ValueError` if LED name is not found
|
|
96
|
+
during open.
|
|
97
|
+
* Add `devpath` property.
|
|
98
|
+
* Fix exception handling for Python 2 with `ioctl()` operations in Serial,
|
|
99
|
+
SPI, and I2C modules.
|
|
100
|
+
* Fix `with` statement context manager support for all modules.
|
|
101
|
+
* Update tests with running hints for Raspberry Pi 3.
|
|
102
|
+
* Contributors
|
|
103
|
+
* Uwe Kleine-König, @ukleinek - 0005260
|
|
104
|
+
* Heath Robinson, @ubiquitousthey - ac457d6
|
|
105
|
+
|
|
106
|
+
* v1.1.2 - 06/25/2019
|
|
107
|
+
* Add LICENSE file to packaging.
|
|
108
|
+
|
|
109
|
+
* v1.1.1 - 04/03/2018
|
|
110
|
+
* Fix handling of delayed pin directory export when opening a GPIO.
|
|
111
|
+
|
|
112
|
+
* v1.1.0 - 10/24/2016
|
|
113
|
+
* Add support for preserving pin direction when opening GPIO.
|
|
114
|
+
* Improve GPIO poll() implementation to work with more platforms.
|
|
115
|
+
* Improve atomicity of MMIO fixed width writes.
|
|
116
|
+
* Add PWM module.
|
|
117
|
+
* Add LED module.
|
|
118
|
+
* Add support for universal wheel packaging.
|
|
119
|
+
* Contributors
|
|
120
|
+
* Sanket Dasgupta - 8ac7b40
|
|
121
|
+
* Joseph Kogut - 022ef29, d2e9132
|
|
122
|
+
* Hector Martin - 1e3343a
|
|
123
|
+
* Francesco Valla - 34b3877
|
|
124
|
+
|
|
125
|
+
* v1.0.0 - 06/25/2015
|
|
126
|
+
* Initial release.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2015-
|
|
1
|
+
Copyright (c) 2015-2026 vsergeev / Ivan (Vanya) A. Sergeev
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: python-periphery
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.2
|
|
4
4
|
Summary: A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
|
|
5
5
|
Home-page: https://github.com/vsergeev/python-periphery
|
|
6
6
|
Author: vsergeev
|
|
@@ -19,5 +19,14 @@ Classifier: Topic :: Software Development :: Embedded Systems
|
|
|
19
19
|
Classifier: Topic :: System :: Hardware
|
|
20
20
|
Classifier: Topic :: System :: Hardware :: Hardware Drivers
|
|
21
21
|
License-File: LICENSE
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: classifier
|
|
25
|
+
Dynamic: description
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: keywords
|
|
28
|
+
Dynamic: license
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
Dynamic: summary
|
|
22
31
|
|
|
23
32
|
python-periphery is a pure Python library for GPIO, LED, PWM, SPI, I2C, MMIO, and Serial peripheral I/O interface access in userspace Linux. It is useful in embedded Linux environments (including Raspberry Pi, BeagleBone, etc. platforms) for interfacing with external peripherals. python-periphery is compatible with Python 2 and Python 3, is written in pure Python, and is MIT licensed. See https://github.com/vsergeev/python-periphery for more information.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# python-periphery [](https://github.com/vsergeev/python-periphery/actions/workflows/tests.yml) [](https://python-periphery.readthedocs.io/en/latest/) [](https://github.com/vsergeev/python-periphery) [](https://github.com/vsergeev/python-periphery/blob/master/LICENSE)
|
|
2
2
|
|
|
3
3
|
## Linux Peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) with Python 2 & 3
|
|
4
4
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Minimal makefile for Sphinx documentation
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# You can set these variables from the command line, and also
|
|
5
|
+
# from the environment for the first two.
|
|
6
|
+
SPHINXOPTS ?=
|
|
7
|
+
SPHINXBUILD ?= sphinx-build
|
|
8
|
+
SOURCEDIR = .
|
|
9
|
+
BUILDDIR = _build
|
|
10
|
+
|
|
11
|
+
# Put it first so that "make" without argument is like "make help".
|
|
12
|
+
help:
|
|
13
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
+
|
|
15
|
+
.PHONY: help Makefile
|
|
16
|
+
|
|
17
|
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
+
%: Makefile
|
|
20
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
#
|
|
3
|
+
# For the full list of built-in configuration values, see the documentation:
|
|
4
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
5
|
+
|
|
6
|
+
# -- Path setup --------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
# If extensions (or modules to document with autodoc) are in another directory,
|
|
9
|
+
# add these directories to sys.path here. If the directory is relative to the
|
|
10
|
+
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
sys.path.insert(0, os.path.abspath('..'))
|
|
15
|
+
|
|
16
|
+
# -- Project information -----------------------------------------------------
|
|
17
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
18
|
+
|
|
19
|
+
project = u'python-periphery'
|
|
20
|
+
copyright = u'2015-2026, vsergeev / Ivan (Vanya) A. Sergeev'
|
|
21
|
+
author = u'Vanya A. Sergeev'
|
|
22
|
+
release = '2.4.2'
|
|
23
|
+
|
|
24
|
+
# -- General configuration ---------------------------------------------------
|
|
25
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
26
|
+
|
|
27
|
+
extensions = [
|
|
28
|
+
'sphinx.ext.autodoc',
|
|
29
|
+
'sphinx.ext.napoleon',
|
|
30
|
+
'sphinx.ext.todo',
|
|
31
|
+
'sphinx.ext.viewcode',
|
|
32
|
+
'sphinx_rtd_theme',
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
autoclass_content = 'init'
|
|
36
|
+
autodoc_member_order = 'bysource'
|
|
37
|
+
|
|
38
|
+
templates_path = ['_templates']
|
|
39
|
+
exclude_patterns = ['_build']
|
|
40
|
+
|
|
41
|
+
pygments_style = 'sphinx'
|
|
42
|
+
|
|
43
|
+
# -- Options for HTML output -------------------------------------------------
|
|
44
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
45
|
+
|
|
46
|
+
html_theme = 'sphinx_rtd_theme'
|
|
47
|
+
html_static_path = ['_static']
|
|
48
|
+
html_show_sourcelink = False
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
GPIO
|
|
2
|
+
====
|
|
3
|
+
|
|
4
|
+
Code Example
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
.. code-block:: python
|
|
8
|
+
|
|
9
|
+
from periphery import GPIO
|
|
10
|
+
|
|
11
|
+
# Open GPIO /dev/gpiochip0 line 10 with input direction
|
|
12
|
+
gpio_in = GPIO("/dev/gpiochip0", 10, "in")
|
|
13
|
+
# Open GPIO /dev/gpiochip0 line 12 with output direction
|
|
14
|
+
gpio_out = GPIO("/dev/gpiochip0", 12, "out")
|
|
15
|
+
|
|
16
|
+
value = gpio_in.read()
|
|
17
|
+
gpio_out.write(not value)
|
|
18
|
+
|
|
19
|
+
gpio_in.close()
|
|
20
|
+
gpio_out.close()
|
|
21
|
+
|
|
22
|
+
API
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
.. class:: periphery.GPIO(path, line, direction)
|
|
26
|
+
:noindex:
|
|
27
|
+
|
|
28
|
+
.. autoclass:: periphery.gpio_cdev2.Cdev2GPIO
|
|
29
|
+
:noindex:
|
|
30
|
+
|
|
31
|
+
.. class:: periphery.GPIO(line, direction)
|
|
32
|
+
:noindex:
|
|
33
|
+
|
|
34
|
+
.. autoclass:: periphery.SysfsGPIO
|
|
35
|
+
:noindex:
|
|
36
|
+
|
|
37
|
+
.. autoclass:: periphery.GPIO
|
|
38
|
+
:members:
|
|
39
|
+
:undoc-members:
|
|
40
|
+
:show-inheritance:
|
|
41
|
+
|
|
42
|
+
.. autoclass:: periphery.EdgeEvent
|
|
43
|
+
:members:
|
|
44
|
+
:undoc-members:
|
|
45
|
+
:show-inheritance:
|
|
46
|
+
|
|
47
|
+
.. autoclass:: periphery.GPIOError
|
|
48
|
+
:members:
|
|
49
|
+
:undoc-members:
|
|
50
|
+
:show-inheritance:
|
|
51
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
I2C
|
|
2
|
+
===
|
|
3
|
+
|
|
4
|
+
Code Example
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
.. code-block:: python
|
|
8
|
+
|
|
9
|
+
from periphery import I2C
|
|
10
|
+
|
|
11
|
+
# Open i2c-0 controller
|
|
12
|
+
i2c = I2C("/dev/i2c-0")
|
|
13
|
+
|
|
14
|
+
# Read byte at address 0x100 of EEPROM at 0x50
|
|
15
|
+
msgs = [I2C.Message([0x01, 0x00]), I2C.Message([0x00], read=True)]
|
|
16
|
+
i2c.transfer(0x50, msgs)
|
|
17
|
+
print("0x100: 0x{:02x}".format(msgs[1].data[0]))
|
|
18
|
+
|
|
19
|
+
i2c.close()
|
|
20
|
+
|
|
21
|
+
API
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
.. autoclass:: periphery.I2C
|
|
25
|
+
:members: transfer, close, fd, devpath, Message
|
|
26
|
+
:undoc-members:
|
|
27
|
+
:show-inheritance:
|
|
28
|
+
|
|
29
|
+
.. autoclass:: periphery.I2CError
|
|
30
|
+
:members:
|
|
31
|
+
:undoc-members:
|
|
32
|
+
:show-inheritance:
|
|
33
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.. periphery documentation master file, created by
|
|
2
|
+
sphinx-quickstart2 on Sat Jun 20 18:30:50 2015.
|
|
3
|
+
You can adapt this file completely to your liking, but it should at least
|
|
4
|
+
contain the root `toctree` directive.
|
|
5
|
+
|
|
6
|
+
Welcome to python-periphery's documentation!
|
|
7
|
+
============================================
|
|
8
|
+
|
|
9
|
+
python-periphery is a pure Python library for GPIO, LED, PWM, SPI, I2C, MMIO,
|
|
10
|
+
and Serial peripheral I/O interface access in userspace Linux. It is useful in
|
|
11
|
+
embedded Linux environments (including Raspberry Pi, BeagleBone, etc.
|
|
12
|
+
platforms) for interfacing with external peripherals. python-periphery is
|
|
13
|
+
compatible with Python 2 and Python 3, is written in pure Python, and is MIT
|
|
14
|
+
licensed.
|
|
15
|
+
|
|
16
|
+
Contents
|
|
17
|
+
--------
|
|
18
|
+
|
|
19
|
+
.. toctree::
|
|
20
|
+
:maxdepth: 1
|
|
21
|
+
|
|
22
|
+
gpio
|
|
23
|
+
led
|
|
24
|
+
pwm
|
|
25
|
+
spi
|
|
26
|
+
i2c
|
|
27
|
+
mmio
|
|
28
|
+
serial
|
|
29
|
+
version
|
|
30
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
LED
|
|
2
|
+
====
|
|
3
|
+
|
|
4
|
+
Code Example
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
.. code-block:: python
|
|
8
|
+
|
|
9
|
+
from periphery import LED
|
|
10
|
+
|
|
11
|
+
# Open LED "led0" with initial state off
|
|
12
|
+
led0 = LED("led0", False)
|
|
13
|
+
# Open LED "led1" with initial state on
|
|
14
|
+
led1 = LED("led1", True)
|
|
15
|
+
|
|
16
|
+
value = led0.read()
|
|
17
|
+
led1.write(value)
|
|
18
|
+
|
|
19
|
+
# Set custom brightness level
|
|
20
|
+
led1.write(led1.max_brightness / 2)
|
|
21
|
+
|
|
22
|
+
led0.close()
|
|
23
|
+
led1.close()
|
|
24
|
+
|
|
25
|
+
API
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
.. autoclass:: periphery.LED
|
|
29
|
+
:members:
|
|
30
|
+
:undoc-members:
|
|
31
|
+
:show-inheritance:
|
|
32
|
+
|
|
33
|
+
.. autoclass:: periphery.LEDError
|
|
34
|
+
:members:
|
|
35
|
+
:undoc-members:
|
|
36
|
+
:show-inheritance:
|
|
37
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
MMIO
|
|
2
|
+
====
|
|
3
|
+
|
|
4
|
+
Code Example
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
.. code-block:: python
|
|
8
|
+
|
|
9
|
+
from periphery import MMIO
|
|
10
|
+
|
|
11
|
+
# Open am335x real-time clock subsystem page
|
|
12
|
+
rtc_mmio = MMIO(0x44E3E000, 0x1000)
|
|
13
|
+
|
|
14
|
+
# Read current time
|
|
15
|
+
rtc_secs = rtc_mmio.read32(0x00)
|
|
16
|
+
rtc_mins = rtc_mmio.read32(0x04)
|
|
17
|
+
rtc_hrs = rtc_mmio.read32(0x08)
|
|
18
|
+
|
|
19
|
+
print("hours: {:02x} minutes: {:02x} seconds: {:02x}".format(rtc_hrs, rtc_mins, rtc_secs))
|
|
20
|
+
|
|
21
|
+
rtc_mmio.close()
|
|
22
|
+
|
|
23
|
+
# Open am335x control module page
|
|
24
|
+
ctrl_mmio = MMIO(0x44E10000, 0x1000)
|
|
25
|
+
|
|
26
|
+
# Read MAC address
|
|
27
|
+
mac_id0_lo = ctrl_mmio.read32(0x630)
|
|
28
|
+
mac_id0_hi = ctrl_mmio.read32(0x634)
|
|
29
|
+
|
|
30
|
+
print("MAC address: {:04x}{:08x}".format(mac_id0_lo, mac_id0_hi))
|
|
31
|
+
|
|
32
|
+
ctrl_mmio.close()
|
|
33
|
+
|
|
34
|
+
API
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
.. autoclass:: periphery.MMIO
|
|
38
|
+
:members:
|
|
39
|
+
:undoc-members:
|
|
40
|
+
:show-inheritance:
|
|
41
|
+
|
|
42
|
+
.. autoclass:: periphery.MMIOError
|
|
43
|
+
:members:
|
|
44
|
+
:undoc-members:
|
|
45
|
+
:show-inheritance:
|
|
46
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
PWM
|
|
2
|
+
===
|
|
3
|
+
|
|
4
|
+
Code Example
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
.. code-block:: python
|
|
8
|
+
|
|
9
|
+
from periphery import PWM
|
|
10
|
+
|
|
11
|
+
# Open PWM chip 0, channel 10
|
|
12
|
+
pwm = PWM(0, 10)
|
|
13
|
+
|
|
14
|
+
# Set frequency to 1 kHz
|
|
15
|
+
pwm.frequency = 1e3
|
|
16
|
+
# Set duty cycle to 75%
|
|
17
|
+
pwm.duty_cycle = 0.75
|
|
18
|
+
|
|
19
|
+
pwm.enable()
|
|
20
|
+
|
|
21
|
+
# Change duty cycle to 50%
|
|
22
|
+
pwm.duty_cycle = 0.50
|
|
23
|
+
|
|
24
|
+
pwm.close()
|
|
25
|
+
|
|
26
|
+
API
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
.. autoclass:: periphery.PWM
|
|
30
|
+
:members:
|
|
31
|
+
:undoc-members:
|
|
32
|
+
:show-inheritance:
|
|
33
|
+
|
|
34
|
+
.. autoclass:: periphery.PWMError
|
|
35
|
+
:members:
|
|
36
|
+
:undoc-members:
|
|
37
|
+
:show-inheritance:
|
|
38
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Serial
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
Code Example
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
.. code-block:: python
|
|
8
|
+
|
|
9
|
+
from periphery import Serial
|
|
10
|
+
|
|
11
|
+
# Open /dev/ttyUSB0 with baudrate 115200, and defaults of 8N1, no flow control
|
|
12
|
+
serial = Serial("/dev/ttyUSB0", 115200)
|
|
13
|
+
|
|
14
|
+
serial.write(b"Hello World!")
|
|
15
|
+
|
|
16
|
+
# Read up to 128 bytes with 500ms timeout
|
|
17
|
+
buf = serial.read(128, 0.5)
|
|
18
|
+
print("read {:d} bytes: _{:s}_".format(len(buf), buf))
|
|
19
|
+
|
|
20
|
+
serial.close()
|
|
21
|
+
|
|
22
|
+
API
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
.. autoclass:: periphery.Serial
|
|
26
|
+
:members:
|
|
27
|
+
:undoc-members:
|
|
28
|
+
:show-inheritance:
|
|
29
|
+
|
|
30
|
+
.. autoclass:: periphery.SerialError
|
|
31
|
+
:members:
|
|
32
|
+
:undoc-members:
|
|
33
|
+
:show-inheritance:
|
|
34
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
SPI
|
|
2
|
+
===
|
|
3
|
+
|
|
4
|
+
Code Example
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
.. code-block:: python
|
|
8
|
+
|
|
9
|
+
from periphery import SPI
|
|
10
|
+
|
|
11
|
+
# Open spidev1.0 with mode 0 and max speed 1MHz
|
|
12
|
+
spi = SPI("/dev/spidev1.0", 0, 1000000)
|
|
13
|
+
|
|
14
|
+
data_out = [0xaa, 0xbb, 0xcc, 0xdd]
|
|
15
|
+
data_in = spi.transfer(data_out)
|
|
16
|
+
|
|
17
|
+
print("shifted out [0x{:02x}, 0x{:02x}, 0x{:02x}, 0x{:02x}]".format(*data_out))
|
|
18
|
+
print("shifted in [0x{:02x}, 0x{:02x}, 0x{:02x}, 0x{:02x}]".format(*data_in))
|
|
19
|
+
|
|
20
|
+
spi.close()
|
|
21
|
+
|
|
22
|
+
API
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
.. autoclass:: periphery.SPI
|
|
26
|
+
:members:
|
|
27
|
+
:undoc-members:
|
|
28
|
+
:show-inheritance:
|
|
29
|
+
|
|
30
|
+
.. autoclass:: periphery.SPIError
|
|
31
|
+
:members:
|
|
32
|
+
:undoc-members:
|
|
33
|
+
:show-inheritance:
|
|
34
|
+
|
|
@@ -121,6 +121,7 @@ class Cdev2GPIO(GPIO):
|
|
|
121
121
|
_GPIO_V2_LINE_FLAG_BIAS_PULL_UP = 0x100
|
|
122
122
|
_GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN = 0x200
|
|
123
123
|
_GPIO_V2_LINE_FLAG_BIAS_DISABLED = 0x400
|
|
124
|
+
_GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME = 0x800
|
|
124
125
|
|
|
125
126
|
SUPPORTED = KERNEL_VERSION >= (5, 10)
|
|
126
127
|
|
|
@@ -257,6 +258,7 @@ class Cdev2GPIO(GPIO):
|
|
|
257
258
|
|
|
258
259
|
if direction == "in":
|
|
259
260
|
flags |= Cdev2GPIO._GPIO_V2_LINE_FLAG_EDGE_RISING if edge == "rising" else Cdev2GPIO._GPIO_V2_LINE_FLAG_EDGE_FALLING if edge == "falling" else (Cdev2GPIO._GPIO_V2_LINE_FLAG_EDGE_RISING | Cdev2GPIO._GPIO_V2_LINE_FLAG_EDGE_FALLING) if edge == "both" else 0
|
|
261
|
+
flags |= Cdev2GPIO._GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME if edge != "none" else 0
|
|
260
262
|
|
|
261
263
|
line_request.offsets[0] = self._line
|
|
262
264
|
line_request.consumer = self._label
|
|
@@ -149,11 +149,12 @@ class SPI(object):
|
|
|
149
149
|
|
|
150
150
|
# Methods
|
|
151
151
|
|
|
152
|
-
def transfer(self, data):
|
|
152
|
+
def transfer(self, data, inplace=False):
|
|
153
153
|
"""Shift out `data` and return shifted in data.
|
|
154
154
|
|
|
155
155
|
Args:
|
|
156
156
|
data (bytes, bytearray, list): a byte array or list of 8-bit integers to shift out.
|
|
157
|
+
inplace (bool): read in-place into data. data must be of type `bytearray`.
|
|
157
158
|
|
|
158
159
|
Returns:
|
|
159
160
|
bytes, bytearray, list: data shifted in.
|
|
@@ -166,20 +167,20 @@ class SPI(object):
|
|
|
166
167
|
"""
|
|
167
168
|
if not isinstance(data, (bytes, bytearray, list)):
|
|
168
169
|
raise TypeError("Invalid data type, should be bytes, bytearray, or list.")
|
|
170
|
+
elif inplace and not isinstance(data, bytearray):
|
|
171
|
+
raise TypeError("Invalid data type, should be bytearray for in-place read.")
|
|
169
172
|
|
|
170
173
|
# Create mutable array
|
|
171
174
|
try:
|
|
172
|
-
buf =
|
|
175
|
+
buf = data if inplace else bytearray(data)
|
|
173
176
|
except OverflowError:
|
|
174
177
|
raise ValueError("Invalid data bytes.")
|
|
175
178
|
|
|
176
|
-
buf_addr, buf_len = buf.buffer_info()
|
|
177
|
-
|
|
178
179
|
# Prepare transfer structure
|
|
179
180
|
spi_xfer = _CSpiIocTransfer()
|
|
180
|
-
spi_xfer.tx_buf =
|
|
181
|
-
spi_xfer.rx_buf =
|
|
182
|
-
spi_xfer.len =
|
|
181
|
+
spi_xfer.tx_buf = (ctypes.c_ubyte * len(data)).from_buffer(buf)
|
|
182
|
+
spi_xfer.rx_buf = spi_xfer.tx_buf
|
|
183
|
+
spi_xfer.len = len(data)
|
|
183
184
|
|
|
184
185
|
# Transfer
|
|
185
186
|
try:
|
|
@@ -189,11 +190,11 @@ class SPI(object):
|
|
|
189
190
|
|
|
190
191
|
# Return shifted out data with the same type as shifted in data
|
|
191
192
|
if isinstance(data, bytes):
|
|
192
|
-
return bytes(
|
|
193
|
+
return bytes(buf)
|
|
193
194
|
elif isinstance(data, bytearray):
|
|
194
|
-
return bytearray(buf)
|
|
195
|
+
return buf if inplace else bytearray(buf)
|
|
195
196
|
elif isinstance(data, list):
|
|
196
|
-
return buf
|
|
197
|
+
return list(buf)
|
|
197
198
|
|
|
198
199
|
def close(self):
|
|
199
200
|
"""Close the spidev SPI device.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: python-periphery
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.2
|
|
4
4
|
Summary: A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
|
|
5
5
|
Home-page: https://github.com/vsergeev/python-periphery
|
|
6
6
|
Author: vsergeev
|
|
@@ -19,5 +19,14 @@ Classifier: Topic :: Software Development :: Embedded Systems
|
|
|
19
19
|
Classifier: Topic :: System :: Hardware
|
|
20
20
|
Classifier: Topic :: System :: Hardware :: Hardware Drivers
|
|
21
21
|
License-File: LICENSE
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: classifier
|
|
25
|
+
Dynamic: description
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: keywords
|
|
28
|
+
Dynamic: license
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
Dynamic: summary
|
|
22
31
|
|
|
23
32
|
python-periphery is a pure Python library for GPIO, LED, PWM, SPI, I2C, MMIO, and Serial peripheral I/O interface access in userspace Linux. It is useful in embedded Linux environments (including Raspberry Pi, BeagleBone, etc. platforms) for interfacing with external peripherals. python-periphery is compatible with Python 2 and Python 3, is written in pure Python, and is MIT licensed. See https://github.com/vsergeev/python-periphery for more information.
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
.flake8
|
|
2
|
+
.gitignore
|
|
3
|
+
.readthedocs.yaml
|
|
4
|
+
CHANGELOG.md
|
|
1
5
|
LICENSE
|
|
2
6
|
README.md
|
|
3
7
|
setup.cfg
|
|
4
8
|
setup.py
|
|
9
|
+
.github/workflows/tests.yml
|
|
10
|
+
docs/Makefile
|
|
11
|
+
docs/conf.py
|
|
12
|
+
docs/gpio.rst
|
|
13
|
+
docs/i2c.rst
|
|
14
|
+
docs/index.rst
|
|
15
|
+
docs/led.rst
|
|
16
|
+
docs/mmio.rst
|
|
17
|
+
docs/pwm.rst
|
|
18
|
+
docs/requirements.txt
|
|
19
|
+
docs/serial.rst
|
|
20
|
+
docs/spi.rst
|
|
21
|
+
docs/version.rst
|
|
5
22
|
periphery/__init__.py
|
|
6
23
|
periphery/__init__.pyi
|
|
7
24
|
periphery/gpio.py
|
|
@@ -26,6 +43,7 @@ python_periphery.egg-info/PKG-INFO
|
|
|
26
43
|
python_periphery.egg-info/SOURCES.txt
|
|
27
44
|
python_periphery.egg-info/dependency_links.txt
|
|
28
45
|
python_periphery.egg-info/top_level.txt
|
|
46
|
+
tests/__init__.py
|
|
29
47
|
tests/test.py
|
|
30
48
|
tests/test_gpio.py
|
|
31
49
|
tests/test_gpio_sysfs.py
|
|
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
|
{python-periphery-2.4.0 → python_periphery-2.4.2}/python_periphery.egg-info/dependency_links.txt
RENAMED
|
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
|