Pure Python peripheral APIs for NuttX character devices
Project description
nuttx-periphery
Pure Python peripheral APIs for NuttX character devices.
nuttx_periphery wraps GPIO, PWM, User LED, and Timer character devices with typed Python methods built on os.open, fcntl.ioctl, and ctypes structures aligned with NuttX headers.
NuttX is a POSIX compliant real-time operating system (RTOS) which now has CPython support on QEMU RISC-V and Espressif devices such as ESP32-P4.
Installation
Currently pip installations are very slow due to the amount of imports required. To fix this, a custom installation script is provided.
NOTE: This process will be simplified when PyPi releases are available.
On the host machine, clone this repository, generate the .whl file and start a http server:
python3 -m venv venv
source venv/bin/activate
pip install -e .
python3 -m build --wheel
python3 -m http.server
On the target, download the install script and wheel to /tmp/:
wget -O /tmp/install-packages.py <host IP>:8000/scripts/install-packages.py
wget -O /tmp/nuttx_periphery-0.1.0-py3-none-any.whl <host IP>:8000/dist/nuttx_periphery-0.1.0-py3-none-any.whl
Now run the installer (defaults: install to /data, use the newest .whl in the script directory):
python /tmp/install-packages.py /data /tmp/nuttx_periphery-0.1.0-py3-none-any.whl
export PYTHONPATH=/data:$PYTHONPATH
The script and wheel must live in the same directory (e.g. /tmp/) unless the wheel path is passed explicitly.
Features
- GPIO: output, input, and signal-based interrupt registration.
- User LED: per-LED and mask read/write.
- PWM: per-channel frequency, duty, and optional dead-time / pulse count.
- Timer: status polling, timeouts, and signal notification.
- Generic device access: raw read/ioctl via
CharacterDevice.
Requirements
- NuttX running on microcontroller with CPython available
- esp32p4-function-ev-board:python
- NuttX on QEMU (rv-virt:python)
- rv-virt:python
Quick Start
Execute the following snippet from the Python interpreter on target:
from nuttx_periphery import GPIO, GPIOPinType
with GPIO("/dev/gpio0") as gpio:
gpio.set_pin_type(GPIOPinType.GPIO_OUTPUT_PIN)
gpio.write(True)
Examples
Additional runnable scripts are in examples/:
gpio_out.py— blink a GPIO outputgpio_interrupt.py— wait for a GPIO interrupt via signalpwm.py— read and write PWM channel settingstimer.py— poll timer time left until expirationtimer_notification.py— wait for timer expiration via signal
Run on a NuttX board:
wget -O /tmp/gpio_out.py <host IP>:8000/examples/gpio_out.py
python /tmp/gpio_out.py
Contributing
Contributions are welcome.
- Tests are required for new features.
- Code linting via
pre-commitis required.
Install from source:
git clone <repository-url>
cd nuttx-periphery
python -m pip install -e ".[dev]"
pre-commit install
pytest
The generated .whl and install script will be in dist/.
License
This project is licensed under the Apache License 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nuttx_periphery-0.1.0.tar.gz.
File metadata
- Download URL: nuttx_periphery-0.1.0.tar.gz
- Upload date:
- Size: 27.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b747f6102b654b752cc4d76689ce8c06fe516e873a3e3829aad59dd3e2371ffe
|
|
| MD5 |
70f05990bdb5c7035d3c1efda69e3e4a
|
|
| BLAKE2b-256 |
e2d5f65d387847453aca183c1d5ee39571164cd7961c10ddb6228aafbb5641a6
|
Provenance
The following attestation bundles were made for nuttx_periphery-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on fdcavalcanti/nuttx-periphery
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nuttx_periphery-0.1.0.tar.gz -
Subject digest:
b747f6102b654b752cc4d76689ce8c06fe516e873a3e3829aad59dd3e2371ffe - Sigstore transparency entry: 1769463531
- Sigstore integration time:
-
Permalink:
fdcavalcanti/nuttx-periphery@0ad34b9c2bd9b6219cd3dd461f37f35e1c37adb1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fdcavalcanti
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@0ad34b9c2bd9b6219cd3dd461f37f35e1c37adb1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nuttx_periphery-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nuttx_periphery-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f74fecdd85e4b4defaa049c5a0b780bdf22ed6a4a10fa329b8f7c5b1a3b793ec
|
|
| MD5 |
295e816eb59188fa47b4102f14365955
|
|
| BLAKE2b-256 |
0507656a4fbb17bd2ce41e692c0ef895cdc32ffe4eb9d46db6540d0e21f4d41f
|
Provenance
The following attestation bundles were made for nuttx_periphery-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on fdcavalcanti/nuttx-periphery
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nuttx_periphery-0.1.0-py3-none-any.whl -
Subject digest:
f74fecdd85e4b4defaa049c5a0b780bdf22ed6a4a10fa329b8f7c5b1a3b793ec - Sigstore transparency entry: 1769463943
- Sigstore integration time:
-
Permalink:
fdcavalcanti/nuttx-periphery@0ad34b9c2bd9b6219cd3dd461f37f35e1c37adb1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fdcavalcanti
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@0ad34b9c2bd9b6219cd3dd461f37f35e1c37adb1 -
Trigger Event:
release
-
Statement type: